Template tuple - calling a function on each element

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

My question is in the code:

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

  void do_something_t         


        
7条回答
  •  星月不相逢
    2020-11-27 03:29

    In addition to the answer of @M. Alaggan, if you need to call a function on tuple elements in order of their appearance in the tuple, in C++17 you can also use a fold expression like this:

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

    (live example).

    Because otherwise order of evaluation of function arguments is unspecified.

提交回复
热议问题