tuple& operator=(const tuple&); // (1) C++11
constexpr tuple& operator=(const tuple&); // (1) C++20
constexpr const tuple& operator=(const tuple&) const; // (2) C++23
tuple& operator=(tuple&&) noexcept(see below); // (3) C++11
constexpr tuple& operator=(tuple&&) noexcept(see below); // (3) C++20
constexpr const tuple& operator=(tuple&&) const; // (4) C++23
template <class... UTypes>
tuple& operator=(const tuple<UTypes...>&); // (5) C++11
template <class... UTypes>
constexpr tuple& operator=(const tuple<UTypes...>&); // (5) C++20
template<class... UTypes>
constexpr const tuple&
operator=(const tuple<UTypes...>&) const; // (6) C++23
template <class... UTypes>
tuple& operator=(tuple<UTypes...>&&); // (7) C++11
template <class... UTypes>
constexpr tuple& operator=(tuple<UTypes...>&&); // (7) C++20
template<class... UTypes>
constexpr const tuple&
operator=(tuple<UTypes...>&&) const; // (8) C++23
template <class U1, class U2>
tuple& operator=(const pair<U1, U2>&); // (9) C++11
template <class U1, class U2>
constexpr tuple& operator=(const pair<U1, U2>&); // (9) C++20
template<class U1, class U2>
constexpr const tuple&
operator=(const pair<U1, U2>&) const; // (10) C++23
template <class U1, class U2>
tuple& operator=(pair<U1, U2>&&); // (11) C++11
template <class U1, class U2>
constexpr tuple& operator=(pair<U1, U2>&&); // (11) C++20
template<class U1, class U2>
constexpr const tuple& operator=(pair<U1, U2>&&) const; // (12) C++23
template<tuple-like UTuple>
constexpr tuple& operator=(UTuple&&); // (13) C++23
template<tuple-like UTuple>
constexpr const tuple& operator=(UTuple&&) const; // (14) C++23
概要
- (1) : コピー代入を行う
- (2) : (1) のプロキシ参照版
- (3) : ムーブ代入を行う
- (4) : (3) のプロキシ参照版
- (5) : 変換可能な
tupleからのコピー代入を行う - (6) : (5) のプロキシ参照版
- (7) : 変換可能な
tupleからのムーブ代入を行う - (8) : (7) のプロキシ参照版
- (9) : 変換可能な
pairからのコピー代入を行う - (10) : (9) のプロキシ参照版
- (11) : 変換可能な
pairからのムーブ代入を行う - (12) : (11) のプロキシ参照版
- (13) :
tuple-likeなオブジェクトを代入 - (14) : (13) のプロキシ参照版
プロキシ参照版とは、プロキシ参照である(要素が全てプロキシ参照である)tupleが持つ各要素について、その要素の参照先へ、他のtuple又はtuple-likeなオブジェクトの対応する値を代入する動作を行う版である。
要件
Ti(iは[0, sizeof...(Types))を範囲とする)が以下で現れた場合、元のtupleのテンプレートパラメーターパックのi番目とする。また、Uiについては、パラメーターのtupleについてのテンプレートパラメーターパックのi番目とする。
- (1) : 全ての
iについて、is_copy_assignable<Ti>::value == trueであること - (2) : C++23 : 全ての
iについて、is_copy_assignable_v<const Ti> == trueであること - (3) : 全ての
iについて、is_move_assignable<Ti>::value == trueであること - (4) : C++23 : 全ての
iについて、is_assignable_v<const Ti&, Ti> == trueであること - (5) : 要素数が同じかつ、パラメータの
tupleの全ての要素型が、元のtupleの全ての要素型にコピー代入可能であること - (6) : C++23 : 要素数が同じかつ、全ての
iについて、is_assignable_v<const Ti&, const Ui&> == trueであること - (7) : 要素数が同じかつ、パラメータの
tupleの全ての要素型が、元のtupleの全ての要素型にムーブ代入可能であること - (8) : C++23 : 要素数が同じかつ、全ての
iについて、is_assignable_v<const Ti&, Ui> = trueであること - (9) : 元の
tupleの要素数が2であり、パラメータのpairの全ての要素型が元のtupleの全ての要素型にコピー代入可能であること - (10) : C++23 : 元の
tupleの要素数が2であり、is_assignable_v<const T0&, U1> && is_assignable_v<const T1&, U2>であること - (11) : 元の
tupleの要素型が2であり、パラメータのpairの全ての要素型が元のtupleの全ての要素型にムーブ代入可能であること - (12) : C++23 : 元の
tupleの要素数が2であり、is_assignable_v<const T0&, U1> && is_assignable_v<const T1&, U2>であること - (13) : 要素数が同じかつ、次を全て満たすこと
- C++23 :
different-from<UTuple, tuple> - C++23 :
remove_cvref_t<UTuple>がranges::subrangeの特殊化でないこと - C++23 : 全ての
iについて、is_assignable_v<Ti&, decltype(get<i>(std::forward<UTuple>(u)))>
- C++23 :
- (14) : 要素数が同じかつ、次をすべて満たすこと
- C++23 :
different-from<UTuple, tuple> - C++23 :
remove_cvref_t<UTuple>がranges::subrangeの特殊化でないこと - C++23 :
is_assignable_v<const Ti&, decltype(get<i>(std::forward<UTuple>(u)))>
- C++23 :
例外
- (3) : 全ての
iについて、is_nothrow_move_assignable<Ti>::value == trueの場合、決して例外を投げない。
例
#include <string>
#include <tuple>
int main()
{
// コピーコンストラクタ
{
std::tuple<int, char, std::string> t1(1, 'a', "hello");
std::tuple<int, char, std::string> t2 = t1;
}
// ムーブコンストラクタ
{
std::tuple<int, char, std::string> t = std::tuple<int, char, std::string>(1, 'a', "hello");
}
// 変換可能なタプルからのコピー構築
{
std::tuple<int, char, const char*> t1(1, 'a', "hello");
std::tuple<int, char, std::string> t2 = t1;
}
// 変換可能なタプルからのムーブ構築
{
std::tuple<int, char, std::string> t = std::make_tuple(1, 'a', "hello");
}
// 変換可能なpairからのコピー構築
{
std::pair<int, char> p(1, 'a');
std::tuple<int, char> t = p;
}
// 変換可能なpairからのムーブ構築
{
std::tuple<int, char> t = std::make_pair(1, 'a');
}
}
出力
バージョン
言語
- C++11
処理系
- Clang:
- GCC: 4.6.1 ✅
- ICC:
- Visual C++: