Boost logo

Boost :

From: Marc VIALA (mviala_at_[hidden])
Date: 2006-01-16 02:53:24


 
Hi,

May be I've missed some messages of the thread, see message here after, but
is there any method that would return the index of the enumeration element
when using BOOST_ENUM_VALUES.

Or if not, if there any convenient way to be able to do that:

BOOST_ENUM_VALUES(ErrorType, std::string,
        (Warning)("Warning...")
        (BadArg)("Bad argument...")
        (Fatal)("Fatal error...")

void f(ErrorType e)
{
        switch(e) {
                case ErrorType::Warning: break;
                case ErrorType::BadArg: break;
                case ErrorType::Fatal: break;
        }
}

I'm using BOOST_ENUM rev 4.5

Thanks in advance.

Best regards,

Marc Viala
mailto:mviala_at_[hidden]

-----Message d'origine-----
De : boost-bounces_at_[hidden] [mailto:boost-bounces_at_[hidden]] De
la part de Richard Jennings
Envoyé : jeudi 22 décembre 2005 15:31
À : boost_at_[hidden]
Objet : Re: [boost] BOSOT_ENUM proposal rev 4, ENUM_VALUES extension?

On Thu, 22 Dec 2005 11:04:57 -0000, Frank Laub <frank.laub_at_[hidden]>
wrote:

> One alternative is to do this instead:
>
> BOOST_ENUM_VALUES(BlockType_t, const char*,
> (SampleIfg)("Sample Interferogram")
> (SampleSpec)("Sample Spectrum")
> (SamplePhase)("Sample Phase")
> (RefIfg)("Reference Interferogram")
> )
>
> One principle idea of the Boost.Enum library is to hide the fact that
> integers are really doing the dirty work. I suppose in this case we
> could expose a 'raw' or 'native' method that would return the index
> number of the enumeration element. This could then be used for your
> vector index. Would this work for you?
>

Yes that would work for me. I took it that the spirit of BOOST_ENUM was
indeed to hide the basic type and that you should use BOOST_ENUM_VALUES if
you wanted to be sure of the value of each enumeration.

There's always a 'but', so mine is that using BOOST_ENUM_VALUES as you
suggest requires that the enumeration values start with zero. I think
that's most cases.

_______________________________________________
Unsubscribe & other changes:
http://lists.boost.org/mailman/listinfo.cgi/boost


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