I have BOOST installed on my Windows PC with Mingw. The BOOST installation basically works, but when I use a macro I got following error message:
macro "BOOST_PP_NOT_EQUAL_1" defined here
Under Linux it works!
Anybody out there what can help me? Or at least give some hint.
Here are my marco's:
#include <iostream>
#include <ostream>
#include <set>
#include <boost/preprocessor.hpp>
#include <boost/preprocessor/tuple/elem.hpp>
class EnumShowValue {
private:
static bool showValueFlag;
public:
explicit EnumShowValue(const bool flag) { EnumShowValue::showValueFlag = flag; }
static bool showValue() { return EnumShowValue::showValueFlag; }
};
inline std::ostream &operator <<(std::ostream &os, const EnumShowValue &) { return os; }
// Defines a entry of the enumerations either with an initialization value or with a default value.
#define ENUM_FIELD(C, T, ARGS)\
BOOST_PP_IF(BOOST_PP_EQUAL(BOOST_PP_TUPLE_SIZE(ARGS), 2),\
BOOST_PP_TUPLE_ELEM(0, ARGS) = BOOST_PP_TUPLE_ELEM(1, ARGS),\
BOOST_PP_TUPLE_ELEM(0, ARGS)),
// Define output of a single enumeration value.
#define ENUM_OUTPUT_CASE(C, T, ARGS)\
case T::BOOST_PP_TUPLE_ELEM(0, ARGS):\
os << BOOST_PP_STRINGIZE(BOOST_PP_TUPLE_ELEM(0, ARGS));\
break;
#define ENUM_INSERT(C, T, ARGS)\
this->insert(T::BOOST_PP_TUPLE_ELEM(0, ARGS));
#define ENUM_DEFINE_SET(C, T, ARGS)\
class Collection : public std::set<C> {\
public:\
Collection() : std::set<C>() {\
BOOST_PP_SEQ_FOR_EACH(ENUM_INSERT, C, ARGS)\
}\
};\
Collection collection;
// Works only if the enumeration values are unique.
#define ENUM(C, T, ARGS) \
enum class C : T {\
BOOST_PP_SEQ_FOR_EACH(ENUM_FIELD, C, ARGS)\
};\
ENUM_DEFINE_SET(C, T, ARGS)\
std::ostream &operator <<(std::ostream &os, const C val);\
std::ostream &operator <<(std::ostream &os, const C val) {\
switch (val) {\
BOOST_PP_SEQ_FOR_EACH(ENUM_OUTPUT_CASE, C, ARGS)\
default:\
os << "illegal value: " << BOOST_PP_STRINGIZE(C);\
if (!EnumShowValue::showValue()) {\
os << '(';\
if (sizeof(T) == 1) {\
os << static_cast<int>(val);\
} else {\
os << static_cast<T>(val);\
}\
os << ')';\
}\
}\
if (EnumShowValue::showValue()) {\
os << '(';\
if (sizeof(T) == 1) {\
os << static_cast<int>(val);\
} else {\
os << static_cast<T>(val);\
}\
os << ')';\
}\
return os;\
}
and a example how to use: (it defines some logging levels)
namespace logging {
ENUM(Level, unsigned char, ((DEBUG)(INFO)(WARNING)(ERR)))
}