tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
three_way_comparable.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2// SPDX-FileCopyrightText: Copyright (C) 2021 Tobias Hienzsch
3
4#ifndef TETL_COMPARE_THREE_WAY_COMPAREABLE_HPP
5#define TETL_COMPARE_THREE_WAY_COMPAREABLE_HPP
6
7#include <etl/_compare/common_comparison_category.hpp>
8#include <etl/_compare/partial_ordering.hpp>
9#include <etl/_compare/weak_ordering.hpp>
10#include <etl/_concepts/boolean_testable.hpp>
11#include <etl/_concepts/same_as.hpp>
12#include <etl/_concepts/weakly_equality_comparable_with.hpp>
13#include <etl/_type_traits/remove_reference.hpp>
14
15namespace etl {
16namespace detail {
17template <typename T, typename Cat>
18concept compares_as = same_as<common_comparison_category_t<T, Cat>, Cat>;
19
20// clang-format off
21template<typename T, typename U>
22concept partially_ordered_with = requires(remove_reference_t<T> const& t, remove_reference_t<U> const& u) {
23 { t < u } -> boolean_testable;
24 { t > u } -> boolean_testable;
25 { t <= u } -> boolean_testable;
26 { t >= u } -> boolean_testable;
27 { u < t } -> boolean_testable;
28 { u > t } -> boolean_testable;
29 { u <= t } -> boolean_testable;
30 { u >= t } -> boolean_testable;
31};
32// clang-format on
33
34} // namespace detail
35
36// clang-format off
37/// \ingroup compare
38template<typename T, typename Cat = partial_ordering>
39concept three_way_comparable =
40 weakly_equality_comparable_with<T, T> &&
41 detail::partially_ordered_with<T, T> &&
42 requires(remove_reference_t<T> const& a, remove_reference_t<T> const& b) {
43 { a <=> b } -> detail::compares_as<Cat>;
44 };
45// clang-format on
46} // namespace etl
47
48#endif // TETL_COMPARE_THREE_WAY_COMPAREABLE_HPP
Definition adjacent_find.hpp:9
Definition partial_ordering.hpp:13