4 ms·
`std::remove_if` only takes two iterator arguments, and it's too ad hoc in exactly the same way Ruby's `reject!` is too ad hoc: it's the result of specializing
by catnaroek 10y ago
`std::remove_if` only takes two iterator arguments, and it's too ad hoc in exactly the same way Ruby's `reject!` is too ad hoc: it's the result of specializing `std::copy_if` to the case when the zeroth and second iterator arguments agree.
- smitherfield 10y agoMy mistake; I read about it (http://en.cppreference.com/w/cpp/algorithm/remove http://en.cppreference.com/w/cpp/algorithm/remove) too fast and thought it was the simple inverse of copy. I wasn't aware of it before this thread. In the unlikely event some future reader is copy-pasting these snippets, here's the corrected version: const auto last{ std::remove_if(vec.begin(), vec.end(), [](const auto x) { return x <= 2; }) }; vec.resize(last - vec.cbegin());
- marvy 10y agoremove_if is a convenience method; for full generality you can use remove_copy_if. I don't see how any of this allows you to achieve your idea of two independent containers backed by the same storage and thereby eliminate the extra step of calling resize.