Created on 2018-10-02.00:00:00 last changed 55 months ago
Proposed resolution:
This wording is relative to N4861.
Edit [stack.defn], class template stack definition, as indicated:
template<class... Args> decltype(auto) emplace(Args&&... args) { if constexpr (requires { c.emplace_back(std::forward<Args>(args)...); }) { return c.emplace_back(std::forward<Args>(args)...); } else { return c.emplace(c.end(), std::forward<Args>(args)...); } }
Edit [queue.defn], class template queue definition, as indicated:
template<class... Args> decltype(auto) emplace(Args&&... args) { if constexpr (requires { c.emplace_back(std::forward<Args>(args)...); }) { return c.emplace_back(std::forward<Args>(args)...); } else { return c.emplace(c.end(), std::forward<Args>(args)...); } }
[ 2020-05-09; Reflector prioritization ]
Set priority to 3 after reflector discussions.
[ 2020-05 Casey provides new wording ]
This is the "probe for emplace_back with fallback to emplace" approach that LWG wanted to see wording for in Kona.
[ 2019-02; Kona Wednesday night issue processing ]
Status to Open; Casey to provide updated wording, and re-vote on reflector.
Polls were: NAD - 5-1-3; "Option B" - 2-5-2 and "Probe the container" - 7-2-0
Previous resolution [SUPERSEDED]: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
Edit [stack], as indicated:
Any sequence container supporting operations back(), push_back(), emplace_back() and pop_back() can be used to instantiate stack.
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
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)...); }
[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 |
2020-05-09 19:18:02 | admin | set | messages: + msg11273 |
2020-05-04 23:20:54 | admin | set | messages: + msg11271 |
2019-02-21 17:23:36 | admin | set | messages: + msg10319 |
2019-02-21 17:23:36 | admin | set | status: new -> open |
2018-10-02 17:25:26 | admin | set | messages: + msg10155 |
2018-10-02 00:00:00 | admin | create |