std::tuple<Types...>:: operator=
|
tuple
&
operator
=
(
const
tuple
&
other
)
;
|
(1) |
(C++11부터)
(C++20부터 constexpr) |
|
constexpr
const
tuple
&
operator
=
(
const
tuple
&
other
)
const
;
|
(2) | (C++23부터) |
|
tuple
&
operator
=
(
tuple
&&
other
)
noexcept
(
/* see below */
)
;
|
(3) |
(C++11부터)
(C++20부터 constexpr) |
|
constexpr
const
tuple
&
operator
=
(
tuple
&&
other
)
const
;
|
(4) | (C++23 이후) |
|
template
<
class
...
UTypes
>
tuple & operator = ( const tuple < UTypes... > & other ) ; |
(5) |
(C++11 이후)
(C++20 이후 constexpr) |
|
template
<
class
...
UTypes
>
constexpr const tuple & operator = ( const tuple < UTypes... > & other ) const ; |
(6) | (C++23부터) |
|
template
<
class
...
UTypes
>
tuple & operator = ( tuple < UTypes... > && other ) ; |
(7) |
(C++11부터)
(C++20부터 constexpr) |
|
template
<
class
...
UTypes
>
constexpr const tuple & operator = ( tuple < UTypes... > && other ) const ; |
(8) | (C++23 이후) |
|
template
<
class
E1,
class
E2
>
tuple & operator = ( const std:: pair < E1, E2 > & p ) ; |
(9) |
(C++11부터)
(C++20부터 constexpr) |
|
template
<
class
E1,
class
E2
>
constexpr const tuple & operator = ( const std:: pair < E1, E2 > & p ) const ; |
(10) | (C++23 이후) |
|
template
<
class
E1,
class
E2
>
tuple & operator = ( std:: pair < E1, E2 > && p ) ; |
(11) |
(C++11 이후)
(C++20 이후 constexpr) |
|
template
<
class
E1,
class
E2
>
constexpr const tuple & operator = ( std:: pair < E1, E2 > && p ) const ; |
(12) | (C++23 이후) |
|
template
<
tuple
-
like UTuple
>
constexpr tuple & operator = ( UTuple && u ) ; |
(13) | (C++23 이후) |
|
template
<
tuple
-
like UTuple
>
constexpr const tuple & operator = ( UTuple && u ) const ; |
(14) | (C++23부터) |
튜플의 내용을 다른 튜플과 유사한 객체의 내용으로 대체합니다.
다음 설명에서 다음과 같이 가정합니다.
-
i
가 범위
[ 0 ,sizeof... ( Types ))내에서 순서대로 존재하고, -
Ti가 클래스 템플릿 매개변수 팩Types의i번째 타입이며, -
Ui가UTypes라는 이름의 함수 템플릿 매개변수 팩에서i번째 타입인 경우,
인덱싱은 0부터 시작합니다.
Ti
와
Ui
에 대해
true
인 경우입니다.
Ti
와
Ui
에 대해
std::
is_assignable_v
<
const
Ti
&
,
const
Ui
&
>
가
true
인 경우.
Ti
와
Ui
에 대해
std::
is_assignable
<
Ti
&
, Ui
>
::
value
가
true
인 경우.
Ti
와
Ui
에 대해
std::
is_assignable_v
<
const
Ti
&
, Ui
>
가
true
인 경우.
- sizeof... ( Types ) == 2 ,
- std:: is_assignable < T0 & , const E1 & > :: value 가 true 이고,
- std:: is_assignable < T1 & , const E2 & > :: value 가 true 인 경우.
- sizeof... ( Types ) == 2 ,
- std:: is_assignable_v < const T0 & , const E1 & > 가 true 이고,
- std:: is_assignable_v < const T1 & , const E2 & > 가 true 인 경우.
- sizeof... ( Types ) == 2 ,
- std:: is_assignable_v < T0 & , E1 > 가 true 이고,
- std:: is_assignable_v < T1 & , E2 > 가 true 인 경우.
- sizeof... ( Types ) == 2 ,
- std:: is_assignable_v < const T0 & , E1 > 가 true 이고,
- std:: is_assignable_v < const T1 & , E2 > 가 true 인 경우.
- std:: same_as < std:: remove_cvref_t < UTuple > , std:: tuple > 가 false 인 경우,
- std:: remove_cvref_t < UTuple > 가 std::ranges::subrange 의 특수화가 아닌 경우,
- sizeof... ( Types ) 가 std:: tuple_size_v < std:: remove_cvref_t < UTuple >> 와 같은 경우, 그리고
- std:: is_assignable_v < Ti & , decltype ( std :: get < i > ( std:: forward < UTuple > ( u ) ) ) > 가 true 인 모든 i 에 대해.
- std:: same_as < std:: remove_cvref_t < UTuple > , std:: tuple > 가 false 인 경우,
- std:: remove_cvref_t < UTuple > 가 std::ranges::subrange 의 특수화가 아닌 경우,
- sizeof... ( Types ) 가 std:: tuple_size_v < std:: remove_cvref_t < UTuple >> 와 같은 경우, 그리고
- std:: is_assignable_v < const Ti & , decltype ( std :: get < i > ( std:: forward < UTuple > ( u ) ) ) > 가 true 인 모든 i 에 대해.
목차 |
매개변수
| other | - | 이 튜플의 내용을 대체할 튜플 |
| p | - | 이 2-튜플의 내용을 대체할 페어 |
| u | - |
tuple-like
이 튜플의 내용을 대체할 튜플-라이크 객체
|
반환값
* this
예외
Types
에 포함된 타입들 중 하나의 할당이 예외를 발생시키는 경우, 구현에서 정의된 예외를 발생시킬 수 있습니다.
std::
is_nothrow_move_assignable
<
T0
>
::
value
&&
std::
is_nothrow_move_assignable
<
T1
>
::
value
&&
std::
is_nothrow_move_assignable
<
T2
>
::
value
&&
...
Types
에 포함된 타입 중 하나의 할당이 예외를 발생시키는 경우, 구현에서 정의된 예외를 발생시킬 수 있습니다.
예제
#include <iostream> #include <string> #include <string_view> #include <tuple> #include <utility> #include <vector> // std::vector<int> 출력을 위한 헬퍼 함수 std::ostream& operator<<(std::ostream& os, std::vector<int> const& v) { os << '{'; for (std::size_t t = 0; t != v.size(); ++t) os << v[t] << (t + 1 < v.size() ? ", " : ""); return os << '}'; } // 임의 크기의 튜플을 출력하는 헬퍼 함수 template<class... Args> void print_tuple(std::string_view name, const std::tuple<Args...>& t) { std::cout << name << " = {"; std::apply([&](auto&& arg, auto&&... args) { std::cout << arg; ((std::cout << ", " << args), ...); }, t); std::cout << '}'; } template<class Tuple1, class Tuple2> void print_tuples(std::string_view name1, const Tuple1& t1, std::string_view name2, const Tuple2& t2) { print_tuple(name1, t1); std::cout << ", "; print_tuple(name2, std::tuple(t2)); std::cout << "\n\n"; } int main() { // 튜플에서 튜플로의 변환 예제 // std::tuple<int, std::string, std::vector<int>> t1{1, "알파", {1, 2, 3}}, t2{2, "베타", {4, 5}}; print_tuples("1) t1", t1, "t2", t2); // 일반 복사 할당 // operator=( const tuple& other ); t1 = t2; print_tuples("2) t1 = t2;\n t1", t1, "t2", t2); // Normal move assignment // operator=( tuple&& other ); t1 = std::move(t2); print_tuples("3) t1 = std::move(t2);\n t1", t1, "t2", t2); // 복사 할당 변환 // operator=( const tuple<UTypes...>& other ); std::tuple<short, const char*, std::vector<int>> t3{3, "감마", {6, 7, 8}}; t1 = t3; print_tuples("4) t1 = t3;\n t1", t1, "t3", t3); // 이동 할당 변환 // operator=( tuple&& other ); t1 = std::move(t3); print_tuples("5) t1 = std::move(t3);\n t1", t1, "t3", t3); // Pair to tuple 예제 // std::tuple<std::string, std::vector<int>> t4{"델타", {10, 11, 12}}; std::pair<const char*, std::vector<int>> p1{"엡실론", {14, 15, 16}}; print_tuples("6) t4", t4, "p1", p1); // std::pair에서 복사 할당 변환 // operator=( const std::pair<U1, U2>& p ); t4 = p1; print_tuples("7) t4 = p1;\n t4", t4, "p1", p1); // std::pair에서 이동 할당 변환 // operator=( std::pair<U1, U2>&& p ); t4 = std::move(p1); print_tuples("8) t4 = std::move(p1);\n t4", t4, "p1", p1); }
가능한 출력:
1) t1 = {1, alpha, {1, 2, 3}}, t2 = {2, beta, {4, 5}}
2) t1 = t2;
t1 = {2, beta, {4, 5}}, t2 = {2, beta, {4, 5}}
3) t1 = std::move(t2);
t1 = {2, beta, {4, 5}}, t2 = {2, , {}}
4) t1 = t3;
t1 = {3, gamma, {6, 7, 8}}, t3 = {3, gamma, {6, 7, 8}}
5) t1 = std::move(t3);
t1 = {3, gamma, {6, 7, 8}}, t3 = {3, gamma, {}}
6) t4 = {delta, {10, 11, 12}}, p1 = {epsilon, {14, 15, 16}}
7) t4 = p1;
t4 = {epsilon, {14, 15, 16}}, p1 = {epsilon, {14, 15, 16}}
8) t4 = std::move(p1);
t4 = {epsilon, {14, 15, 16}}, p1 = {epsilon, {}}
결함 보고서
다음의 동작 변경 결함 보고서들은 이전에 발표된 C++ 표준에 소급 적용되었습니다.
| DR | 적용 대상 | 게시된 동작 | 올바른 동작 |
|---|---|---|---|
| LWG 2729 | C++11 |
operator
=
제약 조건이 없어 불필요한
미정의 동작이 발생할 수 있었음 |
제약 조건 추가됨 |
참고 항목
새로운
tuple
을 생성합니다
(public member function) |
|
|
내용을 할당합니다
(
std::pair<T1,T2>
의 public member function)
|