os_grep_if


Searches for strings matching a regular expression pattern using predicate.

Finds all strings in the range [ begin , end ) that match the regular expression pattern using predicate , and copies them to out . Returns the number of matches found.

Library

Helper<ToolKit>

Declaration

#include <ospace/helper/regalgo.h>

template< class InputIterator, class OutputIterator, class Predicate >
size_t os_grep_if
  (
  InputIterator begin,
  InputIterator end,
  OutputIterator out,
  const string& pattern,
  Predicate predicate
  );
  
Example <ospace/helper/examples/regexpr5.cpp>
#include <iostream>
#include <algorithm>
#include <vector>
#include <ospace/helper.h>

void
fill( vector< string >& v )
  {
  v.push_back( "Systems<ToolKit> is portable." );
  v.push_back( "Web<ToolKit> is portable." );
  v.push_back( "Systems<ToolKit> is flexible." );
  v.push_back( "Thread<ToolKit> is flexible." );
  v.push_back( "Systems<ToolKit> is efficient." );
  v.push_back( "Network<ToolKit> is efficient." );
  v.push_back( "Systems<ToolKit> is fun." );
  v.push_back( "Helper<ToolKit> is fun." );
  }

bool
filter( os_regexp& rx, const string& in, string& out )
  {
  if ( rx.search( in ).valid() )
    return false;
  out = in;
  return true;
  }

void
print( const string& s )
  {
  cout << s << endl;
  }

void
main()
  {
  vector< string > in;
  fill( in );
  string pattern( "Systems" );
  cout << "Search for strings not containing = " << pattern << endl;
  vector< string > out( in.size() );
  size_t n = os_grep_if( in.begin(),in.end(),out.begin(),pattern,filter );
  for_each( out.begin(), out.begin() + n, print );
  }

Search for strings not containing = Systems
Web<ToolKit> is portable.
Thread<ToolKit> is flexible.
Network<ToolKit> is efficient.
Helper<ToolKit> is fun.


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