style(*): add comments and attribute specifiers

This commit is contained in:
2022-12-29 21:55:02 +08:00
parent b75cb30f4f
commit 9368a49806
15 changed files with 916 additions and 268 deletions

View File

@ -1,4 +1,4 @@
#pragma once
#pragma once
#include "CoreTypes.h"
#include "TypeTraits/CompositeType.h"
@ -9,15 +9,18 @@ NAMESPACE_REDCRAFT_BEGIN
NAMESPACE_MODULE_BEGIN(Redcraft)
NAMESPACE_MODULE_BEGIN(Utility)
/** Forms lvalue reference to const type of 'Ref'. */
template <typename T>
FORCEINLINE constexpr const T& AsConst(T& Ref)
{
return Ref;
}
/** The const rvalue reference overload is deleted to disallow rvalue arguments. */
template <typename T>
void AsConst(const T&& Ref) = delete;
/** MoveTemp will cast a reference to an rvalue reference. */
template <typename T>
FORCEINLINE constexpr TRemoveReference<T>&& MoveTemp(T&& Obj)
{
@ -25,36 +28,43 @@ FORCEINLINE constexpr TRemoveReference<T>&& MoveTemp(T&& Obj)
return static_cast<CastType&&>(Obj);
}
/** CopyTemp will enforce the creation of an rvalue which can bind to rvalue reference parameters. */
template <typename T>
FORCEINLINE constexpr T CopyTemp(T& Obj)
{
return const_cast<const T&>(Obj);
}
/** CopyTemp will enforce the creation of an rvalue which can bind to rvalue reference parameters. */
template <typename T>
FORCEINLINE constexpr T CopyTemp(const T& Obj)
{
return Obj;
}
/** CopyTemp will enforce the creation of an rvalue which can bind to rvalue reference parameters. */
template <typename T>
FORCEINLINE constexpr T&& CopyTemp(T&& Obj)
{
// If we already have an rvalue, just return it unchanged, rather than needlessly creating yet another rvalue from it.
return MoveTemp(Obj);
}
/** Forwards lvalues as either lvalues or as rvalues, depending on T. */
template <typename T>
FORCEINLINE constexpr T&& Forward(TRemoveReference<T>& Obj)
{
return static_cast<T&&>(Obj);
}
/** Forwards lvalues as either lvalues or as rvalues, depending on T. */
template <typename T>
FORCEINLINE constexpr T&& Forward(TRemoveReference<T>&& Obj)
{
return static_cast<T&&>(Obj);
}
/** Exchanges the given values. */
template <typename T> requires (CMoveConstructible<T> && CMoveAssignable<T>)
FORCEINLINE constexpr void Swap(T& A, T& B)
{
@ -63,6 +73,7 @@ FORCEINLINE constexpr void Swap(T& A, T& B)
B = MoveTemp(Temp);
}
/** Replaces the value of 'A' with 'B' and returns the old value of 'A'. */
template <typename T, typename U = T> requires (CMoveConstructible<T> && CAssignableFrom<T&, U>)
FORCEINLINE constexpr T Exchange(T& A, U&& B)
{
@ -71,27 +82,42 @@ FORCEINLINE constexpr T Exchange(T& A, U&& B)
return Temp;
}
/**
* Converts any type T to a reference type, making it possible to use member functions
* in decltype expressions without the need to go through constructors.
*/
template <typename T>
TAddRValueReference<T> DeclVal();
/** Obtains the actual address of the object or function arg, even in presence of overloaded operator&. */
template <typename T> requires (CObject<T>)
FORCEINLINE constexpr T* AddressOf(T& Object)
{
return reinterpret_cast<T*>(&const_cast<char&>(reinterpret_cast<const volatile char&>(Object)));
}
/** Obtains the actual address of the object or function arg, even in presence of overloaded operator&. */
template <typename T> requires (!CObject<T>)
FORCEINLINE constexpr T* AddressOf(T& Object)
{
return &Object;
}
/** Rvalue overload is deleted to prevent taking the address of const rvalues. */
template <typename T>
const T* AddressOf(const T&&) = delete;
struct FIgnore
{
template <typename T>
FORCEINLINE constexpr void operator=(T&&) const { }
};
/**
* An object of unspecified type such that any value can be assigned to it with no effect.
* Intended for use with Tie when unpacking a TTuple, as placeholders for unused arguments
* or using Ignore to avoid warnings about unused return values from NODISCARD functions.
*/
inline constexpr FIgnore Ignore;
// This macro is used in place of using type aliases, see Atomic.h, etc
@ -109,14 +135,15 @@ inline constexpr FIgnore Ignore;
\
}
// TOverloaded Usage Example
//
// Visit(TOverloaded {
// [](auto A) { ... },
// [](double A) { ... },
// [](const FString& A) { ... },
// }, Target);
//
/**
* This class is used to create a set of overloaded functions.
*
* Visit(TOverloaded {
* [](auto A) { ... },
* [](double A) { ... },
* [](const FString& A) { ... },
* }, Target);
*/
template <typename... Ts>
struct TOverloaded : Ts...
{