Aliasing arguments in the template parameter list of an is-expression

anonymous anonymous at example.com
Tue Mar 18 12:18:22 PDT 2014


On Tuesday, 18 March 2014 at 18:58:04 UTC, Meta wrote:
> On Tuesday, 18 March 2014 at 17:38:26 UTC, anonymous wrote:
[...]
>> Since left and right are alias parameters, you need "alias" in
>> the is expression, too:
>> ---
>> if (is(P == Pair!(left, right), alias left, alias right)
>>     && /* etc */)
>> ---
>
> Yes, my mistake. I also got an error about Pair!(1, 2) being 
> unable to be interpreted at compile time, so I changed left and 
> right to be types. The corrected example code:
>
> struct Pair(left, right) {}
>
> template Left(P)
> if (is(P == Pair!(left, right), left, right)
>     && is(left == int)
>     && is(right == int))
> {
>     //Error: undefined identifier left
>     alias Left = left;
> }
>
> void main()
> {
> 	alias test = Left!(Pair!(int, int));
> }
>
> Surprisingly, left and right are actually visible in the 
> subsequent is-expressions that test if they're int. However, 
> they are not available in the body. Is there a way around this?

See the rest of my message.


More information about the Digitalmars-d-learn mailing list