Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::flat_multimap<Key,T,Compare,KeyContainer,MappedContainer>::replace

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

      [edit template]
       
       
       
      std::flat_multimap
      Member types
      Member functions
      Non-member functions
      Helper classes
      Tags
      Deduction guides
       
      void replace( key_container_type&& key_cont, mapped_container_type&& mapped_cont);
      (since C++23)

      Replaces the underlying containersc. Equivalent to:

      c.keys= std::move(key_cont);c.values= std::move(mapped_cont);

      The following conditions must be met:

      • The expressionkey_cont.size()== mapped_cont.size() istrue,
      • The elements ofkey_cont are sorted with respect tocompare.

        Otherwise, the behavior is undefined.

      Contents

      [edit]Parameters

      keys_cont - a sorted keys container of typeKeyContainer, the contents of which will be moved into*this
      mapped_cont - a container of mapped values of typeMappedContainer, the contents of which will be moved into*this

      [edit]Return value

      (none)

      [edit]Complexity

      Equals to complexity ofstd::move applied to adapted containers.

      [edit]Example

      Run this code
      #include <algorithm>#include <cassert>#include <flat_map>#include <print>#include <vector> int main(){std::vector<int> keys{1,2,3};assert(std::ranges::is_sorted(keys));std::vector<double> values{2.2,3.3,1.1};assert(keys.size()== values.size()); std::flat_multimap<int,double> map;assert(map.empty());     map.replace(keys, values);assert(map.size()==3);assert(map.keys()==3);assert(map.values()==3);assert(keys.empty());assert(values.empty()); std::println("{}", map);}

      Output:

      {1: 2.2, 2: 3.3, 3: 1.1}

      [edit]See also

      extracts the underlying containers
      (public member function)[edit]

      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/container/flat_multimap/replace&oldid=169484"

      [8]ページ先頭

      ©2009-2025 Movatter.jp