Void pointers
Steven Schveighoffer via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Mon May 16 14:15:16 PDT 2016
On 5/16/16 4:39 PM, Alex wrote:
> // something that does not worked as expected:
> // how to rewrite a for loop
> for(auto i = 0; i < b.length; i++) writeln(&b[i]);
> // into a foreach loop?
>
What you need is a range that produces void * instead element itself.
This would probably work:
struct VoidRange
{
void[] arr;
auto front() { return arr.ptr; }
void popFront() { arr.popFront; }
bool empty() { return arr.empty; }
}
foreach(p; VoidRange(b)) writeln(p);
-Steve
More information about the Digitalmars-d-learn
mailing list