diff --git a/changelog/pattern-deprecate.dd b/changelog/pattern-deprecate.dd index 2fe5214fe66..12bedbeb189 100644 --- a/changelog/pattern-deprecate.dd +++ b/changelog/pattern-deprecate.dd @@ -8,3 +8,57 @@ $(MREF std, regex) and $(MREF std, algorithm). They will be removed from $(MREF std, string) on May 2018. If you still need to use these, please see $(LINK2 https://github.com/dlang/undeaD, undeaD). + +The following are examples of the deprecated functions, and their modern replacements. + +Use $(REF find, std, algorithm, searching) to replace $(REF munch, std, string): +------- +import std.algorithm; +import std.ascii; +import std.string; +import std.utf; + +string s = "\tabc"; + +// old +s.munch(whitespace); + +// new +s = s.find!(a => !isWhite(a)); +------- + +Use $(REF matchFirst, std, regex) to replace $(REF inPattern, std, string): +------- +import std.string; +import std.regex; + +// old +if (inPattern('x', "a-z")) { ... } + +// new +if ("x".matchFirst(regex("[a-z]"))) { ... } +------- + +Use $(REF replaceAll, std, regex) to replace $(REF removechars, std, string): +------- +import std.string; +import std.regex; + +// old +"abc".removechars("a-z"); + +// new +"abc".replaceAll(regex("[a-z]"), ""); +------- + +Use $(REF uniq, std, algorithm, iteration) to replace $(REF squeeze, std, string): +------- +import std.algorithm; +import std.string; + +// old +"hello".squeeze; + +// new +"hello".uniq; +------- diff --git a/changelog/split-std-datetime.dd b/changelog/split-std-datetime.dd index 656979a6cac..13f080340ec 100644 --- a/changelog/split-std-datetime.dd +++ b/changelog/split-std-datetime.dd @@ -28,7 +28,7 @@ $(MREF std,datetime,timezone) contains the time zone types. $(MREF std,datetime,package) contains StopWatch and the benchmarking functions (so, they can only be imported via std.datetime and not via a submodule). As those functions use $(REF TickDuration,core,time) (which is being replaced by -$(REF MonoTime,core,time), they are slated for deprecation. +$(REF MonoTime,core,time), they are slated for deprecation). $(MREF std,datetime,stopwatch) has been added. It contains versions of StopWatch and benchmark which have almost the same API as the existing symbols, diff --git a/std/container/rbtree.d b/std/container/rbtree.d index 5342b1692e4..7db3ca61408 100644 --- a/std/container/rbtree.d +++ b/std/container/rbtree.d @@ -627,8 +627,7 @@ struct RBNode(V) Node dup() { - Node copy = new RBNode!V; - copy.value = value; + Node copy = new RBNode!V(null, null, null, value); copy.color = color; if (_left !is null) copy.left = _left.dup(); @@ -801,9 +800,7 @@ if (is(typeof(binaryFun!less(T.init, T.init)))) static private Node allocate(Elem v) { - auto result = allocate(); - result.value = v; - return result; + return new RBNode(null, null, null, v); } /** @@ -1190,7 +1187,8 @@ if (is(typeof(binaryFun!less(T.init, T.init)))) else { assert(ts.length == 5); - assert(ts.stableInsert(cast(Elem[])[7, 8, 6, 9, 10, 8]) == 5); + Elem[] elems = [7, 8, 6, 9, 10, 8]; + assert(ts.stableInsert(elems) == 5); assert(ts.length == 10); assert(ts.stableInsert(cast(Elem) 11) == 1 && ts.length == 11); assert(ts.stableInsert(cast(Elem) 7) == 0 && ts.length == 11); @@ -1398,11 +1396,7 @@ assert(equal(rbt[], [5])); size_t removeKey(U...)(U elems) if (allSatisfy!(isImplicitlyConvertibleToElem, U)) { - Elem[U.length] toRemove; - - foreach (i, e; elems) - toRemove[i] = e; - + Elem[U.length] toRemove = [elems]; return removeKey(toRemove[]); } @@ -2056,3 +2050,16 @@ if ( is(typeof(binaryFun!less((ElementType!Stuff).init, (ElementType!Stuff).init class C {} RedBlackTree!(C, "cast(void*)a < cast(void*) b") tree; } + +@safe pure unittest // const/immutable elements (issue 17519) +{ + RedBlackTree!(immutable int) t1; + RedBlackTree!(const int) t2; + + import std.algorithm.iteration : map; + static struct S { int* p; } + auto t3 = new RedBlackTree!(immutable S, (a, b) => *a.p < *b.p); + t3.insert([1, 2, 3].map!(x => immutable S(new int(x)))); + static assert(!__traits(compiles, *t3.front.p = 4)); + assert(*t3.front.p == 1); +} diff --git a/std/file.d b/std/file.d index 1fff42df695..d39093a37fe 100644 --- a/std/file.d +++ b/std/file.d @@ -4178,8 +4178,8 @@ auto dirEntries(string path, string pattern, SpanMode mode, * Reads a file line by line and parses the line into a single value or a * $(REF Tuple, std,typecons) of values depending on the length of `Types`. * The lines are parsed using the specified format string. The format string is - * passed to $(REF formattedRead, std,format), and therefore must conform to the - * format string specification outlined in $(MREF format). + * passed to $(REF formattedRead, std,_format), and therefore must conform to the + * format string specification outlined in $(MREF std, _format). * * Params: * Types = the types that each of the elements in the line should be returned as @@ -4193,7 +4193,7 @@ auto dirEntries(string path, string pattern, SpanMode mode, * Throws: * `Exception` if the format string is malformed. Also, throws `Exception` * if any of the lines in the file are not fully consumed by the call - * to $(REF formattedRead, std,format). Meaning that no empty lines or lines + * to $(REF formattedRead, std,_format). Meaning that no empty lines or lines * with extra characters are allowed. */ Select!(Types.length == 1, Types[0][], Tuple!(Types)[])