From ae1644e7e92b09055af18c4a2d5bc9a027eb16a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Ho=C5=99e=C5=88ovsk=C3=BD?= Date: Sun, 20 Nov 2022 15:29:12 +0100 Subject: [PATCH] Add logical trait polyfills --- src/CMakeLists.txt | 1 + src/catch2/catch_all.hpp | 1 + src/catch2/internal/catch_logical_traits.hpp | 44 +++++++++++++++++++ .../matchers/catch_matchers_templated.hpp | 17 +------ src/catch2/meson.build | 1 + 5 files changed, 49 insertions(+), 15 deletions(-) create mode 100644 src/catch2/internal/catch_logical_traits.hpp 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 #include #include +#include #include #include #include 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 + +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 struct conjunction : std::true_type {}; + template struct conjunction : B1 {}; + template + struct conjunction + : std::conditional_t, B1> {}; + + template struct disjunction : std::false_type {}; + template struct disjunction : B1 {}; + template + struct disjunction + : std::conditional_t> {}; + + template + struct negation : std::integral_constant {}; + +#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 #include #include +#include #include #include @@ -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 - struct conjunction : std::true_type {}; - - template - struct conjunction : std::integral_constant::value> {}; - -#endif // __cpp_lib_logical_traits - template using is_generic_matcher = std::is_base_of< Catch::Matchers::MatcherGenericBase, @@ -77,7 +64,7 @@ namespace Matchers { >; template - using are_generic_matchers = conjunction...>; + using are_generic_matchers = Catch::Detail::conjunction...>; template 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',