|
Boost : |
From: John Maddock (John_Maddock_at_[hidden])
Date: 2000-10-11 06:25:45
Daryl,
>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?
What about the "curiously recursive template trick"?
template <class T>
class myclass : public myclass_base<myclass<T>,
std::numeric_limits<T>::is_integer >
{
/* details*/
};
The base class would declare the relavent operators as friends, only if the
second parameter is true (ie partial specialisation), see operators.hpp for
examples.
- John.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk