From 9e1b727745a993f526747e7025f3685b325c1b6b Mon Sep 17 00:00:00 2001 From: Pavel Kirienko Date: Thu, 22 Feb 2024 13:09:05 +0200 Subject: [PATCH] Advance the variant; we need to move the destruction logic away from the arena --- include/cetl/pf17/variant.hpp | 129 +++++++++++++++++++++++++++++----- 1 file changed, 113 insertions(+), 16 deletions(-) diff --git a/include/cetl/pf17/variant.hpp b/include/cetl/pf17/variant.hpp index df4cf233..480bc4e9 100644 --- a/include/cetl/pf17/variant.hpp +++ b/include/cetl/pf17/variant.hpp @@ -10,10 +10,12 @@ #include #include +#include #include #include #include +#include #include #include // We need this even if exceptions are disabled for std::terminate. #include @@ -25,6 +27,18 @@ namespace pf17 /// Implementation of \ref std::variant_npos. constexpr std::size_t variant_npos = std::numeric_limits::max(); +/// Implementation of \ref std::monostate. +struct monostate +{}; +// clang-format off +inline constexpr bool operator==(const monostate, const monostate) noexcept { return true; } +inline constexpr bool operator!=(const monostate, const monostate) noexcept { return false; } +inline constexpr bool operator< (const monostate, const monostate) noexcept { return false; } +inline constexpr bool operator> (const monostate, const monostate) noexcept { return false; } +inline constexpr bool operator<=(const monostate, const monostate) noexcept { return true; } +inline constexpr bool operator>=(const monostate, const monostate) noexcept { return true; } +// clang-format on + namespace detail { namespace var @@ -32,6 +46,26 @@ namespace var template using nth_type = std::tuple_element_t>; +/// An internal helper used to keep the list of the variant types and query their properties. +template +struct types final +{ + template