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

履歴 編集

class
<flat_map>

std::flat_map::containers(C++23)

namespace std {
  template <class Key,
            class T,
            class Compare = less<Key>,
            class KeyContainer = vector<Key>,
            class MappedContainer = vector<T>>
  class flat_map {
  public:
    using key_container_type = KeyContainer;
    using mapped_container_type = MappedContainer;

    struct containers {
      key_container_type keys;
      mapped_container_type values;
    };
  };
}

概要

flat_mapクラス内部のデータ保持方法として、キーのコンテナと値のコンテナをもつ。

この形式の内部表現はextract()メンバ関数で取得でき、シリアライズなどの用途に使用できる。

基本的な使い方

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

int main()
{
  std::flat_map<std::string, int> fm = {
    {"Alice", 3},
    {"Bob",   1},
    {"Carol", 4}
  };

  decltype(fm)::containers c = fm.extract();

  std::cout << "keys:"
  for (const auto& key : c.keys) {
    std::cout << "  " << key << std::endl;
  }

  std::cout << "values:"
  for (const auto& value : c.values) {
    std::cout << "  " << value << std::endl;
  }
}

出力

keys:
  Alice
  Bob
  Carol
values:
  3
  1
  4

バージョン

言語

  • C++23

処理系