How should I return multiple const values from a function?
Paul Backus
snarwin at gmail.com
Tue Jan 3 01:56:10 UTC 2023
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 v)
{
return Tuple!(const(Key), const(Value))(k, v);
}
void main()
{
string k;
uint v;
auto result = func(k, v);
static assert(is(typeof(result[0]) == const(string)));
static assert(is(typeof(result[1]) == const(uint)));
}
More information about the Digitalmars-d-learn
mailing list