[C++] apply
Updated:
개요
- Callable 객체를 튜플 인수로 호출하는 함수
- 튜플 뿐만 아니라 get과 tuple_size를 지원하는 모든 것(pair, array)이 인수로 가능
예제
- 코드
#include <iostream> #include <string> #include <tuple> #include <utility> using namespace std; int main() { cout << apply([](int x, int y) { return x + y; }, pair(1, 2)) << endl; cout << apply([](int x, int y, int z) { return x + y + z; }, array{1, 2, 3}) << endl; cout << apply([](int i, string s) { return s + to_string(i); }, make_tuple(1, "a")) << endl; return 0; }
- 실행 결과
3 6 a1