Boost logo

Boost :

From: Douglas Gregor (gregod_at_[hidden])
Date: 2002-08-01 11:26:00


[Usual disclaimer: this post should not be confused with my role as review
manager]

At WCGP'02 last month, Michael Burton presented a paper titled "Static Data
Structures: Reconciling Template Metaprogramming and Generic Programming".
The most important part of their work, I think, was that they gave a very
natural way to shift code from using dynamic data structures (STL sequences)
to static data structures (type vectors), by appropriately overloading STL
algorithms. The same line of code, e.g.,

  for_each(particles.begin(), particles.end(), DoSomething());

would call either the normal STL for_each loop for a dynamic data structure
or, for a static data structure, would fully unroll the for_each loop in the
typical manner. I think this would be a great syntactic addition for MPL, but
that's not the point. Back to the "multiple sequence types" argument...

In their system, they used type vectors instead of type lists, because it is
easy to specify the _dynamic_ contents of each element. For instance, they
were working finite element analysis, so they might define the particles in
the system like this:

template<int N> struct ParticleArray {};

template<> struct ParticleArray<0> {
  Neutron particle; ParticleArray() : particle(...) {}
};

template<> struct ParticleArray<1> {
  Proton particle; ParticleArray() : particle(...) {}
};

// etc etc etc for 10,000 particles

Anyone want to figure out a typelist equivalent for this static data structure
with dynamic elements? I can't find a good one, and I think that justifies
the need for a type vector in MPL. I also think that typelists are
well-justified, so conclude what you may.

The proceedings for WCGP'02 haven't been published yet, but I'll try to
contact the author to get an electronic copy of the paper if anyone would
like to read it.

        Doug


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk