On 5/21/18 4:29 PM, Nick Sabalausky (Abscissa) wrote:
On 05/21/2018 01:30 PM, Paul Backus wrote:

I'm not sure making `_data` private is really a good idea. For example, this only works if `_data` is public:

import std.algorithm;
import std.range;
import std.stdio;

struct MyType
{
     auto _data = iota(10);
     alias _data this;
}

void main()
{
     MyType x;
     x.each!writeln;
}

Ouch, and the error message isn't very helpful either. I wonder what causes this to fail though, and whether it might simply be a compiler bug?

No, an alias to private data doesn't magically make it public.

The reason it doesn't work is that each is in std.algorithm.iteration, which has no visibility into private symbols of your main module.

This also fails:

assert(isInputRange!MyType);

-Steve

Reply via email to