Type traits | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Compile-time rational arithmetic | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Compile-time integer sequences | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
(C++14) |
Defined in header <type_traits> | ||
template<class T> struct remove_reference; | (since C++11) | |
If the typeT
is a reference type, provides the member typedeftype
which is the type referred to byT
. Otherwisetype
isT
.
If the program adds specializations forstd::remove_reference
, the behavior is undefined.
Contents |
Name | Definition |
type | the type referred byT orT if it is not a reference |
template<class T> using remove_reference_t=typename remove_reference<T>::type; | (since C++14) | |
template<class T>struct remove_reference{typedef T type;};template<class T>struct remove_reference<T&>{typedef T type;};template<class T>struct remove_reference<T&&>{typedef T type;}; |
#include <iostream>#include <type_traits> int main(){std::cout<<std::boolalpha; std::cout<<"std::remove_reference<int>::type is int? "<<std::is_same<int, std::remove_reference<int>::type>::value<<'\n';std::cout<<"std::remove_reference<int&>::type is int? "<<std::is_same<int, std::remove_reference<int&>::type>::value<<'\n';std::cout<<"std::remove_reference<int&&>::type is int? "<<std::is_same<int, std::remove_reference<int&&>::type>::value<<'\n';std::cout<<"std::remove_reference<const int&>::type is const int? "<<std::is_same<constint, std::remove_reference<constint&>::type>::value<<'\n';}
Output:
std::remove_reference<int>::type is int? truestd::remove_reference<int&>::type is int? truestd::remove_reference<int&&>::type is int? truestd::remove_reference<const int&>::type is const int? true
(C++11) | checks if a type is either anlvalue reference orrvalue reference (class template)[edit] |
(C++11)(C++11) | adds anlvalue orrvalue reference to the given type (class template)[edit] |
(C++20) | combinesstd::remove_cv andstd::remove_reference (class template)[edit] |