Boost logo

Boost :

From: Dave Steffen (dgsteffen_at_[hidden])
Date: 2006-06-01 19:00:32

 (A voice from the sidelines...)

David Abrahams writes:
> Sebastian Redl <sebastian.redl_at_[hidden]> writes:
> > Marsh J. Ray wrote:
> >
> >>Seems to me that, if the author is really set on using inheritance here,
> >>integer should inherit from unsigned_integer, since integer can do
> >>everything that an unsigned can do, but not vice-versa. Integer extends
> >>unsigned with the ability to represent negative values and the result of
> >>subtraction.
> >>
> >>
> > No, that's not true. (See Scott Meyers, Effective C++, Item 35) If a
> > signed integer IS-A unsigned integer, then all invariants of unsigned
> > integer must hold true for signed integer - including the one about
> > negative values. ("There's no such thing.")
> IMO the whole idea of using inheritance here is so misguided in the
> first place that which order you do it in is probably not worth
> arguing about.

 I agree, but turn it around; this is another point in favor of not
 using inheritance at all.

 Signed can't inherit from unsigned, as stated above. But unsigned
 can't inherit from signed, since signeds can be negative, so an
 unsigned is-NOT-a signed. This is the classic "squares and
 rectangles can't derive from each other" situation.

 If you really wanted to use inheritance, both would have to inherit
 from a base class. I suspect that most (maybe all) of the operations
 would have to be virtual, with all the attendant design and
 performance issues that implies.

 I'm with many other here, in thinking that there's no need for an
 unsigned infinite integer. Make it signed, and make it do as the
 ints do. No inheritance, no templates, no muss, no fuss, simple,
 fast, easy to understand, easy to maintain.

 Also note that Boost libraries can change. An unsigned version could
 be added later, _after_ you've got use cases for it. Start with the
 simple thing.

<lurk mode on>

Dave Steffen, Ph.D. Fools ignore complexity.
Software Engineer IV Pragmatists suffer it.
Numerica Corporation Some can avoid it.
ph (970) 419-8343 x27 Geniuses remove it.
fax (970) 223-6797 -- Alan Perlis
dgsteffen at numerica dot us

Boost list run by bdawes at, gregod at, cpdaniel at, john at