std:: is_object
| Type traits | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Compile-time rational arithmetic | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Compile-time integer sequences | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
(C++14)
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
헤더 파일에 정의됨
<type_traits>
|
||
|
template
<
class
T
>
struct is_object ; |
(C++11부터) | |
std::is_object
는
UnaryTypeTrait
입니다.
만약
T
가
객체 타입
(즉, 함수, 참조, 또는
void
타입이 아닌 임의의 가능한 cv-한정 타입)인 경우, 멤버 상수
value
를
true
와 동일하게 제공합니다. 다른 모든 타입에 대해서는
value
가
false
입니다.
프로그램이
std::is_object
나
std::is_object_v
에 대한 특수화를 추가하는 경우, 그 동작은 정의되지 않습니다.
목차 |
템플릿 매개변수
| T | - | 확인할 타입 |
헬퍼 변수 템플릿
|
template
<
class
T
>
constexpr bool is_object_v = is_object < T > :: value ; |
(C++17부터) | |
std:: integral_constant 로부터 상속됨
멤버 상수
|
value
[static]
|
true
만약
T
가 객체 타입이면,
false
그렇지 않으면
(public static member constant) |
멤버 함수
|
operator bool
|
객체를
bool
로 변환,
value
반환
(public member function) |
|
operator()
(C++14)
|
value
반환
(public member function) |
멤버 타입
| 타입 | 정의 |
value_type
|
bool |
type
|
std:: integral_constant < bool , value > |
가능한 구현
template<class T> struct is_object : std::integral_constant<bool, std::is_scalar<T>::value || std::is_array<T>::value || std::is_union<T>::value || std::is_class<T>::value> {}; |
예제
#include <iomanip> #include <iostream> #include <type_traits> #define IS_OBJECT(...) \ std::cout << std::boolalpha << std::left << std::setw(9) << #__VA_ARGS__ \ << (std::is_object_v<__VA_ARGS__> ? " is object\n" \ : " is not an object\n") int main() { class cls {}; IS_OBJECT(void); IS_OBJECT(int); IS_OBJECT(int&); IS_OBJECT(int*); IS_OBJECT(int*&); IS_OBJECT(cls); IS_OBJECT(cls&); IS_OBJECT(cls*); IS_OBJECT(int()); IS_OBJECT(int(*)()); IS_OBJECT(int(&)()); }
출력:
void is not an object int is object int& is not an object int* is object int*& is not an object cls is object cls& is not an object cls* is object int() is not an object int(*)() is object int(&)() is not an object
참고 항목
|
(C++11)
|
타입이 스칼라 타입인지 확인합니다
(클래스 템플릿) |
|
(C++11)
|
타입이 배열 타입인지 확인합니다
(클래스 템플릿) |
|
(C++11)
|
타입이 공용체 타입인지 확인합니다
(클래스 템플릿) |
|
(C++11)
|
타입이 비공용체 클래스 타입인지 확인합니다
(클래스 템플릿) |