On this page
std::remove_reference
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
.
The behavior of a program that adds specializations for std::remove_reference
is undefined.
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
#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
(C++11)
|
checks if a type is either an lvalue reference or rvalue reference (class template) |
(C++11)(C++11)
|
adds an lvalue or rvalue reference to the given type (class template) |
(C++20)
|
combines std::remove_cv and std::remove_reference (class template) |
© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
https://en.cppreference.com/w/cpp/types/remove_reference