www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Rationale for no opIndex, length in std.algorithm.map?

reply dsimcha <dsimcha yahoo.com> writes:
What is the rationale for lack of opIndex and length in map?  opIndex might be
a bad idea if the function being mapped is expensive, but it's not so bad if
the function is cheap.  Length just seems like a no-brainer to me if the
underlying range has a length.  There are several places in various code I've
written where I need to copy an arbitrary range, or some transform of it, to
an array, and this obviously can be done more efficiently when the length is
known in advance.  Were these just oversights, and should an enhancement
request be filed, or is there a good reason for excluding them?
May 13 2009
parent Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> writes:
dsimcha wrote:
 What is the rationale for lack of opIndex and length in map?  opIndex might be
 a bad idea if the function being mapped is expensive, but it's not so bad if
 the function is cheap.  Length just seems like a no-brainer to me if the
 underlying range has a length.  There are several places in various code I've
 written where I need to copy an arbitrary range, or some transform of it, to
 an array, and this obviously can be done more efficiently when the length is
 known in advance.  Were these just oversights, and should an enhancement
 request be filed, or is there a good reason for excluding them?
It's an oversight. map should offer opIndex and length iff the mapped range offers them. Could you please bugzilla that? Andrei P.S. I appreciate the great work you're doing. Good going!
May 13 2009