Boost logo

Boost :

Subject: Re: [boost] [typeof] Determining if a type has been registered or not at compile time
From: Edward Diener (eldiener_at_[hidden])
Date: 2009-12-27 12:02:35

Peder Holt wrote:
> 2009/12/22 Edward Diener <eldiener_at_[hidden]>
>> Is there any way one can determine whether a type has been registered or
>> not with Boost.Typeof at compile time so that the information can be used in
>> TMP ? I am thinking, of course, of the use of typeof in a template, where a
>> template parameter may or may not be aregistered type when the template has
>> been instantiated. I would like to provide my own TMP fallback code if the
>> type has not been registered rather than see an immediate compiler error
>> generated. Something like:
>> Here is a possible implementation of boost::typeof::is_registered: snipped...
>> boost::mpl::eval_if
>> <
>> boost::typeof::registered<T>, // this would be nice to have
>> boost::mpl::identity<BOOST_TYPEOF_TPL(some_expression)>,
>> boost::mpl::identity</* use another facility to get the type I want into a
>> metafunction*/>
>> >
> The problem is that BOOST_TYPEOF_TPL is evaluated even if is_registered is
> false.

You are right and I had not realized this until you mentioned it. So
'registered' metafunction does little good for my proposed situation.

> One way to workaroun this is to allow the user to add a default type:
> typedef
> BOOST_TYPEOF_WITH_DEFAULT(some_expression,some_backup_type_if_some_expression_not_registered)
> type;
> Is this acceptable?

Yes, that seems the best solution. An excellent idea. Should I create a
Trac suggestion for it or will you remember to implement it if you
decide to do it ? If you do this, I think you will want to do it for
TYPEOF_TPL also. I see much less use for AUTO and AUTO_TPL defaults if
the type is not registered but I think you should also implement it for
these two also both to be orthogonal and for the possibility that
someone will find a use there also.

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