How should I return multiple const values from a function?
Salih Dincer
salihdb at hotmail.com
Tue Jan 3 07:41:46 UTC 2023
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:
```d
template Fun(Key, Value)
{
import std.typecons;
alias Tup = Tuple!(const(Key), const(Value));
enum Fun = (Key k, Value v) => Tup(k, v);/*
auto Fun(Key k, Value v) {
return Tup(k, v);
}//*/
}
string k;
uint v;
auto res = Fun(k, v);
static assert(is(typeof(res[0]) == const(string))); // false
static assert(is(typeof(res[1]) == const(uint))); //false
```
I rewrote the code to return the enum. However, static asserts
return false. What could this cause?
P.S. Actually the code works when we don't use enum.
SDB at 79
More information about the Digitalmars-d-learn
mailing list