
<type_traits> 헤더는 유틸리티를 제공함.
Traits | Effect |
is_void<T> | void |
is_integral<T> | int류, bool, char, char16, char32_t, wchar_t |
it_array<T> | 내장 배열형, std::array는 클래스 형임 |
is_pointer<T> | 포인터형, 함수 포인터 포함, static 들어간 멤버 함수 포인터 |
is_null_pointer<T> | nullptr 형식 |
is_member_object_pointer<T> | non-static 멤버 |
is_member_function_pointer<T> | non-static 멤버 함수 포인터 |
is_lvalue_reference<T> | lvalue 레퍼런스 |
is_rvalue_reference<T> | rvalue 레퍼런스 |
is_enum<T> | 열거형 |
is_class<T> | 클래스/구조체 |
is_union<T> | 공용체 |
is_function<T> | 함수형 |
std::is_void<T>
is_void<void> //참
is_void_v<void> //참
is_void_v<int> //거짓
void f();
is_void<decltype(f)> //거짓
is_void_v<decltype(f())> //참, f()의 반환형이 void 이기 때문
std::array<T>
is_array<int[]> // 참
is_array<int[5]> // 참
is_array<int*> //거짓
void foo(int[], int b[5], int*){
is_array_v<decltype(a)> // 거짓(int*)
is_array_v<decltype(b)> // 거짓(int*)
is_array_v<decltype(c)> // 거짓(int*)
}
std::is_pointer<T>
is_pointer_v<int> // 거짓
is_pointer_v<int*> // 참
is_pointer_v<int* const> // 참
is_pointer_v<int*&> // 거짓
is_pointer_v<decltype(nullptr)> // 거짓
int* foo(int a[5], void(f)){
is_pointer_v<decltype(a)> //참, a는 int*
is_pointer_v<decltype(f)> //참, f는 void(*)()
is_pointer_v<decltype(foo)> //거짓
is_pointer_v<decltype(&foo)> //참
is_pointer_v<decltype(foo(a, f))> //참, 반환형(int*)
}
std::is_lvalue_reference<T>
std::is_rvalue_reference<T>
is_lvalue_reference<int> // 거짓
is_lvalue_reference<int&> // 참
is_lvalue_reference<int&&> // 거짓
is_lvalue_reference<void> // 거짓
is_rvalue_reference<int> // 거짓
is_rvalue_reference<int&> // 거짓
is_rvalue_reference<int&&> // 참
is_rvalue_reference<void> // 거짓
std::is_class<T>
is_class_v<int> // 거짓
is_class_v<std::string> // 참
is_class_v<std::string const> // 참
is_class_v<std::string> // 거짓
auto lambda = []{};
is_class_v<decltype(lambda)> // 참, 람다는 사실 클래스 객체임!!
'C++' 카테고리의 다른 글
Type Category Testing_2(형 카 검-컴포지트 타입) (0) | 2022.07.04 |
---|---|
Template 가이드라인 (0) | 2022.07.04 |
[C++] Return Value Optimization(RVO) (0) | 2021.01.04 |
std::exception과 Stack Unwinding 과 RAII (0) | 2020.12.04 |
[레거시 코드] 함수포인터, 보이드포인터 (0) | 2020.12.03 |