[Issue 5638] New: Auto-flattening std.range.chain()
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Mon Feb 21 15:57:57 PST 2011
http://d.puremagic.com/issues/show_bug.cgi?id=5638
Summary: Auto-flattening std.range.chain()
Product: D
Version: D2
Platform: All
OS/Version: All
Status: NEW
Severity: enhancement
Priority: P2
Component: Phobos
AssignedTo: nobody at puremagic.com
ReportedBy: bearophile_hugs at eml.cc
--- Comment #0 from bearophile_hugs at eml.cc 2011-02-21 15:55:16 PST ---
A D2 demo program:
import std.range, std.stdio;
void main() {
auto c1 = chain([1, 2], [3, 4]);
writeln(c1);
writeln(typeid(typeof(c1)));
auto c2 = chain(c1, [5, 6]);
writeln(c2);
writeln(typeid(typeof(c2)));
auto c3 = chain([1, 2], [3, 4], [5, 6]);
writeln(c3);
writeln(typeid(typeof(c3)));
}
It prints, with DMD 2.052:
[1, 2, 3, 4]
std.range.ChainImpl!(int[],int[]).ChainImpl
[1, 2, 3, 4, 5, 6]
std.range.ChainImpl!(ChainImpl!(int[],int[]),int[]).ChainImpl
[1, 2, 3, 4, 5, 6]
std.range.ChainImpl!(int[],int[],int[]).ChainImpl
I suggest to add some simple automatic simplifications to chain(), so c2 has
the same type of c3:
chain(chain(something), r2) ==> chain(something, r2)
chain(r1, chain(something)) ==> chain(r1, something)
chain(chain(something1), chain(something2)) ==> chain(something1, something2)
To perform them chain() just needs to recognize the type of itself among its
iterable arguments and return a chain of the arguments of the sub-chains.
This flattening is useful to speed up the code with complex nested/paired
chainings, like ones coming from recursive algorithms.
--
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