From 0ff85c49b1965c237cc3ed7ab995fff0070c65da Mon Sep 17 00:00:00 2001 From: jmdavis Date: Sun, 16 Sep 2012 21:14:08 -0700 Subject: [PATCH] Moved filter to the public section. It seems that Filter accidentally got put in the private section of the file, and now that the bug making all templates public has been fixed, Filter isn't useable. --- std/typetuple.d | 85 +++++++++++++++++++++++++------------------------ 1 file changed, 43 insertions(+), 42 deletions(-) diff --git a/std/typetuple.d b/std/typetuple.d index 6cf8f46b1..e1123e44f 100644 --- a/std/typetuple.d +++ b/std/typetuple.d @@ -628,6 +628,49 @@ unittest static assert(anySatisfy!(isIntegral, int, double)); } + +/++ + Filters a $(D TypeTuple) using a template predicate. Returns a + $(D TypeTuple) of the elements which satisfy the predicate. + + Examples: +-------------------- +static assert(is(Filter!(isNarrowString, string, wstring, + dchar[], char[], dstring, int) == + TypeTuple!(string, wstring, char[]))); +static assert(is(Filter!(isUnsigned, int, byte, ubyte, + dstring, dchar, uint, ulong) == + TypeTuple!(ubyte, uint, ulong))); +-------------------- + +/ +template Filter(alias pred, TList...) +{ + static if(TList.length == 0) + alias TypeTuple!() Filter; + else static if(pred!(TList[0])) + alias TypeTuple!(TList[0], Filter!(pred, TList[1 .. $])) Filter; + else + alias Filter!(pred, TList[1 .. $]) Filter; +} + +//Verify Examples +unittest +{ + static assert(is(Filter!(isNarrowString, string, wstring, + dchar[], char[], dstring, int) == + TypeTuple!(string, wstring, char[]))); + static assert(is(Filter!(isUnsigned, int, byte, ubyte, + dstring, dchar, uint, ulong) == + TypeTuple!(ubyte, uint, ulong))); +} + +unittest +{ + static assert(is(Filter!(isPointer, int, void*, char[], int*) == TypeTuple!(void*, int*))); + static assert(is(Filter!isPointer == TypeTuple!())); +} + + // : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : // private: @@ -779,48 +822,6 @@ unittest } -/++ - Filters a $(D TypeTuple) using a template predicate. Returns a - $(D TypeTuple) of the elements which satisfy the predicate. - - Examples: --------------------- -static assert(is(Filter!(isNarrowString, string, wstring, - dchar[], char[], dstring, int) == - TypeTuple!(string, wstring, char[]))); -static assert(is(Filter!(isUnsigned, int, byte, ubyte, - dstring, dchar, uint, ulong) == - TypeTuple!(ubyte, uint, ulong))); --------------------- - +/ -template Filter(alias pred, TList...) -{ - static if(TList.length == 0) - alias TypeTuple!() Filter; - else static if(pred!(TList[0])) - alias TypeTuple!(TList[0], Filter!(pred, TList[1 .. $])) Filter; - else - alias Filter!(pred, TList[1 .. $]) Filter; -} - -//Verify Examples -unittest -{ - static assert(is(Filter!(isNarrowString, string, wstring, - dchar[], char[], dstring, int) == - TypeTuple!(string, wstring, char[]))); - static assert(is(Filter!(isUnsigned, int, byte, ubyte, - dstring, dchar, uint, ulong) == - TypeTuple!(ubyte, uint, ulong))); -} - -unittest -{ - static assert(is(Filter!(isPointer, int, void*, char[], int*) == TypeTuple!(void*, int*))); - static assert(is(Filter!isPointer == TypeTuple!())); -} - - /* * Instantiates the given template with the given list of parameters. *