< cpp‎ | types
Metaprogramming library
Type traits
Type categories
Type properties
(C++11)(until C++20)
(C++11)(deprecated in C++20)
Type trait constants
Supported operations
Relationships and property queries
Type modifications

Type transformations
(C++11)(deprecated in C++23)
(C++11)(deprecated in C++23)

(C++11)(until C++20)(C++17)
Compile-time rational arithmetic
Compile-time integer sequences
Defined in header <type_traits>
template< class T >
struct remove_reference;
(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.

The behavior of a program that adds specializations for remove_reference is undefined.


[edit] Member types

Name Definition
type the type referred by T or T if it is not a reference

[edit] Helper types

template< class T >
using remove_reference_t = typename remove_reference<T>::type;
(since C++14)

[edit] 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; };

[edit] Example

#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';


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

[edit] See also

checks if a type is either a lvalue reference or rvalue reference
(class template) [edit]
adds a lvalue or rvalue reference to the given type
(class template) [edit]
combines std::remove_cv and std::remove_reference
(class template) [edit]