feat(templates): add MakeAny() and fix MakeOptional()
This commit is contained in:
parent
56cc0a4d69
commit
02cdce39e2
@ -599,6 +599,34 @@ static_assert(sizeof(FAny) == 64, "The byte size of FAny is unexpected");
|
|||||||
|
|
||||||
static_assert(alignof(FAny) == 16, "The byte alignment of FAny is unexpected");
|
static_assert(alignof(FAny) == 16, "The byte alignment of FAny is unexpected");
|
||||||
|
|
||||||
|
/** Creates an any object that does not contain a value. */
|
||||||
|
template <typename T> requires (NAMESPACE_PRIVATE::CFAnyPlaceable<T>)
|
||||||
|
NODISCARD FORCEINLINE constexpr FAny MakeAny(FInvalid)
|
||||||
|
{
|
||||||
|
return FAny(Invalid);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Creates an any object from value. */
|
||||||
|
template <typename T> requires (NAMESPACE_PRIVATE::CFAnyPlaceable<T> && CConstructibleFrom<TDecay<T>, T>)
|
||||||
|
NODISCARD FORCEINLINE constexpr FAny MakeAny(T&& InValue)
|
||||||
|
{
|
||||||
|
return FAny(Forward<T>(InValue));
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Creates an any object constructed in-place from Args.... */
|
||||||
|
template <typename T, typename... Ts> requires (NAMESPACE_PRIVATE::CFAnyPlaceable<T> && CConstructibleFrom<T, Ts...>)
|
||||||
|
NODISCARD FORCEINLINE constexpr FAny MakeAny(Ts&&... Args)
|
||||||
|
{
|
||||||
|
return FAny(InPlaceType<TDecay<T>>, Forward<T>(Args)...);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Creates an any object constructed in-place from IL, Args.... */
|
||||||
|
template <typename T, typename U, typename... Ts> requires (NAMESPACE_PRIVATE::CFAnyPlaceable<T> && CConstructibleFrom<T, initializer_list<U>, Ts...>)
|
||||||
|
NODISCARD FORCEINLINE constexpr FAny MakeAny(initializer_list<U> IL, Ts&&... Args)
|
||||||
|
{
|
||||||
|
return FAny(InPlaceType<TDecay<T>>, IL, Forward<T>(Args)...);
|
||||||
|
}
|
||||||
|
|
||||||
NAMESPACE_MODULE_END(Utility)
|
NAMESPACE_MODULE_END(Utility)
|
||||||
NAMESPACE_MODULE_END(Redcraft)
|
NAMESPACE_MODULE_END(Redcraft)
|
||||||
NAMESPACE_REDCRAFT_END
|
NAMESPACE_REDCRAFT_END
|
||||||
|
@ -377,25 +377,32 @@ TOptional(T) -> TOptional<T>;
|
|||||||
|
|
||||||
/** Creates an optional object that does not contain a value. */
|
/** Creates an optional object that does not contain a value. */
|
||||||
template <typename T> requires (CDestructible<T>)
|
template <typename T> requires (CDestructible<T>)
|
||||||
NODISCARD FORCEINLINE constexpr TOptional<TDecay<T>> MakeOptional(FInvalid)
|
NODISCARD FORCEINLINE constexpr TOptional<T> MakeOptional(FInvalid)
|
||||||
{
|
{
|
||||||
return TOptional<TDecay<T>>(Invalid);
|
return TOptional<T>(Invalid);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Creates an optional object from value. */
|
/** Creates an optional object from value. */
|
||||||
template <typename T> requires (CDestructible<T> && CConstructibleFrom<T, T&&>)
|
template <typename T> requires (CDestructible<TDecay<T>> && CConstructibleFrom<TDecay<T>, T>)
|
||||||
NODISCARD FORCEINLINE constexpr TOptional<T> MakeOptional(T&& InValue)
|
NODISCARD FORCEINLINE constexpr TOptional<TDecay<T>> MakeOptional(T&& InValue)
|
||||||
{
|
{
|
||||||
return TOptional<T>(Forward<T>(InValue));
|
return TOptional<TDecay<T>>(Forward<T>(InValue));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Creates an optional object constructed in-place from args.... */
|
/** Creates an optional object constructed in-place from Args.... */
|
||||||
template <typename T, typename... Ts> requires (CDestructible<T> && CConstructibleFrom<T, Ts...>)
|
template <typename T, typename... Ts> requires (CDestructible<T> && CConstructibleFrom<T, Ts...>)
|
||||||
NODISCARD FORCEINLINE constexpr TOptional<T> MakeOptional(Ts&&... Args)
|
NODISCARD FORCEINLINE constexpr TOptional<T> MakeOptional(Ts&&... Args)
|
||||||
{
|
{
|
||||||
return TOptional<T>(InPlace, Forward<T>(Args)...);
|
return TOptional<T>(InPlace, Forward<T>(Args)...);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Creates an optional object constructed in-place from IL, Args.... */
|
||||||
|
template <typename T, typename U, typename... Ts> requires (CDestructible<T> && CConstructibleFrom<T, initializer_list<U>, Ts...>)
|
||||||
|
NODISCARD FORCEINLINE constexpr TOptional<T> MakeOptional(initializer_list<U> IL, Ts&&... Args)
|
||||||
|
{
|
||||||
|
return TOptional<T>(InPlace, IL, Forward<T>(Args)...);
|
||||||
|
}
|
||||||
|
|
||||||
NAMESPACE_MODULE_END(Utility)
|
NAMESPACE_MODULE_END(Utility)
|
||||||
NAMESPACE_MODULE_END(Redcraft)
|
NAMESPACE_MODULE_END(Redcraft)
|
||||||
NAMESPACE_REDCRAFT_END
|
NAMESPACE_REDCRAFT_END
|
||||||
|
Loading…
Reference in New Issue
Block a user