Tuple issue
Paul Backus
snarwin at gmail.com
Sun Nov 15 20:21:05 UTC 2026
On Sunday, 15 November 2026 at 19:29:32 UTC, DLearner wrote:
> Hi
>
> Please see (under -betterC):
> [...]
> Expected: Assert failure on Arg1 == 0 (because value actually 8)
> Actual: Assert failure on Arg1 == 8.
>
> Suggestions (without having to name a tuple variable)?
struct Ref(T)
{
T* ptr;
ref inout(T) deref() inout => *ptr;
alias this = deref;
}
Ref!T byRef(T)(ref T obj) => Ref!T(&obj);
extern(C) void main()
{
import core.stdc.stdio: printf;
import std.typecons: tuple, Tuple;
Tuple!(int, int) fun() => tuple(123, 456);
int a = 0, b = 0;
tuple(a.byRef, b.byRef) = fun();
printf("(%d, %d)\n", a, b); // (123, 456)
}
More information about the Digitalmars-d-learn
mailing list