名前空間
変種
操作

std::flat_map<Key,T,Compare,KeyContainer,MappedContainer>::flat_map

From cppreference.com
 
 
 
 
flat_map()
    : flat_map(key_compare()) { }
(1) (C++23から)
template< class Allocator >
flat_map( const flat_map&, const Allocator& alloc );
(2) (C++23から)
template< class Allocator >
flat_map( flat_map&&, const Allocator& alloc );
(3) (C++23から)
flat_map( key_container_type key_cont, mapped_container_type mapped_cont,
          const key_compare& comp = key_compare() );
(4) (C++23から)
template< class Allocator >

flat_map( const key_container_type& key_cont,
          const mapped_container_type& mapped_cont,

          const Allocator& alloc );
(5) (C++23から)
template< class Allocator >

flat_map( const key_container_type& key_cont,
          const mapped_container_type& mapped_cont,

          const key_compare& comp, const Allocator& alloc );
(6) (C++23から)
flat_map( std::sorted_unique_t, key_container_type key_cont,

          mapped_container_type mapped_cont,

          const key_compare& comp = key_compare() );
(7) (C++23から)
template< class Allocator >

flat_map( std::sorted_unique_t, const key_container_type& key_cont,

          const mapped_container_type& mapped_cont, const Allocator& alloc );
(8) (C++23から)
template< class Allocator >

flat_map( std::sorted_unique_t, const key_container_type& key_cont,
          const mapped_container_type& mapped_cont,

          const key_compare& comp, const Allocator& alloc );
(9) (C++23から)
explicit flat_map( const key_compare& comp )
    : c(), compare(comp) { }
(10) (C++23から)
template< class Allocator >
flat_map( const key_compare& comp, const Allocator& alloc );
(11) (C++23から)
template< class Allocator >
explicit flat_map( const Allocator& alloc );
(12) (C++23から)
template< class InputIter >

flat_map( InputIter first, InputIter last,
          const key_compare& comp = key_compare() )

    : c(), compare(comp);
(13) (C++23から)
template< class InputIter, class Allocator >

flat_map( InputIter first, InputIter last,

          const key_compare& comp, const Allocator& alloc );
(14) (C++23から)
template< class InputIter, class Allocator >
flat_map( InputIter first, InputIter last, const Allocator& alloc );
(15) (C++23から)
template< container-compatible-range<value_type> R >

flat_map( std::from_range_t, R&& rg, const key_compare& comp )

    : flat_map(comp);
(16) (C++23から)
template< container-compatible-range<value_type> R >

flat_map( std::from_range_t fr, R&& rg )

    : flat_map(fr, std::forward<R>(rg), key_compare()) { }
(17) (C++23から)
template< container-compatible-range<value_type> R, class Allocator >
flat_map( std::from_range_t, R&& rg, const Allocator& alloc );
(18) (C++23から)
template< container-compatible-range<value_type> R, class Allocator >

flat_map( std::from_range_t, R&& rg, const key_compare& comp,

          const Allocator& alloc );
(19) (C++23から)
template< class InputIter >

flat_map( std::sorted_unique_t s, InputIter first, InputIter last,
          const key_compare& comp = key_compare() )

    : c(), compare(comp);
(20) (C++23から)
template< class InputIter, class Allocator >

flat_map( std::sorted_unique_t s, InputIter first, InputIter last,

          const key_compare& comp, const Allocator& alloc );
(21) (C++23から)
template< class InputIter, class Allocator >

flat_map( std::sorted_unique_t s, InputIter first, InputIter last,

          const Allocator& alloc );
(22) (C++23から)
flat_map( std::initializer_list<value_type> init,

          const key_compare& comp = key_compare() )

    : flat_map(init.begin(), init.end(), comp) { }
(23) (C++23から)
template< class Allocator >

flat_map( std::initializer_list<value_type> init, const key_compare& comp,

          const Allocator& alloc );
(24) (C++23から)
template< class Allocator >
flat_map( std::initializer_list<value_type> init, const Allocator& alloc );
(25) (C++23から)
flat_map( std::sorted_unique_t s, std::initializer_list<value_type> init,

          const key_compare& comp = key_compare() )

    : flat_map(s, init.begin(), init.end(), comp) { }
(26) (C++23から)
template< class Allocator >

flat_map( std::sorted_unique_t s, std::initializer_list<value_type> init,

          const key_compare& comp, const Allocator& alloc );
(27) (C++23から)
template< class Allocator >

flat_map( std::sorted_unique_t s, std::initializer_list<value_type> init,

          const Allocator& alloc );
(28) (C++23から)

様々なデータソースから、オプションでユーザー指定の比較関数オブジェクト comp および/またはアロケータ alloc を使用して、新しいコンテナアダプタを構築します。

