小编Chi*_*Lin的帖子

C++:获取参数包的头和尾

如何获取参数包的前n个元素?或者最后 n 个元素,或者 [n, n+1, ..., m) 中的一片元素?例如:

head<3>(1, 2.0f, "three", '4') => make_tuple(1, 2.0f, "three")
tail<2>(1, 2.0f, "three", '4') => make_tuple("three", '4')
slice<1,3>(1, 2.0f, "three", '4') => make_tuple(2.0, "three")
Run Code Online (Sandbox Code Playgroud)

这可以通过 std::tuple、std::integer_sequence 和 std::get 的组合来实现,但我想知道是否有更简单的方法。

c++ templates variadic parameter-pack

5
推荐指数
1
解决办法
901
查看次数

标签 统计

c++ ×1

parameter-pack ×1

templates ×1

variadic ×1