
"Jason Hise" wrote:
Pavel and I have been discussing a sibling class to the singleton, namely a multiton. Such a class would manage a unique object instance for each key provided to GetInst. It should be able to use many of the same policies that the singleton uses.
Pavel thinks that it could be useful to allow GetInst to take any number of parameters. Would this actually be useful, and if so, how could such a design be achieved?
The idea is to have library which allows to create "parametrized singletons", like: City& c1 = City::get_inst("Belgium", "Ghent"); ... City& c2 = City::get_inst("Belgium", "Ghent"); assert(&c1 == &c2); The name "Multiton" was already used with similar library in Ruby. The problem is what syntax to use to define Multiton, like: template < typename T, typename Parameters = TYPELIST2(std::string, std::string), typename Lifetime = ...
class Multiton { .... }; and how to 'generate' flat structure from the typelist. (The structure would be then used as key in lookup map.) /Pavel