module - Bringing items in a template instantiation scope unqualified into local scope -


i want bring unqualified names of functions in template working/local scope. eg.:

struct st {     int t = 44; }  template inter(t) { // 'base' template/interface/parameterized-module     alias self = t;      void myfunc(ref self) {         writeln("inter: ", self.stringof, " : ", 11);     } }  template inter(t: st) {       /+ ^^^^^ 'specialization'          implementation template-module type `st`       +/     alias self = t;      void myfunc(ref self self) {         writeln("inter 2 (st)! : ", self.stringof, " : ", self.t);     } }  void main(string[] args){     st s;      /+  here  +/      /+  s.myfunc(s);  +/ // <- want able } 

something mixin template work @ cost of lots of needless code duplication (i wouldn't duplicating compiler would have work lots of same code).

put way: yes, ufcs not work in case if bring myfunc(self) scope of main(). question how bring stuff inside template's scope openly/unqualified scope? or yet way: imagine i'm making nested module (i don't know how this) that's inside mixin template, instantiating mixin type want, importing in mymodule_templ!mytype working scope.

ask clarifications in comments please. questions seldom readable on first formulation of them. thanks!

you mentioned mixin template maybe tried , didn't work.... you're asking mixin template does:

import std.stdio;  struct st {     int t = 44; }  // needs declared mixin template mixin template inter(t) {     alias self = t;      void myfunc(ref self) {         writeln("inter: ", self.stringof, " : ", 11);     } }  // overload mixin template.... mixin template inter(t: st) {     alias self = t;      void myfunc(ref self self) {         writeln("inter 2 (st)! : ", self.stringof, " : ", self.t);     } }   mixin inter!st; // , mix in current scope  void main(string[] args){     st s;      s.myfunc(); // boom, works! } 

you mix in main, ufcs won't work there because ufcs doesn't consider local symbols, wouldn't work if hand-wrote function either. looks @ module level.

so mixin keyword import functionality you're looking for.... unless misunderstood question.


Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -