On Monday, 2 January 2017 at 15:16:31 UTC, Basile B. wrote:
Write your plan here, and let's take a rendez-vous next year, to check those plans !!

Enable non-copyable (r-value) ranges to be passed to range-based algorithms that require a single reference to the source range. My motivation for this is to enable non-copyable values, typically containers, to be passed by move into a specific range I currently call `UniqueRange`. `UniqueRange`, being in turn non-copyable, should then be passed Phobos' higher-order algorithms, typically `map`, `filter`, `reduce` etc. `UniqueRange` is similar to Rusts' `IntoIterator`. In order for this happen both the compiler and Phobos needs be adjusted in a non-breaking way.

Here's a sample implementation of this idea that compiles and tests out correctly with a branch of Phobos (link provided below).

https://github.com/nordlow/phobos-next/blob/master/src/unique_range.d

being a wrapper for

https://github.com/nordlow/phobos-next/blob/master/src/array_ex.d

The first thing is to improve the compiler so that it always moves the last reference (in scope X) of a variable passed by value into scope X (typically as a function parameter or foreach aggregate). More specifically this lowers to calling `doCopyOrMove()` on the DMD node of that last reference. The challenge is to find *which* node(s) this applies to.

This will enable D to compete with Rust's iterator flexibility by enabling range-based D algorithms to be safely and efficiently combined with containers (both copyable and non-copyable).

To kickstart this I need help by the DMD developers on figuring out how to fix DMD so that move semantics kicks in all places where it should (as described above). After DMD has been fixed, I will happily implement the rest.

Andrei has already approved this improvement as seen here

https://github.com/dlang/phobos/pull/4971

Reply via email to