最終更新日時(UTC):
が更新

履歴 編集

function
<tuple>

std::tuple::operator=(C++11)

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なオブジェクトの対応する値を代入する動作を行う版である。

要件

Tii[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) : 要素数が同じかつ、次を全て満たすこと
  • (14) : 要素数が同じかつ、次をすべて満たすこと

例外

#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

処理系

参照