On Saturday, 14 November 2026 at 18:41:06 UTC, AndyC wrote:
Hi all. I'm wondering if there is a way to avoid double
pointers in something like this:
```D
module ptrptr;
import std.stdio;
struct Rec {
string name;
string pin;
string id;
}
void main() {
Rec[string] table;
table["uart"] = Rec(name: "uart", pin: "K54");
table["clk"] = Rec(name: "clk", pin: "A22");
Rec*[string] pinIndex;
foreach(n, ref r; table) {
pinIndex[r.pin] = &r;
}
auto at = "K54" in pinIndex;
if (at) {
writeln(**at);
}
}
```
I have a table of data that I'd like to find elements by name,
or by pin. I'd like to be able to update the same element.
But when I search by pin, I get this **at double pointer. It
works, but feels like there might be a better way.
Thanks,
-Andy
your like 5 pointers deep; string has a pointer, hashmaps are 2
pointers
a canonical answer would be to make pin an int, sort by pin, its
got a stupid name but its in there, binary sreach lookups by pin
better answers exist but you clearly airnt thinking with types
yet; get down to 1 indirection.