diff options
| author | Martin Hořeňovský | 2022-11-01 08:48:23 +0100 |
|---|---|---|
| committer | Martin Hořeňovský | 2022-11-04 19:24:42 +0100 |
| commit | d7f8c36e4cb856ee632b4ca01f8d5847984aa276 (patch) | |
| tree | 002a27d20dcf90798070da1c4c254608aaf22961 /src | |
| parent | b3dbd83da2f793a8630647e0053b6613ba5fb874 (diff) | |
| download | catch3-d7f8c36e4cb856ee632b4ca01f8d5847984aa276.tar.gz | |
Add traits for checking whether types are comparable
Diffstat (limited to 'src')
| -rw-r--r-- | src/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | src/catch2/catch_all.hpp | 1 | ||||
| -rw-r--r-- | src/catch2/internal/catch_compare_traits.hpp | 47 | ||||
| -rw-r--r-- | src/catch2/meson.build | 1 |
4 files changed, 50 insertions, 0 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 313d57e3..98f2ffd8 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -61,6 +61,7 @@ set(INTERNAL_HEADERS ${SOURCES_DIR}/internal/catch_clara.hpp ${SOURCES_DIR}/internal/catch_commandline.hpp ${SOURCES_DIR}/internal/catch_source_line_info.hpp + ${SOURCES_DIR}/internal/catch_compare_traits.hpp ${SOURCES_DIR}/internal/catch_compiler_capabilities.hpp ${SOURCES_DIR}/catch_config.hpp ${SOURCES_DIR}/internal/catch_config_android_logwrite.hpp diff --git a/src/catch2/catch_all.hpp b/src/catch2/catch_all.hpp index 9c5241be..1fc49abf 100644 --- a/src/catch2/catch_all.hpp +++ b/src/catch2/catch_all.hpp @@ -50,6 +50,7 @@ #include <catch2/internal/catch_case_sensitive.hpp> #include <catch2/internal/catch_clara.hpp> #include <catch2/internal/catch_commandline.hpp> +#include <catch2/internal/catch_compare_traits.hpp> #include <catch2/internal/catch_compiler_capabilities.hpp> #include <catch2/internal/catch_config_android_logwrite.hpp> #include <catch2/internal/catch_config_counter.hpp> diff --git a/src/catch2/internal/catch_compare_traits.hpp b/src/catch2/internal/catch_compare_traits.hpp new file mode 100644 index 00000000..381dba89 --- /dev/null +++ b/src/catch2/internal/catch_compare_traits.hpp @@ -0,0 +1,47 @@ + +// Copyright Catch2 Authors +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.txt or copy at +// https://www.boost.org/LICENSE_1_0.txt) + +// SPDX-License-Identifier: BSL-1.0 +#ifndef CATCH_COMPARE_TRAITS_HPP_INCLUDED +#define CATCH_COMPARE_TRAITS_HPP_INCLUDED + +#include <catch2/internal/catch_void_type.hpp> + +#include <type_traits> + +namespace Catch { + namespace Detail { + +#define CATCH_DEFINE_COMPARABLE_TRAIT( id, op ) \ + template <typename, typename, typename = void> \ + struct is_##id##_comparable : std::false_type {}; \ + template <typename T, typename U> \ + struct is_##id##_comparable< \ + T, \ + U, \ + void_t<decltype( std::declval<T>() op std::declval<U>() )>> \ + : std::true_type {}; \ + template <typename, typename = void> \ + struct is_##id##_0_comparable : std::false_type {}; \ + template <typename T> \ + struct is_##id##_0_comparable<T, \ + void_t<decltype( std::declval<T>() op 0 )>> \ + : std::true_type {}; + + // We need all 6 pre-spaceship comparison ops: <, <=, >, >=, ==, != + CATCH_DEFINE_COMPARABLE_TRAIT( lt, < ) + CATCH_DEFINE_COMPARABLE_TRAIT( le, <= ) + CATCH_DEFINE_COMPARABLE_TRAIT( gt, > ) + CATCH_DEFINE_COMPARABLE_TRAIT( ge, >= ) + CATCH_DEFINE_COMPARABLE_TRAIT( eq, == ) + CATCH_DEFINE_COMPARABLE_TRAIT( ne, != ) + +#undef CATCH_DEFINE_COMPARABLE_TRAIT + + } // namespace Detail +} // namespace Catch + +#endif // CATCH_COMPARE_TRAITS_HPP_INCLUDED diff --git a/src/catch2/meson.build b/src/catch2/meson.build index 5af841ce..1083897d 100644 --- a/src/catch2/meson.build +++ b/src/catch2/meson.build @@ -72,6 +72,7 @@ internal_headers = [ 'internal/catch_case_sensitive.hpp', 'internal/catch_clara.hpp', 'internal/catch_commandline.hpp', + 'internal/catch_compare_traits.hpp', 'internal/catch_compiler_capabilities.hpp', 'internal/catch_config_android_logwrite.hpp', 'internal/catch_config_counter.hpp', |