Template tuple - calling a function on each element

后端 未结 7 2130
猫巷女王i
猫巷女王i 2020-11-27 02:28

My question is in the code:

template
struct TupleOfVectors {
  std::tuple...> tuple;

  void do_something_t         


        
7条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-27 03:29

    In C++17 you can do this:

    std::apply([](auto ...x){std::make_tuple(some_function(x)...);} , the_tuple);
    

    given that some_function has suitable overloads for all the types in the tuple.

    This already works in Clang++ 3.9, using std::experimental::apply.

提交回复
热议问题