mixin does not work as expected
vit
vit at vit.vit
Wed Jan 5 09:33:07 UTC 2022
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", "5"));
>> static if (true) {
>> mixin(overflow_check!"i8.min"); }
>> }
>> ```
>> is_same - is undefined
>> i8 - is undefined
>> overflow_check!"i8.min" - ?
>>
>>
>> This code with mixins is horrible :)
>
> Hi and thanks for your time. "pragma(msg, ...)" will indeed
> work but it will print the code in the standard output. Is
> there something that I'm missing?
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(""
+ 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", "i32", "true", "12", "10",
"34", "13")
+ type_check!("else", "i64", "true", "21", "18", "66", "24")
);
```
3) last type_checkin signed and unsigned part of function test
has else with condition.
```d
else(is_same!(num, i64)) {
mixin(base_digit!("21", "18", "66", "24"));
static if (true) {
mixin(overflow_check!"i64.min"); }
}
```
More information about the Digitalmars-d-learn
mailing list