os_erase_if


Erases items from a container that satisfy a predicate.

A helper algorithm for remove_if() . Erases all elements that satisfy pred from the container c . Unlike remove_if() , the size of the container decreases by the number of elements that are erased.

Library

Helper<ToolKit>

Declaration

#include <ospace/helper/helpalgo.h>

template< class Container, class Predicate >
void os_erase_if( Container& c, Predicate pred )
Example <ospace/helper/examples/oerasif0.cpp>
#include <vector>
#include <ospace/helper.h>

bool
odd( int a_ )
  {
  return a_ % 2;
  }

int numbers[ 6 ] = { 0, 0, 1, 1, 2, 2 };

void
main()
  {
  vector< int > v( numbers, numbers + 6 );

  os_erase_if( v, odd );

  for ( vector< int >::iterator i = v.begin(); i != v.end(); ++i )
    cout << *i << ` `;
  cout << "\n";
  }

0 0 2 2 2 2

Copyright©1994-2026 Recursion Software LLC
All Rights Reserved - For use by licensed users only.