Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-15 10:11:16

0001 /// \file
0002 //  CPP, the Concepts PreProcessor library
0003 //
0004 //  Copyright Eric Niebler 2018-present
0005 //  Copyright (c) 2020-present, Google LLC.
0006 //
0007 //  Use, modification and distribution is subject to the
0008 //  Boost Software License, Version 1.0. (See accompanying
0009 //  file LICENSE_1_0.txt or copy at
0010 //  http://www.boost.org/LICENSE_1_0.txt)
0011 //
0012 // This source code is licensed under the MIT license found in the
0013 // LICENSE file in the root directory of this source tree.
0014 //
0015 // Project home: https://github.com/ericniebler/range-v3
0016 //
0017 #ifndef CPP_COMPARE_HPP
0018 #define CPP_COMPARE_HPP
0019 
0020 #if __cplusplus > 201703L && __has_include(<compare>) && \
0021     defined(__cpp_concepts) && defined(__cpp_impl_three_way_comparison)
0022 
0023 #include <compare>
0024 #include <concepts/concepts.hpp>
0025 #include <range/v3/compare.hpp>
0026 
0027 // clang-format off
0028 
0029 namespace concepts
0030 {
0031     // Note: concepts in this file can use C++20 concepts, since operator<=> isn't available in
0032     // compilers that don't support core concepts.
0033     namespace detail
0034     {
0035         template<typename T, typename Cat>
0036         concept compares_as = same_as<ranges::common_comparison_category_t<T, Cat>, Cat>;
0037     } // namespace detail
0038 
0039     inline namespace defs
0040     {
0041         template<typename T, typename Cat = std::partial_ordering>
0042         concept three_way_comparable =
0043             detail::weakly_equality_comparable_with_<T, T> &&
0044             detail::partially_ordered_with_<T ,T> &&
0045             requires(detail::as_cref_t<T>& a, detail::as_cref_t<T>& b) {
0046                 { a <=> b } -> detail::compares_as<Cat>;
0047             };
0048 
0049         template<typename T, typename U, typename Cat = std::partial_ordering>
0050         concept three_way_comparable_with =
0051             three_way_comparable<T, Cat> &&
0052             three_way_comparable<U, Cat> &&
0053             common_reference_with<detail::as_cref_t<T>&, detail::as_cref_t<U>&> &&
0054             three_way_comparable<common_reference_t<detail::as_cref_t<T>&, detail::as_cref_t<U>&>> &&
0055             detail::partially_ordered_with_<T, U> &&
0056             requires(detail::as_cref_t<T>& t, detail::as_cref_t<U>& u) {
0057                 { t <=> u } -> detail::compares_as<Cat>;
0058                 { u <=> t } -> detail::compares_as<Cat>;
0059             };
0060     } // inline namespace defs
0061 } // namespace concepts
0062 
0063 // clang-format on
0064 
0065 #endif // __cplusplus
0066 #endif // CPP_COMPARE_HPP