| Customization point object(C++20) | ||||
| Exposition-only entities | ||||
decay-copy (C++11) | ||||
(C++20)(C++20) |
template<class T> typenamestd::decay<T>::type decay-copy( T&& value); | (since C++11) (until C++20) (exposition only*) | |
template<class T> requiresstd::convertible_to<T,std::decay_t<T>> | (since C++20) (exposition only*) | |
Returnsstd::forward<T>(value) (implicitly converted to the decayed type), a decayed prvalue copy ofvalue.
Contents |
| value | - | the value to be copied |
A decayed copy ofvalue as a prvalue.
decay-copy was introduced by the resolution ofLWG issue 929. It is initially used in theconcurrency support library to ensure that arguments are decayed when passing-by-value, and is later used in theranges library.
The language featureauto(x) introduced in C++23 also allows decayed copies to be created as prvalues. The only difference is thatdecay-copy alwaysmaterializesvalue and produces a copy, whileauto(expr) is a no-op ifexpr is a prvalue.
All usages ofdecay-copy in the standard library (see below) exceptviews::all,ranges::take_view andranges::drop_view are replaced withauto(x) since C++23.
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
| DR | Applied to | Behavior as published | Correct behavior |
|---|---|---|---|
| LWG 3724 | C++20 | decay-copy was not constrained | constrained |
constructs newthread object(public member function of std::thread)[edit] | |
constructs newjthread object(public member function of std::jthread)[edit] | |
(C++11) | runs a function asynchronously (potentially in a new thread) and returns astd::future that will hold the result (function template)[edit] |
(C++20) | returns an iterator to the beginning of a range (customization point object)[edit] |
(C++20) | returns a sentinel indicating the end of a range (customization point object)[edit] |
(C++20) | returns a reverse iterator to a range (customization point object)[edit] |
(C++20) | returns a reverse end iterator to a range (customization point object)[edit] |
(C++20) | returns an integer equal to the size of a range (customization point object)[edit] |
(C++20) | obtains a pointer to the beginning of a contiguous range (customization point object)[edit] |
(C++20) | aview that includes all elements of arange(alias template)(range adaptor object)[edit] |
(C++20) | aview consisting of the first N elements of anotherview(class template)(range adaptor object)[edit] |
(C++20) | aview consisting of elements of anotherview, skipping the first N elements(class template)(range adaptor object)[edit] |