【发布时间】:2018-09-28 10:43:31
【问题描述】:
我需要在查找库中设置大量的 std::vector。都有结构:
{N, N, ..., -N, -N}
我可以使用一些模板函数来做到这一点:
template<int N>
static constexpr std::initializer_list<int> H2 = {N, -N};
template<int N>
static constexpr std::initializer_list<int> H4 = {N, N, -N -N};
...
从中我可以简单地做到:
std::vector<int> v22 = H2<3>
std::vector<int> v35 = H3<5>
etc.
但是有没有办法将数字 2、4 等也包含在模板参数中?
【问题讨论】:
标签: c++11 templates template-meta-programming