如何基于可变进模板的sizeof自动填充std::数组
How to automatically fill a std::array base on sizeof a variadic template?
在这个简化的代码中:
template <int... vars>
struct Compile_Time_Array_Indexes
{
static std::array < int, sizeof...(vars)> indexes;//automatically fill it base on sizeof...(vars)
};
template <int ... vars>
struct Compile_Time_Array :public Compile_Time_Array_Indexes<vars...>
{
};
我想根据vars...
的大小自动填充indexes
。
示例:
Compile_Time_Array <1,3,5,2> arr1;//indexes --> [0,1,2,3]
Compile_Time_Array <8,5> arr2; // indexes --> [0,1]
下面的定义显然适用于GCC-4.9和Clang-3.5:
template <typename Type, Type ...Indices>
auto make_index_array(std::integer_sequence<Type, Indices...>)
-> std::array<Type, sizeof...(Indices)>
{
return std::array<Type, sizeof...(Indices)>{Indices...};
}
template <int... vars>
std::array<int, sizeof...(vars)>
Compile_Time_Array_Indexes<vars...>::indexes
= make_index_array<int>(std::make_integer_sequence<int, sizeof...(vars)>{});
相关文章:
- 如何用文本填充 std::vector<int64_t>
- 用原始数据填充 std::vector
- 给定一个填充无符号字符**的 C 函数,如何在没有中间副本的情况下用数据填充 std::vector
- 直接从 C API 填充 std::string
- 用常量值填充 std::vector<double>
- 在成员初始化列表中填充 std::array
- 可以使用 memset 来填充 std::complex<float>s 数组吗?
- 填充 std::d eque<std::vector<std::string>> with boost::assign::list_of
- 清除并重新填充 std::vector<std::vector<T>>导致分配问题
- 用类的第一个条目填充std::向量的首选方法
- 使用函数指针自动填充 std::map
- 如何从缓冲区及其大小填充std::向量
- 可以直接用get_line填充std::vector<std::string>
- 使用boost::bind()填充std::min_element()的自定义函数中的结构
- 填充 std::map 时"C2593: operator = is ambiguous"
- 在填充std::矢量时使用不同的地址
- 为什么从std::string的initializer列表中填充std::向量不会调用std::字符串构造函数
- 在编译时填充 std::数组,并使用 const_cast 填充可能的未定义行为
- 用异构boost::融合向量类型数据填充std::vector
- c++使用' .reserve() '填充' std::vector '作为防止多线程缓存无效和错误共享的一种方