Boost logo

Boost :

Subject: Re: [boost] [integer] Type-safe and bounded integers with compile-time checking
From: Mathias Gaunard (mathias.gaunard_at_[hidden])
Date: 2011-09-06 04:30:34


On 05/09/2011 21:27, Leif Linderstam wrote:

> My first go at this was that if the result range cannot be represented by
> any fundamental int type a compile time error is issued. My latest
> thoughts though are that the library should instead allow for multi-sized
> integers, which then of course touches on the current work of Christopher
> Kormanyos. In the original post I said that the range type should accept
> types as bounds instead of integers; this is the reason. With types there
> we can specify really big ranges.

A typed approach prevents iterative programming somewhat, since each
operation would yield an object of a different type.

You can't write
a = 0;
while(some_cond)
   a += something;

You have to write it as a fold.

If it's just to ensure overflow doesn't happen, wouldn't it be better to
make all of the checking happen at runtime, and disable it in NDEBUG builds?


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