www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - `with (TemplateInstance):` shoild work

reply Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> writes:
I just tried this:

template x() {
     void fun(int) {}
}

void main() {
     with (x!()) {
	    42.fun();
     }
}

It works, and it's a great way to inject UFCS symbols. But at best it 
should work with the colon syntax so it applies through the end of 
scope/module:

with (x!()):

void main() {
     42.fun();
}

Once that is possible, you get to inject UFCS symbols into a module with 
ease.
Aug 20 2020
next sibling parent reply Mathias LANG <geod24 gmail.com> writes:
On Friday, 21 August 2020 at 05:10:14 UTC, Andrei Alexandrescu 
wrote:
 with (x!()):

 void main() {
     42.fun();
 }

 Once that is possible, you get to inject UFCS symbols into a 
 module with ease.
Would the following suit your needs ? ``` template x() { void fun(int) {} } mixin x; void main() { 42.fun(); } ```
Aug 20 2020
parent Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> writes:
On 8/21/20 2:49 AM, Mathias LANG wrote:
 On Friday, 21 August 2020 at 05:10:14 UTC, Andrei Alexandrescu wrote:
 with (x!()):

 void main() {
     42.fun();
 }

 Once that is possible, you get to inject UFCS symbols into a module 
 with ease.
Would the following suit your needs ? ``` template x() {     void fun(int) {} } mixin x; void main() {     42.fun(); } ```
Ah, nice. Thanks!
Aug 21 2020
prev sibling parent Stefan Koch <uplink.coder googlemail.com> writes:
On Friday, 21 August 2020 at 05:10:14 UTC, Andrei Alexandrescu 
wrote:
 I just tried this:

 template x() {
     void fun(int) {}
 }

 void main() {
     with (x!()) {
 	    42.fun();
     }
 }

 It works, and it's a great way to inject UFCS symbols. But at 
 best it should work with the colon syntax so it applies through 
 the end of scope/module:

 with (x!()):

 void main() {
     42.fun();
 }

 Once that is possible, you get to inject UFCS symbols into a 
 module with ease.
You would need a DIP for the colon synatx. I would be in support of with: As for using template instances, yeah ... maybe not
Aug 21 2020