How to mixin finction name?

Boris Carvajal boris2.9 at gmail.com
Sun Apr 14 12:39:18 UTC 2019


On Sunday, 14 April 2019 at 12:00:38 UTC, Andrey wrote:
> On Sunday, 14 April 2019 at 11:44:16 UTC, Boris Carvajal wrote:
>> On Sunday, 14 April 2019 at 10:07:30 UTC, Andrey wrote:
> I want to mixin only name - not the full function code.

I think you can't do a partial statement in a mixin.
But this works by declaring pointers to functions and assigning a 
function literal to them.

import std.stdio;
void main()
{
     auto dg = (uint i){ writeln('a' , " - ", i); };
      enum letters = ['A', 'B', 'C'];
      static foreach(ch; letters)
      {
          mixin("void function(uint i) print" ~ ch ~ ";");
          dg = (uint i){ writeln(ch , " - ", i); };
          mixin("print" ~ ch ~ " = dg;");
      }

      printA(1);
      printB(2);
      printC(3);
}


More information about the Digitalmars-d-learn mailing list