mixin template's alias parameter ... ignored ?
Steven Schveighoffer
schveiguy at gmail.com
Sun Jul 11 13:14:23 UTC 2021
On 7/11/21 8:49 AM, Adam D Ruppe wrote:
> On Sunday, 11 July 2021 at 05:20:49 UTC, someone wrote:
>> ```d
>> mixin template templateUGC (
>> typeStringUTF,
>> alias lstrStructureID
>> ) {
>>
>> public struct lstrStructureID {
>>
>> typeStringUTF whatever;
>>
>> }
>
>
> This creates a struct with teh literal name `lstrStructureID`. Just like
> any other name. So it is NOT the value of the variable.
>
>> ```d
>> public struct mixin(lstrStructureID) { ... }
>> ```
>>
>> because the argument seems to require a complete statement.
>
> Indeed, you'd have to mixin the whole thing like
>
> mixin("public struct " ~ lstrStructureId ~ " { ... } ");
when I've done this kind of stuff, what I usually do is:
```d
struct Thing {
... // actual struct
}
mixin("alias ", lstrStructureID, " = Thing;");
```
the downside is that the actual struct name symbol will be `Thing`, or
whatever you called it. But at least you are not writing lots of code
using mixins.
-Steve
More information about the Digitalmars-d-learn
mailing list