std:: make_tuple
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Member functions | ||||
| Non-member functions | ||||
|
make_tuple
|
||||
|
(until C++20)
(until C++20)
(until C++20)
(until C++20)
(until C++20)
(C++20)
|
||||
| Helper concepts | ||||
|
(C++23)
|
||||
| Helper classes | ||||
|
(C++23)
|
||||
|
(C++23)
|
||||
| Deduction guides (C++17) |
|
헤더에 정의됨
<tuple>
|
||
|
template
<
class
...
Types
>
std:: tuple < VTypes... > make_tuple ( Types && ... args ) ; |
(C++11부터)
(C++14부터 constexpr) |
|
인수의 타입들로부터 대상 타입을 추론하여 튜플 객체를 생성합니다.
각
Ti
에 대해
Types...
에서,
VTypes...
의 해당 타입
Vi
는
std::
decay
<
Ti
>
::
type
입니다. 단,
std::decay
를 적용한 결과가 어떤 타입
X
에 대해
std::
reference_wrapper
<
X
>
인 경우, 추론된 타입은
X&
입니다.
목차 |
매개변수
| args | - | 튜플을 구성하기 위한 0개 이상의 인수 |
반환값
주어진 값들을 포함하는 std::tuple 객체로, std:: tuple < VTypes... > ( std:: forward < Types > ( t ) ... ) . 와 같이 생성됩니다.
가능한 구현
template <class T> struct unwrap_refwrapper { using type = T; }; template <class T> struct unwrap_refwrapper<std::reference_wrapper<T>> { using type = T&; }; template <class T> using unwrap_decay_t = typename unwrap_refwrapper<typename std::decay<T>::type>::type; // 또는 std::unwrap_ref_decay_t 사용 (C++20부터) template <class... Types> constexpr // C++14부터 std::tuple<unwrap_decay_t<Types>...> make_tuple(Types&&... args) { return std::tuple<unwrap_decay_t<Types>...>(std::forward<Types>(args)...); } |
예제
#include <iostream> #include <tuple> #include <functional> std::tuple<int, int> f() // 이 함수는 여러 값을 반환합니다 { int x = 5; return std::make_tuple(x, 7); // C++17에서는 return {x,7}; 사용 } int main() { // 이종 튜플 생성 int n = 1; auto t = std::make_tuple(10, "Test", 3.14, std::ref(n), n); n = 7; std::cout << "The value of t is (" << std::get<0>(t) << ", " << std::get<1>(t) << ", " << std::get<2>(t) << ", " << std::get<3>(t) << ", " << std::get<4>(t) << ")\n"; // 여러 값을 반환하는 함수 int a, b; std::tie(a, b) = f(); std::cout << a << ' ' << b << '\n'; }
출력:
The value of t is (10, Test, 3.14, 7, 1) 5 7
참고 항목
|
(C++11)
|
lvalue 참조의
tuple
을 생성하거나 tuple을 개별 객체로 언패킹함
(함수 템플릿) |
|
(C++11)
|
전달 참조
의
tuple
을 생성함
(함수 템플릿) |
|
(C++11)
|
임의의 개수의 tuple을 연결하여
tuple
을 생성함
(함수 템플릿) |
|
(C++17)
|
인수의 tuple로 함수를 호출함
(함수 템플릿) |