Silicon Graphics, Inc.

max

Categories: algorithms, utilities Component type: function

Prototype

Max is an overloaded name; there are actually two max functions.
template <class T> const T& max(const T& a, const T& b);

template <class T, class BinaryPredicate>
const T& max(const T& a, const T& b, BinaryPredicate comp);

Description

Max returns the greater of its two arguments; it returns the first argument if neither is greater than the other.

The two versions of max differ in how they define whether one element is less than another. The first version compares objects using operator<, and the second compares objects using the function object comp.

Definition

Declared in algo.h. The implementation is in algobase.h.

Requirements on types

For the first version: For the second version:

Preconditions

Complexity

Example

const int x = max(3, 9);
assert(x == 9);

Notes

See also

min, min_element, max_element, LessThan Comparable
[Silicon Surf] [STL Home]
Copyright © 1996 Silicon Graphics, Inc. All Rights Reserved. TrademarkInformation