The Comma Operator's Deprecation Can't Come Soon Enough

Frustrated via Digitalmars-d digitalmars-d at puremagic.com
Tue Jul 15 09:01:35 PDT 2014


On Tuesday, 15 July 2014 at 08:01:40 UTC, Meta wrote:
> Spot the bug:
>
> template flattenedType(R, uint depth = uint.max)
> if (isInputRange!R)
> {
> 	static if (depth > 0)
> 	{
> 		static if (!isInputRange!(typeof(R.init.front)))
> 		{
> 			alias flattenedType = typeof(R.init.front, depth - 1);
> 		}
> 		else
> 		{
> 			alias flattenedType = flattenedType!(typeof(R.init.front), 
> depth - 1);
> 		}
> 	}
> 	else
> 	{
> 		alias flattenedType = typeof(R.init.front);
> 	}
> }
>
> I'll give you a hint: the bug causes flattenedType!R to always 
> returned uint.

This isn't a bug! It's a logic mistake.

Why the heck would you have such a line anyways?

alias flattenedType = typeof(R.init.front, depth - 1);

The 2nd "argument" to typeof makes no sense. It shouldn't be on 
that line at all. Total fail by the programmer.





More information about the Digitalmars-d mailing list