Boost logo

Boost :

From: Sebastian Faust (sfaust_at_[hidden])
Date: 2003-11-15 19:47:52


Hi,

> What I now wanna, and I sadly don't know how to solve such, is the
> follwing:
>
> Given again the classes which I wanna create with some kind of special
> factory:
>
> class vehicle
> {
> public:
> vehicle(vehicle* successor) : m_successor(successor) {}
> virtual vehicle* create(vehicle* successor) = 0;
> vehicle* m_successor;
>
> };
>
> class car : public vehicle
> {
> public:
> static const int _key = 1;
> virtual vehicle* create(vehicle* successor)
> {
> return new car(successor);
> }
>};
>
> class bicycle : public vehicle
> {
> public:
> static const int _key = 2;
> virtual vehicle* create(vehicle* successor)
> {
> return new bicycle (successor);
> }
> };
>
> Now the main-Function should look the following:
>
> void main()
> {
> std::map<int, boost::shared_ptr<vehicle> > myMap;
> factory::make(myMap);
> }
>
> After this the map should contain one object from type car with the
key
> 1, and one object from type bicycle with the key 2.
I tried now the following:
namespace factory
{

template <typename T = boost::mpl::_1>
struct tag{};

template <typename C>
struct mv{
    template <typename T>
                void operator()(tag<T>)
        {
                m_c.insert(std::make_pair(T::_key, typename
C::value_type(new T)));
        }
    mv(C& v):m_c(v){}
private:
    C& m_c;
};

template <typename T>
mv<T> make_mv(T& t){return mv<T>(t);}
}

int _tmain(int argc, _TCHAR* argv[])
{
    using namespace boost;
    using namespace boost::mpl;
    std::map<int, shared_ptr<vehicle> > vs;
    for_each<vector<car,train>,factory::tag<> >(factory::make_mv(vs));
    return 0;
}

With that I got the following compiler-error:
error C2440: 'Typeconversion': 'boost::mpl::bind1<F,T1>::apply<U1>::t1
*' can't be converted in 'std::_Tree<_Traits>::value_type'
        with
        [
            F=boost::mpl::quote1<factory::tag>,
            T1=boost::mpl::lambda_impl<boost::mpl::_1>::type,
            U1=item
        ]
        and
        [
 
_Traits=std::_Tmap_traits<int,boost::shared_ptr<vehicle>,std::less<int>,
std::allocator<std::pair<const int,boost::shared_ptr<vehicle>>>,false>
        ]

How can I elminiate this error?

Can somebody tell me when the book about the mpl will be available?

Thanks in advance
Sebastian


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk