
Le 23/03/2017 à 00:01, Andrey Semashev via Boost a écrit :
On 03/23/17 01:54, Vicente J. Botet Escriba wrote:
I have an ordinal_set<Ordinal> that is type safe. An enum as the previous one canbe see as an Ordinal and so
enum animal_traits { eats_meat, eats_grass, has_tail, _count }; using animal_traits_set = ordinal_set
Is the ordinal_set part of Boost? Where can I see it? It was enum_set in [TBost.Enums] https://github.com/viboes/enums https://htmlpreview.github.io/?https://github.com/viboes/enums/blob/master/l...
and then it became ordinal_set in [JASEL] https://github.com/viboes/std-make/tree/master/include/experimental/fundamen... The last needs some work yet to adapt enums.
Also, how do you deduce the number of bits from the enum type?
it is the size of the ordinal type. For enums, the number of unique enumerators.
typedef typed_bitset< animal_traits, animal_traits::_count > animal;
animal a1; // all traits are false a1[eats_grass] = 1; a1[has_tail] = 1; a1[10] = 1; // error
I suspect it would also be faster to compile. compile time for ordinal sets would suffer a little bit as we need to associate at compile time each enumerator to its position (this could be provided by reflection or by user defined ordinal traits).
Ah, so one would also have to specialize traits for the enum?
Yes. There could be a linear default trait 0..N trait. Vicente