|
Boost : |
From: David Abrahams (dave_at_[hidden])
Date: 2003-11-03 21:52:32
"Sebastian Faust" <sfaust_at_[hidden]> writes:
> Hi,
>
>>The simplest way would be something like this:
>>
>> namespace mpl = boost::mpl;
>> using namespace mpl::placeholders;
>>
>> struct pass_through_make
>> {
>> static vehicle* make( vehicle* ptr )
>> {
>> return ptr;
>> }
>> };
>>
>> template< typename T, typename Base > struct make_vehicle
>> {
>> static vehicle* make( vehicle* ptr )
>> {
>> return new T( Base::make( ptr ) );
>> }
>> };
>>
>> typedef mpl::fold<
>> mpl::vector<car,bicycle,train>
>> , pass_through_make
>> , make_vehicle<_2,_1>
>> >::type factory;
> I tested the code above but my compiler gives me the following errors:
>
> c:\projekte\boost-1.30.2\boost-1.30.2\boost\mpl\aux_\preprocessed\msvc70
> \apply.hpp(97): error C2039: 'boost::mpl::apply<F,T1,T2,T3,T4,T5>' : is
> not a member of 'make_vehicle<T,Base>'
>
> c:\projekte\boost-1.30.2\boost-1.30.2\boost\mpl\aux_\preprocessed\msvc70
> \apply.hpp(54): error C2039: 'boost::mpl::apply<F,T1,T2,T3,T4,T5>' : is
> not a member of 'pass_through_make'
>
> Sadly I am not that familiar with mpl-programming and I can't find in
> the documentation information about the _1, _2 templates. So it would be
> nice if you could give me any further hints.
When you're using a broken compiler you need to resort to slightly
uglier code. Try this definition of make_vehicle:
struct make_vehicle
{
template< typename Base, typename T >
struct apply
{
static vehicle* make( vehicle* ptr )
{
return new T( Base::make( ptr ) );
}
};
};
Now use make_vehicle instead of make_vehicle<_2,_1>
> Furthermore, where can I learn more about the mpl? Is there any
> literature? Cause I am really getting fascinated by this
> compile-time programming, which I sadly never recognized before.
We're writing a book; in the meantime you could take a look at our
paper at http://www.boost.org/libs/mpl/doc/index.html, but it's a bit
rough and not terribly complete. There's also the reference docs, of
course...
-- Dave Abrahams Boost Consulting www.boost-consulting.com
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk