mirror of
https://github.com/RPCS3/rpcs3.git
synced 2025-07-03 21:41:26 +12:00
multicast<> rewritten
This commit is contained in:
parent
1a7ea2d235
commit
71441819e5
1 changed files with 14 additions and 25 deletions
|
@ -461,40 +461,29 @@ using any16 = any_pod<simple_t, sizeof(u16)>;
|
||||||
using any32 = any_pod<simple_t, sizeof(u32)>;
|
using any32 = any_pod<simple_t, sizeof(u32)>;
|
||||||
using any64 = any_pod<simple_t, sizeof(u64)>;
|
using any64 = any_pod<simple_t, sizeof(u64)>;
|
||||||
|
|
||||||
// Allows to define integer convertible to multiple enum types
|
// Allows to define integer convertible to multiple types
|
||||||
template<typename T = void, typename... Ts>
|
template<typename T, T Value, typename T1 = void, typename... Ts>
|
||||||
struct multicast : multicast<Ts...>
|
struct multicast : multicast<T, Value, Ts...>
|
||||||
{
|
{
|
||||||
static_assert(std::is_enum<T>::value, "multicast<> error: invalid conversion type (enum type expected)");
|
constexpr multicast() = default;
|
||||||
|
|
||||||
multicast() = default;
|
// Implicit conversion to desired type
|
||||||
|
constexpr operator T1() const
|
||||||
template<typename UT>
|
|
||||||
constexpr multicast(const UT& value)
|
|
||||||
: multicast<Ts...>(value)
|
|
||||||
, m_value{ value } // Forbid narrowing
|
|
||||||
{
|
{
|
||||||
|
return static_cast<T1>(Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr operator T() const
|
|
||||||
{
|
|
||||||
// Cast to enum type
|
|
||||||
return static_cast<T>(m_value);
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
std::underlying_type_t<T> m_value;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Recursion terminator
|
// Recursion terminator
|
||||||
template<>
|
template<typename T, T Value>
|
||||||
struct multicast<void>
|
struct multicast<T, Value, void>
|
||||||
{
|
{
|
||||||
multicast() = default;
|
constexpr multicast() = default;
|
||||||
|
|
||||||
template<typename UT>
|
// Explicit conversion to base type
|
||||||
constexpr multicast(const UT& value)
|
explicit constexpr operator T() const
|
||||||
{
|
{
|
||||||
|
return Value;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue