const/immutable member functions

spir denis.spir at gmail.com
Tue Jan 25 04:26:14 PST 2011


On 01/25/2011 10:45 AM, Jens Mueller wrote:
> I distinguish the following:
> type qualifiers: const, immutable, maybe also inout
> function attributes: pure, nothrow
> storage class: ref, in, out, static
> access qualifiers: private, package, protected, public, export

Nice & clear classification. Then, if you allow replacing "attribute" and 
"class" by "qualifier" (which by the way both are somewhat confusing because of 
other common meanings), you get a super-class of qualifiers.
All are put aside a name which can denote a plain var, a type etc... Only in 
case of function they can be prefixed to the whole signature, which creates 
ambiguity with the return type:
	const int square (int x) {...}	// func or return type?

The obvious consistent choice, imo, would be to place them aside the function name:
	int const square (int x) {...}
	const int square (int x) {...}
	const int const square (int x) {...}
but indeed would be a syntactic revolution ;-)

Another solution would be to enforce parentheses except in the case of function:
	const int square (int x) {...}	// func
	const(int) square (int x) {...}	// return type

Denis
-- 
_________________
vita es estrany
spir.wikidot.com



More information about the Digitalmars-d mailing list