Tobias Schwinger wrote:
dariomt@gmail.com wrote:
class Base {...}; class Factory {...}; template <typename T> struct Helper {...}; // constructor registers creation function for template parameter
Now we have a template defining a family of derived classes: template
class DerivedUVW : public Base {...}; ...
And all possible U V and W classes in the combination game: struct A1 {}; struct A2 {}; // for U struct B1 {}; struct B2 {}; // for V struct C1 {}; struct C2 {}; // for W
...
And now the six million dollar question: Is there a way in which MPL and fusion can automatically do the registration?
I think so (see attachment)!
Here's an MPL-based solution. It does not require any preprocessor code and compiles with GCC4.
With a bug. It successfully determines whether there is nothing to do -
but also does nothing if there's almost nothing to do, that is only one
combination. It also won't work if one of the input sequences is empty.
The attached patches remove the entry condition. So the precondition is
"the sequences yield at least one combination" now. Checking it is left
an exercise to the reader :).
Regards,
Tobias
--- combinations.cpp.bak 2008-01-05 10:55:37.000000000 +0100
+++ combinations.cpp 2008-01-05 10:56:04.000000000 +0100
@@ -206,12 +206,7 @@
inline void register_factories()
{
typedef typename mpl::transform