Boost logo

Boost Users :

Subject: [Boost-users] [MPL] Applying a boost::mpl::list to the template parameter of a type.
From: Andrew Hundt (athundt_at_[hidden])
Date: 2010-12-17 21:30:23


Hello,

I have a class that requires a boost::variant containing shared pointers to
various types as follows:

    template <typename ToySharedPtrVariant, typename ColorSharedPtrVariant>
    class ToyPicker {
       typedef std::pair<
         ToySharedPtrVariant,
         ColorSharedPtrVariant
> toyAndColorPair;
       typedef std::map<
         std::string,
         std::vector<
           toyAndColoPair
>
> stringToToyColorPairMap;

       // ... methods that use the defined types...
    }

This class currently requires template parameters of the following form to
compile:

    ToyPicker<
               boost::variant<
                 boost::shared_ptr<ToyModel>
>,
               boost::variant<
                 boost::shared_ptr<BlueToy>,
                 boost::shared_ptr<RedToy>,
                 boost::shared_ptr<GreenToy>
>
> toyPicker;

How do I use an mpl list so that I can allow the following much simpler
definition for users, then convert it into the one above inside my class?

    ToyPicker<
           boost::mpl::list<
             ToyModel
>,
           boost::mpl::list<
             BlueToy,
             RedToy,
             GreenToy
>
> toyPicker;

I really appreciate all of the user help you all give, and hope that as I
become more experienced I may be able to contribute myself.

Cheers!
Andrew Hundt



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