Re: mixin does not work as expected

2022-01-10 Thread donalexinder24 via Digitalmars-d-learn
On Wednesday, 5 January 2022 at 09:33:07 UTC, vit wrote: On Wednesday, 5 January 2022 at 09:17:54 UTC, rempas wrote: [...] 1) That printed code on standard output is wrong, missing declaration for is_same and i8. 2) if-else must be in same mixin: ```d mixin("" +

Re: mixin does not work as expected

2022-01-05 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Jan 05, 2022 at 11:29:08PM +, Era Scarecrow via Digitalmars-d-learn wrote: [...] > That said, rolling your own mixins should really be the last resort. > You're dumping a lot into a single line of code you can't trace, > follow, debug, or look at. Mixins are kinda like the nuclear

Re: mixin does not work as expected

2022-01-05 Thread Era Scarecrow via Digitalmars-d-learn
On Wednesday, 5 January 2022 at 08:40:15 UTC, rempas wrote: I'm trying to use mixins and enums to "expand" code in place but the results are not what I expected and I'm getting an weird error. I have created the smallest possible example to reproduce the error and it is the following: Back

Re: mixin does not work as expected

2022-01-05 Thread rempas via Digitalmars-d-learn
On Wednesday, 5 January 2022 at 17:48:03 UTC, H. S. Teoh wrote: Yeah, this won't fly. Whatever you pass to mixin must be one or more *complete* declaration or (possibly compound) statements. It's illegal to pass the `static if` and its else-clause to two different mixin() invocations (they are

Re: mixin does not work as expected

2022-01-05 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Jan 05, 2022 at 08:40:15AM +, rempas via Digitalmars-d-learn wrote: [...] > void test(bool signed)(int num, int base) { > static if (signed) { > mixin(type_check!("static if", "i8", "true", "5", "4", "10", "5")); > mixin(type_check!("else static if", "i16", "true", "7", "6",

Re: mixin does not work as expected

2022-01-05 Thread rempas via Digitalmars-d-learn
On Wednesday, 5 January 2022 at 10:47:44 UTC, rempas wrote: There may be a problem in the "type_check" enum but I wanted to post this reply before I search any any case there is something else happening and you happen to know. I will update if I found it Well, it is specifically the "static

Re: mixin does not work as expected

2022-01-05 Thread rempas via Digitalmars-d-learn
On Wednesday, 5 January 2022 at 09:33:07 UTC, vit wrote: 2) if-else must be in same mixin: ```d mixin("" + type_check!("static if", "i8", "true", "5", "4", "10", "5") + type_check!("else static if", "i16", "true", "7", "6", "18", "8") + type_check!("else static if",

Re: mixin does not work as expected

2022-01-05 Thread vit via Digitalmars-d-learn
On Wednesday, 5 January 2022 at 09:17:54 UTC, rempas wrote: On Wednesday, 5 January 2022 at 09:02:53 UTC, vit wrote: Try this: ```d pragma(msg, type_check!("static if", "i8", "true", "5", "4", "10", "5")); ``` Result: ```d static if(is_same!(num, i8)) { mixin(base_digit!("5", "4", "10",

Re: mixin does not work as expected

2022-01-05 Thread rempas via Digitalmars-d-learn
On Wednesday, 5 January 2022 at 09:02:53 UTC, vit wrote: Try this: ```d pragma(msg, type_check!("static if", "i8", "true", "5", "4", "10", "5")); ``` Result: ```d static if(is_same!(num, i8)) { mixin(base_digit!("5", "4", "10", "5")); static if (true) {

Re: mixin does not work as expected

2022-01-05 Thread vit via Digitalmars-d-learn
On Wednesday, 5 January 2022 at 08:40:15 UTC, rempas wrote: I'm trying to use mixins and enums to "expand" code in place but the results are not what I expected and I'm getting an weird error. I have created the smallest possible example to reproduce the error and it is the following: [...]

Re: mixin does not work as expected

2022-01-05 Thread vit via Digitalmars-d-learn
On Wednesday, 5 January 2022 at 08:40:15 UTC, rempas wrote: I'm trying to use mixins and enums to "expand" code in place but the results are not what I expected and I'm getting an weird error. I have created the smallest possible example to reproduce the error and it is the following: [...]

mixin does not work as expected

2022-01-05 Thread rempas via Digitalmars-d-learn
I'm trying to use mixins and enums to "expand" code in place but the results are not what I expected and I'm getting an weird error. I have created the smallest possible example to reproduce the error and it is the following: ``` enum base_digit(string ten, string sixteen, string two, string