[Issue 5935] New: Non-tuple iteration with std.range.zip

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri May 6 07:41:40 PDT 2011


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

           Summary: Non-tuple iteration with std.range.zip
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Keywords: patch
          Severity: enhancement
          Priority: P2
         Component: Phobos
        AssignedTo: nobody at puremagic.com
        ReportedBy: k.hara.pg at gmail.com


--- Comment #0 from Kenji Hara <k.hara.pg at gmail.com> 2011-05-06 07:37:46 PDT ---
Zip sequence should provide non-tuple version foreach like this:
----
foreach (i, c; zip(sequence!"n"(), "str"))
{
         if (i==0) assert(c == 's');
    else if (i==1) assert(c == 't');
    else if (i==2) assert(c == 'r');
    else assert(0);
}
----

Patch:

 std/range.d |   15 +++++++++++++++
 1 files changed, 15 insertions(+), 0 deletions(-)

diff --git a/std/range.d b/std/range.d
index 7e7916c..0a24500 100644
--- a/std/range.d
+++ b/std/range.d
@@ -3209,6 +3209,21 @@ if(Ranges.length && allSatisfy!(isInputRange,
staticMap!(Unqual, Ranges)))
             }
         }
     }
+
+/**
+   Iterate zip elements with directry named heads of ranges.
+ */
+    int opApply(int delegate(ref ElementType.Types) dg)
+    {
+        auto r = this;
+        for (; !r.empty; r.popFront())
+        {
+            auto e = r.front;
+            if (auto result = dg(e.field))
+                return result;
+        }
+        return 0;
+    }
 }

 /// Ditto

-- 
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