Accessing part of a struct in an easy way

Paolo Invernizzi via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Jul 3 06:53:45 PDT 2017


I've struct like that:

struct Foo {
     int a_1; float a_2; string a_3;
     string b_1; double b_2;
}

I would like to transparently access that like:

foo.a.first
foo.b.second = "baz";

with an helper like:

auto a(...) { ... }
auto b(...) { ... }

that can be used also in functions that are expecting it:

void worksOnA( .... ) { }
void worksOnB( .... ) { }

auto foo = Foo( ... )
foo.a.worksOnA();
foo.b.worksOnB();

But I'm struggling in finding a good way to do it...
Suggestions?

Thanks!
/Paolo



More information about the Digitalmars-d-learn mailing list