Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2021-03-10 17:57:30

Andrzej Krzemienski wrote:
> I do not appreciate the BOOST_DEFINE_ macros for enumerations. We get as
> much as four of them, ...

We'll even get eight once the requested support for class-nested enums is added. :-)

> and neither is able to handle the use case that I consider
> basic, which I often have in my code: where I omit value zero and start from 1:
> struct Error {
> badSoething = 1,
> badSomethingElse,
> tooLongSomethng,
> ...
> };
> So, I am not sure how many real life enums these macros cover.

They cover the common case of an enumeration without any initializers; the
case where you have a number of alternatives but don't care about their exact
numeric values. I do believe this is reasonably common, even if it's not

E.g. enum class Shape { Triangle, Rectangle, Circle }.

Further e.g.

template<class E, class... T> class evariant: public variant<T...>

    E index() const { return (E)variant<T...>::index(); }

and then evariant<Shape, Triangle, Rectangle, Circle>, and JSON serialization
gives you ["Circle", {"radius": 14.2}]. Or perhaps {"Circle": {"radius": 14.2}}. :-)

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