Boost logo

Boost :

From: Daryle Walker (darylew_at_[hidden])
Date: 2000-10-10 12:55:41


I haven't written anything for this yet, but I was thinking of making a
certain kind of a numeric adapter class. It should support all the
arithmetic operations the base type supports.

The problem is the modulus operators. They should be defined only if the
base type is integral. I can check this from the base type's
std::numeric_limits implementation. The value should be a compile-time
constant, so I can use it as a template parameter.

So I could make one version of my adapter class that includes modulus
operations, and one that doesn't. But I want the end user to see only one
adapter class, which would secretly inherit(?) from one of the specialized
adapter classes (based on the numeric-limit compile-time constant). How
would I do it, or do I have to settle for a single adapter class without
modulus operations?

(I know this technique can work for template functions. For example, the
iterator std::distance function could specialize for different iterator
types by secretly calling another function that takes the iterator's type
tag as an extra argument. I'm asking for a similar technique for template
classes.)

-- 

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