Re: Scope of Mixins

2021-08-26 Thread Adam D Ruppe via Digitalmars-d-learn
On Thursday, 26 August 2021 at 19:31:54 UTC, DLearner wrote: if (typeof(v).stringof == "int" ) { Tip: you can instead of string of do if (is(typeof(v) == int)) That is operator lets you compare types directly. (stringof is something you will almost never use as you learn more of the

Re: Scope of Mixins

2021-08-26 Thread DLearner via Digitalmars-d-learn
On Thursday, 26 August 2021 at 16:28:22 UTC, Adam D Ruppe wrote: On Thursday, 26 August 2021 at 16:16:55 UTC, DLearner wrote: Please confirm that mixins of format: You really shouldn't use string mixins like this at all. If you want to work with a variable, pass the variable itself as an

Re: Scope of Mixins

2021-08-26 Thread Adam D Ruppe via Digitalmars-d-learn
On Thursday, 26 August 2021 at 18:07:48 UTC, Ali Çehreli wrote: In some cases it's more useful to have a 'static if' inside a single function template instead of two separate function templates. In most cases that's better. A template constraint is really a way to say "this template cannot

Re: Scope of Mixins

2021-08-26 Thread Ali Çehreli via Digitalmars-d-learn
On 8/26/21 10:45 AM, Adam D Ruppe wrote: On Thursday, 26 August 2021 at 17:39:16 UTC, Ali Çehreli wrote: String mixins are appealing because they can inject code like C macros do. It's not trivially possible to do the same with template mixins. Template mixins are great, but obviously totally

Re: Scope of Mixins

2021-08-26 Thread Adam D Ruppe via Digitalmars-d-learn
On Thursday, 26 August 2021 at 17:39:16 UTC, Ali Çehreli wrote: String mixins are appealing because they can inject code like C macros do. It's not trivially possible to do the same with template mixins. Template mixins are great, but obviously totally inappropriate here. I'm just talking

Re: Scope of Mixins

2021-08-26 Thread Ali Çehreli via Digitalmars-d-learn
On 8/26/21 10:06 AM, Adam D Ruppe wrote: On Thursday, 26 August 2021 at 17:01:06 UTC, DLearner wrote: The object was to take a variable, and do alternative things with it depending on (say) whether it was an 'int' or an 'int*'. That's *very* easy to do with the alias. You can just check

Re: Scope of Mixins

2021-08-26 Thread Adam D Ruppe via Digitalmars-d-learn
On Thursday, 26 August 2021 at 17:01:06 UTC, DLearner wrote: The object was to take a variable, and do alternative things with it depending on (say) whether it was an 'int' or an 'int*'. That's *very* easy to do with the alias. You can just check `typeof(v)` in there.

Re: Scope of Mixins

2021-08-26 Thread DLearner via Digitalmars-d-learn
On Thursday, 26 August 2021 at 16:28:22 UTC, Adam D Ruppe wrote: On Thursday, 26 August 2021 at 16:16:55 UTC, DLearner wrote: Please confirm that mixins of format: You really shouldn't use string mixins like this at all. If you want to work with a variable, pass the variable itself as an

Re: Scope of Mixins

2021-08-26 Thread Adam D Ruppe via Digitalmars-d-learn
On Thursday, 26 August 2021 at 16:16:55 UTC, DLearner wrote: Please confirm that mixins of format: You really shouldn't use string mixins like this at all. If you want to work with a variable, pass the variable itself as an argument to the function and use it with regular code instead of

Re: Scope of Mixins

2021-08-26 Thread Paul Backus via Digitalmars-d-learn
On Thursday, 26 August 2021 at 16:16:55 UTC, DLearner wrote: Please confirm that mixins of format: ``` string mxn1(string VarName) { ... } ``` Invoked like: ``` mixin(mxn1("Var1")); ``` Have a wider scope than mixins like: ``` string mxn2(string VarName)() { ... } ``` In

Scope of Mixins

2021-08-26 Thread DLearner via Digitalmars-d-learn
Please confirm that mixins of format: ``` string mxn1(string VarName) { ... } ``` Invoked like: ``` mixin(mxn1("Var1")); ``` Have a wider scope than mixins like: ``` string mxn2(string VarName)() { ... } ``` Invoked like: ``` mixin(mxn2!"Var2"); ``` I tried direct r