BDE 4.14.0 Production release
|
Convert a type to the type used for pass-by-value.
bsl::decay
meta-functionThis component provides a metafunction, bsl::decay
, that applies array-to-pointer and function-to-pointer conversion and cv-qualification removal to a type, thus modeling the decay of an argument type when passed by-value into a function. bsl::decay
provides identical functionality to the C++11 standard metafunction std::decay
. From the C++14, standard description of std::decay
:
Let U
be remove_reference_t<T>
. If is_array<U>::value
is true
, the member typedef type
shall equal remove_extent_t<U>*
. If is_function<U>::value
is true
, the member typedef type
shall equal add_pointer_t<U>
. Otherwise the member typedef type
equals remove_cv_t<U>
. [ Note: This behavior is similar to the lvalue-to-rvalue (4.1), array-to-pointer (4.2), and function-to-pointer (4.3) conversions applied when an lvalue expression is used as an rvalue, but also strips cv-qualifiers from class types in order to more closely model by-value argument passing. - end note ]
A class template needs to cache a value of type T
. There is nothing in the definition of the class that would prevent it from working for T
of function type or array-of-unknown bound, but one cannot simply declare a member of either of those types. Instead, we use bsl::decay<T>::type
, which can be stored, copied, and compared as needed:
Note that if the current compiler supports alias templates C++11 feature, we can use bsl::decay_t
alias to the "result" type of the bsl::decay
meta-function, that avoids the ::type
suffix and typename
prefix in the declaration of the function return type:
Now verify that for function and array types, cache()
will return a simple pointer: