Hello David, thanks for your clean and simple answer. I also thought about something similar to your answer but I was wondering if there exist some way to calculate that index at compile-time. Looking at the assembly code generated, it doesn't make a big difference to my version where the index values are hard-coded but still... In fact, the question I'm really trying to answer is: what is the price to pay (in term of performance and space) for using an mpl based solution compared to have my array elements initialized by a totally hard-coded function? Up to now what I've found is that my executable is 10% larger and the code is about 4 times slower (again by looking at the assembly code generated). So, if you can think of a more efficient solution I'm still interested. Thanks, Istvan On Monday 26 July 2004 03:36, David Abrahams wrote:
Istvan Buki
writes: Hello mpl experts,
I'm trying to initialize the elements of an array using rules defined in a list of structures. The code below illustrate what I'm trying to achieve.
The problem I have with this code is that the First_Descriptor structure contain this index member that will be used to access the right item of the array. This is not nice because it force the writer of this structure to deal with implementation details. Is there a way to get rid of this index typedef in the *_Descriptor structures by using another construct from the mpl that would generate it ?
The easiest thing to do is just to embed the index as a data member in the Initializer object, which can be stateful. Just bump the index each time the Initializer is invoked.
HTH, Dave