os_binary_search


Locates an item in a sorted container.

A helper algorithm for binary_search() . Returns true if value is in the container c . This algorithm assumes that the elements in the container are already sorted using operator< .

Library

Helper<ToolKit>

Declaration

#include <ospace/helper/helpalgo.h>

template< class Container, class T >
bool os_binary_search( const Container& c, const T& value )
Example <ospace/helper/examples/obinsch0.cpp>
#include <iostream>
#include <vector>
#include <ospace/helper.h>

void
main()
  {
  vector< int > v;
  for ( int i = 0; i < 100; ++i )
    v.push_back( i );

  if ( os_binary_search( v, 42 ) )
    cout << "found 42\n";
  else
    cout << "did not find 42\n";
  }

found 42

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