On Saturday, 10 September 2022 at 16:33:03 UTC, Erdem Demir wrote:
I wish I could use ref DListOfA returnVal = .... but we can't in D.

Can you please suggest alternatives?

I think you should try advanced update. Your flexibility and what you can do are limited by your dreams. A couple delicious code:

```d
import object, std.container;

struct A
{
    double val;
    bool isBig;
}

void main()
{
    alias  DListOfA = DList!A;
    DListOfA returnVal;
    //DListOfA[string] temp;/*
    DListOfA[string] temp = [
        "a": DListOfA( A(0) )
    ];//*/
    
    auto a = A(6, true); // replacement element
    temp.update("a", {
       return DListOfA( A(0) ); // not updated: unsucceeded but initialized
    }, (ref DListOfA v) {
        v = DListOfA( a ); // existing v has been replaced
        returnVal = v;
        assert(returnVal.front == a);
    });
    assert(is(typeof(temp["a"]) == DList!A));
}
```
SDB@79

Reply via email to