
Frank Laub wrote:
There should be no problems using this macro in a header file. I get around the one definition rule by simply making the enum actually be a namespace with static functions inside that namespace. So basically:
BOOST_ENUM(Foo, (a)(b))
expands into:
namespace Foo { enum type { a, b, size = 2, Invalid = -1 };
typedef boost::array<const std::string, size+1> array_type;
Is it not possible to go for typedef boost::array<const char*, size+1> array_type ?
static const array_type names = { "a", "b", "2" };
static const std::string& str(type index) { assert(index >= 0 && index <= size); return names[(int)index]; }
and maybe a CT version: template< type index > inline const char* str() { BOOST_STATIC_ASSERT( index > Invalid ); return names[(int)index]; } -Thorsten