Algorithms should be free from rich types

Richard (Rikki) Andrew Cattermole richard at cattermole.co.nz
Wed Jun 28 17:06:43 UTC 2023


Oh how you dare me.

--- app.d
module app;
import foo;
void main()
{
     Foo foo = new Foo;
     foo.privateGet!"i" = 2;
     foo.say();
}

ref privateGet(string name, From)(ref From from) {
     static foreach(I; 0 .. from.tupleof.length) {
         {
             enum Name = __traits(identifier, from.tupleof[I]);

             static if (Name == name) {
                 return from.tupleof[I];
             }
         }
     }

     assert(0);
}

--- foo.d
module foo;
class Foo {
     void say() {
         import std.stdio;
      	writeln(i);
     }

private:
     int i;
     bool b;
}


More information about the Digitalmars-d mailing list