Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:54:05

0001 
0002 //              Copyright Catch2 Authors
0003 // Distributed under the Boost Software License, Version 1.0.
0004 //   (See accompanying file LICENSE.txt or copy at
0005 //        https://www.boost.org/LICENSE_1_0.txt)
0006 
0007 // SPDX-License-Identifier: BSL-1.0
0008 #ifndef CATCH_COMPARE_TRAITS_HPP_INCLUDED
0009 #define CATCH_COMPARE_TRAITS_HPP_INCLUDED
0010 
0011 #include <catch2/internal/catch_void_type.hpp>
0012 
0013 #include <type_traits>
0014 
0015 namespace Catch {
0016     namespace Detail {
0017 
0018 #if defined( __GNUC__ ) && !defined( __clang__ )
0019 #    pragma GCC diagnostic push
0020     // GCC likes to complain about comparing bool with 0, in the decltype()
0021     // that defines the comparable traits below.
0022 #    pragma GCC diagnostic ignored "-Wbool-compare"
0023     // "ordered comparison of pointer with integer zero" same as above,
0024     // but it does not have a separate warning flag to suppress
0025 #    pragma GCC diagnostic ignored "-Wextra"
0026     // Did you know that comparing floats with `0` directly
0027     // is super-duper dangerous in unevaluated context?
0028 #    pragma GCC diagnostic ignored "-Wfloat-equal"
0029 #endif
0030 
0031 #if defined( __clang__ )
0032 #    pragma clang diagnostic push
0033     // Did you know that comparing floats with `0` directly
0034     // is super-duper dangerous in unevaluated context?
0035 #    pragma clang diagnostic ignored "-Wfloat-equal"
0036 #endif
0037 
0038 #define CATCH_DEFINE_COMPARABLE_TRAIT( id, op )                               \
0039     template <typename, typename, typename = void>                            \
0040     struct is_##id##_comparable : std::false_type {};                         \
0041     template <typename T, typename U>                                         \
0042     struct is_##id##_comparable<                                              \
0043         T,                                                                    \
0044         U,                                                                    \
0045         void_t<decltype( std::declval<T>() op std::declval<U>() )>>           \
0046         : std::true_type {};                                                  \
0047     template <typename, typename = void>                                      \
0048     struct is_##id##_0_comparable : std::false_type {};                       \
0049     template <typename T>                                                     \
0050     struct is_##id##_0_comparable<T,                                          \
0051                                   void_t<decltype( std::declval<T>() op 0 )>> \
0052         : std::true_type {};
0053 
0054         // We need all 6 pre-spaceship comparison ops: <, <=, >, >=, ==, !=
0055         CATCH_DEFINE_COMPARABLE_TRAIT( lt, < )
0056         CATCH_DEFINE_COMPARABLE_TRAIT( le, <= )
0057         CATCH_DEFINE_COMPARABLE_TRAIT( gt, > )
0058         CATCH_DEFINE_COMPARABLE_TRAIT( ge, >= )
0059         CATCH_DEFINE_COMPARABLE_TRAIT( eq, == )
0060         CATCH_DEFINE_COMPARABLE_TRAIT( ne, != )
0061 
0062 #undef CATCH_DEFINE_COMPARABLE_TRAIT
0063 
0064 #if defined( __GNUC__ ) && !defined( __clang__ )
0065 #    pragma GCC diagnostic pop
0066 #endif
0067 #if defined( __clang__ )
0068 #    pragma clang diagnostic pop
0069 #endif
0070 
0071 
0072     } // namespace Detail
0073 } // namespace Catch
0074 
0075 #endif // CATCH_COMPARE_TRAITS_HPP_INCLUDED