Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::flat_map<Key,T,Compare,KeyContainer,MappedContainer>::operator=

      From cppreference.com
      <cpp‎ |container‎ |flat map

      [edit template]
       
       
       
      std::flat_map
      Member types
      Member functions
      Non-member functions
      Helper classes
      Tags
      Deduction guides
       
      flat_map& operator=(const flat_map& other);
      (1)(since C++23)
      (implicitly declared)
      flat_map& operator=( flat_map&& other);
      (2)(since C++23)
      (implicitly declared)
      flat_map& operator=(std::initializer_list<value_type> ilist);
      (3)(since C++23)

      Replaces the contents of the container adaptor with the contents of given argument.

      1) Copy assignment operator. Replaces the contents with a copy of the contents ofother. Effectively callsc= other.c; comp= other.comp;.
      2) Move assignment operator. Replaces the contents with those ofother using move semantics. Effectively callsc= std::move(other.c); comp= std::move(other.comp);.
      3) Replaces the contents with those identified by initializer listilist.

      Contents

      [edit]Parameters

      other - another container adaptor to be used as source
      ilist - initializer list to be used as source

      [edit]Return value

      *this

      [edit]Complexity

      1,2) Equivalent to that ofoperator= of the underlyingcontainer.
      3) Linear in the size of*this andilist.

      [edit]Example

      Run this code
      #include <flat_map>#include <initializer_list>#include <print>#include <utility> int main(){std::flat_map<int,int> x{{1,1},{2,2},{3,3}}, y, z;constauto w={std::pair<constint,int>{4,4},{5,5},{6,6},{7,7}}; std::println("Initially:");std::println("x = {}", x);std::println("y = {}", y);std::println("z = {}", z);     y= x;// overload (1)std::println("Copy assignment copies data from x to y:");std::println("x = {}", x);std::println("y = {}", y);     z= std::move(x);// overload (2)std::println("Move assignment moves data from x to z, modifying both x and z:");std::println("x = {}", x);std::println("z = {}", z);     z= w;// overload (3)std::println("Assignment of initializer_list w to z:");std::println("w = {}", w);std::println("z = {}", z);}

      Output:

      Initially:x = {1: 1, 2: 2, 3: 3}y = {}z = {}Copy assignment copies data from x to y:x = {1: 1, 2: 2, 3: 3}y = {1: 1, 2: 2, 3: 3}Move assignment moves data from x to z, modifying both x and z:x = {}z = {1: 1, 2: 2, 3: 3}Assignment of initializer_list w to z:w = {4: 4, 5: 5, 6: 6, 7: 7}z = {4: 4, 5: 5, 6: 6, 7: 7}

      [edit]See also

      constructs theflat_map
      (public member function)[edit]
      replaces the underlying containers
      (public member function)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/container/flat_map/operator%3D&oldid=169511"

      [8]ページ先頭

      ©2009-2025 Movatter.jp