问题描述
我的问题在代码中:
您可以使用一些索引机制轻松地做到这一点.给定一个元函数 gen_seq
用于生成编译时整数序列(由 seq
类模板封装):
以及以下函数模板:
你可以这样使用上面的for_each_in_tuple
函数:
这是一个现场示例.>
在您的具体情况下,您可以这样使用它:
再一次,这是一个现场示例.
更新
如果您使用的是 C++14 或更高版本,则可以将上面的 seq
和 gen_seq
类替换为 std::integer_sequence
像这样:
如果您使用的是 C++17 或更高版本,则可以执行此操作(来自 下面的此评论):
My question is in the code:
You can quite easily do that with some indices machinery. Given a meta-function gen_seq
for generating compile-time integer sequences (encapsulated by the seq
class template):
And the following function templates:
You can use the for_each_in_tuple
function above this way:
Here is a live example.
In your concrete situation, this is how you could use it:
And once again, here is a live example.
Update
If you're using C++14 or later, you can replace the seq
and gen_seq
classes above with std::integer_sequence
like so:
If you're using C++17 or later you can do this (from this comment below):
这篇关于模板元组 - 在每个元素上调用一个函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!