std::remove_reference
Материал из cppreference.com
<tbody>
</tbody>
| Определено в заголовочном файле <type_traits>
|
||
template< class T > struct remove_reference; |
(начиная с C++11) | |
Если тип T является ссылочным типом, предоставляет typedef элемент type, на который ссылается T, иначе type будет типом T.
Типы-элементы
| Имя | Определение |
type
|
тип, на который ссылается T, или T, если это была не ссылка
|
Вспомогательные типы
<tbody> </tbody> 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 это int? "
<< std::is_same<int, std::remove_reference<int>::type>::value << '\n';
std::cout << "std::remove_reference<int&>::type это int? "
<< std::is_same<int, std::remove_reference<int&>::type>::value << '\n';
std::cout << "std::remove_reference<int&&>::type это int? "
<< std::is_same<int, std::remove_reference<int&&>::type>::value << '\n';
std::cout << "std::remove_reference<const int&>::type это const int? "
<< std::is_same<const int,
std::remove_reference<const int&>::type>::value << '\n';
}
Вывод:
std::remove_reference<int>::type это int? true
std::remove_reference<int&>::type это int? true
std::remove_reference<int&&>::type это int? true
std::remove_reference<const int&>::type это const int? true
Смотрите также
(C++11) |
проверяет, является ли тип либо левосторонней ссылкой, либо правосторонней ссылкой (шаблон класса) |
(C++11)(C++11) |
добавляет левостороннюю или правостороннюю ссылку к данному типу (шаблон класса) |
(C++20) |
объединяет std::remove_cv и std::remove_reference (шаблон класса) |