◐ Shell
clean mode source ↗

std::remove_reference — cppreference.com

Материал из cppreference.com

<tbody> </tbody>

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

Смотрите также