types_remove_reference
types_remove_reference (참조형을 제거하는 타입 특성)
이 페이지에서는 C++ 표준 라이브러리의 std::remove_reference 타입 특성에 대해 알아볼게요. 이 템플릿은 주어진 타입이 참조형일 때 그 참조를 제거한 실제 타입을 제공해요. 참조형이 아니라면 원래 타입을 그대로 유지해요.
출처: cppreference
본문
정의와 설명
<type_traits> 헤더에 정의됨 |
||
|---|---|---|
template < class T > struct remove_reference; |
(C++11부터) |
타입 T가 참조형이면, 멤버 typedef type은 T가 참조하는 타입이 돼요. 그렇지 않으면 type은 T예요.
프로그램에서 std::remove_reference에 대한 특수화를 추가하면 동작이 정의되지 않아요.
멤버 타입 (Member types)
| 이름 | 설명 |
|---|---|
type |
T가 참조형이면 T가 참조하는 타입, 아니면 T |
헬퍼 타입 (Helper types)
template < class T > using remove_reference_t = typename remove_reference<T>::type; |
(C++14부터) |
|---|
가능한 구현 (Possible implementation)
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 ; };
예제 (Example)
#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
같이 보기 (See also)
is_reference (C++11) |
타입이 lvalue 참조 또는 rvalue 참조인지 확인해요 (클래스 템플릿) |
|---|---|
add_lvalue_reference add_rvalue_reference (C++11) (C++11) |
주어진 타입에 lvalue 또는 rvalue 참조를 추가해요 (클래스 템플릿) |
remove_cvref (C++20) |
std::remove_cv와 std::remove_reference를 결합해요 (클래스 템플릿) |
remove_reference (C++26) |
반영된 타입에서 참조를 제거해요 (함수) |