What function(s) determine the max or min of two integers?


What function(s) determine the max or min of two integers?



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?





Possible duplicate of Use of min and max functions in C++
– Radiodef
2 days ago




3 Answers
3



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).


std::min


std::max


<algorithm>


<



See Algorithms library (link to cppreference.com).



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.


std::max


std::min


algorithm



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






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Comments

Popular posts from this blog

paramiko-expect timeout is happening after executing the command

Opening a url is failing in Swift

Export result set on Dbeaver to CSV