std::multiset<Key,Compare,Allocator>:: multiset
| (1) | ||
|
multiset
(
)
;
|
(C++11 前) | |
|
multiset
(
)
:
multiset
(
Compare
(
)
)
{
}
|
(C++11 起)
(C++26 起为 constexpr) |
|
|
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) | (C++26 起为 constexpr) |
|
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
>
::
|
(since C++11) |
|
在
类模板实参推导
期间,仅首个实参参与容器
|
(since C++23) |
|
在
类模板实参推导
期间,仅第一个实参参与容器
|
(C++23 起) |
目录参数
复杂度
1-3)
常量。
4,5)
N·log(N)
其中
N
为
std::
distance
(
first, last
)
的返回值。通常情况下时间复杂度为 N·log(N),若
[
first
,
last
)
已按
value_comp
(
)
排序,则时间复杂度为线性。
6,7)
与
other
的大小成线性关系。
8,9)
常数复杂度。若指定了
alloc
且
alloc
!
=
other.
get_allocator
(
)
,则为线性复杂度。
10,11)
N·log(N)
其中
N
是
init.
size
(
)
,通常情况下的时间复杂度,若
init
已按
value_comp
(
)
排序则为
N
的线性复杂度。
异常
对
说明在容器移动构造(重载 (8,9))之后,原先指向 尽管直到 C++23 才正式要求,但一些实现已经在早期模式中将模板参数
示例
运行此代码
#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++标准。
另请参阅
| ||||||||||||||||||||||||||||||||||||||||||||||||||||