Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- template <class InIt, class Pred>
- InIt stable_partition(InIt Begin, InIt end, Pred p) {
- using val = std::iterator_traits<InIt>::value_type;
- std::vector<val> failed;
- InIt dest = Begin;
- for (InIt src = Begin; src != end; ++src)
- if (p(*src))
- * dest++ = std::move(*src);
- else
- failed.push_back(std::move(*src));
- auto ret = dest;
- for (auto const& f : failed)
- * dest++ = f;
- return ret;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement