RefRange behavior
Alex
sascha.orlov at gmail.com
Wed Mar 14 10:22:45 UTC 2018
Hi all,
given this:
´´´
import std.range;
size_t[] arr;
struct S
{
RefRange!(size_t[]) member;
}
void fun(ref size_t numByRef){}
void main()
{
arr.length = 42;
S s;
s.member = refRange(&arr);
static assert(__traits(compiles, fun(s.member[0])));
static assert(!__traits(compiles, fun(s.member.front)));
//fun(s.member.front);
/*
source/app.d(19,5): Error: function `app.fun(ref ulong
numByRef)` is not callable using argument types `(ulong)`
source/app.d(19,5): cannot pass rvalue argument
`s.member.front()` of type `ulong` to parameter `ref ulong
numByRef`
*/
}
´´´
Why does the last static assert yields false? Is there a simple
workaround, maybe?
More information about the Digitalmars-d-learn
mailing list