Commit graph

962 commits

Author SHA1 Message Date
Inkrementator
91af96cddb
Change documentation for reduce (#10707)
* reduce: Document Acc, Elem order in most visible place

* Reduce doesn't enforce predicates

* Reduce: Document behaviour on range with 1 elem

* Doc: Remove references to implemententation detail

Accumulator is the commonly used term for this concept.
2025-03-24 05:39:45 +08:00
Inkrementator
c79914db2d
Fix #10440 Use right template constraint for each (#10689)
The current contraints have been implemented in #3837 to make `each`
behave more like `foreach` and automatically destructure tuples.

I haven't publically documented this behavior because it is probably
better these days to use `bind` for that.
2025-03-19 07:14:17 +08:00
Inkrementator
d4dd391123
Remove obsolete workaround (#10641)
For resolved bugzilla issue 15777
2025-02-19 06:42:13 +08:00
Nick Treleaven
5f39350c48
Fix #10538 - Cannot swap a std.typecons.Tuple (#8864)
* Fix #10538 - Cannot swap a std.typecons.Tuple

Co-authored-by: Elias Batek <0xEAB@users.noreply.github.com>

* De-optimize `opAssign` of `std.typecons.Tuple`

---------

Co-authored-by: Elias Batek <0xEAB@users.noreply.github.com>
Co-authored-by: Elias Batek <desisma@heidel.beer>
2025-01-17 15:13:37 +08:00
Nick Treleaven
347e4152cc Extend tests 2025-01-03 03:38:57 +01:00
Nick Treleaven
92f677f2cf Only require input range 2025-01-03 03:38:57 +01:00
Nick Treleaven
762b0b4881 Minor tweaks 2025-01-03 03:38:57 +01:00
Nick Treleaven
6c7d0e2ef1 [std.algorithm.searching] Add extrema 2025-01-03 03:38:55 +01:00
Sebastian Wilzbach
d8955042d6
Fix #10257 - variadic overload of std.algorithm.searching.countUntil should return which needle was found (#5618) 2024-12-27 11:41:14 +08:00
Martin Kinkelin
b0ef9ac009 Merge remote-tracking branch 'origin/stable' into merge_stable 2024-11-17 01:17:07 +01:00
Jonathan M Davis
ef6a991534 Fix bugzilla issue 24809: In some cases, stable sort assigns to unininitialized elements (#9057) 2024-10-28 13:46:41 +01:00
Sönke Ludwig
9e78de4d86 Fix Bugzilla 24773: Don't invoke destructors on uninitialized elements in stable sort
Uses a regular initialized temporary array when sorting elements with an elaborate assignment to avoid undefined behavior when destructors, postblits or copy constructors are invoked during the array assignment.
2024-10-28 13:46:26 +01:00
Vladiwostok
231ae8b68a
Fix D-Scanner linting issues (#9070)
* Fix UndocumentedDeclarationCheck linting issue

* Fix IfConstraintsIndentCheck linting issue

* Address feedback

* Fix publictests CI

* Fix old (libdparse) D-Scanner linting warn
2024-10-27 01:21:56 -07:00
Jonathan M Davis
f0c3e4a66b
Fix Bugzilla issue 24827: maxElement does not handle opAssign correctly. (#9067)
Rebindable2 did not handle types with opAssign correctly, which affected
both minElement and maxElement. Namely, Rebindable2 assigned to memory
which was not properly initialized when the correct solution in such a
situation is to use copyEmplace. Assignment works when assignment is
just a memcpy, but in the general case, opAssign needs to have a
properly initialized object in order to work correctly. copyEmplace
instead copies the object and then places the copy into the unitialized
memory, so it avoids assigning to uninitialized memory.

This commit also adds additional tests for types with destructors (which
do get opAssign automatically) and types with postblit constructors or
copy constructors to try to ensure that the code is doing the correct
thing in those cases with regards to copying, assignment, and
destruction.

https://issues.dlang.org/show_bug.cgi?id=24829 was found in the process,
and this does not fix that. Namely, types which cannot be assigned to
and which also have a postblit constructor or copy constructor do not
get copied correctly. So, among the tests added here are commented out
tests for that case, since they're an altered version of some of the
enabled tests. However, fixing that issue would be involved enough that
I'm not attempting to fix it at this time.
2024-10-27 01:16:22 -07:00
Walter Bright
a51c0eada6
co-locate overloads of std.algorithm.mutation.swap() (#8951) 2024-10-18 13:18:04 +08:00
Jonathan M Davis
913ef46bca
Fix bugzilla issue 24809: In some cases, stable sort assigns to unininitialized elements (#9057) 2024-10-17 20:00:02 -07:00
Sönke Ludwig
2168becf74 Fix Bugzilla 24773: Don't invoke destructors on uninitialized elements in stable sort
Uses a regular initialized temporary array when sorting elements with an elaborate assignment to avoid undefined behavior when destructors, postblits or copy constructors are invoked during the array assignment.
2024-09-20 13:38:31 +02:00
Nick Treleaven
9ffe71fea3
Fix Bugzilla 15315 - can break immutable with std.algorithm.move (#9032) 2024-07-29 06:49:54 +08:00
0-v-0
d8e8f1f351 Remove std.conv import from quickSortImpl 2024-06-22 11:07:40 +08:00
FeepingCreature
539dc473ba
Fix bugzilla issue 24596: std.typecons.Rebindable2: Don't destroy classes! Only destroy structs! (#9012) 2024-06-10 23:10:18 +08:00
dokutoku
9a8325ca5f
Fix some invalid links (#8994)
Co-authored-by: dokutoku <3729541-dokutoku@users.noreply.gitlab.com>
2024-04-29 22:08:10 +08:00
Nick Treleaven
0b45fc77c6 Fix pred description when there's no needle 2024-03-13 11:26:58 +00:00
Nick Treleaven
4ea7dd3e07 Add short descriptions for each overload set; minor tweaks
Short descriptions improve ddox output.
Use overload instead of version.
2024-03-13 11:26:50 +00:00
Nick Treleaven
e695747422 Update cheat sheet description 2024-03-13 11:19:06 +00:00
Nick Treleaven
ac6c03a646 [std.algorithm.searching] Improve count docs
Fix `value` missing reference.
Tweak wording.
Explain `pred` better.
Separate out needle overloads from the other 2.
Fix 'Returns'.
Split example into 2.
2024-03-08 16:10:59 +00:00
Paul Backus
54a4afae9c
Merge pull request #8912 from ntrel/mut-remove
[std.algorithm.mutation] Improve `remove` docs
2024-02-15 08:59:06 -05:00
Walter Bright
42b8c65ccf CheckBy postblit should be scope 2024-02-12 09:24:07 +01:00
Nick Treleaven
ca9561b389 [std.algorithm.mutation] Improve remove docs
Make examples runnable.
Add 2 subheadings.
Minor tweaks.
Fix throwing example of tuple offset.
2024-02-10 12:34:45 +00:00
Mathis Beer
5976fe8c1a Fix Bugzilla issue 24342: Actually check that range and sentinel types match in until before using "sentinel as subrange" mode.
`until` does special magic when `Sentinel` consists of multiple elements of `Range`. However, because `Range` can be a range of ranges, in which case even a `Sentinel` that is a range may still only be a single element, we must confirm that the element type of `Sentinel` is actually the same as `Range` before enabling this.
The `immutable ElementEncodingType` idiom is stolen from `startsWith`, which forms the basis of `until` anyways (see `predSatisfied`).
2024-01-18 14:56:52 +08:00
Dennis
8c39523ba9
Merge pull request #8857 from ntrel/find-split-result
[std.algorithm.searching] Refactor `findSplit` result types
2023-11-28 23:38:54 +01:00
Dennis
505f81ab87
Merge pull request #8856 from ntrel/find-split-docs
[std/algorithm/searching] Improve findSplit docs
2023-11-28 23:34:43 +01:00
Nick Treleaven
52ae4d36a9 3 minor tweaks 2023-11-28 17:38:29 +00:00
Nick Treleaven
0819fec814 [std.algorithm.searching] Refactor findSplit result types 2023-11-28 17:28:55 +00:00
Nick Treleaven
6b5f730b84 [std/algorithm/searching] Improve findSplit docs
Improve formatting for returned tuple.
Fix type of `result[1]` for After/Before.
Fix `pred` description.
Show example using custom `pred`.
2023-11-27 17:19:31 +00:00
Dennis
fe33c84610
Merge pull request #8836 from ntrel/fold-docs
[std.algorithm] Improve `fold` docs
2023-11-20 17:36:06 +01:00
Nick Treleaven
0ced94ca1c
[std.algorithm] Split find docs into 2 (#8844)
It's much clearer to have separate docs for the overload not taking
`needle`, because its `pred` has a different signature and its behaviour
is simpler. It was necessary to move that overload (and its unittests)
above the other two.

Also improve the docs for the other overloads:
Remove duplicate BIGOH sentence already present under *Complexity*.
Use `e, n` for predicate parameter names, short for `element, needle`.
2023-11-20 22:19:03 +08:00
Nick Treleaven
edc5bbde7b Make new tests documented 2023-11-20 11:11:44 +00:00
Nick Treleaven
a2c2f79dfa Fix Issue 11111 - std.algorithm.canFind should support Needles...
The requirement that each needle must be a range is arbitrary, so remove
it.
Note: This overload of `canFind` calls `find(haystack, needles)` which
calls `startsWith`, which accepts mixed element and range needles.
2023-11-20 10:58:16 +00:00
Nick Treleaven
585ddbe691
[std.algorithm] Improve canFind docs (#8843)
Minor tweaks.
Fix wrong `LREF`.
Also fix wrong `REF` to `among`.
2023-11-20 05:55:26 +08:00
Nick Treleaven
7f06f2358a Rename b to e for element in predicates 2023-10-31 17:40:45 +00:00
Nick Treleaven
2170bb37bc Tweak seed description 2023-10-31 17:37:05 +00:00
Nick Treleaven
5762f3311b Explain predicate signature 2023-10-31 17:26:48 +00:00
Nick Treleaven
f491d1f233 [std.algorithm] Improve fold docs
Mention iteratively calling predicates in summary.
Use list to explain calling a single predicate with a seed.
Mention multiple results are produced in description.
Use list for see also.
Rename `seed` parameter `seeds` and fix docs.
Fix result docs when >1 predicate.
2023-10-30 16:17:24 +00:00
Per Nordlöw
578dfbfeb3 Correct spelling of Seperator to Separator in joiner() 2023-10-10 15:58:42 +02:00
Iain Buclaw
faca94c214 Fix broken tests caused by merge conflicts 2023-07-15 14:15:20 +00:00
Iain Buclaw
ab307c9acf Merge remote-tracking branch 'upstream/stable' into merge_stable 2023-07-15 13:49:21 +00:00
FeepingCreature
dfcbee7056 Fix issue 24027: Instead of a bunch of special-cases, just check that Rebindable did in fact alias itself away.
This looks ugly, but it's just for the `stable` branch - this is fixed on `master` via the `Rebindable2` rewrite https://github.com/dlang/phobos/pull/8768
2023-07-04 01:31:32 +02:00
Iain Buclaw
a3526d11dd Merge remote-tracking branch 'upstream/stable' into merge_stable 2023-07-02 02:10:20 +00:00
Mathis Beer
10601cc046 Add std.typecons.Rebindable2 for internal use.
Rebindable2 is a simplified version of std.typecons.Rebindable that clears up every special case: classes, arrays and structs now have the same struct.
Whichever type you instantiate `Rebindable2` with, you always get the same type out by calling `value.get` on the resulting container.
Also use this type to simplify the parts of Phobos we previously used `Rebindable` for.
2023-06-19 13:24:30 +02:00
Dennis
5cd77a6e32
User hyperlinks to refer to bugzilla issues (#8766) 2023-06-16 14:45:44 +03:00