Boost logo

Boost :

From: Jonathan Turkanis (technews_at_[hidden])
Date: 2003-12-18 13:31:03


"David Abrahams" <dave_at_[hidden]> wrote in message
news:u3cbigbr0.fsf_at_boost-consulting.com...
> "Jonathan Turkanis" <technews_at_[hidden]> writes:
>
> > I have occassionally used mpl::bool_ as a tool for compile-time 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 non-integral */ }
> >
> > 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 sepcialzation--by cheating!
Should I cheat too when I define traits templates?)

But is_integral was just an example. For a general MPL-compatible 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