On Monday, 7 October 2024 at 09:22:20 UTC, Nick Treleaven wrote:
> On Monday, 7 October 2024 at 08:05:59 UTC, ryuukk_ wrote:
> I'm working on it TODAY, therefore i need a today's solution
import std.typecons;
struct EntityDef
{
Tuple!(int, "hp") stats;
}
void main()
{
EntityDef ed;
int x = ed.stats.hp;
}
Okay, i notice a pattern with Dlang
We went from trying to do that:
struct EntityDef
{
struct
{
int hp;
} stats;
}
to getting suggested to do that instead:
struct Foo
{
int bar;
//struct {/*
Baz baz;
struct Baz
{
auto opAssign(int value)
=> baz = value;//*/
int baz;
}
}
void main()
{
Foo foo;
foo.bar = 7;
foo.baz = 42;
imported!"std.stdio".writeln(foo); /*
with opAssign() Anonymous
Foo(7, Baz(42)) or Foo(7, 42) */
}
to getting suggested to now do that:
import std.typecons;
struct EntityDef
{
Tuple!(int, "hp") stats;
}
void main()
{
EntityDef ed;
int x = ed.stats.hp;
}
Wich ends up improting a 11k LOC module: https://github.com/dlang/phobos/blob/master/std/typecons.d#L11092
Wich traverse god knows how many templates
Only just because i wanteed to do:
struct EntityDef
{
struct
{
int hp;
} stats;
}
Why wanting to complicate everything?
I know i'm not a professional developper, i do this as a hobby, so i must be missing something
But something tells me that i'm not missing anything, i can't pin point it just yet!