Boost logo

Boost :

From: Fernando Cacciola (fcacciola_at_[hidden])
Date: 2002-07-04 08:55:09

----- Original Message -----
From: "David B. Held" <dheld_at_[hidden]>
Newsgroups: gmane.comp.lib.boost.devel
To: <boost_at_[hidden]>
Sent: Thursday, July 04, 2002 2:19 AM
Subject: [boost] Re: boost::is_empty<> for bcc

> "David B. Held" <dheld_at_[hidden]> wrote in message
> news:ag0idi$t84$
> > Is there a version of boost::is_empty<> that works with bcc?
> That was a really dumb question. Of course is_empty<> works for
> bcc. What I really want is a set of type_traits that traffics in
> and false_type instead of BOOST_STATIC_CONSTANTs. This is
> because bcc does not like bool template parameters much, and so
> it makes it almost impossible to use the type traits in any useful
> metaprogramming. It looks like a big chore to provide this
> implementation, since many of the type traits depend on each other.
> I was just wondering if anyone has tried to use them with bcc (for
> example, in a partial spec switch), and already made any workarounds.
> I wrote a wrapper called bool2type that converts an int into a true_type
> or false_type, but on bcc it is very fragile, and will break if there is a
> template type in the expression. For instance, this works:
> template <typename T> class x
> {
> public:
> typedef bool2type<boost::is_empty<some_class>::value>::value value;
> };
> but this doesn't:
> template <typename T> class x
> {
> public:
> typedef bool2type<boost::is_empty<T>::value>::value value;
> };
> Any advice is appreciated.
Both versions will work if you 'fully' qualify the argument of bool2type.
And to 'fully' qualify it, you need to prepend '::'.
NOTE: This is one of the **very common** little details that makes most
metaprogramming libraries don't work with BCC; so, if anyone out there would
like to switch his/her own library to full qualification, we borlanders will
all be very glad :-) TIA

Usually, you need two tools to make this sort of things work with bcc. With
these two combined you should be able to use any 'value-oriented'

The type2bool<> you already have, and something like this:

template<class Value> struct ctv_wrap : Value {}; (*I saw this on MPL

This last helper is used to access the 'value' (non-type) of a dependent
object, something that is broken in bcc:

Consider, for example:

template<class Condition, class T1, class T2>
struct ct_select_type
  typedef typename
   ctv_select_type< Condition::value <=======
                    , T1
                    , T2
>::type type;

"Condition::value" won't work with bcc because 'Condition' is a template
So you need to use ctv_wrap<>:

   ctv_select_type< ::boost::ctv_wrap<Condition>::value,

BTW: Your bool2type<> exposes 'value', but it is actually exposing a type
(true_type,false_type), so it should be named 'type', IMO.

Fernando Cacciola
Sierra s.r.l.


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