operator==,!=,<,<=,>,>=,<=> (std::tuple)
|
定義済みヘッダー
<tuple>
|
||
|
template
<
class
...
TTypes
,
class
...
UTypes
>
bool
operator
==
(
const
std::
tuple
<
TTypes...
>
&
lhs,
|
(1) |
(C++11以降)
(C++14以降 constexpr) |
|
template
<
class
...
TTypes
,
class
...
UTypes
>
bool
operator
!
=
(
const
std::
tuple
<
TTypes...
>
&
lhs,
|
(2) |
(C++11以降)
(C++14以降 constexpr) (C++20まで) |
|
template
<
class
...
TTypes
,
class
...
UTypes
>
bool
operator
<
(
const
std::
tuple
<
TTypes...
>
&
lhs,
|
(3) |
(C++11以降)
(C++14以降constexpr) (C++20まで) |
|
template
<
class
...
TTypes
,
class
...
UTypes
>
bool
operator
<=
(
const
std::
tuple
<
TTypes...
>
&
lhs,
|
(4) |
(C++11以降)
(C++14以降 constexpr) (C++20まで) |
|
template
<
class
...
TTypes
,
class
...
UTypes
>
bool
operator
>
(
const
std::
tuple
<
TTypes...
>
&
lhs,
|
(5) |
(C++11以降)
(C++14以降 constexpr) (C++20まで) |
|
template
<
class
...
TTypes
,
class
...
UTypes
>
bool
operator
>=
(
const
std::
tuple
<
TTypes...
>
&
lhs,
|
(6) |
(C++11以降)
(C++14以降 constexpr) (C++20まで) |
|
template
<
class
...
TTypes
,
class
...
UTypes
>
constexpr
std::
common_comparison_category_t
<
|
(7) | (C++20以降) |
|
template
<
class
...
TTypes
, tuple
-
like UTuple
>
constexpr bool operator == ( const tuple < TTypes... > & lhs, const UTuple & rhs ) ; |
(8) | (C++23以降) |
|
template
<
class
...
TTypes
, tuple
-
like UTuple
>
constexpr
std::
common_comparison_category_t
<
|
(9) | (C++23以降) |
|
sizeof...
(
TTypes
)
が
sizeof...
(
UTypes
)
と等しくない場合、または
std
::
get
<
i
>
(
lhs
)
==
std
::
get
<
i
>
(
rhs
)
が
[
0
,
sizeof...
(
Types
)
)
の範囲内のいずれかの
i
に対して有効な式でない場合、プログラムは不適格となる。
std
::
get
<
i
>
(
lhs
)
==
std
::
get
<
i
>
(
rhs
)
の型と値カテゴリが
[
0
,
sizeof...
(
Types
)
)
の範囲内のいずれかの
i
に対して
BooleanTestable
の要件を満たさない場合、動作は未定義となる。
|
(C++26まで) |
|
このオーバーロードは、
sizeof...
(
TTypes
)
が
sizeof...
(
UTypes
)
と等しく、
std
::
get
<
i
>
(
lhs
)
==
std
::
get
<
i
>
(
rhs
)
が有効な式であり、かつ
decltype
(
std
::
get
<
i
>
(
lhs
)
==
std
::
get
<
i
>
(
rhs
)
)
が
[
0
,
sizeof...
(
Types
)
)
の範囲内のすべての
i
に対して
boolean-testable
をモデル化する場合にのみ、オーバーロード解決に参加する。
|
(C++26から) |
if ( std :: get < 0 > ( lhs ) < std :: get < 0 > ( rhs ) ) return true ;
if
(
std
::
get
<
0
>
(
rhs
)
<
std
::
get
<
0
>
(
lhs
)
)
return
false
;
if
(
std
::
get
<
1
>
(
lhs
)
<
std
::
get
<
1
>
(
rhs
)
)
return
true
;
if
(
std
::
get
<
1
>
(
rhs
)
<
std
::
get
<
1
>
(
lhs
)
)
return
false
;
...
- 空のタプルの場合、 std::strong_ordering::equal を返します。
- 空でないタプルの場合、効果は以下と同等です
if
(
auto
c
=
synth-three-way
(
std
::
get
<
0
>
(
lhs
)
, std
::
get
<
0
>
(
rhs
)
)
;
c
!
=
0
)
return
c
;
if
(
auto
c
=
synth-three-way
(
std
::
get
<
1
>
(
lhs
)
, std
::
get
<
1
>
(
rhs
)
)
;
c
!
=
0
)
return
c
;
...
return
synth-three-way
(
std
::
get
<
N
-
1
>
(
lhs
)
, std
::
get
<
N
-
1
>
(
rhs
)
)
;
tuple-like
オブジェクトであり、
rhs
の要素数が
std::
tuple_size_v
<
UTuple
>
によって決定される点が異なる。このオーバーロードは
argument-dependent lookup
によってのみ見つけることができる。
tuple-like
オブジェクトである点が異なる。
/* Elems */
は
[
0
,
std::
tuple_size_v
<
UTuple
>
)
の範囲で増加する各
i
に対する
std::
tuple_element_t
<
i, UTuple
>
型のパックを表す。このオーバーロードは
実引数依存探索
によってのみ発見される。
すべての比較演算子は短絡評価されます。比較結果を決定するために必要な範囲を超えてタプルの要素にアクセスすることはありません。
|
|
(C++20以降) |
目次 |
パラメータ
| lhs, rhs | - | 比較対象のタプル |
戻り値
[
0
,
sizeof...
(
Types
)
)
の範囲内の全ての
i
に対して成り立つ場合。それ以外の場合は
false
を返す。二つの空タプルの場合は
true
を返す。
注記
|
関係演算子は各要素の operator < を用いて定義される。 |
(C++20まで) |
|
関係演算子は synth-three-way を用いて定義され、これは可能な場合は operator <=> を、そうでない場合は operator < を使用する。 特に、要素型自体が operator <=> を提供していないが、三方比較可能な型に暗黙変換可能な場合、その変換が operator < の代わりに使用される。 |
(C++20以降) |
| 機能テスト マクロ | 値 | 標準 | 機能 |
|---|---|---|---|
__cpp_lib_constrained_equality
|
202403L
|
(C++26) | 制約付き operator == を std::tuple に追加 |
例
operator < がタプルに対して定義されているため、タプルのコンテナをソートすることができます。
#include <algorithm> #include <iostream> #include <tuple> #include <vector> int main() { std::vector<std::tuple<int, std::string, float>> v { {2, "baz", -0.1}, {2, "bar", 3.14}, {1, "foo", 10.1}, {2, "baz", -1.1}, }; std::sort(v.begin(), v.end()); for (const auto& p: v) std::cout << "{ " << get<0>(p) << ", " << get<1>(p) << ", " << get<2>(p) << " }\n"; }
出力:
{ 1, foo, 10.1 }
{ 2, bar, 3.14 }
{ 2, baz, -1.1 }
{ 2, baz, -0.1 }
欠陥報告
以下の動作変更の欠陥報告書は、以前に公開されたC++規格に対して遡及的に適用されました。
| DR | 適用対象 | 公開時の動作 | 正しい動作 |
|---|---|---|---|
|
LWG 2114
( P2167R3 ) |
C++11 | 論理演算の型事前条件が欠落していた | 追加された |
関連項目
|
(C++20で削除)
(C++20で削除)
(C++20で削除)
(C++20で削除)
(C++20で削除)
(C++20)
|
pair
内の値を辞書順に比較する
(関数テンプレート) |