I have a macro that is building a class for me. I want to provide a constructor which takes an int if the class itself does not have an int specified as its type. The macro looks something like:
CLASS_DECLARE(NAME, TYPE)\ class NAME { \ public: NAME(const TYPE& x) : value(x) {}\ private: TYPE value; }; I can come close using the boost preprocessor to manually turn this constructor on and off...
CLASS_DECLARE(NAME, TYPE)\ class NAME { \ public: NAME(const TYPE& x) : value(x) {}\ BOOST_PP_EXPR_IF(0, NAME(const int& x) : value(static_cast<TYPE>(x)) {})\ private: TYPE value; }; However, I cannot replace the 0 in the macro with a conditional. I want something like:
CLASS_DECLARE(NAME, TYPE)\ class NAME { \ public: NAME(const TYPE& x) : value(x) {}\ BOOST_PP_EXPR_IF(BOOST_PP_NOT_EQUAL(TYPE, int), NAME(const int& x) : value(static_cast<TYPE>(x)) {})\ private: TYPE value; }; However, that expands to something less than helpful:
BOOST_PP_EXPR_IIF_BOOST_PP_BOOL_BOOST_PP_NOT_EQUAL_CHECK_BOOST_PP_NOT_EQUAL_int(0, BOOST_PP_NOT_EQUAL_int)(MyType(const int& x) : value(static_cast<int>(x)){}; Looking around, it doesn't seem as though BOOST_PP_NOT_EQUAL is intended for this type of comparison. (I am aware of macro expansion issues and have build some "IMPL" macros to try to get things expanded out further. I don't think that is the problem here, however.) Thoughts?