[C++] tuple
Updated:
개요
- 서로 다른 n개의 타입의 값을 저장할 수 있는 클래스 템플릿
- C++17의 경우 tie 대신 structured binding declaration를 통해 조금 더 간편한 바인딩 가능
예제
- 코드
#include <iostream> #include <string> #include <tuple> using namespace std; int main() { tuple<int, string> t1(1, "a"); cout << get<0>(t1) << ", " << get<1>(t1) << endl; auto t2 = make_tuple(2, "b"); int i = 0; string s = ""; tie(i, s) = t2; cout << i << ", " << s << endl; return 0; }
- 실행 결과
1, a 2, b