3

Which WG21 documents explain the decision not to include ref-qualifiers in most standard library classes?

An example that would benefit from such inclusion:

template <class C1, class C2>
C1 container_cast(C2&& source)
{
    C1 dest;
    // if constexpr(can do so) dest.reserve(source.size());
    for(auto&& element : std::forward<C2>(source))
    {
        dest.emplace_back(std::forward<decltype(element)>(element));
    }
    return dest;
}

However, no methods of accessing container members propagate rvalue-ness to them, causing unnecessary copies. This is in contrast to, for example, std::get(std::tuple) and std::optional::operator *, which do provide overloads of all kinds, including the oxymoronic “const &&”.

(Closely related to rvalue ref-qualifiers for STL containers, but the question is more specific.)

Roman Odaisky
  • 2,811
  • 22
  • 26
  • 1
    You would want a `make_move_container` which will calls `make_move_iterator` for `begin`/`end`? – Jarod42 Aug 26 '19 at 20:38
  • 1
    I can't speak to the intent of the comittee, but to me, the state in which the source container would find itself in if an exception was to be thrown from within that loop would be *weird*, at best. So I'm fine with `begin` and `end` not promoting to move_iterators by default, and requiring a bit more legwork in order to perform what you want. –  Aug 26 '19 at 20:56
  • @Frank, well, if the container was an rvalue, it means nobody expected anything more than destructibility of it. This postcondition is perfectly satisfied even if an exception is thrown (from something other than a move constructor of course). – Roman Odaisky Aug 26 '19 at 21:06
  • @RomanOdaisky Sure, but the fact remains that there is a period of time where the container is a mish-mash of regular and moved-out objects. Even if this container is **likely** (not even necessarily) only going to live during the stack unwinding, the fact that it's in that state outside of the loop is icky to me, and so I don't mind having a bit of friction around that. –  Aug 26 '19 at 21:11
  • @Frank I would like to find out what is icky to the Committee. Given that the result of calling std::remove_if on lvalues does not seem to be icky to them, I do not see a reason to suppose they care all that much about aesthetics of rvalue containers. – Roman Odaisky Aug 26 '19 at 21:25

0 Answers0