Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::decay

      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
      Type transformations
      (C++11)(deprecated in C++23)
      (C++11)(deprecated in C++23)
      decay
      (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 decay;
      (since C++11)

      Performs the type conversions equivalent to the ones performed when passingfunction arguments by value. Formally:

      • IfT is “array ofU” or reference to it, the member typedeftype isU*.
      • Otherwise, ifT is a function typeF or reference to one, the member typedeftype isstd::add_pointer<F>::type.

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

      Contents

      [edit]Member types

      Name Definition
      type the result of applying the decay type conversions toT

      [edit]Helper types

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

      [edit]Possible implementation

      template<class T>struct decay{private:typedeftypenamestd::remove_reference<T>::type U;public:typedeftypenamestd::conditional<std::is_array<U>::value,typenamestd::add_pointer<typenamestd::remove_extent<U>::type>::type,typenamestd::conditional<std::is_function<U>::value,typenamestd::add_pointer<U>::type,typenamestd::remove_cv<U>::type>::type>::type type;};

      [edit]Example

      Run this code
      #include <type_traits> template<typename T,typename U>constexprbool is_decay_equ=std::is_same_v<std::decay_t<T>, U>; static_assert(    is_decay_equ<int,int>&&! is_decay_equ<int,float>&&    is_decay_equ<int&,int>&&    is_decay_equ<int&&,int>&&    is_decay_equ<constint&,int>&&    is_decay_equ<int[2],int*>&&! is_decay_equ<int[4][2],int*>&&! is_decay_equ<int[4][2],int**>&&    is_decay_equ<int[4][2],int(*)[2]>&&    is_decay_equ<int(int),int(*)(int)>); int main(){}

      [edit]See also

      combinesstd::remove_cv andstd::remove_reference
      (class template)[edit]
      implicit conversion array-to-pointer, function-to-pointer, lvalue-to-rvalue conversions
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/types/decay&oldid=182067"

      [8]ページ先頭

      ©2009-2025 Movatter.jp