aboutsummaryrefslogtreecommitdiff
path: root/app/source/Cplt/Utils/Variant.hpp
diff options
context:
space:
mode:
authorrtk0c <[email protected]>2022-06-30 21:38:53 -0700
committerrtk0c <[email protected]>2022-06-30 21:38:53 -0700
commit7fe47a9d5b1727a61dc724523b530762f6d6ba19 (patch)
treee95be6e66db504ed06d00b72c579565bab873277 /app/source/Cplt/Utils/Variant.hpp
parent2cf952088d375ac8b2f45b144462af0953436cff (diff)
Restructure project
Diffstat (limited to 'app/source/Cplt/Utils/Variant.hpp')
-rw-r--r--app/source/Cplt/Utils/Variant.hpp33
1 files changed, 33 insertions, 0 deletions
diff --git a/app/source/Cplt/Utils/Variant.hpp b/app/source/Cplt/Utils/Variant.hpp
new file mode 100644
index 0000000..df2f882
--- /dev/null
+++ b/app/source/Cplt/Utils/Variant.hpp
@@ -0,0 +1,33 @@
+#pragma once
+
+#include <utility>
+#include <variant>
+
+template <class... Ts>
+struct Overloaded : Ts...
+{
+ using Ts::operator()...;
+};
+template <class... Ts>
+Overloaded(Ts...) -> Overloaded<Ts...>;
+
+template <class... Args>
+struct VariantCastProxy
+{
+ std::variant<Args...> v;
+
+ template <class... ToArgs>
+ operator std::variant<ToArgs...>() const
+ {
+ return std::visit(
+ [](auto&& arg) -> std::variant<ToArgs...> { return arg; },
+ v);
+ }
+};
+
+/// Use snake_case naming to align with `static_cast`, `dynamic_cast`, etc..
+template <class... Args>
+auto variant_cast(std::variant<Args...> v) -> VariantCastProxy<Args...>
+{
+ return { std::move(v) };
+}