, , , , , , - :
template <typename T, T(*INC)(const T), T start = {}>
struct managed_enum
{
enum
{
a = start,
b = INC(a),
c = INC(b),
};
};
:
template<typename T>
constexpr T shift_left(const T value) { return value << 1; }
using shifted = managed_enum<int, shift_left<int>, 1>;
, (. ). , shifted , , , .
Defining the different functions of the increment, you can automatically increase the different families of transfers, as long as they all have only three values managed_enum( a, b, c):
template<typename T>
constexpr T shift_left(const T value) { return value << 1; }
template<typename T>
constexpr T increment(const T value) { return value + 1; }
template<typename T>
constexpr T bicrement(const T value) { return value + 2; }
using shifted = managed_enum<int, shift_left<int>, 1>;
using increment = managed_enum<int, increment<int>>;
using bicrement = managed_enum<int, bicrement<int>>;
source
share