Thread overview | |||||
---|---|---|---|---|---|
|
October 01, 2017 mtaching types with static if | ||||
---|---|---|---|---|
| ||||
struct ArrayAccesssor(alias ptr, alias len) {} char * p; size_t len; ArrayAccesssor!(p,len) aa; template helper(Fields...) { static if (Fields.length == 0) enum helper = ""; else static if (is(typeof(Fields[0]) : ArrayAccesssor!(ptr,len),ptr, len)) //13 { pragma(msg, "ArrayAccesssor"); enum helper = helper!(Fields[1 .. $]); } else { pragma(msg, "else"); enum helper = helper!(Fields[1 .. $]); } } enum f = helper!(aa,len); What is the correct line 13 to make the instansiation of `helper!(aa,len)` print ArrayAccesssor else ? Thanks Nic |
October 01, 2017 Re: mtaching types with static if | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nicholas Wilson | On 10/01/2017 09:03 AM, Nicholas Wilson wrote:
> struct ArrayAccesssor(alias ptr, alias len) {}
>
> char * p;
> size_t len;
>
> ArrayAccesssor!(p,len) aa;
>
> template helper(Fields...)
> {
> static if (Fields.length == 0)
> enum helper = "";
>
> else static if (is(typeof(Fields[0]) : ArrayAccesssor!(ptr,len),ptr, len)) //13
> {
> pragma(msg, "ArrayAccesssor");
> enum helper = helper!(Fields[1 .. $]);
> }
> else
> {
> pragma(msg, "else");
> enum helper = helper!(Fields[1 .. $]);
> }
> }
>
> enum f = helper!(aa,len);
>
> What is the correct line 13 to make the instansiation of `helper!(aa,len)` print
>
> ArrayAccesssor
> else
>
> ?
else static if (is(typeof(Fields[0]) : ArrayAccesssor!(ptr,len),
alias ptr, alias len))
|
October 01, 2017 Re: mtaching types with static if | ||||
---|---|---|---|---|
| ||||
Posted in reply to ag0aep6g | On Sunday, 1 October 2017 at 07:21:57 UTC, ag0aep6g wrote:
> else static if (is(typeof(Fields[0]) : ArrayAccesssor!(ptr,len),
> alias ptr, alias len))
Ah, so close. Thanks!
|
Copyright © 1999-2021 by the D Language Foundation