os_sort


Sorts a sequence.

A helper algorithm for sort() . Sorts all elements in the container c into ascending order. The first version uses operator< to compare elements, whereas the second version uses the binary function compare .

Library

Helper<ToolKit>

Declaration

#include <ospace/helper/helpalgo.h>

template< class Container >
void os_sort( Container& c )

template< class Container, class Compare >
void os_sort( Container& c, Compare compare )
Example <ospace/helper/examples/osort0.cpp>
#include <iostream>
#include <vector>
#include <ospace/helper.h>

int numbers[ 6 ] = { 1, 50, -10, 11, 42, 19 };

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

  os_sort( v );

  for ( size_t i = 0; i < v.size(); ++i )
    cout << v[ i ] << ` `;
  cout << "\n";
  }

-10 1 11 19 42 50
Example <ospace/helper/examples /osort1.cpp>
#include <iostream>
#include <functional>
#include <vector>
#include <ospace/helper.h>

int numbers[] = { 1, 50, -10, 11, 42, 19 };

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

  os_sort( v, greater< int >() );

  for ( size_t i = 0; i < v.size(); ++i )
    cout << v[ i ] << ` `;
  cout << "\n";
  }

50 42 19 11 1 -10

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