Defined in header <type_traits> | ||||
---|---|---|---|---|
| (since C++11) |
If the type T
is a reference type, provides the member typedef type
which is the type referred to by T
. Otherwise type
is T
.
Member types
Name | Definition |
---|---|
type | the type referred by T or T if it is not a reference |
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 | #include <iostream> // std::cout #include <type_traits> // std::is_same template < class T1, class T2> void print_is_same() { std::cout << std::is_same<T1, T2>() << '\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_is_same< int , std::remove_reference< int >::type>(); // true print_is_same< int , std::remove_reference< int &>::type>(); // true print_is_same< int , std::remove_reference< int &&>::type>(); // true } |
Output:
1 2 3 4 5 6 | true false false true true true |
See also
(C++11) | checks if a type is either lvalue reference or rvalue reference (class template) |
(C++11)(C++11) | adds lvalue or rvalue reference to the given type (class template) |
Please login to continue.