variadic mixin templates and other stuff

Martin Drasar drasar at ics.muni.cz
Fri Apr 20 07:56:54 PDT 2012


On 20.4.2012 16:09, Timon Gehr wrote:

Thanks Timon for the answer.

>> My questions are following:
>> - can mixin templates be used this way?
> 
> They can only mixin declarations.
> 
>> - why are they complaining?
> 
> Because if is a statement and not a declaration.

Ok.

>> - is there a better way to do this other than reproducing C macros?
>>
> 
> Inline EXPOSE_INTERFACE into EXPOSE_INTERFACES and it'll work.

I tried but it still refuses to compile:

string interfaceGuid(string ifaceName)
{
  return ifaceName ~ "Guid";
}

mixin template EXPOSE_INTERFACES(T...)(T args)
{
  void QueryInterface(ref IComponent comp, string guid)
  {
    foreach (arg; args)
    {
      if (mixin(interfaceGuid(arg)) == guid) {}
    }
  }
}

component.d(6): members of template declaration expected
component.d(6): Declaration expected, not '('
component.d(10): no identifier for declarator args
component.d(10): semicolon expected, not ')'
component.d(10): Declaration expected, not ')'

I am compiling it with dmd v2.058.

Martin


More information about the Digitalmars-d-learn mailing list