The P0849 paper adds the auto(x)
expression to the language to enable perfect forwarding. This is needed because the decay_copy
function, shown below, cannot perfect forward parameters declared with a universal/forwarding reference.
template<class T>
constexpr decay_t<T> decay_copy(T&& v) noexcept(
is_nothrow_convertible_v<T, decay_t<T>>) {
return std::forward<T>(v);
}
An issue arises when using decay_copy(x.front())
: even if x.front()
is a prvalue
(a temporary object), it will be copied and not perfectly forwarded.