Boost logo

Boost :

From: Iain Denniston (iain.denniston_at_[hidden])
Date: 2007-08-23 07:37:51

> Somehow it doesn't compile here, but it can be a feature of g++.
> Unfortunately I have no other compiler to test.

Interesting - just tested it with MinGW GCC and with VC8 and as you say
doesn't compile with GCC - but does with VC8.

Delving into the gcc version of the STL provides the answer. From

// The following definitions of bitmask types are enums, not ints,
// as permitted (but not required) in the standard, in order to provide
// better type safety in iostream calls. A side effect is that
// expressions involving them are no longer compile-time constants.

which is then followed by overloads of all relevant bitwise operators
specifically for the relevant enum type(s), thereby creating the better
type safety mentioned. An interesting alternative solution, with the
advantage of not requiring a construction (like my proposal) but with
the disadvantage of requiring the witting of bitmask overloads for each
enum requiring this treatment.

So not a feature of GCC per-say - rather a feature of the provided STL.
Makes me wonder why this is not used in all other STLs.

> If limited to g++ now, then of course same feature for all platforms
> will be useful.

Well having looked into all of that I've decided I don't like my
proposal any more :oD There is an easier, more elegant solution, which
I'll go put together now.

The idea now being that at the definition of the enum you can write
something like:

enum foo


Which will define all relevant operators for that enum - giving the
safety required for the enum. Only difference is that now the function
will be of the form: void func(foo options); (and will only accept foo
enums or bitwise combinations of them)

So thanks for that - your comments have been most helpful indeed!


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