Boost logo

Boost :

From: Reece Dunn (msclrhd_at_[hidden])
Date: 2003-12-14 17:56:13

Jonathan Turkanis wrote:

>I have occassionally used mpl::bool_ as a tool for compile-time dispatch
>based on a boolean condition. E.g.:


>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, or are true_ and false_ only
>to be integral constant types with values true and false?

It would seem that they are part of the public interface (they are not
defined within a detail namespace, not are they located in the aux_
directory). This would also make it consistent with the bool type.

As for the example not being self-documenting, could you not do something

namespace detail
   typedef mpl::true_ integral_type;
   typedef mpl::false_ nonintegral_type;

   template< typename T >
   void f( const T &, integral_type ){ ... }

template<typename T>
void f(const T& t) { detail::f(t, mpl::bool_<is_integral<T>::value>()); }



Tired of 56k? Get a FREE BT Broadband connection

Boost list run by bdawes at, gregod at, cpdaniel at, john at