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

Section: 26.6.4.1 [queue.defn], 26.6.6.1 [stack.defn] Status: WP Submitter: Jonathan Wakely Opened: 2016-10-14 Last modified: 2017-07-30

Priority: 2

View all issues with WP 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 26.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 26.6.6.1 [stack.defn]:

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