opMixin or mixin function templates with convenience operator?

aliak something at something.com
Thu Dec 12 10:33:21 UTC 2019

So the interpolated dip thread got me thinking, and wondering if 
any time there's been a proposal for an opMixin? It can possibly 
be the hash tag symbol? And opMixin does what mixin does, and 
mixes the code in the spot.

struct interpolator {
   void opMixin!(string)() {

// globally declared interpolator
interpolator i;

--- code.d

import interpolation;

string str = i#"an ${interpolated} string";

Advantages over template mixins include that this has a return 
type so it can be used to create things out of the current 
context and give you something back.

auto html = json#q{ // compile error if invalid json
   "hello": "${variable}",
   "another: "${a + b}",

Another one is function mixin templates? So maybe that can be 
done with eponymous mixin templates?

mixin template i(string str) {
     string i() {
         return str;

string s = i#"someting";

If it can't be done eponymously then how about:

mixin string s(string str)() {
   // parse str
   return mixin(stuff);

You get the hygiene with # as I believe it's not used anywhere? 
And this enables string interpolation libraries that have the 
syntax that any or all of the dips that are being propose have.

- ali

More information about the Digitalmars-d mailing list