aboutsummaryrefslogtreecommitdiff
path: root/libphobos/src/std/algorithm
diff options
context:
space:
mode:
authorIain Buclaw <ibuclaw@gdcproject.org>2024-02-17 21:03:38 +0100
committerIain Buclaw <ibuclaw@gdcproject.org>2024-02-17 21:28:58 +0100
commit5aff58e5ed8f634e0b20892452bde484db93039b (patch)
tree64900b511f0dbee5f61fb9e3e19c1ee8274f166a /libphobos/src/std/algorithm
parenta71d87431d0c4e04a402ef6566be090c470b2b53 (diff)
downloadgcc-5aff58e5ed8f634e0b20892452bde484db93039b.zip
gcc-5aff58e5ed8f634e0b20892452bde484db93039b.tar.gz
gcc-5aff58e5ed8f634e0b20892452bde484db93039b.tar.bz2
d: Merge dmd, druntime 9471b25db9, phobos 547886846.
D front-end changes: - Import dmd v2.107.1-rc.1. D runtime changes: - Import druntime v2.107.1-rc.1. Phobos changes: - Import phobos v2.107.1-rc.1. gcc/d/ChangeLog: * dmd/MERGE: Merge upstream dmd 9471b25db9. * dmd/VERSION: Bump version to v2.107.1-rc.1. * Make-lang.in (D_FRONTEND_OBJS): Add d/cxxfrontend.o. * d-attribs.cc (build_attributes): Update for new front-end interface. * d-builtins.cc (build_frontend_type): Likewise. (strip_type_modifiers): Likewise. (covariant_with_builtin_type_p): Likewise. * d-codegen.cc (declaration_type): Likewise. (parameter_type): Likewise. (build_array_struct_comparison): Likewise. (void_okay_p): Likewise. * d-convert.cc (convert_expr): Likewise. (check_valist_conversion): Likewise. * d-lang.cc (d_generate_ddoc_file): Likewise. (d_parse_file): Likewise. * d-target.cc (TargetCPP::toMangle): Likewise. (TargetCPP::typeInfoMangle): Likewise. (TargetCPP::thunkMangle): Likewise. (TargetCPP::parameterType): Likewise. * decl.cc (d_mangle_decl): Likewise. (DeclVisitor::visit): Likewise. (DeclVisitor::visit (CAsmDeclaration *)): New method. (get_symbol_decl): Update for new front-end interface. (layout_class_initializer): Likewise. * expr.cc (ExprVisitor::visit): Likewise. * intrinsics.cc (maybe_set_intrinsic): Likewise. (expand_intrinsic_rotate): Likewise. * modules.cc (layout_moduleinfo_fields): Likewise. (layout_moduleinfo): Likewise. * runtime.cc (get_libcall_type): Likewise. * typeinfo.cc (make_frontend_typeinfo): Likewise. (TypeInfoVisitor::visit): Likewise. (create_typeinfo): Likewise. * types.cc (same_type_p): Likewise. (build_ctype): Likewise. libphobos/ChangeLog: * libdruntime/MERGE: Merge upstream druntime 9471b25db9. * src/MERGE: Merge upstream phobos 547886846.
Diffstat (limited to 'libphobos/src/std/algorithm')
-rw-r--r--libphobos/src/std/algorithm/iteration.d4
-rw-r--r--libphobos/src/std/algorithm/mutation.d38
2 files changed, 33 insertions, 9 deletions
diff --git a/libphobos/src/std/algorithm/iteration.d b/libphobos/src/std/algorithm/iteration.d
index ef11706..1453d2b 100644
--- a/libphobos/src/std/algorithm/iteration.d
+++ b/libphobos/src/std/algorithm/iteration.d
@@ -2027,7 +2027,7 @@ private struct ChunkByGroup(alias eq, Range, bool eqEquivalenceAssured)
}
// Cannot be a copy constructor due to https://issues.dlang.org/show_bug.cgi?id=22239
- this(this) @trusted
+ this(this) scope @trusted
{
import core.lifetime : emplace;
// since mothership has to be in a union, we have to manually trigger
@@ -2129,7 +2129,7 @@ if (isForwardRange!Range)
}
// Cannot be a copy constructor due to https://issues.dlang.org/show_bug.cgi?id=22239
- this(this) @trusted
+ this(this) scope @trusted
{
import core.lifetime : emplace;
// since _impl has to be in a union, we have to manually trigger
diff --git a/libphobos/src/std/algorithm/mutation.d b/libphobos/src/std/algorithm/mutation.d
index 61b6a5e..fbef28e 100644
--- a/libphobos/src/std/algorithm/mutation.d
+++ b/libphobos/src/std/algorithm/mutation.d
@@ -1813,22 +1813,28 @@ range.
For example, here is how to remove a single element from an array:
+$(RUNNABLE_EXAMPLE
----
+import std.algorithm.mutation;
string[] a = [ "a", "b", "c", "d" ];
a = a.remove(1); // remove element at offset 1
assert(a == [ "a", "c", "d"]);
----
+)
Note that `remove` does not change the length of the original range directly;
instead, it returns the shortened range. If its return value is not assigned to
the original range, the original range will retain its original length, though
its contents will have changed:
+$(RUNNABLE_EXAMPLE
----
+import std.algorithm.mutation;
int[] a = [ 3, 5, 7, 8 ];
assert(remove(a, 1) == [ 3, 7, 8 ]);
assert(a == [ 3, 7, 8, 8 ]);
----
+)
The element at offset `1` has been removed and the rest of the elements have
shifted up to fill its place, however, the original array remains of the same
@@ -1838,25 +1844,34 @@ invoked to rearrange elements, and on integers `move` simply copies the source
to the destination. To replace `a` with the effect of the removal, simply
assign the slice returned by `remove` to it, as shown in the first example.
+$(H3 $(LNAME2 remove-multiple, Removing multiple elements))
+
Multiple indices can be passed into `remove`. In that case,
elements at the respective indices are all removed. The indices must
be passed in increasing order, otherwise an exception occurs.
+$(RUNNABLE_EXAMPLE
----
+import std.algorithm.mutation;
int[] a = [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ];
assert(remove(a, 1, 3, 5) ==
[ 0, 2, 4, 6, 7, 8, 9, 10 ]);
----
+)
-(Note that all indices refer to slots in the $(I original) array, not
-in the array as it is being progressively shortened.)
+Note that all indices refer to slots in the $(I original) array, not
+in the array as it is being progressively shortened.
-Tuples of two integral offsets can be used to remove an indices range:
+Tuples of two integral offsets can be supplied to remove a range of indices:
+$(RUNNABLE_EXAMPLE
----
+import std.algorithm.mutation, std.typecons;
int[] a = [ 3, 4, 5, 6, 7];
-assert(remove(a, 1, tuple(1, 3), 9) == [ 3, 6, 7 ]);
+// remove elements at indices 1 and 2
+assert(remove(a, tuple(1, 3)) == [ 3, 6, 7 ]);
----
+)
The tuple passes in a range closed to the left and open to
the right (consistent with built-in slices), e.g. `tuple(1, 3)`
@@ -1865,22 +1880,31 @@ means indices `1` and `2` but not `3`.
Finally, any combination of integral offsets and tuples composed of two integral
offsets can be passed in:
+$(RUNNABLE_EXAMPLE
----
+import std.algorithm.mutation, std.typecons;
int[] a = [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ];
-assert(remove(a, 1, tuple(3, 5), 9) == [ 0, 2, 5, 6, 7, 8, 10 ]);
+a = remove(a, 1, tuple(3, 5), 9);
+assert(a == [ 0, 2, 5, 6, 7, 8, 10 ]);
----
+)
In this case, the slots at positions 1, 3, 4, and 9 are removed from
the array.
+$(H3 $(LNAME2 remove-moving, Moving strategy))
+
If the need is to remove some elements in the range but the order of
the remaining elements does not have to be preserved, you may want to
pass `SwapStrategy.unstable` to `remove`.
+$(RUNNABLE_EXAMPLE
----
+import std.algorithm.mutation;
int[] a = [ 0, 1, 2, 3 ];
assert(remove!(SwapStrategy.unstable)(a, 1) == [ 0, 3, 2 ]);
----
+)
In the case above, the element at slot `1` is removed, but replaced
with the last element of the range. Taking advantage of the relaxation
@@ -1888,7 +1912,7 @@ of the stability requirement, `remove` moved elements from the end
of the array over the slots to be removed. This way there is less data
movement to be done which improves the execution time of the function.
-The function `remove` works on bidirectional ranges that have assignable
+`remove` works on bidirectional ranges that have assignable
lvalue elements. The moving strategy is (listed from fastest to slowest):
$(UL
@@ -1914,7 +1938,7 @@ Params:
offset = which element(s) to remove
Returns:
- A range containing all of the elements of range with offset removed.
+ A range containing elements of `range` with 1 or more elements removed.
*/
Range remove
(SwapStrategy s = SwapStrategy.stable, Range, Offset ...)