【问题标题】:How to apply a function to a variadic argument list and cat them to a tuple如何将函数应用于可变参数列表并将它们归类到元组
【发布时间】:2017-10-20 03:09:05
【问题描述】:

在下面的示例中,我想将整数列表转换为字符串元组并将其作为std::tuplestd::strings 返回。我该如何实现这个目标?

std::string to_str(int i) {
  return std::to_string(i);
}

template <typename... int>
auto generate_tuple_string(int... ints) {
  // what to do here?
}

理想情况下,to_str() 可以是返回相同(或不同)类型的其他函数。返回类型应该是 std::tuple 将它们连接在一起。

【问题讨论】:

    标签: c++ templates tuples variadic-templates c++17


    【解决方案1】:

    也许

    template <typename... I>
    auto generate_tuple_string(I ... ints) {
      return std::make_tuple(std::to_string(ints)...);
    }
    

    ?

    【讨论】:

    • @Rakete1111 - 天哪!当然不是。谢谢。
    猜你喜欢
    • 2012-11-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多