
Boost : 
From: Jonathan Turkanis (technews_at_[hidden])
Date: 20031218 13:31:03
"David Abrahams" <dave_at_[hidden]> wrote in message
news:u3cbigbr0.fsf_at_boostconsulting.com...
> "Jonathan Turkanis" <technews_at_[hidden]> writes:
>
> > I have occassionally used mpl::bool_ as a tool for compiletime dispatch
> > based on a boolean condition. E.g.:
> >
> > template<typename T>
> > void f(const T&, mpl::true_) { /* T is integral */ }
> >
> > template<typename T>
> > void f(const T&, boost::mpl::false_) { /* T is nonintegral */ }
> >
> > template<typename T>
> > void f(const T& t) { f(t, mpl::bool_<is_integral<T>::value>()); }
>
> Better:
>
> template<typename T>
> void f(const T& t) { f(t, typename is_integral<T>::type()); }
>
Thanks. Looking into the guts of the type traits library, is see why this
works. (BTW, I also see why lambda expressions based on TT work on compilers
without template template arguments or partial sepcialzationby cheating!
Should I cheat too when I define traits templates?)
But is_integral was just an example. For a general MPLcompatible boolean
type traits template, the only guarantee is that the inner 'type' is a model
of intergral constant with value_type bool., right? Doesn't this mean that
is_xxx<T>::type and is_xxx<S>::type need not be the same, even if T and S
both saitisfy or both fail to satify the condition?
Jonathan
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk