Boost logo

Boost :

From: Bill Seymour (bill-at-the-office_at_[hidden])
Date: 2003-07-19 07:59:22

I've been thinking about the related issues of whether decimal
should be a template and whether the scale should be immutable.

First, I'm adamant that the user should be able to write

  dollars = foo;

without magically losing pennies or gaining mils; and I don't
think the user should have to type something like


as a workaround to get that behavior.

Given that, then as Daryle has correctly pointed out, standard
library sequence collections of decimals, and mutating algorithms
that work on sequences of decimals, don't work right unless all
objects in the sequence have the same scale. This issue of
"working right" must be addressed before we worry about efficiency
or the size of the objects.

1. The scale could be part of the type (decimal becomes a class

2. A warning could be put in the documentation that says that
    storing decimals of different scales in the standard collections
    yields undefined behavior.

3. I could try to work some other kind of magic.

The main difference I see between 1 and 2 is whether it's possible
for the user to make the mistake. In neither can we have collections
of different scales; but I now think that ought to be allowed if
there's some way I can make it work. (Note, for example, that with
either of the first two solutions, 1, 1.2 and 1.23 can't be sorted!)
So I'd like to try 3, at least as a mind experiment, before deciding
on 1 or 2.

Note that copy construction works correctly; it's just assignment
that has the perverse behavior.

Let's say I specialize std::swap() to swap scale as well as value,
and then specialize other standard algorithms to use swap where
they might otherwise use assignment. Have I done enough?

--Bill Seymour

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