std::remove_reference
Материал из cppreference.com
Определено в заголовочном файле <type_traits>
|
||
template< class T > struct remove_reference; |
(начиная с C++11) | |
Если тип T
является ссылочным типом, предоставляет typedef элемент type
, на который ссылается T
, иначе type
будет типом T
.
Содержание |
[править] Типы-элементы
Имя | Определение |
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 это 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 (шаблон класса) |