Return by 'ref' problems...

H. S. Teoh hsteoh at quickfur.ath.cx
Fri May 4 06:53:32 PDT 2012


On Fri, May 04, 2012 at 01:46:21AM -0700, Jonathan M Davis wrote:
> On Friday, May 04, 2012 11:38:32 Manu wrote:
> > I try rearranging the syntax to make the first issue stop complaining:
> > 
> > ref const(Thing) func2() { return gThing; } // this seems to work now, but
> > i don't like the inconsistency...
> 
> That's thanks to the nonsense that putting const on the left-hand side
> of a member function is legal, making it so that you _must_ use parens
> with const and return types for the const to apply to the return type
> rather than the function.

Yeah, I've recently started building the habit of always using
parentheses with const applied to a type, in order to make it less
confusing with const as applied to a function. Even though it's legal to
write:

	int func(const T t) {...}

nowadays I prefer to write:

	int func(const(T) t) {...}

so that when you need to return const, the syntax is more consistent:

	const(T) func(const(T) t) {...}

and it doesn't visually clash so much with const as applied to the
function itself:

	const(T) func(const(T) t) const {...}

This is one of the warts in D syntax that I find annoying.


T

-- 
"I'm running Windows '98." "Yes." "My computer isn't working now." "Yes, you already said that." -- User-Friendly


More information about the Digitalmars-d mailing list