From 6b0741306964f3a5220acb2b375b09cf1814443b Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sat, 12 Nov 2022 18:56:17 +0100 Subject: OptionalStl, we hardly knew you --- compat/optional.hpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 compat/optional.hpp (limited to 'compat') diff --git a/compat/optional.hpp b/compat/optional.hpp new file mode 100644 index 00000000..9c1f9f6c --- /dev/null +++ b/compat/optional.hpp @@ -0,0 +1,25 @@ +#pragma once +#include +#include + +namespace std { +template struct tuple_size> : std::integral_constant {}; +template struct tuple_element<0, Corrade::Containers::Optional> { using type = T; }; +template struct tuple_element<1, Corrade::Containers::Optional> { using type = bool; }; +} + +namespace Corrade::Containers { + +template +std::tuple_element_t> +get(const Optional& value) noexcept(std::is_nothrow_default_constructible_v && std::is_nothrow_copy_constructible_v) +{ + static_assert(N < 2); + static_assert(std::is_default_constructible_v && std::is_copy_constructible_v); + if constexpr (N == 0) + return value ? *value : T{}; + if constexpr (N == 1) + return bool(value); +} + +} // namespace Corrade::Containers -- cgit v1.2.3