Is Primitive Type Trait?

closed account (o1vk4iN6)
Is there a type trait in the standard library to check if a value is a primitive?

Something along the lines of:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

template<class T>
struct is_primitive
{ static const value = false; }

template<>
struct is_primitive<char>
{ static const value = true; }


template<>
struct is_primitive<int>
{ static const value = true; }

template<>
struct is_primitive<float>
{ static const value = true; }


// etc...


I haven't seen this, just to avoid conflicts with a standard if there is one.
how about template <typename T>? Won't the primitive types satisfy this one?

Nevermind, I see that you were just asking if your name will clash with one in std. I don't think so.

<typeinfo> has some interesting related stuff:
http://cplusplus.com/reference/std/typeinfo/type_info/

and there are some related functions in <limits>
http://cplusplus.com/reference/std/limits/numeric_limits/

But nothing that is the same.
Last edited on
Depends on your definition of "primitive". There is a trait for each official type category, yours looks like std::is_arithmetic so far. http://en.cppreference.com/w/cpp/types/is_arithmetic
Last edited on
std::is_fundamental is what you ask for.
@Stewbond: it does not matter whether you write class or typename, both will accept primitive types and class types and function signatures/pointers and member pointers, etc...
The only time you "need" to use typename is to identify nested dependent type names, otherwise they are interchangeable.
Topic archived. No new replies allowed.