min


Return the minimum of two items.

Return the smaller of a and b , or return a if a and b are equal. The first version uses operator< to perform the comparison, whereas the second version uses the binary function compare .

Library

Standards<ToolKit>

Declaration


#include <algorithm>

template< class T >
const T& min( const T& a, const T& b );

template< class T, class Compare >
const T& min( const T& a, const T& b, Compare compare );

Complexity

Space and time complexity are constant.

Example <ospace/osstd/examples/min1.cpp>
#include <iostream>
#include <algorithm>

void
main()
  {
  cout << min( 42, 100 ) << "\n";
  }

42
Example <ospace/osstd/examples/min2.cpp>
#include <iostream>
#include <string.h>
#include <algorithm>

bool
str_compare( const char* a_, const char* b_ )
  {
  return ::strcmp( a_, b_ ) < 0 ? 1 : 0;
  }

void
main()
  {
  cout << min( "shoe", "shine", str_compare ) << "\n";
  }

shine

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