table of contents
- Tumbleweed 2026.11.13-1.1
- Leap-16.0
- Leap-15.6
| std::remove_reference(3) | C++ Standard Libary | std::remove_reference(3) |
NAME¶
std::remove_reference - std::remove_reference
Synopsis¶
Defined in header <type_traits> template< class T > (since C++11) struct remove_reference;
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.
If the program adds specializations for std::remove_reference, the behavior is undefined.
Member types¶
Name Definition type the type referred by T or T if it is not a reference
Helper types¶
template< class T > (since C++14) using remove_reference_t = typename remove_reference<T>::type;
Possible implementation¶
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; };
Example¶
// Run this code
#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<const int,
std::remove_reference<const int&>::type>::value << '\n';
}
Output:¶
std::remove_reference<int>::type is int? true std::remove_reference<int&>::type is int? true std::remove_reference<int&&>::type is int? true std::remove_reference<const int&>::type is const int? true
See also¶
is_reference checks if a type is either an lvalue reference or rvalue reference (C++11) (class template) add_lvalue_reference add_rvalue_reference adds an lvalue or rvalue reference to the given type (C++11) (class template) (C++11) remove_cvref combines std::remove_cv and std::remove_reference (C++20) (class template)
| 2026.11.10 | http://cppreference.com |