std::multiset<Key,Compare,Allocator>:: multiset
| (1) | ||
|
multiset
(
)
;
|
(C++11まで) | |
|
multiset
(
)
:
multiset
(
Compare
(
)
)
{
}
|
(C++11から)
(constexprはC++26から) |
|
|
explicit
multiset
(
const
Compare
&
comp,
const Allocator & alloc = Allocator ( ) ) ; |
(2) | (C++26以降 constexpr) |
|
explicit
multiset
(
const
Allocator
&
alloc
)
;
|
(3) |
(C++11以降)
(C++26以降 constexpr) |
|
template
<
class
InputIt
>
multiset
(
InputIt first, InputIt last,
|
(4) | (constexpr since C++26) |
|
template
<
class
InputIt
>
multiset
(
InputIt first, InputIt last,
|
(5) |
(C++14以降)
(C++26以降constexpr) |
|
multiset
(
const
multiset
&
other
)
;
|
(6) | (C++26以降 constexpr) |
|
multiset
(
const
multiset
&
other,
const
Allocator
&
alloc
)
;
|
(7) |
(C++11以降)
(C++26以降 constexpr) |
|
multiset
(
multiset
&&
other
)
;
|
(8) |
(C++11以降)
(C++26以降 constexpr) |
|
multiset
(
multiset
&&
other,
const
Allocator
&
alloc
)
;
|
(9) |
(C++11以降)
(C++26以降constexpr) |
|
multiset
(
std::
initializer_list
<
value_type
>
init,
const
Compare
&
comp
=
Compare
(
)
,
|
(10) |
(C++11以降)
(C++26以降constexpr) |
|
multiset
(
std::
initializer_list
<
value_type
>
init,
const
Allocator
&
alloc
)
|
(11) |
(C++14以降)
(C++26以降 constexpr) |
|
template
<
container-compatible-range
<
value_type
>
R
>
multiset
(
std::
from_range_t
, R
&&
rg,
|
(12) |
(C++23以降)
(C++26以降constexpr) |
|
template
<
container-compatible-range
<
value_type
>
R
>
multiset
(
std::
from_range_t
, R
&&
rg,
|
(13) |
(C++23以降)
(C++26以降constexpr) |
様々なデータソースから新しいコンテナを構築し、オプションでユーザー指定のアロケータ alloc または比較関数オブジェクト comp を使用します。
[
first
,
last
)
。
|
alloc
が提供されない場合、アロケータは
std::
allocator_traits
<
allocator_type
>
::
|
(C++11以降) |
|
クラステンプレート引数推論
中、最初の引数のみがコンテナの
|
(C++23以降) |
|
クラステンプレート引数推論
中、最初の引数のみがコンテナの
|
(C++23以降) |
目次 |
パラメータ
| alloc | - | このコンテナのすべてのメモリ割り当てに使用するアロケータ |
| comp | - | キーのすべての比較に使用する比較関数オブジェクト |
| first, last | - | コピーする要素のソース範囲を定義するイテレータのペア range |
| other | - | コンテナの要素を初期化するためのソースとして使用する別のコンテナ |
| init | - | コンテナの要素を初期化するための初期化子リスト |
| rg | - |
container compatible range
、すなわち、要素が
value_type
に変換可能な
input_range
|
| 型要件 | ||
-
InputIt
は
LegacyInputIterator
の要件を満たさなければならない
|
||
-
Compare
は
Compare
の要件を満たさなければならない
|
||
-
Allocator
は
Allocator
の要件を満たさなければならない
|
||
計算量
[
first
,
last
)
が既に
value_comp
(
)
によってソートされている場合は
N
に対して線形時間となる。
例外
Allocator::allocate
への呼び出しは例外をスローする可能性があります。
注記
コンテナのムーブ構築後(オーバーロード ( 8,9 ) )、 other への参照、ポインタ、およびイテレータ(終端イテレータを除く)は有効なままですが、現在は * this 内の要素を参照します。現在の標準は [container.reqmts]/67 の包括的な記述によってこの保証を行っており、 LWG issue 2321 を通じてより直接的な保証が検討されています。
C++23で正式に要求される前から、一部の実装では既にテンプレートパラメータ
Allocator
を
非推定コンテキスト
に置いていた。
| 機能テスト マクロ | 値 | 標準 | 機能 |
|---|---|---|---|
__cpp_lib_containers_ranges
|
202202L
|
(C++23) | Ranges-aware 構築と挿入; オーバーロード ( 12,13 ) |
例
#include <iostream> #include <set> #include <string_view> template <typename T> void println(const std::string_view name, const std::multiset<T>& ms) { std::cout << name << ": "; for (const auto& element : ms) std::cout << element << ' '; std::cout << '\n'; } int main() { // (1) デフォルトコンストラクタ std::multiset<int> a; a.insert(4); a.insert(3); a.insert(2); a.insert(1); println("a", a); // (4) 範囲コンストラクタ std::multiset<int> b(a.begin(), a.find(3)); println("b", b); // (6) コピーコンストラクタ std::multiset<int> c(a); println("c", c); // (8) ムーブコンストラクタ std::multiset<int> d(std::move(a)); println("d", d); // (10) 初期化子リストコンストラクタ std::multiset<int> e{3, 2, 1, 2, 4, 7, 3}; println("e", e); // (12) 範囲コンストラクタ const auto w = {"α", "β", "γ", "δ", "δ", "γ", "β", "α"}; #if __cpp_lib_containers_ranges std::multiset<std::string> f(std::from_range, w); // オーバーロード (12) #else std::multiset<std::string> f(w.begin(), w.end()); // (4) へのフォールバック #endif println("f", f); }
出力:
a: 1 2 3 4 b: 1 2 c: 1 2 3 4 d: 1 2 3 4 e: 1 2 2 3 3 4 7 f: α α β β γ γ δ δ
不具合報告
以下の動作変更の欠陥報告書は、以前に公開されたC++規格に対して遡及的に適用されました。
| DR | 適用対象 | 公開時の動作 | 正しい動作 |
|---|---|---|---|
| LWG 2076 | C++11 |
オーバーロード
(
4
)
が条件付きで
Key
の
CopyInsertable
を要求
*
this
|
要求しない |
| LWG 2193 | C++11 | デフォルトコンストラクタがexplicit | non-explicitに変更 |
関連項目
|
コンテナに値を代入する
(公開メンバ関数) |