Commit Graph

191 Commits

Author SHA1 Message Date
Hui Xie 042dc3c46d [libc++] add zip_view and views::zip for C++23
- add zip_view and views::zip for C++23
- added unit tests
- implemented section 5.6 (zip) in P2321R2

I used clang-format to format the files but they look nothing like the rest of the code base. Manually indenting each line to match the styles sounds like an impossible task. Is there any clang-format file which can format it reasonable similar to the rest of the code base so that I can manually format the rest lines that look weird?

Reviewed By: ldionne, #libc, philnik, var-const

Spies: Mordante, philnik, libcxx-commits, mgorny

Differential Revision: https://reviews.llvm.org/D122806
2022-04-25 12:22:22 +02:00
Nikolas Klauser 1d83750f63 [libc++] Implement ranges::copy{, _n, _if, _backward}
Reviewed By: Mordante, var-const, #libc

Spies: sstefan1, libcxx-commits, mgorny

Differential Revision: https://reviews.llvm.org/D122982
2022-04-15 13:44:11 +02:00
Nikolas Klauser 58d9ab70ae [libc++][ranges] Implement ranges::minmax and ranges::minmax_element
Reviewed By: var-const, #libc, ldionne

Spies: sstefan1, ldionne, BRevzin, libcxx-commits, mgorny

