Advertisement
jack06215

[c++] iter by index

Jul 7th, 2020
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.46 KB | None | 0 0
  1. // position is the std::vector<int> of index position
  2. // src.erase(byIndices(src, begin(position), end(position)), src.end());
  3. // position.clear();
  4.  
  5. template<typename Cont, typename It>
  6. auto iterByIndices(Cont &cont, It beg, It end) -> decltype(std::end(cont))
  7. {
  8.     int helpIndx(0);
  9.     return std::stable_partition(std::begin(cont), std::end(cont),
  10.         [&](decltype(*std::begin(cont)) const& val) -> bool {
  11.         return std::find(beg, end, helpIndx++) == end;
  12.     });
  13. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement