operator==,!=,<,<=,>,>=,<=> (std::multimap)
|
定义于头文件
<map>
|
||
|
template
<
class
Key,
class
T,
class
Compare,
class
Alloc
>
bool
operator
==
(
const
std::
multimap
<
Key, T, Compare, Alloc
>
&
lhs,
|
(1) | (C++26 起为 constexpr) |
|
template
<
class
Key,
class
T,
class
Compare,
class
Alloc
>
bool
operator
!
=
(
const
std::
multimap
<
Key, T, Compare, Alloc
>
&
lhs,
|
(2) | (C++20 前) |
|
template
<
class
Key,
class
T,
class
Compare,
class
Alloc
>
bool
operator
<
(
const
std::
multimap
<
Key, T, Compare, Alloc
>
&
lhs,
|
(3) | (C++20 前) |
|
template
<
class
Key,
class
T,
class
Compare,
class
Alloc
>
bool
operator
<=
(
const
std::
multimap
<
Key, T, Compare, Alloc
>
&
lhs,
|
(4) | (C++20 前) |
|
template
<
class
Key,
class
T,
class
Compare,
class
Alloc
>
bool
operator
>
(
const
std::
multimap
<
Key, T, Compare, Alloc
>
&
lhs,
|
(5) | (C++20 前) |
|
template
<
class
Key,
class
T,
class
Compare,
class
Alloc
>
bool
operator
>=
(
const
std::
multimap
<
Key, T, Compare, Alloc
>
&
lhs,
|
(6) | (C++20 前) |
|
template
<
class
Key,
class
T,
class
Compare,
class
Alloc
>
/* 见下文 */
|
(7) |
(C++20 起)
(C++26 起为 constexpr) |
比较两个
multimap
的内容。
设
value_type
为
multimap
的值类型(即
typename
multimap
::
value_type
):
|
return
std::
distance
(
lhs.
begin
(
)
, lhs.
end
(
)
)
|
(C++14 前) |
|
return std:: equal ( lhs. begin ( ) , lhs. end ( ) , rhs. begin ( ) , rhs. end ( ) ) ; |
(C++14 起) |
rhs. begin ( ) , rhs. end ( ) ) ; 。
-
value_type不满足 可小于比较 要求。 - operator < 未建立 全序关系 。
rhs.
begin
(
)
, rhs.
end
(
)
,
synth-three-way
)
。
-
T不满足three_way_comparable概念。 -
未为(可能 const 限定的)
value_type类型值定义 operator < 。 - operator < 未建立 全序关系 。
|
|
(since C++20) |
目录 |
参数
| lhs, rhs | - |
待比较内容的
multimap
容器
|
返回值
| 运算符 |
lhs
与
rhs
相等 |
lhs
字典序更大 |
rhs
字典序更大 |
|---|---|---|---|
| operator == | true | false | |
| operator ! = | false | true | |
| operator < | false | false | true |
| operator <= | true | ||
| operator > | false | true | false |
| operator >= | true | ||
| operator <=> | 等于 0 的值 | 大于 0 的值 | 小于 0 的值 |
复杂度
multimap
的大小成线性关系。
multimap
的大小成线性关系。
注释
|
关系运算符通过
|
(C++20 前) |
|
未定义关系运算符。重写候选 operator <=> 将通过重载决议被选择。
operator
<=>
优先使用
|
(C++20 起) |
这些非成员比较运算符不使用
Compare
来比较元素。
示例
#include <cassert> #include <compare> #include <map> int main() { std::multimap<int, char> a{{1, 'a'}, {2, 'b'}, {3, 'c'}}; std::multimap<int, char> b{{1, 'a'}, {2, 'b'}, {3, 'c'}}; std::multimap<int, char> c{{7, 'Z'}, {8, 'Y'}, {9, 'X'}, {10, 'W'}}; assert ("" "比较相等的容器:" && (a != b) == false && (a == b) == true && (a < b) == false && (a <= b) == true && (a > b) == false && (a >= b) == true && (a <=> b) != std::weak_ordering::less && (a <=> b) != std::weak_ordering::greater && (a <=> b) == std::weak_ordering::equivalent && (a <=> b) >= 0 && (a <=> b) <= 0 && (a <=> b) == 0 && "比较不相等的容器:" && (a != c) == true && (a == c) == false && (a < c) == true && (a <= c) == true && (a > c) == false && (a >= c) == false && (a <=> c) == std::weak_ordering::less && (a <=> c) != std::weak_ordering::equivalent && (a <=> c) != std::weak_ordering::greater && (a <=> c) < 0 && (a <=> c) != 0 && (a <=> c) <= 0 && ""); }
缺陷报告
以下行为变更缺陷报告被追溯应用于先前发布的C++标准。
| 缺陷报告 | 应用于 | 发布时的行为 | 正确行为 |
|---|---|---|---|
| LWG 3431 | C++20 |
operator
<=>
未要求
T
建模
three_way_comparable
|
要求 |