# decay-copy

> C++ Atlas: `cppatlas.com/w/cpp/standard_library/decay-copy` | Source: https://en.cppreference.com/w/cpp/standard_library/decay-copy | Domain: Standard library | Standards: C++11, C++20

Returns std::forward<T>(value) (implicitly converted to the decayed type), a decayed prvalue copy of value.

## Official Specification Summary (cppreference)

```cpp
template< class T >
typename std::decay<T>::type decay-copy( T&& value ); // (since C++11) (until C++20) (exposition only*)

template< class T >
    requires std::convertible_to<T, std::decay_t<T>>
constexpr std::decay_t<T> decay-copy( T&& value )
    noexcept(std::is_nothrow_convertible_v<T, std::decay_t<T>>); // (since C++20) (exposition only*)
```

Returns `std::forward<T>(value)` (implicitly converted to the decayed type), a decayed prvalue copy of `value`.

### Parameters

- `value` - the value to be copied

### Return value

A decayed copy of `value` as a prvalue.

### Notes

`decay-copy` was introduced by the resolution of LWG issue 929. It is initially used in the concurrency support library to ensure that arguments are decayed when passing-by-value, and is later used in the ranges library.

The language feature `auto(x)` introduced in C++23 also allows decayed copies to be created as prvalues. The only difference is that `decay-copy` always materializes `value` and produces a copy, while `auto(expr)` is a no-op if `expr` is a prvalue.

All usages of `decay-copy` in the standard library (see below) except `views::all`, `ranges::take_view` and `ranges::drop_view` are replaced with `auto(x)` since C++23.

### Defect reports

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 |

### See also

- [(constructor)](https://en.cppreference.com/w/cpp/thread/thread/thread): constructs new `thread` object (public member function of `std::thread`)
- [(constructor)](https://en.cppreference.com/w/cpp/thread/jthread/jthread): constructs new `jthread` object (public member function of `std::jthread`)
- [`async`](https://en.cppreference.com/w/cpp/thread/async) (C++11): runs a function asynchronously (potentially in a new thread) and returns a `std::future` that will hold the result (function template)
- [`ranges::begin`](https://en.cppreference.com/w/cpp/ranges/begin) (C++20): returns an iterator to the beginning of a range (customization point object)
- [`ranges::end`](https://en.cppreference.com/w/cpp/ranges/end) (C++20): returns a sentinel indicating the end of a range (customization point object)
- [`ranges::rbegin`](https://en.cppreference.com/w/cpp/ranges/rbegin) (C++20): returns a reverse iterator to a range (customization point object)
- [`ranges::rend`](https://en.cppreference.com/w/cpp/ranges/rend) (C++20): returns a reverse end iterator to a range (customization point object)
- [`ranges::size`](https://en.cppreference.com/w/cpp/ranges/size) (C++20): returns an integer equal to the size of a range (customization point object)
- [`ranges::data`](https://en.cppreference.com/w/cpp/ranges/data) (C++20): obtains a pointer to the beginning of a contiguous range (customization point object)
- [`views::all_t`](https://en.cppreference.com/w/cpp/ranges/all_view) (C++20), [`views::all`](https://en.cppreference.com/w/cpp/ranges/all_view): a `view` that includes all elements of a `range` (alias template) (range adaptor object)
- [`ranges::take_view`](https://en.cppreference.com/w/cpp/ranges/take_view) (C++20), [`views::take`](https://en.cppreference.com/w/cpp/ranges/take_view): a `view` consisting of the first N elements of another `view` (class template) (range adaptor object)
- [`ranges::drop_view`](https://en.cppreference.com/w/cpp/ranges/drop_view) (C++20), [`views::drop`](https://en.cppreference.com/w/cpp/ranges/drop_view): a `view` consisting of elements of another `view`, skipping the first N elements (class template) (range adaptor object)

---
Attribution: content from https://en.cppreference.com/w/cpp/standard_library/decay-copy (cppreference.com), licensed under CC-BY-SA 3.0 and GFDL. Modified: converted to markdown, study notes added. Offline snapshot of 9 February 2025.