std::remove_reference - cppreference.com (original) (raw)

| | | | | ---------------------------------------------- | | ------------- | | 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.

If the program adds specializations for std::remove_reference, the behavior 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 struct remove_reference { typedef T type; }; template struct remove_reference<T&> { typedef T type; }; template struct remove_reference<T&&> { typedef T type; };

[edit] Example

#include #include   int main() { std::cout << std::boolalpha;   std::cout << "std::remove_reference::type is int? " << std::is_same<int, std::remove_reference::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::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