Boost logo

Boost :

From: Thorsten Ottosen (tottosen_at_[hidden])
Date: 2005-12-08 09:55:20


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


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk