Boost logo

Boost :

From: Vesa Karvonen (vesa.karvonen_at_[hidden])
Date: 2001-06-26 04:42:26


From: "Larry Evans" <jcampbell3_at_[hidden]>
> Vesa Karvonen wrote:
> > Anyway, I'm interested in seeing plausible uses of template template
> > parameters. I think that this subject might be more appropriate for a C++
> > newsgroup, except that I'm mainly interested in seeing actual use of
template
> > template parameters in existing libraries.
>
> The smart pointer garbage collection classes in the zip files in:
> http://groups.yahoo.com/group/boost/files/GarbageCollectByTmplSpecializa/
> use template template parameters. I'd be interested in knowing if they can
> be avoided.

I think that at least any class template design that uses template template
parameters, but doesn't use partial specialization, can be (mechanically)
transformed into a design that doesn't use template template parameters.

I'm interested to know of any problems with the following transformation (I
developed it while writing this e-mail and it probably is not correct) and
whether it can be extended for partial specialization and/or function
templates.

The transformation to remove template template parameters consists of the
following sub-transformations:

1. Every class template (both member templates and namespace templates) is
wrapped inside a non-template class like this:

    // original
    template<...>
    struct an_arbitrary_class_name
     ...
    {...};

    // transformed
    struct an_arbitrary_class_name
    {
      template<...>
      struct some_standard_identifier
       ...
      {...};
    };

(This transformation obviously stops when all class templates are member
templates and have the name "some_standard_identifier".)

2. Every (partial or full) instantiation of a class template is transformed to
use the "some_standard_identifier" member template:

    // original
    an_arbitrary_class_name<...>

    // transformed
    an_arbitrary_class_name::/*template*/ some_standard_identifier<...>

3. Every template template parameter is transformed into a type parameter:

(At this point all class templates are named "some_standard_identifier".)

    // original
    template<... template<class> class p ...>
    struct some_standard_identifier
      ...
    { ... };

    // transformed
    template<... class p ...>
    struct some_standard_identifier
      ...
    { ... };

This completes the transformation.

> > These techniques are quite powerful. For instance, I'm using lists that
>
> This technique was also used in the subjprox_vec and subjprox_one templates
> in GarbageCollectByTmplSpecializa to enable the smart pointer analog to
> vector of vectors and pointers to pointers.

The code seems quite interesting. I need to take a closer look at it.


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