From e488e2919856e9982a1474758861112e84147704 Mon Sep 17 00:00:00 2001 From: Sebastian Wilzbach Date: Wed, 2 Mar 2016 22:56:41 +0200 Subject: [PATCH] add documentation example for SList --- std/container/slist.d | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/std/container/slist.d b/std/container/slist.d index 7d14d411634..bf308fa2bc3 100644 --- a/std/container/slist.d +++ b/std/container/slist.d @@ -20,6 +20,33 @@ Authors: Steven Schveighoffer, $(WEB erdani.com, Andrei Alexandrescu) */ module std.container.slist; +/// +unittest +{ + import std.container: SList; + import std.algorithm: equal; + + auto s = SList!int(1, 2, 3); + assert(equal(s[], [1, 2, 3])); + + s.removeFront(); + assert(equal(s[], [2, 3])); + + s.insertFront([5, 6]); + assert(equal(s[], [5, 6, 2, 3])); + + // If you want to apply range operations, simply slice it. + import std.algorithm: countUntil; + import std.range: popFrontN, walkLength; + + auto sl = SList!int(1, 2, 3, 4, 5); + assert(countUntil(sl[], 2) == 1); + + auto r = sl[]; + popFrontN(r, 2); + assert(walkLength(r) == 3); +} + public import std.container.util; /**