[Issue 15413] Foreach over range with @disable this(this) doesn't work

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Nov 10 09:11:22 UTC 2019


https://issues.dlang.org/show_bug.cgi?id=15413

Johannes Pfau <johannespfau at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |johannespfau at gmail.com

--- Comment #5 from Johannes Pfau <johannespfau at gmail.com> ---
> However, considering that almost all range-based code copies ranges, I find it hard to believe that having a non-copyable range makes much sense.

All implementations of Unique however work by disabling this(this), which means
you can't foreach over unique ranges.

One place where this would be really idiomatic is this: I'd like to return a
Range which maps d2sqlite3 result rows to the deserialized types. However, in
SQLite you have to explicitly keep track of & finalize the statement which was
use to generate the query. Ideally you could do just this:

foreach(value; db.query!Commit(/*sha =*/ "abcd") {}

and when the range goes out of scope it finalizes the statement. Because of
foreachs implicit copying, you now have to use reference counting instead...

--


More information about the Digitalmars-d-bugs mailing list