• Class / Function / Type

      std::
    • Header file

      <>
    • Other / All

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

    履歴 編集

    function
    <flat_map>

    std::flat_multimap::operator=

    flat_multimap& operator=(initializer_list<value_type> il); // C++23
    

    概要

    初期化子リストの値を代入する。

    効果

    *thisの全ての要素が解放され、ilの全ての要素が*thisにコピー代入される。

    戻り値

    *this

    備考

    • 引数の型が const flat_multimap& であるコピー代入演算子と、引数の型が flat_multimap&& であるムーブ代入演算子は、それぞれ自動生成される。

    #include <flat_map>
    #include <iostream>
    #include <string>
    #include <vector>
    
    void print(const std::flat_multimap<std::string, int>& fm)
    {
      std::cout << "{" << std::endl;
      for (const auto& kv: fm) {
        std::cout << "  " << kv.first << ": " << kv.second << "," << std::endl;
      }
      std::cout << "}" << std::endl;
    }
    
    int main()
    {
      std::initializer_list<std::pair<std::string, int>> elems = {{"Alice", 3}, {"Bob", 1}, {"Carol", 4}, {"Alice", 1}};
    
      std::flat_multimap<std::string, int> fm;
      fm = elems;
    
      print(fm);
    }
    

    出力

    {
      Alice: 3,
      Alice: 1,
      Bob: 1,
      Carol: 4,
    }
    

    バージョン

    言語

    • C++23

    処理系