Boost logo

Boost Users :

Subject: Re: [Boost-users] [MPL] return type
From: Dave Abrahams (dave_at_[hidden])
Date: 2011-10-10 10:47:11


on Mon Oct 10 2011, Igor R <boost.lists-AT-gmail.com> wrote:

>> Every type in the sequence has the following form:
>
>>
>> struct sequence_item
>> {
>>     typedef the_real_type type ;
>>     static the_real_type *parse( const QDomElement & ) ;
>> } ;
>>
>>
>> The code for iterating over the sequence is the following:
>>
>>
>> template < typename It, typename End >
>> ?? *dispatchM( const QDomElement &, mpl::true_ /* endofvec */ )
>> {
>>     return 0 ;
>> }
>>
>>
>> template < typename It, typename End >
>> ?? *dispatchM( const QDomElement &element, mpl::false_ )
>> {
>>     typedef typename mpl::deref< It >::type MapEntry ;
>>     if ( element.tagName() == MapEntry::first::name() )
>
> The above line means that you figure out the correct type in
> *run-time*, don't you?
> But the result type must be known in compile-time.

Yeah, as long as you're doing that with a runtime test, your only option
is to use some kind of type erasure (boost::any, polymorphic base class,
etc). If you are stuck with a runtime test, you might consider passing
in a function object to handle whatever was going to be done at the
outer level with full knowledge of the types.

-- 
Dave Abrahams
BoostPro Computing
http://www.boostpro.com

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net