any news on const/invariant?

Walter Bright newshound1 at digitalmars.com
Wed Nov 28 21:27:35 PST 2007


Derek Parnell wrote:
> On Wed, 28 Nov 2007 23:02:06 -0500, Steven Schveighoffer wrote:
> 
>> If that method returns a const type, then the method is declared as:
>>
>> const const(Type) f();
>  
>> To someone who never used const before in another language, this isn't any 
>> less or more intuitive than the way C++ does it.  It's like saying using 
>> semicolons at the end of statements is intuitive.  It's just a different way 
>> of expressing what you want to the compiler.
> 
> Got it. When I see two adjacent "const" keywords I need to realize that the
> first const refers to the second 'thing' and the second const refers to the
> first 'thing'. Very intuitive.

To make a type const, you add parens:

	const(T)

So, to make a const function that returns a constant T:

	const(const(T) f())

The storage class const is just a shorthand for putting ( ) around the 
whole declaration.



More information about the Digitalmars-d mailing list