I was checking the implementation of clamp
in boost:
template<typename T, typename Pred>
T const & clamp ( T const& val,
typename boost::mpl::identity<T>::type const & lo,
typename boost::mpl::identity<T>::type const & hi, Pred p )
{
// assert ( !p ( hi, lo )); // Can't assert p ( lo, hi ) b/c they might be equal
return p ( val, lo ) ? lo : p ( hi, val ) ? hi : val;
}
If I look up the documentation, identity
returns the template argument unchanged.
The identity metafunction. Returns X unchanged.
So what's the point of using it here?
Isn't typename boost::mpl::identity<T>::type
equivalent to T
?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…