C++ boost ::minmax














































C++ boost ::minmax



 Boost.minmax provides an algorithm to find the minimum and the maximum of two values using only one function call, which is more efficient than calling std::min( ) and std::max( ).

Code:

#include <boost/algorithm/minmax.hpp> #include <boost/tuple/tuple.hpp> #include <iostream> int main() { int i = 5; int j = 7; boost::tuples::tuple<const int&, const int&> t = boost::minmax(i, j); std::cout << t.get<0>() << '\n'; std::cout << t.get<1>() << '\n'; }
Output: 5
7

Explanation:
Boost::minmax() computes the minimum and maximum of two objects. While both std::min( ) and     std::max( ) return only one value, boost::minmax( ) returns two values as a tuple. The first reference in the tuple points to the minimum and the second to the maximum.It writes 1 and 2 to the standard output stream.

Comments