How should I return multiple const values from a function?

2023-01-02 Thread Charles Hixson via Digitalmars-d-learn
I want to return values of the template parameter type, so there doesn't seem to be any way to dup or idup them.  I don't want the returned values to be able to be used to modify the values held in the table.  const out is an illegal parameter type.  dup doesn't work on ints. So I tried to ret

Re: How should I return multiple const values from a function?

2023-01-02 Thread Paul Backus via Digitalmars-d-learn
On Monday, 2 January 2023 at 22:53:13 UTC, Charles Hixson wrote: I want to return values of the template parameter type, so there doesn't seem to be any way to dup or idup them. It's hard to say where exactly you're going wrong if you only post the error message, without the code that produced

Re: How should I return multiple const values from a function?

2023-01-02 Thread Charles Hixson via Digitalmars-d-learn
On 1/2/23 15:14, Paul Backus via Digitalmars-d-learn wrote: On Monday, 2 January 2023 at 22:53:13 UTC, Charles Hixson wrote: I want to return values of the template parameter type, so there doesn't seem to be any way to dup or idup them. It's hard to say where exactly you're going wrong if y

Re: How should I return multiple const values from a function?

2023-01-02 Thread Charles Hixson via Digitalmars-d-learn
On 1/2/23 15:14, Paul Backus via Digitalmars-d-learn wrote: On Monday, 2 January 2023 at 22:53:13 UTC, Charles Hixson wrote: I want to return values of the template parameter type, so there doesn't seem to be any way to dup or idup them. It's hard to say where exactly you're going wrong if y

Re: How should I return multiple const values from a function?

2023-01-02 Thread Paul Backus via Digitalmars-d-learn
On Monday, 2 January 2023 at 23:25:48 UTC, Charles Hixson wrote: They syntax I wanted was something like: bool func (const out Key k, const out Val v) { k = this.key.dup; v = this.val.dup; return true;    } This works for me: import std.typecons; auto func(Key, Value)(Key k, Value

Re: How should I return multiple const values from a function?

2023-01-02 Thread Charles Hixson via Digitalmars-d-learn
On 1/2/23 17:56, Paul Backus via Digitalmars-d-learn wrote: return Tuple!(const(Key), const(Value))(k, v); Great!  OK, now the code is:     auto    findFirst ()     {    if    (root is null)    {    Key k    =    Key.init;        Val v    =    Val.init;        return Tuple!(co

Re: How should I return multiple const values from a function?

2023-01-02 Thread Salih Dincer via Digitalmars-d-learn
On Tuesday, 3 January 2023 at 01:56:10 UTC, Paul Backus wrote: On Monday, 2 January 2023 at 23:25:48 UTC, Charles Hixson wrote: They syntax I wanted was something like: bool func (const out Key k, const out Val v) { k = this.key.dup; v = this.val.dup; return true;    } This works for me:

Re: How should I return multiple const values from a function?

2023-01-03 Thread Salih Dincer via Digitalmars-d-learn
On Tuesday, 3 January 2023 at 07:41:46 UTC, Salih Dincer wrote: P.S. Actually the code works when we don't use enum. My mistake, I forgot that enum cannot be inferred! Very very sorry, suppose I didn't intervene 😀 Also this has worked: ```d void main() { template Fun(Key, Value) { i