【发布时间】:2022-06-13 01:26:08
【问题描述】:
我在阅读std::integer_sequence 时遇到了这种语法。
这个双括号有什么作用?它看起来像某种形式的循环。它仅适用于非类型模板参数吗?它必须与参数的顺序相同吗?我们可以向后迭代吗?跳过一个数字?
// pretty-print a tuple
template<class Ch, class Tr, class Tuple, std::size_t... Is>
void print_tuple_impl(std::basic_ostream<Ch,Tr>& os,
const Tuple& t,
std::index_sequence<Is...>)
{
((os << (Is == 0? "" : ", ") << std::get<Is>(t)), ...);
}
【问题讨论】:
-
折叠表达式
-
可能相关,在我的anwser initialize tuple with a fixed-length array element
-
另请注意,这里的
std::index_sequence不是将元组输出到basic_ostream所必需的。std::apply的页面有一种方法可以做到这一点,您仍然有一个逗号,但不需要索引序列。
标签: c++