Namespaces
Variants

std:: is_scalar

From cppreference.net
Metaprogramming library
Type traits
Type categories
(C++11)
(C++11) ( DR* )
(C++11)
is_scalar
(C++11)
Type properties
(C++11)
(C++11)
(C++14)
(C++11) (deprecated in C++26)
(C++11) ( until C++20* )
(C++11) (deprecated in C++20)
(C++11)
Type trait constants
Metafunctions
(C++17)
Supported operations
Relationships and property queries
Type modifications
Type transformations
(C++11) (deprecated in C++23)
(C++11) (deprecated in C++23)
(C++11)
(C++11) ( until C++20* ) (C++17)

Compile-time rational arithmetic
Compile-time integer sequences
헤더 파일에 정의됨 <type_traits>
template < class T >
struct is_scalar ;
(C++11부터)

std::is_scalar UnaryTypeTrait 입니다.

만약 T scalar type 라면, 멤버 상수 value true 로 제공합니다. 다른 모든 타입에 대해서는 value false 입니다.

프로그램이 std::is_scalar 또는 std::is_scalar_v 에 대한 특수화를 추가하는 경우, 그 동작은 정의되지 않습니다.

목차

템플릿 매개변수

T - 확인할 타입

헬퍼 변수 템플릿

template < class T >
constexpr bool is_scalar_v = is_scalar < 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 >

참고 사항

C++ 메모리 모델에서 각 개별 메모리 위치(예: 가상 테이블 포인터와 같은 언어 기능에 의해 사용되는 숨겨진 메모리 위치 포함)는 스칼라 타입을 가지거나(또는 길이가 0이 아닌 인접한 비트 필드들의 시퀀스입니다). 표현식 평가에서의 부수 효과 순서 지정, 스레드 간 동기화, 그리고 의존성 순서 지정은 모두 개별 스칼라 객체를 기준으로 정의됩니다.

가능한 구현

template<class T>
struct is_scalar : std::integral_constant<bool, std::is_arithmetic<T>::value
                                             || std::is_enum<T>::value
                                             || std::is_pointer<T>::value
                                             || std::is_member_pointer<T>::value
                                             || std::is_null_pointer<T>::value>
{};

예제

#include <iostream>
#include <type_traits>
#include <typeinfo>
#include <utility>
template<typename Head, typename... Tail>
void are_scalars(Head&& head, Tail&&... tail)
{
    using T = std::decay_t<decltype(head)>;
    std::cout << typeid(T).name() << " is "
              << (std::is_scalar_v<T> ? "" : "not ")
              << "a scalar\n";
    if constexpr (sizeof... (Tail))
    {
        are_scalars(std::forward<decltype(tail)>(tail)...);
    }
}
int main()
{
    struct S { int m; } s;
    int S::* mp = &S::m;
    enum class E { e };
    are_scalars(42, 3.14, E::e, "str", mp, nullptr, s);
}

가능한 출력:

int is a scalar
double is a scalar
main::E is a scalar
char const* is a scalar
int main::S::* is a scalar
nullptr is a scalar
main::S is not a scalar

참고 항목

타입이 산술 타입인지 검사합니다
(클래스 템플릿)
(C++11)
타입이 열거형 타입인지 검사합니다
(클래스 템플릿)
(C++11)
타입이 포인터 타입인지 검사합니다
(클래스 템플릿)
타입이 비정적 멤버 함수나 객체에 대한 포인터인지 검사합니다
(클래스 템플릿)