any news on const/invariant?
David Gileadi
foo at bar.com
Tue Nov 27 12:03:21 PST 2007
Bill Baxter wrote:
> Janice Caron wrote:
>> On Nov 27, 2007 9:13 AM, Walter Bright <newshound1 at digitalmars.com>
>> wrote:
>>> Think of it this way:
>>>
>>> const A f()
>>>
>>> means:
>>>
>>> const (A f())
>>>
>>> which applies the const to the function f, not A.
>>
>> Ah, but the natural interpretation of const(...) is that /everything/
>> inside the brackets is const. Thus, if I write
>>
>> const(void f(char[] b))
>>
>> that "suggests" to me that b is const, since it is inside (albeit
>> deeply inside) the const(...) brackets. But I only want f's "this" to
>> be const, not b. Perhaps this is a case where "const at the end"
>> creates a more helpful mneumonic?
>
>
> What if it were
>
> const() A f() {...}
>
> or const(this) A f() {...}
>
> ?
>
> --bb
While maybe a bit of typing, I really like the const(this) form--its
intent is very clear IMHO. And
const(this)
{
int foo();
int bar();
}
isn't too bad either.
More information about the Digitalmars-d
mailing list