From f679a6604f10ee93bcb0828bf1c80121cf3e0a0a Mon Sep 17 00:00:00 2001 From: Pavel Kirienko Date: Thu, 22 Feb 2024 13:07:34 +0200 Subject: [PATCH] Add C++17 type traits needed for the variant --- include/cetl/pf17/type_traits.hpp | 48 +++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/include/cetl/pf17/type_traits.hpp b/include/cetl/pf17/type_traits.hpp index 424b3566..ab55b26a 100644 --- a/include/cetl/pf17/type_traits.hpp +++ b/include/cetl/pf17/type_traits.hpp @@ -30,6 +30,54 @@ constexpr bool is_nothrow_swappable = noexcept(swap(std::declval(), std::dec template constexpr bool is_nothrow_swappable_v = detail::type_traits::is_nothrow_swappable; +/// Implementation of \ref std::conjunction. +template +struct conjunction : std::true_type +{}; +template +struct conjunction : A +{}; +template +struct conjunction : std::conditional_t(A::value), conjunction, A> +{}; + +/// Implementation of \ref std::conjunction_v. +template +constexpr bool conjunction_v = conjunction::value; + +/// Implementation of \ref std::disjunction. +template +struct disjunction : std::false_type +{}; +template +struct disjunction : A +{}; +template +struct disjunction : std::conditional_t(A::value), A, disjunction> +{}; + +/// Implementation of \ref std::disjunction_v. +template +constexpr bool disjunction_v = disjunction::value; + +// --------------------------------------------------------------------------------------------------------------------- + +static_assert(conjunction_v<> == true, ""); +static_assert(conjunction_v == true, ""); +static_assert(conjunction_v == false, ""); +static_assert(conjunction_v == true, ""); +static_assert(conjunction_v == false, ""); +static_assert(conjunction_v == false, ""); +static_assert(conjunction_v == false, ""); + +static_assert(disjunction_v<> == false, ""); +static_assert(disjunction_v == true, ""); +static_assert(disjunction_v == false, ""); +static_assert(disjunction_v == true, ""); +static_assert(disjunction_v == true, ""); +static_assert(disjunction_v == true, ""); +static_assert(disjunction_v == false, ""); + } // namespace pf17 } // namespace cetl