Added utility type to convert variant members via std::visit.

This commit is contained in:
Patrick 2025-07-12 12:50:10 +02:00
parent 042e0d2465
commit 79f49829d3

View File

@ -4,6 +4,7 @@
#if !defined(MIJIN_UTIL_VARIANT_HPP_INCLUDED) #if !defined(MIJIN_UTIL_VARIANT_HPP_INCLUDED)
#define MIJIN_UTIL_VARIANT_HPP_INCLUDED 1 #define MIJIN_UTIL_VARIANT_HPP_INCLUDED 1
#include <utility>
#include <variant> #include <variant>
#include "./traits.hpp" #include "./traits.hpp"
@ -23,10 +24,21 @@ inline constexpr bool variant_contains_v<TSearch, std::variant<TVariantTypes...>
// //
// public types // public types
// //
template<typename... TCallable> template<typename... TCallable>
struct Visitor : TCallable ... struct Visitor : TCallable ...
{ {
using TCallable::operator()...; using TCallable::operator()...;
}; };
template<typename TRet>
struct CastTo
{
template<typename T>
TRet operator()(T&& arg) const
{
return static_cast<TRet>(std::forward<T>(arg));
}
};
} }
#endif // !defined(MIJIN_UTIL_VARIANT_HPP_INCLUDED) #endif // !defined(MIJIN_UTIL_VARIANT_HPP_INCLUDED)