Boost logo

Boost :

From: Frank Laub (frank.laub_at_[hidden])
Date: 2005-12-09 00:45:26

Thanks a lot for this suggestion. It inspired me to write version 2. In this
approach, the macro expansion only produces a type that contains the
underlying enum and storage(), which contains all the strings. The trick now
is that there is:

template <typename base>
struct safe_enum : base;

The macro now expands:



    class Boolean_base
        enum type
            size = 2,
            Invalid = -1

        typedef boost::array<const char*, (size)+1> array_type;
        static const array_type& storage()
            static const array_type names =
            return names;
    typedef safe_enum<Boolean_base> Boolean;

The Boolean now gets the following methods from safe_enum:
str() (CT and RT versions)

I was thinking of re-naming the other kind of enum that I had before
(BOOST_ENUM_COMMENTS) to something like BOOST_STRINGTABLE, since that's
really the intention.

I've uploaded v2 to the file vault under Preprocessor Metaprogramming. I'd
love to hear more suggestions or even complaints!

Thanks a ton,

Boost list run by bdawes at, gregod at, cpdaniel at, john at