Comment #0 by verylonglogin.reg — 2014-01-15T23:49:31Z
Test code:
---
import std.typecons;
struct S1
{
@property bool empty();
@property Tuple!(int, int) front();
void popFront();
}
struct S2
{
@property bool empty();
@property ref Tuple!(int, int) front();
void popFront();
}
void main()
{
static assert( __traits(compiles, { foreach( a, b; S1()) { } }));
static assert(!__traits(compiles, { foreach(ref a, ref b; S1()) { } }));
static assert( __traits(compiles, { foreach(ref a, ref b; S2()) { } }));
}
---
This issue is for front tuple expansion only. For regular `foreach` over range see Issue 11934.
Also Issue 11929 is a simplified variant proposing just disable `ref` in front tuple expansion case because in general created tuple is a temporary. It should be WONTFIX-ed if this one is fixed.
Comment #1 by robert.schadek — 2024-12-13T18:16:07Z