这是我在 GCC 4.6 上使用带有和不带有Boost Concepts Common Type Traits的可变参数模板的解决方案。min
不过,我不确定是否需要 common_type。
#define LessThanComparable class
#include <boost/type_traits/common_type.hpp>
/*! Multi-Type Minimum of \p a. */
template <LessThanComparable T> const T & multi_type_min (const T & a) { return a; } // template termination
/*! Multi-Type Minimum of \p a, \p b and \p args. */
template <class T, class ... R >
//requires SameType <T , Args >...
T multi_type_min(const T & a, const T & b, const R &... args)
{
return multi_type_min(a < b ? a : b, args...);
}
/*! Minimum of \p a. */
template <LessThanComparable T> const T & min(const T & a) { return a; } // template termination
/*! Minimum of \p a, \p b and \p args. */
template <class T, class U, class ... R, class C = typename boost::common_type<T, U, R...>::type >
C min(const T & a, const U & b, const R &... c)
{
return min(static_cast<C>(a < b ? a : b), static_cast<C>(c)...);
}