March 14, 2018 RefRange behavior | ||||
---|---|---|---|---|
| ||||
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? |
Copyright © 1999-2021 by the D Language Foundation