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

履歴 編集

function
<flat_map>

std::flat_map::operator=(C++23)

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

概要

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

効果

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

戻り値

*this

備考

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

#include <flat_map>
#include <iostream>
#include <string>
#include <vector>

void print(const std::flat_map<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}};

  std::flat_map<std::string, int> fm;
  fm = elems;

  print(fm);
}

出力

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

バージョン

言語

  • C++23

処理系