Okay I think I've got a solution but I it is a bit ugly. Is there a cleaner solution? template< typename T > struct wrap { }; template< typename ResourceCaches > struct CacheClearer { ResourceCaches& m_caches; CacheClearer( ResourceCaches& caches ) : m_caches( caches ) {} template< typename Resource > void operator()( wrap<Resource> ) { static_cast<Cache<Resource>&>(m_caches).value.Clear(); } }; template< typename ResourceCaches > CacheClearer<ResourceCaches> MakeCacheClearer( ResourceCaches& caches ) { return CacheClearer<ResourceCaches>( caches ); }; 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() { boost::mpl::for_each<resource_types, wrap<boost::mpl::_1> >( MakeCacheClearer(m_caches) ); } 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; };
Thanks, Michael Marcin