Defined in header <type_traits> | ||||
---|---|---|---|---|
| (since C++11) |
Provides the member typedef type
which is the type pointed to by T
, or, if T
is not a pointer, then type
is the same as T
.
Member types
Name | Definition |
---|---|
type | the type pointed to by T or T if it's not a pointer |
Helper types
| (since C++14) |
Possible implementation
|
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | #include <iostream> #include <type_traits> template < class T1, class T2> void print_is_same() { std::cout << std::is_same<T1, T2>() << '\n' ; } void print_separator() { std::cout << "-----\n" ; } int main() { std::cout << std::boolalpha; print_is_same< int , int >(); // true print_is_same< int , int *>(); // false print_is_same< int , int **>(); // false print_separator(); print_is_same< int , std::remove_pointer< int >::type>(); // true print_is_same< int , std::remove_pointer< int *>::type>(); // true print_is_same< int , std::remove_pointer< int **>::type>(); // false print_separator(); print_is_same< int , std::remove_pointer< int * const >::type>(); // true print_is_same< int , std::remove_pointer< int * volatile >::type>(); // true print_is_same< int , std::remove_pointer< int * const volatile >::type>(); // true } |
Output:
1 2 3 4 5 6 7 8 9 10 11 | true false false ----- true true false ----- true true true |
See also
(C++11) | checks if a type is a pointer type (class template) |
(C++11) | adds pointer to the given type (class template) |
Please login to continue.