os_max_element, os_max_element_value


Finds the maximum element in a container.

Helper algorithms for max_element() . The first version sets t to point to the maximum element of container c , or zero if c is empty. If container c is not empty, the second version sets t to the maximum element of c and returns true ; otherwise, the algorithm returns false .

Library

Helper<ToolKit>

Declaration

#include <ospace/helper/helpalgo.h>

template< class Container, class T >
void os_max_element( const Container& c, T*& t )

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

int numbers[ 6 ] = { -10, 15, -100, 36, -242, 42 };

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

  os_max_element( v, ptr );

  if ( ptr )
    cout << "maximum = " << *ptr << "\n";;
  int value;

  bool result = os_max_element_value( v, value );

  if ( result )
    cout << "maximum = " << value << "\n";
  }

maximum 42
maximum 42

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