Question

Which _STD function(s) return the max, or min of 2 integers, signed or unsigned? Is it the max, min in the math.h header library or what could they be?

Was it helpful?

Solution

std::min and std::max in the <algorithm> library. As they're templates they return the min and max for every type that implements the < operator (or you can supply a functor for your custom comparison).

See Algorithms library (link to cppreference.com).

OTHER TIPS

You can use the new algorithm introduced in C++11(

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

Returns: pair(b, a) if b is smaller than a, and pair(a, b) otherwise.

std::max and std::min are in the file algorithm.

You can look up the other functions included in this file at C++ Reference. Bookmark it for future usage.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top