、のC++11可変個引数バージョンの実装について考察する必要がありstd::min
ますstd::max
。これが私の2つの選択肢です。ここでは、std::min
次のstd::max
ように置き換えるだけで同様に実装されstd::min
ますstd::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()を1つの引数で呼び出すことができることに注意してください。これは混乱や問題を引き起こす可能性がありますか?