Let\'s say I have a constant value (possibly of some enum type). Let\'s say I have many classes A, B, D, etc.
Can I have something like this?
C<1>
This is a fairly simple metafunction:
template
struct C {
typedef typename std::conditional::type type;
};
You would use this as C<1>::type foo;
.
If your compiler supports C++11 template aliases, you can simplify to:
template
using C = typename std::conditional::type;
and have your preferred C<1> foo;
syntax.
In pure C++03, implement std::conditional
as:
template
struct conditional {
typedef A type;
};
template
struct conditional {
typedef B type;
};