summaryrefslogtreecommitdiffstats
path: root/Utilities/std/cm/bits/erase_if.hxx
blob: 8952fb589f69056a5ce0c7c330dfc05f68a3547b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// -*-c++-*-
// vim: set ft=cpp:

/* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
   file Copyright.txt or https://cmake.org/licensing for details.  */

#ifndef cm_bits_erase_if_hxx
#define cm_bits_erase_if_hxx

namespace cm {
namespace internals {

template <typename Container, typename Predicate>
void erase_if(Container& cont, Predicate pred)
{
  for (typename Container::iterator iter = cont.begin(), last = cont.end();
       iter != last;) {
    if (pred(*iter)) {
      iter = cont.erase(iter);
    } else {
      ++iter;
    }
  }
}

} // namespace internals
} // namespace cm

#endif