Differential Revision: https://reviews.llvm.org/D120637
2022-04-14 15:37:22 +02:00
Arthur O'Dwyer 2fb026ee4d Implement move_sentinel and C++20 move_iterator.
Differential Revision: https://reviews.llvm.org/D117656
2022-04-13 09:51:43 -04:00
Louis Dionne 2b424f4ea8 [libc++] Implement ranges::filter_view
Differential Revision: https://reviews.llvm.org/D109086
2022-04-13 09:03:46 -04:00
Konstantin Varlamov e53c461bf3 [libc++][ranges] Implement `lazy_split_view`.
Note that this class was called just `split_view` in the original One
Ranges Proposal and was renamed to `lazy_split_view` by
[P2210](https://wg21.link/p2210).

Co-authored-by: zoecarver <z.zoelec2@gmail.com>

Differential Revision: https://reviews.llvm.org/D107500
2022-04-12 22:28:38 -07:00
Louis Dionne c292b6066c [libc++] Implement P1007R3: std::assume_aligned
This supersedes and incoroporates content from both D108906 and D54966,
and also some original content.

Co-Authored-by: Marshall Clow <mclow.lists@gmail.com>
Co-Authored-by: Gonzalo Brito Gadeschi

Differential Revision: https://reviews.llvm.org/D118938
2022-04-11 10:46:52 -04:00
Nikolas Klauser a96443edde [libc++] Implement P0401R6 (allocate_at_least)
Reviewed By: ldionne, var-const, #libc

Spies: mgorny, libcxx-commits, arichardson

Differential Revision: https://reviews.llvm.org/D122877
2022-04-09 16:03:45 +02:00
Mark de Wever 889302292b [libc++][format][3/6] Adds a __container_buffer.
Instead of writing every character directly into the container by using
a `back_insert_iterator` the data is buffered in an `array`. This buffer
is then inserted to the container by calling its `insert` member function.

Since there's no guarantee every container's `insert` behaves properly
containers need to opt-in to this behaviour. The appropriate standard
containers opt-in to this behaviour.

This change improves the performance of the format functions that use a
`back_insert_iterator`.

Depends on D110495

Reviewed By: ldionne, vitaut, #libc

Differential Revision: https://reviews.llvm.org/D110497
2022-04-09 09:35:48 +02:00
Nikolas Klauser 08920cc043 [libc++] Add __is_callable type trait and begin granularizing type_traits
`__is_callable` is required to ensure that the classic algorithms are only called with functions or functors. I also begin to granularize `<type_traits>`.

Reviewed By: ldionne, #libc

Spies: libcxx-commits, mgorny

Differential Revision: https://reviews.llvm.org/D123114
2022-04-08 12:23:52 +02:00
Nikolas Klauser 1306b1025c [libc++][ranges] Implement ranges::count{, _if}
Reviewed By: var-const, Mordante, ldionne, #libc

Spies: tcanens, libcxx-commits, mgorny

Differential Revision: https://reviews.llvm.org/D121523
2022-04-07 15:18:14 +02:00
Mark de Wever d78624975b [NFC][libc++] Modularize chrono's calendar.
The is a followup of D116965 to split the calendar header. This is a
preparation to add the formatters for the chrono header.

The code is only moved no other changes have been made.

Reviewed By: ldionne, #libc, philnik

Differential Revision: https://reviews.llvm.org/D122995
2022-04-06 17:47:53 +02:00
Nikolas Klauser 3ba8548c8e [libc++][ranges] Implement ranges::transform
Reviewed By: ldionne, var-const, #libc

Spies: libcxx-commits, mgorny

Differential Revision: https://reviews.llvm.org/D122173
2022-04-05 11:06:28 +02:00
Louis Dionne e70533ae6c [libc++] Remove unused <iosfwd> include from <__debug>
Differential Revision: https://reviews.llvm.org/D122999
2022-04-03 16:15:48 -04:00
Nikolas Klauser e476df5629 [libc++][ranges] Implement ranges::max
Reviewed By: Mordante, var-const, #libc

Spies: sstefan1, libcxx-commits, mgorny

Differential Revision: https://reviews.llvm.org/D122002
2022-04-03 17:04:56 +02:00
Mark de Wever 555214cbcc [libc++][format][2/6] Adds a __output_iterator.
Instead of using a temporary `string` in `__vformat_to_wrapped` use a new
generic iterator. This aids to reduce the number of template instantions
and avoids using a `string` to buffer the entire formatted output.

This changes the type of `format_context` and `wformat_context`, this can
still be done since the code isn't ABI stable yet.

Several approaches have been evaluated:
- Using a __output_buffer base class with:
  - a put function to store the buffer in its internal buffer
  - a virtual flush function to copy the internal buffer to the output
- Using a `function` to forward the output operation to the output buffer,
  much like the next method.
- Using a type erased function point to store the data in the buffer.
The last version resulted in the best performance. For some cases there's
still a loss of speed over the original method. This loss many becomes
apparent when large strings are copied to a pointer like iterator, before
the compiler optimized this using `memcpy`.

Reviewed By: ldionne, vitaut, #libc

Differential Revision: https://reviews.llvm.org/D110495
2022-03-26 16:48:01 +01:00
Nikolas Klauser f83d833e41 [libc++][ranges] Implement ranges::min
Reviewed By: var-const, Mordante, #libc

Spies: jwakely, ldionne, libcxx-commits, mgorny

Differential Revision: https://reviews.llvm.org/D119589
2022-03-18 12:52:21 +01:00
Nikolas Klauser ee0f8c4010 [libc++][ranges] Implement ranges::find{, _if, _if_not}
Reviewed By: var-const, #libc, ldionne

Spies: ldionne, tcanens, libcxx-commits, mgorny

Differential Revision: https://reviews.llvm.org/D121248
2022-03-12 01:46:02 +01:00
Nikolas Klauser c2cd15a665 [libc++][ranges] Implement ranges::mismatch
Implement `ranges::mismatch`

Reviewed By: Quuxplusone, ldionne, #libc

Spies: libcxx-commits, mgorny

Differential Revision: https://reviews.llvm.org/D117817
2022-03-08 23:20:40 +01:00
Nikolas Klauser 205557c908 [libc++][ranges] Implement ranges::max_element
Implement ranges::max_element

Reviewed By: Quuxplusone, #libc

Spies: libcxx-commits, mgorny

Differential Revision: https://reviews.llvm.org/D117523
2022-03-07 17:11:23 +01:00
Louis Dionne 311ff39178 [libc++] Add missing header <cuchar>
Fixes llvm-project#44216

Differential Revision: https://reviews.llvm.org/D97870
2022-03-07 08:48:50 -05:00
Arthur O'Dwyer 0444a0e8a9 [libc++] Remove extraneous space in module.modulemap. NFC. 2022-03-01 14:25:09 -05:00
Arthur O'Dwyer a3255f219a [libc++] Explicitly reject `uniform_int_distribution<bool>` and `<char>`.
`uniform_int_distribution<T>` is UB unless `T` is one of the non-character,
non-boolean integer types (`short` or larger). However, libc++ has never
enforced this. D114129 accidentally made `uniform_int_distribution<bool>`
into an error. Make it now *intentionally* an error; and likewise for the
character types and all user-defined class and enum types; but permit
`__[u]int128_t` to continue working.

Apply the same static_assert to all the integer distributions.

Differential Revision: https://reviews.llvm.org/D114920
2022-02-28 14:57:53 -05:00
Nikolas Klauser 68f4131c94 [libc++][ranges] Add ranges::in_found_result
Reviewed By: Quuxplusone, #libc

Spies: libcxx-commits, mgorny

Differential Revision: https://reviews.llvm.org/D119763
2022-02-21 23:08:14 +01:00
Nikolas Klauser 807766be3a [libc++][ranges] Add ranges::min_max_result
Reviewed By: Quuxplusone, #libc

Spies: libcxx-commits, mgorny

Differential Revision: https://reviews.llvm.org/D119751
2022-02-21 22:52:01 +01:00
Konstantin Varlamov 8e979460bb [libc++][ranges] Implement `std::sortable`.
Differential Revision: https://reviews.llvm.org/D119619
2022-02-17 20:17:42 -08:00
Konstantin Varlamov eea3d90af1 [libc++][ranges] Implement `std::mergeable`.
Differential Revision: https://reviews.llvm.org/D119489
2022-02-17 20:12:04 -08:00
Louis Dionne f87aa19be6 [libc++] Move everything related solely to _LIBCPP_ASSERT to its own file
This is the first step towards disentangling the debug mode and assertions
in libc++. This patch doesn't make any functional change: it simply moves
_LIBCPP_ASSERT-related stuff to its own file so as to make it clear that
libc++ assertions and the debug mode are different things. Future patches
will make it possible to enable assertions without enabling the debug
mode.

Differential Revision: https://reviews.llvm.org/D119769
2022-02-16 12:49:50 -05:00
Louis Dionne 987c7f407d [libc++] Revert <stdatomic.h> changes
This reverts commits a30a7948d and 5d1c1a243, which broke the LLDB
data formatters tests because they build with modules in C++11 mode.

Differential Revision: https://reviews.llvm.org/D97044
2022-02-15 12:59:14 -05:00
Marek Kurdej 5d1c1a243c [libc++] [C++2b] [P0943] Add stdatomic.h header.
* https://wg21.link/P0943
* https://eel.is/c++draft/stdatomic.h.syn

Differential Revision: https://reviews.llvm.org/D97044
2022-02-14 16:39:22 -05:00
Nikolas Klauser 2a8f9a5e95 [libc++] Implement P0627R6 (Function to mark unreachable code)
Reviewed By: ldionne, Quuxplusone, #libc

Spies: arichardson, mstorsjo, libcxx-commits, mgorny

Differential Revision: https://reviews.llvm.org/D119152
2022-02-14 20:52:51 +01:00
Konstantin Varlamov 55bd22f853 [libc++][ranges] Implement rbegin, rend, crbegin and crend.
Differential Revision: https://reviews.llvm.org/D119057
2022-02-14 03:29:59 -08:00
Joe Loser 861386dbd6
[libc++] Remove <experimental/filesystem> header
`<filesystem>` header has been around for a while now, so we can safely remove
`<experimental/filesystem>` header. `_LIBCPP_DEPRECATED_EXPERIMENTAL_FILESYSTEM`
suggests we were going to remove `<experimental/filesystem>` in llvm 11 release,
but we never did. So, remove the experimental header now, its associated tests,
and the `_LIBCPP_DEPRECATED_EXPERIMENTAL_FILESYSTEM` macro.

Differential Revision: https://reviews.llvm.org/D119603
2022-02-12 19:43:57 -05:00
Louis Dionne 7338227882 [libc++] Disable local submodule visibility in the modules build
Differential Revision: https://reviews.llvm.org/D119468
2022-02-11 15:52:55 -05:00
Nikolas Klauser 3b470d1ce9 [libc++][ranges] Implement ranges::min_element
Implement ranges::min_element

Reviewed By: Quuxplusone, Mordante, #libc

Spies: miscco, libcxx-commits, mgorny

Differential Revision: https://reviews.llvm.org/D117025
2022-02-11 17:20:27 +01:00
Nikolas Klauser 1e77b396ff [libc++] Add ranges::in_fun_result
Add `ranges::in_fun_result`

Reviewed By: Quuxplusone, #libc, var-const

Spies: CaseyCarter, var-const, libcxx-commits, mgorny

Differential Revision: https://reviews.llvm.org/D116974
2022-02-11 17:10:29 +01:00
Nikolas Klauser 9d90531904 [libc++][ranges] Implement std::ranges::swap_ranges()
Implement `std::ranges::swap_ranges()`

Reviewed By: Quuxplusone, #libc, ldionne

Spies: ldionne, mgorny, jloser, libcxx-commits

Differential Revision: https://reviews.llvm.org/D116303
2022-02-10 16:01:45 +01:00
Konstantin Varlamov 8f1d8785df [libc++][ranges] Implement `permutable`.
Differential Revision: https://reviews.llvm.org/D119222
2022-02-09 20:34:20 -08:00
Louis Dionne 506cf6dc04 [libc++] Fix modules and benchmarks CI builds when incomplete features are disabled
Differential Revision: https://reviews.llvm.org/D119036
2022-02-08 15:15:07 -05:00
Louis Dionne 157bbe6aea [libc++] Remove the ability to use the std::nullptr_t emulation in C++03 mode
Back in https://reviews.llvm.org/D109459, we stopped using the C++03
emulation for std::nullptr_t by default, which was an ABI break. We
still left a knob for users to turn it back on if they were broken by
the change, with a note that we would remove that knob after one release.

The time has now come to remove the knob and clean up the std::nullptr_t
emulation.

Differential Revision: https://reviews.llvm.org/D114786
2022-02-07 17:51:05 -05:00
Nikolas Klauser 679f8a885b [libc++] Move fpos into its own header
For some reason `<string>` defines `std::fpos`, which should be defined in `<ios>`.

Reviewed By: Quuxplusone, Mordante, #libc

Spies: libcxx-commits, mgorny

Differential Revision: https://reviews.llvm.org/D118914
2022-02-04 21:53:43 +01:00
Arthur O'Dwyer 44cdca37c0 [libc++] Define `namespace views` in its own detail header.
Discovered in the comments on D118748: we would like this namespace
to exist anytime Ranges exists, regardless of whether concepts syntax
is supported. Also, we'd like to fully granularize the <ranges> header,
which means not putting any loose declarations at the top level.

Differential Revision: https://reviews.llvm.org/D118809
2022-02-04 12:37:47 -05:00
Nikolas Klauser 610979b301 [libc++][ranges] Add ranges::in_out_out_result
Add `ranges::in_out_out_result`

Reviewed By: Quuxplusone, Mordante, #libc

Spies: libcxx-commits, mgorny

Differential Revision: https://reviews.llvm.org/D118634
2022-02-03 02:17:48 +01:00
Nikolas Klauser f3514af492 [libc++][ranges] Add ranges::in_in_out_result
Add `ranges::in_in_out_result`

Reviewed By: Quuxplusone, Mordante, #libc

Spies: CaseyCarter, libcxx-commits, mgorny

Differential Revision: https://reviews.llvm.org/D117512
2022-01-31 16:33:45 +01:00
Arthur O'Dwyer bf20a09790 [libc++] [P1614] Implement the second half of [cmp.alg]: compare_{strong,weak,partial}_fallback.
The tests for these are just copy-pasted from the tests for std::{strong,weak,partial}_order,
and then I added an extra clause in each (test_2()) to test the stuff that's not just the same
as std::*_order.

This also includes the fix for https://wg21.link/LWG3465 (which falls naturally out of the
"you must write it three times" style, but I've added test cases for it also).

There is an action item here to go back and give good diagnostics for SFINAE failures
in these CPOs. I've filed this as https://github.com/llvm/llvm-project/issues/53456 .

Differential Revision: https://reviews.llvm.org/D111514
2022-01-27 17:48:01 -05:00
Mark de Wever 787ccd345c [libc++][format] Adds formatter pointer.
This implements the last required formatter specialization.

Completes:
- LWG 3251 Are std::format alignment specifiers applied to string arguments?
- LWG 3340 Formatting functions should throw on argument/format string mismatch in §[format.functions]
- LWG 3540 §[format.arg] There should be no const in basic_format_arg(const T* p)

Implements parts of:
- P0645 Text Formatting

Depends on D114001

Reviewed By: ldionne, vitaut, #libc

Differential Revision: https://reviews.llvm.org/D115988
2022-01-24 18:13:02 +01:00
Mark de Wever db2944e34b [libc++][format] Adds formatter floating-point.
This properly implements the formatter for floating-point types.

Completes:
- P1652R1 Printf corner cases in std::format
- LWG 3250 std::format: # (alternate form) for NaN and inf
- LWG 3243 std::format and negative zeroes

Implements parts of:
- P0645 Text Formatting

Reviewed By: #libc, ldionne, vitaut

Differential Revision: https://reviews.llvm.org/D114001
2022-01-24 18:12:24 +01:00
Arthur O'Dwyer 63a991d035 [libc++] Eliminate the `__function_like` helper.
As prefigured in the comments on D115315.
This gives us one unified style for all niebloids,
and also simplifies the modulemap.

Differential Revision: https://reviews.llvm.org/D116570
2022-01-20 14:40:16 -05:00
Louis Dionne df51be85e4 [libc++] Split a few utilities out of __threading_support
This change is the basis for a further refactoring where I'm going to
split up the various implementations we have in __threading_support to
make that code easier to understand.

Note that I had to make __convert_to_timespec a template to break
circular dependencies. Concretely, we never seem to use it with anything
other than ::timespec, but I am wary of hardcoding that assumption as
part of this change, since I suspect there's a reason for going through
these hoops in the first place.

Differential Revision: https://reviews.llvm.org/D116944
2022-01-18 12:23:44 -05:00
Arthur O'Dwyer e93f98f09c [libc++] [test] Check for another kind of modulemap typo in lint_modulemap.sh.py.
Verify that the name of the private submodule matches the name of the detail header.

Differential Revision: https://reviews.llvm.org/D117438
2022-01-17 10:20:34 -05:00