[Issue 6788] std.range.pairwise?

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Feb 7 10:03:34 PST 2013


http://d.puremagic.com/issues/show_bug.cgi?id=6788


bearophile_hugs at eml.cc changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
         Resolution|DUPLICATE                   |


--- Comment #3 from bearophile_hugs at eml.cc 2013-02-07 10:03:25 PST ---
(In reply to comment #2)
> This is the same as the cartesianProduct of two ranges, which is already
> checked into git HEAD.
> 
> *** This issue has been marked as a duplicate of issue 7128 ***

See this test code:

import std.stdio, std.algorithm;
void main() {
    auto data = [1, 2, 3, 4];
    foreach (xy; cartesianProduct(data, data))
        writeln(xy);
}

Tuple!(int, int)(1, 1)
Tuple!(int, int)(2, 1)
Tuple!(int, int)(3, 1)
Tuple!(int, int)(4, 1)
Tuple!(int, int)(1, 2)
Tuple!(int, int)(2, 2)
Tuple!(int, int)(3, 2)
Tuple!(int, int)(4, 2)
Tuple!(int, int)(1, 3)
Tuple!(int, int)(2, 3)
Tuple!(int, int)(3, 3)
Tuple!(int, int)(4, 3)
Tuple!(int, int)(1, 4)
Tuple!(int, int)(2, 4)
Tuple!(int, int)(3, 4)
Tuple!(int, int)(4, 4)



import std.stdio, std.range;
void main() {
    auto data = [1, 2, 3, 4];
    foreach (tup; pairwise(data))
        writeln(tup);
}


Should print:

Tuple!(int,int)(1, 2)
Tuple!(int,int)(1, 3)
Tuple!(int,int)(1, 4)
Tuple!(int,int)(2, 3)
Tuple!(int,int)(2, 4)
Tuple!(int,int)(3, 4)

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list