将运算符[]添加到std::tuple
警告:这是草稿。
基本原理
当前,为了访问元组,我们需要使用std::get<>函数家族。 这与我们为其余类型建立索引的通常方式不一致,而且更为冗长。
用户通常期望元组应该可通过operator []进行索引。 该约定将提供更多的接口统一性: vector , array , map , unordered_map和plain数组。
提议
我建议使用std::integral_constant将operator[]添加到std::tuple 。
这样,我们可以执行以下操作:
template <std>
constexpr std::integral_constant<std> c;
auto fib = make_tuple( 1 , 1 , 2 , 3 , 5 , 8 , 13 , 21 )