Boost logo

Boost :

From: Tobias Schwinger (tschwinger_at_[hidden])
Date: 2006-05-09 12:04:31


Gerhard Wesp wrote:
> On http://tinyurl.com/qtyhh, you write:
>
> rational c = a / b // where a and b are integers a=1 b=2
> integer d = a / b // c is one half, d is zero
> [...]
> rational e = convert(a / b) // e is zero
>
> I guess this can be achieved by some clever expression template magic,
> but do you really want to go there?

It's like math with pen-and-paper, which still feels more intuitive to me
than whatever type-safe programming languages came up with, so far.

The code is more readable and more flexible. You don't have to be afraid
to break things when you change the type of a varaible, it either just
works or the problem is caught at compile time plus you don't have to change
around casts (as there usually are none required).

Expression templates are needed anyway to optimize away temporaries (the
paper you referenced in your previous post also mentions this opportunity).
Otherwise we end up with a "high performance interface" which makes our
optimized code look like as if we were coding in assembler (this aspect of
NTL is rather ugly, IMO).

> I've always tried to stick to the "do it as the ints" philosophy,
> which does have the problems you describe, but has the advantage of
> being consistent with the rest of the language.

The framework I propose is most certainly consistent with the language -
it just has its own conversion rules that are free of machine-centric
considerations ;-).

The inherent loose coupling of the classes that implement the domains
makes it very easy to extend the library (easier than what it takes to
implement proper conversion otherwise, I guess).

Further we can't really "do it as the ints", unfortunately -- temporary
ints can usually be optimized away while we can't teach our optimizers
to generally remove temporary "heavyweights" (we have to teach our
compilers, instead)...

Regards,

Tobias


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