Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here.

is_scalar Class

Tests if type is scalar.

template<class Ty>
    struct is_scalar;


The type to query.

An instance of the type predicate holds true if the type Ty is an integral type, a floating point type, an enumeration type, a pointer type, or a pointer to member type, or a cv-qualified form of one of them, otherwise it holds false.


// std_tr1__type_traits__is_scalar.cpp 
// compile with: /EHsc 
#include <type_traits> 
#include <iostream> 
struct trivial 
    int val; 
int main() 
    std::cout << "is_scalar<trivial> == " << std::boolalpha 
        << std::tr1::is_scalar<trivial>::value << std::endl; 
    std::cout << "is_scalar<trivial *> == " << std::boolalpha 
        << std::tr1::is_scalar<trivial *>::value << std::endl; 
    std::cout << "is_scalar<int> == " << std::boolalpha 
        << std::tr1::is_scalar<int>::value << std::endl; 
    std::cout << "is_scalar<float> == " << std::boolalpha 
        << std::tr1::is_scalar<float>::value << std::endl; 
    return (0); 
is_scalar<trivial> == false is_scalar<trivial *> == true is_scalar<int> == true is_scalar<float> == true

Header: <type_traits>

Namespace: std::tr1

Community Additions

© 2015 Microsoft