
On 9/1/07, Tobias Schwinger <tschwinger@isonews2.com> wrote:
Marco Costalba wrote:
This is a simple yet interesting object factory.
Please see
. It seems with that factory utility one could achieve the semantics of your proposal somehow like this (note: untested code for illustration only - see docs and tests):
[snip code]
It's pretty flexible, isn't it? It also works with smart pointers and there's a variant for by-value construction :-).
A similar approach could be done with http://dispatcher.sourceforge.net/ -- only this time it's not required that the function registered is a "factory". It could very well be any function registered. base_t * foo(int a, int b) { ... }; // somewhere in code dispatcher<string, base_t*(int, int)> d; d["T1"] = factory<T1>(); d["T2"] = factory<T2>(); d["something else"] = &foo; string input; cin >> input; base_t holder = d[input](1, 2); HTH -- Dean Michael C. Berris http://cplusplus-soup.blogspot.com/ mikhailberis AT gmail DOT com +63 928 7291459