I'm trying to figure out how to return a reference to something that may not be a reference type.

```D
struct stats
{
float[string] data=0;

float ref opIndex(string key)
  {
  return data[key]; // want a ref to a specific element
  }
}

void test()
{
stats foo;
auto x = foo.bar(); // returns some sort of reference
       // data["tacos"] = 0
x++;   // data["tacos"] = 1
}
```

Right now, I'm using pointers which resolves to:

```D
// float* opIndex(string key){...} using pointer
(*s["tacos"])++; // works with pointer, but is strange looking

s["tacos"]++; // preferred syntax or something similar
```

  • Returning a refe... Chris Katko via Digitalmars-d-learn
    • Re: Returni... IchorDev via Digitalmars-d-learn
    • Re: Returni... Paul Backus via Digitalmars-d-learn
    • Re: Returni... Jacob Shtokolov via Digitalmars-d-learn
      • Re: Ret... kdevel via Digitalmars-d-learn
        • Re:... Bastiaan Veelo via Digitalmars-d-learn
          • ... kdevel via Digitalmars-d-learn
            • ... Dennis via Digitalmars-d-learn
              • ... kdevel via Digitalmars-d-learn
                • ... Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
                • ... kdevel via Digitalmars-d-learn

Reply via email to