1) デフォルトコンストラクタ。空のコンテナアダプタを構築します。
2) コピーコンストラクタcother.c の内容のコピーで、compareother.compare で初期化します。 アロケータ使用上の注意 を参照してください。
3) ムーブコンストラクタ。ムーブセマンティクスを使用して、other の内容でコンテナアダプタを構築します。 アロケータ使用上の注意を参照してください。
4) まず、c.keysstd::move(key_cont) で、c.valuesstd::move(mapped_cont) で、comparecomp で初期化します。次に、基になる範囲 [begin()end())value_comp() に関してソートします。最後に、重複要素を次のように削除します。
auto zv = views::zip(c.keys, c.values);
auto it = ranges::unique(zv, key_equiv(compare)).begin();
auto dist = distance(zv.begin(), it);
c.keys.erase(c.keys.begin() + dist, c.keys.end());
c.values.erase(c.values.begin() + dist, c.values.end());
.
5) (4) と同じで、flat_map(key_cont, mapped_cont); と同等です。 アロケータ使用上の注意 を参照してください。
6) (4) と同じで、flat_map(key_cont, mapped_cont, comp); と同等です。 アロケータ使用上の注意 を参照してください。
7) c.keysstd::move(key_cont) で、c.valuesstd::move(mapped_cont) で、comparecomp で初期化します。
8) (7) と同じで、flat_map(s, key_cont, mapped_cont); と同等です。 アロケータ使用上の注意 を参照してください。
9) (7) と同じで、flat_map(s, key_cont, mapped_cont, comp); と同等です。 アロケータ使用上の注意 を参照してください。
10) 空のコンテナアダプタを構築します。
11,12) 空のコンテナアダプタを構築します。 アロケータ使用上の注意を参照してください。
13) コンテナアダプタを、範囲 [firstlast) の内容で構築します。 insert(first, last); と同等です。
14,15) (13) と同等です。 アロケータ使用上の注意を参照してください。
16) コンテナアダプタを、範囲 rg の内容で構築します。まず、(10) を 委譲コンストラクタとして使用します。次に、crg の内容で、insert_range(std::forward<R>(rg)); のように初期化します。
17) 委譲コンストラクタとして使用される点を除き、(16) と同等です。
18,19) (16) と同等です。 アロケータ使用上の注意を参照してください。
20) 基になるコンテナを、範囲 [firstlast) の内容で、insert(first, last) のように初期化します。
21,22) (20) と同等です。 アロケータ使用上の注意を参照してください。
23) 初期化子リストコンストラクタ。初期化子リスト init の内容で基になるコンテナを構築します。委譲コンストラクタとして (13) を使用します。
24,25) (23) と同等です。 アロケータ使用上の注意を参照してください。
26) 初期化子リストコンストラクタ。初期化子リスト init の内容で基になるコンテナを構築します。委譲コンストラクタとして (20) を使用します。
27,28) (26) と同等です。 アロケータ使用上の注意を参照してください。

オーバーロード (13-15,20-22) に関する注記: [firstlast)有効な範囲でない場合、動作は未定義です。

オーバーロード (4-6,13-19,23-25) に関する注意: 範囲内にキーが同等と評価される要素が複数ある場合、どの要素が挿入されるかは未指定です ( LWG2844 参照)。

目次

[編集] アロケータ使用上の注意

コンストラクタ (2,3,5,6,8,9,11,12,14,15,17,19,21,22,24,25,27,28) は、対応する非アロケータコンストラクタと同等ですが、基になるコンテナ c.keys および c.valuesuses-allocator construction を使用して構築される点が異なります。これらのオーバーロードは、std::uses_allocator_v<container_type, Allocator>true の場合にのみ、オーバーロード解決に参加します。

[編集] パラメータ

key_cont - 基になるキーコンテナを初期化するためのソースとして使用されるコンテナ
mapped_cont - 基になる値コンテナを初期化するためのソースとして使用されるコンテナ
その他 - 基になるコンテナの要素を初期化するためのソースとして使用される別の `flat_map`
alloc - 基になるコンテナのすべてのメモリ割り当てに使用されるアロケータ
comp - キーのすべての比較に使用される関数オブジェクト。
first, last - コピーする要素のソース 範囲 を定義するイテレータペア
init - 基になるコンテナの要素を初期化するための初期化子リスト
rg - コンテナ互換範囲 (すなわち、input_range であり、その要素が value_type に変換可能) で、基になるコンテナを初期化するためのソースとして使用されます。
fr - 保持されているメンバーが範囲構築されることを示す、曖昧さ解消タグ
s - 曖昧さ解消タグ。入力シーケンスが value_comp() に関してソートされており、すべての要素が一意であることを示します。
型要件
-
InputItLegacyInputIterator の要件を満たす必要があります。
-
CompareCompareの要件を満たす必要がある。
-
AllocatorAllocator の要件を満たす必要があります。

[編集] 計算量

1) 定数時間。
2) other のサイズに対する線形。
3) ラップされたコンテナの対応するムーブコンストラクタと同等。つまり、cont のサイズに対して定数または線形。
4-6) Ncontvalue_comp() に関してソートされている場合は線形、それ以外の場合は 𝓞(N·log(N))。ここで N は、この呼び出し前の key_cont.size() の値です。
7-9) ラップされたコンテナの対応するムーブコンストラクタと同等。つまり、cont のサイズに対して定数または線形。
10-12) 定数。
13-15) 入力範囲 [firstlast)value_comp() に関してソートされている場合は線形、それ以外の場合は 𝓞(N·log(N))。ここで N は、この呼び出し前の key_cont.size() の値です。
16-19) 入力範囲 rgvalue_comp() に関してソートされている場合は線形、それ以外の場合は 𝓞(N·log(N))。ここで N は、この呼び出し前の key_cont.size() の値です。
20-22) [firstlast) のサイズに対する線形。
23-25) init の要素が value_comp() に関してソートされている場合は線形、それ以外の場合は 𝓞(N·log(N))。ここで N は、この呼び出し前の key_cont.size() の値です。
26-28) init のサイズに対する線形。

[編集] 例外

Allocator::allocate の呼び出しが例外をスローする可能性があります。

[編集] 注意

コンテナの移動構築 (オーバーロード (3)) 後、`other` への参照、ポインタ、イテレータ (末尾イテレータを除く) は有効なままですが、現在 `*this` にある要素を参照します。現在の標準では、[container.reqmts]/67 の包括的な声明を通じてこの保証が提供され、より直接的な保証が LWG issue 2321 経由で検討されています。

[編集]

[編集] 関連項目

コンテナアダプタに値を割り当てる
(公開メンバ関数) [編集]

English 日本語 中文(简体) 中文(繁體)