我需要对我的 C++11 可变参数版本的实现进行反思std::min,std::max. 这是我的两个替代方案std::min,其中只需替换std::max为类似地实现:std::minstd::max
/*! 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 and \p args. */
template <class T, class ... R >
//requires SameType <T , Args >...
T multi_type_min(const T & a, const R &... b)
{
return std::min(a, multi_type_min(b...));
}
/*! Minimum of \p a. */
template <LessThanComparable T> const T & common_type_min(const T & a) { return a; } // template termination
/*! Minimum of \p a and \p args. */
template <class T, class ... R, class C = typename boost::common_type<T, R...>::type >
C common_type_min(const T & a, const R &... b)
{
return std::min(static_cast<C>(a), static_cast<C>(common_type_min(b...)));
}
关键问题是我们是否需要common_type_min?请注意,这允许使用一个参数调用 min()。这会导致混乱或问题吗?