-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Extend ResourceCache for factory functions #972
Comments
Possibly relevant info: |
I found I can update the syntax slightly to change how parameters are specified. It's not quite what I want, but interesting. Changing to this allows function style syntax: template <typename FactoryFunction>
class ResourceCache;
template <typename Resource, typename... Params>
class ResourceCache<Resource(Params...)>
// ... Example usage: using AnimationCache = ResourceCache<AnimationSet(std::string)>; Example usage: NAS2D::ResourceCache<MockResource(std::string, int)> cache; The current syntax requires all types to be listed serially: using AnimationCache = ResourceCache<AnimationSet, std::string>; NAS2D::ResourceCache<MockResource, std::string, int> cache; This updated syntax isn't quite what I want, since it's still just a type definition, and doesn't allow specifying a specific factory function that matches that type. Actually, the limitation is on how objects are instantiated and stored in the const auto pairIterBool = cache.try_emplace(key, params...); Here the Incidental note: We should probably be using It may also make sense to use |
Currently
ResourceCache
can only be used with constructors of the cached type. We should find a way to extend this to allow factory functions to be used instead. Really we want some function that takes a given fixed set of parameters, and returns the desired type, which can be added to the cache, and looked up using a parameter list tuple.The text was updated successfully, but these errors were encountered: