Testing for template argument being result of takeExactly

Timon Gehr timon.gehr at gmx.ch
Sun Sep 23 09:14:51 PDT 2012


On 09/23/2012 03:48 PM, Andrei Alexandrescu wrote:
> On 9/23/12 8:47 AM, Timon Gehr wrote:
>> import std.range, std.traits;
>> import std.stdio;
>> template Hello(R) if(is(typeof(R._input.takeExactly(2)) == R)){
>>     alias R Hello;
>> }
>
> That's the nicest.

Well, I noticed it is not entirely correct as takeExactly special cases
sliceable inputs. Therefore, the guard also passes for ranges that have
a sliceable member called _input of the same range type. The correct
guard therefore would be:

if(hasSlicing!R || is(typeof(R._input.takeExactly(2)) == R))

or

if(!hasSlicing!R && is(typeof(R._input.takeExactly(2)) == R))

depending on what the goal is.


> Regarding availability of "_input", I meant to make
> it available systematically as "input" for ranges where the notion makes
> sense.
>
> Andrei

This seems to be reasonable.


More information about the Digitalmars-d-learn mailing list