Reference : TEnableIf | Unreal Engine Documentation
TEnableIf
Includes a function in an overload set if the predicate is true.
docs.unrealengine.com
template <bool Predicate, typename Result = void>
class TEnableIf { }
template <typename Result>
class TEnableIf<true, Result>
{
public :
typedef Result type;
}
Unreal 코드 내부를 보다보면 종종 마주치는 TEnableIf
std::enable_if와 동일한 역할을 한다.
std::enable_if - cppreference.com
std::enable_if - cppreference.com
template< bool B, class T = void > struct enable_if; (since C++11) If B is true, std::enable_if has a public member typedef type, equal to T; otherwise, there is no member typedef. This metafunction is a convenient way to leverage SFINAE to conditionally r
en.cppreference.com
Predicate하면 C#의 미리 정의된 delegate template Predicate<T>가 생각이 난다.
Predicate<T>는 template인자를 받아 bool 타입을 반환하는 delegate 타입이다. LINQ에서 많이 사용한다.
마찬가지로 TEnableIf의 Predicate 또한 bool 타입으로 정의되어 있다.
기본적으로 TEnableIf는 Result 타입에 대한 type aliasing을 제공하지 않고, Predicate가 true인 템플릿 특수화 버전에서만 Result 타입을 제공해주고 있다. 따라서 Predicate가 false인 경우 컴파일 타임에 에러를 유발해주는 역할을 한다.
쉽게 이해하면 C# Generic의 where문 같은 역할을 해준다고 보면 될 것 같다.
[TR1/C++11] enable_if
1. enable_if enable_if 는 헤더에 포함되어 있으며, TR1에 릴리즈 되어 VS2010부터 사용 가능하다. 우선, enable_if 의 정의를 살펴보자. template struct enable_if{ // 기본적으
egloos.zum.com
'프로그래밍 > Unreal' 카테고리의 다른 글
[Unreal] 클래스의 Prefix를 F로 사용하는 이유. (0) | 2022.05.01 |
---|---|
Unreal의 스레드와 단일 스레드로 실행시키기 (-norenderthread) (0) | 2022.04.06 |
UE4 -waitforattach (0) | 2022.03.30 |
GetTypeHash의 구현 (0) | 2021.02.23 |
Unreal Engine의 저작권 (0) | 2020.11.24 |