diff options
| author | Martin Hořeňovský | 2022-11-20 15:29:12 +0100 |
|---|---|---|
| committer | Martin Hořeňovský | 2022-11-20 17:03:29 +0100 |
| commit | ae1644e7e92b09055af18c4a2d5bc9a027eb16a1 (patch) | |
| tree | f662070ac56334a3d4206ca772d93a17674231aa | |
| parent | 65cc7fd2ae39a7a543767f661b096d7d521ee4f0 (diff) | |
| download | catch3-ae1644e7e92b09055af18c4a2d5bc9a027eb16a1.tar.gz | |
Add logical trait polyfills
| -rw-r--r-- | src/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | src/catch2/catch_all.hpp | 1 | ||||
| -rw-r--r-- | src/catch2/internal/catch_logical_traits.hpp | 44 | ||||
| -rw-r--r-- | src/catch2/matchers/catch_matchers_templated.hpp | 17 | ||||
| -rw-r--r-- | src/catch2/meson.build | 1 |
5 files changed, 49 insertions, 15 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e81d9b6f..b54c6274 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -91,6 +91,7 @@ set(IMPL_HEADERS ${SOURCES_DIR}/internal/catch_lazy_expr.hpp ${SOURCES_DIR}/internal/catch_leak_detector.hpp ${SOURCES_DIR}/internal/catch_list.hpp + ${SOURCES_DIR}/internal/catch_logical_traits.hpp ${SOURCES_DIR}/internal/catch_message_info.hpp ${SOURCES_DIR}/internal/catch_meta.hpp ${SOURCES_DIR}/internal/catch_move_and_forward.hpp diff --git a/src/catch2/catch_all.hpp b/src/catch2/catch_all.hpp index 1fc49abf..a0bf7605 100644 --- a/src/catch2/catch_all.hpp +++ b/src/catch2/catch_all.hpp @@ -74,6 +74,7 @@ #include <catch2/internal/catch_lazy_expr.hpp> #include <catch2/internal/catch_leak_detector.hpp> #include <catch2/internal/catch_list.hpp> +#include <catch2/internal/catch_logical_traits.hpp> #include <catch2/internal/catch_message_info.hpp> #include <catch2/internal/catch_meta.hpp> #include <catch2/internal/catch_move_and_forward.hpp> diff --git a/src/catch2/internal/catch_logical_traits.hpp b/src/catch2/internal/catch_logical_traits.hpp new file mode 100644 index 00000000..bd875659 --- /dev/null +++ b/src/catch2/internal/catch_logical_traits.hpp @@ -0,0 +1,44 @@ + +// 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_LOGICAL_TRAITS_HPP_INCLUDED +#define CATCH_LOGICAL_TRAITS_HPP_INCLUDED + +#include <type_traits> + +namespace Catch { +namespace Detail { + +#if defined( __cpp_lib_logical_traits ) && __cpp_lib_logical_traits >= 201510 + + using std::conjunction; + using std::disjunction; + using std::negation; + +#else + + template <class...> struct conjunction : std::true_type {}; + template <class B1> struct conjunction<B1> : B1 {}; + template <class B1, class... Bn> + struct conjunction<B1, Bn...> + : std::conditional_t<bool( B1::value ), conjunction<Bn...>, B1> {}; + + template <class...> struct disjunction : std::false_type {}; + template <class B1> struct disjunction<B1> : B1 {}; + template <class B1, class... Bn> + struct disjunction<B1, Bn...> + : std::conditional_t<bool( B1::value ), B1, disjunction<Bn...>> {}; + + template <class B> + struct negation : std::integral_constant<bool, !bool(B::value)> {}; + +#endif + +} // namespace Detail +} // namespace Catch + +#endif // CATCH_LOGICAL_TRAITS_HPP_INCLUDED diff --git a/src/catch2/matchers/catch_matchers_templated.hpp b/src/catch2/matchers/catch_matchers_templated.hpp index 232d580f..ba0661ae 100644 --- a/src/catch2/matchers/catch_matchers_templated.hpp +++ b/src/catch2/matchers/catch_matchers_templated.hpp @@ -11,6 +11,7 @@ #include <catch2/matchers/catch_matchers.hpp> #include <catch2/internal/catch_stringref.hpp> #include <catch2/internal/catch_move_and_forward.hpp> +#include <catch2/internal/catch_logical_traits.hpp> #include <array> #include <algorithm> @@ -56,20 +57,6 @@ namespace Matchers { return arr; } -#if defined( __cpp_lib_logical_traits ) && __cpp_lib_logical_traits >= 201510 - - using std::conjunction; - -#else // __cpp_lib_logical_traits - - template<typename... Cond> - struct conjunction : std::true_type {}; - - template<typename Cond, typename... Rest> - struct conjunction<Cond, Rest...> : std::integral_constant<bool, Cond::value && conjunction<Rest...>::value> {}; - -#endif // __cpp_lib_logical_traits - template<typename T> using is_generic_matcher = std::is_base_of< Catch::Matchers::MatcherGenericBase, @@ -77,7 +64,7 @@ namespace Matchers { >; template<typename... Ts> - using are_generic_matchers = conjunction<is_generic_matcher<Ts>...>; + using are_generic_matchers = Catch::Detail::conjunction<is_generic_matcher<Ts>...>; template<typename T> using is_matcher = std::is_base_of< diff --git a/src/catch2/meson.build b/src/catch2/meson.build index 9cdaf9d9..b32f72d2 100644 --- a/src/catch2/meson.build +++ b/src/catch2/meson.build @@ -96,6 +96,7 @@ internal_headers = [ 'internal/catch_lazy_expr.hpp', 'internal/catch_leak_detector.hpp', 'internal/catch_list.hpp', + 'internal/catch_logical_traits.hpp', 'internal/catch_message_info.hpp', 'internal/catch_meta.hpp', 'internal/catch_move_and_forward.hpp', |