Boost logo

Boost :

Subject: Re: [boost] [integer] Type-safe and bounded integers with compile-time checking
From: Leif Linderstam (leif.ls_at_[hidden])
Date: 2011-09-06 14:33:27

Ben Robinson wrote 2011-09-05 21:57:
> ... I currently call it MetaBoundedInt, and the design philosophy
> was to provide both an overflow, and ranged checked integer, which leverages
> as much compile time information as possible to maximize performance, as
> well as communicate overflow/range errors at compile time when possible.

That seems to be more in line with how for instance Ada does it, which
probably means that it is a more reasonable approach than mine. That
said, part of the reason for me to start looking into this was some
sloppy use of integers within a project I joined and a fairly strict
environment would have helped.

> mbi<throwing_policy, int8_t, -8, 8> var2(0U); // Detects overflow and range

Why not go all the way and select an underlying int based on the given

> As you requested Leif, the throwing_policy can be replaced in a release
> build with an ignore_policy, so that these additional checks can be
> eliminated for maximum release build performance.

Then I was not clear enough. If a check cannot be made at compile-time I
want it to be done at runtime. I do want this type of library to be as
efficient as possible for better acceptance among developers, but my
main reason for wanting it to do static checks as much as possible is
to detect faults as early as possible, and to make it harder to write
that sloppy code.

Leif Linderstam

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