• Class / Function / Type

      std::
    • Header file

      <>
    • Other / All

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

    履歴 編集

    function
    <flat_map>

    std::flat_multimap::extract

    containers extract() &&;  // C++23
    

    概要

    キーのコンテナ、値のコンテナを戻り値として返す。

    戻り値

    クラス内部のデータ保持形式である containers オブジェクト。

    事後条件

    呼び出し側の flat_multimap は空になる(たとえ例外で関数が中断されたとしても)。

    計算量

    定数時間。

    備考

    本関数は右辺値修飾されているので、右辺値からのみ読み出し可能である。

    #include <flat_map>
    #include <iostream>
    #include <string>
    #include <utility>
    
    int main()
    {
      std::flat_multimap<std::string, int> fm = {
        {"Alice", 3},
        {"Bob",   1},
        {"Carol", 4}
      };
    
      std::cout << fm.size() << std::endl;
    
      decltype(fm)::containers c = std::move(fm).extract();
    
      std::cout << fm.size() << std::endl;
      std::cout << std::endl;
    
      auto k = c.keys.cbegin();
      auto v = c.values.cbegin();
      std::cout << "{" << std::endl;
      for (; k != c.keys.cend() && v != c.values.cend(); ++k, ++v) {
        std::cout << "  " << *k << ": " << *v << "," << std::endl;
      }
      std::cout << "}" << std::endl;
    }
    

    出力

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

    バージョン

    言語

    • C++23

    処理系

    関連項目