Title
stack::emplace() and queue::emplace() should return decltype(auto)
Status
c++20
Section
[queue.defn][stack.defn]
Submitter
Jonathan Wakely

Created on 2016-10-14.00:00:00 last changed 46 months ago

Messages

Date: 2017-03-14.03:14:09

Proposed resolution:

This wording is relative to N4606.

  1. Change return type of emplace in class definition in [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 [stack.defn]:

    template <class... Args>
      referencedecltype(auto) emplace(Args&&... args) { return c.emplace_back(std::forward<Args>(args)...); }
    
Date: 2017-03-15.00:00:00

[ 2017-03-04, Kona ]

Status to Tentatively Ready.

Date: 2016-11-15.00:00:00

[ 2016-11-12, Issaquah ]

Sat AM: P2

Date: 2016-10-14.00:00:00

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.

History
Date User Action Args
2021-02-25 10:48:01adminsetstatus: wp -> c++20
2017-07-30 20:18:47adminsetstatus: voting -> wp
2017-06-26 13:46:20adminsetstatus: ready -> voting
2017-03-14 03:14:09adminsetmessages: + msg9105
2017-03-14 03:14:09adminsetstatus: new -> ready
2016-11-21 05:09:01adminsetmessages: + msg8666
2016-10-15 13:03:26adminsetmessages: + msg8565
2016-10-14 00:00:00admincreate