◐ Shell
clean mode source ↗

std::remove_reference - cppreference.com

提供: cppreference.com

<tbody> </tbody>

template< class T > struct remove_reference;

(C++11以上)

T が参照型であれば、 T の参照先の型であるメンバ型 type が提供されます。 そうでなければ typeT です。

メンバ型

名前 定義
type T の参照先の型、または 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> // std::cout
#include <type_traits> // std::is_same

template<class T1, class T2>
void print_is_same() {
  std::cout << std::is_same<T1, T2>() << '\n';
}

int main() {
  std::cout << std::boolalpha;

  print_is_same<int, int>();
  print_is_same<int, int &>();
  print_is_same<int, int &&>();

  print_is_same<int, std::remove_reference<int>::type>();
  print_is_same<int, std::remove_reference<int &>::type>();
  print_is_same<int, std::remove_reference<int &&>::type>();
}

出力:

true
false
false
true
true
true

関連項目