[phobos] Pureness of enforce()

Steve Schveighoffer schveiguy at yahoo.com
Tue Nov 9 08:22:55 PST 2010


----- Original Message ----

> From: Robert Jacques <sandford at jhu.edu>
> 
> Well, long term, we need modifiers to  apply to delegates. i.e. it should be 
>possible to declare a pure delegate. (Or a  const delegate. Or an immutable 
>delegate. Or a shared delegate, etc.) For  example, right now, it's not possible 
>to (type-) safely use a delegate in shared  code. And David's std.parallelism is 
>a prime case where many methods could be  marked @safe instead of 
>@here_be_dragons if delegate modifiers  existed.

A pure delegate is not the same as a const, immutable, or shared delegate.

A const, immutable, or shared member function applies the const, immutable, or 
shared part to the hidden context pointer.  So I believe the modifier should be 
hidden as well.  What we do need at some point is for you to not be able to 
create such a delegate.

A pure function does not apply 'pure' to the context pointer or any other 
parameters, it applies directly to the function.  So I think we will need the 
pure modifier as part of the delegate type.  And I think that might solve the 
enforce problem.

@safe is similar to pure.

inout will be a weird one, because you don't know what the constancy of the 
hidden pointer is.  What we probably need is const inout, immutable inout, and 
mutable inout delegates.  Otherwise, the compiler cannot tell what to substitute 
for inout.

-Steve



      


More information about the phobos mailing list