Opened 9 years ago

Closed 9 years ago

#9780 closed Bugs (fixed)

Error in boost_typetraits std::min example?

Reported by: evan.teran@… Owned by: John Maddock
Milestone: To Be Determined Component: type_traits
Version: Boost 1.55.0 Severity: Cosmetic
Keywords: Cc:

Description

In the documentation for boost_typetraits, an example is given on how to improve std::min. However, at least at first glance it looks like there is a typo. The example reads:

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

Notice that type T is being used for the argument u. If I understand the example better, the point is that the return type of min will be the correct type. But I would expect the u parameter to still have the type U not T.

As it is, I believe that this code will cast the second parameter to type T when it is passed to the function.

Change History (2)

comment:1 by Steven Watanabe, 9 years ago

Component: Nonetype_traits
Owner: set to John Maddock

As this stands, you couldn't call min(x, y) because U can't be deduced.

comment:2 by John Maddock, 9 years ago

Resolution: fixed
Status: newclosed

It's a typo, fixed in develop, thanks!

Note: See TracTickets for help on using tickets.