相关疑难解决方法(0)

编译时间映射和反向映射值

有人可以推荐一种更优雅的方式来实现这些编译时常量吗?

template <int> struct Map;
template <> struct Map<0> {static const int value = 4;};
template <> struct Map<1> {static const int value = 8;};
template <> struct Map<2> {static const int value = 15;};

template <int> struct MapInverse;
template <> struct MapInverse<4> {static const int value = 0;};
template <> struct MapInverse<8> {static const int value = 1;};
template <> struct MapInverse<15> {static const int value = 2;};
Run Code Online (Sandbox Code Playgroud)

这个值需要在我的程序中是constexpr,但逆映射值更新很繁琐(容易出错或忘记做).

c++ meta templates map inverse

17
推荐指数
3
解决办法
1万
查看次数

标签 统计

c++ ×1

inverse ×1

map ×1

meta ×1

templates ×1