Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2004-07-14 14:23:04

Toon Knapen <toon.knapen_at_[hidden]> writes:

> Matthias Troyer wrote:
>> How would you do a BOOST_WORKAROUND in a template code where you
>> might not know the value of the static constant? I think that any
>> constant depending on a template parameter will still have to be
>> treated like it is done now.
> Sorry but I fail to understand what you are saying. Anyway what I
> suggest is to use BOOST_WORKAROUND for implementing the enum-trick
> wherever BOOST_STATIC_CONSTANT would use the enum-trick in case

Ultimately I think the right answer is to use

      mpl::integral_c<some_type, some_value>




everywhere as Paul Mensonides suggested. One reason is that it
centralizes the out-of-line static member definitions.

I'm just not sure how it interacts with all the low-level hacks needed
for broken compilers. To get the ::value member (admittedly this is
just a convenience) into a metafunction you have to use forwarding via

    template <class T>
    struct some_trait
      : mpl::bool_<(some-calculation-using-T)>

so it may mean breaking down implementations this way:

    template <class T>
    struct some_trait_impl
       typedef mpl::bool_<(some-calculation-using-T)> type;

    template <class T>
    struct some_trait
      : some_trait_impl<T>::type

But I truly believe this is the optimal approach.

Dave Abrahams
Boost Consulting

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