Skip to content

Commit

Permalink
compare_three_way_result : シンプル化
Browse files Browse the repository at this point in the history
  • Loading branch information
onihusube committed Jun 22, 2022
1 parent 03e07f6 commit 9f5298a
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions reference/compare/compare_three_way_result.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,25 +42,19 @@ namespace std {
#include <type_traits>
template<typename T, typename Cat>
struct fallback_comp3way {
using type = Cat;
};
template<std::three_way_comparable T, typename Cat>
struct fallback_comp3way<T, Cat> {
using type = std::compare_three_way_result_t<T>;
};
using fallback_comp3way_t = std::conditional_t<std::three_way_comparable<T>, std::compare_three_way_result<T>, std::type_identity<Cat>>::type;
template<typename T>
struct wrap {
T t;
//<=>を使用可能ならそれを、そうでないなら< ==を使ってdefault実装
// <=>を使用可能ならそれを、そうでないなら< ==を使ってdefault実装
auto operator<=>(const wrap&) const
-> fallback_comp3way<T, std::weak_ordering>::type
-> fallback_comp3way_t<T, std::weak_ordering>
= default;
}
// <=>を定義しない型
struct no_spaceship {
int n;
Expand All @@ -85,6 +79,7 @@ int main()
}
```
* compare_three_way_result_t[color ff0000]
* type_identity[link /reference/type_traits/type_identity.md]

### 出力
```
Expand Down

0 comments on commit 9f5298a

Please sign in to comment.