[phobos] Pureness of enforce()
Jonathan M Davis
jmdavisProg at gmx.com
Fri Nov 12 10:52:28 PST 2010
On Friday, November 12, 2010 09:17:15 Andrei Alexandrescu wrote:
> 3. I'm not sure there will more pure functions than impure out there. If
> there are more impure functions, using enforce() becomes a net
> pessimization
Well, since few of them are likely to call globals or C functions, most of them
should theoretically be pure. The main problem we're likely to run into (I would
think) would be cases where functions are called which could be pure depending
on the implementation. For instance, front could be pure in many (probably most)
cases, but in others it can't be. It would be _huge_ to be able to reliably make
functions that use such functions pure in cases where they can be and non-pure
where they can't. The same would go for nothrow. Unfortunately, I think that
that that would currently mean having multiple versions of functions where they
use template constraints to determine whether the pure, nothrow, pure nothrow,
or non-pure non-nothrow version should be used (bleh). I wonder if we need some
kind of inout for pure and nothrow.
Ideally, we would make absolutely everything that can be pure (and/or nothrow)
pure (and/or nothrow). The lack of it makes using pure and nothrow in user code
a pain. At least with nothrow, you can catch all exceptions and then assert 0
that there weren't any (in cases where you're sure that there won't be any) -
though having to do so _is_ annoying - but you can't do that with pure.
- Jonathan M Davis
More information about the phobos
mailing list