refRange and @disable this(this);

Mathias Lang via Digitalmars-d digitalmars-d at puremagic.com
Wed Sep 14 08:59:45 PDT 2016


You should be able to work around this by using `for` loop instead of
`foreach`.
IMO that's a design bug in `foreach`:
https://issues.dlang.org/show_bug.cgi?id=15413

2016-09-14 14:39 GMT+02:00 Jerry via Digitalmars-d <
digitalmars-d at puremagic.com>:

> I got a range which disables copy construction and I want to loop the
> range within another loop using the same range.
> So I thought I can mark the struct range with @disable this(this) and then
> use refRange to initialize the loop.
>
> So with something like this:
>
> void main()
> {
>         auto valueRange = FooRange("123");
>         foreach(ch; refRange(&valueRange))
>                 writeln(ch);
> }
>
>
> struct FooRange {
>         @disable this();
>         @disable this(this);
>         this(string str) {
>                 this.str = str;
>         }
>
>         @property bool empty() { return str.empty; }
>         @property dchar front() { return str.front; }
>         void popFront() { str.popFront; }
>
> private:
>         string str;
> }
>
>
> But I get compile time errors messages saying:
> std/range/package.d(8155,23): Error: struct app.FooRange is not copyable
> because it is annotated with @disable
>
> It feels strange that refRange ever want to copy.
> Bug or feature?
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20160914/82b03085/attachment.html>


More information about the Digitalmars-d mailing list