This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of C++20 status.

### 2783. `stack::emplace()` and `queue::emplace()` should return `decltype(auto)`

Section: 22.6.4.1 [queue.defn], 22.6.6.2 [stack.defn] Status: C++20 Submitter: Jonathan Wakely Opened: 2016-10-14 Last modified: 2021-02-25

Priority: 2

View all issues with C++20 status.

Discussion:

The `stack` and `queue` adaptors are now defined as:

>     template <class... Args>
>     reference emplace(Args&&... args) { return c.emplace_back(std::forward<Args>(args)...); }

This breaks any code using `queue<UserDefinedSequence>` or `stack<UserDefinedSequence>` until the user-defined containers are updated to meet the new C++17 requirements.

If we defined them as returning `decltype(auto)` then we don't break any code. When used with `std::vector` or `std::deque` they will return `reference`, as required, but when used with C++14-conforming containers they will return `void`, as before.

[2016-11-12, Issaquah]

Sat AM: P2

[2017-03-04, Kona]

Status to Tentatively Ready.

Proposed resolution:

This wording is relative to N4606.

1. Change return type of `emplace` in class definition in 22.6.4.1 [queue.defn]:

   >     template <class... Args>
   >       referencedecltype(auto) emplace(Args&&... args) { return c.emplace_back(std::forward<Args>(args)...); }

2. Change return type of `emplace` in class definition in 22.6.6.2 [stack.defn]:

   >     template <class... Args>
   >       referencedecltype(auto) emplace(Args&&... args) { return c.emplace_back(std::forward<Args>(args)...); }