Commit graph

240 commits

Author SHA1 Message Date
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
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
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
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
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
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
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
FeepingCreature
f715941036 Fix issue 23993: Discard Rebindable before passing extremum to comparator. 2023-06-15 19:06:27 +02:00
Mathis Beer
2f6b2efaf7 Change struct Rebindable to just use cast() if this is sufficient.
This works better at compiletime.
2023-04-19 22:59:43 +00:00
Mathis Beer
b818901e63 Fix issue 22786 (immutable element in maxElement) by always using Rebindable. 2023-04-19 22:59:43 +00:00
Nick Treleaven
01a12f919e
[std.algorithm.searching] Don't instantiate template pred in all and any constraints (#8715)
Fixes Issue 23769 - Lambda isn't a unary predicate for lambda that
doesn't compile.
2023-04-10 19:10:18 +03:00
Nick Treleaven
72da991685
[std.algorithm.searching] Fix 2 typos in docs (#8728) 2023-03-31 15:38:47 +03:00
james
bc5126469e Fix Issue 14542 - std.algorithm.searching.until does not handle range sentinels nicely 2022-09-23 16:44:42 +02:00
Adam D. Ruppe
8ed1c4095a wrong example - the paren char args are required 2022-08-01 10:08:24 +00:00
Iulia Dumitru
d0c52225b4 Fix issue 18735 all versions of find and canfind should identify usage of predicate 2022-07-24 02:55:44 +00:00
João Lourenço
f25b3fc78e
Issue 22582 - [std.algorithm.count] predicate does not implicitly convert to bool (#8330)
Issue 22582 - [std.algorithm.count] predicate does not implicitly convert to bool

Signed-off-by: Razvan Nitu <RazvanN7@users.noreply.github.com>
Merged-on-behalf-of: Razvan Nitu <RazvanN7@users.noreply.github.com>
2021-12-10 15:16:45 +00:00
Julian Fondren
dc2bf7901f Fix issue 20554 - std.algorithm.searching.all 's static assert produces a garbled error message 2021-09-21 20:25:26 -05:00
Paul Backus
d08548e925 Fix Issue 22297 - Behavior of minElement and maxElement with empty range is undocumented 2021-09-10 17:57:46 +00:00
vladchicos
68dab0e2e5 Fix Issue 19727 - std.algorithm.endsWith fails to compile while startsWith succeeds. 2021-08-12 05:09:14 +03:00
Walter Bright
3301a20c16 fix Issue 22146 - std.algorithm.searching.findAdjacent() can fall off end of function 2021-07-26 14:37:43 +00:00
João Lourenço
882cf3df43
std.algorithm: improve findSplit methods module documentation
Signed-off-by: João Lourenço <jlourenco5691@gmail.com>
2021-06-07 12:07:47 +01:00
nordlow
5d31a68082 Break line to please maximum line length enforced by style checker 2021-05-17 12:04:06 +02:00
nordlow
6bef53dd1a Annotate std/algorithm/searching.d to please dlang/dmd#12520 #8076 2021-05-17 00:02:04 +02:00
Nathan Sashihara
a23fa4ed06 Fix issue #21702 - avoid quadratic template expansion in constraints of multiple search term versions of std.algorithm.searching.startsWith & endsWith 2021-04-25 20:43:24 +08:00
berni44
b2019ebab0 Narrow imports of std.math in the rest of phobos. 2021-04-21 03:00:57 +02:00
Paul Backus
f94815142a Fix incorrect usage of "verify" in docs
Other documentation in std.algorithm.searching consistently uses
"satisfy" for predicates.
2021-03-10 11:23:28 -05:00
Paul Backus
97fe720085 Document result of 'all' and 'any' on empty range 2021-03-10 11:21:24 -05:00
Razvan Nitu
44e47a03d2
Merge pull request #7807 from BorisCarvajal/bug21651_changes
Remove a few uses of fully qualified names that rely on a DMD bug
2021-02-23 00:33:17 +08:00
Boris Carvajal
276053dd07
Remove a few uses of fully qualified names that rely on a DMD bug 2021-02-22 08:16:13 -03:00
Bastiaan Veelo
e2a2c54927
Fix copy-paste error in documentation. 2021-02-22 11:15:05 +01:00