The specification of std::decay in N4296 leaves the following note:
[ 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 ]
It seems to me that ideally std::decay would model by-value argument passing exactly, but for some reason it's not defined that way.
I think it could be defined in terms of template argument deduction in which case the implementation could also be defined to leverage template argument deduction to exactly model by-value argument passing.
template <typename T>
struct decay {
private:
template <typename U>
static U impl(U);
public:
using type = decltype(impl(std::declval<T>()));
};
Questions:
- What are the differences between
std::decayand by-value argument passing? - Is
std::decaydesigned to not model by-value argument passing exactly? - Would the implementation above model it exactly?
Aucun commentaire:
Enregistrer un commentaire