Template magic exercise
Jack Applegame
japplegame at gmail.com
Sun Mar 30 05:42:15 PDT 2014
Target is to create a template for mapping member "array
accessor" to member function.
For example:
class Foo {
...
int elementsAccessor(size_t index) { ... }
...
mixin MagicTemplateMixin!("elements", elementsAccessor);
// or better
alias elements = SuperMagicTemplate!elementsAccessor;
}
and now we can call Foo.getter like this:
auto foo = new Foo;
int el = foo.elements[10]; // int el = foo.getter(10);
I wrote poor and ugly solution with proxy structure:
http://dpaste.dzfl.pl/93085910f8c7
I hate it. :)
I need more powerful spell, but my magic level is too low.
More information about the Digitalmars-d-learn
mailing list