c++ - What's the point of "boost::mpl::identity::type" here? -
c++ - What's the point of "boost::mpl::identity<T>::type" here? -
i checking 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 might equal homecoming p ( val, lo ) ? lo : p ( hi, val ) ? hi : val; }
if documentation, identity
returns template argument unchanged.
the identity metafunction. returns x unchanged.
so what's point of using here?
isn't typename boost::mpl::identity<t>::type
equivalent t
?
a nested-name-specifier creates non-deduced context. therefore, compiler not effort deduce type t
based on sec , 3rd parameters declared as:
typename boost::mpl::identity<t>::type const &
type t
deduced based on type of first argument, , used instantiate types of rest parameters. using identity
type mutual trick prevent template argument type deduction on parameters, otherwise result in ambiguous phone call error in case types of arguments differ, utilize same type template parameter. can desired not allow compiler automatically infer type, , forcefulness caller on his/her own.
c++ templates boost argument-deduction
Comments
Post a Comment