Boost logo

Boost :

Subject: Re: [boost] [C++0x] Emulation of scoped enums
From: Daniel James (daniel_james_at_[hidden])
Date: 2009-03-06 06:39:06


2009/3/6 vicente.botet <vicente.botet_at_[hidden]>:
>
> I don't think there is a better solution. You need to mask the fact that a enum type in C++0x is name scope and a type and can not be in C++03.

A class is a name scope and a type - isn't that why it's called 'enum class'?

    class algae {
    public:
        enum value {green, red, cyan};

        algae() {}
        algae(value v) : v_(v) {}

        // And any other required methods...
    private:
        value v_;
    };

    algae x = algae::red;
    algae y = red; // error...

This would also be closer to 'enum class' as it's strongly typed.

Beman's preprocessing syntax would have to change, as the closing
macro would have to know the name. The syntax using a preprocessor
sequence or varargs would be the same.

Daniel


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