• Class / Function / Type

      std::
    • Header file

      <>
    • Other / All

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

    履歴 編集

    class
    <flat_map>

    std::flat_multimap::containers

    namespace std {
      template <class Key,
                class T,
                class Compare = less<Key>,
                class KeyContainer = vector<Key>,
                class MappedContainer = vector<T>>
      class flat_multimap {
      public:
        using key_container_type = KeyContainer;
        using mapped_container_type = MappedContainer;
    
        struct containers {
          key_container_type keys;
          mapped_container_type values;
        };
      };
    }
    

    概要

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

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

    基本的な使い方

    #include <flat_map>
    #include <iostream>
    #include <string>
    #include <utility>
    
    int main()
    {
      std::flat_multimap<char, std::string> fm = {
        {'s', "static"},
        {'s', "signed"},
        {'s', "struct"},
        {'c', "const"},
        {'c', "class"}
      };
    
      decltype(fm)::containers c = std::move(fm).extract();
    
      std::cout << "keys:" << std::endl;
      for (const auto& key : c.keys) {
        std::cout << "  '" << key << "'" << std::endl;
      }
    
      std::cout << "values:" << std::endl;
      for (const auto& value : c.values) {
        std::cout << "  \"" << value << "\"" << std::endl;
      }
    }
    

    出力

    keys:
      'c'
      'c'
      's'
      's'
      's'
    values:
      "const"
      "class"
      "static"
      "signed"
      "struct"
    

    バージョン

    言語

    • C++23

    処理系

    関連項目