Namespaces
Variants

std:: remove_reference

From cppreference.net
Metaprogramming library
Type traits
Type categories
(C++11)
(C++11) ( DR* )
Type properties
(C++11)
(C++11)
(C++14)
(C++11) (deprecated in C++26)
(C++11) ( until C++20* )
(C++11) (deprecated in C++20)
(C++11)
Type trait constants
Metafunctions
(C++17)
Supported operations
Relationships and property queries
Type modifications
Type transformations
(C++11) (deprecated in C++23)
(C++11) (deprecated in C++23)
(C++11)
(C++11) ( until C++20* ) (C++17)

Compile-time rational arithmetic
Compile-time integer sequences
헤더 파일에 정의됨 <type_traits>
template < class T >
struct remove_reference ;
(C++11부터)

타입 T 가 참조 타입인 경우, T 가 참조하는 타입인 type 멤버 typedef를 제공합니다. 그렇지 않은 경우 type T 입니다.

프로그램이 std::remove_reference 에 대한 특수화를 추가하는 경우, 동작은 정의되지 않습니다.

목차

멤버 타입

이름 정의
type T 가 참조하는 타입 또는 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

참고 항목

해당 타입이 lvalue reference 또는 rvalue reference 인지 검사합니다
(class template)
주어진 타입에 lvalue 또는 rvalue reference를 추가합니다
(class template)
std::remove_cv std::remove_reference 를 결합합니다
(class template)