On Mon, 21 Mar 2011 15:35:58 +0100, Steven Schveighoffer
<[email protected]> wrote:
Why does one make sense and the other not? In other words, if I have a
function like this:
int foo(int delegate() x) pure {...}
is this *ever* callable from a strong-pure function? Or does the
delegate have to be declared pure? It seems to me that either:
1) it's not ever callable from a strong-pure function, making the pure
decoration useless or
2) it's callable from a strong pure function, but then the compiler
needs to generate two copies of the function, one with a pure delegate,
one without.
On item 2, the reason I feel this way is in the case where foo wants to
pass the delegate to another pure function, it might optimize that call
differently if the delegate is known to be pure. Or maybe we
don't/can't care...
That is a good point. However, pure delegates should (but might not
currently) be implicitly castable to impure. Hence, one version, taking
an impure delegate, should be enough.
Moreover, I believe a pure delegate could only ever be weakly-pure, hence
precluding the use of aggressive optimizations.
If my first assumption is correct, and the latter is not, the problem
should only occur if you have two versions of a function, one taking a
pure delegate, the other taking an impure one.
--
Simen