$include_dir="/home/hyper-archives/boost-users/include"; include("$include_dir/msg-header.inc") ?>
Subject: Re: [Boost-users] [typeof] Determining if a type has been registered or not at compile time
From: Edward Diener (eldiener_at_[hidden])
Date: 2009-12-22 13:55:07
joel falcou wrote:
> Edward Diener wrote:
>> 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:
>>
>> 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*/>
>>   >
> A simple way could be to add a meta-function specialisation in the 
> typeof registration macro so that a is_registered<T> is available in a 
> pervasive way.
I don't know how the internals of typeof work, but what I think probably 
has to happen is that all types which are registered by the end-user 
need to be kept in some sort of MPL sequence which can be later checked 
to see whether a particular type is registered at compile time via some 
boolean metafunction.
But I have not heard anything from the typeof developers so I do not 
think they are much interested in this issue.
For my own use I am using typeof to generate the return values of 
operators for built-in types but I want to be able to do the same for 
user-defined types also. But if a user-defined type is not registered 
via typeof I want to fall back on other methods rather than the have the 
end-user issued a compiler error. To do this I need a metafunction which 
tells me whether or not a type is registered with typeof.