Skip to content

Commit 9f5298a

Browse files
authored
compare_three_way_result : シンプル化
https://twitter.com/wx257osn2/status/1539647083153883136
1 parent 03e07f6 commit 9f5298a

File tree

1 file changed

+5
-10
lines changed

1 file changed

+5
-10
lines changed

reference/compare/compare_three_way_result.md

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,25 +42,19 @@ namespace std {
4242
#include <type_traits>
4343
4444
template<typename T, typename Cat>
45-
struct fallback_comp3way {
46-
using type = Cat;
47-
};
48-
49-
template<std::three_way_comparable T, typename Cat>
50-
struct fallback_comp3way<T, Cat> {
51-
using type = std::compare_three_way_result_t<T>;
52-
};
45+
using fallback_comp3way_t = std::conditional_t<std::three_way_comparable<T>, std::compare_three_way_result<T>, std::type_identity<Cat>>::type;
5346
5447
template<typename T>
5548
struct wrap {
5649
T t;
5750
58-
//<=>を使用可能ならそれを、そうでないなら< ==を使ってdefault実装
51+
// <=>を使用可能ならそれを、そうでないなら< ==を使ってdefault実装
5952
auto operator<=>(const wrap&) const
60-
-> fallback_comp3way<T, std::weak_ordering>::type
53+
-> fallback_comp3way_t<T, std::weak_ordering>
6154
= default;
6255
}
6356
57+
// <=>を定義しない型
6458
struct no_spaceship {
6559
int n;
6660
@@ -85,6 +79,7 @@ int main()
8579
}
8680
```
8781
* compare_three_way_result_t[color ff0000]
82+
* type_identity[link /reference/type_traits/type_identity.md]
8883

8984
### 出力
9085
```

0 commit comments

Comments
 (0)