Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2003-12-17 20:23:15


"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()); }

>
> Aside from the question of whether this is good programming style (e.g., it
> is not self-documenting), I wonder if it is correct. Are the typedefs
>
> typedef bool_<true> true_;
> typedef bool_<false> false_;
>
> part of the public interface of MPL

Yep.

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk