Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is the documentation for an old version of Boost. Click here to view this page for the latest version.
PrevUpHomeNext

Improving std::min with common_type

An improved std::min function could be written like this:

template <class T, class U>
typename common_type<T, U>::type min(T t, T u)
{
   return t < u ? t : u;
}

And now expressions such as:

min(1, 2.0)

will actually compile and return the correct type!


PrevUpHomeNext