summaryrefslogtreecommitdiffhomepage
path: root/compat
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2022-11-12 18:56:17 +0100
committerStanislaw Halik <sthalik@misaki.pl>2022-11-12 18:56:17 +0100
commit6b0741306964f3a5220acb2b375b09cf1814443b (patch)
treed5b24fab133847e2cb53507e081974e54238bc39 /compat
parentfcf1619d1d13242ff316cf5232ef933cf58e04be (diff)
OptionalStl, we hardly knew you
Diffstat (limited to 'compat')
-rw-r--r--compat/optional.hpp25
1 files changed, 25 insertions, 0 deletions
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 <type_traits>
+#include <Corrade/Containers/Optional.h>
+
+namespace std {
+template<class T> struct tuple_size<Corrade::Containers::Optional<T>> : std::integral_constant<std::size_t, 2> {};
+template<class T> struct tuple_element<0, Corrade::Containers::Optional<T>> { using type = T; };
+template<class T> struct tuple_element<1, Corrade::Containers::Optional<T>> { using type = bool; };
+}
+
+namespace Corrade::Containers {
+
+template<std::size_t N, class T>
+std::tuple_element_t<N, Optional<T>>
+get(const Optional<T>& value) noexcept(std::is_nothrow_default_constructible_v<T> && std::is_nothrow_copy_constructible_v<T>)
+{
+ static_assert(N < 2);
+ static_assert(std::is_default_constructible_v<T> && std::is_copy_constructible_v<T>);
+ if constexpr (N == 0)
+ return value ? *value : T{};
+ if constexpr (N == 1)
+ return bool(value);
+}
+
+} // namespace Corrade::Containers