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.:

>[snip]

>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
>guaranteed
>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
like:

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

?

Regards,
Reece

_________________________________________________________________
Tired of 56k? Get a FREE BT Broadband connection
http://www.msn.co.uk/specials/btbroadband


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