Find struct not passed by reference

Ali Çehreli acehreli at yahoo.com
Tue Aug 3 20:14:33 UTC 2021


On 8/3/21 12:22 PM, frame wrote:
> On Tuesday, 3 August 2021 at 19:19:27 UTC, jfondren wrote:
>> On Tuesday, 3 August 2021 at 19:11:16 UTC, frame wrote:
>>> On Tuesday, 3 August 2021 at 16:35:04 UTC, Ali Çehreli wrote:
>>> Why foreach() does not accept a pointer?
>>
>> pointers don't come with a length?
> 
> Where is the problem if it points to something with a range interface?

Must be more complicated than a trivial derefencing:

import std.range;

void main() {
   auto r = 5.iota;
   auto p = &r;

   foreach (e; *p) {
   }
}

Having said that, I swear there is a seemingly-over-the-top help of D 
for foreach loops, which I can't remember now. Similar to what you said, 
it works with a certain type of construct by thinking outside the box.

Do others know what I am trying to remember?

Ali



More information about the Digitalmars-d-learn mailing list