forward range properties with alias this - how?
    Ivan Kazmenko via Digitalmars-d-learn 
    digitalmars-d-learn at puremagic.com
       
    Wed Jul 29 17:13:39 PDT 2015
    
    
  
On Wednesday, 29 July 2015 at 23:54:29 UTC, Ivan Kazmenko wrote:
> On Wednesday, 29 July 2015 at 12:25:14 UTC, Marc Schütz wrote:
>> On Tuesday, 28 July 2015 at 21:25:23 UTC, Ivan Kazmenko wrote:
>>> ...
Perhaps I still don't implement save() correctly.
The line
     @property auto save() {return S(contents.dup);}
was meant to be just:
     @property auto save() {return S(contents);}
But with either of them, I get an error when trying a function 
using save.
-----
import std.algorithm, std.range, std.stdio;
struct S {
     int[] contents;
     alias contents this;
     @property auto save() {return S(contents);}
     auto opSlice(size_t lo, size_t hi) {return 
S(contents[lo..hi]);}
}
void main() {
     S s;
     s = [4, 3, 2, 1];
     nextPermutation(s);
}
-----
The error is:
-----
sorting.d(2460): Warning: use std.algorithm.reverse instead of 
.reverse property
sorting.d(2460): Error: function expected before (), not 
_adReverse(range.contents, 4u) of type int[]
-----
So, is something wrong with my save()?
Anyway, I reckon nextPermutation itself is wrong and should use
         reverse(range);
instead of
         range.reverse();
as it does ten lines later:
https://github.com/D-Programming-Language/phobos/blob/30e4ff1717d6d3eb82d2cb0e00a3c07af4263a7b/std/algorithm/sorting.d#L2468-L2478
If anybody can confirm that, I can file an issue and a patch.
    
    
More information about the Digitalmars-d-learn
mailing list