std::flat_multimap<Key,T,Compare,KeyContainer,MappedContainer>::replace
From cppreference.com
< cpp | コンテナ | flat_multimap
| void replace( key_container_type&& key_cont, mapped_container_type&& mapped_cont ); |
(C++23から) | |
基底となるコンテナ c を置き換えます。これは以下の操作と同等です。
c.keys = std::move(key_cont); c.values = std::move(mapped_cont);
以下の条件を満たす必要があります。
- 式 key_cont.size() == mapped_cont.size() は true でなければなりません。
- key_cont の要素は、
compareに関してソートされている必要があります。それ以外の場合、動作は未定義です。
目次 |
[編集] パラメータ
| keys_cont | - | KeyContainer 型のソート済みのキーコンテナ。その内容は *this にムーブされます。 |
| mapped_cont | - | MappedContainer 型のマッピング値のコンテナ。その内容は *this にムーブされます。 |
[編集] 戻り値
(なし)
[編集] 計算量
アダプトされたコンテナに適用される std::move の複雑さに等しい。
[編集] 例
このコードを実行
#include <algorithm> #include <cassert> #include <flat_map> #include <print> #include <vector> int main() { std::vector<int> keys{1, 2, 3}; assert(std::ranges::is_sorted(keys)); std::vector<double> values{2.2, 3.3, 1.1}; assert(keys.size() == values.size()); std::flat_multimap<int, double> map; assert(map.empty()); map.replace(keys, values); assert(map.size() == 3); assert(map.keys() == 3); assert(map.values() == 3); assert(keys.empty()); assert(values.empty()); std::println("{}", map); }
出力
{1: 2.2, 2: 3.3, 3: 1.1}[編集] 関連項目
| 基底コンテナを抽出する (公開メンバ関数) |