From d929cea294d3477684e36b3cda3a8d0ec31e21d8 Mon Sep 17 00:00:00 2001 From: Walter Bright Date: Mon, 5 Oct 2015 19:45:55 -0700 Subject: [PATCH 1/8] Merge pull request #3697 from CyberShadow/pull-20151005-194915 std.getopt: Re-add constructor removed in PR #3489 --- std/getopt.d | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/std/getopt.d b/std/getopt.d index d177c2962..1f5154de7 100644 --- a/std/getopt.d +++ b/std/getopt.d @@ -45,6 +45,12 @@ $(UL */ class GetOptException : Exception { + @safe pure nothrow + this(string msg, string file = __FILE__, + size_t line = __LINE__) + { + super(msg, file, line); + } @safe pure nothrow this(string msg, Exception next, string file = __FILE__, size_t line = __LINE__) @@ -53,6 +59,9 @@ class GetOptException : Exception } } +static assert(is(typeof(new GetOptException("message")))); +static assert(is(typeof(new GetOptException("message", Exception.init)))); + /** Parse and remove command line options from an string array. From af28028637db77d7a55461718911297b12ad4e98 Mon Sep 17 00:00:00 2001 From: Martin Nowak Date: Tue, 6 Oct 2015 15:29:45 +0200 Subject: [PATCH 2/8] changelog entries from dlang.org's upcoming.dd --- changelog.dd | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/changelog.dd b/changelog.dd index cdaf0ff7b..c32f63a9d 100644 --- a/changelog.dd +++ b/changelog.dd @@ -9,6 +9,12 @@ $(BUGSTITLE Library Changes, $(LI $(RELATIVE_LINK2 more-rangified-functions, More phobos functions were rangified.)) $(LI $(RELATIVE_LINK2 std-algorithm-moveEmplace, `moveEmplace` was added)) $(LI $(RELATIVE_LINK2 curl-dynamic-loading, libcurl is now loaded dynamically)) +$(LI $(XREF traits, getUDAs) was added to help get + user-defined attributes of specific types from symbols.) +$(LI $(XREF traits, getSymbolsByUDA) was + added to find symbols with specific user-defined attributes.) +$(LI $(XREF math, cmp) was added, defining total ordering on + floating-point numbers, including NaN.) $(LI FreeBSD now also ships with a shared libphobos2.so library ($(LINK2 http://dlang.org/dll-linux.html, usage info)).) $(LI The package $(STDMODREF experimental_allocator, std.experimental.allocator) was added.) From a52d43e42004607e035a704926d04fa5734dc3c5 Mon Sep 17 00:00:00 2001 From: Robert burner Schadek Date: Wed, 7 Oct 2015 13:37:45 +0200 Subject: [PATCH 3/8] std.string.lineSplitter_string_alias_fix lineSplitter used to accept struct and classes with an alias this to a string returning function. This PR add that feature again. https://github.com/D-Programming-Language/phobos/pull/3694 --- std/string.d | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/std/string.d b/std/string.d index 110ab6343..616ec7c8a 100644 --- a/std/string.d +++ b/std/string.d @@ -2460,7 +2460,7 @@ S[] splitLines(S)(S s, in KeepTerminator keepTerm = KeepTerminator.no) @safe pur */ auto lineSplitter(KeepTerminator keepTerm = KeepTerminator.no, Range)(Range r) if ((hasSlicing!Range && hasLength!Range) || - isSomeString!Range) + __traits(compiles, StringTypeOf!Range)) { import std.uni : lineSep, paraSep; import std.conv : unsigned; @@ -2468,7 +2468,11 @@ if ((hasSlicing!Range && hasLength!Range) || static struct Result { private: - Range _input; + static if (__traits(compiles, StringTypeOf!Range)) + StringTypeOf!Range _input; + else + Range _input; + alias IndexType = typeof(unsigned(_input.length)); enum IndexType _unComputed = IndexType.max; IndexType iStart = _unComputed; @@ -2493,7 +2497,7 @@ if ((hasSlicing!Range && hasLength!Range) || } } - @property Range front() + @property typeof(_input) front() { if (iStart == _unComputed) { @@ -2613,6 +2617,7 @@ if ((hasSlicing!Range && hasLength!Range) || "\rpeter\n\rpaul\r\njerry\u2028ice\u2029cream\n\n" ~ "sunday\nmon\u2030day\nschadenfreude\vkindergarten\f\vcookies\u0085" ); + auto lines = lineSplitter(s).array; assert(lines.length == 14); assert(lines[0] == ""); @@ -2678,6 +2683,19 @@ if ((hasSlicing!Range && hasLength!Range) || assert(i == witness.length); } +unittest +{ + import std.file : DirEntry; + import std.algorithm.comparison : equal; + + auto s = "std/string.d"; + auto de = DirEntry(s); + auto i = de.lineSplitter(); + auto j = s.lineSplitter(); + + assert(equal(i, j)); +} + /++ Strips leading whitespace (as defined by $(XREF uni, isWhite)). From 68f4373a6dbe4bc16fa2e3db23a038e6f4707a33 Mon Sep 17 00:00:00 2001 From: Robert burner Schadek Date: Wed, 7 Oct 2015 14:36:01 +0200 Subject: [PATCH 4/8] std.string.stripRight_string_alias_fix make stripRight accept custom types with alias this to string member(functions) --- std/string.d | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/std/string.d b/std/string.d index 110ab6343..7349190e4 100644 --- a/std/string.d +++ b/std/string.d @@ -2742,18 +2742,25 @@ Range stripLeft(Range)(Range str) Strips trailing whitespace (as defined by $(XREF uni, isWhite)). Params: - str = string or random access range of characters + input = string or random access range of characters Returns: - slice of $(D str) stripped of trailing whitespace. + slice of $(D input) stripped of trailing whitespace. +/ -auto stripRight(Range)(Range str) +auto stripRight(Range)(Range input) if (isSomeString!Range || - isRandomAccessRange!Range && hasLength!Range && hasSlicing!Range && - isSomeChar!(ElementEncodingType!Range)) + (isRandomAccessRange!Range && hasLength!Range && hasSlicing!Range && + isSomeChar!(ElementEncodingType!Range)) + || __traits(compiles, StringTypeOf!Range)) { - alias C = Unqual!(ElementEncodingType!Range); - static if (isSomeString!Range) + static if (__traits(compiles, StringTypeOf!Range)) + StringTypeOf!Range str = input; + else + alias str = input; + + alias C = Unqual!(ElementEncodingType!(typeof(str))); + + static if (isSomeString!(typeof(str))) { import std.utf : codeLength; foreach_reverse (i, dchar c; str) @@ -2856,6 +2863,17 @@ unittest [paraSep] ~ "hello world"); } +unittest +{ + static struct ToString + { + string s; + alias s this; + } + + assert(stripRight(ToString("hello ")) == "hello"); +} + unittest { import std.utf; From dcec6a153a11e9f3cbd2435cff282cacbabf226e Mon Sep 17 00:00:00 2001 From: Robert burner Schadek Date: Wed, 7 Oct 2015 14:21:01 +0200 Subject: [PATCH 5/8] std.string.stripleft_string_alias_fix make stripLeft accept types with an alias this to a string member(function) small update --- std/string.d | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/std/string.d b/std/string.d index 110ab6343..fb2cdff0e 100644 --- a/std/string.d +++ b/std/string.d @@ -2682,20 +2682,26 @@ if ((hasSlicing!Range && hasLength!Range) || Strips leading whitespace (as defined by $(XREF uni, isWhite)). Params: - str = string or ForwardRange of characters + input = string or ForwardRange of characters - Returns: $(D str) stripped of leading whitespace. + Returns: $(D input) stripped of leading whitespace. - Postconditions: $(D str) and the returned value + Postconditions: $(D input) and the returned value will share the same tail (see $(XREF array, sameTail)). +/ -Range stripLeft(Range)(Range str) - if (isForwardRange!Range && isSomeChar!(ElementEncodingType!Range)) +auto stripLeft(Range)(Range input) + if (isForwardRange!Range && isSomeChar!(ElementEncodingType!Range) || + __traits(compiles, StringTypeOf!Range)) { import std.ascii : isASCII, isWhite; import std.uni : isWhite; import std.utf : decodeFront; + static if (__traits(compiles, StringTypeOf!Range)) + StringTypeOf!Range str = input; + else + alias str = input; + while (!str.empty) { auto c = str.front; @@ -2737,6 +2743,16 @@ Range stripLeft(Range)(Range str) "hello world "); } +unittest +{ + static struct ToString + { + string s; + alias s this; + } + + assert(stripLeft(ToString(" hello")) == "hello"); +} /++ Strips trailing whitespace (as defined by $(XREF uni, isWhite)). From 5ed2368fc447225c0acceff74997a681c0cbab3b Mon Sep 17 00:00:00 2001 From: Martin Nowak Date: Mon, 12 Oct 2015 17:32:30 +0200 Subject: [PATCH 6/8] Added the two new comparison algorithms to the changelog --- changelog.dd | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/changelog.dd b/changelog.dd index c32f63a9d..67d394d4a 100644 --- a/changelog.dd +++ b/changelog.dd @@ -8,6 +8,8 @@ $(BUGSTITLE Library Changes, $(LI $(RELATIVE_LINK2 more-rangified-functions, More phobos functions were rangified.)) $(LI $(RELATIVE_LINK2 std-algorithm-moveEmplace, `moveEmplace` was added)) +$(LI $(RELATIVE_LINK2 std-algorithm-isPermutation, `isPermutation` was added)) +$(LI $(RELATIVE_LINK2 std-algorithm-isSameLength, `isSameLength` was added)) $(LI $(RELATIVE_LINK2 curl-dynamic-loading, libcurl is now loaded dynamically)) $(LI $(XREF traits, getUDAs) was added to help get user-defined attributes of specific types from symbols.) @@ -89,6 +91,36 @@ $(LI $(LNAME2 std-algorithm-moveEmplace, A combined `moveEmplace` was added.) ) ) +$(LI $(LNAME2 std-algorithm-isPermutation, `isPermutation` was added.) + + $(P $(XREF algorithm_comparison, isPermuatation) compares two forward ranges to + determine if they are permuations of each other. + ) + + ------ + auto r1 = [10, 15, 7, 12, 30]; + auto r2 = [7, 10, 12, 15, 30]; + + assert(r1.isPermutation(r2)); + ------ +) + +$(LI $(LNAME2 std-algorithm-isSameLength, `isSameLength` was added.) + + $(P $(XREF algorithm_comparison, isSameLength) compares two input ranges to + determine if they have the same length. This algorithm always takes advantage + of the `length` range primitive if it exists. Otherwise, this algorithm will + walk the ranges to find their length. + ) + + ------ + auto r1 = [1, 10, 100, 1000, 10000]; + auto r2 = [1, 2, 3, 4, 5]; + + assert(r1.isSameLength(r2)); + ------ +) + $(LI $(RELATIVE_LINK2 curl-dynamic-loading, libcurl is now loaded dynamically) $(P $(STDMODREF net_curl, std.net.curl) was changed to load curl as shared From 4eab18f14ae66ce5c6a3c37e64d3af6a1c1d49ba Mon Sep 17 00:00:00 2001 From: Martin Nowak Date: Mon, 12 Oct 2015 17:32:41 +0200 Subject: [PATCH 7/8] fix link to moveEmplace --- changelog.dd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelog.dd b/changelog.dd index 67d394d4a..b18d739df 100644 --- a/changelog.dd +++ b/changelog.dd @@ -69,7 +69,7 @@ $(LI $(LNAME2 more-rangified-functions, More phobos functions were rangified.) $(LI $(LNAME2 std-algorithm-moveEmplace, A combined `moveEmplace` was added.) - $(P $(XREF algorithm_mutation, MoveEmplace) efficiently combines $(XREF + $(P $(XREF algorithm_mutation, moveEmplace) efficiently combines $(XREF algorithm_mutation, move) with $(XREF conv, emplace) thus avoids having to initialize and destroy a value before moving into uninitialized data. ) From 96bc6da667ef98561e27e2e0787d8e026df33e47 Mon Sep 17 00:00:00 2001 From: Martin Nowak Date: Wed, 14 Oct 2015 13:56:37 +0200 Subject: [PATCH 8/8] missing docs for moveEmplace --- std/algorithm/mutation.d | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/std/algorithm/mutation.d b/std/algorithm/mutation.d index ec4010e80..1d33e0476 100644 --- a/std/algorithm/mutation.d +++ b/std/algorithm/mutation.d @@ -1152,7 +1152,7 @@ unittest// Issue 8057 static assert(__traits(compiles, move(x, x) )); } -/* +/** * Similar to $(LREF move) but assumes `target` is uninitialized. This * is more efficient because `source` can be blitted over `target` * without destroying or initializing it first.