why does isForwardRange work like this?

Vlad Levenfeld via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Jul 31 13:34:41 PDT 2014


I've been having trouble propagating range traits for 
range-wrapper structs.

Consider this sample code:

struct Wrapper (R)
{
	R range;

	static if (isInputRange!R)
	{
		/* input range stuff */
	}
	static if (isForwardRange!R)
	{
		auto save () inout
		{
			return this;
		}

		static assert (isForwardRange!Wrapper); // <-- this fails
	}
}

making save @property makes it compile.

So I looked at the implementation of isForwardRange and now I am 
very confused about this condition:

is(typeof((inout int = 0)
     {
         R r1 = void;
         static assert (is(typeof(r1.save) == R));
     }));

What's the rationale behind stating the condition this way as 
opposed to, say,

is (typeof(R.init.save)) == R) || is ((typeof(R.init.save()) == R)

so that member fields as well as @property and non- at property 
methods will match, and what is the purpose of (inout int = 0)?


More information about the Digitalmars-d-learn mailing list