Monday, November 27, 2017

C++17: std::apply()

C++17 added the template function std::apply() to apply a function object to arguments from a tuple. Here is an example:


#include <iostream>
#include <tuple>

int main()
{
  std::apply([](int a, int b, int c)
             {
               std::cout << a << " " << b << " " << c << std::endl;
             },
             std::make_tuple(1, 2, 3));
  return 0;
}
// Output:: 1 2 3

Reference: http://en.cppreference.com/w/cpp/types/integer

No comments:

Post a Comment