Thread overview | |||||||
---|---|---|---|---|---|---|---|
|
May 13, 2009 [Issue 2976] New: rename retreatN to retreat | ||||
---|---|---|---|---|
| ||||
http://d.puremagic.com/issues/show_bug.cgi?id=2976 Summary: rename retreatN to retreat Product: D Version: 2.030 Platform: All OS/Version: All Status: NEW Keywords: ddoc, patch Severity: enhancement Priority: P2 Component: Phobos AssignedTo: bugzilla@digitalmars.com ReportedBy: k-foley@onu.edu I think it was named retreatN before because the name retreat was already taken. Now that retreat is free, I think retreatN should be renamed to retreat to complement advance (it's not advanceN). As a bonus, I've fixed documentation misprints: /** Eagerly retreats $(D r) itself (not a copy) $(D n) times (by calling $(D r.popBack) $(D n) times). The pass of $(D r) into $(D retreat) is by reference, so the original range is affected. Completes in $(BIGOH 1) steps for ranges that support slicing, and in $(BIGOH n) time for all other ranges. Example: ---- int[] a = [ 1, 2, 3, 4, 5 ]; a.retreat(2); assert(a == [ 1, 2, 3 ]); ---- */ size_t retreat(Range)(ref Range r, size_t n) if (isBidirectional!(Range)) { static if (hasSlicing!(Range) && hasLength!(Range)) { auto newLen = n < r.length ? r.length - n : 0; n = r.length - newLen; r = r[0 .. newLen]; } else { foreach (i; 0 .. n) { if (r.empty) return i; r.popBack; } } return n; } version(none) unittest { int[] a = [ 1, 2, 3, 4, 5 ]; a.retreat(2); assert(a == [ 1, 2, 3 ]); } -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
May 13, 2009 [Issue 2976] rename retreatN to retreat | ||||
---|---|---|---|---|
| ||||
Posted in reply to k-foley@onu.edu | http://d.puremagic.com/issues/show_bug.cgi?id=2976 --- Comment #1 from Kyle Foley <k-foley@onu.edu> 2009-05-13 13:37:08 PDT --- I forgot to comment on changing the concept for the function. I changed from: ---- size_t retreat(Range)(ref Range r, size_t n) if (isInputRange!(Range)) { ... } ---- to: ---- size_t retreat(Range)(ref Range r, size_t n) if (isBidirectionalRange!(Range)) { ... } I know the first is not correct, but I am unsure about isBidirectionalRange, since retreat really only requires popBack and empty. It looks like the best match without inventing isRetroInputRange or similar. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
August 27, 2009 [Issue 2976] rename retreatN to retreat | ||||
---|---|---|---|---|
| ||||
Posted in reply to k-foley@onu.edu | http://d.puremagic.com/issues/show_bug.cgi?id=2976 Andrei Alexandrescu <andrei@metalanguage.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED Resolution| |FIXED --- Comment #2 from Andrei Alexandrescu <andrei@metalanguage.com> 2009-08-27 14:39:32 PDT --- I ended up calling it popBackN. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
August 28, 2009 [Issue 2976] rename retreatN to retreat | ||||
---|---|---|---|---|
| ||||
Posted in reply to k-foley@onu.edu | http://d.puremagic.com/issues/show_bug.cgi?id=2976 --- Comment #3 from Kyle Foley <k-foley@onu.edu> 2009-08-27 17:59:48 PDT --- Are you going to rename advance to popFrontN? -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
August 28, 2009 [Issue 2976] rename retreatN to retreat | ||||
---|---|---|---|---|
| ||||
Posted in reply to k-foley@onu.edu | http://d.puremagic.com/issues/show_bug.cgi?id=2976 --- Comment #4 from Andrei Alexandrescu <andrei@metalanguage.com> 2009-08-27 18:23:40 PDT --- (In reply to comment #3) > Are you going to rename advance to popFrontN? Great idea! Just did so, thanks. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
Copyright © 1999-2021 by the D Language Foundation