Boost logo

Boost :

From: David A. Greene (greened_at_[hidden])
Date: 2002-08-17 09:53:17


Jaakko Jarvi wrote:

>>Yes, of course you have to know the names -- but only the
>>_implementation_ need know those names, right? Hence my
>>diversion into the pimpl analogy.
>
> Ok, I think I understand what you mean.
>
> Say we have our car template, which has a fixed set of features.
> In the case it's instantiated directly from client code, the programmer
> does know the number of features too.
> But it might get instantiated indirectly from some generic function, which
> doesn't necessarily know anything about the car template, (it could maybe
> be just a template template parameter).

That's one possible scenario. I was thinking more about something
like this:

template<typename Params>
class car : public car_impl<Params> {
    typedef car_impl<Params> car_base;
    // ...
public:
    void drive(void) {
       // ...
       car_base::shift(); // Needs to know tranny
       // ...
    };
    // ...etc.
};

Class car is then just a functional interface to the car -- it
doesn't really care what color the car is or even if the car
_has_ a color. If car does want to know something about the
parameters, it can get it from car_impl, but it need not know
about all of the parameters, just the ones it is interested in.

This doesn't give the same compiler firewall as pimpl,
unfortunately, which is why I say it may not be all that useful.
It does separate out the interface from the details for the
user, however.

It's true that during instantiation, the user probably has
to know about at least some of the parameters to car_impl
unless a generator or some simpler mechanism is involved.
In any event, a typelist just seems more flexible to me.
Perhaps that flexibility comes at too high a cost. On the
other hand, that complexity can be hidden with a wrapper
(more on this below).

Typelists also have the nice property that template template
parameters are less of a problem. Default template parameters
really mess things up in that area.

Of course, one style of NTP can always be implemented on
top of the other. I just feel that it's easier to wrap
a typelist implementation with a scalar interface than the
other way around since the typelist version doesn't require
Model_is, etc. It's interesting that this is exactly what
C&E did in their NTP implementation. They also use a form
of ntp<> (TypeTemplParam<>), which serves as a base to little
classes that act like Model_is (ValueType<>, etc.).

                      -Dave

-- 
"Some little people have music in them, but Fats, he was all music,
  and you know how big he was."  --  James P. Johnson

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