October 22nd, 2012, 12:57 am
Attached is some explicit code illustrating what I have in mind as our "Dynamic Configuration Problem". The immediate problem as I see it, is the necessity of handling a very large collection of types. In my simple toy example, there are just 3 x 3 x 2 = 18 types, corresponding to the case where the builder pattern chooses a triple of types from three families of types, A, B and C where A and B have 3 types each and C has 2 types. But in practice there would likely be several thousand types. The goal in this code is to perform a simple task for each of the 18 triples in the cartesian product of types A x B x C. Three methods to achieve this are compared in the code. I have just attached the main .cpp, but the source tree can be obtained from svn and compiled. The output is also attached below.(1) "Advanced" TMP, where the cartesian product of types is literally computed by meta-code. The example code for Method 1 is clearly the most elegant and concise. Currently this solution has the problem that computing cartesian products in TMP is very slow to compile even for moderately sized product, and even worse causes the compiler to blow up as the size grows. However, I believe that these compiler issues can be overcome by using the MPL package I mentioned below --- but this remains to be tested.(2) Run-time polymorphism. This is essentially BLOCK I in Cuchulainn's post below. It is easy to implement, but very inelegant, goes against the design goals and will cause performance degradation. (I'm assuming we agree that BLOCK II is not helpful for the problem at hand.)(3) Hard-coding at the top level. I originally dismissed this solution, and it is unfeasible to write this code by hand in larger examples. However, perhaps the solution could be made feasible where the original source (which may or may not be entirely in C++) is compiled once to obtain intermediate source code which is then run through the C++ compiler. It seems inelegant to me, but perhaps this is a normal procedure for large projects... QuoteOriginally posted by: CuchulainnThe design is well-known (e.g. C#, Java, COM) _but_ not in C++ and TMP AFAIK. The question is why...I would be very interested to see an example in C#. I'm currently reading about reflection in C#. If this gives an alternative solution in C#, then it seems likely it would also be applicable to C++ using the library Polter mentioned.C:\...\Visual Studio 2010\Projects\QFCL\bin\examples\Release>cartesian_product_simple_example.exe