algorithm - STL C++

max()

Declaration

template <class X>
const X& max(
	const X& kxrItem1,
	const X& kxrItem2
);

Description

This function returns the larger of the two elements "kxrItem1" and "kxrItem2." The overloaded version uses the function "xComp" as a comparison function.

Header Include

#include <algorithm>

Overloads

template <class X,  class BinaryPred>
const X& max(
	const X& kxrItem1,
	const X& kxrItem2,
	BinaryPred xComp
);

Example

#include <iostream>
#include <algorithm>

int main()
{
	using namespace std;

	const double kdPi = 3.141259;
	const double kdE = 2.71828;
	// Find the larger of two values
	cout << "The larger of " << kdPi << " and " << kdE << " is ";
	cout << max(kdPi, kdE);

	// Keep the window open
	cin.get();
	return 0;
}

Output

max() Output
 

© 2007–2024 XoaX.net LLC. All rights reserved.