Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::remove_reference

      From cppreference.com
      <cpp‎ |types
       
       
      Metaprogramming library
      Type traits
      Type categories
      (C++11)
      (C++11)(DR*)
      (C++11)
      (C++11)
      (C++11)
      (C++11)
      (C++11)
      (C++11) 
      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
      remove_reference
      (C++11)

      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
       
      Defined in header<type_traits>
      template<class T>
      struct remove_reference;
      (since C++11)

      If the typeT is a reference type, provides the member typedeftype which is the type referred to byT. Otherwisetype isT.

      If the program adds specializations forstd::remove_reference, the behavior is undefined.

      Contents

      [edit]Member types

      Name Definition
      type the type referred byT orT if it is not a reference

      [edit]Helper types

      template<class T>
      using remove_reference_t=typename remove_reference<T>::type;
      (since C++14)

      [edit]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;};

      [edit]Example

      Run this code
      #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<constint,                              std::remove_reference<constint&>::type>::value<<'\n';}

      Output:

      std::remove_reference<int>::type is int? truestd::remove_reference<int&>::type is int? truestd::remove_reference<int&&>::type is int? truestd::remove_reference<const int&>::type is const int? true

      [edit]See also

      checks if a type is either anlvalue reference orrvalue reference
      (class template)[edit]
      adds anlvalue orrvalue reference to the given type
      (class template)[edit]
      combinesstd::remove_cv andstd::remove_reference
      (class template)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/types/remove_reference&oldid=152487"

      [8]ページ先頭

      ©2009-2025 Movatter.jp