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-02.17:25:26

Proposed resolution:

This wording is relative to N4762.

  • 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)...); }
    
  • 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-02.17:31:24
[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].

The calls to c.emplace_back(std::forward<Args>(args)...) should be replaced 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.

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