Aug 1, 2017 at 2:07pm UTC
I have a series of classes that look like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
template <typename WrappedT, size_t Size>
class IntegerWrapper{/*...*/ };
//------------------------------------------------------------------------------
template <typename WrappedT, typename MemoryT, size_t Size>
class EnumWrapper{/*...*/ };
//------------------------------------------------------------------------------
template <typename T, size_t S>
struct WrapperSelector{
};
template <size_t S>
struct WrapperSelector<int , S>{
typedef IntegerWrapper<int , S> type;
};
template <size_t S>
struct WrapperSelector<long , S>{
typedef IntegerWrapper<long , S> type;
};
//And so on for long long, short, etc.
//------------------------------------------------------------------------------
template <typename WrappedT, size_t Length, size_t ElementSize>
class WrappedArray{
public :
typedef typename WrapperSelector<WrappedT, ElementSize>::type indexed_type;
//...
};
WrappedArray may be used like
1 2
WrappedArray<char , 16, 1> array;
WrappedArray<SomeEnum, 12, 3> array;
I want to specialize WrapperSelector for all enum types in one go, without having to specialize it individually for every enum type I actually wrap. Is there any way to do this?
EDIT:
The specialization for SomeEnum might look like this:
1 2 3 4
template <size_t S>
struct WrapperSelector<SomeEnum, S>{
typedef EnumWrapper<SomeEnum, short , S> type;
};
Last edited on Aug 1, 2017 at 2:10pm UTC
Aug 1, 2017 at 3:55pm UTC
I know about std::is_enum. I don't know how to use it here.
Aug 1, 2017 at 10:25pm UTC
Thanks, that did exactly what I needed.