12049 Commits

Author SHA1 Message Date
David Spickett
23eadbda36 [libcxx][test] Use smaller time range for 32 bit time_t (#104762)
This fixes the test on Arm 32 bit Ubuntu Jammy where time_t is 32 bit.

(cherry picked from commit cdd608b8f0ce090b3568238387df368751bdbb5d)
2024-10-01 09:03:25 +02:00
David Spickett
4dbe72f91a [lldb][test] Mark sys_info zdump test unsupported on 32 bit Arm Linux
Until https://github.com/llvm/llvm-project/pull/103056 lands
or another more appropriate check can be found.

This test fails on Ubuntu Focal where zdump is built with 32 bit time_t
but passes on Ubuntu Jammy where zdump is built with 64 bit time_t.

Marking it unsupported means Linaro can upgrade its bots to Ubuntu
Jammy without getting an unexpected pass.

(cherry picked from commit 6f6422f4a2b8647a59936c131e50a79906d89510)
2024-10-01 09:03:25 +02:00
Tobias Hieta
fae11d419d
Bump version to 19.1.1 2024-10-01 09:02:07 +02:00
Louis Dionne
53010fcf66 [libc++] Fix AppleClang version number when checking for __builtin_verbose_trap support (#110161)
We should have been checking against 1700, not 17000, which was a typo.

(cherry picked from commit 1eba87904b0cbaaee82cfdb835528b85d99320ef)
2024-10-01 08:56:18 +02:00
Louis Dionne
8a25c601eb [libc++] Disable the clang-tidy checks to get CI back (#109989)
The CI has been a complete mess for the past week, and the only thing
preventing it from being back is the Clang tidy checks. Disable them (as
a total hack) to get CI back.

(cherry picked from commit 78c6506543dee13c9335edc5c85bc73c4853fbd7)
2024-09-26 16:00:43 -04:00
Konstantin Varlamov
82f3a4a32d Guard an include of <ostream> in <chrono> with availability macro (#108429)
This fixes a regression introduced in
https://github.com/llvm/llvm-project/pull/96035.

(cherry picked from commit 127c34948bd54e92ef2ee544e8bc42acecf321ad)
2024-09-16 20:31:52 +02:00
Ties Stuij
6f623478d4 [libcxx] don't #include <cwchar> if wide chars aren't enabled (#99911)
Pull request #96032 unconditionall adds the `cwchar` include in the
`format` umbrella header. However support for wchar_t can be disabled in
the build system (LIBCXX_ENABLE_WIDE_CHARACTERS).

This patch guards against inclusion of `cwchar` in `format` by checking
the `_LIBCPP_HAS_NO_WIDE_CHARACTERS` define.

For clarity I've also merged the include header section that `cwchar`
was in with the one above as they were both guarded by the same `#if`
logic.

(cherry picked from commit ec56790c3b27df4fa1513594ca9a74fd8ad5bf7f)
2024-09-01 10:20:37 +02:00
Louis Dionne
6883c490e0 [libc++] Add missing include to three_way_comp_ref_type.h
We were using a `_LIBCPP_ASSERT_FOO` macro without including `<__assert>`.

rdar://134425695
(cherry picked from commit 0df78123fdaed39d5135c2e4f4628f515e6d549d)
2024-09-01 10:11:08 +02:00
Louis Dionne
90f2d48965 [libc++] Fix rejects-valid in std::span copy construction (#104500)
Trying to copy-construct a std::span from another std::span holding an
incomplete type would fail as we evaluate the SFINAE for the range-based
constructor. The problem was that we checked for __is_std_span after
checking for the range being a contiguous_range, which hard-errored
because of arithmetic on a pointer to incomplete type.

As a drive-by, refactor the whole test and format it.

Fixes #104496

(cherry picked from commit 99696b35bc8a0054e0b0c1a26e8dd5049fa8c41b)
2024-08-19 09:17:27 +02:00
Louis Dionne
4d4a4100f6 [libc++] Fix ambiguous constructors for std::complex and std::optional (#103409)
Fixes #101960

(cherry picked from commit 4d08bb11eea5907fa9cdfe4c7bc9d5c91e79c6a7)
2024-08-15 09:40:37 +02:00
Brian Cain
a3b18fcd24 [libc++] Use a different smart ptr type alias (#102089)
The `_SP` type is used by some C libraries and this alias could conflict
with it.

(cherry picked from commit 7951673d408ee64744d0b924a49db78e8243d876)
2024-08-15 09:34:45 +02:00
PaulXiCao
2c29bd3d4c [libc++][math] Fix undue overflowing of std::hypot(x,y,z) (#100820)
This is in relation to mr #93350. It was merged to main, but reverted
because of failing sanitizer builds on PowerPC.

The fix includes replacing the hard-coded threshold constants (e.g.
`__overflow_threshold`) for different floating-point sizes by a general
computation using `std::ldexp`. Thus, it should now work for all architectures.
This has the drawback of not being `constexpr` anymore as `std::ldexp`
is not implemented as `constexpr` (even though the standard mandates it
for C++23).

Closes #92782

(cherry picked from commit 72825fde03aab3ce9eba2635b872144d1fb6b6b2)
2024-08-13 09:07:01 +02:00
Mitch Phillips
5230e327a1 Revert "[libc++][math] Fix undue overflowing of std::hypot(x,y,z) (#93350)"
This reverts commit 9628777479a970db5d0c2d0b456dac6633864760.

More details in https://github.com/llvm/llvm-project/pull/93350, but
this broke the PowerPC sanitizer bots.

(cherry picked from commit 1031335f2ee1879737576fde3a3425ce0046e773)
2024-08-13 09:07:01 +02:00
Xing Xue
f6381989f4 [NFC][libc++][test][AIX] UnXFAIL LIT test transform.pass.cpp (#102338)
Remove `XFAIL: LIBCXX-AIX-FIXME` from lit test `transform.pass.cpp` now
that AIX system call `wcsxfrm`/`wcsxfrm_l` is fixed in AIX 7.2.5.8 and
7.3.2.2 and buildbot machines have been upgraded.

Backported from commit cb5912a71061c6558bd4293596dcacc1ce0ca2f6
2024-08-12 10:39:47 +02:00
Mark de Wever
01a49d21c7 [libc++][bit] Improves rotate functions. (#98032)
Investigating #96612 shows our implementation was different from the
Standard and could cause UB. Testing the codegen showed quite a bit of
assembly generated for these functions. The functions have been written
differently which allows Clang to optimize the code to use simple CPU
rotate instructions.

Fixes: https://github.com/llvm/llvm-project/issues/96612
2024-08-10 11:52:40 +02:00
Xing Xue
3ee69f2405 [NFC][libc++][libc++abi][libunwind][test] Fix/unify AIX triples used in LIT tests (#101196)
This patch fixes/unifies AIX target triples used in libc++, libc++abi,
and libunwind LIT tests.

(cherry picked from commit 2d3655037ccfa276cb0949c2ce0cff56985f6637)
2024-08-02 09:26:00 +02:00
Damien L-G
39e8e7797a [libc++] Increase atomic_ref's required alignment for small types (#99654)
This patch increases the alignment requirement for std::atomic_ref
such that we can guarantee lockfree operations more often. Specifically,
we require types that are 1, 2, 4, 8, or 16 bytes in size to be aligned
to at least their size to be used with std::atomic_ref.

This is the case for most types, however a notable exception is
`long long` on x86, which is 8 bytes in length but has an alignment
of 4.

As a result of this patch, one has to be more careful about the
alignment of objects used with std::atomic_ref. Failure to provide
a properly-aligned object to std::atomic_ref is a precondition
violation and is technically UB. On the flipside, this allows us
to provide an atomic_ref that is actually lockfree more often,
which is an important QOI property.

More information in the discussion at https://github.com/llvm/llvm-project/pull/99570#issuecomment-2237668661.

Co-authored-by: Louis Dionne <ldionne.2@gmail.com>
(cherry picked from commit 59ca618e3b7aec8c32e24d781bae436dc99b2727)
2024-08-02 09:25:20 +02:00
Louis Dionne
0e615206e3 [libc++] Revert "Use GCC type traits builtins for remove_cv and remove_cvref (#81386)"
This reverts commit 55357160d0e151c32f86e1d6683b4bddbb706aa1.
This is only being reverted from the LLVM 19 branch as a
convenience to avoid breaking some IDEs which were not ready
for that change.

Fixes #99464
2024-08-01 09:21:02 +02:00
Mark de Wever
3389604cd9 [libc++][spaceship] Marks P1614 as complete. (#99375)
Implements parts of:
- P1902R1 Missing feature-test macros 2017-2019

Completes:
- P1614R2 The Mothership has Landed

Fixes #100018
2024-07-30 17:06:54 +02:00
Louis Dionne
f53633b1e2 [libc++][libc++abi] Minor follow-up changes after ptrauth upstreaming (#87481)
This patch applies the comments provided on #84573. This is done as a
separate PR to avoid merge conflicts with downstreams that already had
ptrauth support.

(cherry picked from commit e64e745e8fb802ffb06259b1a5ba3db713a17087)
2024-07-29 10:05:31 +02:00
Louis Dionne
47fafad155 [libc++] Fix bug in atomic_ref's calculation of lock_free-ness (#99570)
The builtin __atomic_always_lock_free takes into account the type of the
pointer provided as the second argument. Because we were passing void*,
rather than T*, the calculation failed. This meant that
atomic_ref<T>::is_always_lock_free was only true for char & bool.

This bug exists elsewhere in the atomic library (when using GCC, we fail
to pass a pointer at all, and we fail to correctly align the atomic like
_Atomic would).

This change also attempts to start sorting out testing difficulties with
this function that caused the bug to exist by using the
__GCC_ATOMIC_(CHAR|SHORT|INT|LONG|LLONG|POINTER)_IS_LOCK_FREE predefined
macros to establish an expected value for `is_always_lock_free` and
`is_lock_free` for the respective types, as well as types with matching
sizes and compatible alignment values.

Using these compiler pre-defines we can actually validate that certain
types, like char and int, are actually always lock free like they are on
every platform in the wild.

Note that this patch was actually authored by Eric Fiselier but I picked
up the patch and GitHub won't let me set Eric as the primary author.

Co-authored-by: Eric Fiselier <eric@efcs.ca>
(cherry picked from commit cc1dfb37aa84d1524243b83fadb8ff0f821e03e9)
2024-07-27 16:03:10 +02:00
Louis Dionne
ec17a7a759 [libc++] Add missing xlocale.h include on Apple and FreeBSD (#99689)
The `<locale>` header uses `strtoll_l` and friends which are defined in
`<xlocale.h>` on these platforms. While this works via transitive
includes when modules are disabled, this doesn't work anymore if the
platforms are modularized properly.

(cherry picked from commit a55df237375e98cfc2520d5eb1a23b302ef02ba0)
2024-07-26 09:29:22 +02:00
Mark de Wever
05446fb31a [libc++][spaceship] Implements X::iterator container requirements. (#99343)
This implements the requirements for the container iterator requirements
for array, deque, vector, and `vector<bool>`.

Implements:
- LWG3352 strong_equality isn't a thing

Implements parts of:
- P1614R2 The Mothership has Landed

Fixes: https://github.com/llvm/llvm-project/issues/62486
2024-07-26 09:25:49 +02:00
Louis Dionne
5c03c4fc26 [libc++] Improve behavior when using relative path for LIBCXX_ASSERTION_HANDLER_FILE (#100157)
Fixes #80696

(cherry picked from commit 046a17717d9c5b5385ecd914621b48bdd91524d0)
2024-07-26 09:25:23 +02:00
Mark de Wever
2df1cec9db [libc++][doc] Update the release notes for LLVM 19. (#99061)
This is a preparation for the upcoming LLVM 19 release.
2024-07-26 09:20:03 +02:00
Mark de Wever
c5cd826c05 [libc++][string] Fixes shrink_to_fit. (#97961)
This ensures that shrink_to_fit does not increase the allocated size.

Partly addresses #95161

(cherry picked from commit d0ca9f23e8f25b0509c3ff34ed215508b39ea6e7)
2024-07-24 09:25:07 +02:00
Mark de Wever
a930d1f322 [libc++][vector<bool>] Tests shrink_to_fit requirement. (#98009)
`vector<bool>`'s shrink_to_fit implementation is using the
"swap-to-free-container-resources-trick" which only shrinks when the
input vector is empty. Since the request to shrink_to_fit is
non-binding, this is a valid implementation. It is not a high-quality
implementation. Since `vector<bool>` is not a very popular container the
implementation has not been changed and only a test to validate the
non-growing property has been added.

This was discovered while investigating #95161.

(cherry picked from commit c2e438675754b83c31d7d5ba40cb13fe77e795de)
2024-07-24 09:24:42 +02:00
PaulXiCao
40af7ee9c1 [libc++][math] Fix undue overflowing of std::hypot(x,y,z) (#93350)
The 3-dimentionsional `std::hypot(x,y,z)` was sub-optimally implemented.
This lead to possible over-/underflows in (intermediate) results which
can be circumvented by this proposed change.

The idea is to to scale the arguments (see linked issue for full
discussion).

Tests have been added for problematic over- and underflows.

Closes #92782

(cherry picked from commit 9628777479a970db5d0c2d0b456dac6633864760)
2024-07-24 09:24:11 +02:00
Tobias Hieta
c2dbaeb91a
Bump version to 19.1.0git 2024-07-23 11:06:16 +02:00
David Benjamin
bcf9fb9802
[libc++][hardening] Use bounded iterators in std::vector and std::string (#78929)
~~NB: This PR depends on #78876. Ignore the first commit when reviewing,
and don't merge it until #78876 is resolved. When/if #78876 lands, I'll
clean this up.~~

This partially restores parity with the old, since removed debug build.
We now can re-enable a bunch of the disabled tests. Some things of note:

- `bounded_iter`'s converting constructor has never worked. It needs a
friend declaration to access the other `bound_iter` instantiation's
private fields.

- The old debug iterators also checked that callers did not try to
compare iterators from different objects. `bounded_iter` does not
currently do this, so I've left those disabled. However, I think we
probably should add those. See
https://github.com/llvm/llvm-project/issues/78771#issuecomment-1902999181

- The `std::vector` iterators are bounded up to capacity, not size. This
makes for a weaker safety check. This is because the STL promises not to
invalidate iterators when appending up to the capacity. Since we cannot
retroactively update all the iterators on `push_back()`, I've instead
sized it to the capacity. This is not as good, but at least will stop
the iterator from going off the end of the buffer.

There was also no test for this, so I've added one in the `std`
directory.

- `std::string` has two ambiguities to deal with. First, I opted not to
size it against the capacity. https://eel.is/c++draft/string.require#4
says iterators are invalidated on an non-const operation. Second,
whether the iterator can reach the NUL terminator. The previous debug
tests and the special-case in https://eel.is/c++draft/string.access#2
suggest no. If either of these causes widespread problems, I figure we
can revisit.

- `resize_and_overwrite.pass.cpp` assumed `std::string`'s iterator
supported `s.begin().base()`, but I see no promise of this in the
standard. GCC also doesn't support this. I fixed the test to use
`std::to_address`.

- `alignof.compile.pass.cpp`'s pointer isn't enough of a real pointer.
(It needs to satisfy `NullablePointer`, `LegacyRandomAccessIterator`,
and `LegacyContiguousIterator`.) `__bounded_iter` seems to instantiate
enough to notice. I've added a few more bits to satisfy it.

Fixes #78805
2024-07-22 22:44:25 -07:00
Ryan Prichard
a1359f5ed4
[libc++][Android] Pass -no-metrics to emulator (#99627)
The Android Emulator has started printing this message, so pass the
`-no-metrics` option:

```
##############################################################################
##                        WARNING - ACTION REQUIRED                         ##
##  Consider using the '-metrics-collection' flag to help improve the       ##
##  emulator by sending anonymized usage data. Or use the '-no-metrics'     ##
##  flag to bypass this warning and turn off the metrics collection.        ##
##  In a future release this warning will turn into a one-time blocking     ##
##  prompt to ask for explicit user input regarding metrics collection.     ##
##                                                                          ##
##  Please see '-help-metrics-collection' for more details. You can use     ##
##  '-metrics-to-file' or '-metrics-to-console' flags to see what type of   ##
##  data is being collected by emulator as part of usage statistics.        ##
##############################################################################
```
2024-07-22 15:30:31 -07:00
nicole mazzuca
4189226236
[libc++] Update some C++23 statuses to "Nothing to do" or "Complete" (#99621)
- [P2160R1][] "Locks lock lockables"
- [P2212R2][] "Relax Requirements for `time_point::clock`"
- [P1675R2][] "`rethrow_exception` must be allowed to copy"
- [P2340R1][] "Clarifying the status of the 'C headers'"
- [P2460R2][] "Relax requirements on `wchar_t` to match existing
practices"

Are all papers that change wording without changing implementation
behaviour.

Additionally, [P2736R2][] "Referencing The Unicode Standard", is an
already complete paper in 19.0 (as of [LLVM-86543][])

[P2160R1]: https://wg21.link/p2160r1
[P2212R2]: https://wg21.link/p2212r2
[P1675R2]: https://wg21.link/p1675r2
[P2340R1]: https://wg21.link/p2340r1
[P2460R2]: https://wg21.link/p2460r2
[P2736R2]: https://wg21.link/p2736r2
[LLVM-86543]: https://github.com/llvm/llvm-project/pull/86543
2024-07-22 18:33:41 +02:00
Xiaoyang Liu
3d7622ea0b
[libc++][ranges] LWG3618: Unnecessary iter_move for transform_view::iterator (#91809)
## Introduction

This patch implements LWG3618: Unnecessary `iter_move` for
`transform_view::iterator`.

`transform_view`'s iterator currently specifies a customization point
for `iter_move`. This customization point does the same thing that the
default implementation would do, but its sole purpose is to ensure the
appropriate conditional `noexcept` specification.

## Reference

-
[[range.transform.iterator]](https://eel.is/c++draft/range.transform.iterator)
- [LWG3618](https://cplusplus.github.io/LWG/issue3618)
2024-07-22 18:32:37 +02:00
Martin Storsjö
ec966f699d
[libcxx] [test] Make indentation more consistent in thousands_sep. NFC. (#99844)
This was made inconsistent recently in
f114eddb1923289b696f1b0980cc22c4dbaafa22.
2024-07-22 19:31:47 +03:00
Mark de Wever
14ec4746cc
[libc++] Makes `unique_ptr operator*() noexcept. (#98047)
This implements
 - LWG2762  unique_ptr operator*() should be noexcept.

Differential Revision: https://reviews.llvm.org/D128214
2024-07-21 13:06:02 +02:00
Nikolas Klauser
f9dd885cb6
[libc++] Make std::pair trivially copyable if its members are (#89652)
This makes `std::pair` trivially copyable if its members are and we have
a way to do so. We need either C++20 with requires clauses or support
for `__attribute__((enable_if))`. Only Clang has support for this
attribute, so it's effectively clang or C++20.

Co-authored-by: Christopher Di Bella <cjdb@google.com>
2024-07-20 19:59:06 +02:00
Mark de Wever
afbfb16d29
[libc++][TZDB] Implements zoned_time formatters. (#98347)
Implements parts of:
- P0355 Extending to chrono Calendars and Time Zones
- P1361 Integration of chrono with text formatting
- P2372 Fixing locale handling in chrono formatters
2024-07-20 19:24:41 +02:00
PaulXiCao
af0d731b12
[libc++][math] Mathematical Special Functions: Hermite Polynomial (#89982)
Implementing the Hermite polynomials which are part of C++17's
mathematical special functions. The goal is to get early feedback which
will make implementing the other functions easier. Integration of
functions in chunks (e.g. `std::hermite` at first, then `std::laguerre`,
etc.) might make sense as well (also see note on boost.math below).

I started out from this abandoned merge request:
https://reviews.llvm.org/D58876 .

The C++23 standard defines them in-terms of `/* floating-point type */`
arguments. I have not looked into that.

Note, there is still an ongoing discussion on discourse whether
importing boost.math is an option.
2024-07-20 17:50:05 +02:00
Mark de Wever
f65d7fdcf8
[libc++][vector] Fixes shrink_to_fit. (#97895)
This assures shrink_to_fit does not increase the allocated size.

Partly addresses https://github.com/llvm/llvm-project/issues/95161

---------

Co-authored-by: Mital Ashok <mital.vaja@googlemail.com>
2024-07-20 12:55:44 +02:00
Tacet
9d03275550
[ASan][libc++] Turn off SSO annotations for Apple platforms (#96269)
This commit disables short string AddressSanitizer annotations on Apple
platforms as a temporary solution to the problem reported in #96099.

For more information on Apple's block implementation, please refer to
clang/docs/Block-ABI-Apple.rst [1]. The core issue lies in the fact
that blocks are unaware of their content, causing AddressSanitizer
errors when blocks are moved using `memmove`.

I believe - and I'm not alone - that the issue should ideally be
addressed within the block moving logic. However, this patch provides
a temporary fix until a proper resolution exists in the Blocks runtime.

[1]: https://github.com/llvm/llvm-project/blob/main/clang/docs/Block-ABI-Apple.rst
2024-07-19 17:24:10 -04:00
Louis Dionne
ffda521228
[libc++] Make libc++ forward-compatible with AppleClang's definition of __builtin_verbose_trap (#99529)
AppleClang as included in the Xcode 16 beta implements
`__builtin_verbose_trap`, but it implements slightly different semantics
from the ones implemented upstream. This patch makes libc++ compatible
with either definition until we drop support for the version of
AppleClang that differs from upstream.
2024-07-19 17:00:40 -04:00
nicole mazzuca
04760bfadb
[libc++][ranges] P1223R5: find_last (#99312)
Implements [P1223R5][] completely.

Includes an implementation of `find_last`, `find_last_if`, and
`find_last_if_not`.

[P1223R5]: https://wg21.link/p1223r5
2024-07-19 09:42:16 -07:00
Louis Dionne
2f8c786846
[libc++] Refactor buildkite-pipeline.yml (#99483)
This patch removes unused stuff from the Buildkite pipeline definition.
2024-07-19 11:47:34 -04:00
Louis Dionne
da44c0695c
[libc++][docs] Add tip for developers running the test suite on macOS (#99544) 2024-07-19 11:46:35 -04:00
David Spickett
f0617d2def
[libcxx][test] Remove picolib UNSUPPORTED for now.pass.cpp (#99503)
This ARM semihosting call was implemented in QEMU by
4d834039c2
and is present in the qemu-system-arm v8.1.3 used by the builders.
2024-07-19 09:59:06 +01:00
Petr Hosek
3b78dfa10c
[libc][libcxx] Support for building libc++ against LLVM libc (#99287)
Provide an option to build libc++ against LLVM libc and set the CMake
compile and link options appropriately when the option is enabled.
2024-07-18 22:17:42 -07:00
Hristo Hristov
e475bb7ac3
[libc++][memory] P1132R8: out_ptr - a scalable output pointer abstraction (#73618)
Differential Revision: https://reviews.llvm.org/D150525

Implements:
- https://wg21.link/P1132R8 - `out_ptr` - a scalable output pointer
abstraction
- https://eel.is/c++draft/smartptr.adapt - 20.3.4 Smart pointer adaptors
- https://wg21.link/LWG3734 - Inconsistency in `inout_ptr` and `out_ptr`
for empty case
- https://wg21.link/LWG3897- `inout_ptr` will not update raw pointer to
0

---------

Co-authored-by: Hristo Hristov <zingam@outlook.com>
2024-07-19 06:38:02 +03:00
Louis Dionne
50b5bb717c [libc++] Add comment about matching standard version in apple-install-libcxx
This was forgotten when I landed #99086
2024-07-18 16:49:53 -04:00
Louis Dionne
719b2ac42e
[libc++] Allow testing Apple's system library as it is installed (#99086)
In order to test libc++ under the "Apple System Library" configuration,
we need to run the tests using DYLD_LIBRARY_PATH. This is required
because libc++ gets an install_name of /usr/lib when built as a system
library, which means that we must override the copy of libc++ used by
the whole process. This effectively reverts 2cf2f1b, which was the wrong
solution for the problem I was having.

Of course, this assumes that the just-built libc++ is sufficient to
replace the system library, which is not actually the case
out-of-the-box. Indeed, the system library contains a few symbols that
are not provided by the upstream library, leading to undefined symbols
when replacing the system library by the just-built one.

To solve this problem, we separately build shims that provide those
missing symbols and we manually link against them when we build
executables in the tests. While this is somewhat brittle, it provides a
localized and unintrusive way to allow testing the Apple system
configuration in an upstream environment, which has been a frequent
request.
2024-07-18 16:49:07 -04:00
Iuri Chaer
a0662176a9
[libc++] Speed up set_intersection() by fast-forwarding over ranges of non-matching elements with one-sided binary search. (#75230)
One-sided binary search, aka meta binary search, has been in the public
domain for decades, and has the general advantage of being constant time
in the best case, with the downside of executing at most 2*log(N)
comparisons vs classic binary search's exact log(N). There are two
scenarios in which it really shines: the first one is when operating
over non-random-access iterators, because the classic algorithm requires
knowing the container's size upfront, which adds N iterator increments
to the complexity. The second one is when traversing the container in
order, trying to fast-forward to the next value: in that case the
classic algorithm requires at least O(N*log(N)) comparisons and, for
non-random-access iterators, O(N^2) iterator increments, whereas the
one-sided version will yield O(N) operations on both counts, with a
best-case of O(log(N)) comparisons which is very common in practice.
2024-07-18 16:11:24 -04:00