Re: Weird behavior with UDAs

2020-06-13 Thread Stanislav Blinov via Digitalmars-d-learn
On Saturday, 13 June 2020 at 13:08:29 UTC, realhet wrote: How can be a string represented with 'null' by default instead on `""`. Unless I state it explicitly with name="" ? o.O Because string is simply `alias string = immutable(char)[]`, and default initializer for arrays is null.

Re: Weird behavior with UDAs

2020-06-13 Thread realhet via Digitalmars-d-learn
On Saturday, 13 June 2020 at 12:55:36 UTC, realhet wrote: Hello, I have a problem I can't even understand with the code For the first I realized that an UDA can be a type too, and come up with this: template getUDA(alias a, U){ enum u = q{ getUDAs!(a, U)[$-1] }; static if(hasUDA!(a,

Re: Weird behavior with UDAs

2020-06-13 Thread Adam D. Ruppe via Digitalmars-d-learn
On Saturday, 13 June 2020 at 12:55:36 UTC, realhet wrote: My first question is, how to avoid that error with A.i4? Why is there a difference between @UNIFORM and @UNIFORM(), do the first returns a type and the later returns a value? Basically yeah. a UDA in D is just whatever you write gets

Weird behavior with UDAs

2020-06-13 Thread realhet via Digitalmars-d-learn
Hello, I have a problem I can't even understand with the code below: https://run.dlang.io/is/7yXAEA import std.stdio, std.range, std.algorithm, std.traits, std.meta; struct UNIFORM{ string name; } struct A{ int i1; @UNIFORM() int i2; @UNIFORM("fuzz") int i3; @UNIFORM int i4;