On Saturday, 31 August 2024 at 15:38:49 UTC, ryuukk_ wrote:
Let's see how other languages do it:

```zig
    map.put("hello", 42);

    // get pointer
    if (map.get("hello")) |*it| {
        std.log.debug("{}", .{it});
    }

    // get value
    if (map.get("hello")) |it| {
        std.log.debug("{}", .{it});
    }
```
No imports, no templates, ONE LINER

We don't have `if` callback syntax, but essentially you can do that:
```d
void main()
{
    int[string] test;

    test["hello"] = 42;
    test.update("hello", () => noreturn.init, (ref int x) {
        x++;
    });
    assert(test["hello"] == 43);
}
```

Omit the `ref` if you want a copy of the value. Annoyingly, the `int` is required, though maybe just an IFTI bug.
  • Associative Arra... ryuukk_ via Digitalmars-d-learn
    • Re: Associa... Steven Schveighoffer via Digitalmars-d-learn
      • Re: Ass... ryuukk_ via Digitalmars-d-learn
        • Re:... kdevel via Digitalmars-d-learn
    • Re: Associa... Paul Backus via Digitalmars-d-learn
      • Re: Ass... ryuukk_ via Digitalmars-d-learn
        • Re:... ryuukk_ via Digitalmars-d-learn
          • ... Lance Bachmeier via Digitalmars-d-learn
            • ... ryuukk_ via Digitalmars-d-learn
            • ... Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
          • ... Nick Treleaven via Digitalmars-d-learn
            • ... Nick Treleaven via Digitalmars-d-learn
            • ... Nick Treleaven via Digitalmars-d-learn
      • Re: Ass... kdevel via Digitalmars-d-learn
        • Re:... Paul Backus via Digitalmars-d-learn
          • ... ryuukk_ via Digitalmars-d-learn
            • ... evilrat via Digitalmars-d-learn

Reply via email to