Boost logo

Boost Users :

From: Michael Marcin (mmarcin_at_[hidden])
Date: 2007-10-10 20:11:35


Looking back into the MPL book I think I can create the required members
and implement Get by modifying the class in the last posting with:

template< typename Resource >
struct Cache
{
    resource::Cache<Resource> value;
};

class Manager
{
public:
     /// Returns Cache<Resource>::Retrieve( id )
    template< typename Resource >
    Resource& Get( ResourceId id )
    {
       return static_cast<Cache<Resource>&>(m_caches).value.Retrieve(id);
    }

    /// Calls Cache::Clear for all resource types
    void Clear();

private:
    typedef boost::mpl::vector25<
       Sound,
       Script,
       // etc.
> resource_types;

    boost::mpl::inherit_linearly<
       resource_types, boost::mpl::inherit< Cache< boost::mpl::_2 >,
boost::mpl::_1 >
>::type m_caches;
};

Now I need to figure out a way to iterate the members of m_caches and
call the Clear method on each value.

As an aside it's syntactically heavy to have to qualify each placeholder
with "boost::mpl::". Unfortunately if I don't do that it picks up
boost::bind placeholders from an unnamed namespace and gives an
impressive spew of error messages.

Thanks,

Michael Marcin


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