std::remove_reference
Определён в заголовочном файле <type_traits> | ||
|---|---|---|
template< class T > struct remove_reference; | (начиная с C++11) |
Если тип T является ссылочным типом, предоставляет тип-член type, который является типом, на который ссылается T. В противном случае type — это T.
Если программа добавляет специализации для std::remove_reference, поведение не определено.
Типы-члены
| Имя | Описание |
|---|---|
type | тип, на который ссылается T, или T, если это не ссылка |
Вспомогательные типы
template< class T > using remove_reference_t = typename remove_reference<T>::type; | (начиная с 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<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
См. также
|
(C++11) | проверяет, является ли тип ссылкой на lvalue или ссылкой на rvalue (шаблон класса) |
|
(C++11)(C++11) | добавляет к заданному типу ссылку на lvalue или rvalue (шаблон класса) |
|
(C++20) | объединяет std::remove_cv и std::remove_reference (шаблон класса) |
|
(C++26) | удаляет ссылку из отражённого типа (функция) |
© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
https://en.cppreference.com/cpp/types/remove_reference