Coming back, Unique, opDot and whatever else
    Stanislav Blinov 
    stanislav.blinov at gmail.com
       
    Fri Jan 17 23:18:22 PST 2014
    
    
  
On Friday, 17 January 2014 at 20:25:37 UTC, Stanislav Blinov 
wrote:
> Heh, now I'm even more leaning towards a proxy. Because 
> honestly, x.opDispatch!("release")() is even uglier than 
> x.opDot().release() :D...
Well, what can I say? I didn't need to go very far. Because 
Phobos has such proxy. Which is called std.typecons.Proxy :) I 
skimmed over it in the docs several times, probably because the 
docs just say "Make proxy for a." without going into much detail. 
But the last time I spotted it, associative memory kicked in, I 
guess, and I stayed a bit longer to actually look at the example.
There is, however, at least one issue with it: template arguments 
are not forwarded properly:
---
class Widget {
   auto inconsistent(T...)(T args) if (T.length) { return args[0]; 
}
}
auto widget = new Widget;
widget.inconsistent("hello", 10, 20); // works
auto uwidget = createUnique!Widget();
uwidget.inconsistent("hello", 10, 20); // Error: template 
instance inconsistent!() does not match template declaration 
inconsistent(T...)(T args) if (T.length)
uwidget.inconsistent!(string,int,int)("hello", 10, 20); //works
---
I hadn't had a chance for a closer inspection yet as to why 
though. In any case, that Proxy is a nice thing to have in the 
library!
    
    
More information about the Digitalmars-d-announce
mailing list