digitalmars.D.learn - Looking for a workaround
- Guillaume Piolat (35/35) Apr 06 2022 This program fails to build:
- Adam D Ruppe (29/30) Apr 06 2022 Works fine if you just use the language instead of the buggy
- Guillaume Piolat (2/32) Apr 06 2022 Thanks, it will also create less templates.
- MoonlightSentinel (3/5) Apr 07 2022 Use a frontend >= dmd 2.099, it works according to run.dlang.io.
- Guillaume Piolat (3/8) Apr 07 2022 Good to know, thanks.
This program fails to build:
import std.traits: getSymbolsByUDA;
struct MyUDA
{
}
class A
{
MyUDA int a;
}
class B : A
{
MyUDA int b;
}
void main()
{
alias G = getSymbolsByUDA!(B, MyUDA);
}
Output:
c:\d\ldc2-1.28.0-windows-multilib\bin\..\import\std\traits.d(8933): Error:
template
instance `AliasSeq!(b, a)` `AliasSeq!(b, a)` is nested in
both `B` and `A`
c:\d\ldc2-1.28.0-windows-multilib\bin\..\import\std\traits.d(8707): Error:
template
instance `std.traits.getSymbolsByUDAImpl!(B, MyUDA, "b", "a",
"toString", "toHash",
"opCmp", "opEquals", "Monitor", "factory")` error
instantiating
main.d(19): instantiated from here:
`getSymbolsByUDA!(B, MyUDA)`
Failed:
["c:\\d\\ldc2-1.28.0-windows-multilib\\bin\\ldmd2.exe", "-v",
"-o-", "main.d", "-I."]
Any idea how to workaround that? I really need the same UDA in
parent and child class.
Apr 06 2022
On Wednesday, 6 April 2022 at 18:10:32 UTC, Guillaume Piolat wrote:Any idea how to workaround that?Works fine if you just use the language instead of the buggy phobos wrappers: --- struct MyUDA { } class A { MyUDA int a; } class B : A { MyUDA int b; } void main() { foreach(memberName; __traits(allMembers, B)) foreach(attr; __traits(getAttributes, __traits(getMember, B, memberName))) static if(is(attr == MyUDA)) pragma(msg, memberName); // a, b } --- So make a function that does that and applies whatever it is you need to apply and you're in business. Note that it is `is(typeof(attr) == MyUDA)` if defined ` MyUDA(args)`.
Apr 06 2022
On Wednesday, 6 April 2022 at 18:21:11 UTC, Adam D Ruppe wrote:On Wednesday, 6 April 2022 at 18:10:32 UTC, Guillaume Piolat wrote:Thanks, it will also create less templates.Any idea how to workaround that?Works fine if you just use the language instead of the buggy phobos wrappers: --- struct MyUDA { } class A { MyUDA int a; } class B : A { MyUDA int b; } void main() { foreach(memberName; __traits(allMembers, B)) foreach(attr; __traits(getAttributes, __traits(getMember, B, memberName))) static if(is(attr == MyUDA)) pragma(msg, memberName); // a, b } --- So make a function that does that and applies whatever it is you need to apply and you're in business. Note that it is `is(typeof(attr) == MyUDA)` if defined ` MyUDA(args)`.
Apr 06 2022
On Wednesday, 6 April 2022 at 18:10:32 UTC, Guillaume Piolat wrote:Any idea how to workaround that? I really need the same UDA in parent and child class.Use a frontend >= dmd 2.099, it works according to run.dlang.io.
Apr 07 2022
On Thursday, 7 April 2022 at 12:56:05 UTC, MoonlightSentinel wrote:On Wednesday, 6 April 2022 at 18:10:32 UTC, Guillaume Piolat wrote:Good to know, thanks.Any idea how to workaround that? I really need the same UDA in parent and child class.Use a frontend >= dmd 2.099, it works according to run.dlang.io.
Apr 07 2022









Guillaume Piolat <first.last gmail.com> 