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 +++++++++++++++++++++++++ editor/app.hpp | 2 +- editor/editor.hpp | 2 +- external/corrade | 2 +- src/precomp.hpp | 2 +- 5 files changed, 29 insertions(+), 4 deletions(-) create mode 100644 compat/optional.hpp 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 diff --git a/editor/app.hpp b/editor/app.hpp index 6be1eed3..5a52ef58 100644 --- a/editor/app.hpp +++ b/editor/app.hpp @@ -13,7 +13,7 @@ #include #include -#include +#include "compat/optional.hpp" #include namespace floormat { diff --git a/editor/editor.hpp b/editor/editor.hpp index e40e695a..1093aa8d 100644 --- a/editor/editor.hpp +++ b/editor/editor.hpp @@ -10,7 +10,7 @@ #include #include -#include +#include "compat/optional.hpp" #include namespace floormat { diff --git a/external/corrade b/external/corrade index d5cb9286..0c88d8dc 160000 --- a/external/corrade +++ b/external/corrade @@ -1 +1 @@ -Subproject commit d5cb9286d35e133435af69b0e196d837cb4c27a3 +Subproject commit 0c88d8dc75a1151285fdd7c2d97ddb6aeadd4993 diff --git a/src/precomp.hpp b/src/precomp.hpp index 5ec01fe0..bdd5a380 100644 --- a/src/precomp.hpp +++ b/src/precomp.hpp @@ -35,7 +35,7 @@ #include #include #include -#include +#include "compat/optional.hpp" #include #include #include -- cgit v1.2.3