Boost logo

Boost :

From: Eric Ford (eford_at_[hidden])
Date: 2001-09-05 00:48:47

> There needs to be a way to tell the library (at compile time) to
> the checks, because this sort of library is likely to be used in
> compute-bound contexts where checking beforehand that all initial
> are in a known stable region of the problem space, and then running
> whole thing with no further checking, can be an order of magnitude
> faster than checking along the way. If you insist on checking all
> function arguments, you lose a lot of potential users.

This is very true. I normally deal with this by having two versions
of each function: foo_safe(...) and foo_unsafe(...). foo_safe would
be implemented in terms of foo_unsafe, but include extra checks. For
convience, you can define a foo(...) which calls whichever you want to
be the default (for me, foo_safe during testing, foo_unsafe during
running). Another option is to use if...throw's in the safe version
and include assert statements in even the unsafe code, since that can
be easily disabled once the code is ready for real use.

One potentail problem is what if the user can only guarentee some of
the checks (e.g. the most expensive one), but not all of the
guarentees necessary (e.g. the nearly trivial and quick to test
ones)? In the past, I've just used foo_unsafe2(...) for this type of
thing, but it's not very elegant.

Has someone thought of a better way to address this important issue?


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