From 58c82f12671acd0ed542161cf954a4f193291811 Mon Sep 17 00:00:00 2001 From: Brad Anderson Date: Tue, 12 Jun 2012 14:18:51 -0600 Subject: [PATCH] Add Example to SList.insertAfter documentation Along with matching unit test. --- std/container.d | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/std/container.d b/std/container.d index cd2c8add31a..884083fe12b 100644 --- a/std/container.d +++ b/std/container.d @@ -1200,8 +1200,8 @@ Inserts $(D stuff) after range $(D r), which must be a range previously extracted from this container. Given that all ranges for a list end at the end of the list, this function essentially appends to the list and uses $(D r) as a potentially fast way to reach the last -node in the list. (Ideally $(D r) is positioned near or at the last -element of the list.) +node in the list. Ideally $(D r) is positioned near or at the last +element of the list. $(D stuff) can be a value convertible to $(D T) or a range of objects convertible to $(D T). The stable version behaves the same, but @@ -1212,6 +1212,15 @@ Returns: The number of values inserted. Complexity: $(BIGOH k + m), where $(D k) is the number of elements in $(D r) and $(D m) is the length of $(D stuff). + +Examples: +-------------------- +auto sl = SList!string(["a", "b", "d"]); +sl.insertAfter(sl[], "e"); // insert at the end (slowest) +assert(std.algorithm.equal(sl[], ["a", "b", "d", "e"])); +sl.insertAfter(std.range.take(sl[], 2), "c"); // insert after "b" +assert(std.algorithm.equal(sl[], ["a", "b", "c", "d", "e"])); +-------------------- */ size_t insertAfter(Stuff)(Range r, Stuff stuff) @@ -1411,6 +1420,16 @@ unittest assert(s == SList!int(1, 2, 5, 3, 4)); } +unittest +{ + // insertAfter documentation example + auto sl = SList!string(["a", "b", "d"]); + sl.insertAfter(sl[], "e"); // insert at the end (slowest) + assert(std.algorithm.equal(sl[], ["a", "b", "d", "e"])); + sl.insertAfter(std.range.take(sl[], 2), "c"); // insert after "b" + assert(std.algorithm.equal(sl[], ["a", "b", "c", "d", "e"])); +} + unittest { auto s = SList!int(1, 2, 3, 4, 5);