Boost logo

Boost Users :

Subject: [Boost-users] [MPL] return type
From: Istvan Buki (buki.istvan_at_[hidden])
Date: 2011-10-10 07:07:26


Dear Boost experts,

I'm trying to find a solution to the following problem.

I'm iterating over an MPL sequence and once I found the appropriate type in
the sequence
I call a static function that returns a pointer to a newly created object
that I need to return to the caller of the ModelDispatcher::parse member
function with its exact type.
In other words I need to propagate the exact type of the object created
somewhere in a recursive chain of function calls back to the original
caller.
Unfortunately I can't figure out how to specify the return type of this
recursive function.

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() )
        {
            // return type is MapEntry::second::type
            return MapEntry::second::parse( element ) ;
        }
    else
        {
            typedef typename mpl::next< It >::type Next ;
            return dispatchM< Next, End >( element, typename boost::is_same<
Next, End >::type() ) ;
        }
}

template < typename ModelMap >
struct ModelDispatcher
{
    static
    ?? *parse( const QDomElement &element )
    {
        mpl::false_ f ;
        return dispatchM< typename mpl::begin< ModelMap >::type, typename
mpl::end< ModelMap >::type >( element, f ) ;
    }
} ;

Thanks a lot for your help.

Istvan



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