www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - mtaching types with static if

reply Nicholas Wilson <iamthewilsonator hotmail.com> writes:
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
Oct 01 2017
parent reply ag0aep6g <anonymous example.com> writes:
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))
Oct 01 2017
parent Nicholas Wilson <iamthewilsonator hotmail.com> writes:
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!
Oct 01 2017