os_deref1, os_deref2


Allows function objects to support pointers to objects.

Two helper algorithms that allow function objects (such as less< T > ) to be used correctly with pointers to objects by automatically dereferencing the pointer before the function object is evaluated. The os_deref1 algorithm should be used with unary function objects, while os_deref2 is designed for use with binary function objects.

Library

Helper<ToolKit>

Declaration

#include <ospace/helper/deref.h>

template< class Predicate >
os_unary_deref< Predicate >
os_deref1( const Predicate& pred );

template< class Predicate >
os_binary_deref< Predicate >
os_deref2( const Predicate& pred );
Example <ospace/helper/examples/deref3.cpp>
#include <ospace/std/vector>
#include <ospace/helper.h>

template< class T >
class print : public os_unary_function< T, T >
  {
  public:
    T operator()( const T& t ) const
      {
      cout << t << ' ';
      return t;
      }
  };

void
main()
  {
  vector< int* > d;
  d.push_back( new int( 42 ) );
  d.push_back( new int( 03 ) );
  d.push_back( new int( 86 ) );
  d.push_back( new int( 69 ) );
  d.push_back( new int( 21 ) );

  cout << "Unsorted:\n\t";
  os_for_each( d, os_deref1( print< int >() ) );
  cout << endl;

  os_sort( d, os_deref2( less< int >() ) );

  cout << "Sorted:\n\t";
  os_for_each( d, os_deref1( print< int >() ) );
  cout << endl;
  }

Unsorted:
        42 3 86 69 21
Sorted:
        3 21 42 69 86
	

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