Proposal: Relax rules for 'pure'
Don
nospam at nospam.com
Wed Sep 22 23:57:28 PDT 2010
Robert Jacques wrote:
>>>>>> The point of the proposal is *not* to provide the weak guarantee.
>>>>>> It is to provide the strong guarantee in more situations.
>>>>> The problem from my point of view is that the programmer can not
>>>>> declare that a function should be 'strongly-pure' or 'weakly-pure'.
>>>>
>>>> Yes they can. They just need to declare the parameters to be immutable.
>>>
>>> What about value types?
>>
>> Value types are implicitly convertable to immutable, so they can be
>> strongly-pure.
>
> No their not. Remember, arrays and other structs are value types in the
> type system. Logically, they may be reference types, but as far as their
> type signature goes, they are value types.
>
>> The problem I think Robert is referring to is, a person cannot always
>> tell just from looking at a signature that a type is strongly-pure
>> qualified or not.
>
> And that you can not manually specify one or the other.
Yes you can. Just add const to the parameter declaration. This works
because const is transitive.
>
>> For example, is this function weak or strong?
>>
>> pure int foo(T t);
pure int foo(const T t);
is always strong pure, regardless of what T is.
More information about the Digitalmars-d
mailing list