digitalmars.D.bugs - [Issue 5935] New: Non-tuple iteration with std.range.zip
- d-bugmail puremagic.com (56/56) May 06 2011 http://d.puremagic.com/issues/show_bug.cgi?id=5935
- d-bugmail puremagic.com (10/10) May 06 2011 http://d.puremagic.com/issues/show_bug.cgi?id=5935
- d-bugmail puremagic.com (8/9) May 06 2011 http://d.puremagic.com/issues/show_bug.cgi?id=5935
- d-bugmail puremagic.com (14/14) May 06 2011 http://d.puremagic.com/issues/show_bug.cgi?id=5935
- d-bugmail puremagic.com (7/13) May 06 2011 http://d.puremagic.com/issues/show_bug.cgi?id=5935
- d-bugmail puremagic.com (40/40) May 09 2011 http://d.puremagic.com/issues/show_bug.cgi?id=5935
- d-bugmail puremagic.com (15/15) Aug 09 2012 http://d.puremagic.com/issues/show_bug.cgi?id=5935
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 puremagic.com
ReportedBy: k.hara.pg gmail.com
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: -------
May 06 2011
http://d.puremagic.com/issues/show_bug.cgi?id=5935
kennytm gmail.com changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |kennytm gmail.com
What about std.range.lockstep?
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 06 2011
http://d.puremagic.com/issues/show_bug.cgi?id=5935What about std.range.lockstep?Oh, I have been overlooked. Thanks. But..., why can't we merge Zip and Lockstep? -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
May 06 2011
http://d.puremagic.com/issues/show_bug.cgi?id=5935
Andrei Alexandrescu <andrei metalanguage.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |andrei metalanguage.com
11:18:36 PDT ---
I'm worried about this development. Before long we could get to the point where
a lot of ranges get bloated to support two iteration methods because opApply
has capabilities that ranges don't.
To prevent that we should improve range-based iteration to provide good support
for foreach, and leave opApply to entities that need internal iteration.
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 06 2011
http://d.puremagic.com/issues/show_bug.cgi?id=5935I'm worried about this development. Before long we could get to the point where a lot of ranges get bloated to support two iteration methods because opApply has capabilities that ranges don't. To prevent that we should improve range-based iteration to provide good support for foreach, and leave opApply to entities that need internal iteration.Implement (a subset of) issue 4579? -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
May 06 2011
http://d.puremagic.com/issues/show_bug.cgi?id=5935
Lutger <lutger.blijdestijn gmail.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |lutger.blijdestijn gmail.co
| |m
PDT ---
If no language changes for range iteration and tuple unpacking will be made,
perhaps it's worth to consider a generic wrapper for this purpose as a
compromise?
I couldn't think of a good name:
auto iterUntupled(R)(R input)
if ( isInputRange!R &&
is( typeof( { auto x = input.front.tupleof; }() ) ) )
{
static struct IterUntupled(R)
{
this(R input)
{
_input = input;
}
int opApply( int delegate( ref typeof(_input.front.tupleof) ) dg )
{
while( !_input.empty)
{
auto front = _input.front;
if ( auto result = dg(front.tupleof) )
return result;
_input.popFront();
}
return 0;
}
R _input;
}
return IterUntupled!R(input);
}
This will also unpack arbitrary structs and classes, is that too loose?
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 09 2011
http://d.puremagic.com/issues/show_bug.cgi?id=5935
Denis Shelomovskij <verylonglogin.reg gmail.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
CC| |verylonglogin.reg gmail.com
Resolution| |FIXED
13:35:50 MSD ---
"front tuple expansion" by Kenji Hara fixed this issue.
But it still isn't documented.
See Issue 7361 - No documentation for front tuple expansion in foreach over
range
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 09 2012









d-bugmail puremagic.com 