MCRO
C++23 utilities for Unreal Engine.
Loading...
Searching...
No Matches
Mcro::TypeName Namespace Reference

Variables

template<typename T >
constexpr FStringView TTypeName
 
template<typename T >
constexpr FStdStringView TTypeNameStd = GetCompileTimeTypeName<std::decay_t<T>>()
 
template<typename T >
const FName TTypeFName = FName(TTypeName<T>.Len(), TTypeName<T>.GetData())
 
template<typename T >
const FString TTypeString = FString(TTypeName<T>.GetData(), TTypeName<T>.Len())
 

Detailed Description

Convert types to string

Variable Documentation

◆ TTypeFName

template<typename T >
const FName Mcro::TypeName::TTypeFName = FName(TTypeName<T>.Len(), TTypeName<T>.GetData())
See also
TTypeName

Definition at line 142 of file TypeName.h.

◆ TTypeName

template<typename T >
FStringView Mcro::TypeName::TTypeName
constexpr
Initial value:
= FStringView(
GetCompileTimeTypeName<std::decay_t<T>>().data(),
GetCompileTimeTypeName<std::decay_t<T>>().size()
)
consteval Mcro::Text::FStdStringView GetCompileTimeTypeName()
Definition TypeName.h:46

Get a friendly string of an input type without using typeid(T).name() Actually this method gives more predictable results across compilers than typeid(T).name() but still not 100% the same. Besides TTypeName<T> can deal with incomplete types as well, whereas typeid(T) cannot (more on this in remarks). While it is more consistent across compilers, it is still not 100% consistent. Take templated types for instance where MSVC compiler will add "class" prefix in front of type arguments where GCC or CLang might not. Because of subtle differences like this, it is strongly discouraged to assume the exact format of the output of TTypeName<T>

Usage:

FStringView myTypeName = TTypeName<FMyType>;
constexpr FStringView TTypeName
Definition TypeName.h:131

It is useful in templates where a type name should be known in runtime as well. (e.g.: Modular features)

Remarks
Note on incomplete types: incomplete types on MSVC are localized to current scope. which means
class I;
class A
{
FStringView GetName() { return TTypeName<I>; }
// Returns "I"
}
BUT:
class A
{
FStringView GetName() { return TTypeName<class I>; }
// Returns "A::GetName::I"
}
as you can see they are not equal. For sake of simplicity TTypeName only supports incomplete types when they're declared in global scope. Any other case might yield undesired results (e.g.: TTypeName<class I> of incomplete I might not be the same as TTypeName somewhere else with I being fully defined)
Template Parameters
TThe type to be named

Definition at line 131 of file TypeName.h.

◆ TTypeNameStd

template<typename T >
FStdStringView Mcro::TypeName::TTypeNameStd = GetCompileTimeTypeName<std::decay_t<T>>()
constexpr
See also
TTypeName

Definition at line 138 of file TypeName.h.

◆ TTypeString

template<typename T >
const FString Mcro::TypeName::TTypeString = FString(TTypeName<T>.GetData(), TTypeName<T>.Len())
See also
TTypeName

Definition at line 146 of file TypeName.h.