digitalmars.D.bugs - [Issue 5791] New: array.Appender with operator "~=" (source included)
- d-bugmail puremagic.com (41/41) Mar 28 2011 http://d.puremagic.com/issues/show_bug.cgi?id=5791
- d-bugmail puremagic.com (12/12) Jun 08 2011 http://d.puremagic.com/issues/show_bug.cgi?id=5791
http://d.puremagic.com/issues/show_bug.cgi?id=5791
Summary: array.Appender with operator "~=" (source included)
Product: D
Version: D2
Platform: All
OS/Version: All
Status: NEW
Severity: enhancement
Priority: P2
Component: Phobos
AssignedTo: nobody puremagic.com
ReportedBy: alvaro.segura gmail.com
For consistency with normal array appending and to better follow "the D way" it
would be good to have a "~=" operator in struct std.array.Appender.
Operators are easier to remember and it will be easier to change existing code
using normal arrays to Appender when performance suggests it would improve.
Just add the following in the body of struct Appender in phobos/std/array.d and
it's done:
void opOpAssign(string op, U)(U u)
{
static if (op=="~")
{
put(u);
}
}
It works with ranges too:
Appender!(int[]) a; // this can be changed to int[] a; with no harm!
a ~= 4;
a ~= [5, 7];
Additionally, for more consistency and ease of change T[] <-> Appender!(T[]),
index operator can also be added:
auto opIndex(size_t i)
{
return data[i];
}
So we can now:
writeln(a[2]); // will print 7
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 28 2011
http://d.puremagic.com/issues/show_bug.cgi?id=5791
Rob Jacques <sandford jhu.edu> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
CC| |sandford jhu.edu
Resolution| |DUPLICATE
*** This issue has been marked as a duplicate of issue 4287 ***
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 08 2011








d-bugmail puremagic.com