Title
Container adapters mandate use of emplace_back but don't require it
Status
new
Section
[stack] [queue]
Submitter
Marshall Clow

Created on 2018-10-02.00:00:00, last changed 2018-10-02.17:25:26.

Messages

Date: 2018-10-06.11:12:02

Proposed resolution:

This wording is relative to N4762.

I have prepared two mutually exclusive options.
Option A a requirement for emplace_back to the underlying container.
Option B one replaces the calls to emplace_back with calls to emplace.

Option A

  1. Edit [stack], as indicated:

    Any sequence container supporting operations back(), push_back(), emplace_back() and pop_back() can be used to instantiate stack.

  2. Edit [queue.defn], as indicated:

    Any sequence container supporting operations front(), back(), push_back(), emplace_back() and pop_front() can be used to instantiate queue.

Option B

  1. Edit [stack.defn], class template stack definition, as indicated:

    template<class... Args>
      decltype(auto) emplace(Args&&... args)
        { return c.emplace_back(c.end(), std::forward<Args>(args)...); }
    
  2. Edit [queue.defn], class template queue definition, as indicated:

    template<class... Args>
      decltype(auto) emplace(Args&&... args)
        { return c.emplace_back(c.end(), std::forward<Args>(args)...); }
    
Date: 2018-10-06.11:12:02

[stack] p1 says:

Any sequence container supporting operations back(), push_back() and pop_back() can be used to instantiate stack.

but then in [stack.defn] we have the following code:

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

The same pattern appears in [queue].

I see two ways to resolve this:

The first is to add emplace_back() to the list of requirements for underlying containers for stack and queue

The second is to replace the calls to c.emplace_back(std::forward<Args>(args)...) with c.emplace(c.end(), std::forward<Args>(args)...). We can do this w/o messing with the list above because emplace is part of the sequence container requirements, while emplace_back is not. I checked the libc++ implementation of vector, deque, and list, and they all do the same thing for emplace(end(), ...) and emplace_back(...).

History
Date User Action Args
2018-10-02 17:25:26adminsetmessages: + msg10155
2018-10-02 00:00:00admincreate