On Saturday, 29 June 2024 at 23:33:41 UTC, solidstate1991 wrote:
My question is can I initialize structs like these in one line
without relying on a second line?
```d
template ValueOfUDAType(alias T, alias UDA) {
static foreach (uidx, U; __traits(getAttributes, T)) static if
(is(typeof(U) ==
On Saturday, 29 June 2024 at 23:33:41 UTC, solidstate1991 wrote:
My usecase scenario doesn't really allow constructors for the
struct, since it's a binding to an external library via C API.
BTW, this is not true. A constructor does not change the struct
layout or anything about it from the C
On Saturday, 29 June 2024 at 23:33:41 UTC, solidstate1991 wrote:
```d
union U {
int i32;
long i64;
float f32;
double f64;
}
struct S {
TypeEnum type;
U data;
}
S foo0 = S(TypeEnum.Integer32, S(20)); //Ugly, but works
S foo1 = S(TypeEnum.Integer64, S(20L)); //Error: cann
On Sunday, 30 June 2024 at 11:23:45 UTC, Nick Treleaven wrote:
On Saturday, 29 June 2024 at 23:33:41 UTC, solidstate1991 wrote:
S foo0 = S(TypeEnum.Integer32, S(20)); //Ugly, but works
S foo1 = S(TypeEnum.Integer64, S(20L)); //Error: cannot
Did you mean `U(20)`? The 20 applies to the first fi
On Saturday, 29 June 2024 at 23:33:41 UTC, solidstate1991 wrote:
S foo0 = S(TypeEnum.Integer32, S(20)); //Ugly, but works
S foo1 = S(TypeEnum.Integer64, S(20L)); //Error: cannot
Did you mean `U(20)`? The 20 applies to the first field of the
union, i32. `U(20L)` also works and (I think) it doe
On Saturday, 29 June 2024 at 23:33:41 UTC, solidstate1991 wrote:
[...]
My question is can I initialize structs like these in one line
without relying on a second line? My usecase scenario doesn't
really allow constructors for the struct, since it's a binding
to an external library via C API.
```d
union U {
int i32;
long i64;
float f32;
double f64;
}
struct S {
TypeEnum type;
U data;
}
S foo0 = S(TypeEnum.Integer32, S(20)); //Ugly, but works
S foo1 = S(TypeEnum.Integer64, S(20L)); //Error: cannot
implicitly convert expression
//ditto for the rest of the mem