From 619fd6c518c3d5a9f7189de479532526f253c805 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Mon, 3 Aug 2026 12:35:12 +0200 Subject: [PATCH] libcxx: update to LLVM 23 --- lib/libcxx/include/__algorithm/clamp.h | 8 +- lib/libcxx/include/__algorithm/copy.h | 31 +- .../include/__algorithm/copy_backward.h | 35 +- lib/libcxx/include/__algorithm/copy_if.h | 7 +- .../include/__algorithm/copy_move_common.h | 21 +- lib/libcxx/include/__algorithm/copy_n.h | 10 +- lib/libcxx/include/__algorithm/equal.h | 71 +- lib/libcxx/include/__algorithm/find.h | 27 +- lib/libcxx/include/__algorithm/find_if.h | 19 +- lib/libcxx/include/__algorithm/find_if_not.h | 24 +- .../include/__algorithm/find_segment_if.h | 17 +- lib/libcxx/include/__algorithm/for_each.h | 2 +- lib/libcxx/include/__algorithm/for_each_n.h | 5 +- lib/libcxx/include/__algorithm/generate_n.h | 7 +- .../include/__algorithm/in_out_result.h | 14 + .../lexicographical_compare_three_way.h | 8 +- lib/libcxx/include/__algorithm/lower_bound.h | 9 +- lib/libcxx/include/__algorithm/move.h | 31 +- .../include/__algorithm/move_backward.h | 30 +- .../include/__algorithm/out_value_result.h | 8 +- .../include/__algorithm/partial_sort_copy.h | 9 +- lib/libcxx/include/__algorithm/pstl.h | 90 ++ lib/libcxx/include/__algorithm/radix_sort.h | 8 +- lib/libcxx/include/__algorithm/ranges_copy.h | 6 +- .../__algorithm/ranges_copy_backward.h | 6 +- .../include/__algorithm/ranges_copy_if.h | 6 +- .../include/__algorithm/ranges_copy_n.h | 11 +- lib/libcxx/include/__algorithm/ranges_equal.h | 4 +- .../include/__algorithm/ranges_find_if.h | 15 +- .../include/__algorithm/ranges_find_if_not.h | 11 +- lib/libcxx/include/__algorithm/ranges_fold.h | 149 ++- lib/libcxx/include/__algorithm/ranges_move.h | 11 +- .../__algorithm/ranges_move_backward.h | 11 +- .../__algorithm/ranges_partial_sort_copy.h | 6 +- .../include/__algorithm/ranges_remove_if.h | 5 +- .../include/__algorithm/ranges_reverse_copy.h | 3 +- .../__algorithm/ranges_set_difference.h | 9 +- .../include/__algorithm/ranges_shift_left.h | 73 ++ .../include/__algorithm/ranges_shift_right.h | 76 ++ .../include/__algorithm/ranges_swap_ranges.h | 33 +- .../include/__algorithm/ranges_unique_copy.h | 7 +- lib/libcxx/include/__algorithm/rotate.h | 4 +- .../include/__algorithm/set_difference.h | 11 +- .../include/__algorithm/set_intersection.h | 7 +- .../__algorithm/set_symmetric_difference.h | 4 +- lib/libcxx/include/__algorithm/set_union.h | 4 +- lib/libcxx/include/__algorithm/shift_left.h | 43 +- lib/libcxx/include/__algorithm/shift_right.h | 80 +- lib/libcxx/include/__algorithm/shuffle.h | 2 + lib/libcxx/include/__algorithm/simd_utils.h | 16 +- lib/libcxx/include/__algorithm/sort.h | 2 + .../__algorithm/specialized_algorithms.h | 1 + lib/libcxx/include/__algorithm/swap_ranges.h | 202 +--- .../__algorithm/three_way_comp_ref_type.h | 8 +- lib/libcxx/include/__algorithm/unique_copy.h | 16 +- lib/libcxx/include/__algorithm/unwrap_iter.h | 18 +- lib/libcxx/include/__algorithm/unwrap_range.h | 57 +- lib/libcxx/include/__assert | 2 +- lib/libcxx/include/__atomic/atomic.h | 6 +- lib/libcxx/include/__atomic/atomic_flag.h | 34 +- lib/libcxx/include/__atomic/atomic_ref.h | 19 +- lib/libcxx/include/__atomic/atomic_sync.h | 19 +- .../include/__atomic/atomic_sync_timed.h | 23 +- .../include/__atomic/atomic_waitable_traits.h | 10 +- lib/libcxx/include/__atomic/contention_t.h | 8 +- .../include/__atomic/floating_point_helper.h | 8 +- lib/libcxx/include/__atomic/support.h | 4 +- lib/libcxx/include/__bit/bit_cast.h | 12 +- lib/libcxx/include/__bit/bit_ceil.h | 7 +- lib/libcxx/include/__bit/byteswap.h | 31 +- lib/libcxx/include/__bit_reference | 187 +++- .../__charconv/from_chars_floating_point.h | 2 + .../include/__charconv/from_chars_integral.h | 5 +- lib/libcxx/include/__charconv/to_chars.h | 4 - .../__charconv/to_chars_floating_point.h | 2 + lib/libcxx/include/__chrono/convert_to_tm.h | 5 +- lib/libcxx/include/__chrono/day.h | 14 +- lib/libcxx/include/__chrono/duration.h | 50 +- lib/libcxx/include/__chrono/exception.h | 2 + lib/libcxx/include/__chrono/file_clock.h | 4 + lib/libcxx/include/__chrono/gps_clock.h | 8 +- lib/libcxx/include/__chrono/hh_mm_ss.h | 20 +- lib/libcxx/include/__chrono/literals.h | 4 +- lib/libcxx/include/__chrono/month.h | 12 +- lib/libcxx/include/__chrono/month_weekday.h | 40 +- lib/libcxx/include/__chrono/monthday.h | 34 +- lib/libcxx/include/__chrono/steady_clock.h | 8 +- lib/libcxx/include/__chrono/system_clock.h | 2 + lib/libcxx/include/__chrono/tai_clock.h | 8 +- lib/libcxx/include/__chrono/time_zone.h | 10 +- lib/libcxx/include/__chrono/time_zone_link.h | 8 +- lib/libcxx/include/__chrono/tzdb.h | 10 +- lib/libcxx/include/__chrono/tzdb_list.h | 10 +- lib/libcxx/include/__chrono/utc_clock.h | 8 +- lib/libcxx/include/__chrono/weekday.h | 44 +- lib/libcxx/include/__chrono/year.h | 24 +- lib/libcxx/include/__chrono/year_month.h | 33 +- lib/libcxx/include/__chrono/year_month_day.h | 79 +- .../include/__chrono/year_month_weekday.h | 82 +- lib/libcxx/include/__chrono/zoned_time.h | 8 +- .../__compare/common_comparison_category.h | 8 +- .../include/__compare/compare_three_way.h | 8 +- .../__compare/compare_three_way_result.h | 8 +- lib/libcxx/include/__compare/ordering.h | 8 +- .../include/__compare/synth_three_way.h | 8 +- .../include/__compare/three_way_comparable.h | 8 +- lib/libcxx/include/__concepts/arithmetic.h | 8 +- lib/libcxx/include/__concepts/assignable.h | 8 +- .../include/__concepts/boolean_testable.h | 8 +- lib/libcxx/include/__concepts/class_or_enum.h | 8 +- .../__concepts/common_reference_with.h | 8 +- .../__concepts/comparison_common_type.h | 8 +- lib/libcxx/include/__concepts/constructible.h | 8 +- .../include/__concepts/convertible_to.h | 8 +- lib/libcxx/include/__concepts/copyable.h | 8 +- lib/libcxx/include/__concepts/derived_from.h | 8 +- lib/libcxx/include/__concepts/destructible.h | 8 +- .../include/__concepts/different_from.h | 8 +- .../include/__concepts/equality_comparable.h | 8 +- lib/libcxx/include/__concepts/invocable.h | 8 +- lib/libcxx/include/__concepts/movable.h | 8 +- lib/libcxx/include/__concepts/predicate.h | 8 +- .../primary_template.h} | 15 +- .../referenceable.h} | 16 +- lib/libcxx/include/__concepts/regular.h | 8 +- lib/libcxx/include/__concepts/relation.h | 8 +- lib/libcxx/include/__concepts/same_as.h | 8 +- lib/libcxx/include/__concepts/semiregular.h | 8 +- lib/libcxx/include/__concepts/swappable.h | 8 +- .../include/__concepts/totally_ordered.h | 8 +- .../__condition_variable/condition_variable.h | 10 +- lib/libcxx/include/__config | 724 +------------ lib/libcxx/include/__configuration/abi.h | 20 +- .../include/__configuration/attributes.h | 476 +++++++++ .../include/__configuration/availability.h | 165 +-- lib/libcxx/include/__configuration/compiler.h | 33 +- .../__configuration/diagnostic_suppression.h | 44 + .../include/__configuration/hardening.h | 17 - lib/libcxx/include/__configuration/language.h | 42 + .../include/__configuration/namespace.h | 99 ++ lib/libcxx/include/__configuration/platform.h | 4 + lib/libcxx/include/__configuration/pstl.h | 66 ++ lib/libcxx/include/__configuration/utility.h | 26 + lib/libcxx/include/__cstddef/byte.h | 12 +- lib/libcxx/include/__cstddef/max_align_t.h | 8 +- lib/libcxx/include/__debug_utils/sanitizers.h | 35 +- lib/libcxx/include/__exception/exception.h | 2 + .../include/__exception/exception_ptr.h | 52 +- .../include/__exception/nested_exception.h | 12 +- lib/libcxx/include/__exception/operations.h | 4 + lib/libcxx/include/__exception/terminate.h | 4 + .../include/__expected/bad_expected_access.h | 2 + lib/libcxx/include/__expected/expected.h | 32 +- .../include/__filesystem/directory_entry.h | 2 + .../include/__filesystem/directory_iterator.h | 2 + .../include/__filesystem/filesystem_error.h | 2 + lib/libcxx/include/__filesystem/operations.h | 2 + lib/libcxx/include/__filesystem/path.h | 89 +- .../include/__filesystem/path_iterator.h | 2 + .../recursive_directory_iterator.h | 2 + lib/libcxx/include/__flat_map/flat_multimap.h | 9 - lib/libcxx/include/__flat_set/flat_multiset.h | 9 - .../include/__format/container_adaptor.h | 8 +- .../include/__format/enable_insertable.h | 8 +- .../include/__format/escaped_output_table.h | 13 +- lib/libcxx/include/__format/fmt_pair_like.h | 8 +- lib/libcxx/include/__format/format_context.h | 11 +- lib/libcxx/include/__format/format_error.h | 2 + .../include/__format/format_functions.h | 26 +- lib/libcxx/include/__format/formatter_bool.h | 35 +- .../include/__format/formatter_bool_impl.h | 60 ++ .../__format/formatter_floating_point.h | 8 +- lib/libcxx/include/__format/formatter_tuple.h | 8 +- .../__format/range_default_formatter.h | 9 +- lib/libcxx/include/__format/range_format.h | 22 +- lib/libcxx/include/__format/range_formatter.h | 10 +- lib/libcxx/include/__format/unicode.h | 2 +- .../include/__functional/binary_negate.h | 8 +- lib/libcxx/include/__functional/bind_front.h | 49 + lib/libcxx/include/__functional/binder1st.h | 8 +- lib/libcxx/include/__functional/binder2nd.h | 8 +- lib/libcxx/include/__functional/compose.h | 8 +- lib/libcxx/include/__functional/function.h | 15 +- lib/libcxx/include/__functional/hash.h | 28 +- lib/libcxx/include/__functional/invoke.h | 12 +- .../include/__functional/is_transparent.h | 6 +- lib/libcxx/include/__functional/mem_fun_ref.h | 8 +- lib/libcxx/include/__functional/operations.h | 8 +- .../include/__functional/perfect_forward.h | 8 +- .../__functional/pointer_to_binary_function.h | 8 +- .../__functional/pointer_to_unary_function.h | 8 +- .../include/__functional/ranges_operations.h | 8 +- .../include/__functional/unary_negate.h | 8 +- lib/libcxx/include/__fwd/format.h | 27 +- lib/libcxx/include/__fwd/map.h | 31 - lib/libcxx/include/__fwd/set.h | 30 - lib/libcxx/include/__fwd/span.h | 8 +- lib/libcxx/include/__fwd/variant.h | 8 +- lib/libcxx/include/__hash_table | 20 +- lib/libcxx/include/__iterator/access.h | 28 +- .../include/__iterator/back_insert_iterator.h | 4 +- lib/libcxx/include/__iterator/bounded_iter.h | 16 +- .../__iterator/capacity_aware_iterator.h | 186 ++++ .../include/__iterator/common_iterator.h | 6 +- lib/libcxx/include/__iterator/concepts.h | 17 +- .../include/__iterator/counted_iterator.h | 26 +- lib/libcxx/include/__iterator/data.h | 18 +- .../include/__iterator/default_sentinel.h | 8 +- lib/libcxx/include/__iterator/distance.h | 9 +- lib/libcxx/include/__iterator/empty.h | 8 +- .../include/__iterator/erase_if_container.h | 3 +- .../__iterator/front_insert_iterator.h | 6 +- .../include/__iterator/incrementable_traits.h | 12 +- .../include/__iterator/insert_iterator.h | 4 +- .../include/__iterator/istream_iterator.h | 2 +- .../include/__iterator/istreambuf_iterator.h | 6 +- lib/libcxx/include/__iterator/iter_move.h | 10 +- lib/libcxx/include/__iterator/iter_swap.h | 8 +- .../include/__iterator/iterator_traits.h | 6 +- lib/libcxx/include/__iterator/move_iterator.h | 45 +- lib/libcxx/include/__iterator/move_sentinel.h | 10 +- .../include/__iterator/ostream_iterator.h | 2 +- .../include/__iterator/ostreambuf_iterator.h | 27 +- .../__iterator/ranges_iterator_traits.h | 8 +- .../include/__iterator/readable_traits.h | 10 +- .../include/__iterator/reverse_access.h | 35 +- .../include/__iterator/reverse_iterator.h | 46 +- .../include/__iterator/segmented_iterator.h | 2 - lib/libcxx/include/__iterator/size.h | 19 +- .../include/__iterator/static_bounded_iter.h | 13 +- lib/libcxx/include/__iterator/wrap_iter.h | 247 +++-- lib/libcxx/include/__locale | 176 ++-- .../include/__locale_dir/check_grouping.h | 2 + .../include/__locale_dir/get_c_locale.h | 2 + .../include/__locale_dir/locale_base_api.h | 24 +- .../__locale_dir/locale_base_api/android.h | 45 - .../__locale_dir/locale_base_api/ibm.h | 97 ++ .../__locale_dir/locale_base_api/musl.h | 31 - .../__locale_dir/locale_base_api/openbsd.h | 19 - lib/libcxx/include/__locale_dir/messages.h | 7 +- lib/libcxx/include/__locale_dir/money.h | 20 +- lib/libcxx/include/__locale_dir/num.h | 5 +- .../include/__locale_dir/pad_and_output.h | 16 +- .../include/__locale_dir/support/bsd_like.h | 11 +- .../include/__locale_dir/support/fuchsia.h | 5 + .../include/__locale_dir/support/linux.h | 15 +- .../include/__locale_dir/support/newlib.h | 9 +- .../support/no_locale/characters.h | 10 +- .../support/no_locale/conversions.h | 73 ++ .../support/no_locale/formatting.h | 50 + .../include/__locale_dir/support/openbsd.h | 229 +++++ .../include/__locale_dir/support/windows.h | 10 +- lib/libcxx/include/__locale_dir/time.h | 2 + .../include/__locale_dir/wbuffer_convert.h | 6 +- .../include/__locale_dir/wstring_convert.h | 24 +- lib/libcxx/include/__log_hardening_failure | 2 + lib/libcxx/include/__math/abs.h | 13 + lib/libcxx/include/__math/gamma.h | 28 + lib/libcxx/include/__math/special_functions.h | 10 +- lib/libcxx/include/__mbstate_t.h | 4 + .../include/__mdspan/aligned_accessor.h | 8 +- lib/libcxx/include/__mdspan/extents.h | 157 ++- lib/libcxx/include/__mdspan/layout_left.h | 6 +- lib/libcxx/include/__mdspan/layout_right.h | 6 +- lib/libcxx/include/__mdspan/layout_stride.h | 48 +- lib/libcxx/include/__mdspan/mdspan.h | 76 +- lib/libcxx/include/__memory/aligned_alloc.h | 63 -- .../include/__memory/allocator_traits.h | 62 +- lib/libcxx/include/__memory/compressed_pair.h | 33 +- lib/libcxx/include/__memory/inout_ptr.h | 11 +- .../__memory/is_sufficiently_aligned.h | 7 +- lib/libcxx/include/__memory/out_ptr.h | 11 +- lib/libcxx/include/__memory/pointer_traits.h | 55 +- .../ranges_uninitialized_algorithms.h | 55 +- .../include/__memory/raw_storage_iterator.h | 8 +- lib/libcxx/include/__memory/shared_count.h | 2 + lib/libcxx/include/__memory/shared_ptr.h | 504 ++++----- .../include/__memory/temporary_buffer.h | 3 + .../__memory/uninitialized_algorithms.h | 245 +---- ...ninitialized_multidimensional_algorithms.h | 194 ++++ lib/libcxx/include/__memory/unique_ptr.h | 172 ++-- .../__memory/uses_allocator_construction.h | 12 +- lib/libcxx/include/__memory/valid_range.h | 74 ++ .../__memory_resource/memory_resource.h | 2 + .../monotonic_buffer_resource.h | 2 + .../synchronized_pool_resource.h | 2 + .../unsynchronized_pool_resource.h | 2 + lib/libcxx/include/__mutex/lock_guard.h | 2 +- lib/libcxx/include/__mutex/mutex.h | 4 +- lib/libcxx/include/__mutex/once_flag.h | 2 + lib/libcxx/include/__mutex/unique_lock.h | 10 +- lib/libcxx/include/__new/exceptions.h | 3 + lib/libcxx/include/__new/new_handler.h | 4 + .../include/__new/placement_new_delete.h | 4 +- lib/libcxx/include/__node_handle | 73 +- lib/libcxx/include/__numeric/accumulate.h | 4 +- lib/libcxx/include/__numeric/gcd_lcm.h | 4 +- lib/libcxx/include/__numeric/inner_product.h | 4 +- lib/libcxx/include/__numeric/pstl.h | 12 +- lib/libcxx/include/__numeric/ranges_iota.h | 9 +- lib/libcxx/include/__numeric/reduce.h | 16 +- .../include/__numeric/saturation_arithmetic.h | 30 +- .../include/__numeric/transform_reduce.h | 16 +- lib/libcxx/include/__ostream/basic_ostream.h | 2 + lib/libcxx/include/__ostream/print.h | 17 +- lib/libcxx/include/__pstl/backend_fwd.h | 20 + lib/libcxx/include/__pstl/backends/default.h | 78 ++ .../include/__pstl/backends/libdispatch.h | 2 + .../include/__random/bernoulli_distribution.h | 14 +- .../include/__random/binomial_distribution.h | 45 +- .../include/__random/cauchy_distribution.h | 18 +- .../__random/chi_squared_distribution.h | 14 +- .../include/__random/discard_block_engine.h | 19 +- .../include/__random/discrete_distribution.h | 14 +- .../__random/exponential_distribution.h | 14 +- .../__random/extreme_value_distribution.h | 18 +- .../include/__random/fisher_f_distribution.h | 18 +- .../include/__random/gamma_distribution.h | 18 +- .../include/__random/generate_canonical.h | 2 +- .../include/__random/geometric_distribution.h | 14 +- .../__random/independent_bits_engine.h | 64 +- .../include/__random/is_seed_sequence.h | 6 +- .../__random/linear_congruential_engine.h | 67 +- .../include/__random/lognormal_distribution.h | 18 +- .../__random/mersenne_twister_engine.h | 135 +-- .../__random/negative_binomial_distribution.h | 18 +- .../include/__random/normal_distribution.h | 18 +- .../piecewise_constant_distribution.h | 18 +- .../__random/piecewise_linear_distribution.h | 18 +- .../include/__random/poisson_distribution.h | 14 +- lib/libcxx/include/__random/random_device.h | 24 +- lib/libcxx/include/__random/seed_seq.h | 4 +- .../include/__random/shuffle_order_engine.h | 56 +- .../include/__random/student_t_distribution.h | 14 +- .../__random/subtract_with_carry_engine.h | 91 +- .../__random/uniform_int_distribution.h | 18 +- .../__random/uniform_random_bit_generator.h | 8 +- .../__random/uniform_real_distribution.h | 18 +- .../include/__random/weibull_distribution.h | 18 +- lib/libcxx/include/__ranges/access.h | 8 +- .../__ranges/adjacent_transform_view.h | 39 +- lib/libcxx/include/__ranges/adjacent_view.h | 37 +- lib/libcxx/include/__ranges/all.h | 8 +- lib/libcxx/include/__ranges/chunk_by_view.h | 2 +- lib/libcxx/include/__ranges/concat_view.h | 651 ++++++++++++ lib/libcxx/include/__ranges/concepts.h | 8 +- .../__ranges/container_compatible_range.h | 8 +- lib/libcxx/include/__ranges/dangling.h | 8 +- lib/libcxx/include/__ranges/data.h | 12 +- lib/libcxx/include/__ranges/drop_view.h | 3 +- lib/libcxx/include/__ranges/drop_while_view.h | 4 +- lib/libcxx/include/__ranges/elements_of.h | 8 +- lib/libcxx/include/__ranges/elements_view.h | 41 +- lib/libcxx/include/__ranges/empty.h | 8 +- .../include/__ranges/enable_borrowed_range.h | 8 +- lib/libcxx/include/__ranges/enable_view.h | 8 +- lib/libcxx/include/__ranges/enumerate_view.h | 350 +++++++ lib/libcxx/include/__ranges/filter_view.h | 4 +- lib/libcxx/include/__ranges/from_range.h | 8 +- lib/libcxx/include/__ranges/iota_view.h | 12 +- lib/libcxx/include/__ranges/istream_view.h | 8 +- lib/libcxx/include/__ranges/join_view.h | 16 +- lib/libcxx/include/__ranges/join_with_view.h | 5 +- lib/libcxx/include/__ranges/lazy_split_view.h | 34 +- lib/libcxx/include/__ranges/owning_view.h | 8 +- lib/libcxx/include/__ranges/range_adaptor.h | 8 +- lib/libcxx/include/__ranges/ref_view.h | 8 +- lib/libcxx/include/__ranges/repeat_view.h | 10 +- lib/libcxx/include/__ranges/reverse_view.h | 16 +- lib/libcxx/include/__ranges/single_view.h | 2 +- lib/libcxx/include/__ranges/size.h | 8 +- lib/libcxx/include/__ranges/split_view.h | 17 +- lib/libcxx/include/__ranges/stride_view.h | 410 ++++++++ lib/libcxx/include/__ranges/subrange.h | 29 +- lib/libcxx/include/__ranges/take_view.h | 3 +- lib/libcxx/include/__ranges/take_while_view.h | 20 +- lib/libcxx/include/__ranges/transform_view.h | 59 +- lib/libcxx/include/__ranges/view_interface.h | 8 +- lib/libcxx/include/__ranges/views.h | 3 +- .../include/__ranges/zip_transform_view.h | 35 +- lib/libcxx/include/__ranges/zip_view.h | 33 +- lib/libcxx/include/__split_buffer | 147 ++- .../include/__stop_token/atomic_unique_lock.h | 15 +- .../__stop_token/intrusive_list_view.h | 8 +- .../__stop_token/intrusive_shared_ptr.h | 9 +- .../include/__stop_token/stop_callback.h | 8 +- lib/libcxx/include/__stop_token/stop_state.h | 11 +- lib/libcxx/include/__stop_token/stop_token.h | 8 +- .../__support/xlocale/__nop_locale_mgmt.h | 33 - .../__support/xlocale/__strtonum_fallback.h | 37 - .../include/__system_error/error_category.h | 2 + .../include/__system_error/error_code.h | 2 + .../include/__system_error/error_condition.h | 2 + .../include/__system_error/system_error.h | 2 + .../__system_error/throw_system_error.h | 2 + lib/libcxx/include/__thread/formatter.h | 9 +- lib/libcxx/include/__thread/id.h | 9 +- lib/libcxx/include/__thread/support/pthread.h | 19 +- lib/libcxx/include/__thread/support/windows.h | 2 + lib/libcxx/include/__thread/this_thread.h | 2 + lib/libcxx/include/__thread/thread.h | 37 +- lib/libcxx/include/__tree | 827 ++++++++------- lib/libcxx/include/__tuple/make_tuple_types.h | 80 -- lib/libcxx/include/__tuple/sfinae_helpers.h | 11 +- lib/libcxx/include/__tuple/tuple_indices.h | 37 - lib/libcxx/include/__tuple/tuple_like.h | 8 +- lib/libcxx/include/__tuple/tuple_like_ext.h | 52 - .../include/__tuple/tuple_like_no_subrange.h | 8 +- lib/libcxx/include/__tuple/tuple_types.h | 25 - .../include/__type_traits/add_pointer.h | 31 +- .../include/__type_traits/aligned_union.h | 23 +- .../include/__type_traits/can_extract_key.h | 53 - .../include/__type_traits/common_reference.h | 8 +- .../include/__type_traits/conditional.h | 14 +- .../include/__type_traits/conjunction.h | 2 +- .../include/__type_traits/dependent_type.h | 25 - .../include/__type_traits/disjunction.h | 3 +- .../has_unique_object_representation.h | 8 +- .../include/__type_traits/integer_traits.h | 55 +- .../include/__type_traits/integral_constant.h | 2 +- .../include/__type_traits/is_bounded_array.h | 36 - .../__type_traits/is_constant_evaluated.h | 2 +- .../__type_traits/is_implicit_lifetime.h | 8 +- .../is_implicitly_default_constructible.h | 8 +- .../include/__type_traits/is_literal_type.h | 8 +- .../include/__type_traits/is_replaceable.h | 61 -- .../__type_traits/is_trivially_relocatable.h | 4 + .../__type_traits/is_unbounded_array.h | 38 - .../__type_traits/is_valid_expansion.h | 31 - .../__type_traits/is_within_lifetime.h | 2 +- lib/libcxx/include/__type_traits/lazy.h | 25 - .../include/__type_traits/make_transparent.h | 24 +- lib/libcxx/include/__type_traits/rank.h | 22 +- .../reference_converts_from_temporary.h | 8 +- .../include/__type_traits/remove_pointer.h | 19 +- lib/libcxx/include/__type_traits/result_of.h | 10 +- .../include/__type_traits/strip_signature.h | 3 + lib/libcxx/include/__utility/as_const.h | 8 +- .../include/__utility/constant_wrapper.h | 326 ++++++ .../__utility/default_three_way_comparator.h | 4 +- lib/libcxx/include/__utility/exchange.h | 17 +- lib/libcxx/include/__utility/forward_like.h | 8 +- lib/libcxx/include/__utility/in_place.h | 8 +- .../include/__utility/is_pointer_in_range.h | 12 +- lib/libcxx/include/__utility/is_valid_range.h | 37 - .../lazy_synth_three_way_comparator.h | 33 +- lib/libcxx/include/__utility/pair.h | 174 ++-- .../include/__utility/try_key_extraction.h | 12 +- lib/libcxx/include/__variant/monostate.h | 8 +- lib/libcxx/include/__vector/layout.h | 479 +++++++++ lib/libcxx/include/__vector/vector.h | 519 ++++------ lib/libcxx/include/__vector/vector_bool.h | 30 +- lib/libcxx/include/__verbose_abort | 2 + lib/libcxx/include/__verbose_trap | 13 +- lib/libcxx/include/algorithm | 59 +- lib/libcxx/include/any | 20 +- lib/libcxx/include/array | 2 +- lib/libcxx/include/atomic | 6 +- lib/libcxx/include/barrier | 4 +- lib/libcxx/include/bit | 2 +- lib/libcxx/include/bitset | 2 +- lib/libcxx/include/cctype | 68 +- lib/libcxx/include/cfenv | 13 +- lib/libcxx/include/cfloat | 14 +- lib/libcxx/include/charconv | 6 +- lib/libcxx/include/chrono | 7 +- lib/libcxx/include/cinttypes | 13 +- lib/libcxx/include/cmath | 2 +- lib/libcxx/include/codecvt | 4 +- lib/libcxx/include/compare | 2 +- lib/libcxx/include/complex | 2 +- lib/libcxx/include/concepts | 2 +- lib/libcxx/include/condition_variable | 7 +- lib/libcxx/include/coroutine | 2 +- lib/libcxx/include/ctype.h | 65 -- lib/libcxx/include/cuchar | 8 +- lib/libcxx/include/cwchar | 2 +- lib/libcxx/include/deque | 76 +- lib/libcxx/include/exception | 4 +- lib/libcxx/include/execution | 2 +- lib/libcxx/include/experimental/iterator | 4 +- lib/libcxx/include/experimental/memory | 12 +- .../include/experimental/propagate_const | 2 +- lib/libcxx/include/experimental/simd | 2 +- lib/libcxx/include/experimental/type_traits | 2 +- lib/libcxx/include/experimental/utility | 2 +- lib/libcxx/include/ext/hash_map | 2 +- lib/libcxx/include/ext/hash_set | 2 +- lib/libcxx/include/fenv.h | 118 --- lib/libcxx/include/filesystem | 2 +- lib/libcxx/include/float.h | 99 -- lib/libcxx/include/format | 23 +- lib/libcxx/include/forward_list | 12 +- lib/libcxx/include/fstream | 121 ++- lib/libcxx/include/functional | 12 +- lib/libcxx/include/future | 33 +- lib/libcxx/include/initializer_list | 12 +- lib/libcxx/include/inttypes.h | 268 ----- lib/libcxx/include/iomanip | 22 +- lib/libcxx/include/ios | 33 +- lib/libcxx/include/istream | 6 +- lib/libcxx/include/iterator | 4 +- lib/libcxx/include/latch | 2 +- lib/libcxx/include/limits | 16 +- lib/libcxx/include/list | 12 +- lib/libcxx/include/locale | 2 +- lib/libcxx/include/map | 960 ++++++++++-------- lib/libcxx/include/mdspan | 92 +- lib/libcxx/include/memory | 2 +- lib/libcxx/include/memory_resource | 4 +- lib/libcxx/include/mutex | 31 +- lib/libcxx/include/new | 6 +- lib/libcxx/include/numbers | 2 +- lib/libcxx/include/numeric | 14 +- lib/libcxx/include/optional | 726 +++++++------ lib/libcxx/include/ostream | 4 +- lib/libcxx/include/print | 136 +-- lib/libcxx/include/queue | 2 +- lib/libcxx/include/random | 2 +- lib/libcxx/include/ranges | 40 +- lib/libcxx/include/ratio | 2 +- lib/libcxx/include/regex | 7 +- lib/libcxx/include/scoped_allocator | 10 +- lib/libcxx/include/semaphore | 2 +- lib/libcxx/include/set | 587 +++++++---- lib/libcxx/include/shared_mutex | 58 +- lib/libcxx/include/source_location | 8 +- lib/libcxx/include/span | 51 +- lib/libcxx/include/sstream | 4 +- lib/libcxx/include/stack | 2 +- lib/libcxx/include/stdatomic.h | 2 +- lib/libcxx/include/stdbool.h | 44 - lib/libcxx/include/stdexcept | 4 +- lib/libcxx/include/stop_token | 6 +- lib/libcxx/include/streambuf | 6 +- lib/libcxx/include/string | 388 +++---- lib/libcxx/include/string.h | 2 + lib/libcxx/include/string_view | 2 +- lib/libcxx/include/strstream | 2 + lib/libcxx/include/syncstream | 11 +- lib/libcxx/include/system_error | 2 +- lib/libcxx/include/text_encoding | 835 +++++++++++++++ lib/libcxx/include/thread | 20 +- lib/libcxx/include/tuple | 118 +-- lib/libcxx/include/typeindex | 2 +- lib/libcxx/include/typeinfo | 4 +- lib/libcxx/include/unordered_map | 98 +- lib/libcxx/include/unordered_set | 98 +- lib/libcxx/include/utility | 21 +- lib/libcxx/include/valarray | 4 +- lib/libcxx/include/variant | 58 +- lib/libcxx/include/vector | 20 +- lib/libcxx/include/version | 38 +- lib/libcxx/include/wchar.h | 2 + lib/libcxx/src/algorithm.cpp | 2 + lib/libcxx/src/any.cpp | 6 +- lib/libcxx/src/atomic.cpp | 221 ++-- lib/libcxx/src/barrier.cpp | 2 + lib/libcxx/src/call_once.cpp | 2 + lib/libcxx/src/charconv.cpp | 3 + lib/libcxx/src/chrono.cpp | 5 +- lib/libcxx/src/condition_variable.cpp | 2 + .../src/condition_variable_destructor.cpp | 2 + lib/libcxx/src/error_category.cpp | 2 + lib/libcxx/src/expected.cpp | 4 + .../src/experimental/chrono_exception.cpp | 2 + .../experimental/include/tzdb/tzdb_private.h | 2 + .../experimental/log_hardening_failure.cpp | 2 + lib/libcxx/src/experimental/time_zone.cpp | 8 +- lib/libcxx/src/experimental/tzdb.cpp | 4 +- lib/libcxx/src/experimental/tzdb_list.cpp | 2 + lib/libcxx/src/filesystem/directory_entry.cpp | 2 + .../src/filesystem/directory_iterator.cpp | 2 + .../src/filesystem/filesystem_clock.cpp | 4 +- .../src/filesystem/filesystem_error.cpp | 2 + lib/libcxx/src/filesystem/operations.cpp | 5 + lib/libcxx/src/filesystem/path.cpp | 23 +- lib/libcxx/src/fstream.cpp | 2 + lib/libcxx/src/functional.cpp | 2 + lib/libcxx/src/future.cpp | 2 + lib/libcxx/src/hash.cpp | 351 +------ lib/libcxx/src/include/apple_availability.h | 34 - lib/libcxx/src/include/config_elast.h | 2 +- lib/libcxx/src/include/overridable_function.h | 130 ++- lib/libcxx/src/include/refstring.h | 2 +- lib/libcxx/src/include/ryu/ryu.h | 18 - .../src/include/to_chars_floating_point.h | 2 +- lib/libcxx/src/ios.cpp | 77 +- lib/libcxx/src/ios.instantiations.cpp | 21 + lib/libcxx/src/iostream.cpp | 2 + lib/libcxx/src/locale.cpp | 40 +- lib/libcxx/src/memory.cpp | 5 +- lib/libcxx/src/memory_resource.cpp | 37 +- lib/libcxx/src/mutex.cpp | 2 + lib/libcxx/src/mutex_destructor.cpp | 2 + lib/libcxx/src/new.cpp | 32 +- lib/libcxx/src/optional.cpp | 2 + lib/libcxx/src/ostream.cpp | 2 + lib/libcxx/src/print.cpp | 7 +- lib/libcxx/src/pstl/libdispatch.cpp | 2 + lib/libcxx/src/random.cpp | 2 + lib/libcxx/src/random_shuffle.cpp | 2 + lib/libcxx/src/regex.cpp | 2 + lib/libcxx/src/ryu/d2s.cpp | 15 +- lib/libcxx/src/ryu/f2s.cpp | 4 +- lib/libcxx/src/shared_mutex.cpp | 2 + lib/libcxx/src/std_stream.h | 2 + lib/libcxx/src/stdexcept.cpp | 2 + lib/libcxx/src/string.cpp | 2 + lib/libcxx/src/strstream.cpp | 2 + .../runtime/exception_pointer_msvc.ipp | 463 ++++++++- lib/libcxx/src/support/win32/locale_win32.cpp | 262 +++++ lib/libcxx/src/support/win32/thread_win32.cpp | 2 + lib/libcxx/src/system_error.cpp | 2 + lib/libcxx/src/text_encoding.cpp | 54 + lib/libcxx/src/thread.cpp | 2 + lib/libcxx/src/valarray.cpp | 2 + lib/libcxx/src/variant.cpp | 2 + lib/libcxx/src/vector.cpp | 2 + lib/libcxx/src/verbose_abort.cpp | 4 +- src/libs/libcxx.zig | 5 +- 621 files changed, 13795 insertions(+), 9389 deletions(-) create mode 100644 lib/libcxx/include/__algorithm/ranges_shift_left.h create mode 100644 lib/libcxx/include/__algorithm/ranges_shift_right.h rename lib/libcxx/include/{__type_traits/is_primary_template.h => __concepts/primary_template.h} (69%) rename lib/libcxx/include/{__type_traits/is_referenceable.h => __concepts/referenceable.h} (77%) create mode 100644 lib/libcxx/include/__configuration/attributes.h create mode 100644 lib/libcxx/include/__configuration/diagnostic_suppression.h create mode 100644 lib/libcxx/include/__configuration/namespace.h create mode 100644 lib/libcxx/include/__configuration/pstl.h create mode 100644 lib/libcxx/include/__configuration/utility.h create mode 100644 lib/libcxx/include/__format/formatter_bool_impl.h delete mode 100644 lib/libcxx/include/__fwd/map.h delete mode 100644 lib/libcxx/include/__fwd/set.h create mode 100644 lib/libcxx/include/__iterator/capacity_aware_iterator.h delete mode 100644 lib/libcxx/include/__locale_dir/locale_base_api/android.h create mode 100644 lib/libcxx/include/__locale_dir/locale_base_api/ibm.h delete mode 100644 lib/libcxx/include/__locale_dir/locale_base_api/musl.h delete mode 100644 lib/libcxx/include/__locale_dir/locale_base_api/openbsd.h create mode 100644 lib/libcxx/include/__locale_dir/support/no_locale/conversions.h create mode 100644 lib/libcxx/include/__locale_dir/support/no_locale/formatting.h create mode 100644 lib/libcxx/include/__locale_dir/support/openbsd.h delete mode 100644 lib/libcxx/include/__memory/aligned_alloc.h create mode 100644 lib/libcxx/include/__memory/uninitialized_multidimensional_algorithms.h create mode 100644 lib/libcxx/include/__memory/valid_range.h create mode 100644 lib/libcxx/include/__ranges/concat_view.h create mode 100644 lib/libcxx/include/__ranges/enumerate_view.h create mode 100644 lib/libcxx/include/__ranges/stride_view.h delete mode 100644 lib/libcxx/include/__support/xlocale/__nop_locale_mgmt.h delete mode 100644 lib/libcxx/include/__support/xlocale/__strtonum_fallback.h delete mode 100644 lib/libcxx/include/__tuple/make_tuple_types.h delete mode 100644 lib/libcxx/include/__tuple/tuple_indices.h delete mode 100644 lib/libcxx/include/__tuple/tuple_like_ext.h delete mode 100644 lib/libcxx/include/__tuple/tuple_types.h delete mode 100644 lib/libcxx/include/__type_traits/can_extract_key.h delete mode 100644 lib/libcxx/include/__type_traits/dependent_type.h delete mode 100644 lib/libcxx/include/__type_traits/is_bounded_array.h delete mode 100644 lib/libcxx/include/__type_traits/is_replaceable.h delete mode 100644 lib/libcxx/include/__type_traits/is_unbounded_array.h delete mode 100644 lib/libcxx/include/__type_traits/is_valid_expansion.h delete mode 100644 lib/libcxx/include/__type_traits/lazy.h create mode 100644 lib/libcxx/include/__utility/constant_wrapper.h delete mode 100644 lib/libcxx/include/__utility/is_valid_range.h create mode 100644 lib/libcxx/include/__vector/layout.h delete mode 100644 lib/libcxx/include/ctype.h delete mode 100644 lib/libcxx/include/fenv.h delete mode 100644 lib/libcxx/include/float.h delete mode 100644 lib/libcxx/include/inttypes.h delete mode 100644 lib/libcxx/include/stdbool.h create mode 100644 lib/libcxx/include/text_encoding delete mode 100644 lib/libcxx/src/include/apple_availability.h create mode 100644 lib/libcxx/src/text_encoding.cpp diff --git a/lib/libcxx/include/__algorithm/clamp.h b/lib/libcxx/include/__algorithm/clamp.h index 1a5a3d0744be9c35d8aa2222a87d0580b4d6b42a..cf7cd507a1497bd12ba549c25ecc83f819c6e169 100644 --- a/lib/libcxx/include/__algorithm/clamp.h +++ b/lib/libcxx/include/__algorithm/clamp.h @@ -17,9 +17,10 @@ # pragma GCC system_header #endif -_LIBCPP_BEGIN_NAMESPACE_STD - #if _LIBCPP_STD_VER >= 17 + +_LIBCPP_BEGIN_NAMESPACE_STD + template [[nodiscard]] inline _LIBCPP_HIDE_FROM_ABI constexpr const _Tp& clamp(_LIBCPP_LIFETIMEBOUND const _Tp& __v, @@ -37,8 +38,9 @@ clamp(_LIBCPP_LIFETIMEBOUND const _Tp& __v, _LIBCPP_LIFETIMEBOUND const _Tp& __hi) { return std::clamp(__v, __lo, __hi, __less<>()); } -#endif _LIBCPP_END_NAMESPACE_STD +#endif // _LIBCPP_STD_VER >= 17 + #endif // _LIBCPP___ALGORITHM_CLAMP_H diff --git a/lib/libcxx/include/__algorithm/copy.h b/lib/libcxx/include/__algorithm/copy.h index 344a53e516e3ed0d4ea91edc5cfabdc5b5bf7be0..711cb644462cb455f192a3b299b2dfc6f70f1df4 100644 --- a/lib/libcxx/include/__algorithm/copy.h +++ b/lib/libcxx/include/__algorithm/copy.h @@ -11,6 +11,7 @@ #include <__algorithm/copy_move_common.h> #include <__algorithm/for_each_segment.h> +#include <__algorithm/in_out_result.h> #include <__algorithm/min.h> #include <__algorithm/specialized_algorithms.h> #include <__config> @@ -19,7 +20,6 @@ #include <__type_traits/common_type.h> #include <__type_traits/enable_if.h> #include <__utility/move.h> -#include <__utility/pair.h> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header @@ -35,7 +35,8 @@ inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator copy(_InputIterator __first, _InputIterator __last, _OutputIterator __result); template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_InIter, _OutIter> __copy(_InIter, _Sent, _OutIter); +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 __in_out_result<_InIter, _OutIter> + __copy(_InIter, _Sent, _OutIter); struct __copy_impl { template , __single_iterator<_OutIter> >::__has_algorithm, int> = 0> - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_InIter, _OutIter> + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 __in_out_result<_InIter, _OutIter> operator()(_InIter __first, _Sent __last, _OutIter __result) const { while (__first != __last) { *__result = *__first; @@ -53,7 +54,7 @@ struct __copy_impl { ++__result; } - return std::make_pair(std::move(__first), std::move(__result)); + return {std::move(__first), std::move(__result)}; } template , __single_iterator<_OutIter> >::__has_algorithm, int> = 0> - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 static pair<_InIter, _OutIter> + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 static __in_out_result<_InIter, _OutIter> operator()(_InIter __first, _Sent __last, _OutIter __result) { return __specialized_algorithm<_Algorithm::__copy, __iterator_pair<_InIter, _Sent>, __single_iterator<_OutIter> >()( std::move(__first), std::move(__last), std::move(__result)); } template , int> = 0> - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_InIter, _OutIter> + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 __in_out_result<_InIter, _OutIter> operator()(_InIter __first, _InIter __last, _OutIter __result) const { using __local_iterator = typename __segmented_iterator_traits<_InIter>::__local_iterator; std::__for_each_segment(__first, __last, [&__result](__local_iterator __lfirst, __local_iterator __llast) { - __result = std::__copy(std::move(__lfirst), std::move(__llast), std::move(__result)).second; + __result = std::__copy(std::move(__lfirst), std::move(__llast), std::move(__result)).__out_; }); - return std::make_pair(__last, std::move(__result)); + return {__last, std::move(__result)}; } template ::value && !__is_segmented_iterator_v<_InIter> && __is_segmented_iterator_v<_OutIter>, int> = 0> - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_InIter, _OutIter> + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 __in_out_result<_InIter, _OutIter> operator()(_InIter __first, _InIter __last, _OutIter __result) const { using _Traits = __segmented_iterator_traits<_OutIter>; using _DiffT = typename common_type<__iterator_difference_type<_InIter>, __iterator_difference_type<_OutIter> >::type; if (__first == __last) - return std::make_pair(std::move(__first), std::move(__result)); + return {std::move(__first), std::move(__result)}; auto __local_first = _Traits::__local(__result); auto __segment_iterator = _Traits::__segment(__result); @@ -99,10 +100,10 @@ struct __copy_impl { auto __local_last = _Traits::__end(__segment_iterator); auto __size = std::min<_DiffT>(__local_last - __local_first, __last - __first); auto __iters = std::__copy(__first, __first + __size, __local_first); - __first = std::move(__iters.first); + __first = std::move(__iters.__in_); if (__first == __last) - return std::make_pair(std::move(__first), _Traits::__compose(__segment_iterator, std::move(__iters.second))); + return {std::move(__first), _Traits::__compose(__segment_iterator, std::move(__iters.__out_))}; __local_first = _Traits::__begin(++__segment_iterator); } @@ -110,14 +111,14 @@ struct __copy_impl { // At this point, the iterators have been unwrapped so any `contiguous_iterator` has been unwrapped to a pointer. template ::value, int> = 0> - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_In*, _Out*> + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 __in_out_result<_In*, _Out*> operator()(_In* __first, _In* __last, _Out* __result) const { return std::__copy_trivial_impl(__first, __last, __result); } }; template -pair<_InIter, _OutIter> inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 +__in_out_result<_InIter, _OutIter> inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 __copy(_InIter __first, _Sent __last, _OutIter __result) { return std::__copy_move_unwrap_iters<__copy_impl>(std::move(__first), std::move(__last), std::move(__result)); } @@ -125,7 +126,7 @@ __copy(_InIter __first, _Sent __last, _OutIter __result) { template _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator copy(_InputIterator __first, _InputIterator __last, _OutputIterator __result) { - return std::__copy(__first, __last, __result).second; + return std::__copy(__first, __last, __result).__out_; } _LIBCPP_END_NAMESPACE_STD diff --git a/lib/libcxx/include/__algorithm/copy_backward.h b/lib/libcxx/include/__algorithm/copy_backward.h index 8758d2c9e7b5d514e34f25b754613e8b98e2e451..15c213a4c5dec2780194723d7ffac0b7e68988ca 100644 --- a/lib/libcxx/include/__algorithm/copy_backward.h +++ b/lib/libcxx/include/__algorithm/copy_backward.h @@ -12,6 +12,7 @@ #include <__algorithm/copy_move_common.h> #include <__algorithm/copy_n.h> #include <__algorithm/for_each_segment.h> +#include <__algorithm/in_out_result.h> #include <__algorithm/iterator_operations.h> #include <__algorithm/min.h> #include <__config> @@ -23,7 +24,6 @@ #include <__type_traits/enable_if.h> #include <__type_traits/is_constructible.h> #include <__utility/move.h> -#include <__utility/pair.h> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header @@ -35,7 +35,7 @@ _LIBCPP_PUSH_MACROS _LIBCPP_BEGIN_NAMESPACE_STD template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_InIter, _OutIter> +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __in_out_result<_InIter, _OutIter> __copy_backward(_InIter __first, _Sent __last, _OutIter __result); template @@ -159,7 +159,7 @@ _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI __bit_iterator<_Cp, false> _ template struct __copy_backward_impl { template - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_InIter, _OutIter> + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 __in_out_result<_InIter, _OutIter> operator()(_InIter __first, _Sent __last, _OutIter __result) const { auto __last_iter = _IterOps<_AlgPolicy>::next(__first, __last); auto __original_last_iter = __last_iter; @@ -168,17 +168,17 @@ struct __copy_backward_impl { *--__result = *--__last_iter; } - return std::make_pair(std::move(__original_last_iter), std::move(__result)); + return {std::move(__original_last_iter), std::move(__result)}; } template , int> = 0> - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_InIter, _OutIter> + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 __in_out_result<_InIter, _OutIter> operator()(_InIter __first, _InIter __last, _OutIter __result) const { using __local_iterator = typename __segmented_iterator_traits<_InIter>::__local_iterator; std::__for_each_segment_backward(__first, __last, [&__result](__local_iterator __lfirst, __local_iterator __llast) { - __result = std::__copy_backward<_AlgPolicy>(std::move(__lfirst), std::move(__llast), std::move(__result)).second; + __result = std::__copy_backward<_AlgPolicy>(std::move(__lfirst), std::move(__llast), std::move(__result)).__out_; }); - return std::make_pair(__last, std::move(__result)); + return {__last, std::move(__result)}; } template ::value && !__is_segmented_iterator_v<_InIter> && __is_segmented_iterator_v<_OutIter>, int> = 0> - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_InIter, _OutIter> + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 __in_out_result<_InIter, _OutIter> operator()(_InIter __first, _InIter __last, _OutIter __result) const { using _Traits = __segmented_iterator_traits<_OutIter>; auto __orig_last = __last; @@ -194,7 +194,7 @@ struct __copy_backward_impl { // When the range contains no elements, __result might not be a valid iterator if (__first == __last) - return std::make_pair(__first, __result); + return {__first, __result}; auto __local_last = _Traits::__local(__result); while (true) { @@ -203,36 +203,37 @@ struct __copy_backward_impl { auto __local_first = _Traits::__begin(__segment_iterator); auto __size = std::min<_DiffT>(__local_last - __local_first, __last - __first); - auto __iter = std::__copy_backward<_AlgPolicy>(__last - __size, __last, __local_last).second; + auto __iter = std::__copy_backward<_AlgPolicy>(__last - __size, __last, __local_last).__out_; __last -= __size; if (__first == __last) - return std::make_pair(std::move(__orig_last), _Traits::__compose(__segment_iterator, std::move(__iter))); + return {std::move(__orig_last), _Traits::__compose(__segment_iterator, std::move(__iter))}; --__segment_iterator; __local_last = _Traits::__end(__segment_iterator); } } template - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<__bit_iterator<_Cp, _IsConst>, __bit_iterator<_Cp, false> > + _LIBCPP_HIDE_FROM_ABI + _LIBCPP_CONSTEXPR_SINCE_CXX20 __in_out_result<__bit_iterator<_Cp, _IsConst>, __bit_iterator<_Cp, false> > operator()(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, __bit_iterator<_Cp, false> __result) { if (__last.__ctz_ == __result.__ctz_) - return std::make_pair(__last, std::__copy_backward_aligned(__first, __last, __result)); - return std::make_pair(__last, std::__copy_backward_unaligned(__first, __last, __result)); + return {__last, std::__copy_backward_aligned(__first, __last, __result)}; + return {__last, std::__copy_backward_unaligned(__first, __last, __result)}; } // At this point, the iterators have been unwrapped so any `contiguous_iterator` has been unwrapped to a pointer. template ::value, int> = 0> - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_In*, _Out*> + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 __in_out_result<_In*, _Out*> operator()(_In* __first, _In* __last, _Out* __result) const { return std::__copy_backward_trivial_impl(__first, __last, __result); } }; template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_BidirectionalIterator1, _BidirectionalIterator2> +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __in_out_result<_BidirectionalIterator1, _BidirectionalIterator2> __copy_backward(_BidirectionalIterator1 __first, _Sentinel __last, _BidirectionalIterator2 __result) { return std::__copy_move_unwrap_iters<__copy_backward_impl<_AlgPolicy> >( std::move(__first), std::move(__last), std::move(__result)); @@ -245,7 +246,7 @@ copy_backward(_BidirectionalIterator1 __first, _BidirectionalIterator1 __last, _ std::is_copy_constructible<_BidirectionalIterator1>::value, "Iterators must be copy constructible."); - return std::__copy_backward<_ClassicAlgPolicy>(std::move(__first), std::move(__last), std::move(__result)).second; + return std::__copy_backward<_ClassicAlgPolicy>(std::move(__first), std::move(__last), std::move(__result)).__out_; } _LIBCPP_END_NAMESPACE_STD diff --git a/lib/libcxx/include/__algorithm/copy_if.h b/lib/libcxx/include/__algorithm/copy_if.h index ffea621fc061830af3d4515152181938addf849e..7bbfaa37ff95d35f359bc3ee5ea838ca5f3d7f23 100644 --- a/lib/libcxx/include/__algorithm/copy_if.h +++ b/lib/libcxx/include/__algorithm/copy_if.h @@ -9,6 +9,7 @@ #ifndef _LIBCPP___ALGORITHM_COPY_IF_H #define _LIBCPP___ALGORITHM_COPY_IF_H +#include <__algorithm/in_out_result.h> #include <__config> #include <__functional/identity.h> #include <__type_traits/invoke.h> @@ -25,7 +26,7 @@ _LIBCPP_PUSH_MACROS _LIBCPP_BEGIN_NAMESPACE_STD template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_InIter, _OutIter> +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 __in_out_result<_InIter, _OutIter> __copy_if(_InIter __first, _Sent __last, _OutIter __result, _Pred& __pred, _Proj& __proj) { for (; __first != __last; ++__first) { if (std::__invoke(__pred, std::__invoke(__proj, *__first))) { @@ -33,14 +34,14 @@ __copy_if(_InIter __first, _Sent __last, _OutIter __result, _Pred& __pred, _Proj ++__result; } } - return std::make_pair(std::move(__first), std::move(__result)); + return {std::move(__first), std::move(__result)}; } template inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator copy_if(_InputIterator __first, _InputIterator __last, _OutputIterator __result, _Predicate __pred) { __identity __proj; - return std::__copy_if(__first, __last, __result, __pred, __proj).second; + return std::__copy_if(__first, __last, __result, __pred, __proj).__out_; } _LIBCPP_END_NAMESPACE_STD diff --git a/lib/libcxx/include/__algorithm/copy_move_common.h b/lib/libcxx/include/__algorithm/copy_move_common.h index 7471012c01d969134d9f39c4a150ca7bc32767ed..85723a7ebe587245515359c965ee3e290fb7b75b 100644 --- a/lib/libcxx/include/__algorithm/copy_move_common.h +++ b/lib/libcxx/include/__algorithm/copy_move_common.h @@ -9,21 +9,18 @@ #ifndef _LIBCPP___ALGORITHM_COPY_MOVE_COMMON_H #define _LIBCPP___ALGORITHM_COPY_MOVE_COMMON_H +#include <__algorithm/in_out_result.h> #include <__algorithm/unwrap_iter.h> #include <__algorithm/unwrap_range.h> #include <__config> #include <__cstddef/size_t.h> -#include <__iterator/iterator_traits.h> -#include <__memory/pointer_traits.h> #include <__string/constexpr_c_functions.h> #include <__type_traits/enable_if.h> #include <__type_traits/is_always_bitcastable.h> -#include <__type_traits/is_constant_evaluated.h> #include <__type_traits/is_constructible.h> #include <__type_traits/is_trivially_assignable.h> #include <__type_traits/is_volatile.h> #include <__utility/move.h> -#include <__utility/pair.h> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header @@ -57,24 +54,24 @@ struct __can_lower_move_assignment_to_memmove { // `memmove` algorithms implementation. template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_In*, _Out*> +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 __in_out_result<_In*, _Out*> __copy_trivial_impl(_In* __first, _In* __last, _Out* __result) { const size_t __n = static_cast(__last - __first); std::__constexpr_memmove(__result, __first, __element_count(__n)); - return std::make_pair(__last, __result + __n); + return {__last, __result + __n}; } template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_In*, _Out*> +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 __in_out_result<_In*, _Out*> __copy_backward_trivial_impl(_In* __first, _In* __last, _Out* __result) { const size_t __n = static_cast(__last - __first); __result -= __n; std::__constexpr_memmove(__result, __first, __element_count(__n)); - return std::make_pair(__last, __result); + return {__last, __result}; } // Iterator unwrapping and dispatching to the correct overload. @@ -88,12 +85,12 @@ template ::value, int> = 0> -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 pair<_InIter, _OutIter> +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 __in_out_result<_InIter, _OutIter> __copy_move_unwrap_iters(_InIter __first, _Sent __last, _OutIter __out_first) { auto __range = std::__unwrap_range(__first, std::move(__last)); auto __result = _Algorithm()(std::move(__range.first), std::move(__range.second), std::__unwrap_iter(__out_first)); - return std::make_pair(std::__rewrap_range<_Sent>(std::move(__first), std::move(__result.first)), - std::__rewrap_iter(std::move(__out_first), std::move(__result.second))); + return {std::__rewrap_range<_Sent>(std::move(__first), std::move(__result.__in_)), + std::__rewrap_iter(std::move(__out_first), std::move(__result.__out_))}; } template ::value, int> = 0> -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 pair<_InIter, _OutIter> +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 __in_out_result<_InIter, _OutIter> __copy_move_unwrap_iters(_InIter __first, _Sent __last, _OutIter __out_first) { return _Algorithm()(std::move(__first), std::move(__last), std::move(__out_first)); } diff --git a/lib/libcxx/include/__algorithm/copy_n.h b/lib/libcxx/include/__algorithm/copy_n.h index 56fb44811fc4a7e8ba772e165a1840d2de8157c5..ac52b2b686c282d2c69d16085993afc4bd900b17 100644 --- a/lib/libcxx/include/__algorithm/copy_n.h +++ b/lib/libcxx/include/__algorithm/copy_n.h @@ -10,13 +10,13 @@ #define _LIBCPP___ALGORITHM_COPY_N_H #include <__algorithm/copy.h> +#include <__algorithm/in_out_result.h> #include <__algorithm/iterator_operations.h> #include <__config> #include <__iterator/iterator_traits.h> #include <__type_traits/enable_if.h> #include <__utility/convert_to_integral.h> #include <__utility/move.h> -#include <__utility/pair.h> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header @@ -31,7 +31,7 @@ template ::value, int> = 0> -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_InIter, _OutIter> +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __in_out_result<_InIter, _OutIter> __copy_n(_InIter __first, typename _IterOps<_AlgPolicy>::template __difference_type<_InIter> __n, _OutIter __result) { return std::__copy(__first, __first + __n, std::move(__result)); } @@ -40,7 +40,7 @@ template ::value, int> = 0> -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_InIter, _OutIter> +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __in_out_result<_InIter, _OutIter> __copy_n(_InIter __first, typename _IterOps<_AlgPolicy>::template __difference_type<_InIter> __n, _OutIter __result) { while (__n != 0) { *__result = *__first; @@ -48,7 +48,7 @@ __copy_n(_InIter __first, typename _IterOps<_AlgPolicy>::template __difference_t ++__result; --__n; } - return std::make_pair(std::move(__first), std::move(__result)); + return {std::move(__first), std::move(__result)}; } // The InputIterator case is handled specially here because it's been written in a way to avoid incrementing __first @@ -84,7 +84,7 @@ copy_n(_InputIterator __first, _Size __n, _OutputIterator __result) { using _IntegralSize = decltype(std::__convert_to_integral(__n)); _IntegralSize __converted = __n; return std::__copy_n<_ClassicAlgPolicy>(__first, __iterator_difference_type<_InputIterator>(__converted), __result) - .second; + .__out_; } _LIBCPP_END_NAMESPACE_STD diff --git a/lib/libcxx/include/__algorithm/equal.h b/lib/libcxx/include/__algorithm/equal.h index 957cc29759424e38e2b4b9e967067870f6fca668..b6247c1bc4047ea76972c096c9b610b8bbcda0f7 100644 --- a/lib/libcxx/include/__algorithm/equal.h +++ b/lib/libcxx/include/__algorithm/equal.h @@ -11,15 +11,16 @@ #define _LIBCPP___ALGORITHM_EQUAL_H #include <__algorithm/comp.h> +#include <__algorithm/find_segment_if.h> #include <__algorithm/min.h> #include <__algorithm/unwrap_iter.h> #include <__config> #include <__functional/identity.h> #include <__fwd/bit_reference.h> -#include <__iterator/distance.h> #include <__iterator/iterator_traits.h> -#include <__memory/pointer_traits.h> +#include <__iterator/segmented_iterator.h> #include <__string/constexpr_c_functions.h> +#include <__type_traits/common_type.h> #include <__type_traits/desugars_to.h> #include <__type_traits/enable_if.h> #include <__type_traits/invoke.h> @@ -27,6 +28,7 @@ #include <__type_traits/is_same.h> #include <__type_traits/is_volatile.h> #include <__utility/move.h> +#include <__utility/unreachable.h> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header @@ -177,15 +179,6 @@ template -[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool __equal_iter_impl( - _InIter1 __first1, _Sent1 __last1, _InIter2 __first2, _Pred& __pred, _Proj1& __proj1, _Proj2& __proj2) { - for (; __first1 != __last1; ++__first1, (void)++__first2) - if (!std::__invoke(__pred, std::__invoke(__proj1, *__first1), std::__invoke(__proj2, *__first2))) - return false; - return true; -} - template +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool __equal_iter_impl( + _InIter1 __first1, _Sent1 __last1, _InIter2 __first2, _Pred& __pred, _Proj1& __proj1, _Proj2& __proj2) { +#ifndef _LIBCPP_CXX03_LANG + if constexpr (__has_random_access_iterator_category<_InIter1>::value && + __has_random_access_iterator_category<_InIter2>::value) { + if constexpr (is_same<_InIter1, _Sent1>::value && __is_segmented_iterator_v<_InIter1>) { + using __local_iterator_t = typename __segmented_iterator_traits<_InIter1>::__local_iterator; + bool __is_equal = true; + std::__find_segment_if(__first1, __last1, [&](__local_iterator_t __lfirst, __local_iterator_t __llast) { + if (std::__equal_iter_impl( + std::__unwrap_iter(__lfirst), std::__unwrap_iter(__llast), __first2, __pred, __proj1, __proj2)) { + __first2 += __llast - __lfirst; + return __llast; + } + __is_equal = false; + return __lfirst; + }); + return __is_equal; + } else if constexpr (__is_segmented_iterator_v<_InIter2>) { + using _Traits = __segmented_iterator_traits<_InIter2>; + using _DiffT = + typename common_type<__iterator_difference_type<_InIter1>, __iterator_difference_type<_InIter2> >::type; + + if (__first1 == __last1) + return true; + + auto __local_first = _Traits::__local(__first2); + auto __segment_iterator = _Traits::__segment(__first2); + + while (true) { + auto __local_last = _Traits::__end(__segment_iterator); + auto __size = std::min<_DiffT>(__local_last - __local_first, __last1 - __first1); + if (!std::__equal_iter_impl( + __first1, __first1 + __size, std::__unwrap_iter(__local_first), __pred, __proj1, __proj2)) + return false; + + __first1 += __size; + if (__first1 == __last1) + return true; + + __local_first = _Traits::__begin(++__segment_iterator); + } + } + } +#endif + for (; __first1 != __last1; ++__first1, (void)++__first2) + if (!std::__invoke(__pred, std::__invoke(__proj1, *__first1), std::__invoke(__proj2, *__first2))) + return false; + return true; +} + template [[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool equal(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _BinaryPredicate __pred) { @@ -247,11 +292,11 @@ equal(_InputIterator1 __first1, _InputIterator2 __first2, _InputIterator2 __last2, _BinaryPredicate __pred) { - static constexpr bool __both_random_access = + constexpr bool __both_random_access = __has_random_access_iterator_category<_InputIterator1>::value && __has_random_access_iterator_category<_InputIterator2>::value; if constexpr (__both_random_access) { - if (std::distance(__first1, __last1) != std::distance(__first2, __last2)) + if (__last1 - __first1 != __last2 - __first2) return false; } __identity __proj; diff --git a/lib/libcxx/include/__algorithm/find.h b/lib/libcxx/include/__algorithm/find.h index 852bc2da3eb7b863e1b379163db115ec6cbf29b6..f677fb2c7392dd8f48f6b2a96fe2a37ab29cb1be 100644 --- a/lib/libcxx/include/__algorithm/find.h +++ b/lib/libcxx/include/__algorithm/find.h @@ -10,6 +10,7 @@ #ifndef _LIBCPP___ALGORITHM_FIND_H #define _LIBCPP___ALGORITHM_FIND_H +#include <__algorithm/find_if.h> #include <__algorithm/find_segment_if.h> #include <__algorithm/min.h> #include <__algorithm/simd_utils.h> @@ -47,17 +48,18 @@ _LIBCPP_BEGIN_NAMESPACE_STD // generic implementation template _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Iter -__find_loop(_Iter __first, _Sent __last, const _Tp& __value, _Proj& __proj) { - for (; __first != __last; ++__first) - if (std::__invoke(__proj, *__first) == __value) - break; - return __first; +__find_generic(_Iter __first, _Sent __last, const _Tp& __value, _Proj& __proj) { + return std::__find_if( + std::move(__first), + std::move(__last), + [&](_ValT&& __val) -> bool { return __val == __value; }, + __proj); } template _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Iter __find(_Iter __first, _Sent __last, const _Tp& __value, _Proj& __proj) { - return std::__find_loop(std::move(__first), std::move(__last), __value, __proj); + return std::__find_generic(std::move(__first), std::move(__last), __value, __proj); } #if _LIBCPP_VECTORIZE_ALGORITHMS @@ -108,7 +110,7 @@ _LIBCPP_CONSTEXPR_SINCE_CXX14 _Tp* __find_vectorized(_Tp* __first, _Tp* __last, } __identity __proj; - return std::__find_loop(__first, __last, __value, __proj); + return std::__find_generic(__first, __last, __value, __proj); } #endif @@ -138,7 +140,7 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Tp* __find(_Tp* __first, _T # endif else { __identity __proj; - return std::__find_loop(__first, __last, __value, __proj); + return std::__find_generic(__first, __last, __value, __proj); } } #endif @@ -216,13 +218,10 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _SegmentedIterator __find(_SegmentedIterator __first, _SegmentedIterator __last, const _Tp& __value, _Proj& __proj) { using __local_iterator = typename __segmented_iterator_traits<_SegmentedIterator>::__local_iterator; return std::__find_segment_if( - std::move(__first), - std::move(__last), - [&__value](__local_iterator __lfirst, __local_iterator __llast, _Proj& __lproj) { + std::move(__first), std::move(__last), [&__value, &__proj](__local_iterator __lfirst, __local_iterator __llast) { return std::__rewrap_iter( - __lfirst, std::__find(std::__unwrap_iter(__lfirst), std::__unwrap_iter(__llast), __value, __lproj)); - }, - __proj); + __lfirst, std::__find(std::__unwrap_iter(__lfirst), std::__unwrap_iter(__llast), __value, __proj)); + }); } // public API diff --git a/lib/libcxx/include/__algorithm/find_if.h b/lib/libcxx/include/__algorithm/find_if.h index fd63bcc3a50dd96192ba7b064ee6892a891a2ff6..2a96e13ce354662ac08fe23028fb10b8f0b4cc34 100644 --- a/lib/libcxx/include/__algorithm/find_if.h +++ b/lib/libcxx/include/__algorithm/find_if.h @@ -11,6 +11,9 @@ #define _LIBCPP___ALGORITHM_FIND_IF_H #include <__config> +#include <__functional/identity.h> +#include <__memory/valid_range.h> +#include <__type_traits/invoke.h> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header @@ -18,15 +21,23 @@ _LIBCPP_BEGIN_NAMESPACE_STD -template -[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _InputIterator -find_if(_InputIterator __first, _InputIterator __last, _Predicate __pred) { +template +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 _Iter +__find_if(_Iter __first, _Sent __last, _Pred&& __pred, _Proj&& __proj) { + std::__assume_valid_range(__first, __last); + for (; __first != __last; ++__first) - if (__pred(*__first)) + if (std::__invoke(__pred, std::__invoke(__proj, *__first))) break; return __first; } +template +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _InputIterator +find_if(_InputIterator __first, _InputIterator __last, _Predicate __pred) { + return std::__find_if(__first, __last, __pred, __identity()); +} + _LIBCPP_END_NAMESPACE_STD #endif // _LIBCPP___ALGORITHM_FIND_IF_H diff --git a/lib/libcxx/include/__algorithm/find_if_not.h b/lib/libcxx/include/__algorithm/find_if_not.h index b4441b297c4bf481e72a76e00e70db9e48090335..d37da4c645468b7472beae9a8e61f3dbd216b0f3 100644 --- a/lib/libcxx/include/__algorithm/find_if_not.h +++ b/lib/libcxx/include/__algorithm/find_if_not.h @@ -10,23 +10,39 @@ #ifndef _LIBCPP___ALGORITHM_FIND_IF_NOT_H #define _LIBCPP___ALGORITHM_FIND_IF_NOT_H +#include <__algorithm/find_if.h> #include <__config> +#include <__functional/identity.h> +#include <__type_traits/invoke.h> +#include <__utility/move.h> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header #endif +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + _LIBCPP_BEGIN_NAMESPACE_STD +template +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Iter +__find_if_not(_Iter __first, _Sent __last, _Pred&& __pred, _Proj&& __proj) { + return std::__find_if( + std::move(__first), + std::move(__last), + [&](_ValT&& __val) -> bool { return !std::__invoke(__pred, __val); }, + __proj); +} + template [[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _InputIterator find_if_not(_InputIterator __first, _InputIterator __last, _Predicate __pred) { - for (; __first != __last; ++__first) - if (!__pred(*__first)) - break; - return __first; + return std::__find_if_not(__first, __last, __pred, __identity()); } _LIBCPP_END_NAMESPACE_STD +_LIBCPP_POP_MACROS + #endif // _LIBCPP___ALGORITHM_FIND_IF_NOT_H diff --git a/lib/libcxx/include/__algorithm/find_segment_if.h b/lib/libcxx/include/__algorithm/find_segment_if.h index 9d6064f3e283a6953c03a983baa4ce467a7f1337..558f8a108f3a9eeccb044624e802349c51f8a9b2 100644 --- a/lib/libcxx/include/__algorithm/find_segment_if.h +++ b/lib/libcxx/include/__algorithm/find_segment_if.h @@ -19,14 +19,13 @@ _LIBCPP_BEGIN_NAMESPACE_STD // __find_segment_if is a utility function for optimizing iteration over segmented iterators linearly. -// [__first, __last) has to be a segmented range. __pred is expected to take a range of local iterators and the __proj. +// [__first, __last) has to be a segmented range. __pred is expected to take a range of local iterators. // It returns an iterator to the first element that satisfies the predicate, or a one-past-the-end iterator if there was -// no match. __proj may be anything that should be passed to __pred, but is expected to be a projection to support -// ranges algorithms, or __identity for classic algorithms. +// no match. -template +template _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _SegmentedIterator -__find_segment_if(_SegmentedIterator __first, _SegmentedIterator __last, _Pred __pred, _Proj& __proj) { +__find_segment_if(_SegmentedIterator __first, _SegmentedIterator __last, _Pred __pred) { using _Traits = __segmented_iterator_traits<_SegmentedIterator>; auto __sfirst = _Traits::__segment(__first); @@ -34,11 +33,11 @@ __find_segment_if(_SegmentedIterator __first, _SegmentedIterator __last, _Pred _ // We are in a single segment, so we might not be at the beginning or end if (__sfirst == __slast) - return _Traits::__compose(__sfirst, __pred(_Traits::__local(__first), _Traits::__local(__last), __proj)); + return _Traits::__compose(__sfirst, __pred(_Traits::__local(__first), _Traits::__local(__last))); { // We have more than one segment. Iterate over the first segment, since we might not start at the beginning auto __llast = _Traits::__end(__sfirst); - auto __liter = __pred(_Traits::__local(__first), __llast, __proj); + auto __liter = __pred(_Traits::__local(__first), __llast); if (__liter != __llast) return _Traits::__compose(__sfirst, __liter); } @@ -47,14 +46,14 @@ __find_segment_if(_SegmentedIterator __first, _SegmentedIterator __last, _Pred _ // Iterate over the segments which are guaranteed to be completely in the range while (__sfirst != __slast) { auto __llast = _Traits::__end(__sfirst); - auto __liter = __pred(_Traits::__begin(__sfirst), _Traits::__end(__sfirst), __proj); + auto __liter = __pred(_Traits::__begin(__sfirst), _Traits::__end(__sfirst)); if (__liter != __llast) return _Traits::__compose(__sfirst, __liter); ++__sfirst; } // Iterate over the last segment - return _Traits::__compose(__sfirst, __pred(_Traits::__begin(__sfirst), _Traits::__local(__last), __proj)); + return _Traits::__compose(__sfirst, __pred(_Traits::__begin(__sfirst), _Traits::__local(__last))); } _LIBCPP_END_NAMESPACE_STD diff --git a/lib/libcxx/include/__algorithm/for_each.h b/lib/libcxx/include/__algorithm/for_each.h index 85fedce3d936d9fb5db35190cb42a03ba3863dd5..bb656a2db0188a8f1f677ab99cc7f81cbe5af6fc 100644 --- a/lib/libcxx/include/__algorithm/for_each.h +++ b/lib/libcxx/include/__algorithm/for_each.h @@ -26,7 +26,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD template _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _InputIterator -__for_each(_InputIterator __first, _Sent __last, _Func& __func, _Proj& __proj) { +__for_each(_InputIterator __first, _Sent __last, _Func&& __func, _Proj& __proj) { #ifndef _LIBCPP_CXX03_LANG if constexpr (using _SpecialAlg = __specialized_algorithm<_Algorithm::__for_each, __iterator_pair<_InputIterator, _Sent>>; diff --git a/lib/libcxx/include/__algorithm/for_each_n.h b/lib/libcxx/include/__algorithm/for_each_n.h index 72c7adb093f95c96c8c0b068cb2c80aa380d5fa3..7ff3f9b157c0267367a8d59963156e51ea7cd0ca 100644 --- a/lib/libcxx/include/__algorithm/for_each_n.h +++ b/lib/libcxx/include/__algorithm/for_each_n.h @@ -18,6 +18,7 @@ #include <__iterator/segmented_iterator.h> #include <__type_traits/invoke.h> #include <__utility/convert_to_integral.h> +#include <__utility/forward.h> #include <__utility/move.h> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) @@ -31,7 +32,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD template _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _InputIterator -__for_each_n(_InputIterator __first, _Size __orig_n, _Func& __f, _Proj& __proj) { +__for_each_n(_InputIterator __first, _Size __orig_n, _Func&& __f, _Proj& __proj) { typedef decltype(std::__convert_to_integral(__orig_n)) _IntegralSize; _IntegralSize __n = __orig_n; @@ -43,7 +44,7 @@ __for_each_n(_InputIterator __first, _Size __orig_n, _Func& __f, _Proj& __proj) std::__for_each(__lfirst, __llast, __f, __proj); }); } else { - return std::__for_each(__first, __first + __n, __f, __proj); + return std::__for_each(__first, __first + __n, std::forward<_Func>(__f), __proj); } } else #endif diff --git a/lib/libcxx/include/__algorithm/generate_n.h b/lib/libcxx/include/__algorithm/generate_n.h index 23899e49e0b65677a2503e93b3b6b00031e761ac..ba04eb62e3c3a4450ae518c181984b3481be638b 100644 --- a/lib/libcxx/include/__algorithm/generate_n.h +++ b/lib/libcxx/include/__algorithm/generate_n.h @@ -29,8 +29,11 @@ inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator __generate_n(_OutputIterator __first, _Size __orig_n, _Generator& __gen) { using __iter_ref = decltype(*__first); __identity __proj; - auto __f = [&](__iter_ref __element) { std::forward<__iter_ref>(__element) = __gen(); }; - return std::__for_each_n(std::move(__first), __orig_n, __f, __proj); + return std::__for_each_n( + std::move(__first), + __orig_n, + [&](__iter_ref __element) { std::forward<__iter_ref>(__element) = __gen(); }, + __proj); } template diff --git a/lib/libcxx/include/__algorithm/in_out_result.h b/lib/libcxx/include/__algorithm/in_out_result.h index a7a986cf8e6c097112f8dc4a7d3063faee90ba6d..2616bb89d1e2186b3d034c178089dd79f3ad5035 100644 --- a/lib/libcxx/include/__algorithm/in_out_result.h +++ b/lib/libcxx/include/__algorithm/in_out_result.h @@ -49,6 +49,20 @@ struct in_out_result { #endif // _LIBCPP_STD_VER >= 20 +template +struct __in_out_result { + _InIter __in_; + _OutIter __out_; + +#if _LIBCPP_STD_VER >= 20 + template + requires convertible_to<_InIter, _InIter2> && convertible_to<_OutIter, _OutIter2> + constexpr operator ranges::in_out_result<_InIter2, _OutIter2>() && { + return {std::move(__in_), std::move(__out_)}; + } +#endif +}; + _LIBCPP_END_NAMESPACE_STD _LIBCPP_POP_MACROS diff --git a/lib/libcxx/include/__algorithm/lexicographical_compare_three_way.h b/lib/libcxx/include/__algorithm/lexicographical_compare_three_way.h index 442223e79e4ecaf3562619e4cb486c4d0581afb0..5be95c4d51347155ca6151815584d1266750e8ea 100644 --- a/lib/libcxx/include/__algorithm/lexicographical_compare_three_way.h +++ b/lib/libcxx/include/__algorithm/lexicographical_compare_three_way.h @@ -27,10 +27,10 @@ _LIBCPP_PUSH_MACROS #include <__undef_macros> -_LIBCPP_BEGIN_NAMESPACE_STD - #if _LIBCPP_STD_VER >= 20 +_LIBCPP_BEGIN_NAMESPACE_STD + // Fast path for random access iterators which computes the number of loop iterations up-front and // then skips the iterator comparisons inside the loop. template @@ -116,10 +116,10 @@ template std::move(__first1), std::move(__last1), std::move(__first2), std::move(__last2), std::compare_three_way()); } -#endif // _LIBCPP_STD_VER >= 20 - _LIBCPP_END_NAMESPACE_STD +#endif // _LIBCPP_STD_VER >= 20 + _LIBCPP_POP_MACROS #endif // _LIBCPP___ALGORITHM_LEXICOGRAPHICAL_COMPARE_THREE_WAY_H diff --git a/lib/libcxx/include/__algorithm/lower_bound.h b/lib/libcxx/include/__algorithm/lower_bound.h index 4fba6748e6d7121bc1c7c9e389a12e66c61b2705..aa1d4c47444520c907c8a0d21563e26f7955f018 100644 --- a/lib/libcxx/include/__algorithm/lower_bound.h +++ b/lib/libcxx/include/__algorithm/lower_bound.h @@ -56,11 +56,11 @@ template // would yield \Omega(n*log(n)) comparisons and, for non-random-access iterators, \Omega(n^2) iterator increments, // whereas the one-sided version will yield O(n) operations on both counts, with a \Omega(log(n)) bound on the number of // comparisons. -template +template [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator -__lower_bound_onesided(_ForwardIterator __first, _Sent __last, const _Type& __value, _Comp& __comp, _Proj& __proj) { +__lower_bound_onesided(_ForwardIterator __first, _Sent __last, const _Type& __value, _Comp& __comp) { // step = 0, ensuring we can always short-circuit when distance is 1 later on - if (__first == __last || !std::__invoke(__comp, std::__invoke(__proj, *__first), __value)) + if (__first == __last || !std::__invoke(__comp, *__first, __value)) return __first; using _Distance = typename iterator_traits<_ForwardIterator>::difference_type; @@ -69,11 +69,12 @@ __lower_bound_onesided(_ForwardIterator __first, _Sent __last, const _Type& __va auto __dist = __step - _IterOps<_AlgPolicy>::__advance_to(__it, __step, __last); // once we reach the last range where needle can be we must start // looking inwards, bisecting that range - if (__it == __last || !std::__invoke(__comp, std::__invoke(__proj, *__it), __value)) { + if (__it == __last || !std::__invoke(__comp, *__it, __value)) { // we've already checked the previous value and it was less, we can save // one comparison by skipping bisection if (__dist == 1) return __it; + __identity __proj; return std::__lower_bound_bisecting<_AlgPolicy>(__first, __value, __dist, __comp, __proj); } // range not found, move forward! diff --git a/lib/libcxx/include/__algorithm/move.h b/lib/libcxx/include/__algorithm/move.h index ddadfa778fc241f9dc67a79777070a131e35eeff..a41be89578e46f1e20b8bb1d5431ecef0b4cd50e 100644 --- a/lib/libcxx/include/__algorithm/move.h +++ b/lib/libcxx/include/__algorithm/move.h @@ -12,6 +12,7 @@ #include <__algorithm/copy.h> #include <__algorithm/copy_move_common.h> #include <__algorithm/for_each_segment.h> +#include <__algorithm/in_out_result.h> #include <__algorithm/iterator_operations.h> #include <__algorithm/min.h> #include <__config> @@ -22,7 +23,6 @@ #include <__type_traits/enable_if.h> #include <__type_traits/is_constructible.h> #include <__utility/move.h> -#include <__utility/pair.h> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header @@ -34,30 +34,30 @@ _LIBCPP_PUSH_MACROS _LIBCPP_BEGIN_NAMESPACE_STD template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_InIter, _OutIter> +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 __in_out_result<_InIter, _OutIter> __move(_InIter __first, _Sent __last, _OutIter __result); template struct __move_impl { template - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_InIter, _OutIter> + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 __in_out_result<_InIter, _OutIter> operator()(_InIter __first, _Sent __last, _OutIter __result) const { while (__first != __last) { *__result = _IterOps<_AlgPolicy>::__iter_move(__first); ++__first; ++__result; } - return std::make_pair(std::move(__first), std::move(__result)); + return {std::move(__first), std::move(__result)}; } template , int> = 0> - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_InIter, _OutIter> + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 __in_out_result<_InIter, _OutIter> operator()(_InIter __first, _InIter __last, _OutIter __result) const { using __local_iterator = typename __segmented_iterator_traits<_InIter>::__local_iterator; std::__for_each_segment(__first, __last, [&__result](__local_iterator __lfirst, __local_iterator __llast) { - __result = std::__move<_AlgPolicy>(__lfirst, __llast, std::move(__result)).second; + __result = std::__move<_AlgPolicy>(__lfirst, __llast, std::move(__result)).__out_; }); - return std::make_pair(__last, std::move(__result)); + return {__last, std::move(__result)}; } template ::value && !__is_segmented_iterator_v<_InIter> && __is_segmented_iterator_v<_OutIter>, int> = 0> - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_InIter, _OutIter> + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 __in_out_result<_InIter, _OutIter> operator()(_InIter __first, _InIter __last, _OutIter __result) const { using _Traits = __segmented_iterator_traits<_OutIter>; using _DiffT = typename common_type<__iterator_difference_type<_InIter>, __iterator_difference_type<_OutIter> >::type; if (__first == __last) - return std::make_pair(std::move(__first), std::move(__result)); + return {std::move(__first), std::move(__result)}; auto __local_first = _Traits::__local(__result); auto __segment_iterator = _Traits::__segment(__result); @@ -80,17 +80,18 @@ struct __move_impl { auto __local_last = _Traits::__end(__segment_iterator); auto __size = std::min<_DiffT>(__local_last - __local_first, __last - __first); auto __iters = std::__move<_AlgPolicy>(__first, __first + __size, __local_first); - __first = std::move(__iters.first); + __first = std::move(__iters.__in_); if (__first == __last) - return std::make_pair(std::move(__first), _Traits::__compose(__segment_iterator, std::move(__iters.second))); + return {std::move(__first), _Traits::__compose(__segment_iterator, std::move(__iters.__out_))}; __local_first = _Traits::__begin(++__segment_iterator); } } template - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<__bit_iterator<_Cp, _IsConst>, __bit_iterator<_Cp, false> > + _LIBCPP_HIDE_FROM_ABI + _LIBCPP_CONSTEXPR_SINCE_CXX20 __in_out_result<__bit_iterator<_Cp, _IsConst>, __bit_iterator<_Cp, false> > operator()(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, __bit_iterator<_Cp, false> __result) { @@ -99,14 +100,14 @@ struct __move_impl { // At this point, the iterators have been unwrapped so any `contiguous_iterator` has been unwrapped to a pointer. template ::value, int> = 0> - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_In*, _Out*> + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 __in_out_result<_In*, _Out*> operator()(_In* __first, _In* __last, _Out* __result) const { return std::__copy_trivial_impl(__first, __last, __result); } }; template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_InIter, _OutIter> +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 __in_out_result<_InIter, _OutIter> __move(_InIter __first, _Sent __last, _OutIter __result) { return std::__copy_move_unwrap_iters<__move_impl<_AlgPolicy> >( std::move(__first), std::move(__last), std::move(__result)); @@ -118,7 +119,7 @@ move(_InputIterator __first, _InputIterator __last, _OutputIterator __result) { static_assert(is_copy_constructible<_InputIterator>::value, "Iterators has to be copy constructible."); static_assert(is_copy_constructible<_OutputIterator>::value, "The output iterator has to be copy constructible."); - return std::__move<_ClassicAlgPolicy>(std::move(__first), std::move(__last), std::move(__result)).second; + return std::__move<_ClassicAlgPolicy>(std::move(__first), std::move(__last), std::move(__result)).__out_; } _LIBCPP_END_NAMESPACE_STD diff --git a/lib/libcxx/include/__algorithm/move_backward.h b/lib/libcxx/include/__algorithm/move_backward.h index 43b72057a5eca53f81c21cd4f5af741f49ae82eb..d243bc5cd3b8e591b8c6c01aff01160b51321cdf 100644 --- a/lib/libcxx/include/__algorithm/move_backward.h +++ b/lib/libcxx/include/__algorithm/move_backward.h @@ -12,6 +12,7 @@ #include <__algorithm/copy_backward.h> #include <__algorithm/copy_move_common.h> #include <__algorithm/for_each_segment.h> +#include <__algorithm/in_out_result.h> #include <__algorithm/iterator_operations.h> #include <__algorithm/min.h> #include <__config> @@ -34,13 +35,13 @@ _LIBCPP_PUSH_MACROS _LIBCPP_BEGIN_NAMESPACE_STD template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_BidirectionalIterator1, _BidirectionalIterator2> +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __in_out_result<_BidirectionalIterator1, _BidirectionalIterator2> __move_backward(_BidirectionalIterator1 __first, _Sentinel __last, _BidirectionalIterator2 __result); template struct __move_backward_impl { template - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_InIter, _OutIter> + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 __in_out_result<_InIter, _OutIter> operator()(_InIter __first, _Sent __last, _OutIter __result) const { auto __last_iter = _IterOps<_AlgPolicy>::next(__first, __last); auto __original_last_iter = __last_iter; @@ -49,17 +50,17 @@ struct __move_backward_impl { *--__result = _IterOps<_AlgPolicy>::__iter_move(--__last_iter); } - return std::make_pair(std::move(__original_last_iter), std::move(__result)); + return {std::move(__original_last_iter), std::move(__result)}; } template , int> = 0> - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_InIter, _OutIter> + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 __in_out_result<_InIter, _OutIter> operator()(_InIter __first, _InIter __last, _OutIter __result) const { using __local_iterator = typename __segmented_iterator_traits<_InIter>::__local_iterator; std::__for_each_segment_backward(__first, __last, [&__result](__local_iterator __lfirst, __local_iterator __llast) { - __result = std::__move_backward<_AlgPolicy>(std::move(__lfirst), std::move(__llast), std::move(__result)).second; + __result = std::__move_backward<_AlgPolicy>(std::move(__lfirst), std::move(__llast), std::move(__result)).__out_; }); - return std::make_pair(__last, std::move(__result)); + return {__last, std::move(__result)}; } template ::value && !__is_segmented_iterator_v<_InIter> && __is_segmented_iterator_v<_OutIter>, int> = 0> - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_InIter, _OutIter> + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 __in_out_result<_InIter, _OutIter> operator()(_InIter __first, _InIter __last, _OutIter __result) const { using _Traits = __segmented_iterator_traits<_OutIter>; using _DiffT = @@ -75,7 +76,7 @@ struct __move_backward_impl { // When the range contains no elements, __result might not be a valid iterator if (__first == __last) - return std::make_pair(__first, __result); + return {__first, __result}; auto __orig_last = __last; @@ -84,18 +85,19 @@ struct __move_backward_impl { while (true) { auto __local_first = _Traits::__begin(__segment_iterator); auto __size = std::min<_DiffT>(__local_last - __local_first, __last - __first); - auto __iter = std::__move_backward<_AlgPolicy>(__last - __size, __last, __local_last).second; + auto __iter = std::__move_backward<_AlgPolicy>(__last - __size, __last, __local_last).__out_; __last -= __size; if (__first == __last) - return std::make_pair(std::move(__orig_last), _Traits::__compose(__segment_iterator, std::move(__iter))); + return {std::move(__orig_last), _Traits::__compose(__segment_iterator, std::move(__iter))}; __local_last = _Traits::__end(--__segment_iterator); } } template - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<__bit_iterator<_Cp, _IsConst>, __bit_iterator<_Cp, false> > + _LIBCPP_HIDE_FROM_ABI + _LIBCPP_CONSTEXPR_SINCE_CXX20 __in_out_result<__bit_iterator<_Cp, _IsConst>, __bit_iterator<_Cp, false> > operator()(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, __bit_iterator<_Cp, false> __result) { @@ -104,14 +106,14 @@ struct __move_backward_impl { // At this point, the iterators have been unwrapped so any `contiguous_iterator` has been unwrapped to a pointer. template ::value, int> = 0> - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_In*, _Out*> + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 __in_out_result<_In*, _Out*> operator()(_In* __first, _In* __last, _Out* __result) const { return std::__copy_backward_trivial_impl(__first, __last, __result); } }; template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_BidirectionalIterator1, _BidirectionalIterator2> +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __in_out_result<_BidirectionalIterator1, _BidirectionalIterator2> __move_backward(_BidirectionalIterator1 __first, _Sentinel __last, _BidirectionalIterator2 __result) { static_assert(std::is_copy_constructible<_BidirectionalIterator1>::value && std::is_copy_constructible<_BidirectionalIterator1>::value, @@ -124,7 +126,7 @@ __move_backward(_BidirectionalIterator1 __first, _Sentinel __last, _Bidirectiona template inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _BidirectionalIterator2 move_backward(_BidirectionalIterator1 __first, _BidirectionalIterator1 __last, _BidirectionalIterator2 __result) { - return std::__move_backward<_ClassicAlgPolicy>(std::move(__first), std::move(__last), std::move(__result)).second; + return std::__move_backward<_ClassicAlgPolicy>(std::move(__first), std::move(__last), std::move(__result)).__out_; } _LIBCPP_END_NAMESPACE_STD diff --git a/lib/libcxx/include/__algorithm/out_value_result.h b/lib/libcxx/include/__algorithm/out_value_result.h index 9e1e0e07286d46f1ba9623dd2db667428787a2b9..398328b042069741b2bc1ccede8415c0c42b1cd5 100644 --- a/lib/libcxx/include/__algorithm/out_value_result.h +++ b/lib/libcxx/include/__algorithm/out_value_result.h @@ -21,10 +21,10 @@ _LIBCPP_PUSH_MACROS #include <__undef_macros> -_LIBCPP_BEGIN_NAMESPACE_STD - #if _LIBCPP_STD_VER >= 23 +_LIBCPP_BEGIN_NAMESPACE_STD + namespace ranges { template @@ -47,10 +47,10 @@ struct out_value_result { } // namespace ranges -#endif // _LIBCPP_STD_VER >= 23 - _LIBCPP_END_NAMESPACE_STD +#endif // _LIBCPP_STD_VER >= 23 + _LIBCPP_POP_MACROS #endif // _LIBCPP___ALGORITHM_OUT_VALUE_RESULT_H diff --git a/lib/libcxx/include/__algorithm/partial_sort_copy.h b/lib/libcxx/include/__algorithm/partial_sort_copy.h index 2230dfc9cc4adeb30a5972835c7ae81ccd99c2bd..ad17eec5260f7c2c8fce7433e2f75cc03ca87b46 100644 --- a/lib/libcxx/include/__algorithm/partial_sort_copy.h +++ b/lib/libcxx/include/__algorithm/partial_sort_copy.h @@ -11,6 +11,7 @@ #include <__algorithm/comp.h> #include <__algorithm/comp_ref_type.h> +#include <__algorithm/in_out_result.h> #include <__algorithm/iterator_operations.h> #include <__algorithm/make_heap.h> #include <__algorithm/make_projected.h> @@ -41,7 +42,8 @@ template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_InputIterator, _RandomAccessIterator> __partial_sort_copy( +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __in_out_result<_InputIterator, _RandomAccessIterator> +__partial_sort_copy( _InputIterator __first, _Sentinel1 __last, _RandomAccessIterator __result_first, @@ -65,8 +67,7 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_InputIterator, _Random std::__sort_heap<_AlgPolicy>(__result_first, __r, __projected_comp); } - return pair<_InputIterator, _RandomAccessIterator>( - _IterOps<_AlgPolicy>::next(std::move(__first), std::move(__last)), std::move(__r)); + return {_IterOps<_AlgPolicy>::next(std::move(__first), std::move(__last)), std::move(__r)}; } template @@ -87,7 +88,7 @@ inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _RandomAccessIterator static_cast<__comp_ref_type<_Compare> >(__comp), __identity(), __identity()); - return __result.second; + return __result.__out_; } template diff --git a/lib/libcxx/include/__algorithm/pstl.h b/lib/libcxx/include/__algorithm/pstl.h index 7169dd85df6027c19dbda47274a5c5245b007435..2bf9b4276baab6f5f21cd89f9008a2be4bfeaf85 100644 --- a/lib/libcxx/include/__algorithm/pstl.h +++ b/lib/libcxx/include/__algorithm/pstl.h @@ -293,6 +293,54 @@ find(_ExecutionPolicy&& __policy, _ForwardIterator __first, _ForwardIterator __l std::forward<_ExecutionPolicy>(__policy), std::move(__first), std::move(__last), __value); } +template , + enable_if_t, int> = 0> +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI _ForwardIterator1 find_first_of( + _ExecutionPolicy&& __policy, + _ForwardIterator1 __first1, + _ForwardIterator1 __last1, + _ForwardIterator2 __first2, + _ForwardIterator2 __last2) { + _LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator1, "find_first_of requires ForwardIterators"); + _LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator2, "find_first_of requires ForwardIterators"); + using _Implementation = __pstl::__dispatch<__pstl::__find_first_of, __pstl::__current_configuration, _RawPolicy>; + return __pstl::__handle_exception<_Implementation>( + std::forward<_ExecutionPolicy>(__policy), + std::move(__first1), + std::move(__last1), + std::move(__first2), + std::move(__last2), + std::equal_to<>{}); +} + +template , + enable_if_t, int> = 0> +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI _ForwardIterator1 find_first_of( + _ExecutionPolicy&& __policy, + _ForwardIterator1 __first1, + _ForwardIterator1 __last1, + _ForwardIterator2 __first2, + _ForwardIterator2 __last2, + _BinaryPredicate __pred) { + _LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator1, "find_first_of requires ForwardIterators"); + _LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator2, "find_first_of requires ForwardIterators"); + using _Implementation = __pstl::__dispatch<__pstl::__find_first_of, __pstl::__current_configuration, _RawPolicy>; + return __pstl::__handle_exception<_Implementation>( + std::forward<_ExecutionPolicy>(__policy), + std::move(__first1), + std::move(__last1), + std::move(__first2), + std::move(__last2), + std::move(__pred)); +} + template (__policy), std::move(__first), std::move(__n), std::move(__gen)); } +template , + enable_if_t, int> = 0> +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI _ForwardIterator reverse_copy( + _ExecutionPolicy&& __policy, + _BidirectionalIterator __first, + _BidirectionalIterator __last, + _ForwardIterator __result) { + _LIBCPP_REQUIRE_CPP17_BIDIRECTIONAL_ITERATOR(_BidirectionalIterator, "reverse_copy requires a BidirectionalIterator"); + _LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator, "reverse_copy requires a ForwardIterator"); + using _Implementation = __pstl::__dispatch<__pstl::__reverse_copy, __pstl::__current_configuration, _RawPolicy>; + return __pstl::__handle_exception<_Implementation>( + std::forward<_ExecutionPolicy>(__policy), std::move(__first), std::move(__last), std::move(__result)); +} + template , + enable_if_t, int> = 0> +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI bool +is_sorted(_ExecutionPolicy&& __policy, _ForwardIterator __first, _ForwardIterator __last) { + _LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator, "is_sorted requires ForwardIterators"); + using _Implementation = __pstl::__dispatch<__pstl::__is_sorted, __pstl::__current_configuration, _RawPolicy>; + return __pstl::__handle_exception<_Implementation>( + std::forward<_ExecutionPolicy>(__policy), std::move(__first), std::move(__last), less{}); +} + +template , + enable_if_t, int> = 0> +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI bool +is_sorted(_ExecutionPolicy&& __policy, _ForwardIterator __first, _ForwardIterator __last, _Comp __comp) { + _LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator, "is_sorted requires ForwardIterators"); + using _Implementation = __pstl::__dispatch<__pstl::__is_sorted, __pstl::__current_configuration, _RawPolicy>; + return __pstl::__handle_exception<_Implementation>( + std::forward<_ExecutionPolicy>(__policy), std::move(__first), std::move(__last), std::move(__comp)); +} + _LIBCPP_END_NAMESPACE_STD #endif // _LIBCPP_HAS_EXPERIMENTAL_PSTL && _LIBCPP_STD_VER >= 17 diff --git a/lib/libcxx/include/__algorithm/radix_sort.h b/lib/libcxx/include/__algorithm/radix_sort.h index 5549a69f5e2209768d9b1bc709cf6bff55ff4d99..4f685ea162d55d2f9d84ad968d76045f7af0201c 100644 --- a/lib/libcxx/include/__algorithm/radix_sort.h +++ b/lib/libcxx/include/__algorithm/radix_sort.h @@ -67,10 +67,10 @@ _LIBCPP_PUSH_MACROS #include <__undef_macros> -_LIBCPP_BEGIN_NAMESPACE_STD - #if _LIBCPP_STD_VER >= 14 +_LIBCPP_BEGIN_NAMESPACE_STD + template _LIBCPP_HIDE_FROM_ABI constexpr pair<_OutputIterator, __iterator_value_type<_InputIterator>> __partial_sum_max(_InputIterator __first, _InputIterator __last, _OutputIterator __result) { @@ -422,10 +422,10 @@ __radix_sort(_RandomAccessIterator1 __first, _RandomAccessIterator1 __last, _Ran std::__radix_sort(__first, __last, __buffer, __identity{}, __low_byte_fn{}); } -#endif // _LIBCPP_STD_VER >= 14 - _LIBCPP_END_NAMESPACE_STD +#endif // _LIBCPP_STD_VER >= 14 + _LIBCPP_POP_MACROS #endif // _LIBCPP___ALGORITHM_RADIX_SORT_H diff --git a/lib/libcxx/include/__algorithm/ranges_copy.h b/lib/libcxx/include/__algorithm/ranges_copy.h index a69af9b2bffc3182d8244eaebc0f20ae1250f775..00017f46465fd49f5a235fd409e00cc802ecde1f 100644 --- a/lib/libcxx/include/__algorithm/ranges_copy.h +++ b/lib/libcxx/include/__algorithm/ranges_copy.h @@ -41,16 +41,14 @@ struct __copy { requires indirectly_copyable<_InIter, _OutIter> _LIBCPP_HIDE_FROM_ABI constexpr copy_result<_InIter, _OutIter> operator()(_InIter __first, _Sent __last, _OutIter __result) const { - auto __ret = std::__copy(std::move(__first), std::move(__last), std::move(__result)); - return {std::move(__ret.first), std::move(__ret.second)}; + return std::__copy(std::move(__first), std::move(__last), std::move(__result)); } template requires indirectly_copyable, _OutIter> _LIBCPP_HIDE_FROM_ABI constexpr copy_result, _OutIter> operator()(_Range&& __r, _OutIter __result) const { - auto __ret = std::__copy(ranges::begin(__r), ranges::end(__r), std::move(__result)); - return {std::move(__ret.first), std::move(__ret.second)}; + return std::__copy(ranges::begin(__r), ranges::end(__r), std::move(__result)); } }; diff --git a/lib/libcxx/include/__algorithm/ranges_copy_backward.h b/lib/libcxx/include/__algorithm/ranges_copy_backward.h index 81d14e465f7f258b5ab6b015a490cd8a66a35380..ff4e7c241e1e89613ba07c22d587124db5b031a4 100644 --- a/lib/libcxx/include/__algorithm/ranges_copy_backward.h +++ b/lib/libcxx/include/__algorithm/ranges_copy_backward.h @@ -40,16 +40,14 @@ struct __copy_backward { requires indirectly_copyable<_InIter1, _InIter2> _LIBCPP_HIDE_FROM_ABI constexpr copy_backward_result<_InIter1, _InIter2> operator()(_InIter1 __first, _Sent1 __last, _InIter2 __result) const { - auto __ret = std::__copy_backward<_RangeAlgPolicy>(std::move(__first), std::move(__last), std::move(__result)); - return {std::move(__ret.first), std::move(__ret.second)}; + return std::__copy_backward<_RangeAlgPolicy>(std::move(__first), std::move(__last), std::move(__result)); } template requires indirectly_copyable, _Iter> _LIBCPP_HIDE_FROM_ABI constexpr copy_backward_result, _Iter> operator()(_Range&& __r, _Iter __result) const { - auto __ret = std::__copy_backward<_RangeAlgPolicy>(ranges::begin(__r), ranges::end(__r), std::move(__result)); - return {std::move(__ret.first), std::move(__ret.second)}; + return std::__copy_backward<_RangeAlgPolicy>(ranges::begin(__r), ranges::end(__r), std::move(__result)); } }; diff --git a/lib/libcxx/include/__algorithm/ranges_copy_if.h b/lib/libcxx/include/__algorithm/ranges_copy_if.h index acf74b669d481c19fe50964fbbf67ce5709bdc9b..e3669d1ffcc0c15ffd1c7489f9556d4a05688398 100644 --- a/lib/libcxx/include/__algorithm/ranges_copy_if.h +++ b/lib/libcxx/include/__algorithm/ranges_copy_if.h @@ -46,8 +46,7 @@ struct __copy_if { requires indirectly_copyable<_Iter, _OutIter> _LIBCPP_HIDE_FROM_ABI constexpr copy_if_result<_Iter, _OutIter> operator()(_Iter __first, _Sent __last, _OutIter __result, _Pred __pred, _Proj __proj = {}) const { - auto __res = std::__copy_if(std::move(__first), std::move(__last), std::move(__result), __pred, __proj); - return {std::move(__res.first), std::move(__res.second)}; + return std::__copy_if(std::move(__first), std::move(__last), std::move(__result), __pred, __proj); } template , _OutIter> _LIBCPP_HIDE_FROM_ABI constexpr copy_if_result, _OutIter> operator()(_Range&& __r, _OutIter __result, _Pred __pred, _Proj __proj = {}) const { - auto __res = std::__copy_if(ranges::begin(__r), ranges::end(__r), std::move(__result), __pred, __proj); - return {std::move(__res.first), std::move(__res.second)}; + return std::__copy_if(ranges::begin(__r), ranges::end(__r), std::move(__result), __pred, __proj); } }; diff --git a/lib/libcxx/include/__algorithm/ranges_copy_n.h b/lib/libcxx/include/__algorithm/ranges_copy_n.h index 6bee4c3e7c9e555332f600bb487d48700a25963e..1720ac358fa4d023c96746539d292413db1c3ddd 100644 --- a/lib/libcxx/include/__algorithm/ranges_copy_n.h +++ b/lib/libcxx/include/__algorithm/ranges_copy_n.h @@ -24,10 +24,10 @@ _LIBCPP_PUSH_MACROS #include <__undef_macros> -_LIBCPP_BEGIN_NAMESPACE_STD - #if _LIBCPP_STD_VER >= 20 +_LIBCPP_BEGIN_NAMESPACE_STD + namespace ranges { template @@ -38,8 +38,7 @@ struct __copy_n { requires indirectly_copyable<_Ip, _Op> _LIBCPP_HIDE_FROM_ABI constexpr copy_n_result<_Ip, _Op> operator()(_Ip __first, iter_difference_t<_Ip> __n, _Op __result) const { - auto __res = std::__copy_n<_RangeAlgPolicy>(std::move(__first), __n, std::move(__result)); - return {std::move(__res.first), std::move(__res.second)}; + return std::__copy_n<_RangeAlgPolicy>(std::move(__first), __n, std::move(__result)); } }; @@ -48,10 +47,10 @@ inline constexpr auto copy_n = __copy_n{}; } // namespace __cpo } // namespace ranges -#endif // _LIBCPP_STD_VER >= 20 - _LIBCPP_END_NAMESPACE_STD +#endif // _LIBCPP_STD_VER >= 20 + _LIBCPP_POP_MACROS #endif // _LIBCPP___ALGORITHM_RANGES_COPY_N_H diff --git a/lib/libcxx/include/__algorithm/ranges_equal.h b/lib/libcxx/include/__algorithm/ranges_equal.h index 8eb2fc1017f288e097bea46e0d7808198171384f..98f0baaabc29db4a629c10ca7c61e72c0da4fd89 100644 --- a/lib/libcxx/include/__algorithm/ranges_equal.h +++ b/lib/libcxx/include/__algorithm/ranges_equal.h @@ -50,7 +50,7 @@ struct __equal { _Pred __pred = {}, _Proj1 __proj1 = {}, _Proj2 __proj2 = {}) const { - static constexpr bool __both_sized = sized_sentinel_for<_Sent1, _Iter1> && sized_sentinel_for<_Sent2, _Iter2>; + constexpr bool __both_sized = sized_sentinel_for<_Sent1, _Iter1> && sized_sentinel_for<_Sent2, _Iter2>; if constexpr (__both_sized) { if (__last1 - __first1 != __last2 - __first2) return false; @@ -71,7 +71,7 @@ struct __equal { requires indirectly_comparable, iterator_t<_Range2>, _Pred, _Proj1, _Proj2> [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool operator()( _Range1&& __range1, _Range2&& __range2, _Pred __pred = {}, _Proj1 __proj1 = {}, _Proj2 __proj2 = {}) const { - static constexpr bool __both_sized = sized_range<_Range1> && sized_range<_Range2>; + constexpr bool __both_sized = sized_range<_Range1> && sized_range<_Range2>; if constexpr (__both_sized) { if (ranges::size(__range1) != ranges::size(__range2)) return false; diff --git a/lib/libcxx/include/__algorithm/ranges_find_if.h b/lib/libcxx/include/__algorithm/ranges_find_if.h index ed6406e6186a31f50654b0e124903b22c4282081..c72ade02516b34cdb376cf542697daab13b56af8 100644 --- a/lib/libcxx/include/__algorithm/ranges_find_if.h +++ b/lib/libcxx/include/__algorithm/ranges_find_if.h @@ -9,10 +9,10 @@ #ifndef _LIBCPP___ALGORITHM_RANGES_FIND_IF_H #define _LIBCPP___ALGORITHM_RANGES_FIND_IF_H +#include <__algorithm/find_if.h> #include <__config> #include <__functional/identity.h> #include <__functional/invoke.h> -#include <__functional/ranges_operations.h> #include <__iterator/concepts.h> #include <__iterator/projected.h> #include <__ranges/access.h> @@ -33,15 +33,6 @@ _LIBCPP_BEGIN_NAMESPACE_STD namespace ranges { -template -_LIBCPP_HIDE_FROM_ABI constexpr _Ip __find_if_impl(_Ip __first, _Sp __last, _Pred& __pred, _Proj& __proj) { - for (; __first != __last; ++__first) { - if (std::invoke(__pred, std::invoke(__proj, *__first))) - break; - } - return __first; -} - struct __find_if { template _Sp, @@ -49,13 +40,13 @@ struct __find_if { indirect_unary_predicate> _Pred> [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Ip operator()(_Ip __first, _Sp __last, _Pred __pred, _Proj __proj = {}) const { - return ranges::__find_if_impl(std::move(__first), std::move(__last), __pred, __proj); + return std::__find_if(std::move(__first), std::move(__last), __pred, __proj); } template , _Proj>> _Pred> [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr borrowed_iterator_t<_Rp> operator()(_Rp&& __r, _Pred __pred, _Proj __proj = {}) const { - return ranges::__find_if_impl(ranges::begin(__r), ranges::end(__r), __pred, __proj); + return std::__find_if(ranges::begin(__r), ranges::end(__r), __pred, __proj); } }; diff --git a/lib/libcxx/include/__algorithm/ranges_find_if_not.h b/lib/libcxx/include/__algorithm/ranges_find_if_not.h index 9a359b2afdab1bedd8e0f717459a1e54a5d9116f..ae0d64fdc77df04b49f3f134228fc7a2a8483f8b 100644 --- a/lib/libcxx/include/__algorithm/ranges_find_if_not.h +++ b/lib/libcxx/include/__algorithm/ranges_find_if_not.h @@ -9,17 +9,14 @@ #ifndef _LIBCPP___ALGORITHM_RANGES_FIND_IF_NOT_H #define _LIBCPP___ALGORITHM_RANGES_FIND_IF_NOT_H -#include <__algorithm/ranges_find_if.h> +#include <__algorithm/find_if_not.h> #include <__config> #include <__functional/identity.h> -#include <__functional/invoke.h> -#include <__functional/ranges_operations.h> #include <__iterator/concepts.h> #include <__iterator/projected.h> #include <__ranges/access.h> #include <__ranges/concepts.h> #include <__ranges/dangling.h> -#include <__utility/forward.h> #include <__utility/move.h> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) @@ -41,15 +38,13 @@ struct __find_if_not { indirect_unary_predicate> _Pred> [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Ip operator()(_Ip __first, _Sp __last, _Pred __pred, _Proj __proj = {}) const { - auto __pred2 = [&](auto&& __e) -> bool { return !std::invoke(__pred, std::forward(__e)); }; - return ranges::__find_if_impl(std::move(__first), std::move(__last), __pred2, __proj); + return std::__find_if_not(std::move(__first), std::move(__last), __pred, __proj); } template , _Proj>> _Pred> [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr borrowed_iterator_t<_Rp> operator()(_Rp&& __r, _Pred __pred, _Proj __proj = {}) const { - auto __pred2 = [&](auto&& __e) -> bool { return !std::invoke(__pred, std::forward(__e)); }; - return ranges::__find_if_impl(ranges::begin(__r), ranges::end(__r), __pred2, __proj); + return std::__find_if_not(ranges::begin(__r), ranges::end(__r), __pred, __proj); } }; diff --git a/lib/libcxx/include/__algorithm/ranges_fold.h b/lib/libcxx/include/__algorithm/ranges_fold.h index d2c3921398504413c78862b2e55796718cd031ba..87579b264296acb13311d04852a3bae7bd0f0b3e 100644 --- a/lib/libcxx/include/__algorithm/ranges_fold.h +++ b/lib/libcxx/include/__algorithm/ranges_fold.h @@ -10,17 +10,21 @@ #ifndef _LIBCPP___ALGORITHM_RANGES_FOLD_H #define _LIBCPP___ALGORITHM_RANGES_FOLD_H +#include <__algorithm/for_each.h> #include <__concepts/assignable.h> #include <__concepts/constructible.h> #include <__concepts/convertible_to.h> #include <__concepts/invocable.h> #include <__concepts/movable.h> #include <__config> +#include <__functional/identity.h> #include <__functional/invoke.h> #include <__functional/reference_wrapper.h> #include <__iterator/concepts.h> #include <__iterator/iterator_traits.h> #include <__iterator/next.h> +#include <__iterator/prev.h> +#include <__iterator/reverse_iterator.h> #include <__ranges/access.h> #include <__ranges/concepts.h> #include <__ranges/dangling.h> @@ -28,6 +32,7 @@ #include <__type_traits/invoke.h> #include <__utility/forward.h> #include <__utility/move.h> +#include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header @@ -62,6 +67,9 @@ struct in_value_result { template using fold_left_with_iter_result = in_value_result<_Ip, _Tp>; +template +using fold_left_first_with_iter_result = in_value_result<_Ip, _Tp>; + template > concept __indirectly_binary_left_foldable_impl = convertible_to<_Rp, _Up> && // @@ -77,6 +85,22 @@ concept __indirectly_binary_left_foldable = invocable<_Fp&, _Tp, iter_reference_t<_Ip>> && // __indirectly_binary_left_foldable_impl<_Fp, _Tp, _Ip, invoke_result_t<_Fp&, _Tp, iter_reference_t<_Ip>>>; +template +struct __flipped { + _Func __func; + + template + requires invocable<_Func&, _Up, _Tp> + invoke_result_t<_Func&, _Up, _Tp> operator()(_Tp&&, _Up&&); +}; + +template +concept __indirectly_binary_right_foldable = + __indirectly_binary_left_foldable_impl<__flipped<_Func>, + _Tp, + _Iter, + invoke_result_t<_Func&, _Tp, iter_reference_t<_Iter>>>; + struct __fold_left_with_iter { template _Sp, class _Tp, __indirectly_binary_left_foldable<_Tp, _Ip> _Fp> [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static constexpr auto operator()(_Ip __first, _Sp __last, _Tp __init, _Fp __f) { @@ -87,11 +111,17 @@ struct __fold_left_with_iter { } _Up __result = std::invoke(__f, std::move(__init), *__first); - for (++__first; __first != __last; ++__first) { - __result = std::invoke(__f, std::move(__result), *__first); - } + ++__first; + __identity __proj; + auto __end = std::__for_each( + std::move(__first), + std::move(__last), + [&](auto&& __element) { + __result = std::invoke(__f, std::move(__result), std::forward(__element)); + }, + __proj); - return fold_left_with_iter_result<_Ip, _Up>{std::move(__first), std::move(__result)}; + return fold_left_with_iter_result<_Ip, _Up>{std::move(__end), std::move(__result)}; } template > _Fp> @@ -118,6 +148,117 @@ struct __fold_left { }; inline constexpr auto fold_left = __fold_left(); + +struct __fold_left_first_with_iter { + template _Sent, + __indirectly_binary_left_foldable, _Iter> _Func> + requires constructible_from, iter_reference_t<_Iter>> + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static constexpr auto operator()(_Iter __first, _Sent __last, _Func __func) { + using _Up = decltype(fold_left(std::move(__first), __last, iter_value_t<_Iter>(*__first), __func)); + + if (__first == __last) + return fold_left_first_with_iter_result<_Iter, optional<_Up>>{std::move(__first), optional<_Up>()}; + + _Up __result(*__first); + ++__first; + __identity __proj; + auto __end = std::__for_each( + std::move(__first), + std::move(__last), + [&](auto&& __element) { + __result = std::invoke(__func, std::move(__result), std::forward(__element)); + }, + __proj); + + return fold_left_first_with_iter_result<_Iter, optional<_Up>>{std::move(__end), optional<_Up>(std::move(__result))}; + } + + template , iterator_t<_Range>> _Func> + requires constructible_from, range_reference_t<_Range>> + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static constexpr auto operator()(_Range&& __range, _Func __func) { + auto __result = operator()(ranges::begin(__range), ranges::end(__range), std::ref(__func)); + + using _Up = decltype(fold_left( + ranges::begin(__range), ranges::end(__range), range_value_t<_Range>(*ranges::begin(__range)), __func)); + return fold_left_first_with_iter_result, optional<_Up>>{ + std::move(__result.in), std::move(__result.value)}; + } +}; + +inline constexpr auto fold_left_first_with_iter = __fold_left_first_with_iter(); + +struct __fold_left_first { + template _Sent, + __indirectly_binary_left_foldable, _Iter> _Func> + requires constructible_from, iter_reference_t<_Iter>> + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static constexpr auto operator()(_Iter __first, _Sent __last, _Func __func) { + return fold_left_first_with_iter(std::move(__first), std::move(__last), std::ref(__func)).value; + } + + template , iterator_t<_Range>> _Func> + requires constructible_from, range_reference_t<_Range>> + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static constexpr auto operator()(_Range&& __range, _Func __func) { + return fold_left_first_with_iter(ranges::begin(__range), ranges::end(__range), std::ref(__func)).value; + } +}; + +inline constexpr auto fold_left_first = __fold_left_first(); + +struct __fold_right { + template _Sp, + class _Tp, + __indirectly_binary_right_foldable<_Tp, _Iter> _Func> + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static constexpr auto + operator()(_Iter __first, _Sp __last, _Tp __init, _Func __func) { + using _Up = decay_t, _Tp>>; + + if (__first == __last) + return _Up(std::move(__init)); + + _Iter __tail = ranges::next(__first, __last); + --__tail; + _Up __result = std::invoke(__func, *__tail, std::move(__init)); + std::for_each(std::make_reverse_iterator(__tail), std::make_reverse_iterator(__first), [&](auto&& __element) { + __result = std::invoke(__func, std::forward(__element), std::move(__result)); + }); + + return __result; + } + + template > _Func> + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static constexpr auto operator()(_Range&& __range, _Tp __init, _Func __func) { + return operator()(ranges::begin(__range), ranges::end(__range), std::move(__init), std::ref(__func)); + } +}; + +inline constexpr auto fold_right = __fold_right(); + +struct __fold_right_last { + template _Sp, + __indirectly_binary_right_foldable, _Iter> _Func> + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static constexpr auto operator()(_Iter __first, _Sp __last, _Func __func) { + using _Up = decltype(fold_right(__first, __last, iter_value_t<_Iter>(*__first), __func)); + + if (__first == __last) + return optional<_Up>(); + + _Iter __tail = ranges::prev(ranges::next(__first, __last)); + return optional<_Up>( + in_place, ranges::fold_right(std::move(__first), __tail, iter_value_t<_Iter>(*__tail), std::move(__func))); + } + + template , iterator_t<_Range>> _Func> + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static constexpr auto operator()(_Range&& __range, _Func __func) { + return operator()(ranges::begin(__range), ranges::end(__range), std::ref(__func)); + } +}; + +inline constexpr auto fold_right_last = __fold_right_last(); } // namespace ranges #endif // _LIBCPP_STD_VER >= 23 diff --git a/lib/libcxx/include/__algorithm/ranges_move.h b/lib/libcxx/include/__algorithm/ranges_move.h index 02bf7fd006190d4607c4297fd37a18f25838f4b8..e99e5ac7f8cdd8898de7134b39510e751920f181 100644 --- a/lib/libcxx/include/__algorithm/ranges_move.h +++ b/lib/libcxx/include/__algorithm/ranges_move.h @@ -36,25 +36,18 @@ template using move_result = in_out_result<_InIter, _OutIter>; struct __move { - template - _LIBCPP_HIDE_FROM_ABI constexpr static move_result<_InIter, _OutIter> - __move_impl(_InIter __first, _Sent __last, _OutIter __result) { - auto __ret = std::__move<_RangeAlgPolicy>(std::move(__first), std::move(__last), std::move(__result)); - return {std::move(__ret.first), std::move(__ret.second)}; - } - template _Sent, weakly_incrementable _OutIter> requires indirectly_movable<_InIter, _OutIter> _LIBCPP_HIDE_FROM_ABI constexpr move_result<_InIter, _OutIter> operator()(_InIter __first, _Sent __last, _OutIter __result) const { - return __move_impl(std::move(__first), std::move(__last), std::move(__result)); + return std::__move<_RangeAlgPolicy>(std::move(__first), std::move(__last), std::move(__result)); } template requires indirectly_movable, _OutIter> _LIBCPP_HIDE_FROM_ABI constexpr move_result, _OutIter> operator()(_Range&& __range, _OutIter __result) const { - return __move_impl(ranges::begin(__range), ranges::end(__range), std::move(__result)); + return std::__move<_RangeAlgPolicy>(ranges::begin(__range), ranges::end(__range), std::move(__result)); } }; diff --git a/lib/libcxx/include/__algorithm/ranges_move_backward.h b/lib/libcxx/include/__algorithm/ranges_move_backward.h index 4737e6c9756ded95dba1e80945e07560485c59db..a4b51d09a68b0128217cc5220343f3dca3fa4bfd 100644 --- a/lib/libcxx/include/__algorithm/ranges_move_backward.h +++ b/lib/libcxx/include/__algorithm/ranges_move_backward.h @@ -38,25 +38,18 @@ template using move_backward_result = in_out_result<_InIter, _OutIter>; struct __move_backward { - template - _LIBCPP_HIDE_FROM_ABI constexpr static move_backward_result<_InIter, _OutIter> - __move_backward_impl(_InIter __first, _Sent __last, _OutIter __result) { - auto __ret = std::__move_backward<_RangeAlgPolicy>(std::move(__first), std::move(__last), std::move(__result)); - return {std::move(__ret.first), std::move(__ret.second)}; - } - template _Sent, bidirectional_iterator _OutIter> requires indirectly_movable<_InIter, _OutIter> _LIBCPP_HIDE_FROM_ABI constexpr move_backward_result<_InIter, _OutIter> operator()(_InIter __first, _Sent __last, _OutIter __result) const { - return __move_backward_impl(std::move(__first), std::move(__last), std::move(__result)); + return std::__move_backward<_RangeAlgPolicy>(std::move(__first), std::move(__last), std::move(__result)); } template requires indirectly_movable, _Iter> _LIBCPP_HIDE_FROM_ABI constexpr move_backward_result, _Iter> operator()(_Range&& __range, _Iter __result) const { - return __move_backward_impl(ranges::begin(__range), ranges::end(__range), std::move(__result)); + return std::__move_backward<_RangeAlgPolicy>(ranges::begin(__range), ranges::end(__range), std::move(__result)); } }; diff --git a/lib/libcxx/include/__algorithm/ranges_partial_sort_copy.h b/lib/libcxx/include/__algorithm/ranges_partial_sort_copy.h index f221504a8cae0d967069ef0fb609e0b8bddb7d7b..afa1d15f2faeb36ba2b979acb8b512b409b75a9e 100644 --- a/lib/libcxx/include/__algorithm/ranges_partial_sort_copy.h +++ b/lib/libcxx/include/__algorithm/ranges_partial_sort_copy.h @@ -60,7 +60,7 @@ struct __partial_sort_copy { _Comp __comp = {}, _Proj1 __proj1 = {}, _Proj2 __proj2 = {}) const { - auto __result = std::__partial_sort_copy<_RangeAlgPolicy>( + return std::__partial_sort_copy<_RangeAlgPolicy>( std::move(__first), std::move(__last), std::move(__result_first), @@ -68,7 +68,6 @@ struct __partial_sort_copy { __comp, __proj1, __proj2); - return {std::move(__result.first), std::move(__result.second)}; } template , borrowed_iterator_t<_Range2>> operator()( _Range1&& __range, _Range2&& __result_range, _Comp __comp = {}, _Proj1 __proj1 = {}, _Proj2 __proj2 = {}) const { - auto __result = std::__partial_sort_copy<_RangeAlgPolicy>( + return std::__partial_sort_copy<_RangeAlgPolicy>( ranges::begin(__range), ranges::end(__range), ranges::begin(__result_range), @@ -92,7 +91,6 @@ struct __partial_sort_copy { __comp, __proj1, __proj2); - return {std::move(__result.first), std::move(__result.second)}; } }; diff --git a/lib/libcxx/include/__algorithm/ranges_remove_if.h b/lib/libcxx/include/__algorithm/ranges_remove_if.h index 384b3d41d080109263f1e40f3e1d870cfd45ece2..397959b888b0d95a9a57fb4e38aa65a90ebf8f67 100644 --- a/lib/libcxx/include/__algorithm/ranges_remove_if.h +++ b/lib/libcxx/include/__algorithm/ranges_remove_if.h @@ -10,10 +10,9 @@ #define _LIBCPP___ALGORITHM_RANGES_REMOVE_IF_H #include <__config> -#include <__algorithm/ranges_find_if.h> +#include <__algorithm/find_if.h> #include <__functional/identity.h> #include <__functional/invoke.h> -#include <__functional/ranges_operations.h> #include <__iterator/concepts.h> #include <__iterator/iter_move.h> #include <__iterator/permutable.h> @@ -39,7 +38,7 @@ namespace ranges { template _LIBCPP_HIDE_FROM_ABI constexpr subrange<_Iter> __remove_if_impl(_Iter __first, _Sent __last, _Pred& __pred, _Proj& __proj) { - auto __new_end = ranges::__find_if_impl(__first, __last, __pred, __proj); + auto __new_end = std::__find_if(__first, __last, __pred, __proj); if (__new_end == __last) return {__new_end, __new_end}; diff --git a/lib/libcxx/include/__algorithm/ranges_reverse_copy.h b/lib/libcxx/include/__algorithm/ranges_reverse_copy.h index e5ca5cf652dc4d091d0129658adfe63beeadeabb..9fedab5bd43628473133b5573244efd2f255c59e 100644 --- a/lib/libcxx/include/__algorithm/ranges_reverse_copy.h +++ b/lib/libcxx/include/__algorithm/ranges_reverse_copy.h @@ -18,6 +18,7 @@ #include <__ranges/access.h> #include <__ranges/concepts.h> #include <__ranges/dangling.h> +#include <__ranges/reverse_view.h> #include <__ranges/subrange.h> #include <__utility/move.h> @@ -49,7 +50,7 @@ struct __reverse_copy { requires indirectly_copyable, _OutIter> _LIBCPP_HIDE_FROM_ABI constexpr reverse_copy_result, _OutIter> operator()(_Range&& __range, _OutIter __result) const { - auto __ret = ranges::copy(std::__reverse_range(__range), std::move(__result)); + auto __ret = ranges::copy(__range | views::reverse, std::move(__result)); return {ranges::next(ranges::begin(__range), ranges::end(__range)), std::move(__ret.out)}; } }; diff --git a/lib/libcxx/include/__algorithm/ranges_set_difference.h b/lib/libcxx/include/__algorithm/ranges_set_difference.h index 1c83c7bdd5a33e748364c5c35a38a783f3b508ae..bcdc6f27a2b0004009bdf1e84f32e9cff57c6316 100644 --- a/lib/libcxx/include/__algorithm/ranges_set_difference.h +++ b/lib/libcxx/include/__algorithm/ranges_set_difference.h @@ -14,16 +14,13 @@ #include <__algorithm/set_difference.h> #include <__config> #include <__functional/identity.h> -#include <__functional/invoke.h> #include <__functional/ranges_operations.h> #include <__iterator/concepts.h> #include <__iterator/mergeable.h> #include <__ranges/access.h> #include <__ranges/concepts.h> #include <__ranges/dangling.h> -#include <__type_traits/decay.h> #include <__utility/move.h> -#include <__utility/pair.h> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header @@ -60,9 +57,8 @@ struct __set_difference { _Comp __comp = {}, _Proj1 __proj1 = {}, _Proj2 __proj2 = {}) const { - auto __ret = std::__set_difference( + return std::__set_difference( __first1, __last1, __first2, __last2, __result, ranges::__make_projected_comp(__comp, __proj1, __proj2)); - return {std::move(__ret.first), std::move(__ret.second)}; } template +#include <__algorithm/shift_left.h> +#include <__config> +#include <__iterator/concepts.h> +#include <__iterator/distance.h> +#include <__iterator/incrementable_traits.h> +#include <__iterator/permutable.h> +#include <__ranges/access.h> +#include <__ranges/concepts.h> +#include <__ranges/subrange.h> +#include <__utility/move.h> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + +_LIBCPP_BEGIN_NAMESPACE_STD + +#if _LIBCPP_STD_VER >= 23 + +namespace ranges { +namespace __shift_left { + +struct __fn { + template _Sent> + _LIBCPP_HIDE_FROM_ABI static constexpr subrange<_Iter> + operator()(_Iter __first, _Sent __last, iter_difference_t<_Iter> __n) { + auto __ret = std::__shift_left<_RangeAlgPolicy>(std::move(__first), std::move(__last), std::move(__n)); + return {std::move(__ret.first), std::move(__ret.second)}; + } + + template + requires permutable> + _LIBCPP_HIDE_FROM_ABI static constexpr borrowed_subrange_t<_Range> + operator()(_Range&& __range, range_difference_t<_Range> __n) { + if constexpr (sized_range<_Range>) { + if (__n >= ranges::distance(__range)) { + return {ranges::begin(__range), ranges::begin(__range)}; + } + } + + auto __ret = std::__shift_left<_RangeAlgPolicy>(ranges::begin(__range), ranges::end(__range), std::move(__n)); + return {std::move(__ret.first), std::move(__ret.second)}; + } +}; +} // namespace __shift_left + +inline namespace __cpo { +inline constexpr auto shift_left = __shift_left::__fn{}; +} // namespace __cpo +} // namespace ranges + +#endif // _LIBCPP_STD_VER >= 23 + +_LIBCPP_END_NAMESPACE_STD + +_LIBCPP_POP_MACROS + +#endif // _LIBCPP___ALGORITHM_RANGES_SHIFT_LEFT_H diff --git a/lib/libcxx/include/__algorithm/ranges_shift_right.h b/lib/libcxx/include/__algorithm/ranges_shift_right.h new file mode 100644 index 0000000000000000000000000000000000000000..d3521b958271de271372b784a4ee93bcd8ec1934 --- /dev/null +++ b/lib/libcxx/include/__algorithm/ranges_shift_right.h @@ -0,0 +1,76 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP___ALGORITHM_RANGES_SHIFT_RIGHT_H +#define _LIBCPP___ALGORITHM_RANGES_SHIFT_RIGHT_H + +#include <__algorithm/iterator_operations.h> +#include <__algorithm/shift_right.h> +#include <__config> +#include <__iterator/concepts.h> +#include <__iterator/distance.h> +#include <__iterator/incrementable_traits.h> +#include <__iterator/permutable.h> +#include <__ranges/access.h> +#include <__ranges/concepts.h> +#include <__ranges/subrange.h> +#include <__utility/move.h> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + +_LIBCPP_BEGIN_NAMESPACE_STD + +#if _LIBCPP_STD_VER >= 23 + +namespace ranges { +namespace __shift_right { + +struct __fn { + template _Sent> + _LIBCPP_HIDE_FROM_ABI static constexpr subrange<_Iter> + operator()(_Iter __first, _Sent __last, iter_difference_t<_Iter> __n) { + auto __ret = std::__shift_right<_RangeAlgPolicy>(std::move(__first), std::move(__last), std::move(__n)); + return {std::move(__ret.first), std::move(__ret.second)}; + } + + template + requires permutable> + _LIBCPP_HIDE_FROM_ABI static constexpr borrowed_subrange_t<_Range> + operator()(_Range&& __range, range_difference_t<_Range> __n) { + if constexpr (sized_range<_Range>) { + if (__n >= ranges::distance(__range)) { + auto __iter = ranges::begin(__range); + auto __end = ranges::end(__range); + ranges::advance(__iter, __end); + return {__iter, std::move(__iter)}; + } + } + + auto __ret = std::__shift_right<_RangeAlgPolicy>(ranges::begin(__range), ranges::end(__range), std::move(__n)); + return {std::move(__ret.first), std::move(__ret.second)}; + } +}; +} // namespace __shift_right + +inline namespace __cpo { +inline constexpr auto shift_right = __shift_right::__fn{}; +} // namespace __cpo +} // namespace ranges + +#endif // _LIBCPP_STD_VER >= 23 + +_LIBCPP_END_NAMESPACE_STD + +_LIBCPP_POP_MACROS + +#endif // _LIBCPP___ALGORITHM_RANGES_SHIFT_RIGHT_H diff --git a/lib/libcxx/include/__algorithm/ranges_swap_ranges.h b/lib/libcxx/include/__algorithm/ranges_swap_ranges.h index ab6db50d8a13efd13611541d3c3ffa6bd8102dde..d24636b5ef98a4d8b9982ed42ef444c26fa0b016 100644 --- a/lib/libcxx/include/__algorithm/ranges_swap_ranges.h +++ b/lib/libcxx/include/__algorithm/ranges_swap_ranges.h @@ -11,6 +11,7 @@ #include <__algorithm/in_in_result.h> #include <__algorithm/iterator_operations.h> +#include <__algorithm/min.h> #include <__algorithm/swap_ranges.h> #include <__config> #include <__iterator/concepts.h> @@ -18,7 +19,9 @@ #include <__ranges/access.h> #include <__ranges/concepts.h> #include <__ranges/dangling.h> +#include <__type_traits/is_same.h> #include <__utility/move.h> +#include <__utility/pair.h> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header @@ -41,9 +44,33 @@ struct __swap_ranges { requires indirectly_swappable<_I1, _I2> _LIBCPP_HIDE_FROM_ABI constexpr swap_ranges_result<_I1, _I2> operator()(_I1 __first1, _S1 __last1, _I2 __first2, _S2 __last2) const { - auto __ret = std::__swap_ranges<_RangeAlgPolicy>( - std::move(__first1), std::move(__last1), std::move(__first2), std::move(__last2)); - return {std::move(__ret.first), std::move(__ret.second)}; + if constexpr (sized_sentinel_for<_I1, _S1> && sized_sentinel_for<_I2, _S2> && + (random_access_iterator<_I1> || random_access_iterator<_I2> || + (is_same_v<_I1, _S1> && is_same_v<_I2, _S2>))) { + auto __offset = std::min(__last1 - __first1, __last2 - __first2); + + auto __ret = [&] { + if constexpr (random_access_iterator<_I1>) + return std::__swap_ranges<_RangeAlgPolicy>(__first1, __first1 + __offset, std::move(__first2)); + else if constexpr (random_access_iterator<_I2>) + return std::__swap_ranges<_RangeAlgPolicy>(__first2, __first2 + __offset, std::move(__first1)); + else if (__last2 - __first2 < __last1 - __first1) { + auto __reversed = + std::__swap_ranges<_RangeAlgPolicy>(std::move(__first2), std::move(__last2), std::move(__first1)); + return std::pair<_I1, _I2>(std::move(__reversed.second), std::move(__reversed.first)); + } else + return std::__swap_ranges<_RangeAlgPolicy>(std::move(__first1), std::move(__last1), std::move(__first2)); + }(); + return {std::move(__ret.first), std::move(__ret.second)}; + } else { + while (__first1 != __last1 && __first2 != __last2) { + ranges::iter_swap(__first1, __first2); + ++__first1; + ++__first2; + } + + return {std::move(__first1), std::move(__first2)}; + } } template diff --git a/lib/libcxx/include/__algorithm/ranges_unique_copy.h b/lib/libcxx/include/__algorithm/ranges_unique_copy.h index ee7f0a0187b7399f1013dfedde69aaa1cc25161c..07191d1a7cc1b175bc28e093b2872599c67ef343 100644 --- a/lib/libcxx/include/__algorithm/ranges_unique_copy.h +++ b/lib/libcxx/include/__algorithm/ranges_unique_copy.h @@ -26,7 +26,6 @@ #include <__ranges/dangling.h> #include <__utility/forward.h> #include <__utility/move.h> -#include <__utility/pair.h> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header @@ -73,13 +72,12 @@ struct __unique_copy { indirectly_copyable_storable<_InIter, _OutIter>) _LIBCPP_HIDE_FROM_ABI constexpr unique_copy_result<_InIter, _OutIter> operator()(_InIter __first, _Sent __last, _OutIter __result, _Comp __comp = {}, _Proj __proj = {}) const { - auto __ret = std::__unique_copy<_RangeAlgPolicy>( + return std::__unique_copy<_RangeAlgPolicy>( std::move(__first), std::move(__last), std::move(__result), std::__make_projected(__comp, __proj), __algo_tag_t<_InIter, _OutIter>()); - return {std::move(__ret.first), std::move(__ret.second)}; } template , _OutIter>) _LIBCPP_HIDE_FROM_ABI constexpr unique_copy_result, _OutIter> operator()(_Range&& __range, _OutIter __result, _Comp __comp = {}, _Proj __proj = {}) const { - auto __ret = std::__unique_copy<_RangeAlgPolicy>( + return std::__unique_copy<_RangeAlgPolicy>( ranges::begin(__range), ranges::end(__range), std::move(__result), std::__make_projected(__comp, __proj), __algo_tag_t, _OutIter>()); - return {std::move(__ret.first), std::move(__ret.second)}; } }; diff --git a/lib/libcxx/include/__algorithm/rotate.h b/lib/libcxx/include/__algorithm/rotate.h index b6d9eb3b2dd00b3eb8bd18097b5c3c0c52c17c93..91782a62db447cdb210a82d177c84be55145113c 100644 --- a/lib/libcxx/include/__algorithm/rotate.h +++ b/lib/libcxx/include/__algorithm/rotate.h @@ -39,7 +39,7 @@ __rotate_left(_ForwardIterator __first, _ForwardIterator __last) { using _Ops = _IterOps<_AlgPolicy>; value_type __tmp = _Ops::__iter_move(__first); - _ForwardIterator __lm1 = std::__move<_AlgPolicy>(_Ops::next(__first), __last, __first).second; + _ForwardIterator __lm1 = std::__move<_AlgPolicy>(_Ops::next(__first), __last, __first).__out_; *__lm1 = std::move(__tmp); return __lm1; } @@ -52,7 +52,7 @@ __rotate_right(_BidirectionalIterator __first, _BidirectionalIterator __last) { _BidirectionalIterator __lm1 = _Ops::prev(__last); value_type __tmp = _Ops::__iter_move(__lm1); - _BidirectionalIterator __fp1 = std::__move_backward<_AlgPolicy>(__first, __lm1, std::move(__last)).second; + _BidirectionalIterator __fp1 = std::__move_backward<_AlgPolicy>(__first, __lm1, std::move(__last)).__out_; *__first = std::move(__tmp); return __fp1; } diff --git a/lib/libcxx/include/__algorithm/set_difference.h b/lib/libcxx/include/__algorithm/set_difference.h index 0cd1bc45d64f761bac4cc456c5cc9a05fe8175ab..26f4f9c22438091dc0858e9507358d4653e2696e 100644 --- a/lib/libcxx/include/__algorithm/set_difference.h +++ b/lib/libcxx/include/__algorithm/set_difference.h @@ -12,12 +12,10 @@ #include <__algorithm/comp.h> #include <__algorithm/comp_ref_type.h> #include <__algorithm/copy.h> +#include <__algorithm/in_out_result.h> #include <__config> -#include <__functional/identity.h> -#include <__iterator/iterator_traits.h> #include <__type_traits/remove_cvref.h> #include <__utility/move.h> -#include <__utility/pair.h> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header @@ -29,7 +27,8 @@ _LIBCPP_PUSH_MACROS _LIBCPP_BEGIN_NAMESPACE_STD template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<__remove_cvref_t<_InIter1>, __remove_cvref_t<_OutIter> > +_LIBCPP_HIDE_FROM_ABI +_LIBCPP_CONSTEXPR_SINCE_CXX20 __in_out_result<__remove_cvref_t<_InIter1>, __remove_cvref_t<_OutIter> > __set_difference( _InIter1&& __first1, _Sent1&& __last1, _InIter2&& __first2, _Sent2&& __last2, _OutIter&& __result, _Comp&& __comp) { while (__first1 != __last1 && __first2 != __last2) { @@ -56,7 +55,7 @@ inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator set_d _OutputIterator __result, _Compare __comp) { return std::__set_difference<__comp_ref_type<_Compare> >(__first1, __last1, __first2, __last2, __result, __comp) - .second; + .__out_; } template @@ -66,7 +65,7 @@ inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator set_d _InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result) { - return std::__set_difference(__first1, __last1, __first2, __last2, __result, __less<>()).second; + return std::__set_difference(__first1, __last1, __first2, __last2, __result, __less<>()).__out_; } _LIBCPP_END_NAMESPACE_STD diff --git a/lib/libcxx/include/__algorithm/set_intersection.h b/lib/libcxx/include/__algorithm/set_intersection.h index 6246e24b9ca4e763b4e22dad8c2249a0851a4b2b..d048b5fe08e628ebf63159c78965f06f9b529594 100644 --- a/lib/libcxx/include/__algorithm/set_intersection.h +++ b/lib/libcxx/include/__algorithm/set_intersection.h @@ -96,12 +96,10 @@ __set_intersection( _Compare&& __comp, std::forward_iterator_tag, std::forward_iterator_tag) { - _LIBCPP_CONSTEXPR std::__identity __proj; bool __prev_may_be_equal = false; while (__first2 != __last2) { - _InForwardIter1 __first1_next = - std::__lower_bound_onesided<_AlgPolicy>(__first1, __last1, *__first2, __comp, __proj); + _InForwardIter1 __first1_next = std::__lower_bound_onesided<_AlgPolicy>(__first1, __last1, *__first2, __comp); std::swap(__first1_next, __first1); // keeping in mind that a==b iff !(a(__first2, __last2, *__first1, __comp, __proj); + _InForwardIter2 __first2_next = std::__lower_bound_onesided<_AlgPolicy>(__first2, __last2, *__first1, __comp); std::swap(__first2_next, __first2); std::__set_intersection_add_output_if_equal( __first2 == __first2_next, __first1, __first2, __result, __prev_may_be_equal); diff --git a/lib/libcxx/include/__algorithm/set_symmetric_difference.h b/lib/libcxx/include/__algorithm/set_symmetric_difference.h index 91ea4067c0d0f770ee395e1dfbc797ed62346ea1..e8364cd9a73e0a6bf592f7f10302412e3abd34c3 100644 --- a/lib/libcxx/include/__algorithm/set_symmetric_difference.h +++ b/lib/libcxx/include/__algorithm/set_symmetric_difference.h @@ -46,7 +46,7 @@ __set_symmetric_difference( if (__first2 == __last2) { auto __ret1 = std::__copy(std::move(__first1), std::move(__last1), std::move(__result)); return __set_symmetric_difference_result<_InIter1, _InIter2, _OutIter>( - std::move(__ret1.first), std::move(__first2), std::move((__ret1.second))); + std::move(__ret1.__in_), std::move(__first2), std::move((__ret1.__out_))); } if (__comp(*__first1, *__first2)) { *__result = *__first1; @@ -64,7 +64,7 @@ __set_symmetric_difference( } auto __ret2 = std::__copy(std::move(__first2), std::move(__last2), std::move(__result)); return __set_symmetric_difference_result<_InIter1, _InIter2, _OutIter>( - std::move(__first1), std::move(__ret2.first), std::move((__ret2.second))); + std::move(__first1), std::move(__ret2.__in_), std::move((__ret2.__out_))); } template diff --git a/lib/libcxx/include/__algorithm/set_union.h b/lib/libcxx/include/__algorithm/set_union.h index 393dddce4302a2fedd2011ba4510f6b26c86b85a..7180682494cf91d0ac11a4cbe8d44488c6bc6be8 100644 --- a/lib/libcxx/include/__algorithm/set_union.h +++ b/lib/libcxx/include/__algorithm/set_union.h @@ -45,7 +45,7 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __set_union_result<_InIter1, if (__first2 == __last2) { auto __ret1 = std::__copy(std::move(__first1), std::move(__last1), std::move(__result)); return __set_union_result<_InIter1, _InIter2, _OutIter>( - std::move(__ret1.first), std::move(__first2), std::move((__ret1.second))); + std::move(__ret1.__in_), std::move(__first2), std::move((__ret1.__out_))); } if (__comp(*__first2, *__first1)) { *__result = *__first2; @@ -60,7 +60,7 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __set_union_result<_InIter1, } auto __ret2 = std::__copy(std::move(__first2), std::move(__last2), std::move(__result)); return __set_union_result<_InIter1, _InIter2, _OutIter>( - std::move(__first1), std::move(__ret2.first), std::move((__ret2.second))); + std::move(__first1), std::move(__ret2.__in_), std::move((__ret2.__out_))); } template diff --git a/lib/libcxx/include/__algorithm/shift_left.h b/lib/libcxx/include/__algorithm/shift_left.h index 06cd7c5f87644e93dbd8d4aa49a672ab9cc693ef..df60636f84dbb763a7f0e5285382a2dcbb633cf8 100644 --- a/lib/libcxx/include/__algorithm/shift_left.h +++ b/lib/libcxx/include/__algorithm/shift_left.h @@ -9,9 +9,14 @@ #ifndef _LIBCPP___ALGORITHM_SHIFT_LEFT_H #define _LIBCPP___ALGORITHM_SHIFT_LEFT_H +#include <__algorithm/iterator_operations.h> #include <__algorithm/move.h> +#include <__assert> #include <__config> +#include <__iterator/concepts.h> #include <__iterator/iterator_traits.h> +#include <__utility/move.h> +#include <__utility/pair.h> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header @@ -24,30 +29,42 @@ _LIBCPP_BEGIN_NAMESPACE_STD #if _LIBCPP_STD_VER >= 20 -template -inline _LIBCPP_HIDE_FROM_ABI constexpr _ForwardIterator -shift_left(_ForwardIterator __first, - _ForwardIterator __last, - typename iterator_traits<_ForwardIterator>::difference_type __n) { +template +_LIBCPP_HIDE_FROM_ABI constexpr pair<_Iter, _Iter> +__shift_left(_Iter __first, _Sent __last, typename _IterOps<_AlgPolicy>::template __difference_type<_Iter> __n) { + _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__n >= 0, "n must be greater than or equal to 0"); + if (__n == 0) { - return __last; + _Iter __end = _IterOps<_AlgPolicy>::next(__first, __last); + return {std::move(__first), std::move(__end)}; } - _ForwardIterator __m = __first; - if constexpr (__has_random_access_iterator_category<_ForwardIterator>::value) { - if (__n >= __last - __first) { - return __first; + _Iter __m = __first; + if constexpr (sized_sentinel_for<_Sent, _Iter>) { + auto __size = _IterOps<_AlgPolicy>::distance(__first, __last); + if (__n >= __size) { + return {__first, std::move(__first)}; } - __m += __n; + _IterOps<_AlgPolicy>::advance(__m, __n); } else { for (; __n > 0; --__n) { if (__m == __last) { - return __first; + return {__first, std::move(__first)}; } ++__m; } } - return std::move(__m, __last, __first); + + _Iter __result = std::__move<_AlgPolicy>(__m, __last, __first).__out_; + return {std::move(__first), std::move(__result)}; +} + +template +_LIBCPP_HIDE_FROM_ABI constexpr _ForwardIterator +shift_left(_ForwardIterator __first, + _ForwardIterator __last, + typename iterator_traits<_ForwardIterator>::difference_type __n) { + return std::__shift_left<_ClassicAlgPolicy>(std::move(__first), std::move(__last), __n).second; } #endif // _LIBCPP_STD_VER >= 20 diff --git a/lib/libcxx/include/__algorithm/shift_right.h b/lib/libcxx/include/__algorithm/shift_right.h index 01853057fc47887f0b86c3f97da356d0fe643d9d..757d9a7f589db9fa44eafd28faddd7c534cfddc8 100644 --- a/lib/libcxx/include/__algorithm/shift_right.h +++ b/lib/libcxx/include/__algorithm/shift_right.h @@ -9,11 +9,17 @@ #ifndef _LIBCPP___ALGORITHM_SHIFT_RIGHT_H #define _LIBCPP___ALGORITHM_SHIFT_RIGHT_H +#include <__algorithm/iterator_operations.h> #include <__algorithm/move.h> #include <__algorithm/move_backward.h> #include <__algorithm/swap_ranges.h> +#include <__assert> +#include <__concepts/derived_from.h> #include <__config> +#include <__iterator/concepts.h> #include <__iterator/iterator_traits.h> +#include <__utility/move.h> +#include <__utility/pair.h> #include <__utility/swap.h> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) @@ -27,36 +33,48 @@ _LIBCPP_BEGIN_NAMESPACE_STD #if _LIBCPP_STD_VER >= 20 -template -inline _LIBCPP_HIDE_FROM_ABI constexpr _ForwardIterator -shift_right(_ForwardIterator __first, - _ForwardIterator __last, - typename iterator_traits<_ForwardIterator>::difference_type __n) { +template +_LIBCPP_HIDE_FROM_ABI constexpr pair<_Iter, _Iter> +__shift_right(_Iter __first, _Sent __last, typename _IterOps<_AlgPolicy>::template __difference_type<_Iter> __n) { + _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__n >= 0, "Providing a negative shift amount to shift_right is UB"); if (__n == 0) { - return __first; + _Iter __end = _IterOps<_AlgPolicy>::next(__first, __last); + return pair<_Iter, _Iter>(std::move(__first), std::move(__end)); } - if constexpr (__has_random_access_iterator_category<_ForwardIterator>::value) { - decltype(__n) __d = __last - __first; - if (__n >= __d) { - return __last; + using _IterCategory = typename _IterOps<_AlgPolicy>::template __iterator_category<_Iter>; + + if constexpr (derived_from<_IterCategory, random_access_iterator_tag>) { + _Iter __end = _IterOps<_AlgPolicy>::next(__first, __last); + auto __size = __end - __first; + if (__n >= __size) { + return pair<_Iter, _Iter>(__end, std::move(__end)); } - _ForwardIterator __m = __first + (__d - __n); - return std::move_backward(__first, __m, __last); - } else if constexpr (__has_bidirectional_iterator_category<_ForwardIterator>::value) { - _ForwardIterator __m = __last; + _Iter __m = __first; + _IterOps<_AlgPolicy>::advance(__m, (__size - __n)); + auto __ret = std::__move_backward<_AlgPolicy>(std::move(__first), std::move(__m), __end); + return pair<_Iter, _Iter>(std::move(__ret.__out_), std::move(__end)); + } else if constexpr (derived_from<_IterCategory, bidirectional_iterator_tag>) { + _Iter __end = _IterOps<_AlgPolicy>::next(__first, __last); + if constexpr (sized_sentinel_for<_Sent, _Iter>) { + if (__n >= ranges::distance(__first, __last)) { + return pair<_Iter, _Iter>(__end, std::move(__end)); + } + } + _Iter __m = __end; for (; __n > 0; --__n) { if (__m == __first) { - return __last; + return pair<_Iter, _Iter>(__end, std::move(__end)); } --__m; } - return std::move_backward(__first, __m, __last); + auto __ret = std::__move_backward<_AlgPolicy>(std::move(__first), std::move(__m), __end); + return pair<_Iter, _Iter>(std::move(__ret.__out_), std::move(__end)); } else { - _ForwardIterator __ret = __first; + _Iter __ret = __first; for (; __n > 0; --__n) { if (__ret == __last) { - return __last; + return pair<_Iter, _Iter>(__ret, std::move(__ret)); } ++__ret; } @@ -64,28 +82,28 @@ shift_right(_ForwardIterator __first, // We have an __n-element scratch space from __first to __ret. // Slide an __n-element window [__trail, __lead) from left to right. // We're essentially doing swap_ranges(__first, __ret, __trail, __lead) - // over and over; but once __lead reaches __last we needn't bother - // to save the values of elements [__trail, __last). + // over and over; but once __lead reaches __end we needn't bother + // to save the values of elements [__trail, __end). auto __trail = __first; auto __lead = __ret; while (__trail != __ret) { if (__lead == __last) { - std::move(__first, __trail, __ret); - return __ret; + std::__move<_AlgPolicy>(std::move(__first), std::move(__trail), __ret); + return pair<_Iter, _Iter>(__ret, std::move(__lead)); } ++__trail; ++__lead; } - _ForwardIterator __mid = __first; + _Iter __mid = __first; while (true) { if (__lead == __last) { - __trail = std::move(__mid, __ret, __trail); - std::move(__first, __mid, __trail); - return __ret; + __trail = std::__move<_AlgPolicy>(__mid, __ret, __trail).__out_; + std::__move<_AlgPolicy>(std::move(__first), std::move(__mid), std::move(__trail)); + return pair<_Iter, _Iter>(__ret, std::move(__lead)); } - swap(*__mid, *__trail); + _IterOps<_AlgPolicy>::iter_swap(__mid, __trail); ++__mid; ++__trail; ++__lead; @@ -96,6 +114,14 @@ shift_right(_ForwardIterator __first, } } +template +_LIBCPP_HIDE_FROM_ABI constexpr _ForwardIterator +shift_right(_ForwardIterator __first, + _ForwardIterator __last, + typename iterator_traits<_ForwardIterator>::difference_type __n) { + return std::__shift_right<_ClassicAlgPolicy>(std::move(__first), std::move(__last), __n).first; +} + #endif // _LIBCPP_STD_VER >= 20 _LIBCPP_END_NAMESPACE_STD diff --git a/lib/libcxx/include/__algorithm/shuffle.h b/lib/libcxx/include/__algorithm/shuffle.h index 7177fbb469ba7cc9039ac143739af3ba986e673b..c0707f17b5b33ae947e4e123cee184ee926f2b3b 100644 --- a/lib/libcxx/include/__algorithm/shuffle.h +++ b/lib/libcxx/include/__algorithm/shuffle.h @@ -28,6 +28,7 @@ _LIBCPP_PUSH_MACROS _LIBCPP_BEGIN_NAMESPACE_STD +_LIBCPP_BEGIN_EXPLICIT_ABI_ANNOTATIONS class _LIBCPP_EXPORTED_FROM_ABI __libcpp_debug_randomizer { public: _LIBCPP_HIDE_FROM_ABI __libcpp_debug_randomizer() { @@ -160,6 +161,7 @@ shuffle(_RandomAccessIterator __first, _RandomAccessIterator __last, _UniformRan std::move(__first), std::move(__last), std::forward<_UniformRandomNumberGenerator>(__g)); } +_LIBCPP_END_EXPLICIT_ABI_ANNOTATIONS _LIBCPP_END_NAMESPACE_STD _LIBCPP_POP_MACROS diff --git a/lib/libcxx/include/__algorithm/simd_utils.h b/lib/libcxx/include/__algorithm/simd_utils.h index f73c9ea4b6ea7f2ea4590c4c525fba3e5455c66e..495aed4e21216ad633f9bc5921ba705128e35f88 100644 --- a/lib/libcxx/include/__algorithm/simd_utils.h +++ b/lib/libcxx/include/__algorithm/simd_utils.h @@ -90,6 +90,9 @@ inline constexpr size_t __native_vector_size = 1; template using __simd_vector __attribute__((__ext_vector_type__(_Np))) _LIBCPP_NODEBUG = _ArithmeticT; +_LIBCPP_DIAGNOSTIC_PUSH +_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wpsabi") + template inline constexpr size_t __simd_vector_size_v = []() -> size_t { static_assert(_False, "Not a vector!"); @@ -115,8 +118,6 @@ template } // Load the first _Np elements, zero the rest -_LIBCPP_DIAGNOSTIC_PUSH -_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wpsabi") template [[__nodiscard__]] _LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _VecT __partial_load(_Iter __iter) noexcept { return [=]( @@ -125,16 +126,6 @@ template }(make_index_sequence<_Np>{}, make_index_sequence<__simd_vector_size_v<_VecT> - _Np>{}); } -// Create a vector where every elements is __val -template -[[__nodiscard__]] _LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _VecT -__broadcast(__simd_vector_underlying_type_t<_VecT> __val) { - return [&](index_sequence<_Indices...>) { - return _VecT{((void)_Indices, __val)...}; - }(make_index_sequence<__simd_vector_size_v<_VecT>>()); -} -_LIBCPP_DIAGNOSTIC_POP - template [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI bool __any_of(__simd_vector<_Tp, _Np> __vec) noexcept { return __builtin_reduce_or(__builtin_convertvector(__vec, __simd_vector)); @@ -183,6 +174,7 @@ template [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI size_t __find_first_not_set(__simd_vector<_Tp, _Np> __vec) noexcept { return std::__find_first_set(~__vec); } +_LIBCPP_DIAGNOSTIC_POP _LIBCPP_END_NAMESPACE_STD diff --git a/lib/libcxx/include/__algorithm/sort.h b/lib/libcxx/include/__algorithm/sort.h index 8aa894e9228c634a9d335259319af3adffe687f2..0a936db78e5fd6b2a1370132898d7eb7bbc1b033 100644 --- a/lib/libcxx/include/__algorithm/sort.h +++ b/lib/libcxx/include/__algorithm/sort.h @@ -828,6 +828,7 @@ void __introsort(_RandomAccessIterator __first, } } +_LIBCPP_BEGIN_EXPLICIT_ABI_ANNOTATIONS template void __sort(_RandomAccessIterator, _RandomAccessIterator, _Comp); @@ -856,6 +857,7 @@ extern template _LIBCPP_EXPORTED_FROM_ABI void __sort<__less&, float*>(fl extern template _LIBCPP_EXPORTED_FROM_ABI void __sort<__less&, double*>(double*, double*, __less&); extern template _LIBCPP_EXPORTED_FROM_ABI void __sort<__less&, long double*>(long double*, long double*, __less&); +_LIBCPP_END_EXPLICIT_ABI_ANNOTATIONS template _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void diff --git a/lib/libcxx/include/__algorithm/specialized_algorithms.h b/lib/libcxx/include/__algorithm/specialized_algorithms.h index 7cb94c015f7675e646681750577dacac405601aa..58b4d93ee689406e38972f0ff6d51f7ee6bca82b 100644 --- a/lib/libcxx/include/__algorithm/specialized_algorithms.h +++ b/lib/libcxx/include/__algorithm/specialized_algorithms.h @@ -21,6 +21,7 @@ namespace _Algorithm { struct __copy {}; struct __fill_n {}; struct __for_each {}; +struct __swap_ranges {}; } // namespace _Algorithm template diff --git a/lib/libcxx/include/__algorithm/swap_ranges.h b/lib/libcxx/include/__algorithm/swap_ranges.h index 2731d4feaa63d4dcfee755ffec78f0957f853920..3a9e841f471ba038248838d8b6fbb6a046b579bd 100644 --- a/lib/libcxx/include/__algorithm/swap_ranges.h +++ b/lib/libcxx/include/__algorithm/swap_ranges.h @@ -10,12 +10,11 @@ #define _LIBCPP___ALGORITHM_SWAP_RANGES_H #include <__algorithm/iterator_operations.h> -#include <__algorithm/min.h> +#include <__algorithm/specialized_algorithms.h> #include <__config> -#include <__fwd/bit_reference.h> +#include <__type_traits/enable_if.h> #include <__utility/move.h> #include <__utility/pair.h> -#include <__utility/swap.h> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header @@ -26,189 +25,36 @@ _LIBCPP_PUSH_MACROS _LIBCPP_BEGIN_NAMESPACE_STD -template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __bit_iterator<_Cr, false> __swap_ranges_aligned( - __bit_iterator<_Cl, false> __first, __bit_iterator<_Cl, false> __last, __bit_iterator<_Cr, false> __result) { - using _I1 = __bit_iterator<_Cl, false>; - using difference_type = typename _I1::difference_type; - using __storage_type = typename _I1::__storage_type; - - const int __bits_per_word = _I1::__bits_per_word; - difference_type __n = __last - __first; - if (__n > 0) { - // do first word - if (__first.__ctz_ != 0) { - unsigned __clz = __bits_per_word - __first.__ctz_; - difference_type __dn = std::min(static_cast(__clz), __n); - __n -= __dn; - __storage_type __m = (~__storage_type(0) << __first.__ctz_) & (~__storage_type(0) >> (__clz - __dn)); - __storage_type __b1 = *__first.__seg_ & __m; - *__first.__seg_ &= ~__m; - __storage_type __b2 = *__result.__seg_ & __m; - *__result.__seg_ &= ~__m; - *__result.__seg_ |= __b1; - *__first.__seg_ |= __b2; - __result.__seg_ += (__dn + __result.__ctz_) / __bits_per_word; - __result.__ctz_ = static_cast((__dn + __result.__ctz_) % __bits_per_word); - ++__first.__seg_; - // __first.__ctz_ = 0; - } - // __first.__ctz_ == 0; - // do middle words - for (; __n >= __bits_per_word; __n -= __bits_per_word, ++__first.__seg_, ++__result.__seg_) - swap(*__first.__seg_, *__result.__seg_); - // do last word - if (__n > 0) { - __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n); - __storage_type __b1 = *__first.__seg_ & __m; - *__first.__seg_ &= ~__m; - __storage_type __b2 = *__result.__seg_ & __m; - *__result.__seg_ &= ~__m; - *__result.__seg_ |= __b1; - *__first.__seg_ |= __b2; - __result.__ctz_ = static_cast(__n); - } - } - return __result; -} - -template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __bit_iterator<_Cr, false> __swap_ranges_unaligned( - __bit_iterator<_Cl, false> __first, __bit_iterator<_Cl, false> __last, __bit_iterator<_Cr, false> __result) { - using _I1 = __bit_iterator<_Cl, false>; - using difference_type = typename _I1::difference_type; - using __storage_type = typename _I1::__storage_type; - - const int __bits_per_word = _I1::__bits_per_word; - difference_type __n = __last - __first; - if (__n > 0) { - // do first word - if (__first.__ctz_ != 0) { - unsigned __clz_f = __bits_per_word - __first.__ctz_; - difference_type __dn = std::min(static_cast(__clz_f), __n); - __n -= __dn; - __storage_type __m = (~__storage_type(0) << __first.__ctz_) & (~__storage_type(0) >> (__clz_f - __dn)); - __storage_type __b1 = *__first.__seg_ & __m; - *__first.__seg_ &= ~__m; - unsigned __clz_r = __bits_per_word - __result.__ctz_; - __storage_type __ddn = std::min<__storage_type>(__dn, __clz_r); - __m = (~__storage_type(0) << __result.__ctz_) & (~__storage_type(0) >> (__clz_r - __ddn)); - __storage_type __b2 = *__result.__seg_ & __m; - *__result.__seg_ &= ~__m; - if (__result.__ctz_ > __first.__ctz_) { - unsigned __s = __result.__ctz_ - __first.__ctz_; - *__result.__seg_ |= __b1 << __s; - *__first.__seg_ |= __b2 >> __s; - } else { - unsigned __s = __first.__ctz_ - __result.__ctz_; - *__result.__seg_ |= __b1 >> __s; - *__first.__seg_ |= __b2 << __s; - } - __result.__seg_ += (__ddn + __result.__ctz_) / __bits_per_word; - __result.__ctz_ = static_cast((__ddn + __result.__ctz_) % __bits_per_word); - __dn -= __ddn; - if (__dn > 0) { - __m = ~__storage_type(0) >> (__bits_per_word - __dn); - __b2 = *__result.__seg_ & __m; - *__result.__seg_ &= ~__m; - unsigned __s = __first.__ctz_ + __ddn; - *__result.__seg_ |= __b1 >> __s; - *__first.__seg_ |= __b2 << __s; - __result.__ctz_ = static_cast(__dn); - } - ++__first.__seg_; - // __first.__ctz_ = 0; - } - // __first.__ctz_ == 0; - // do middle words - __storage_type __m = ~__storage_type(0) << __result.__ctz_; - unsigned __clz_r = __bits_per_word - __result.__ctz_; - for (; __n >= __bits_per_word; __n -= __bits_per_word, ++__first.__seg_) { - __storage_type __b1 = *__first.__seg_; - __storage_type __b2 = *__result.__seg_ & __m; - *__result.__seg_ &= ~__m; - *__result.__seg_ |= __b1 << __result.__ctz_; - *__first.__seg_ = __b2 >> __result.__ctz_; - ++__result.__seg_; - __b2 = *__result.__seg_ & ~__m; - *__result.__seg_ &= __m; - *__result.__seg_ |= __b1 >> __clz_r; - *__first.__seg_ |= __b2 << __clz_r; - } - // do last word - if (__n > 0) { - __m = ~__storage_type(0) >> (__bits_per_word - __n); - __storage_type __b1 = *__first.__seg_ & __m; - *__first.__seg_ &= ~__m; - __storage_type __dn = std::min<__storage_type>(__n, __clz_r); - __m = (~__storage_type(0) << __result.__ctz_) & (~__storage_type(0) >> (__clz_r - __dn)); - __storage_type __b2 = *__result.__seg_ & __m; - *__result.__seg_ &= ~__m; - *__result.__seg_ |= __b1 << __result.__ctz_; - *__first.__seg_ |= __b2 >> __result.__ctz_; - __result.__seg_ += (__dn + __result.__ctz_) / __bits_per_word; - __result.__ctz_ = static_cast((__dn + __result.__ctz_) % __bits_per_word); - __n -= __dn; - if (__n > 0) { - __m = ~__storage_type(0) >> (__bits_per_word - __n); - __b2 = *__result.__seg_ & __m; - *__result.__seg_ &= ~__m; - *__result.__seg_ |= __b1 >> __dn; - *__first.__seg_ |= __b2 << __dn; - __result.__ctz_ = static_cast(__n); - } - } - } - return __result; -} - -// 2+1 iterators: size2 >= size1; used by std::swap_ranges. -template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<__bit_iterator<_Cl, false>, __bit_iterator<_Cr, false> > -__swap_ranges(__bit_iterator<_Cl, false> __first1, - __bit_iterator<_Cl, false> __last1, - __bit_iterator<_Cr, false> __first2) { - if (__first1.__ctz_ == __first2.__ctz_) - return std::make_pair(__last1, std::__swap_ranges_aligned(__first1, __last1, __first2)); - return std::make_pair(__last1, std::__swap_ranges_unaligned(__first1, __last1, __first2)); -} - -// 2+2 iterators: used by std::ranges::swap_ranges. -template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<__bit_iterator<_Cl, false>, __bit_iterator<_Cr, false> > -__swap_ranges(__bit_iterator<_Cl, false> __first1, - __bit_iterator<_Cl, false> __last1, - __bit_iterator<_Cr, false> __first2, - __bit_iterator<_Cr, false> __last2) { - if (__last1 - __first1 < __last2 - __first2) - return std::make_pair(__last1, std::__swap_ranges<_AlgPolicy>(__first1, __last1, __first2).second); - return std::make_pair(std::__swap_ranges<_AlgPolicy>(__first2, __last2, __first1).second, __last2); -} - -// 2+2 iterators: the shorter size will be used. -template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_ForwardIterator1, _ForwardIterator2> -__swap_ranges(_ForwardIterator1 __first1, _Sentinel1 __last1, _ForwardIterator2 __first2, _Sentinel2 __last2) { - while (__first1 != __last1 && __first2 != __last2) { - _IterOps<_AlgPolicy>::iter_swap(__first1, __first2); - ++__first1; - ++__first2; - } - - return pair<_ForwardIterator1, _ForwardIterator2>(std::move(__first1), std::move(__first2)); +template < + class _AlgPolicy, + class _Iter1, + class _Sent1, + class _Iter2, + class _SpecialAlg = + __specialized_algorithm<_Algorithm::__swap_ranges, __iterator_pair<_Iter1, _Sent1>, __single_iterator<_Iter2> >, + __enable_if_t<_SpecialAlg::__has_algorithm, int> = 0> +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_Iter1, _Iter2> +__swap_ranges(_Iter1 __first1, _Sent1 __last1, _Iter2 __first2) { + return _SpecialAlg()(std::move(__first1), std::move(__last1), std::move(__first2)); } -// 2+1 iterators: size2 >= size1. -template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_ForwardIterator1, _ForwardIterator2> -__swap_ranges(_ForwardIterator1 __first1, _Sentinel1 __last1, _ForwardIterator2 __first2) { +template < + class _AlgPolicy, + class _Iter1, + class _Sent1, + class _Iter2, + class _SpecialAlg = + __specialized_algorithm<_Algorithm::__swap_ranges, __iterator_pair<_Iter1, _Sent1>, __single_iterator<_Iter2> >, + __enable_if_t = 0> +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_Iter1, _Iter2> +__swap_ranges(_Iter1 __first1, _Sent1 __last1, _Iter2 __first2) { while (__first1 != __last1) { _IterOps<_AlgPolicy>::iter_swap(__first1, __first2); ++__first1; ++__first2; } - return pair<_ForwardIterator1, _ForwardIterator2>(std::move(__first1), std::move(__first2)); + return pair<_Iter1, _Iter2>(std::move(__first1), std::move(__first2)); } template diff --git a/lib/libcxx/include/__algorithm/three_way_comp_ref_type.h b/lib/libcxx/include/__algorithm/three_way_comp_ref_type.h index f6f76455e466418db82a89fd9928d0985b1d8537..8df3f1d6e3b2d5908cd9f9bc74e9e4ab7d0b324d 100644 --- a/lib/libcxx/include/__algorithm/three_way_comp_ref_type.h +++ b/lib/libcxx/include/__algorithm/three_way_comp_ref_type.h @@ -19,10 +19,10 @@ # pragma GCC system_header #endif -_LIBCPP_BEGIN_NAMESPACE_STD - #if _LIBCPP_STD_VER >= 20 +_LIBCPP_BEGIN_NAMESPACE_STD + template struct __debug_three_way_comp { _Comp& __comp_; @@ -67,8 +67,8 @@ template using __three_way_comp_ref_type _LIBCPP_NODEBUG = _Comp&; # endif -#endif // _LIBCPP_STD_VER >= 20 - _LIBCPP_END_NAMESPACE_STD +#endif // _LIBCPP_STD_VER >= 20 + #endif // _LIBCPP___ALGORITHM_THREE_WAY_COMP_REF_TYPE_H diff --git a/lib/libcxx/include/__algorithm/unique_copy.h b/lib/libcxx/include/__algorithm/unique_copy.h index 16ce80cab32f0dfba19bdbb9c3da7677e9e7c901..f31934229c5b103f666ba10dd6b95d0c82414e82 100644 --- a/lib/libcxx/include/__algorithm/unique_copy.h +++ b/lib/libcxx/include/__algorithm/unique_copy.h @@ -10,6 +10,7 @@ #define _LIBCPP___ALGORITHM_UNIQUE_COPY_H #include <__algorithm/comp.h> +#include <__algorithm/in_out_result.h> #include <__algorithm/iterator_operations.h> #include <__config> #include <__iterator/iterator_traits.h> @@ -17,7 +18,6 @@ #include <__type_traits/is_base_of.h> #include <__type_traits/is_same.h> #include <__utility/move.h> -#include <__utility/pair.h> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header @@ -37,7 +37,7 @@ struct __read_from_tmp_value_tag {}; } // namespace __unique_copy_tags template -_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI pair<_InputIterator, _OutputIterator> +_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI __in_out_result<_InputIterator, _OutputIterator> __unique_copy(_InputIterator __first, _Sent __last, _OutputIterator __result, @@ -55,11 +55,11 @@ __unique_copy(_InputIterator __first, } } } - return pair<_InputIterator, _OutputIterator>(std::move(__first), std::move(__result)); + return {std::move(__first), std::move(__result)}; } template -_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI pair<_ForwardIterator, _OutputIterator> +_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI __in_out_result<_ForwardIterator, _OutputIterator> __unique_copy(_ForwardIterator __first, _Sent __last, _OutputIterator __result, @@ -77,11 +77,11 @@ __unique_copy(_ForwardIterator __first, } } } - return pair<_ForwardIterator, _OutputIterator>(std::move(__first), std::move(__result)); + return {std::move(__first), std::move(__result)}; } template -_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI pair<_InputIterator, _InputAndOutputIterator> +_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI __in_out_result<_InputIterator, _InputAndOutputIterator> __unique_copy(_InputIterator __first, _Sent __last, _InputAndOutputIterator __result, @@ -94,7 +94,7 @@ __unique_copy(_InputIterator __first, *++__result = *__first; ++__result; } - return pair<_InputIterator, _InputAndOutputIterator>(std::move(__first), std::move(__result)); + return {std::move(__first), std::move(__result)}; } template @@ -111,7 +111,7 @@ unique_copy(_InputIterator __first, _InputIterator __last, _OutputIterator __res __unique_copy_tags::__read_from_tmp_value_tag> >; return std::__unique_copy<_ClassicAlgPolicy>( std::move(__first), std::move(__last), std::move(__result), __pred, __algo_tag()) - .second; + .__out_; } template diff --git a/lib/libcxx/include/__algorithm/unwrap_iter.h b/lib/libcxx/include/__algorithm/unwrap_iter.h index b66a682e765fa3a660f852748cce9eabebb3765b..ea862cd2f6f30508978fea094d4c9a88c4bfd43b 100644 --- a/lib/libcxx/include/__algorithm/unwrap_iter.h +++ b/lib/libcxx/include/__algorithm/unwrap_iter.h @@ -57,21 +57,19 @@ struct __unwrap_iter_impl<_Iter, true> { } }; -template , - __enable_if_t::value, int> = 0> +template > inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 decltype(_Impl::__unwrap(std::declval<_Iter>())) __unwrap_iter(_Iter __i) _NOEXCEPT { - return _Impl::__unwrap(__i); -} - // Allow input_iterators to be passed to __unwrap_iter (but not __rewrap_iter) #if _LIBCPP_STD_VER >= 20 -template ::value, int> = 0> -inline _LIBCPP_HIDE_FROM_ABI constexpr _Iter __unwrap_iter(_Iter __i) noexcept { - return __i; -} + if constexpr (!is_copy_constructible_v<_Iter>) { + return __i; + } else #endif + { + return _Impl::__unwrap(__i); + } +} template > _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _OrigIter __rewrap_iter(_OrigIter __orig_iter, _Iter __iter) _NOEXCEPT { diff --git a/lib/libcxx/include/__algorithm/unwrap_range.h b/lib/libcxx/include/__algorithm/unwrap_range.h index 2d4b9bb5545ad3e900b2e2e9cb8508155c57eded..c46094f1e6861bc4e9fe26e4d2939a9a026427a6 100644 --- a/lib/libcxx/include/__algorithm/unwrap_range.h +++ b/lib/libcxx/include/__algorithm/unwrap_range.h @@ -10,10 +10,9 @@ #define _LIBCPP___ALGORITHM_UNWRAP_RANGE_H #include <__algorithm/unwrap_iter.h> -#include <__concepts/constructible.h> #include <__config> #include <__iterator/concepts.h> -#include <__iterator/next.h> +#include <__type_traits/is_same.h> #include <__utility/declval.h> #include <__utility/move.h> #include <__utility/pair.h> @@ -32,53 +31,25 @@ _LIBCPP_BEGIN_NAMESPACE_STD // the same type. __unwrap_range tries to get two iterators and then forward to __unwrap_iter. #if _LIBCPP_STD_VER >= 20 -template -struct __unwrap_range_impl { - _LIBCPP_HIDE_FROM_ABI static constexpr auto __unwrap(_Iter __first, _Sent __sent) - requires random_access_iterator<_Iter> && sized_sentinel_for<_Sent, _Iter> - { - auto __last = ranges::next(__first, __sent); - return pair{std::__unwrap_iter(std::move(__first)), std::__unwrap_iter(std::move(__last))}; - } - - _LIBCPP_HIDE_FROM_ABI static constexpr auto __unwrap(_Iter __first, _Sent __last) { - return pair{std::move(__first), std::move(__last)}; - } - - _LIBCPP_HIDE_FROM_ABI static constexpr auto - __rewrap(_Iter __orig_iter, decltype(std::__unwrap_iter(std::move(__orig_iter))) __iter) - requires random_access_iterator<_Iter> && sized_sentinel_for<_Sent, _Iter> - { - return std::__rewrap_iter(std::move(__orig_iter), std::move(__iter)); - } - - _LIBCPP_HIDE_FROM_ABI static constexpr auto __rewrap(const _Iter&, _Iter __iter) - requires(!(random_access_iterator<_Iter> && sized_sentinel_for<_Sent, _Iter>)) - { - return __iter; - } -}; - -template -struct __unwrap_range_impl<_Iter, _Iter> { - _LIBCPP_HIDE_FROM_ABI static constexpr auto __unwrap(_Iter __first, _Iter __last) { - return pair{std::__unwrap_iter(std::move(__first)), std::__unwrap_iter(std::move(__last))}; - } - - _LIBCPP_HIDE_FROM_ABI static constexpr auto - __rewrap(_Iter __orig_iter, decltype(std::__unwrap_iter(__orig_iter)) __iter) { - return std::__rewrap_iter(std::move(__orig_iter), std::move(__iter)); - } -}; - template _LIBCPP_HIDE_FROM_ABI constexpr auto __unwrap_range(_Iter __first, _Sent __last) { - return __unwrap_range_impl<_Iter, _Sent>::__unwrap(std::move(__first), std::move(__last)); + if constexpr (is_same_v<_Iter, _Sent>) + return pair{std::__unwrap_iter(std::move(__first)), std::__unwrap_iter(std::move(__last))}; + else if constexpr (random_access_iterator<_Iter> && sized_sentinel_for<_Sent, _Iter>) { + auto __iter_last = __first + (__last - __first); + return pair{std::__unwrap_iter(std::move(__first)), std::__unwrap_iter(std::move(__iter_last))}; + } else + return pair{std::move(__first), std::move(__last)}; } template < class _Sent, class _Iter, class _Unwrapped> _LIBCPP_HIDE_FROM_ABI constexpr _Iter __rewrap_range(_Iter __orig_iter, _Unwrapped __iter) { - return __unwrap_range_impl<_Iter, _Sent>::__rewrap(std::move(__orig_iter), std::move(__iter)); + if constexpr (is_same_v<_Iter, _Sent>) + return std::__rewrap_iter(std::move(__orig_iter), std::move(__iter)); + else if constexpr (random_access_iterator<_Iter> && sized_sentinel_for<_Sent, _Iter>) + return std::__rewrap_iter(std::move(__orig_iter), std::move(__iter)); + else + return __iter; } #else // _LIBCPP_STD_VER >= 20 template ()))> diff --git a/lib/libcxx/include/__assert b/lib/libcxx/include/__assert index a9451daf47f2f39da17e0e1e3151d9c587b2d8ff..2ecd310553e716850ec2784b2ffd0fd8d8bb4633 100644 --- a/lib/libcxx/include/__assert +++ b/lib/libcxx/include/__assert @@ -20,7 +20,7 @@ #define _LIBCPP_ASSERT(expression, message) \ (__builtin_expect(static_cast(expression), 1) \ ? (void)0 \ - : _LIBCPP_ASSERTION_HANDLER(__FILE__ ":" _LIBCPP_TOSTRING( \ + : _LIBCPP_ASSERTION_HANDLER(__FILE_NAME__ ":" _LIBCPP_TOSTRING( \ __LINE__) ": libc++ Hardening assertion " _LIBCPP_TOSTRING(expression) " failed: " message "\n")) // WARNING: __builtin_assume can currently inhibit optimizations. Only add assumptions with a clear diff --git a/lib/libcxx/include/__atomic/atomic.h b/lib/libcxx/include/__atomic/atomic.h index 02528cd964a582f8a23a56ae3c2b742a10b19819..3d0ed9cc47396553a3874b8373bbb53c9e5c4415 100644 --- a/lib/libcxx/include/__atomic/atomic.h +++ b/lib/libcxx/include/__atomic/atomic.h @@ -26,9 +26,7 @@ #include <__type_traits/is_nothrow_constructible.h> #include <__type_traits/is_same.h> #include <__type_traits/is_trivially_copyable.h> -#include <__type_traits/remove_const.h> #include <__type_traits/remove_pointer.h> -#include <__type_traits/remove_volatile.h> #include <__utility/forward.h> #include @@ -297,13 +295,13 @@ struct atomic<_Tp*> : public __atomic_base<_Tp*> { } _LIBCPP_HIDE_FROM_ABI _Tp* fetch_sub(ptrdiff_t __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT { - // __atomic_fetch_add accepts function pointers, guard against them. + // __atomic_fetch_sub accepts function pointers, guard against them. static_assert(!is_function<__remove_pointer_t<_Tp> >::value, "Pointer to function isn't allowed"); return std::__cxx_atomic_fetch_sub(std::addressof(this->__a_), __op, __m); } _LIBCPP_HIDE_FROM_ABI _Tp* fetch_sub(ptrdiff_t __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT { - // __atomic_fetch_add accepts function pointers, guard against them. + // __atomic_fetch_sub accepts function pointers, guard against them. static_assert(!is_function<__remove_pointer_t<_Tp> >::value, "Pointer to function isn't allowed"); return std::__cxx_atomic_fetch_sub(std::addressof(this->__a_), __op, __m); } diff --git a/lib/libcxx/include/__atomic/atomic_flag.h b/lib/libcxx/include/__atomic/atomic_flag.h index 42864c869d22f569258fcffc2f70589f9df73112..9c3dd13d132d4c4393dd2ef3ad1b71605b75ff9c 100644 --- a/lib/libcxx/include/__atomic/atomic_flag.h +++ b/lib/libcxx/include/__atomic/atomic_flag.h @@ -11,14 +11,10 @@ #include <__atomic/atomic_sync.h> #include <__atomic/atomic_waitable_traits.h> -#include <__atomic/contention_t.h> #include <__atomic/memory_order.h> #include <__atomic/support.h> -#include <__chrono/duration.h> #include <__config> #include <__memory/addressof.h> -#include <__thread/support.h> -#include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header @@ -27,34 +23,34 @@ _LIBCPP_BEGIN_NAMESPACE_STD struct atomic_flag { - __cxx_atomic_impl<_LIBCPP_ATOMIC_FLAG_TYPE> __a_; + __cxx_atomic_impl __a_; _LIBCPP_HIDE_FROM_ABI bool test(memory_order __m = memory_order_seq_cst) const volatile _NOEXCEPT { - return _LIBCPP_ATOMIC_FLAG_TYPE(true) == __cxx_atomic_load(&__a_, __m); + return __cxx_atomic_load(&__a_, __m); } _LIBCPP_HIDE_FROM_ABI bool test(memory_order __m = memory_order_seq_cst) const _NOEXCEPT { - return _LIBCPP_ATOMIC_FLAG_TYPE(true) == __cxx_atomic_load(&__a_, __m); + return __cxx_atomic_load(&__a_, __m); } _LIBCPP_HIDE_FROM_ABI bool test_and_set(memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT { - return __cxx_atomic_exchange(&__a_, _LIBCPP_ATOMIC_FLAG_TYPE(true), __m); + return __cxx_atomic_exchange(&__a_, true, __m); } _LIBCPP_HIDE_FROM_ABI bool test_and_set(memory_order __m = memory_order_seq_cst) _NOEXCEPT { - return __cxx_atomic_exchange(&__a_, _LIBCPP_ATOMIC_FLAG_TYPE(true), __m); + return __cxx_atomic_exchange(&__a_, true, __m); } _LIBCPP_HIDE_FROM_ABI void clear(memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT { - __cxx_atomic_store(&__a_, _LIBCPP_ATOMIC_FLAG_TYPE(false), __m); + __cxx_atomic_store(&__a_, false, __m); } _LIBCPP_HIDE_FROM_ABI void clear(memory_order __m = memory_order_seq_cst) _NOEXCEPT { - __cxx_atomic_store(&__a_, _LIBCPP_ATOMIC_FLAG_TYPE(false), __m); + __cxx_atomic_store(&__a_, false, __m); } #if _LIBCPP_STD_VER >= 20 _LIBCPP_HIDE_FROM_ABI void wait(bool __v, memory_order __m = memory_order_seq_cst) const volatile _NOEXCEPT { - std::__atomic_wait(*this, _LIBCPP_ATOMIC_FLAG_TYPE(__v), __m); + std::__atomic_wait(*this, __v, __m); } _LIBCPP_HIDE_FROM_ABI void wait(bool __v, memory_order __m = memory_order_seq_cst) const _NOEXCEPT { - std::__atomic_wait(*this, _LIBCPP_ATOMIC_FLAG_TYPE(__v), __m); + std::__atomic_wait(*this, __v, __m); } _LIBCPP_HIDE_FROM_ABI void notify_one() volatile _NOEXCEPT { std::__atomic_notify_one(*this); } _LIBCPP_HIDE_FROM_ABI void notify_one() _NOEXCEPT { std::__atomic_notify_one(*this); } @@ -78,23 +74,21 @@ struct atomic_flag { #if _LIBCPP_STD_VER >= 20 template <> struct __atomic_waitable_traits { - using __value_type _LIBCPP_NODEBUG = _LIBCPP_ATOMIC_FLAG_TYPE; + using __value_type _LIBCPP_NODEBUG = bool; - static _LIBCPP_HIDE_FROM_ABI _LIBCPP_ATOMIC_FLAG_TYPE __atomic_load(const atomic_flag& __a, memory_order __order) { + static _LIBCPP_HIDE_FROM_ABI bool __atomic_load(const atomic_flag& __a, memory_order __order) { return std::__cxx_atomic_load(&__a.__a_, __order); } - static _LIBCPP_HIDE_FROM_ABI _LIBCPP_ATOMIC_FLAG_TYPE - __atomic_load(const volatile atomic_flag& __a, memory_order __order) { + static _LIBCPP_HIDE_FROM_ABI bool __atomic_load(const volatile atomic_flag& __a, memory_order __order) { return std::__cxx_atomic_load(&__a.__a_, __order); } - static _LIBCPP_HIDE_FROM_ABI const __cxx_atomic_impl<_LIBCPP_ATOMIC_FLAG_TYPE>* - __atomic_contention_address(const atomic_flag& __a) { + static _LIBCPP_HIDE_FROM_ABI const __cxx_atomic_impl* __atomic_contention_address(const atomic_flag& __a) { return std::addressof(__a.__a_); } - static _LIBCPP_HIDE_FROM_ABI const volatile __cxx_atomic_impl<_LIBCPP_ATOMIC_FLAG_TYPE>* + static _LIBCPP_HIDE_FROM_ABI const volatile __cxx_atomic_impl* __atomic_contention_address(const volatile atomic_flag& __a) { return std::addressof(__a.__a_); } diff --git a/lib/libcxx/include/__atomic/atomic_ref.h b/lib/libcxx/include/__atomic/atomic_ref.h index 69edbfe6ecadd5c989a44370a0035a5bddd74efd..93f19a740ba3a2dc9a6ba76db8a59cd4049a0014 100644 --- a/lib/libcxx/include/__atomic/atomic_ref.h +++ b/lib/libcxx/include/__atomic/atomic_ref.h @@ -30,9 +30,10 @@ #include <__cstddef/byte.h> #include <__cstddef/ptrdiff_t.h> #include <__memory/addressof.h> +#include <__memory/is_sufficiently_aligned.h> +#include <__type_traits/copy_cv.h> #include <__type_traits/has_unique_object_representation.h> #include <__type_traits/is_trivially_copyable.h> -#include #include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) @@ -224,7 +225,7 @@ public: _LIBCPP_HIDE_FROM_ABI void notify_one() const noexcept { std::__atomic_notify_one(*this); } _LIBCPP_HIDE_FROM_ABI void notify_all() const noexcept { std::__atomic_notify_all(*this); } # if _LIBCPP_STD_VER >= 26 - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Tp* address() const noexcept { return __ptr_; } + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr __copy_cv_t<_Tp, void>* address() const noexcept { return __ptr_; } # endif protected: @@ -254,10 +255,12 @@ struct atomic_ref : public __atomic_ref_base<_Tp> { _LIBCPP_HIDE_FROM_ABI explicit atomic_ref(_Tp& __obj) : __base(__obj) { _LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN( - reinterpret_cast(std::addressof(__obj)) % __base::required_alignment == 0, + std::__is_sufficiently_aligned<__base::required_alignment>(std::addressof(__obj)), "atomic_ref ctor: referenced object must be aligned to required_alignment"); } + _LIBCPP_HIDE_FROM_ABI explicit atomic_ref(_Tp&&) = delete; + _LIBCPP_HIDE_FROM_ABI atomic_ref(const atomic_ref&) noexcept = default; _LIBCPP_HIDE_FROM_ABI _Tp operator=(_Tp __desired) const noexcept { return __base::operator=(__desired); } @@ -274,10 +277,12 @@ struct atomic_ref<_Tp> : public __atomic_ref_base<_Tp> { _LIBCPP_HIDE_FROM_ABI explicit atomic_ref(_Tp& __obj) : __base(__obj) { _LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN( - reinterpret_cast(std::addressof(__obj)) % __base::required_alignment == 0, + std::__is_sufficiently_aligned<__base::required_alignment>(std::addressof(__obj)), "atomic_ref ctor: referenced object must be aligned to required_alignment"); } + _LIBCPP_HIDE_FROM_ABI explicit atomic_ref(_Tp&&) = delete; + _LIBCPP_HIDE_FROM_ABI atomic_ref(const atomic_ref&) noexcept = default; _LIBCPP_HIDE_FROM_ABI _Tp operator=(_Tp __desired) const noexcept { return __base::operator=(__desired); } @@ -320,10 +325,12 @@ struct atomic_ref<_Tp> : public __atomic_ref_base<_Tp> { _LIBCPP_HIDE_FROM_ABI explicit atomic_ref(_Tp& __obj) : __base(__obj) { _LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN( - reinterpret_cast(std::addressof(__obj)) % __base::required_alignment == 0, + std::__is_sufficiently_aligned<__base::required_alignment>(std::addressof(__obj)), "atomic_ref ctor: referenced object must be aligned to required_alignment"); } + _LIBCPP_HIDE_FROM_ABI explicit atomic_ref(_Tp&&) = delete; + _LIBCPP_HIDE_FROM_ABI atomic_ref(const atomic_ref&) noexcept = default; _LIBCPP_HIDE_FROM_ABI _Tp operator=(_Tp __desired) const noexcept { return __base::operator=(__desired); } @@ -367,6 +374,8 @@ struct atomic_ref<_Tp*> : public __atomic_ref_base<_Tp*> { _LIBCPP_HIDE_FROM_ABI explicit atomic_ref(_Tp*& __ptr) : __base(__ptr) {} + _LIBCPP_HIDE_FROM_ABI explicit atomic_ref(_Tp*&&) = delete; + _LIBCPP_HIDE_FROM_ABI _Tp* operator=(_Tp* __desired) const noexcept { return __base::operator=(__desired); } atomic_ref& operator=(const atomic_ref&) = delete; diff --git a/lib/libcxx/include/__atomic/atomic_sync.h b/lib/libcxx/include/__atomic/atomic_sync.h index 1234cdea504a27343390bc68bb5cd5a5fad561c6..c96cd63a82e3e6cac0ca4cb7f22b8e2c79b49ef0 100644 --- a/lib/libcxx/include/__atomic/atomic_sync.h +++ b/lib/libcxx/include/__atomic/atomic_sync.h @@ -12,28 +12,25 @@ #include <__atomic/atomic_waitable_traits.h> #include <__atomic/contention_t.h> #include <__atomic/memory_order.h> -#include <__atomic/to_gcc_order.h> #include <__chrono/duration.h> #include <__config> #include <__memory/addressof.h> #include <__thread/poll_with_backoff.h> -#include <__type_traits/conjunction.h> #include <__type_traits/decay.h> -#include <__type_traits/invoke.h> -#include <__type_traits/is_same.h> -#include <__type_traits/void_t.h> -#include <__utility/declval.h> #include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header #endif -_LIBCPP_BEGIN_NAMESPACE_STD - #if _LIBCPP_STD_VER >= 20 + +_LIBCPP_BEGIN_NAMESPACE_STD + # if _LIBCPP_HAS_THREADS +_LIBCPP_BEGIN_EXPLICIT_ABI_ANNOTATIONS + # if !_LIBCPP_AVAILABILITY_HAS_NEW_SYNC // old dylib interface kept for backwards compatibility @@ -79,6 +76,8 @@ _LIBCPP_AVAILABILITY_NEW_SYNC _LIBCPP_EXPORTED_FROM_ABI void __atomic_notify_one template _LIBCPP_AVAILABILITY_NEW_SYNC _LIBCPP_EXPORTED_FROM_ABI void __atomic_notify_all_native(const void*) _NOEXCEPT; +_LIBCPP_END_EXPLICIT_ABI_ANNOTATIONS + # if _LIBCPP_AVAILABILITY_HAS_NEW_SYNC template @@ -260,8 +259,8 @@ _LIBCPP_HIDE_FROM_ABI void __atomic_wait(_AtomicWaitable& __a, _Tp __val, memory }); } -#endif // C++20 - _LIBCPP_END_NAMESPACE_STD +#endif // _LIBCPP_STD_VER >= 20 + #endif // _LIBCPP___ATOMIC_ATOMIC_SYNC_H diff --git a/lib/libcxx/include/__atomic/atomic_sync_timed.h b/lib/libcxx/include/__atomic/atomic_sync_timed.h index 7daff73db7ebde42cfda9b05b5e0f1ca44649cfa..4fed3bf53f6881346896c4ca87a369ec92acd21f 100644 --- a/lib/libcxx/include/__atomic/atomic_sync_timed.h +++ b/lib/libcxx/include/__atomic/atomic_sync_timed.h @@ -12,20 +12,12 @@ #include <__atomic/atomic_waitable_traits.h> #include <__atomic/contention_t.h> #include <__atomic/memory_order.h> -#include <__atomic/to_gcc_order.h> #include <__chrono/duration.h> #include <__config> #include <__memory/addressof.h> #include <__thread/poll_with_backoff.h> #include <__thread/timed_backoff_policy.h> -#include <__type_traits/conjunction.h> #include <__type_traits/decay.h> -#include <__type_traits/has_unique_object_representation.h> -#include <__type_traits/invoke.h> -#include <__type_traits/is_same.h> -#include <__type_traits/is_trivially_copyable.h> -#include <__type_traits/void_t.h> -#include <__utility/declval.h> #include #include @@ -33,11 +25,13 @@ # pragma GCC system_header #endif +#if _LIBCPP_STD_VER >= 20 && _LIBCPP_HAS_THREADS + _LIBCPP_BEGIN_NAMESPACE_STD -#if _LIBCPP_STD_VER >= 20 -# if _LIBCPP_HAS_THREADS && _LIBCPP_AVAILABILITY_HAS_NEW_SYNC +# if _LIBCPP_AVAILABILITY_HAS_NEW_SYNC +_LIBCPP_BEGIN_EXPLICIT_ABI_ANNOTATIONS _LIBCPP_AVAILABILITY_NEW_SYNC _LIBCPP_EXPORTED_FROM_ABI __cxx_contention_t __atomic_monitor_global(void const* __address) _NOEXCEPT; @@ -49,6 +43,7 @@ _LIBCPP_AVAILABILITY_NEW_SYNC _LIBCPP_EXPORTED_FROM_ABI void __atomic_wait_globa template _LIBCPP_AVAILABILITY_NEW_SYNC _LIBCPP_EXPORTED_FROM_ABI void __atomic_wait_native_with_timeout(void const* __address, void const* __old_value, uint64_t __timeout_ns) _NOEXCEPT; +_LIBCPP_END_EXPLICIT_ABI_ANNOTATIONS template struct __atomic_wait_timed_backoff_impl { @@ -116,7 +111,7 @@ _LIBCPP_HIDE_FROM_ABI bool __atomic_wait_unless_with_timeout( return __poll_result == __poll_with_backoff_results::__poll_success; } -# elif _LIBCPP_HAS_THREADS // _LIBCPP_HAS_THREADS && _LIBCPP_AVAILABILITY_HAS_NEW_SYNC +# else // _LIBCPP_AVAILABILITY_HAS_NEW_SYNC template _LIBCPP_HIDE_FROM_ABI bool __atomic_wait_unless_with_timeout( @@ -135,10 +130,10 @@ _LIBCPP_HIDE_FROM_ABI bool __atomic_wait_unless_with_timeout( return __res == __poll_with_backoff_results::__poll_success; } -# endif // _LIBCPP_HAS_THREADS && _LIBCPP_AVAILABILITY_HAS_NEW_SYNC - -#endif // C++20 +# endif // _LIBCPP_AVAILABILITY_HAS_NEW_SYNC _LIBCPP_END_NAMESPACE_STD +#endif // _LIBCPP_STD_VER >= 20 && _LIBCPP_HAS_THREADS + #endif // _LIBCPP___ATOMIC_ATOMIC_SYNC_TIMED_H diff --git a/lib/libcxx/include/__atomic/atomic_waitable_traits.h b/lib/libcxx/include/__atomic/atomic_waitable_traits.h index 849c33122bff4c5101fffc89d55ff30b922eaf88..ed26a60df982ddc5b54b2ad7846f3dd51a0f5c1a 100644 --- a/lib/libcxx/include/__atomic/atomic_waitable_traits.h +++ b/lib/libcxx/include/__atomic/atomic_waitable_traits.h @@ -16,18 +16,16 @@ #include <__type_traits/has_unique_object_representation.h> #include <__type_traits/is_same.h> #include <__type_traits/is_trivially_copyable.h> -#include <__type_traits/void_t.h> -#include <__utility/declval.h> #include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header #endif -_LIBCPP_BEGIN_NAMESPACE_STD - #if _LIBCPP_STD_VER >= 20 +_LIBCPP_BEGIN_NAMESPACE_STD + // The customisation points to enable the following functions: // - __atomic_wait // - __atomic_wait_unless @@ -96,8 +94,8 @@ concept __has_native_atomic_wait = is_same_v<_Tp, __cxx_contention_t>; # endif // _LIBCPP_ABI_ATOMIC_WAIT_NATIVE_BY_SIZE -#endif // C++20 - _LIBCPP_END_NAMESPACE_STD +#endif // _LIBCPP_STD_VER >= 20 + #endif // _LIBCPP___ATOMIC_ATOMIC_WAITABLE_TRAITS_H diff --git a/lib/libcxx/include/__atomic/contention_t.h b/lib/libcxx/include/__atomic/contention_t.h index b7e370439e67a6ee580b5c558f05b209497b383c..c6d2570696079a8e511baf13114332cf1c4249d7 100644 --- a/lib/libcxx/include/__atomic/contention_t.h +++ b/lib/libcxx/include/__atomic/contention_t.h @@ -25,7 +25,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD // instead. #if defined(_LIBCPP_ABI_ATOMIC_WAIT_NATIVE_BY_SIZE) -# ifdef __linux__ +# if defined(__linux__) || defined(__Fuchsia__) using __cxx_contention_t _LIBCPP_NODEBUG = int32_t; # elif defined(__APPLE__) using __cxx_contention_t _LIBCPP_NODEBUG = int64_t; @@ -37,15 +37,15 @@ using __cxx_contention_t _LIBCPP_NODEBUG = int32_t; using __cxx_contention_t _LIBCPP_NODEBUG = int64_t; # else using __cxx_contention_t _LIBCPP_NODEBUG = int64_t; -# endif // __linux__ +# endif // __linux__ || __Fuchsia__ #else // _LIBCPP_ABI_ATOMIC_WAIT_NATIVE_BY_SIZE -# if defined(__linux__) || (defined(_AIX) && !defined(__64BIT__)) +# if defined(__linux__) || defined(__Fuchsia__) || (defined(_AIX) && !defined(__64BIT__)) using __cxx_contention_t _LIBCPP_NODEBUG = int32_t; # else using __cxx_contention_t _LIBCPP_NODEBUG = int64_t; -# endif // __linux__ || (_AIX && !__64BIT__) +# endif // __linux__ || __Fuchsia__ || (_AIX && !__64BIT__) #endif // _LIBCPP_ABI_ATOMIC_WAIT_NATIVE_BY_SIZE diff --git a/lib/libcxx/include/__atomic/floating_point_helper.h b/lib/libcxx/include/__atomic/floating_point_helper.h index 8762ec234b189e5284804ab3026e6a2bc08a3a2b..4f21006dd27dc14b3750a00330f334fabc1e6d3a 100644 --- a/lib/libcxx/include/__atomic/floating_point_helper.h +++ b/lib/libcxx/include/__atomic/floating_point_helper.h @@ -17,10 +17,10 @@ # pragma GCC system_header #endif -_LIBCPP_BEGIN_NAMESPACE_STD - #if _LIBCPP_STD_VER >= 20 +_LIBCPP_BEGIN_NAMESPACE_STD + template _LIBCPP_HIDE_FROM_ABI constexpr bool __is_fp80_long_double() { // Only x87-fp80 long double has 64-bit mantissa @@ -48,8 +48,8 @@ _LIBCPP_HIDE_FROM_ABI constexpr bool __has_rmw_builtin() { # endif } -#endif - _LIBCPP_END_NAMESPACE_STD +#endif // _LIBCPP_STD_VER >= 20 + #endif // _LIBCPP___ATOMIC_FLOATING_POINT_HELPER_H diff --git a/lib/libcxx/include/__atomic/support.h b/lib/libcxx/include/__atomic/support.h index 99d0f6aa543ca4df5a9071269adb813289465c9f..053ad54aa6ce57ab331ffcf6fb8e87d8cbf2ae3c 100644 --- a/lib/libcxx/include/__atomic/support.h +++ b/lib/libcxx/include/__atomic/support.h @@ -102,9 +102,9 @@ // clang-format on // -#if _LIBCPP_HAS_GCC_ATOMIC_IMP +#ifdef _LIBCPP_COMPILER_GCC # include <__atomic/support/gcc.h> -#elif _LIBCPP_HAS_C_ATOMIC_IMP +#else # include <__atomic/support/c11.h> #endif diff --git a/lib/libcxx/include/__bit/bit_cast.h b/lib/libcxx/include/__bit/bit_cast.h index 735025065a729b6d04536462e7122d151b7b4658..72b558f1446c3e825e83a8b9f6b7f7ba36e1bc8a 100644 --- a/lib/libcxx/include/__bit/bit_cast.h +++ b/lib/libcxx/include/__bit/bit_cast.h @@ -17,18 +17,16 @@ # pragma GCC system_header #endif -_LIBCPP_BEGIN_NAMESPACE_STD - #ifndef _LIBCPP_CXX03_LANG +_LIBCPP_BEGIN_NAMESPACE_STD + template [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI constexpr _ToType __bit_cast(const _FromType& __from) noexcept { return __builtin_bit_cast(_ToType, __from); } -#endif // _LIBCPP_CXX03_LANG - -#if _LIBCPP_STD_VER >= 20 +# if _LIBCPP_STD_VER >= 20 template requires(sizeof(_ToType) == sizeof(_FromType) && is_trivially_copyable_v<_ToType> && @@ -37,8 +35,10 @@ template return __builtin_bit_cast(_ToType, __from); } -#endif // _LIBCPP_STD_VER >= 20 +# endif // _LIBCPP_STD_VER >= 20 _LIBCPP_END_NAMESPACE_STD +#endif // _LIBCPP_CXX03_LANG + #endif // _LIBCPP___BIT_BIT_CAST_H diff --git a/lib/libcxx/include/__bit/bit_ceil.h b/lib/libcxx/include/__bit/bit_ceil.h index 99881a853829036e99ea20bd31b399eafbd8089c..73238eb2c37d52e0d3e2ecdc16d2fa4059667f6d 100644 --- a/lib/libcxx/include/__bit/bit_ceil.h +++ b/lib/libcxx/include/__bit/bit_ceil.h @@ -19,10 +19,10 @@ # pragma GCC system_header #endif -_LIBCPP_BEGIN_NAMESPACE_STD - #if _LIBCPP_STD_VER >= 17 +_LIBCPP_BEGIN_NAMESPACE_STD + template [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Tp __bit_ceil(_Tp __t) noexcept { if (__t < 2) @@ -47,8 +47,9 @@ template <__unsigned_integer _Tp> } # endif // _LIBCPP_STD_VER >= 20 -#endif // _LIBCPP_STD_VER >= 17 _LIBCPP_END_NAMESPACE_STD +#endif // _LIBCPP_STD_VER >= 17 + #endif // _LIBCPP___BIT_BIT_CEIL_H diff --git a/lib/libcxx/include/__bit/byteswap.h b/lib/libcxx/include/__bit/byteswap.h index d761e6a6fdb46ed35b8c8f69071e14d6bc7827a2..43490d080910bffbf9f67e06da2027eb627d4a0b 100644 --- a/lib/libcxx/include/__bit/byteswap.h +++ b/lib/libcxx/include/__bit/byteswap.h @@ -12,7 +12,11 @@ #include <__concepts/arithmetic.h> #include <__config> +#include <__type_traits/is_same.h> +#include <__type_traits/remove_cv.h> +#include #include +#include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header @@ -24,26 +28,41 @@ _LIBCPP_BEGIN_NAMESPACE_STD template [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Tp byteswap(_Tp __val) noexcept { + // [bit.byteswap]/Mandates: T does not have padding bits. + // bool is grandfathered: every shipping implementation admits it and the + // size-1 identity path can't shuffle padding bits into value positions. + // LWG 4583 proposes relaxing this to allow byte-aligned padding (e.g. + // _BitInt(48) where 2 whole bytes are padding); revisit once it resolves. + static_assert(is_same_v, bool> || + numeric_limits<_Tp>::digits + numeric_limits<_Tp>::is_signed == sizeof(_Tp) * CHAR_BIT, + "std::byteswap requires T to have no padding bits"); + if constexpr (sizeof(_Tp) == 1) { return __val; +# if __has_builtin(__builtin_bswapg) + } else { + return __builtin_bswapg(__val); + } +# else } else if constexpr (sizeof(_Tp) == 2) { return __builtin_bswap16(__val); } else if constexpr (sizeof(_Tp) == 4) { return __builtin_bswap32(__val); } else if constexpr (sizeof(_Tp) == 8) { return __builtin_bswap64(__val); -# if _LIBCPP_HAS_INT128 +# if _LIBCPP_HAS_INT128 } else if constexpr (sizeof(_Tp) == 16) { -# if __has_builtin(__builtin_bswap128) +# if __has_builtin(__builtin_bswap128) return __builtin_bswap128(__val); -# else - return static_cast<_Tp>(byteswap(static_cast(__val))) << 64 | +# else + return (static_cast<_Tp>(byteswap(static_cast(__val))) << 64) | static_cast<_Tp>(byteswap(static_cast(__val >> 64))); -# endif // __has_builtin(__builtin_bswap128) -# endif // _LIBCPP_HAS_INT128 +# endif // __has_builtin(__builtin_bswap128) +# endif // _LIBCPP_HAS_INT128 } else { static_assert(sizeof(_Tp) == 0, "byteswap is unimplemented for integral types of this size"); } +# endif // __has_builtin(__builtin_bswapg) } #endif // _LIBCPP_STD_VER >= 23 diff --git a/lib/libcxx/include/__bit_reference b/lib/libcxx/include/__bit_reference index 8daf3a2baafcda89dbba1ede7a5c7650fe9a71ba..692686f1584d079ad5a41baf98d40995484f7502 100644 --- a/lib/libcxx/include/__bit_reference +++ b/lib/libcxx/include/__bit_reference @@ -16,10 +16,10 @@ #include <__algorithm/copy_n.h> #include <__algorithm/equal.h> #include <__algorithm/fill_n.h> +#include <__algorithm/in_out_result.h> #include <__algorithm/min.h> #include <__algorithm/rotate.h> #include <__algorithm/specialized_algorithms.h> -#include <__algorithm/swap_ranges.h> #include <__assert> #include <__bit/countr.h> #include <__compare/ordering.h> @@ -35,7 +35,6 @@ #include <__type_traits/desugars_to.h> #include <__type_traits/enable_if.h> #include <__type_traits/is_constant_evaluated.h> -#include <__type_traits/is_same.h> #include <__type_traits/is_unsigned.h> #include <__type_traits/void_t.h> #include <__utility/pair.h> @@ -166,9 +165,6 @@ public: } _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void flip() _NOEXCEPT { *__seg_ ^= __mask_; } - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __bit_iterator<_Cp, false> operator&() const _NOEXCEPT { - return __bit_iterator<_Cp, false>(__seg_, static_cast(std::__countr_zero(__mask_))); - } private: _LIBCPP_HIDE_FROM_ABI @@ -340,7 +336,7 @@ public: } #endif - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 reference operator*() const _NOEXCEPT { + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 reference operator*() const _NOEXCEPT { _LIBCPP_ASSERT_INTERNAL(__ctz_ < __bits_per_word, "Dereferencing an invalid __bit_iterator."); return __conditional_t<_IsConst, __bit_const_reference<_Cp>, __bit_reference<_Cp> >( __seg_, __storage_type(1) << __ctz_); @@ -393,29 +389,32 @@ public: return *this += -__n; } - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __bit_iterator operator+(difference_type __n) const { + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __bit_iterator + operator+(difference_type __n) const { __bit_iterator __t(*this); __t += __n; return __t; } - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __bit_iterator operator-(difference_type __n) const { + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __bit_iterator + operator-(difference_type __n) const { __bit_iterator __t(*this); __t -= __n; return __t; } - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 friend __bit_iterator + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 friend __bit_iterator operator+(difference_type __n, const __bit_iterator& __it) { return __it + __n; } - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 friend difference_type + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 friend difference_type operator-(const __bit_iterator& __x, const __bit_iterator& __y) { return (__x.__seg_ - __y.__seg_) * __bits_per_word + __x.__ctz_ - __y.__ctz_; } - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 reference operator[](difference_type __n) const { + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 reference + operator[](difference_type __n) const { return *(*this + __n); } @@ -487,15 +486,6 @@ private: __bit_iterator<_Dp, _IC> __first, __bit_iterator<_Dp, _IC> __last, __bit_iterator<_Dp, false> __result); template friend struct __copy_backward_impl; - template - _LIBCPP_CONSTEXPR_SINCE_CXX20 friend __bit_iterator<_Cr, false> - __swap_ranges_aligned(__bit_iterator<_Cl, false>, __bit_iterator<_Cl, false>, __bit_iterator<_Cr, false>); - template - _LIBCPP_CONSTEXPR_SINCE_CXX20 friend __bit_iterator<_Cr, false> - __swap_ranges_unaligned(__bit_iterator<_Cl, false>, __bit_iterator<_Cl, false>, __bit_iterator<_Cr, false>); - template - _LIBCPP_CONSTEXPR_SINCE_CXX20 friend pair<__bit_iterator<_Cl, false>, __bit_iterator<_Cr, false> > - __swap_ranges(__bit_iterator<_Cl, false>, __bit_iterator<_Cl, false>, __bit_iterator<_Cr, false>); template _LIBCPP_CONSTEXPR_SINCE_CXX20 friend pair<__bit_iterator<_Dp, false>, __bit_iterator<_Dp, false> > __rotate(__bit_iterator<_Dp, false>, __bit_iterator<_Dp, false>, __bit_iterator<_Dp, false>); @@ -718,13 +708,164 @@ struct __specialized_algorithm<_Algorithm::__copy, } _LIBCPP_HIDE_FROM_ABI - _LIBCPP_CONSTEXPR_SINCE_CXX20 static pair<__bit_iterator<_Cp, _IsConst>, __bit_iterator<_Cp, false> > + _LIBCPP_CONSTEXPR_SINCE_CXX20 static __in_out_result<__bit_iterator<_Cp, _IsConst>, __bit_iterator<_Cp, false> > operator()(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, __bit_iterator<_Cp, false> __result) { if (__first.__ctz_ == __result.__ctz_) - return std::make_pair(__last, __aligned_impl(__first, __last, __result)); - return std::make_pair(__last, __unaligned_impl(__first, __last, __result)); + return {__last, __aligned_impl(__first, __last, __result)}; + return {__last, __unaligned_impl(__first, __last, __result)}; + } +}; + +template +struct __specialized_algorithm<_Algorithm::__swap_ranges, + __iterator_pair<__bit_iterator<_Cl, false>, __bit_iterator<_Cl, false> >, + __single_iterator<__bit_iterator<_Cr, false> > > { + static const bool __has_algorithm = true; + + _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR_SINCE_CXX20 __bit_iterator<_Cr, false> __aligned_impl( + __bit_iterator<_Cl, false> __first, __bit_iterator<_Cl, false> __last, __bit_iterator<_Cr, false> __result) { + using _I1 = __bit_iterator<_Cl, false>; + using difference_type = typename _I1::difference_type; + using __storage_type = typename _I1::__storage_type; + + const int __bits_per_word = _I1::__bits_per_word; + difference_type __n = __last - __first; + if (__n > 0) { + // do first word + if (__first.__ctz_ != 0) { + unsigned __clz = __bits_per_word - __first.__ctz_; + difference_type __dn = std::min(static_cast(__clz), __n); + __n -= __dn; + __storage_type __m = (~__storage_type(0) << __first.__ctz_) & (~__storage_type(0) >> (__clz - __dn)); + __storage_type __b1 = *__first.__seg_ & __m; + *__first.__seg_ &= ~__m; + __storage_type __b2 = *__result.__seg_ & __m; + *__result.__seg_ &= ~__m; + *__result.__seg_ |= __b1; + *__first.__seg_ |= __b2; + __result.__seg_ += (__dn + __result.__ctz_) / __bits_per_word; + __result.__ctz_ = static_cast((__dn + __result.__ctz_) % __bits_per_word); + ++__first.__seg_; + // __first.__ctz_ = 0; + } + // __first.__ctz_ == 0; + // do middle words + for (; __n >= __bits_per_word; __n -= __bits_per_word, ++__first.__seg_, ++__result.__seg_) + swap(*__first.__seg_, *__result.__seg_); + // do last word + if (__n > 0) { + __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n); + __storage_type __b1 = *__first.__seg_ & __m; + *__first.__seg_ &= ~__m; + __storage_type __b2 = *__result.__seg_ & __m; + *__result.__seg_ &= ~__m; + *__result.__seg_ |= __b1; + *__first.__seg_ |= __b2; + __result.__ctz_ = static_cast(__n); + } + } + return __result; + } + + _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR_SINCE_CXX20 __bit_iterator<_Cr, false> __unaligned_impl( + __bit_iterator<_Cl, false> __first, __bit_iterator<_Cl, false> __last, __bit_iterator<_Cr, false> __result) { + using _I1 = __bit_iterator<_Cl, false>; + using difference_type = typename _I1::difference_type; + using __storage_type = typename _I1::__storage_type; + + const int __bits_per_word = _I1::__bits_per_word; + difference_type __n = __last - __first; + if (__n > 0) { + // do first word + if (__first.__ctz_ != 0) { + unsigned __clz_f = __bits_per_word - __first.__ctz_; + difference_type __dn = std::min(static_cast(__clz_f), __n); + __n -= __dn; + __storage_type __m = (~__storage_type(0) << __first.__ctz_) & (~__storage_type(0) >> (__clz_f - __dn)); + __storage_type __b1 = *__first.__seg_ & __m; + *__first.__seg_ &= ~__m; + unsigned __clz_r = __bits_per_word - __result.__ctz_; + __storage_type __ddn = std::min<__storage_type>(__dn, __clz_r); + __m = (~__storage_type(0) << __result.__ctz_) & (~__storage_type(0) >> (__clz_r - __ddn)); + __storage_type __b2 = *__result.__seg_ & __m; + *__result.__seg_ &= ~__m; + if (__result.__ctz_ > __first.__ctz_) { + unsigned __s = __result.__ctz_ - __first.__ctz_; + *__result.__seg_ |= __b1 << __s; + *__first.__seg_ |= __b2 >> __s; + } else { + unsigned __s = __first.__ctz_ - __result.__ctz_; + *__result.__seg_ |= __b1 >> __s; + *__first.__seg_ |= __b2 << __s; + } + __result.__seg_ += (__ddn + __result.__ctz_) / __bits_per_word; + __result.__ctz_ = static_cast((__ddn + __result.__ctz_) % __bits_per_word); + __dn -= __ddn; + if (__dn > 0) { + __m = ~__storage_type(0) >> (__bits_per_word - __dn); + __b2 = *__result.__seg_ & __m; + *__result.__seg_ &= ~__m; + unsigned __s = __first.__ctz_ + __ddn; + *__result.__seg_ |= __b1 >> __s; + *__first.__seg_ |= __b2 << __s; + __result.__ctz_ = static_cast(__dn); + } + ++__first.__seg_; + // __first.__ctz_ = 0; + } + // __first.__ctz_ == 0; + // do middle words + __storage_type __m = ~__storage_type(0) << __result.__ctz_; + unsigned __clz_r = __bits_per_word - __result.__ctz_; + for (; __n >= __bits_per_word; __n -= __bits_per_word, ++__first.__seg_) { + __storage_type __b1 = *__first.__seg_; + __storage_type __b2 = *__result.__seg_ & __m; + *__result.__seg_ &= ~__m; + *__result.__seg_ |= __b1 << __result.__ctz_; + *__first.__seg_ = __b2 >> __result.__ctz_; + ++__result.__seg_; + __b2 = *__result.__seg_ & ~__m; + *__result.__seg_ &= __m; + *__result.__seg_ |= __b1 >> __clz_r; + *__first.__seg_ |= __b2 << __clz_r; + } + // do last word + if (__n > 0) { + __m = ~__storage_type(0) >> (__bits_per_word - __n); + __storage_type __b1 = *__first.__seg_ & __m; + *__first.__seg_ &= ~__m; + __storage_type __dn = std::min<__storage_type>(__n, __clz_r); + __m = (~__storage_type(0) << __result.__ctz_) & (~__storage_type(0) >> (__clz_r - __dn)); + __storage_type __b2 = *__result.__seg_ & __m; + *__result.__seg_ &= ~__m; + *__result.__seg_ |= __b1 << __result.__ctz_; + *__first.__seg_ |= __b2 >> __result.__ctz_; + __result.__seg_ += (__dn + __result.__ctz_) / __bits_per_word; + __result.__ctz_ = static_cast((__dn + __result.__ctz_) % __bits_per_word); + __n -= __dn; + if (__n > 0) { + __m = ~__storage_type(0) >> (__bits_per_word - __n); + __b2 = *__result.__seg_ & __m; + *__result.__seg_ &= ~__m; + *__result.__seg_ |= __b1 >> __dn; + *__first.__seg_ |= __b2 << __dn; + __result.__ctz_ = static_cast(__n); + } + } + } + return __result; + } + + _LIBCPP_HIDE_FROM_ABI static + _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<__bit_iterator<_Cl, false>, __bit_iterator<_Cr, false> > + operator()(__bit_iterator<_Cl, false> __first1, + __bit_iterator<_Cl, false> __last1, + __bit_iterator<_Cr, false> __first2) { + if (__first1.__ctz_ == __first2.__ctz_) + return std::make_pair(__last1, __aligned_impl(__first1, __last1, __first2)); + return std::make_pair(__last1, __unaligned_impl(__first1, __last1, __first2)); } }; diff --git a/lib/libcxx/include/__charconv/from_chars_floating_point.h b/lib/libcxx/include/__charconv/from_chars_floating_point.h index 811e518a81db70c92bb581c56e85a84ed0aa6201..ed7c54ae582612aa33ec9b76eed63fb98489daf9 100644 --- a/lib/libcxx/include/__charconv/from_chars_floating_point.h +++ b/lib/libcxx/include/__charconv/from_chars_floating_point.h @@ -35,6 +35,7 @@ struct __from_chars_result { errc __ec; }; +_LIBCPP_BEGIN_EXPLICIT_ABI_ANNOTATIONS template _LIBCPP_EXPORTED_FROM_ABI __from_chars_result<_Fp> __from_chars_floating_point( _LIBCPP_NOESCAPE const char* __first, _LIBCPP_NOESCAPE const char* __last, chars_format __fmt); @@ -44,6 +45,7 @@ extern template __from_chars_result __from_chars_floating_point( extern template __from_chars_result __from_chars_floating_point( _LIBCPP_NOESCAPE const char* __first, _LIBCPP_NOESCAPE const char* __last, chars_format __fmt); +_LIBCPP_END_EXPLICIT_ABI_ANNOTATIONS template _LIBCPP_HIDE_FROM_ABI from_chars_result diff --git a/lib/libcxx/include/__charconv/from_chars_integral.h b/lib/libcxx/include/__charconv/from_chars_integral.h index 903e892cab85b2254dcf1b4237cf9fef5cedcede..3063c0978c8fa3bd837c934d98e1b79e8f9b6f1f 100644 --- a/lib/libcxx/include/__charconv/from_chars_integral.h +++ b/lib/libcxx/include/__charconv/from_chars_integral.h @@ -10,12 +10,10 @@ #ifndef _LIBCPP___CHARCONV_FROM_CHARS_INTEGRAL_H #define _LIBCPP___CHARCONV_FROM_CHARS_INTEGRAL_H -#include <__algorithm/copy_n.h> #include <__assert> #include <__charconv/from_chars_result.h> #include <__charconv/traits.h> #include <__config> -#include <__memory/addressof.h> #include <__system_error/errc.h> #include <__type_traits/enable_if.h> #include <__type_traits/is_integral.h> @@ -56,8 +54,7 @@ __sign_combinator(_It __first, _It __last, _Tp& __value, _Fn __f, _Ts... __args) if (__neg) { if (__x <= std::__complement(std::__to_unsigned_like(__tl::min()))) { - __x = std::__complement(__x); - std::copy_n(std::addressof(__x), 1, std::addressof(__value)); + __value = std::__complement(__x); return __r; } } else { diff --git a/lib/libcxx/include/__charconv/to_chars.h b/lib/libcxx/include/__charconv/to_chars.h index 8ef09af737559fe6d1ec6a42a49451314425ac0b..0a94ba14addc1d549c48469042dfaa2c928c68dc 100644 --- a/lib/libcxx/include/__charconv/to_chars.h +++ b/lib/libcxx/include/__charconv/to_chars.h @@ -18,8 +18,4 @@ # pragma GCC system_header #endif -_LIBCPP_BEGIN_NAMESPACE_STD - -_LIBCPP_END_NAMESPACE_STD - #endif // _LIBCPP___CHARCONV_TO_CHARS diff --git a/lib/libcxx/include/__charconv/to_chars_floating_point.h b/lib/libcxx/include/__charconv/to_chars_floating_point.h index 118f316b21a10233f237dceac5727281db1545c8..ca997f85526f9da621ce6526b453b4175f28581c 100644 --- a/lib/libcxx/include/__charconv/to_chars_floating_point.h +++ b/lib/libcxx/include/__charconv/to_chars_floating_point.h @@ -19,6 +19,7 @@ #endif _LIBCPP_BEGIN_NAMESPACE_STD +_LIBCPP_BEGIN_EXPLICIT_ABI_ANNOTATIONS #if _LIBCPP_STD_VER >= 17 @@ -50,6 +51,7 @@ _LIBCPP_AVAILABILITY_TO_CHARS_FLOATING_POINT _LIBCPP_EXPORTED_FROM_ABI to_chars_ to_chars(char* __first, char* __last, long double __value, chars_format __fmt, int __precision); #endif // _LIBCPP_STD_VER >= 17 +_LIBCPP_END_EXPLICIT_ABI_ANNOTATIONS _LIBCPP_END_NAMESPACE_STD #endif // _LIBCPP___CHARCONV_TO_CHARS_FLOATING_POINT_H diff --git a/lib/libcxx/include/__chrono/convert_to_tm.h b/lib/libcxx/include/__chrono/convert_to_tm.h index 817e6747a789fae799a6c52d387991a0c83665c8..16e1415238c2b980d0ba5c4d91992b90bd569795 100644 --- a/lib/libcxx/include/__chrono/convert_to_tm.h +++ b/lib/libcxx/include/__chrono/convert_to_tm.h @@ -127,7 +127,10 @@ _LIBCPP_HIDE_FROM_ABI _Tm __convert_to_tm(chrono::tai_time<_Duration> __tp) { template _LIBCPP_HIDE_FROM_ABI _Tm __convert_to_tm(chrono::gps_time<_Duration> __tp) { - return std::__convert_to_tm<_Tm>(chrono::utc_clock::to_sys(chrono::gps_clock::to_utc(__tp))); + using _Rp = common_type_t<_Duration, chrono::seconds>; + // The time between the GPS epoch (1980-01-06) and UNIX epoch (1970-01-01). + constexpr chrono::seconds __offset{3657 * 24 * 60 * 60}; + return std::__convert_to_tm<_Tm>(chrono::sys_time<_Rp>{__tp.time_since_epoch() + __offset}); } # endif // _LIBCPP_HAS_EXPERIMENTAL_TZDB diff --git a/lib/libcxx/include/__chrono/day.h b/lib/libcxx/include/__chrono/day.h index 46822c599192d0d46e5e7b21b4869a64c114ca25..58fdc72616cb64e1274aeef9317601165810dc21 100644 --- a/lib/libcxx/include/__chrono/day.h +++ b/lib/libcxx/include/__chrono/day.h @@ -55,7 +55,7 @@ public: _LIBCPP_HIDE_FROM_ABI constexpr day& operator+=(const days& __dd) noexcept; _LIBCPP_HIDE_FROM_ABI constexpr day& operator-=(const days& __dd) noexcept; _LIBCPP_HIDE_FROM_ABI explicit inline constexpr operator unsigned() const noexcept { return __d_; } - _LIBCPP_HIDE_FROM_ABI inline constexpr bool ok() const noexcept { return __d_ >= 1 && __d_ <= 31; } + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr bool ok() const noexcept { return __d_ >= 1 && __d_ <= 31; } }; _LIBCPP_HIDE_FROM_ABI inline constexpr bool operator==(const day& __lhs, const day& __rhs) noexcept { @@ -66,19 +66,19 @@ _LIBCPP_HIDE_FROM_ABI inline constexpr strong_ordering operator<=>(const day& __ return static_cast(__lhs) <=> static_cast(__rhs); } -_LIBCPP_HIDE_FROM_ABI inline constexpr day operator+(const day& __lhs, const days& __rhs) noexcept { +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr day operator+(const day& __lhs, const days& __rhs) noexcept { return day(static_cast(__lhs) + __rhs.count()); } -_LIBCPP_HIDE_FROM_ABI inline constexpr day operator+(const days& __lhs, const day& __rhs) noexcept { +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr day operator+(const days& __lhs, const day& __rhs) noexcept { return __rhs + __lhs; } -_LIBCPP_HIDE_FROM_ABI inline constexpr day operator-(const day& __lhs, const days& __rhs) noexcept { +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr day operator-(const day& __lhs, const days& __rhs) noexcept { return __lhs + -__rhs; } -_LIBCPP_HIDE_FROM_ABI inline constexpr days operator-(const day& __lhs, const day& __rhs) noexcept { +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr days operator-(const day& __lhs, const day& __rhs) noexcept { return days(static_cast(static_cast(__lhs)) - static_cast(static_cast(__rhs))); } @@ -98,7 +98,9 @@ _LIBCPP_HIDE_FROM_ABI inline constexpr day& day::operator-=(const days& __dd) no template <> struct hash { - _LIBCPP_HIDE_FROM_ABI static size_t operator()(const chrono::day& __d) noexcept { return static_cast(__d); } + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static size_t operator()(const chrono::day& __d) noexcept { + return static_cast(__d); + } }; # endif // _LIBCPP_STD_VER >= 26 diff --git a/lib/libcxx/include/__chrono/duration.h b/lib/libcxx/include/__chrono/duration.h index 9313fc797ecd5bd5edb109682d82f5164d589757..fe5bbd07f6d89b28ce704e0ca310d8ac15ca7f6e 100644 --- a/lib/libcxx/include/__chrono/duration.h +++ b/lib/libcxx/include/__chrono/duration.h @@ -19,6 +19,7 @@ #include <__type_traits/enable_if.h> #include <__type_traits/is_convertible.h> #include <__type_traits/is_floating_point.h> +#include <__type_traits/is_unqualified.h> #include #include @@ -164,6 +165,7 @@ template class duration { + static_assert(__is_unqualified_v<_Rep>, "A duration representation cannot be qualified"); static_assert(!__is_duration_v<_Rep>, "A duration representation can not be a duration"); static_assert(__is_ratio_v<_Period>, "Second template parameter of duration must be a std::ratio"); static_assert(_Period::num > 0, "duration period must be positive"); @@ -291,35 +293,21 @@ typedef duration nanoseconds; typedef duration microseconds; typedef duration milliseconds; typedef duration seconds; -typedef duration< long, ratio< 60> > minutes; -typedef duration< long, ratio<3600> > hours; +typedef duration > minutes; +typedef duration > hours; #if _LIBCPP_STD_VER >= 20 -typedef duration< int, ratio_multiply, hours::period>> days; -typedef duration< int, ratio_multiply, days::period>> weeks; -typedef duration< int, ratio_multiply, days::period>> years; -typedef duration< int, ratio_divide>> months; +typedef duration> days; +typedef duration> weeks; +typedef duration(365.2425 * 60 * 60 * 24)>> years; +typedef duration(365.2425 * 60 * 60 * 24) / 12>> months; #endif // Duration == -template -struct __duration_eq { - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool operator()(const _LhsDuration& __lhs, const _RhsDuration& __rhs) const { - typedef typename common_type<_LhsDuration, _RhsDuration>::type _Ct; - return _Ct(__lhs).count() == _Ct(__rhs).count(); - } -}; - -template -struct __duration_eq<_LhsDuration, _LhsDuration> { - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool operator()(const _LhsDuration& __lhs, const _LhsDuration& __rhs) const { - return __lhs.count() == __rhs.count(); - } -}; - template inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool operator==(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) { - return __duration_eq, duration<_Rep2, _Period2> >()(__lhs, __rhs); + using _Ct = typename common_type, duration<_Rep2, _Period2> >::type; + return _Ct(__lhs).count() == _Ct(__rhs).count(); } #if _LIBCPP_STD_VER <= 17 @@ -336,25 +324,11 @@ operator!=(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period // Duration < -template -struct __duration_lt { - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool operator()(const _LhsDuration& __lhs, const _RhsDuration& __rhs) const { - typedef typename common_type<_LhsDuration, _RhsDuration>::type _Ct; - return _Ct(__lhs).count() < _Ct(__rhs).count(); - } -}; - -template -struct __duration_lt<_LhsDuration, _LhsDuration> { - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool operator()(const _LhsDuration& __lhs, const _LhsDuration& __rhs) const { - return __lhs.count() < __rhs.count(); - } -}; - template inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool operator<(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) { - return __duration_lt, duration<_Rep2, _Period2> >()(__lhs, __rhs); + using _Ct = typename common_type, duration<_Rep2, _Period2> >::type; + return _Ct(__lhs).count() < _Ct(__rhs).count(); } // Duration > diff --git a/lib/libcxx/include/__chrono/exception.h b/lib/libcxx/include/__chrono/exception.h index 1eb5b1b62d92c5dfc4d03b5f1379aa7753da79f1..27fbfd6b57a2bb6fd82e4beaeadacbf246a463c4 100644 --- a/lib/libcxx/include/__chrono/exception.h +++ b/lib/libcxx/include/__chrono/exception.h @@ -31,6 +31,7 @@ # endif _LIBCPP_BEGIN_NAMESPACE_STD +_LIBCPP_BEGIN_EXPLICIT_ABI_ANNOTATIONS # if _LIBCPP_STD_VER >= 20 @@ -128,6 +129,7 @@ template # endif // _LIBCPP_STD_VER >= 20 +_LIBCPP_END_EXPLICIT_ABI_ANNOTATIONS _LIBCPP_END_NAMESPACE_STD #endif // _LIBCPP_HAS_EXPERIMENTAL_TZDB diff --git a/lib/libcxx/include/__chrono/file_clock.h b/lib/libcxx/include/__chrono/file_clock.h index 968f652f796d26fe8dedf4370cbff1d1ca33a2bc..7ded6162fada68a5170c976e62953b24da3fa355 100644 --- a/lib/libcxx/include/__chrono/file_clock.h +++ b/lib/libcxx/include/__chrono/file_clock.h @@ -46,6 +46,8 @@ _LIBCPP_END_NAMESPACE_STD #ifndef _LIBCPP_CXX03_LANG _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM +_LIBCPP_BEGIN_EXPLICIT_ABI_ANNOTATIONS + struct _FilesystemClock { # if _LIBCPP_HAS_INT128 typedef __int128_t rep; @@ -76,6 +78,8 @@ struct _FilesystemClock { } # endif // _LIBCPP_STD_VER >= 20 }; + +_LIBCPP_END_EXPLICIT_ABI_ANNOTATIONS _LIBCPP_END_NAMESPACE_FILESYSTEM #endif // !_LIBCPP_CXX03_LANG diff --git a/lib/libcxx/include/__chrono/gps_clock.h b/lib/libcxx/include/__chrono/gps_clock.h index 2e220cab946e368a1e9dddc2ac2e70e7689b68f9..924156ae5b455e4ec899619f64d5375fbfac0668 100644 --- a/lib/libcxx/include/__chrono/gps_clock.h +++ b/lib/libcxx/include/__chrono/gps_clock.h @@ -28,10 +28,10 @@ _LIBCPP_PUSH_MACROS # include <__undef_macros> -_LIBCPP_BEGIN_NAMESPACE_STD - # if _LIBCPP_STD_VER >= 20 && _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM && _LIBCPP_HAS_LOCALIZATION +_LIBCPP_BEGIN_NAMESPACE_STD + namespace chrono { class gps_clock; @@ -78,11 +78,11 @@ public: } // namespace chrono +_LIBCPP_END_NAMESPACE_STD + # endif // _LIBCPP_STD_VER >= 20 && _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM && // _LIBCPP_HAS_LOCALIZATION -_LIBCPP_END_NAMESPACE_STD - _LIBCPP_POP_MACROS #endif // _LIBCPP_HAS_EXPERIMENTAL_TZDB diff --git a/lib/libcxx/include/__chrono/hh_mm_ss.h b/lib/libcxx/include/__chrono/hh_mm_ss.h index 6ea8a28ee09383eeeb0115287325350fed567d99..746eba903d4f8ce745e6c7914bd4d38bfdff319c 100644 --- a/lib/libcxx/include/__chrono/hh_mm_ss.h +++ b/lib/libcxx/include/__chrono/hh_mm_ss.h @@ -59,13 +59,13 @@ public: __s_(chrono::duration_cast(chrono::abs(__d) - hours() - minutes())), __f_(chrono::duration_cast(chrono::abs(__d) - hours() - minutes() - seconds())) {} - _LIBCPP_HIDE_FROM_ABI constexpr bool is_negative() const noexcept { return __is_neg_; } - _LIBCPP_HIDE_FROM_ABI constexpr chrono::hours hours() const noexcept { return __h_; } - _LIBCPP_HIDE_FROM_ABI constexpr chrono::minutes minutes() const noexcept { return __m_; } - _LIBCPP_HIDE_FROM_ABI constexpr chrono::seconds seconds() const noexcept { return __s_; } - _LIBCPP_HIDE_FROM_ABI constexpr precision subseconds() const noexcept { return __f_; } + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool is_negative() const noexcept { return __is_neg_; } + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr chrono::hours hours() const noexcept { return __h_; } + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr chrono::minutes minutes() const noexcept { return __m_; } + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr chrono::seconds seconds() const noexcept { return __s_; } + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr precision subseconds() const noexcept { return __f_; } - _LIBCPP_HIDE_FROM_ABI constexpr precision to_duration() const noexcept { + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr precision to_duration() const noexcept { auto __dur = __h_ + __m_ + __s_ + __f_; return __is_neg_ ? -__dur : __dur; } @@ -81,14 +81,14 @@ private: }; _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(hh_mm_ss); -_LIBCPP_HIDE_FROM_ABI inline constexpr bool is_am(const hours& __h) noexcept { +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr bool is_am(const hours& __h) noexcept { return __h >= hours(0) && __h < hours(12); } -_LIBCPP_HIDE_FROM_ABI inline constexpr bool is_pm(const hours& __h) noexcept { +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr bool is_pm(const hours& __h) noexcept { return __h >= hours(12) && __h < hours(24); } -_LIBCPP_HIDE_FROM_ABI inline constexpr hours make12(const hours& __h) noexcept { +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr hours make12(const hours& __h) noexcept { if (__h == hours(0)) return hours(12); else if (__h <= hours(12)) @@ -97,7 +97,7 @@ _LIBCPP_HIDE_FROM_ABI inline constexpr hours make12(const hours& __h) noexcept { return __h - hours(12); } -_LIBCPP_HIDE_FROM_ABI inline constexpr hours make24(const hours& __h, bool __is_pm) noexcept { +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr hours make24(const hours& __h, bool __is_pm) noexcept { if (__is_pm) return __h == hours(12) ? __h : __h + hours(12); else diff --git a/lib/libcxx/include/__chrono/literals.h b/lib/libcxx/include/__chrono/literals.h index 89800440edf43522d9295c6d1754e57b4aa8c5e8..b26acbafbf8348b0b6e25a250e8ea87e72561b9f 100644 --- a/lib/libcxx/include/__chrono/literals.h +++ b/lib/libcxx/include/__chrono/literals.h @@ -24,11 +24,11 @@ _LIBCPP_BEGIN_NAMESPACE_STD inline namespace literals { inline namespace chrono_literals { -_LIBCPP_HIDE_FROM_ABI constexpr chrono::day operator""d(unsigned long long __d) noexcept { +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr chrono::day operator""d(unsigned long long __d) noexcept { return chrono::day(static_cast(__d)); } -_LIBCPP_HIDE_FROM_ABI constexpr chrono::year operator""y(unsigned long long __y) noexcept { +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr chrono::year operator""y(unsigned long long __y) noexcept { return chrono::year(static_cast(__y)); } } // namespace chrono_literals diff --git a/lib/libcxx/include/__chrono/month.h b/lib/libcxx/include/__chrono/month.h index 669ac66360ab6d3037ed21a6cc9a638118cf1dc8..abf07e89a556b9789506edc9d5ff5b9e68328efe 100644 --- a/lib/libcxx/include/__chrono/month.h +++ b/lib/libcxx/include/__chrono/month.h @@ -55,7 +55,7 @@ public: _LIBCPP_HIDE_FROM_ABI constexpr month& operator+=(const months& __m1) noexcept; _LIBCPP_HIDE_FROM_ABI constexpr month& operator-=(const months& __m1) noexcept; _LIBCPP_HIDE_FROM_ABI explicit inline constexpr operator unsigned() const noexcept { return __m_; } - _LIBCPP_HIDE_FROM_ABI inline constexpr bool ok() const noexcept { return __m_ >= 1 && __m_ <= 12; } + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr bool ok() const noexcept { return __m_ >= 1 && __m_ <= 12; } }; _LIBCPP_HIDE_FROM_ABI inline constexpr bool operator==(const month& __lhs, const month& __rhs) noexcept { @@ -66,21 +66,21 @@ _LIBCPP_HIDE_FROM_ABI inline constexpr strong_ordering operator<=>(const month& return static_cast(__lhs) <=> static_cast(__rhs); } -_LIBCPP_HIDE_FROM_ABI inline constexpr month operator+(const month& __lhs, const months& __rhs) noexcept { +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr month operator+(const month& __lhs, const months& __rhs) noexcept { auto const __mu = static_cast(static_cast(__lhs)) + (__rhs.count() - 1); auto const __yr = (__mu >= 0 ? __mu : __mu - 11) / 12; return month{static_cast(__mu - __yr * 12 + 1)}; } -_LIBCPP_HIDE_FROM_ABI inline constexpr month operator+(const months& __lhs, const month& __rhs) noexcept { +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr month operator+(const months& __lhs, const month& __rhs) noexcept { return __rhs + __lhs; } -_LIBCPP_HIDE_FROM_ABI inline constexpr month operator-(const month& __lhs, const months& __rhs) noexcept { +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr month operator-(const month& __lhs, const months& __rhs) noexcept { return __lhs + -__rhs; } -_LIBCPP_HIDE_FROM_ABI inline constexpr months operator-(const month& __lhs, const month& __rhs) noexcept { +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr months operator-(const month& __lhs, const month& __rhs) noexcept { auto const __dm = static_cast(__lhs) - static_cast(__rhs); return months(__dm <= 11 ? __dm : __dm + 12); } @@ -114,7 +114,7 @@ inline constexpr month December{12}; template <> struct hash { - _LIBCPP_HIDE_FROM_ABI static size_t operator()(const chrono::month& __m) noexcept { + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static size_t operator()(const chrono::month& __m) noexcept { return static_cast(__m); } }; diff --git a/lib/libcxx/include/__chrono/month_weekday.h b/lib/libcxx/include/__chrono/month_weekday.h index edb7d386067d890009941df5f8b2e3b02851d318..f149806dc6c7c26fc58dae534e58a89b42008bda 100644 --- a/lib/libcxx/include/__chrono/month_weekday.h +++ b/lib/libcxx/include/__chrono/month_weekday.h @@ -35,9 +35,11 @@ public: _LIBCPP_HIDE_FROM_ABI constexpr month_weekday(const chrono::month& __mval, const chrono::weekday_indexed& __wdival) noexcept : __m_{__mval}, __wdi_{__wdival} {} - _LIBCPP_HIDE_FROM_ABI inline constexpr chrono::month month() const noexcept { return __m_; } - _LIBCPP_HIDE_FROM_ABI inline constexpr chrono::weekday_indexed weekday_indexed() const noexcept { return __wdi_; } - _LIBCPP_HIDE_FROM_ABI inline constexpr bool ok() const noexcept { return __m_.ok() && __wdi_.ok(); } + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr chrono::month month() const noexcept { return __m_; } + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr chrono::weekday_indexed weekday_indexed() const noexcept { + return __wdi_; + } + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr bool ok() const noexcept { return __m_.ok() && __wdi_.ok(); } }; _LIBCPP_HIDE_FROM_ABI inline constexpr bool @@ -45,21 +47,23 @@ operator==(const month_weekday& __lhs, const month_weekday& __rhs) noexcept { return __lhs.month() == __rhs.month() && __lhs.weekday_indexed() == __rhs.weekday_indexed(); } -_LIBCPP_HIDE_FROM_ABI inline constexpr month_weekday +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr month_weekday operator/(const month& __lhs, const weekday_indexed& __rhs) noexcept { return month_weekday{__lhs, __rhs}; } -_LIBCPP_HIDE_FROM_ABI inline constexpr month_weekday operator/(int __lhs, const weekday_indexed& __rhs) noexcept { +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr month_weekday +operator/(int __lhs, const weekday_indexed& __rhs) noexcept { return month_weekday{month(__lhs), __rhs}; } -_LIBCPP_HIDE_FROM_ABI inline constexpr month_weekday +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr month_weekday operator/(const weekday_indexed& __lhs, const month& __rhs) noexcept { return month_weekday{__rhs, __lhs}; } -_LIBCPP_HIDE_FROM_ABI inline constexpr month_weekday operator/(const weekday_indexed& __lhs, int __rhs) noexcept { +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr month_weekday +operator/(const weekday_indexed& __lhs, int __rhs) noexcept { return month_weekday{month(__rhs), __lhs}; } @@ -71,9 +75,11 @@ public: _LIBCPP_HIDE_FROM_ABI constexpr month_weekday_last(const chrono::month& __mval, const chrono::weekday_last& __wdlval) noexcept : __m_{__mval}, __wdl_{__wdlval} {} - _LIBCPP_HIDE_FROM_ABI inline constexpr chrono::month month() const noexcept { return __m_; } - _LIBCPP_HIDE_FROM_ABI inline constexpr chrono::weekday_last weekday_last() const noexcept { return __wdl_; } - _LIBCPP_HIDE_FROM_ABI inline constexpr bool ok() const noexcept { return __m_.ok() && __wdl_.ok(); } + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr chrono::month month() const noexcept { return __m_; } + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr chrono::weekday_last weekday_last() const noexcept { + return __wdl_; + } + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr bool ok() const noexcept { return __m_.ok() && __wdl_.ok(); } }; _LIBCPP_HIDE_FROM_ABI inline constexpr bool @@ -81,21 +87,23 @@ operator==(const month_weekday_last& __lhs, const month_weekday_last& __rhs) noe return __lhs.month() == __rhs.month() && __lhs.weekday_last() == __rhs.weekday_last(); } -_LIBCPP_HIDE_FROM_ABI inline constexpr month_weekday_last +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr month_weekday_last operator/(const month& __lhs, const weekday_last& __rhs) noexcept { return month_weekday_last{__lhs, __rhs}; } -_LIBCPP_HIDE_FROM_ABI inline constexpr month_weekday_last operator/(int __lhs, const weekday_last& __rhs) noexcept { +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr month_weekday_last +operator/(int __lhs, const weekday_last& __rhs) noexcept { return month_weekday_last{month(__lhs), __rhs}; } -_LIBCPP_HIDE_FROM_ABI inline constexpr month_weekday_last +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr month_weekday_last operator/(const weekday_last& __lhs, const month& __rhs) noexcept { return month_weekday_last{__rhs, __lhs}; } -_LIBCPP_HIDE_FROM_ABI inline constexpr month_weekday_last operator/(const weekday_last& __lhs, int __rhs) noexcept { +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr month_weekday_last +operator/(const weekday_last& __lhs, int __rhs) noexcept { return month_weekday_last{month(__rhs), __lhs}; } } // namespace chrono @@ -104,7 +112,7 @@ _LIBCPP_HIDE_FROM_ABI inline constexpr month_weekday_last operator/(const weekda template <> struct hash { - _LIBCPP_HIDE_FROM_ABI static size_t operator()(const chrono::month_weekday& __mw) noexcept { + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static size_t operator()(const chrono::month_weekday& __mw) noexcept { return std::__hash_combine( hash{}(__mw.month()), hash{}(__mw.weekday_indexed())); } @@ -112,7 +120,7 @@ struct hash { template <> struct hash { - _LIBCPP_HIDE_FROM_ABI static size_t operator()(const chrono::month_weekday_last& __mwl) noexcept { + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static size_t operator()(const chrono::month_weekday_last& __mwl) noexcept { return std::__hash_combine( hash{}(__mwl.month()), hash{}(__mwl.weekday_last())); } diff --git a/lib/libcxx/include/__chrono/monthday.h b/lib/libcxx/include/__chrono/monthday.h index 2a7262be09dc6cbfb2fee7bb2fb81ca526ac6785..443d7ea2171442f6a783e85a93b8f80644438256 100644 --- a/lib/libcxx/include/__chrono/monthday.h +++ b/lib/libcxx/include/__chrono/monthday.h @@ -37,9 +37,9 @@ public: month_day() = default; _LIBCPP_HIDE_FROM_ABI constexpr month_day(const chrono::month& __mval, const chrono::day& __dval) noexcept : __m_{__mval}, __d_{__dval} {} - _LIBCPP_HIDE_FROM_ABI inline constexpr chrono::month month() const noexcept { return __m_; } - _LIBCPP_HIDE_FROM_ABI inline constexpr chrono::day day() const noexcept { return __d_; } - _LIBCPP_HIDE_FROM_ABI constexpr bool ok() const noexcept; + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr chrono::month month() const noexcept { return __m_; } + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr chrono::day day() const noexcept { return __d_; } + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool ok() const noexcept; }; _LIBCPP_HIDE_FROM_ABI inline constexpr bool month_day::ok() const noexcept { @@ -70,23 +70,25 @@ operator<=>(const month_day& __lhs, const month_day& __rhs) noexcept { return __lhs.day() <=> __rhs.day(); } -_LIBCPP_HIDE_FROM_ABI inline constexpr month_day operator/(const month& __lhs, const day& __rhs) noexcept { +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr month_day +operator/(const month& __lhs, const day& __rhs) noexcept { return month_day{__lhs, __rhs}; } -_LIBCPP_HIDE_FROM_ABI inline constexpr month_day operator/(const day& __lhs, const month& __rhs) noexcept { +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr month_day +operator/(const day& __lhs, const month& __rhs) noexcept { return __rhs / __lhs; } -_LIBCPP_HIDE_FROM_ABI inline constexpr month_day operator/(const month& __lhs, int __rhs) noexcept { +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr month_day operator/(const month& __lhs, int __rhs) noexcept { return __lhs / day(__rhs); } -_LIBCPP_HIDE_FROM_ABI inline constexpr month_day operator/(int __lhs, const day& __rhs) noexcept { +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr month_day operator/(int __lhs, const day& __rhs) noexcept { return month(__lhs) / __rhs; } -_LIBCPP_HIDE_FROM_ABI inline constexpr month_day operator/(const day& __lhs, int __rhs) noexcept { +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr month_day operator/(const day& __lhs, int __rhs) noexcept { return month(__rhs) / __lhs; } @@ -96,8 +98,8 @@ private: public: _LIBCPP_HIDE_FROM_ABI explicit constexpr month_day_last(const chrono::month& __val) noexcept : __m_{__val} {} - _LIBCPP_HIDE_FROM_ABI inline constexpr chrono::month month() const noexcept { return __m_; } - _LIBCPP_HIDE_FROM_ABI inline constexpr bool ok() const noexcept { return __m_.ok(); } + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr chrono::month month() const noexcept { return __m_; } + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr bool ok() const noexcept { return __m_.ok(); } }; _LIBCPP_HIDE_FROM_ABI inline constexpr bool @@ -110,19 +112,19 @@ operator<=>(const month_day_last& __lhs, const month_day_last& __rhs) noexcept { return __lhs.month() <=> __rhs.month(); } -_LIBCPP_HIDE_FROM_ABI inline constexpr month_day_last operator/(const month& __lhs, last_spec) noexcept { +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr month_day_last operator/(const month& __lhs, last_spec) noexcept { return month_day_last{__lhs}; } -_LIBCPP_HIDE_FROM_ABI inline constexpr month_day_last operator/(last_spec, const month& __rhs) noexcept { +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr month_day_last operator/(last_spec, const month& __rhs) noexcept { return month_day_last{__rhs}; } -_LIBCPP_HIDE_FROM_ABI inline constexpr month_day_last operator/(int __lhs, last_spec) noexcept { +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr month_day_last operator/(int __lhs, last_spec) noexcept { return month_day_last{month(__lhs)}; } -_LIBCPP_HIDE_FROM_ABI inline constexpr month_day_last operator/(last_spec, int __rhs) noexcept { +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr month_day_last operator/(last_spec, int __rhs) noexcept { return month_day_last{month(__rhs)}; } @@ -132,14 +134,14 @@ _LIBCPP_HIDE_FROM_ABI inline constexpr month_day_last operator/(last_spec, int _ template <> struct hash { - _LIBCPP_HIDE_FROM_ABI static size_t operator()(const chrono::month_day& __md) noexcept { + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static size_t operator()(const chrono::month_day& __md) noexcept { return std::__hash_combine(hash{}(__md.month()), hash{}(__md.day())); } }; template <> struct hash { - _LIBCPP_HIDE_FROM_ABI static size_t operator()(const chrono::month_day_last& __mdl) noexcept { + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static size_t operator()(const chrono::month_day_last& __mdl) noexcept { return hash{}(__mdl.month()); } }; diff --git a/lib/libcxx/include/__chrono/steady_clock.h b/lib/libcxx/include/__chrono/steady_clock.h index 8e68c9a3c20f2d2e50c320ae7d40bae859d3c1ee..b433b0b3ad29e4706670a6c49ae1e032757e9028 100644 --- a/lib/libcxx/include/__chrono/steady_clock.h +++ b/lib/libcxx/include/__chrono/steady_clock.h @@ -18,11 +18,13 @@ # pragma GCC system_header #endif +#if _LIBCPP_HAS_MONOTONIC_CLOCK + _LIBCPP_BEGIN_NAMESPACE_STD +_LIBCPP_BEGIN_EXPLICIT_ABI_ANNOTATIONS namespace chrono { -#if _LIBCPP_HAS_MONOTONIC_CLOCK class _LIBCPP_EXPORTED_FROM_ABI steady_clock { public: typedef nanoseconds duration; @@ -33,10 +35,12 @@ public: [[__nodiscard__]] static time_point now() _NOEXCEPT; }; -#endif } // namespace chrono +_LIBCPP_END_EXPLICIT_ABI_ANNOTATIONS _LIBCPP_END_NAMESPACE_STD +#endif + #endif // _LIBCPP___CHRONO_STEADY_CLOCK_H diff --git a/lib/libcxx/include/__chrono/system_clock.h b/lib/libcxx/include/__chrono/system_clock.h index e3ef75ae50fa6a248b22f29eebbbc8b8834bf0ff..449514b051492c686c4620920f1d2efda52f6eb7 100644 --- a/lib/libcxx/include/__chrono/system_clock.h +++ b/lib/libcxx/include/__chrono/system_clock.h @@ -20,6 +20,7 @@ #endif _LIBCPP_BEGIN_NAMESPACE_STD +_LIBCPP_BEGIN_EXPLICIT_ABI_ANNOTATIONS namespace chrono { @@ -47,6 +48,7 @@ using sys_days = sys_time; } // namespace chrono +_LIBCPP_END_EXPLICIT_ABI_ANNOTATIONS _LIBCPP_END_NAMESPACE_STD #endif // _LIBCPP___CHRONO_SYSTEM_CLOCK_H diff --git a/lib/libcxx/include/__chrono/tai_clock.h b/lib/libcxx/include/__chrono/tai_clock.h index 14c8b70a94af5ff2297d66fed105eb54ec69d904..9c97e379f4b9a7299e49bdc761f6ff95866df293 100644 --- a/lib/libcxx/include/__chrono/tai_clock.h +++ b/lib/libcxx/include/__chrono/tai_clock.h @@ -28,10 +28,10 @@ _LIBCPP_PUSH_MACROS # include <__undef_macros> -_LIBCPP_BEGIN_NAMESPACE_STD - # if _LIBCPP_STD_VER >= 20 && _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM && _LIBCPP_HAS_LOCALIZATION +_LIBCPP_BEGIN_NAMESPACE_STD + namespace chrono { class tai_clock; @@ -96,11 +96,11 @@ public: } // namespace chrono +_LIBCPP_END_NAMESPACE_STD + # endif // _LIBCPP_STD_VER >= 20 && _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM && // _LIBCPP_HAS_LOCALIZATION -_LIBCPP_END_NAMESPACE_STD - _LIBCPP_POP_MACROS #endif // _LIBCPP_HAS_EXPERIMENTAL_TZDB diff --git a/lib/libcxx/include/__chrono/time_zone.h b/lib/libcxx/include/__chrono/time_zone.h index d18d59d2736bf45c6f77835df470fe95f97e2db2..742367defb21567995020afcb52084fbed7d578d 100644 --- a/lib/libcxx/include/__chrono/time_zone.h +++ b/lib/libcxx/include/__chrono/time_zone.h @@ -35,10 +35,11 @@ _LIBCPP_PUSH_MACROS # include <__undef_macros> -_LIBCPP_BEGIN_NAMESPACE_STD - # if _LIBCPP_STD_VER >= 20 && _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM && _LIBCPP_HAS_LOCALIZATION +_LIBCPP_BEGIN_NAMESPACE_STD +_LIBCPP_BEGIN_EXPLICIT_ABI_ANNOTATIONS + namespace chrono { enum class choose { earliest, latest }; @@ -173,11 +174,12 @@ operator<=>(const time_zone& __x, const time_zone& __y) noexcept { } // namespace chrono +_LIBCPP_END_EXPLICIT_ABI_ANNOTATIONS +_LIBCPP_END_NAMESPACE_STD + # endif // _LIBCPP_STD_VER >= 20 && _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM && // _LIBCPP_HAS_LOCALIZATION -_LIBCPP_END_NAMESPACE_STD - _LIBCPP_POP_MACROS #endif // _LIBCPP_HAS_EXPERIMENTAL_TZDB diff --git a/lib/libcxx/include/__chrono/time_zone_link.h b/lib/libcxx/include/__chrono/time_zone_link.h index cae40b07c2ca676fac97cb678a349de97ca444f9..3c45d953fb7efdb4137b1ccdc5e715cbba77a79d 100644 --- a/lib/libcxx/include/__chrono/time_zone_link.h +++ b/lib/libcxx/include/__chrono/time_zone_link.h @@ -29,10 +29,10 @@ _LIBCPP_PUSH_MACROS # include <__undef_macros> -_LIBCPP_BEGIN_NAMESPACE_STD - # if _LIBCPP_STD_VER >= 20 && _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM && _LIBCPP_HAS_LOCALIZATION +_LIBCPP_BEGIN_NAMESPACE_STD + namespace chrono { class time_zone_link { @@ -67,11 +67,11 @@ operator<=>(const time_zone_link& __x, const time_zone_link& __y) noexcept { } // namespace chrono +_LIBCPP_END_NAMESPACE_STD + # endif // _LIBCPP_STD_VER >= 20 && _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM && // _LIBCPP_HAS_LOCALIZATION -_LIBCPP_END_NAMESPACE_STD - _LIBCPP_POP_MACROS #endif // _LIBCPP_HAS_EXPERIMENTAL_TZDB diff --git a/lib/libcxx/include/__chrono/tzdb.h b/lib/libcxx/include/__chrono/tzdb.h index fb85f66b01968043304c066a4fd7c74fc950456f..6e713a8ff3ddae66b0bc75ae52cecc5574712540 100644 --- a/lib/libcxx/include/__chrono/tzdb.h +++ b/lib/libcxx/include/__chrono/tzdb.h @@ -34,10 +34,11 @@ _LIBCPP_PUSH_MACROS # include <__undef_macros> -_LIBCPP_BEGIN_NAMESPACE_STD - # if _LIBCPP_STD_VER >= 20 && _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM && _LIBCPP_HAS_LOCALIZATION +_LIBCPP_BEGIN_NAMESPACE_STD +_LIBCPP_BEGIN_EXPLICIT_ABI_ANNOTATIONS + namespace chrono { struct tzdb { @@ -84,11 +85,12 @@ private: } // namespace chrono +_LIBCPP_END_EXPLICIT_ABI_ANNOTATIONS +_LIBCPP_END_NAMESPACE_STD + # endif // _LIBCPP_STD_VER >= 20 && _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM && // _LIBCPP_HAS_LOCALIZATION -_LIBCPP_END_NAMESPACE_STD - _LIBCPP_POP_MACROS #endif // _LIBCPP_HAS_EXPERIMENTAL_TZDB diff --git a/lib/libcxx/include/__chrono/tzdb_list.h b/lib/libcxx/include/__chrono/tzdb_list.h index 2b83a6df1daf80d09a769f834ef358e4adfe73b5..64b2f4995c08057a26e30373215c6ce056b19683 100644 --- a/lib/libcxx/include/__chrono/tzdb_list.h +++ b/lib/libcxx/include/__chrono/tzdb_list.h @@ -27,10 +27,11 @@ # pragma GCC system_header # endif -_LIBCPP_BEGIN_NAMESPACE_STD - # if _LIBCPP_STD_VER >= 20 && _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM && _LIBCPP_HAS_LOCALIZATION +_LIBCPP_BEGIN_NAMESPACE_STD +_LIBCPP_BEGIN_EXPLICIT_ABI_ANNOTATIONS + namespace chrono { // TODO TZDB @@ -98,11 +99,12 @@ _LIBCPP_AVAILABILITY_TZDB _LIBCPP_EXPORTED_FROM_ABI const tzdb& reload_tzdb(); } // namespace chrono +_LIBCPP_END_EXPLICIT_ABI_ANNOTATIONS +_LIBCPP_END_NAMESPACE_STD + # endif // _LIBCPP_STD_VER >= 20 && _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM && // _LIBCPP_HAS_LOCALIZATION -_LIBCPP_END_NAMESPACE_STD - #endif // _LIBCPP_HAS_EXPERIMENTAL_TZDB #endif // _LIBCPP___CHRONO_TZDB_LIST_H diff --git a/lib/libcxx/include/__chrono/utc_clock.h b/lib/libcxx/include/__chrono/utc_clock.h index 2207b89c92c594048804c12a75eda555ae148668..42cb41ea9a6f7360902c5f71c27c3ec1434a8362 100644 --- a/lib/libcxx/include/__chrono/utc_clock.h +++ b/lib/libcxx/include/__chrono/utc_clock.h @@ -27,10 +27,10 @@ # pragma GCC system_header # endif -_LIBCPP_BEGIN_NAMESPACE_STD - # if _LIBCPP_STD_VER >= 20 && _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM && _LIBCPP_HAS_LOCALIZATION +_LIBCPP_BEGIN_NAMESPACE_STD + namespace chrono { class utc_clock; @@ -153,11 +153,11 @@ utc_clock::to_sys(const utc_time<_Duration>& __time) { } // namespace chrono +_LIBCPP_END_NAMESPACE_STD + # endif // _LIBCPP_STD_VER >= 20 && _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM && // _LIBCPP_HAS_LOCALIZATION -_LIBCPP_END_NAMESPACE_STD - #endif // _LIBCPP_HAS_EXPERIMENTAL_TZDB #endif // _LIBCPP___CHRONO_UTC_CLOCK_H diff --git a/lib/libcxx/include/__chrono/weekday.h b/lib/libcxx/include/__chrono/weekday.h index 143803495dac86be7950b3f3447cdbb10385dade..5e1065de9302abca510dfc2be5118995e3dbcd90 100644 --- a/lib/libcxx/include/__chrono/weekday.h +++ b/lib/libcxx/include/__chrono/weekday.h @@ -65,11 +65,13 @@ public: } _LIBCPP_HIDE_FROM_ABI constexpr weekday& operator+=(const days& __dd) noexcept; _LIBCPP_HIDE_FROM_ABI constexpr weekday& operator-=(const days& __dd) noexcept; - _LIBCPP_HIDE_FROM_ABI inline constexpr unsigned c_encoding() const noexcept { return __wd_; } - _LIBCPP_HIDE_FROM_ABI inline constexpr unsigned iso_encoding() const noexcept { return __wd_ == 0u ? 7 : __wd_; } - _LIBCPP_HIDE_FROM_ABI inline constexpr bool ok() const noexcept { return __wd_ <= 6; } - _LIBCPP_HIDE_FROM_ABI constexpr weekday_indexed operator[](unsigned __index) const noexcept; - _LIBCPP_HIDE_FROM_ABI constexpr weekday_last operator[](last_spec) const noexcept; + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr unsigned c_encoding() const noexcept { return __wd_; } + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr unsigned iso_encoding() const noexcept { + return __wd_ == 0u ? 7 : __wd_; + } + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr bool ok() const noexcept { return __wd_ <= 6; } + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr weekday_indexed operator[](unsigned __index) const noexcept; + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr weekday_last operator[](last_spec) const noexcept; }; // https://howardhinnant.github.io/date_algorithms.html#weekday_from_days @@ -81,21 +83,25 @@ _LIBCPP_HIDE_FROM_ABI inline constexpr bool operator==(const weekday& __lhs, con return __lhs.c_encoding() == __rhs.c_encoding(); } -_LIBCPP_HIDE_FROM_ABI inline constexpr weekday operator+(const weekday& __lhs, const days& __rhs) noexcept { +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr weekday +operator+(const weekday& __lhs, const days& __rhs) noexcept { auto const __mu = static_cast(__lhs.c_encoding()) + __rhs.count(); auto const __yr = (__mu >= 0 ? __mu : __mu - 6) / 7; return weekday{static_cast(__mu - __yr * 7)}; } -_LIBCPP_HIDE_FROM_ABI inline constexpr weekday operator+(const days& __lhs, const weekday& __rhs) noexcept { +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr weekday +operator+(const days& __lhs, const weekday& __rhs) noexcept { return __rhs + __lhs; } -_LIBCPP_HIDE_FROM_ABI inline constexpr weekday operator-(const weekday& __lhs, const days& __rhs) noexcept { +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr weekday +operator-(const weekday& __lhs, const days& __rhs) noexcept { return __lhs + -__rhs; } -_LIBCPP_HIDE_FROM_ABI inline constexpr days operator-(const weekday& __lhs, const weekday& __rhs) noexcept { +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr days +operator-(const weekday& __lhs, const weekday& __rhs) noexcept { const int __wdu = __lhs.c_encoding() - __rhs.c_encoding(); const int __wk = (__wdu >= 0 ? __wdu : __wdu - 6) / 7; return days{__wdu - __wk * 7}; @@ -120,9 +126,11 @@ public: weekday_indexed() = default; _LIBCPP_HIDE_FROM_ABI inline constexpr weekday_indexed(const chrono::weekday& __wdval, unsigned __idxval) noexcept : __wd_{__wdval}, __idx_(__idxval) {} - _LIBCPP_HIDE_FROM_ABI inline constexpr chrono::weekday weekday() const noexcept { return __wd_; } - _LIBCPP_HIDE_FROM_ABI inline constexpr unsigned index() const noexcept { return __idx_; } - _LIBCPP_HIDE_FROM_ABI inline constexpr bool ok() const noexcept { return __wd_.ok() && __idx_ >= 1 && __idx_ <= 5; } + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr chrono::weekday weekday() const noexcept { return __wd_; } + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr unsigned index() const noexcept { return __idx_; } + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr bool ok() const noexcept { + return __wd_.ok() && __idx_ >= 1 && __idx_ <= 5; + } }; _LIBCPP_HIDE_FROM_ABI inline constexpr bool @@ -136,8 +144,8 @@ private: public: _LIBCPP_HIDE_FROM_ABI explicit constexpr weekday_last(const chrono::weekday& __val) noexcept : __wd_{__val} {} - _LIBCPP_HIDE_FROM_ABI constexpr chrono::weekday weekday() const noexcept { return __wd_; } - _LIBCPP_HIDE_FROM_ABI constexpr bool ok() const noexcept { return __wd_.ok(); } + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr chrono::weekday weekday() const noexcept { return __wd_; } + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool ok() const noexcept { return __wd_.ok(); } }; _LIBCPP_HIDE_FROM_ABI inline constexpr bool operator==(const weekday_last& __lhs, const weekday_last& __rhs) noexcept { @@ -166,19 +174,21 @@ inline constexpr weekday Saturday{6}; template <> struct hash { - _LIBCPP_HIDE_FROM_ABI static size_t operator()(const chrono::weekday& __w) noexcept { return __w.c_encoding(); } + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static size_t operator()(const chrono::weekday& __w) noexcept { + return __w.c_encoding(); + } }; template <> struct hash { - _LIBCPP_HIDE_FROM_ABI static size_t operator()(const chrono::weekday_indexed& __wi) noexcept { + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static size_t operator()(const chrono::weekday_indexed& __wi) noexcept { return std::__hash_combine(hash{}(__wi.weekday()), __wi.index()); } }; template <> struct hash { - _LIBCPP_HIDE_FROM_ABI static size_t operator()(const chrono::weekday_last& __wl) noexcept { + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static size_t operator()(const chrono::weekday_last& __wl) noexcept { return hash{}(__wl.weekday()); } }; diff --git a/lib/libcxx/include/__chrono/year.h b/lib/libcxx/include/__chrono/year.h index aaef38acd92f25ec5bc2edac1a59f89d026bd60b..208d6eba0f165e06a44151a62e9f5bcf72807f03 100644 --- a/lib/libcxx/include/__chrono/year.h +++ b/lib/libcxx/include/__chrono/year.h @@ -58,16 +58,16 @@ public: } _LIBCPP_HIDE_FROM_ABI constexpr year& operator+=(const years& __dy) noexcept; _LIBCPP_HIDE_FROM_ABI constexpr year& operator-=(const years& __dy) noexcept; - _LIBCPP_HIDE_FROM_ABI inline constexpr year operator+() const noexcept { return *this; } - _LIBCPP_HIDE_FROM_ABI inline constexpr year operator-() const noexcept { return year{-__y_}; } + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr year operator+() const noexcept { return *this; } + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr year operator-() const noexcept { return year{-__y_}; } - _LIBCPP_HIDE_FROM_ABI inline constexpr bool is_leap() const noexcept { + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr bool is_leap() const noexcept { return __y_ % 4 == 0 && (__y_ % 100 != 0 || __y_ % 400 == 0); } _LIBCPP_HIDE_FROM_ABI explicit inline constexpr operator int() const noexcept { return __y_; } - _LIBCPP_HIDE_FROM_ABI constexpr bool ok() const noexcept; - _LIBCPP_HIDE_FROM_ABI static inline constexpr year min() noexcept { return year{-32767}; } - _LIBCPP_HIDE_FROM_ABI static inline constexpr year max() noexcept { return year{32767}; } + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool ok() const noexcept; + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static inline constexpr year min() noexcept { return year{-32767}; } + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static inline constexpr year max() noexcept { return year{32767}; } }; _LIBCPP_HIDE_FROM_ABI inline constexpr bool operator==(const year& __lhs, const year& __rhs) noexcept { @@ -78,19 +78,19 @@ _LIBCPP_HIDE_FROM_ABI constexpr strong_ordering operator<=>(const year& __lhs, c return static_cast(__lhs) <=> static_cast(__rhs); } -_LIBCPP_HIDE_FROM_ABI inline constexpr year operator+(const year& __lhs, const years& __rhs) noexcept { +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr year operator+(const year& __lhs, const years& __rhs) noexcept { return year(static_cast(__lhs) + __rhs.count()); } -_LIBCPP_HIDE_FROM_ABI inline constexpr year operator+(const years& __lhs, const year& __rhs) noexcept { +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr year operator+(const years& __lhs, const year& __rhs) noexcept { return __rhs + __lhs; } -_LIBCPP_HIDE_FROM_ABI inline constexpr year operator-(const year& __lhs, const years& __rhs) noexcept { +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr year operator-(const year& __lhs, const years& __rhs) noexcept { return __lhs + -__rhs; } -_LIBCPP_HIDE_FROM_ABI inline constexpr years operator-(const year& __lhs, const year& __rhs) noexcept { +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr years operator-(const year& __lhs, const year& __rhs) noexcept { return years{static_cast(__lhs) - static_cast(__rhs)}; } @@ -115,7 +115,9 @@ _LIBCPP_HIDE_FROM_ABI constexpr bool year::ok() const noexcept { template <> struct hash { - _LIBCPP_HIDE_FROM_ABI static size_t operator()(const chrono::year& __y) noexcept { return static_cast(__y); } + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static size_t operator()(const chrono::year& __y) noexcept { + return static_cast(__y); + } }; # endif // _LIBCPP_STD_VER >= 26 diff --git a/lib/libcxx/include/__chrono/year_month.h b/lib/libcxx/include/__chrono/year_month.h index e36091c02161b3af7c6f6928aea346e563b14e23..fdeeed1f386f82cba230d70beeab15312b934519 100644 --- a/lib/libcxx/include/__chrono/year_month.h +++ b/lib/libcxx/include/__chrono/year_month.h @@ -36,20 +36,20 @@ public: year_month() = default; _LIBCPP_HIDE_FROM_ABI constexpr year_month(const chrono::year& __yval, const chrono::month& __mval) noexcept : __y_{__yval}, __m_{__mval} {} - _LIBCPP_HIDE_FROM_ABI inline constexpr chrono::year year() const noexcept { return __y_; } - _LIBCPP_HIDE_FROM_ABI inline constexpr chrono::month month() const noexcept { return __m_; } + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr chrono::year year() const noexcept { return __y_; } + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr chrono::month month() const noexcept { return __m_; } _LIBCPP_HIDE_FROM_ABI inline constexpr year_month& operator+=(const months& __dm) noexcept; _LIBCPP_HIDE_FROM_ABI inline constexpr year_month& operator-=(const months& __dm) noexcept; _LIBCPP_HIDE_FROM_ABI inline constexpr year_month& operator+=(const years& __dy) noexcept; _LIBCPP_HIDE_FROM_ABI inline constexpr year_month& operator-=(const years& __dy) noexcept; - _LIBCPP_HIDE_FROM_ABI inline constexpr bool ok() const noexcept { return __y_.ok() && __m_.ok(); } + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr bool ok() const noexcept { return __y_.ok() && __m_.ok(); } }; -_LIBCPP_HIDE_FROM_ABI inline constexpr year_month operator/(const year& __y, const month& __m) noexcept { +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr year_month operator/(const year& __y, const month& __m) noexcept { return year_month{__y, __m}; } -_LIBCPP_HIDE_FROM_ABI inline constexpr year_month operator/(const year& __y, int __m) noexcept { +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr year_month operator/(const year& __y, int __m) noexcept { return year_month{__y, month(__m)}; } @@ -64,35 +64,42 @@ operator<=>(const year_month& __lhs, const year_month& __rhs) noexcept { return __lhs.month() <=> __rhs.month(); } -_LIBCPP_HIDE_FROM_ABI inline constexpr year_month operator+(const year_month& __lhs, const months& __rhs) noexcept { +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr year_month +operator+(const year_month& __lhs, const months& __rhs) noexcept { int __dmi = static_cast(static_cast(__lhs.month())) - 1 + __rhs.count(); const int __dy = (__dmi >= 0 ? __dmi : __dmi - 11) / 12; __dmi = __dmi - __dy * 12 + 1; return (__lhs.year() + years(__dy)) / month(static_cast(__dmi)); } -_LIBCPP_HIDE_FROM_ABI inline constexpr year_month operator+(const months& __lhs, const year_month& __rhs) noexcept { +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr year_month +operator+(const months& __lhs, const year_month& __rhs) noexcept { return __rhs + __lhs; } -_LIBCPP_HIDE_FROM_ABI inline constexpr year_month operator+(const year_month& __lhs, const years& __rhs) noexcept { +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr year_month +operator+(const year_month& __lhs, const years& __rhs) noexcept { return (__lhs.year() + __rhs) / __lhs.month(); } -_LIBCPP_HIDE_FROM_ABI inline constexpr year_month operator+(const years& __lhs, const year_month& __rhs) noexcept { +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr year_month +operator+(const years& __lhs, const year_month& __rhs) noexcept { return __rhs + __lhs; } -_LIBCPP_HIDE_FROM_ABI inline constexpr months operator-(const year_month& __lhs, const year_month& __rhs) noexcept { +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr months +operator-(const year_month& __lhs, const year_month& __rhs) noexcept { return (__lhs.year() - __rhs.year()) + months(static_cast(__lhs.month()) - static_cast(__rhs.month())); } -_LIBCPP_HIDE_FROM_ABI inline constexpr year_month operator-(const year_month& __lhs, const months& __rhs) noexcept { +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr year_month +operator-(const year_month& __lhs, const months& __rhs) noexcept { return __lhs + -__rhs; } -_LIBCPP_HIDE_FROM_ABI inline constexpr year_month operator-(const year_month& __lhs, const years& __rhs) noexcept { +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr year_month +operator-(const year_month& __lhs, const years& __rhs) noexcept { return __lhs + -__rhs; } @@ -122,7 +129,7 @@ _LIBCPP_HIDE_FROM_ABI inline constexpr year_month& year_month::operator-=(const template <> struct hash { - _LIBCPP_HIDE_FROM_ABI static size_t operator()(const chrono::year_month& __ym) noexcept { + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static size_t operator()(const chrono::year_month& __ym) noexcept { return std::__hash_combine(hash{}(__ym.year()), hash{}(__ym.month())); } }; diff --git a/lib/libcxx/include/__chrono/year_month_day.h b/lib/libcxx/include/__chrono/year_month_day.h index 0a2aaedd60505a1368b511829164089cb98d4459..b0149d3ee1a37f282d3efe1e70dd0b4da60a066a 100644 --- a/lib/libcxx/include/__chrono/year_month_day.h +++ b/lib/libcxx/include/__chrono/year_month_day.h @@ -59,15 +59,15 @@ public: _LIBCPP_HIDE_FROM_ABI constexpr year_month_day& operator+=(const years& __dy) noexcept; _LIBCPP_HIDE_FROM_ABI constexpr year_month_day& operator-=(const years& __dy) noexcept; - _LIBCPP_HIDE_FROM_ABI inline constexpr chrono::year year() const noexcept { return __y_; } - _LIBCPP_HIDE_FROM_ABI inline constexpr chrono::month month() const noexcept { return __m_; } - _LIBCPP_HIDE_FROM_ABI inline constexpr chrono::day day() const noexcept { return __d_; } + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr chrono::year year() const noexcept { return __y_; } + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr chrono::month month() const noexcept { return __m_; } + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr chrono::day day() const noexcept { return __d_; } _LIBCPP_HIDE_FROM_ABI inline constexpr operator sys_days() const noexcept { return sys_days{__to_days()}; } _LIBCPP_HIDE_FROM_ABI inline explicit constexpr operator local_days() const noexcept { return local_days{__to_days()}; } - _LIBCPP_HIDE_FROM_ABI constexpr bool ok() const noexcept; + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool ok() const noexcept; _LIBCPP_HIDE_FROM_ABI static constexpr year_month_day __from_days(days __d) noexcept; _LIBCPP_HIDE_FROM_ABI constexpr days __to_days() const noexcept; @@ -119,56 +119,62 @@ operator<=>(const year_month_day& __lhs, const year_month_day& __rhs) noexcept { return __lhs.day() <=> __rhs.day(); } -_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day operator/(const year_month& __lhs, const day& __rhs) noexcept { +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day +operator/(const year_month& __lhs, const day& __rhs) noexcept { return year_month_day{__lhs.year(), __lhs.month(), __rhs}; } -_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day operator/(const year_month& __lhs, int __rhs) noexcept { +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day +operator/(const year_month& __lhs, int __rhs) noexcept { return __lhs / day(__rhs); } -_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day operator/(const year& __lhs, const month_day& __rhs) noexcept { +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day +operator/(const year& __lhs, const month_day& __rhs) noexcept { return __lhs / __rhs.month() / __rhs.day(); } -_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day operator/(int __lhs, const month_day& __rhs) noexcept { +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day +operator/(int __lhs, const month_day& __rhs) noexcept { return year(__lhs) / __rhs; } -_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day operator/(const month_day& __lhs, const year& __rhs) noexcept { +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day +operator/(const month_day& __lhs, const year& __rhs) noexcept { return __rhs / __lhs; } -_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day operator/(const month_day& __lhs, int __rhs) noexcept { +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day +operator/(const month_day& __lhs, int __rhs) noexcept { return year(__rhs) / __lhs; } -_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day operator+(const year_month_day& __lhs, const months& __rhs) noexcept { return (__lhs.year() / __lhs.month() + __rhs) / __lhs.day(); } -_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day operator+(const months& __lhs, const year_month_day& __rhs) noexcept { return __rhs + __lhs; } -_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day operator-(const year_month_day& __lhs, const months& __rhs) noexcept { return __lhs + -__rhs; } -_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day operator+(const year_month_day& __lhs, const years& __rhs) noexcept { return (__lhs.year() + __rhs) / __lhs.month() / __lhs.day(); } -_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day operator+(const years& __lhs, const year_month_day& __rhs) noexcept { return __rhs + __lhs; } -_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day operator-(const year_month_day& __lhs, const years& __rhs) noexcept { return __lhs + -__rhs; } @@ -204,17 +210,19 @@ public: _LIBCPP_HIDE_FROM_ABI constexpr year_month_day_last& operator+=(const years& __y) noexcept; _LIBCPP_HIDE_FROM_ABI constexpr year_month_day_last& operator-=(const years& __y) noexcept; - _LIBCPP_HIDE_FROM_ABI inline constexpr chrono::year year() const noexcept { return __y_; } - _LIBCPP_HIDE_FROM_ABI inline constexpr chrono::month month() const noexcept { return __mdl_.month(); } - _LIBCPP_HIDE_FROM_ABI inline constexpr chrono::month_day_last month_day_last() const noexcept { return __mdl_; } - _LIBCPP_HIDE_FROM_ABI constexpr chrono::day day() const noexcept; + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr chrono::year year() const noexcept { return __y_; } + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr chrono::month month() const noexcept { return __mdl_.month(); } + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr chrono::month_day_last month_day_last() const noexcept { + return __mdl_; + } + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr chrono::day day() const noexcept; _LIBCPP_HIDE_FROM_ABI inline constexpr operator sys_days() const noexcept { return sys_days{year() / month() / day()}; } _LIBCPP_HIDE_FROM_ABI inline explicit constexpr operator local_days() const noexcept { return local_days{year() / month() / day()}; } - _LIBCPP_HIDE_FROM_ABI inline constexpr bool ok() const noexcept { return __y_.ok() && __mdl_.ok(); } + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr bool ok() const noexcept { return __y_.ok() && __mdl_.ok(); } }; _LIBCPP_HIDE_FROM_ABI inline constexpr chrono::day year_month_day_last::day() const noexcept { @@ -248,54 +256,57 @@ operator<=>(const year_month_day_last& __lhs, const year_month_day_last& __rhs) return __lhs.month_day_last() <=> __rhs.month_day_last(); } -_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day_last operator/(const year_month& __lhs, last_spec) noexcept { +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day_last +operator/(const year_month& __lhs, last_spec) noexcept { return year_month_day_last{__lhs.year(), month_day_last{__lhs.month()}}; } -_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day_last +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day_last operator/(const year& __lhs, const month_day_last& __rhs) noexcept { return year_month_day_last{__lhs, __rhs}; } -_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day_last operator/(int __lhs, const month_day_last& __rhs) noexcept { +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day_last +operator/(int __lhs, const month_day_last& __rhs) noexcept { return year_month_day_last{year{__lhs}, __rhs}; } -_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day_last +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day_last operator/(const month_day_last& __lhs, const year& __rhs) noexcept { return __rhs / __lhs; } -_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day_last operator/(const month_day_last& __lhs, int __rhs) noexcept { +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day_last +operator/(const month_day_last& __lhs, int __rhs) noexcept { return year{__rhs} / __lhs; } -_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day_last +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day_last operator+(const year_month_day_last& __lhs, const months& __rhs) noexcept { return (__lhs.year() / __lhs.month() + __rhs) / last; } -_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day_last +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day_last operator+(const months& __lhs, const year_month_day_last& __rhs) noexcept { return __rhs + __lhs; } -_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day_last +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day_last operator-(const year_month_day_last& __lhs, const months& __rhs) noexcept { return __lhs + (-__rhs); } -_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day_last +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day_last operator+(const year_month_day_last& __lhs, const years& __rhs) noexcept { return year_month_day_last{__lhs.year() + __rhs, __lhs.month_day_last()}; } -_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day_last +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day_last operator+(const years& __lhs, const year_month_day_last& __rhs) noexcept { return __rhs + __lhs; } -_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day_last +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day_last operator-(const year_month_day_last& __lhs, const years& __rhs) noexcept { return __lhs + (-__rhs); } @@ -336,7 +347,7 @@ _LIBCPP_HIDE_FROM_ABI inline constexpr bool year_month_day::ok() const noexcept template <> struct hash { - _LIBCPP_HIDE_FROM_ABI static size_t operator()(const chrono::year_month_day& __ymd) noexcept { + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static size_t operator()(const chrono::year_month_day& __ymd) noexcept { return std::__hash_combine( hash{}(__ymd.year()), std::__hash_combine(hash{}(__ymd.month()), hash{}(__ymd.day()))); @@ -345,7 +356,7 @@ struct hash { template <> struct hash { - _LIBCPP_HIDE_FROM_ABI static size_t operator()(const chrono::year_month_day_last& __ymdl) noexcept { + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static size_t operator()(const chrono::year_month_day_last& __ymdl) noexcept { return std::__hash_combine( hash{}(__ymdl.year()), hash{}(__ymdl.month_day_last())); } diff --git a/lib/libcxx/include/__chrono/year_month_weekday.h b/lib/libcxx/include/__chrono/year_month_weekday.h index 6ed1e21fe97e53178c08d4f8835a5c452f801b5b..eff472ffcc8a8451df90f746e038a57dc6433818 100644 --- a/lib/libcxx/include/__chrono/year_month_weekday.h +++ b/lib/libcxx/include/__chrono/year_month_weekday.h @@ -54,17 +54,21 @@ public: _LIBCPP_HIDE_FROM_ABI constexpr year_month_weekday& operator+=(const years&) noexcept; _LIBCPP_HIDE_FROM_ABI constexpr year_month_weekday& operator-=(const years&) noexcept; - _LIBCPP_HIDE_FROM_ABI inline constexpr chrono::year year() const noexcept { return __y_; } - _LIBCPP_HIDE_FROM_ABI inline constexpr chrono::month month() const noexcept { return __m_; } - _LIBCPP_HIDE_FROM_ABI inline constexpr chrono::weekday weekday() const noexcept { return __wdi_.weekday(); } - _LIBCPP_HIDE_FROM_ABI inline constexpr unsigned index() const noexcept { return __wdi_.index(); } - _LIBCPP_HIDE_FROM_ABI inline constexpr chrono::weekday_indexed weekday_indexed() const noexcept { return __wdi_; } + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr chrono::year year() const noexcept { return __y_; } + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr chrono::month month() const noexcept { return __m_; } + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr chrono::weekday weekday() const noexcept { + return __wdi_.weekday(); + } + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr unsigned index() const noexcept { return __wdi_.index(); } + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr chrono::weekday_indexed weekday_indexed() const noexcept { + return __wdi_; + } _LIBCPP_HIDE_FROM_ABI inline constexpr operator sys_days() const noexcept { return sys_days{__to_days()}; } _LIBCPP_HIDE_FROM_ABI inline explicit constexpr operator local_days() const noexcept { return local_days{__to_days()}; } - _LIBCPP_HIDE_FROM_ABI inline constexpr bool ok() const noexcept { + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr bool ok() const noexcept { if (!__y_.ok() || !__m_.ok() || !__wdi_.ok()) return false; if (__wdi_.index() <= 4) @@ -96,55 +100,57 @@ operator==(const year_month_weekday& __lhs, const year_month_weekday& __rhs) noe __lhs.weekday_indexed() == __rhs.weekday_indexed(); } -_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_weekday +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr year_month_weekday operator/(const year_month& __lhs, const weekday_indexed& __rhs) noexcept { return year_month_weekday{__lhs.year(), __lhs.month(), __rhs}; } -_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_weekday +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr year_month_weekday operator/(const year& __lhs, const month_weekday& __rhs) noexcept { return year_month_weekday{__lhs, __rhs.month(), __rhs.weekday_indexed()}; } -_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_weekday operator/(int __lhs, const month_weekday& __rhs) noexcept { +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr year_month_weekday +operator/(int __lhs, const month_weekday& __rhs) noexcept { return year(__lhs) / __rhs; } -_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_weekday +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr year_month_weekday operator/(const month_weekday& __lhs, const year& __rhs) noexcept { return __rhs / __lhs; } -_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_weekday operator/(const month_weekday& __lhs, int __rhs) noexcept { +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr year_month_weekday +operator/(const month_weekday& __lhs, int __rhs) noexcept { return year(__rhs) / __lhs; } -_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_weekday +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr year_month_weekday operator+(const year_month_weekday& __lhs, const months& __rhs) noexcept { return (__lhs.year() / __lhs.month() + __rhs) / __lhs.weekday_indexed(); } -_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_weekday +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr year_month_weekday operator+(const months& __lhs, const year_month_weekday& __rhs) noexcept { return __rhs + __lhs; } -_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_weekday +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr year_month_weekday operator-(const year_month_weekday& __lhs, const months& __rhs) noexcept { return __lhs + (-__rhs); } -_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_weekday +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr year_month_weekday operator+(const year_month_weekday& __lhs, const years& __rhs) noexcept { return year_month_weekday{__lhs.year() + __rhs, __lhs.month(), __lhs.weekday_indexed()}; } -_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_weekday +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr year_month_weekday operator+(const years& __lhs, const year_month_weekday& __rhs) noexcept { return __rhs + __lhs; } -_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_weekday +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr year_month_weekday operator-(const year_month_weekday& __lhs, const years& __rhs) noexcept { return __lhs + (-__rhs); } @@ -181,15 +187,21 @@ public: _LIBCPP_HIDE_FROM_ABI constexpr year_month_weekday_last& operator+=(const years& __dy) noexcept; _LIBCPP_HIDE_FROM_ABI constexpr year_month_weekday_last& operator-=(const years& __dy) noexcept; - _LIBCPP_HIDE_FROM_ABI inline constexpr chrono::year year() const noexcept { return __y_; } - _LIBCPP_HIDE_FROM_ABI inline constexpr chrono::month month() const noexcept { return __m_; } - _LIBCPP_HIDE_FROM_ABI inline constexpr chrono::weekday weekday() const noexcept { return __wdl_.weekday(); } - _LIBCPP_HIDE_FROM_ABI inline constexpr chrono::weekday_last weekday_last() const noexcept { return __wdl_; } + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr chrono::year year() const noexcept { return __y_; } + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr chrono::month month() const noexcept { return __m_; } + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr chrono::weekday weekday() const noexcept { + return __wdl_.weekday(); + } + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr chrono::weekday_last weekday_last() const noexcept { + return __wdl_; + } _LIBCPP_HIDE_FROM_ABI inline constexpr operator sys_days() const noexcept { return sys_days{__to_days()}; } _LIBCPP_HIDE_FROM_ABI inline explicit constexpr operator local_days() const noexcept { return local_days{__to_days()}; } - _LIBCPP_HIDE_FROM_ABI inline constexpr bool ok() const noexcept { return __y_.ok() && __m_.ok() && __wdl_.ok(); } + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr bool ok() const noexcept { + return __y_.ok() && __m_.ok() && __wdl_.ok(); + } _LIBCPP_HIDE_FROM_ABI constexpr days __to_days() const noexcept; }; @@ -204,57 +216,57 @@ operator==(const year_month_weekday_last& __lhs, const year_month_weekday_last& return __lhs.year() == __rhs.year() && __lhs.month() == __rhs.month() && __lhs.weekday_last() == __rhs.weekday_last(); } -_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_weekday_last +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr year_month_weekday_last operator/(const year_month& __lhs, const weekday_last& __rhs) noexcept { return year_month_weekday_last{__lhs.year(), __lhs.month(), __rhs}; } -_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_weekday_last +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr year_month_weekday_last operator/(const year& __lhs, const month_weekday_last& __rhs) noexcept { return year_month_weekday_last{__lhs, __rhs.month(), __rhs.weekday_last()}; } -_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_weekday_last +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr year_month_weekday_last operator/(int __lhs, const month_weekday_last& __rhs) noexcept { return year(__lhs) / __rhs; } -_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_weekday_last +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr year_month_weekday_last operator/(const month_weekday_last& __lhs, const year& __rhs) noexcept { return __rhs / __lhs; } -_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_weekday_last +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr year_month_weekday_last operator/(const month_weekday_last& __lhs, int __rhs) noexcept { return year(__rhs) / __lhs; } -_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_weekday_last +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr year_month_weekday_last operator+(const year_month_weekday_last& __lhs, const months& __rhs) noexcept { return (__lhs.year() / __lhs.month() + __rhs) / __lhs.weekday_last(); } -_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_weekday_last +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr year_month_weekday_last operator+(const months& __lhs, const year_month_weekday_last& __rhs) noexcept { return __rhs + __lhs; } -_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_weekday_last +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr year_month_weekday_last operator-(const year_month_weekday_last& __lhs, const months& __rhs) noexcept { return __lhs + (-__rhs); } -_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_weekday_last +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr year_month_weekday_last operator+(const year_month_weekday_last& __lhs, const years& __rhs) noexcept { return year_month_weekday_last{__lhs.year() + __rhs, __lhs.month(), __lhs.weekday_last()}; } -_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_weekday_last +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr year_month_weekday_last operator+(const years& __lhs, const year_month_weekday_last& __rhs) noexcept { return __rhs + __lhs; } -_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_weekday_last +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr year_month_weekday_last operator-(const year_month_weekday_last& __lhs, const years& __rhs) noexcept { return __lhs + (-__rhs); } @@ -286,7 +298,7 @@ year_month_weekday_last::operator-=(const years& __dy) noexcept { template <> struct hash { - _LIBCPP_HIDE_FROM_ABI static size_t operator()(const chrono::year_month_weekday& __ymw) noexcept { + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static size_t operator()(const chrono::year_month_weekday& __ymw) noexcept { return std::__hash_combine( hash{}(__ymw.year()), std::__hash_combine( @@ -296,7 +308,7 @@ struct hash { template <> struct hash { - _LIBCPP_HIDE_FROM_ABI static size_t operator()(const chrono::year_month_weekday_last& __ymwl) noexcept { + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static size_t operator()(const chrono::year_month_weekday_last& __ymwl) noexcept { return std::__hash_combine( hash{}(__ymwl.year()), std::__hash_combine( diff --git a/lib/libcxx/include/__chrono/zoned_time.h b/lib/libcxx/include/__chrono/zoned_time.h index e63528e57d1cc53784509da1bc8fcbc85b081b65..c1488320775fc5e9dc44449dd894eebde43a96a2 100644 --- a/lib/libcxx/include/__chrono/zoned_time.h +++ b/lib/libcxx/include/__chrono/zoned_time.h @@ -40,10 +40,10 @@ _LIBCPP_PUSH_MACROS # include <__undef_macros> -_LIBCPP_BEGIN_NAMESPACE_STD - # if _LIBCPP_STD_VER >= 20 && _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM && _LIBCPP_HAS_LOCALIZATION +_LIBCPP_BEGIN_NAMESPACE_STD + namespace chrono { template @@ -232,11 +232,11 @@ struct hash> { # endif // _LIBCPP_STD_VER >= 26 +_LIBCPP_END_NAMESPACE_STD + # endif // _LIBCPP_STD_VER >= 20 && _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM && // _LIBCPP_HAS_LOCALIZATION -_LIBCPP_END_NAMESPACE_STD - _LIBCPP_POP_MACROS #endif // _LIBCPP_HAS_EXPERIMENTAL_TZDB diff --git a/lib/libcxx/include/__compare/common_comparison_category.h b/lib/libcxx/include/__compare/common_comparison_category.h index eae2ef00624bece63b45dc922efd8926d64d29e4..f785a27fd28e51c6443dccf27b267163dd610ebd 100644 --- a/lib/libcxx/include/__compare/common_comparison_category.h +++ b/lib/libcxx/include/__compare/common_comparison_category.h @@ -18,10 +18,10 @@ # pragma GCC system_header #endif -_LIBCPP_BEGIN_NAMESPACE_STD - #if _LIBCPP_STD_VER >= 20 +_LIBCPP_BEGIN_NAMESPACE_STD + namespace __comp_detail { enum _ClassifyCompCategory : unsigned { _None, _PartialOrd, _WeakOrd, _StrongOrd, _CCC_Size }; @@ -79,8 +79,8 @@ struct common_comparison_category { template using common_comparison_category_t = typename common_comparison_category<_Ts...>::type; -#endif // _LIBCPP_STD_VER >= 20 - _LIBCPP_END_NAMESPACE_STD +#endif // _LIBCPP_STD_VER >= 20 + #endif // _LIBCPP___COMPARE_COMMON_COMPARISON_CATEGORY_H diff --git a/lib/libcxx/include/__compare/compare_three_way.h b/lib/libcxx/include/__compare/compare_three_way.h index 852c5874c61ca87b454ed75e8c39af22181d6903..6999000e9dceae4ae74f23f1a17e1863b4e80fe8 100644 --- a/lib/libcxx/include/__compare/compare_three_way.h +++ b/lib/libcxx/include/__compare/compare_three_way.h @@ -18,10 +18,10 @@ # pragma GCC system_header #endif -_LIBCPP_BEGIN_NAMESPACE_STD - #if _LIBCPP_STD_VER >= 20 +_LIBCPP_BEGIN_NAMESPACE_STD + struct compare_three_way { template requires three_way_comparable_with<_T1, _T2> @@ -33,8 +33,8 @@ struct compare_three_way { using is_transparent = void; }; -#endif // _LIBCPP_STD_VER >= 20 - _LIBCPP_END_NAMESPACE_STD +#endif // _LIBCPP_STD_VER >= 20 + #endif // _LIBCPP___COMPARE_COMPARE_THREE_WAY_H diff --git a/lib/libcxx/include/__compare/compare_three_way_result.h b/lib/libcxx/include/__compare/compare_three_way_result.h index 264a4d603ca442ac6631638e0655c04f37dd94c8..ab04e03490e25fca102071ff5b9cb9e3c4f2a184 100644 --- a/lib/libcxx/include/__compare/compare_three_way_result.h +++ b/lib/libcxx/include/__compare/compare_three_way_result.h @@ -17,10 +17,10 @@ # pragma GCC system_header #endif -_LIBCPP_BEGIN_NAMESPACE_STD - #if _LIBCPP_STD_VER >= 20 +_LIBCPP_BEGIN_NAMESPACE_STD + template struct _LIBCPP_HIDE_FROM_ABI __compare_three_way_result {}; @@ -39,8 +39,8 @@ struct _LIBCPP_NO_SPECIALIZATIONS compare_three_way_result : __compare_three_way template using compare_three_way_result_t = typename compare_three_way_result<_Tp, _Up>::type; -#endif // _LIBCPP_STD_VER >= 20 - _LIBCPP_END_NAMESPACE_STD +#endif // _LIBCPP_STD_VER >= 20 + #endif // _LIBCPP___COMPARE_COMPARE_THREE_WAY_RESULT_H diff --git a/lib/libcxx/include/__compare/ordering.h b/lib/libcxx/include/__compare/ordering.h index 902ef5329dd431c21defb044d24ea8125187e03f..226b513586bb1ccbf9b3de8095ea09501a333d7f 100644 --- a/lib/libcxx/include/__compare/ordering.h +++ b/lib/libcxx/include/__compare/ordering.h @@ -17,10 +17,10 @@ # pragma GCC system_header #endif -_LIBCPP_BEGIN_NAMESPACE_STD - #if _LIBCPP_STD_VER >= 20 +_LIBCPP_BEGIN_NAMESPACE_STD + // exposition only enum class _OrdResult : signed char { __less = -1, __equiv = 0, __greater = 1 }; @@ -275,8 +275,8 @@ template concept __comparison_category = is_same_v<_Tp, partial_ordering> || is_same_v<_Tp, weak_ordering> || is_same_v<_Tp, strong_ordering>; -#endif // _LIBCPP_STD_VER >= 20 - _LIBCPP_END_NAMESPACE_STD +#endif // _LIBCPP_STD_VER >= 20 + #endif // _LIBCPP___COMPARE_ORDERING_H diff --git a/lib/libcxx/include/__compare/synth_three_way.h b/lib/libcxx/include/__compare/synth_three_way.h index 63bf56d0cf42b787ab737b422fb53bb1c3c192de..e1c2642fbdf24c13a41af3d962691750625e85d3 100644 --- a/lib/libcxx/include/__compare/synth_three_way.h +++ b/lib/libcxx/include/__compare/synth_three_way.h @@ -19,10 +19,10 @@ # pragma GCC system_header #endif -_LIBCPP_BEGIN_NAMESPACE_STD - #if _LIBCPP_STD_VER >= 20 +_LIBCPP_BEGIN_NAMESPACE_STD + // [expos.only.func] _LIBCPP_HIDE_FROM_ABI inline constexpr auto __synth_three_way = [](const _Tp& __t, const _Up& __u) @@ -46,8 +46,8 @@ template using __synth_three_way_result _LIBCPP_NODEBUG = decltype(std::__synth_three_way(std::declval<_Tp&>(), std::declval<_Up&>())); -#endif // _LIBCPP_STD_VER >= 20 - _LIBCPP_END_NAMESPACE_STD +#endif // _LIBCPP_STD_VER >= 20 + #endif // _LIBCPP___COMPARE_SYNTH_THREE_WAY_H diff --git a/lib/libcxx/include/__compare/three_way_comparable.h b/lib/libcxx/include/__compare/three_way_comparable.h index ad6d05a6811459f075ecf1df95e4eaaca095f55f..5eb0058708fc98e09d581f8709282a697d7fee88 100644 --- a/lib/libcxx/include/__compare/three_way_comparable.h +++ b/lib/libcxx/include/__compare/three_way_comparable.h @@ -24,10 +24,10 @@ # pragma GCC system_header #endif -_LIBCPP_BEGIN_NAMESPACE_STD - #if _LIBCPP_STD_VER >= 20 +_LIBCPP_BEGIN_NAMESPACE_STD + template concept __compares_as = same_as, _Cat>; @@ -48,8 +48,8 @@ concept three_way_comparable_with = { __u <=> __t } -> __compares_as<_Cat>; }; -#endif // _LIBCPP_STD_VER >= 20 - _LIBCPP_END_NAMESPACE_STD +#endif // _LIBCPP_STD_VER >= 20 + #endif // _LIBCPP___COMPARE_THREE_WAY_COMPARABLE_H diff --git a/lib/libcxx/include/__concepts/arithmetic.h b/lib/libcxx/include/__concepts/arithmetic.h index 64c0200783df7b4c480bb7521a63150eaac83312..addbefa7e11a6638a8a5ef0c7f47342e1e789d28 100644 --- a/lib/libcxx/include/__concepts/arithmetic.h +++ b/lib/libcxx/include/__concepts/arithmetic.h @@ -18,10 +18,10 @@ # pragma GCC system_header #endif -_LIBCPP_BEGIN_NAMESPACE_STD - #if _LIBCPP_STD_VER >= 20 +_LIBCPP_BEGIN_NAMESPACE_STD + // [concepts.arithmetic], arithmetic concepts template @@ -36,8 +36,8 @@ concept unsigned_integral = integral<_Tp> && !signed_integral<_Tp>; template concept floating_point = is_floating_point_v<_Tp>; -#endif // _LIBCPP_STD_VER >= 20 - _LIBCPP_END_NAMESPACE_STD +#endif // _LIBCPP_STD_VER >= 20 + #endif // _LIBCPP___CONCEPTS_ARITHMETIC_H diff --git a/lib/libcxx/include/__concepts/assignable.h b/lib/libcxx/include/__concepts/assignable.h index 7423daabba7801b839a438d8a7986e21b6f06088..70f0bc3b0c95a51d26a40536e0d0f92397ba1eea 100644 --- a/lib/libcxx/include/__concepts/assignable.h +++ b/lib/libcxx/include/__concepts/assignable.h @@ -20,10 +20,10 @@ # pragma GCC system_header #endif -_LIBCPP_BEGIN_NAMESPACE_STD - #if _LIBCPP_STD_VER >= 20 +_LIBCPP_BEGIN_NAMESPACE_STD + // [concept.assignable] template @@ -34,8 +34,8 @@ concept assignable_from = { __lhs = std::forward<_Rhs>(__rhs) } -> same_as<_Lhs>; }; -#endif // _LIBCPP_STD_VER >= 20 - _LIBCPP_END_NAMESPACE_STD +#endif // _LIBCPP_STD_VER >= 20 + #endif // _LIBCPP___CONCEPTS_ASSIGNABLE_H diff --git a/lib/libcxx/include/__concepts/boolean_testable.h b/lib/libcxx/include/__concepts/boolean_testable.h index b379fe9c5a88047935151ac954f983555274fa24..458e4c1da7251646e27872dec01c323b52fa8e0c 100644 --- a/lib/libcxx/include/__concepts/boolean_testable.h +++ b/lib/libcxx/include/__concepts/boolean_testable.h @@ -17,10 +17,10 @@ # pragma GCC system_header #endif -_LIBCPP_BEGIN_NAMESPACE_STD - #if _LIBCPP_STD_VER >= 20 +_LIBCPP_BEGIN_NAMESPACE_STD + // [concepts.booleantestable] template @@ -31,8 +31,8 @@ concept __boolean_testable = __boolean_testable_impl<_Tp> && requires(_Tp&& __t) { !std::forward<_Tp>(__t) } -> __boolean_testable_impl; }; -#endif // _LIBCPP_STD_VER >= 20 - _LIBCPP_END_NAMESPACE_STD +#endif // _LIBCPP_STD_VER >= 20 + #endif // _LIBCPP___CONCEPTS_BOOLEAN_TESTABLE_H diff --git a/lib/libcxx/include/__concepts/class_or_enum.h b/lib/libcxx/include/__concepts/class_or_enum.h index 9fceed034c4681e099d0f55512e8c3a50f57c4cc..920bf8a6fa70961e0b19edede142420ffc138af3 100644 --- a/lib/libcxx/include/__concepts/class_or_enum.h +++ b/lib/libcxx/include/__concepts/class_or_enum.h @@ -18,17 +18,17 @@ # pragma GCC system_header #endif -_LIBCPP_BEGIN_NAMESPACE_STD - #if _LIBCPP_STD_VER >= 20 +_LIBCPP_BEGIN_NAMESPACE_STD + // Whether a type is a class type or enumeration type according to the Core wording. template concept __class_or_enum = is_class_v<_Tp> || is_union_v<_Tp> || is_enum_v<_Tp>; -#endif // _LIBCPP_STD_VER >= 20 - _LIBCPP_END_NAMESPACE_STD +#endif // _LIBCPP_STD_VER >= 20 + #endif // _LIBCPP___CONCEPTS_CLASS_OR_ENUM_H diff --git a/lib/libcxx/include/__concepts/common_reference_with.h b/lib/libcxx/include/__concepts/common_reference_with.h index 4eb687e071bc51318be3138d0e1baf3ff2f5b6a2..613de04b7b5b32f29c8d07b6101e9f01cf053fd4 100644 --- a/lib/libcxx/include/__concepts/common_reference_with.h +++ b/lib/libcxx/include/__concepts/common_reference_with.h @@ -18,10 +18,10 @@ # pragma GCC system_header #endif -_LIBCPP_BEGIN_NAMESPACE_STD - #if _LIBCPP_STD_VER >= 20 +_LIBCPP_BEGIN_NAMESPACE_STD + // [concept.commonref] template @@ -29,8 +29,8 @@ concept common_reference_with = same_as, common_reference_t<_Up, _Tp>> && convertible_to<_Tp, common_reference_t<_Tp, _Up>> && convertible_to<_Up, common_reference_t<_Tp, _Up>>; -#endif // _LIBCPP_STD_VER >= 20 - _LIBCPP_END_NAMESPACE_STD +#endif // _LIBCPP_STD_VER >= 20 + #endif // _LIBCPP___CONCEPTS_COMMON_REFERENCE_WITH_H diff --git a/lib/libcxx/include/__concepts/comparison_common_type.h b/lib/libcxx/include/__concepts/comparison_common_type.h index 3f0d770511f472a6ff6cdc3926df03ea00cad0b2..d06a8dc8786f991868a2772f502d2b76ea3bdb86 100644 --- a/lib/libcxx/include/__concepts/comparison_common_type.h +++ b/lib/libcxx/include/__concepts/comparison_common_type.h @@ -19,10 +19,10 @@ # pragma GCC system_header #endif -_LIBCPP_BEGIN_NAMESPACE_STD - #if _LIBCPP_STD_VER >= 20 +_LIBCPP_BEGIN_NAMESPACE_STD + template > concept __comparison_common_type_with_impl = same_as, common_reference_t> && requires { @@ -33,8 +33,8 @@ concept __comparison_common_type_with_impl = template concept __comparison_common_type_with = __comparison_common_type_with_impl, remove_cvref_t<_Up>>; -#endif // _LIBCPP_STD_VER >= 20 - _LIBCPP_END_NAMESPACE_STD +#endif // _LIBCPP_STD_VER >= 20 + #endif // _LIBCPP___CONCEPTS_COMPARISON_COMMON_TYPE_H diff --git a/lib/libcxx/include/__concepts/constructible.h b/lib/libcxx/include/__concepts/constructible.h index 835a44429c092f9bdaaa2aa250e76ce0053f134d..7b39c80304bcbd67e680eeaf57463da78ddee96d 100644 --- a/lib/libcxx/include/__concepts/constructible.h +++ b/lib/libcxx/include/__concepts/constructible.h @@ -18,10 +18,10 @@ # pragma GCC system_header #endif -_LIBCPP_BEGIN_NAMESPACE_STD - #if _LIBCPP_STD_VER >= 20 +_LIBCPP_BEGIN_NAMESPACE_STD + // [concept.constructible] template concept constructible_from = destructible<_Tp> && is_constructible_v<_Tp, _Args...>; @@ -48,8 +48,8 @@ concept copy_constructible = constructible_from<_Tp, const _Tp> && convertible_to; // clang-format on -#endif // _LIBCPP_STD_VER >= 20 - _LIBCPP_END_NAMESPACE_STD +#endif // _LIBCPP_STD_VER >= 20 + #endif // _LIBCPP___CONCEPTS_CONSTRUCTIBLE_H diff --git a/lib/libcxx/include/__concepts/convertible_to.h b/lib/libcxx/include/__concepts/convertible_to.h index 6d5b6c1268d5d2d1966de999779953f202071db9..01e3cfa2a3bf8da99961a2ae9b1cacb82e24a5be 100644 --- a/lib/libcxx/include/__concepts/convertible_to.h +++ b/lib/libcxx/include/__concepts/convertible_to.h @@ -17,17 +17,17 @@ # pragma GCC system_header #endif -_LIBCPP_BEGIN_NAMESPACE_STD - #if _LIBCPP_STD_VER >= 20 +_LIBCPP_BEGIN_NAMESPACE_STD + // [concept.convertible] template concept convertible_to = is_convertible_v<_From, _To> && requires { static_cast<_To>(std::declval<_From>()); }; -#endif // _LIBCPP_STD_VER >= 20 - _LIBCPP_END_NAMESPACE_STD +#endif // _LIBCPP_STD_VER >= 20 + #endif // _LIBCPP___CONCEPTS_CONVERTIBLE_TO_H diff --git a/lib/libcxx/include/__concepts/copyable.h b/lib/libcxx/include/__concepts/copyable.h index 2bf0ad42fc1a8393d5de87593e3b82fc2c48b730..3bcee3422902a03a48d7be28689e316659e8731d 100644 --- a/lib/libcxx/include/__concepts/copyable.h +++ b/lib/libcxx/include/__concepts/copyable.h @@ -18,10 +18,10 @@ # pragma GCC system_header #endif -_LIBCPP_BEGIN_NAMESPACE_STD - #if _LIBCPP_STD_VER >= 20 +_LIBCPP_BEGIN_NAMESPACE_STD + // [concepts.object] // clang-format off @@ -34,8 +34,8 @@ concept copyable = assignable_from<_Tp&, const _Tp>; // clang-format on -#endif // _LIBCPP_STD_VER >= 20 - _LIBCPP_END_NAMESPACE_STD +#endif // _LIBCPP_STD_VER >= 20 + #endif // _LIBCPP___CONCEPTS_COPYABLE_H diff --git a/lib/libcxx/include/__concepts/derived_from.h b/lib/libcxx/include/__concepts/derived_from.h index 9875faee81b90180af009403648a0fa0a5f76c98..418f5db8ba9a0e7ebda922ea4dcb32b9236dc718 100644 --- a/lib/libcxx/include/__concepts/derived_from.h +++ b/lib/libcxx/include/__concepts/derived_from.h @@ -17,17 +17,17 @@ # pragma GCC system_header #endif -_LIBCPP_BEGIN_NAMESPACE_STD - #if _LIBCPP_STD_VER >= 20 +_LIBCPP_BEGIN_NAMESPACE_STD + // [concept.derived] template concept derived_from = is_base_of_v<_Bp, _Dp> && is_convertible_v; -#endif // _LIBCPP_STD_VER >= 20 - _LIBCPP_END_NAMESPACE_STD +#endif // _LIBCPP_STD_VER >= 20 + #endif // _LIBCPP___CONCEPTS_DERIVED_FROM_H diff --git a/lib/libcxx/include/__concepts/destructible.h b/lib/libcxx/include/__concepts/destructible.h index 28b4b1bc24ec9f9140af3561fa3bce41de2c0932..1db7f6a0a7c714c82e8a23df6e8999abf0992562 100644 --- a/lib/libcxx/include/__concepts/destructible.h +++ b/lib/libcxx/include/__concepts/destructible.h @@ -16,17 +16,17 @@ # pragma GCC system_header #endif -_LIBCPP_BEGIN_NAMESPACE_STD - #if _LIBCPP_STD_VER >= 20 +_LIBCPP_BEGIN_NAMESPACE_STD + // [concept.destructible] template concept destructible = is_nothrow_destructible_v<_Tp>; -#endif // _LIBCPP_STD_VER >= 20 - _LIBCPP_END_NAMESPACE_STD +#endif // _LIBCPP_STD_VER >= 20 + #endif // _LIBCPP___CONCEPTS_DESTRUCTIBLE_H diff --git a/lib/libcxx/include/__concepts/different_from.h b/lib/libcxx/include/__concepts/different_from.h index fd31f6e25805d35c7a07320635c8ee5326923de4..f9888c918d7c9968771d527fa375f3d4fd83a0b5 100644 --- a/lib/libcxx/include/__concepts/different_from.h +++ b/lib/libcxx/include/__concepts/different_from.h @@ -17,15 +17,15 @@ # pragma GCC system_header #endif -_LIBCPP_BEGIN_NAMESPACE_STD - #if _LIBCPP_STD_VER >= 20 +_LIBCPP_BEGIN_NAMESPACE_STD + template concept __different_from = !same_as, remove_cvref_t<_Up>>; -#endif // _LIBCPP_STD_VER >= 20 - _LIBCPP_END_NAMESPACE_STD +#endif // _LIBCPP_STD_VER >= 20 + #endif // _LIBCPP___CONCEPTS_DIFFERENT_FROM_H diff --git a/lib/libcxx/include/__concepts/equality_comparable.h b/lib/libcxx/include/__concepts/equality_comparable.h index 56fc6f8b685c0b61fde50d523e55267a5207cde4..411a19c60ddd9f7223e0a9e712d8e77f9234e3c4 100644 --- a/lib/libcxx/include/__concepts/equality_comparable.h +++ b/lib/libcxx/include/__concepts/equality_comparable.h @@ -20,10 +20,10 @@ # pragma GCC system_header #endif -_LIBCPP_BEGIN_NAMESPACE_STD - #if _LIBCPP_STD_VER >= 20 +_LIBCPP_BEGIN_NAMESPACE_STD + // [concept.equalitycomparable] template @@ -50,8 +50,8 @@ concept equality_comparable_with = __weakly_equality_comparable_with<_Tp, _Up>; // clang-format on -#endif // _LIBCPP_STD_VER >= 20 - _LIBCPP_END_NAMESPACE_STD +#endif // _LIBCPP_STD_VER >= 20 + #endif // _LIBCPP___CONCEPTS_EQUALITY_COMPARABLE_H diff --git a/lib/libcxx/include/__concepts/invocable.h b/lib/libcxx/include/__concepts/invocable.h index 8a29398b3a29f8ea60683e4b6f0885ac8c38917f..92b2ec56affa46cea467e45b74c65b2eef615812 100644 --- a/lib/libcxx/include/__concepts/invocable.h +++ b/lib/libcxx/include/__concepts/invocable.h @@ -17,10 +17,10 @@ # pragma GCC system_header #endif -_LIBCPP_BEGIN_NAMESPACE_STD - #if _LIBCPP_STD_VER >= 20 +_LIBCPP_BEGIN_NAMESPACE_STD + // [concept.invocable] template @@ -33,8 +33,8 @@ concept invocable = requires(_Fn&& __fn, _Args&&... __args) { template concept regular_invocable = invocable<_Fn, _Args...>; -#endif // _LIBCPP_STD_VER >= 20 - _LIBCPP_END_NAMESPACE_STD +#endif // _LIBCPP_STD_VER >= 20 + #endif // _LIBCPP___CONCEPTS_INVOCABLE_H diff --git a/lib/libcxx/include/__concepts/movable.h b/lib/libcxx/include/__concepts/movable.h index bc5b9d767c6a51b309c4abeaf79b35c1ebd7aabb..f38ab37be89a487c4d27b98c370864ddfbd00e78 100644 --- a/lib/libcxx/include/__concepts/movable.h +++ b/lib/libcxx/include/__concepts/movable.h @@ -19,17 +19,17 @@ # pragma GCC system_header #endif -_LIBCPP_BEGIN_NAMESPACE_STD - #if _LIBCPP_STD_VER >= 20 +_LIBCPP_BEGIN_NAMESPACE_STD + // [concepts.object] template concept movable = is_object_v<_Tp> && move_constructible<_Tp> && assignable_from<_Tp&, _Tp> && swappable<_Tp>; -#endif // _LIBCPP_STD_VER >= 20 - _LIBCPP_END_NAMESPACE_STD +#endif // _LIBCPP_STD_VER >= 20 + #endif // _LIBCPP___CONCEPTS_MOVABLE_H diff --git a/lib/libcxx/include/__concepts/predicate.h b/lib/libcxx/include/__concepts/predicate.h index e0263a878b0650e0cf884e01d5d68d52d91d01a8..9e903a9efdb2206a1286c1e4959a721cb8e64d56 100644 --- a/lib/libcxx/include/__concepts/predicate.h +++ b/lib/libcxx/include/__concepts/predicate.h @@ -18,17 +18,17 @@ # pragma GCC system_header #endif -_LIBCPP_BEGIN_NAMESPACE_STD - #if _LIBCPP_STD_VER >= 20 +_LIBCPP_BEGIN_NAMESPACE_STD + // [concept.predicate] template concept predicate = regular_invocable<_Fn, _Args...> && __boolean_testable>; -#endif // _LIBCPP_STD_VER >= 20 - _LIBCPP_END_NAMESPACE_STD +#endif // _LIBCPP_STD_VER >= 20 + #endif // _LIBCPP___CONCEPTS_PREDICATE_H diff --git a/lib/libcxx/include/__type_traits/is_primary_template.h b/lib/libcxx/include/__concepts/primary_template.h similarity index 69% rename from lib/libcxx/include/__type_traits/is_primary_template.h rename to lib/libcxx/include/__concepts/primary_template.h index 5fe6820bc7f7ac0325d63703776ba95c3f1d9ebf..ab22b6dc74eed734b0a451b376e58d34b0a26282 100644 --- a/lib/libcxx/include/__type_traits/is_primary_template.h +++ b/lib/libcxx/include/__concepts/primary_template.h @@ -10,23 +10,24 @@ #define _LIBCPP___TYPE_TRAITS_IS_PRIMARY_TEMPLATE_H #include <__config> -#include <__type_traits/enable_if.h> #include <__type_traits/is_same.h> -#include <__type_traits/is_valid_expansion.h> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header #endif +#if _LIBCPP_STD_VER >= 20 + _LIBCPP_BEGIN_NAMESPACE_STD template -using __test_for_primary_template _LIBCPP_NODEBUG = - __enable_if_t<_IsSame<_Tp, typename _Tp::__primary_template>::value>; - -template -using __is_primary_template _LIBCPP_NODEBUG = _IsValidExpansion<__test_for_primary_template, _Tp>; +concept __primary_template = requires { + typename _Tp::__primary_template; + requires _IsSame::value; +}; _LIBCPP_END_NAMESPACE_STD +#endif // _LIBCPP_STD_VER >= 20 + #endif // _LIBCPP___TYPE_TRAITS_IS_PRIMARY_TEMPLATE_H diff --git a/lib/libcxx/include/__type_traits/is_referenceable.h b/lib/libcxx/include/__concepts/referenceable.h similarity index 77% rename from lib/libcxx/include/__type_traits/is_referenceable.h rename to lib/libcxx/include/__concepts/referenceable.h index 3a9d2858ba4c9713412066378314a9a634c35da1..471d1157a9b8712baeffe54b81c6d0a1eb422ec2 100644 --- a/lib/libcxx/include/__type_traits/is_referenceable.h +++ b/lib/libcxx/include/__concepts/referenceable.h @@ -16,19 +16,15 @@ # pragma GCC system_header #endif -_LIBCPP_BEGIN_NAMESPACE_STD - -template -inline const bool __is_referenceable_v = false; - -template -inline const bool __is_referenceable_v<_Tp, __void_t<_Tp&> > = true; - #if _LIBCPP_STD_VER >= 20 + +_LIBCPP_BEGIN_NAMESPACE_STD + template -concept __referenceable = __is_referenceable_v<_Tp>; -#endif +concept __referenceable = requires { typename __void_t<_Tp&>; }; _LIBCPP_END_NAMESPACE_STD +#endif + #endif // _LIBCPP___TYPE_TRAITS_IS_REFERENCEABLE_H diff --git a/lib/libcxx/include/__concepts/regular.h b/lib/libcxx/include/__concepts/regular.h index 9f3d8bf30be3e0738442280218d73cc9cd3446b0..ab4f68e8f4603692ea0239c3382cd9ae34394418 100644 --- a/lib/libcxx/include/__concepts/regular.h +++ b/lib/libcxx/include/__concepts/regular.h @@ -17,17 +17,17 @@ # pragma GCC system_header #endif -_LIBCPP_BEGIN_NAMESPACE_STD - #if _LIBCPP_STD_VER >= 20 +_LIBCPP_BEGIN_NAMESPACE_STD + // [concept.object] template concept regular = semiregular<_Tp> && equality_comparable<_Tp>; -#endif // _LIBCPP_STD_VER >= 20 - _LIBCPP_END_NAMESPACE_STD +#endif // _LIBCPP_STD_VER >= 20 + #endif // _LIBCPP___CONCEPTS_REGULAR_H diff --git a/lib/libcxx/include/__concepts/relation.h b/lib/libcxx/include/__concepts/relation.h index 7545a7db93da766029314a30df19f0df3ae1ff2d..ccd3643e81fc4f7d879706d76e125bc3f3157229 100644 --- a/lib/libcxx/include/__concepts/relation.h +++ b/lib/libcxx/include/__concepts/relation.h @@ -16,10 +16,10 @@ # pragma GCC system_header #endif -_LIBCPP_BEGIN_NAMESPACE_STD - #if _LIBCPP_STD_VER >= 20 +_LIBCPP_BEGIN_NAMESPACE_STD + // [concept.relation] template @@ -36,8 +36,8 @@ concept equivalence_relation = relation<_Rp, _Tp, _Up>; template concept strict_weak_order = relation<_Rp, _Tp, _Up>; -#endif // _LIBCPP_STD_VER >= 20 - _LIBCPP_END_NAMESPACE_STD +#endif // _LIBCPP_STD_VER >= 20 + #endif // _LIBCPP___CONCEPTS_RELATION_H diff --git a/lib/libcxx/include/__concepts/same_as.h b/lib/libcxx/include/__concepts/same_as.h index 4241131c70c1f4edd1f08dc73c9de032fd6e0776..1385e4d84fdf4af0896db08f5e05ebb66df0e7d5 100644 --- a/lib/libcxx/include/__concepts/same_as.h +++ b/lib/libcxx/include/__concepts/same_as.h @@ -16,10 +16,10 @@ # pragma GCC system_header #endif -_LIBCPP_BEGIN_NAMESPACE_STD - #if _LIBCPP_STD_VER >= 20 +_LIBCPP_BEGIN_NAMESPACE_STD + // [concept.same] template @@ -28,8 +28,8 @@ concept __same_as_impl = _IsSame<_Tp, _Up>::value; template concept same_as = __same_as_impl<_Tp, _Up> && __same_as_impl<_Up, _Tp>; -#endif // _LIBCPP_STD_VER >= 20 - _LIBCPP_END_NAMESPACE_STD +#endif // _LIBCPP_STD_VER >= 20 + #endif // _LIBCPP___CONCEPTS_SAME_AS_H diff --git a/lib/libcxx/include/__concepts/semiregular.h b/lib/libcxx/include/__concepts/semiregular.h index 7a159d17dfc109c257801e29a5ff5698642d4658..d047e8dec122f333959521121a5803c197505a72 100644 --- a/lib/libcxx/include/__concepts/semiregular.h +++ b/lib/libcxx/include/__concepts/semiregular.h @@ -17,17 +17,17 @@ # pragma GCC system_header #endif -_LIBCPP_BEGIN_NAMESPACE_STD - #if _LIBCPP_STD_VER >= 20 +_LIBCPP_BEGIN_NAMESPACE_STD + // [concept.object] template concept semiregular = copyable<_Tp> && default_initializable<_Tp>; -#endif // _LIBCPP_STD_VER >= 20 - _LIBCPP_END_NAMESPACE_STD +#endif // _LIBCPP_STD_VER >= 20 + #endif // _LIBCPP___CONCEPTS_SEMIREGULAR_H diff --git a/lib/libcxx/include/__concepts/swappable.h b/lib/libcxx/include/__concepts/swappable.h index c691d3ab1e12b5feebceda2d7204fffffeb77d96..5077772781619a65145a72ab9b802bc61a0da94b 100644 --- a/lib/libcxx/include/__concepts/swappable.h +++ b/lib/libcxx/include/__concepts/swappable.h @@ -30,10 +30,10 @@ _LIBCPP_PUSH_MACROS #include <__undef_macros> -_LIBCPP_BEGIN_NAMESPACE_STD - #if _LIBCPP_STD_VER >= 20 +_LIBCPP_BEGIN_NAMESPACE_STD + // [concept.swappable] namespace ranges { @@ -113,10 +113,10 @@ concept swappable_with = common_reference_with<_Tp, _Up> && requires(_Tp&& __t, ranges::swap(std::forward<_Up>(__u), std::forward<_Tp>(__t)); }; -#endif // _LIBCPP_STD_VER >= 20 - _LIBCPP_END_NAMESPACE_STD +#endif // _LIBCPP_STD_VER >= 20 + _LIBCPP_POP_MACROS #endif // _LIBCPP___CONCEPTS_SWAPPABLE_H diff --git a/lib/libcxx/include/__concepts/totally_ordered.h b/lib/libcxx/include/__concepts/totally_ordered.h index 186c3b430dd54d220a860b5a04a3c3290852418c..fc4d564b3b4db425279e094410715952f9f56bae 100644 --- a/lib/libcxx/include/__concepts/totally_ordered.h +++ b/lib/libcxx/include/__concepts/totally_ordered.h @@ -19,10 +19,10 @@ # pragma GCC system_header #endif -_LIBCPP_BEGIN_NAMESPACE_STD - #if _LIBCPP_STD_VER >= 20 +_LIBCPP_BEGIN_NAMESPACE_STD + // [concept.totallyordered] template @@ -52,8 +52,8 @@ concept totally_ordered_with = __partially_ordered_with<_Tp, _Up>; // clang-format on -#endif // _LIBCPP_STD_VER >= 20 - _LIBCPP_END_NAMESPACE_STD +#endif // _LIBCPP_STD_VER >= 20 + #endif // _LIBCPP___CONCEPTS_TOTALLY_ORDERED_H diff --git a/lib/libcxx/include/__condition_variable/condition_variable.h b/lib/libcxx/include/__condition_variable/condition_variable.h index b7151930e922662c56eb9ede816944f543adf0ff..e15113ced57582c6c496e1748316c7a6dffdab3b 100644 --- a/lib/libcxx/include/__condition_variable/condition_variable.h +++ b/lib/libcxx/include/__condition_variable/condition_variable.h @@ -31,9 +31,10 @@ _LIBCPP_PUSH_MACROS #include <__undef_macros> +#if _LIBCPP_HAS_THREADS + _LIBCPP_BEGIN_NAMESPACE_STD - -#if _LIBCPP_HAS_THREADS +_LIBCPP_BEGIN_EXPLICIT_ABI_ANNOTATIONS // enum class cv_status _LIBCPP_DECLARE_STRONG_ENUM(cv_status){no_timeout, timeout}; @@ -223,10 +224,11 @@ inline void condition_variable::__do_timed_wait(unique_lock& __lk, wait_for(__lk, __tp - _Clock::now()); } -#endif // _LIBCPP_HAS_THREADS - +_LIBCPP_END_EXPLICIT_ABI_ANNOTATIONS _LIBCPP_END_NAMESPACE_STD +#endif // _LIBCPP_HAS_THREADS + _LIBCPP_POP_MACROS #endif // _LIBCPP___CONDITION_VARIABLE_CONDITION_VARIABLE_H diff --git a/lib/libcxx/include/__config b/lib/libcxx/include/__config index cc7a377334a83cbb34b8a997151b7e76b3810a9c..af241b40958682d8aa5dfbd50a89dc418014dbbf 100644 --- a/lib/libcxx/include/__config +++ b/lib/libcxx/include/__config @@ -25,61 +25,30 @@ #ifdef __cplusplus +# include <__configuration/abi.h> +# include <__configuration/attributes.h> +# include <__configuration/availability.h> +# include <__configuration/compiler.h> +# include <__configuration/diagnostic_suppression.h> +# include <__configuration/experimental.h> +# include <__configuration/hardening.h> +# include <__configuration/language.h> +# include <__configuration/namespace.h> +# include <__configuration/platform.h> +# include <__configuration/pstl.h> +# include <__configuration/utility.h> + // The attributes supported by clang are documented at https://clang.llvm.org/docs/AttributeReference.html // _LIBCPP_VERSION represents the version of libc++, which matches the version of LLVM. // Given a LLVM release LLVM XX.YY.ZZ (e.g. LLVM 17.0.1 == 17.00.01), _LIBCPP_VERSION is // defined to XXYYZZ. -# define _LIBCPP_VERSION 220108 - -# define _LIBCPP_CONCAT_IMPL(_X, _Y) _X##_Y -# define _LIBCPP_CONCAT(_X, _Y) _LIBCPP_CONCAT_IMPL(_X, _Y) -# define _LIBCPP_CONCAT3(X, Y, Z) _LIBCPP_CONCAT(X, _LIBCPP_CONCAT(Y, Z)) - -# if __STDC_HOSTED__ == 0 -# define _LIBCPP_FREESTANDING -# endif - -# define _LIBCPP_TOSTRING2(x) #x -# define _LIBCPP_TOSTRING(x) _LIBCPP_TOSTRING2(x) - -# ifndef __has_constexpr_builtin -# define __has_constexpr_builtin(x) 0 -# endif - -// This checks wheter a Clang module is built -# ifndef __building_module -# define __building_module(...) 0 -# endif - -// '__is_identifier' returns '0' if '__x' is a reserved identifier provided by -// the compiler and '1' otherwise. -# ifndef __is_identifier -# define __is_identifier(__x) 1 -# endif - -# ifndef __has_declspec_attribute -# define __has_declspec_attribute(__x) 0 -# endif - -# define __has_keyword(__x) !(__is_identifier(__x)) - -# ifndef __has_warning -# define __has_warning(...) 0 -# endif - -# if !defined(_LIBCPP_COMPILER_CLANG_BASED) && __cplusplus < 201103L -# error "libc++ only supports C++03 with Clang-based compilers. Please enable C++11" -# endif +# define _LIBCPP_VERSION 230100 # if defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_NO_VCRUNTIME) # define _LIBCPP_ABI_VCRUNTIME # endif -# if defined(__MVS__) -# include // for __NATIVE_ASCII_F -# endif - # if defined(_WIN32) # define _LIBCPP_WIN32API # define _LIBCPP_SHORT_WCHAR 1 @@ -90,15 +59,9 @@ # if defined(_MSC_VER) && !defined(__MINGW32__) # define _LIBCPP_MSVCRT // Using Microsoft's C Runtime library # endif -# if (defined(_M_AMD64) || defined(__x86_64__)) || (defined(_M_ARM) || defined(__arm__)) -# define _LIBCPP_HAS_BITSCAN64 1 -# else -# define _LIBCPP_HAS_BITSCAN64 0 -# endif # define _LIBCPP_HAS_OPEN_WITH_WCHAR 1 # else # define _LIBCPP_HAS_OPEN_WITH_WCHAR 0 -# define _LIBCPP_HAS_BITSCAN64 0 # endif // defined(_WIN32) # if defined(_AIX) && !defined(__64BIT__) @@ -184,259 +147,6 @@ typedef __char32_t char32_t; # define _LIBCPP_HAS_BLOCKS_RUNTIME 0 # endif -# define _LIBCPP_ALWAYS_INLINE __attribute__((__always_inline__)) - -# if defined(_LIBCPP_OBJECT_FORMAT_COFF) - -# ifdef _DLL -# define _LIBCPP_CRT_FUNC __declspec(dllimport) -# else -# define _LIBCPP_CRT_FUNC -# endif - -# if defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) || (defined(__MINGW32__) && !defined(_LIBCPP_BUILDING_LIBRARY)) -# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS -# define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS -# define _LIBCPP_OVERRIDABLE_FUNC_VIS -# define _LIBCPP_EXPORTED_FROM_ABI -# elif defined(_LIBCPP_BUILDING_LIBRARY) -# if defined(__MINGW32__) -# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __declspec(dllexport) -# define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS -# else -# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS -# define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS __declspec(dllexport) -# endif -# define _LIBCPP_OVERRIDABLE_FUNC_VIS __declspec(dllexport) -# define _LIBCPP_EXPORTED_FROM_ABI __declspec(dllexport) -# else -# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __declspec(dllimport) -# define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS -# define _LIBCPP_OVERRIDABLE_FUNC_VIS -# define _LIBCPP_EXPORTED_FROM_ABI __declspec(dllimport) -# endif - -# define _LIBCPP_HIDDEN -# define _LIBCPP_TEMPLATE_DATA_VIS -# define _LIBCPP_NAMESPACE_VISIBILITY - -# else - -# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) -# define _LIBCPP_VISIBILITY(vis) __attribute__((__visibility__(vis))) -# else -# define _LIBCPP_VISIBILITY(vis) -# endif - -# define _LIBCPP_HIDDEN _LIBCPP_VISIBILITY("hidden") -# define _LIBCPP_TEMPLATE_DATA_VIS _LIBCPP_VISIBILITY("default") -# define _LIBCPP_EXPORTED_FROM_ABI _LIBCPP_VISIBILITY("default") -# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS _LIBCPP_VISIBILITY("default") -# define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS - -// TODO: Make this a proper customization point or remove the option to override it. -# ifndef _LIBCPP_OVERRIDABLE_FUNC_VIS -# define _LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_VISIBILITY("default") -# endif - -# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) && __has_attribute(__type_visibility__) -# define _LIBCPP_NAMESPACE_VISIBILITY __attribute__((__type_visibility__("default"))) -# elif !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) -# define _LIBCPP_NAMESPACE_VISIBILITY __attribute__((__visibility__("default"))) -# else -# define _LIBCPP_NAMESPACE_VISIBILITY -# endif - -# endif // defined(_LIBCPP_OBJECT_FORMAT_COFF) - -# if __has_attribute(exclude_from_explicit_instantiation) -# define _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION __attribute__((__exclude_from_explicit_instantiation__)) -# else -// Try to approximate the effect of exclude_from_explicit_instantiation -// (which is that entities are not assumed to be provided by explicit -// template instantiations in the dylib) by always inlining those entities. -# define _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION _LIBCPP_ALWAYS_INLINE -# endif - -# ifdef _LIBCPP_COMPILER_CLANG_BASED -# define _LIBCPP_DIAGNOSTIC_PUSH _Pragma("clang diagnostic push") -# define _LIBCPP_DIAGNOSTIC_POP _Pragma("clang diagnostic pop") -# define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED(str) _Pragma(_LIBCPP_TOSTRING(clang diagnostic ignored str)) -# define _LIBCPP_GCC_DIAGNOSTIC_IGNORED(str) -# elif defined(_LIBCPP_COMPILER_GCC) -# define _LIBCPP_DIAGNOSTIC_PUSH _Pragma("GCC diagnostic push") -# define _LIBCPP_DIAGNOSTIC_POP _Pragma("GCC diagnostic pop") -# define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED(str) -# define _LIBCPP_GCC_DIAGNOSTIC_IGNORED(str) _Pragma(_LIBCPP_TOSTRING(GCC diagnostic ignored str)) -# else -# define _LIBCPP_DIAGNOSTIC_PUSH -# define _LIBCPP_DIAGNOSTIC_POP -# define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED(str) -# define _LIBCPP_GCC_DIAGNOSTIC_IGNORED(str) -# endif - -// Macros to enter and leave a state where deprecation warnings are suppressed. -# define _LIBCPP_SUPPRESS_DEPRECATED_PUSH \ - _LIBCPP_DIAGNOSTIC_PUSH _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wdeprecated") \ - _LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wdeprecated-declarations") -# define _LIBCPP_SUPPRESS_DEPRECATED_POP _LIBCPP_DIAGNOSTIC_POP - -# if _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_FAST -# define _LIBCPP_HARDENING_SIG f -# elif _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_EXTENSIVE -# define _LIBCPP_HARDENING_SIG s -# elif _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_DEBUG -# define _LIBCPP_HARDENING_SIG d -# else -# define _LIBCPP_HARDENING_SIG n // "none" -# endif - -# if _LIBCPP_ASSERTION_SEMANTIC == _LIBCPP_ASSERTION_SEMANTIC_OBSERVE -# define _LIBCPP_ASSERTION_SEMANTIC_SIG o -# elif _LIBCPP_ASSERTION_SEMANTIC == _LIBCPP_ASSERTION_SEMANTIC_QUICK_ENFORCE -# define _LIBCPP_ASSERTION_SEMANTIC_SIG q -# elif _LIBCPP_ASSERTION_SEMANTIC == _LIBCPP_ASSERTION_SEMANTIC_ENFORCE -# define _LIBCPP_ASSERTION_SEMANTIC_SIG e -# else -# define _LIBCPP_ASSERTION_SEMANTIC_SIG i // `ignore` -# endif - -# if !_LIBCPP_HAS_EXCEPTIONS -# define _LIBCPP_EXCEPTIONS_SIG n -# else -# define _LIBCPP_EXCEPTIONS_SIG e -# endif - -# define _LIBCPP_ODR_SIGNATURE \ - _LIBCPP_CONCAT( \ - _LIBCPP_CONCAT(_LIBCPP_CONCAT(_LIBCPP_HARDENING_SIG, _LIBCPP_ASSERTION_SEMANTIC_SIG), _LIBCPP_EXCEPTIONS_SIG), \ - _LIBCPP_VERSION) - -// This macro marks a symbol as being hidden from libc++'s ABI. This is achieved -// on two levels: -// 1. The symbol is given hidden visibility, which ensures that users won't start exporting -// symbols from their dynamic library by means of using the libc++ headers. This ensures -// that those symbols stay private to the dynamic library in which it is defined. -// -// 2. The symbol is given an ABI tag that encodes the ODR-relevant properties of the library. -// This ensures that no ODR violation can arise from mixing two TUs compiled with different -// versions or configurations of libc++ (such as exceptions vs no-exceptions). Indeed, if the -// program contains two definitions of a function, the ODR requires them to be token-by-token -// equivalent, and the linker is allowed to pick either definition and discard the other one. -// -// For example, if a program contains a copy of `vector::at()` compiled with exceptions enabled -// *and* a copy of `vector::at()` compiled with exceptions disabled (by means of having two TUs -// compiled with different settings), the two definitions are both visible by the linker and they -// have the same name, but they have a meaningfully different implementation (one throws an exception -// and the other aborts the program). This violates the ODR and makes the program ill-formed, and in -// practice what will happen is that the linker will pick one of the definitions at random and will -// discard the other one. This can quite clearly lead to incorrect program behavior. -// -// A similar reasoning holds for many other properties that are ODR-affecting. Essentially any -// property that causes the code of a function to differ from the code in another configuration -// can be considered ODR-affecting. In practice, we don't encode all such properties in the ABI -// tag, but we encode the ones that we think are most important: library version, exceptions, and -// hardening mode. -// -// Note that historically, solving this problem has been achieved in various ways, including -// force-inlining all functions or giving internal linkage to all functions. Both these previous -// solutions suffer from drawbacks that lead notably to code bloat. -// -// Note that we use _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION to ensure that we don't depend -// on _LIBCPP_HIDE_FROM_ABI methods of classes explicitly instantiated in the dynamic library. -// -// Also note that the _LIBCPP_HIDE_FROM_ABI_VIRTUAL macro should be used on virtual functions -// instead of _LIBCPP_HIDE_FROM_ABI. That macro does not use an ABI tag. Indeed, the mangled -// name of a virtual function is part of its ABI, since some architectures like arm64e can sign -// the virtual function pointer in the vtable based on the mangled name of the function. Since -// we use an ABI tag that changes with each released version, the mangled name of the virtual -// function would change, which is incorrect. Note that it doesn't make much sense to change -// the implementation of a virtual function in an ABI-incompatible way in the first place, -// since that would be an ABI break anyway. Hence, the lack of ABI tag should not be noticeable. -// -// The macro can be applied to record and enum types. When the tagged type is nested in -// a record this "parent" record needs to have the macro too. Another use case for applying -// this macro to records and unions is to apply an ABI tag to inline constexpr variables. -// This can be useful for inline variables that are implementation details which are expected -// to change in the future. -// -// TODO: We provide a escape hatch with _LIBCPP_NO_ABI_TAG for folks who want to avoid increasing -// the length of symbols with an ABI tag. In practice, we should remove the escape hatch and -// use compression mangling instead, see https://github.com/itanium-cxx-abi/cxx-abi/issues/70. -# ifndef _LIBCPP_NO_ABI_TAG -# define _LIBCPP_HIDE_FROM_ABI \ - _LIBCPP_HIDDEN _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION \ - __attribute__((__abi_tag__(_LIBCPP_TOSTRING(_LIBCPP_ODR_SIGNATURE)))) -# else -# define _LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDDEN _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION -# endif -# define _LIBCPP_HIDE_FROM_ABI_VIRTUAL _LIBCPP_HIDDEN _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION - -// Clang modules take a significant compile time hit when pushing and popping diagnostics. -// Since all the headers are marked as system headers unless _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER is defined, we can -// simply disable this pushing and popping when _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER isn't defined. -# ifdef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER -# define _LIBCPP_PUSH_EXTENSION_DIAGNOSTICS \ - _LIBCPP_DIAGNOSTIC_PUSH \ - _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wc++11-extensions") \ - _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wc++14-extensions") \ - _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wc++17-extensions") \ - _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wc++20-extensions") \ - _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wc++23-extensions") \ - _LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wc++14-extensions") \ - _LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wc++17-extensions") \ - _LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wc++20-extensions") \ - _LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wc++23-extensions") -# define _LIBCPP_POP_EXTENSION_DIAGNOSTICS _LIBCPP_DIAGNOSTIC_POP -# else -# define _LIBCPP_PUSH_EXTENSION_DIAGNOSTICS -# define _LIBCPP_POP_EXTENSION_DIAGNOSTICS -# endif - -// clang-format off - -// The unversioned namespace is used when we want to be ABI compatible with other standard libraries in some way. There -// are two main categories where that's the case: -// - Historically, we have made exception types ABI compatible with libstdc++ to allow throwing them between libstdc++ -// and libc++. This is not used anymore for new exception types, since there is no use-case for it anymore. -// - Types and functions which are used by the compiler are in the unversioned namespace, since the compiler has to know -// their mangling without the appropriate declaration in some cases. -// If it's not clear whether using the unversioned namespace is the correct thing to do, it's not. The versioned -// namespace (_LIBCPP_BEGIN_NAMESPACE_STD) should almost always be used. -# define _LIBCPP_BEGIN_UNVERSIONED_NAMESPACE_STD \ - _LIBCPP_PUSH_EXTENSION_DIAGNOSTICS namespace _LIBCPP_NAMESPACE_VISIBILITY std { - -# define _LIBCPP_END_UNVERSIONED_NAMESPACE_STD } _LIBCPP_POP_EXTENSION_DIAGNOSTICS - -# define _LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_BEGIN_UNVERSIONED_NAMESPACE_STD inline namespace _LIBCPP_ABI_NAMESPACE { -# define _LIBCPP_END_NAMESPACE_STD } _LIBCPP_END_UNVERSIONED_NAMESPACE_STD - -// TODO: This should really be in the versioned namespace -#define _LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL _LIBCPP_BEGIN_UNVERSIONED_NAMESPACE_STD namespace experimental { -#define _LIBCPP_END_NAMESPACE_EXPERIMENTAL } _LIBCPP_END_UNVERSIONED_NAMESPACE_STD - -#define _LIBCPP_BEGIN_NAMESPACE_LFTS _LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL inline namespace fundamentals_v1 { -#define _LIBCPP_END_NAMESPACE_LFTS } _LIBCPP_END_NAMESPACE_EXPERIMENTAL - -#define _LIBCPP_BEGIN_NAMESPACE_LFTS_V2 _LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL inline namespace fundamentals_v2 { -#define _LIBCPP_END_NAMESPACE_LFTS_V2 } _LIBCPP_END_NAMESPACE_EXPERIMENTAL - -#ifdef _LIBCPP_ABI_NO_FILESYSTEM_INLINE_NAMESPACE -# define _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM _LIBCPP_BEGIN_NAMESPACE_STD namespace filesystem { -# define _LIBCPP_END_NAMESPACE_FILESYSTEM } _LIBCPP_END_NAMESPACE_STD -#else -# define _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM _LIBCPP_BEGIN_NAMESPACE_STD \ - inline namespace __fs { namespace filesystem { - -# define _LIBCPP_END_NAMESPACE_FILESYSTEM }} _LIBCPP_END_NAMESPACE_STD -#endif - -// clang-format on - -# if __has_attribute(__enable_if__) -# define _LIBCPP_PREFERRED_OVERLOAD __attribute__((__enable_if__(true, ""))) -# endif - # if !defined(__SIZEOF_INT128__) || defined(_MSC_VER) # define _LIBCPP_HAS_INT128 0 # else @@ -488,36 +198,16 @@ typedef __char32_t char32_t; # endif # endif +# if !_LIBCPP_HAS_LIBRARY_ALIGNED_ALLOCATION || (!defined(__cpp_aligned_new) || __cpp_aligned_new < 201606) +# define _LIBCPP_HAS_ALIGNED_ALLOCATION 0 +# else +# define _LIBCPP_HAS_ALIGNED_ALLOCATION 1 +# endif + # if defined(__APPLE__) || defined(__FreeBSD__) # define _LIBCPP_WCTYPE_IS_MASK # endif -# if _LIBCPP_STD_VER <= 17 || !defined(__cpp_char8_t) -# define _LIBCPP_HAS_CHAR8_T 0 -# else -# define _LIBCPP_HAS_CHAR8_T 1 -# endif - -// Deprecation macros. -// -// Deprecations warnings are always enabled, except when users explicitly opt-out -// by defining _LIBCPP_DISABLE_DEPRECATION_WARNINGS. -# if !defined(_LIBCPP_DISABLE_DEPRECATION_WARNINGS) -# if __has_attribute(__deprecated__) -# define _LIBCPP_DEPRECATED __attribute__((__deprecated__)) -# define _LIBCPP_DEPRECATED_(m) __attribute__((__deprecated__(m))) -# elif _LIBCPP_STD_VER >= 14 -# define _LIBCPP_DEPRECATED [[deprecated]] -# define _LIBCPP_DEPRECATED_(m) [[deprecated(m)]] -# else -# define _LIBCPP_DEPRECATED -# define _LIBCPP_DEPRECATED_(m) -# endif -# else -# define _LIBCPP_DEPRECATED -# define _LIBCPP_DEPRECATED_(m) -# endif - // FIXME: using `#warning` causes diagnostics from system headers which include deprecated headers. This can only be // enabled again once https://github.com/llvm/llvm-project/pull/168041 (or a similar feature) has landed, since that // allows suppression in system headers. @@ -527,102 +217,13 @@ typedef __char32_t char32_t; # define _LIBCPP_DIAGNOSE_DEPRECATED_HEADERS 0 # endif -# if !defined(_LIBCPP_CXX03_LANG) -# define _LIBCPP_DEPRECATED_IN_CXX11 _LIBCPP_DEPRECATED -# else -# define _LIBCPP_DEPRECATED_IN_CXX11 -# endif - -# if _LIBCPP_STD_VER >= 14 -# define _LIBCPP_DEPRECATED_IN_CXX14 _LIBCPP_DEPRECATED -# else -# define _LIBCPP_DEPRECATED_IN_CXX14 -# endif - -# if _LIBCPP_STD_VER >= 17 -# define _LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_DEPRECATED -# else -# define _LIBCPP_DEPRECATED_IN_CXX17 -# endif - -# if _LIBCPP_STD_VER >= 20 -# define _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_DEPRECATED -# else -# define _LIBCPP_DEPRECATED_IN_CXX20 -# endif - -# if _LIBCPP_STD_VER >= 23 -# define _LIBCPP_DEPRECATED_IN_CXX23 _LIBCPP_DEPRECATED -# else -# define _LIBCPP_DEPRECATED_IN_CXX23 -# endif - -# if _LIBCPP_STD_VER >= 26 -# define _LIBCPP_DEPRECATED_IN_CXX26 _LIBCPP_DEPRECATED -# define _LIBCPP_DEPRECATED_IN_CXX26_(m) _LIBCPP_DEPRECATED_(m) -# else -# define _LIBCPP_DEPRECATED_IN_CXX26 -# define _LIBCPP_DEPRECATED_IN_CXX26_(m) -# endif - -# if _LIBCPP_HAS_CHAR8_T -# define _LIBCPP_DEPRECATED_WITH_CHAR8_T _LIBCPP_DEPRECATED -# else -# define _LIBCPP_DEPRECATED_WITH_CHAR8_T -# endif - -# if _LIBCPP_STD_VER <= 11 -# define _LIBCPP_EXPLICIT_SINCE_CXX14 -# else -# define _LIBCPP_EXPLICIT_SINCE_CXX14 explicit -# endif - -# if _LIBCPP_STD_VER >= 23 -# define _LIBCPP_EXPLICIT_SINCE_CXX23 explicit -# else -# define _LIBCPP_EXPLICIT_SINCE_CXX23 -# endif - -# if _LIBCPP_STD_VER >= 14 -# define _LIBCPP_CONSTEXPR_SINCE_CXX14 constexpr -# else -# define _LIBCPP_CONSTEXPR_SINCE_CXX14 -# endif - -# if _LIBCPP_STD_VER >= 17 -# define _LIBCPP_CONSTEXPR_SINCE_CXX17 constexpr -# else -# define _LIBCPP_CONSTEXPR_SINCE_CXX17 -# endif - -# if _LIBCPP_STD_VER >= 20 -# define _LIBCPP_CONSTEXPR_SINCE_CXX20 constexpr -# else -# define _LIBCPP_CONSTEXPR_SINCE_CXX20 -# endif - -# if _LIBCPP_STD_VER >= 23 -# define _LIBCPP_CONSTEXPR_SINCE_CXX23 constexpr -# else -# define _LIBCPP_CONSTEXPR_SINCE_CXX23 -# endif - -# if _LIBCPP_STD_VER >= 26 -# define _LIBCPP_CONSTEXPR_SINCE_CXX26 constexpr -# else -# define _LIBCPP_CONSTEXPR_SINCE_CXX26 -# endif - -# ifndef _LIBCPP_WEAK -# define _LIBCPP_WEAK __attribute__((__weak__)) -# endif - // Thread API // clang-format off # if _LIBCPP_HAS_THREADS && \ !_LIBCPP_HAS_THREAD_API_PTHREAD && \ !_LIBCPP_HAS_THREAD_API_WIN32 && \ - !_LIBCPP_HAS_THREAD_API_EXTERNAL + !_LIBCPP_HAS_THREAD_API_EXTERNAL && \ + !_LIBCPP_HAS_THREAD_API_C11 # if defined(__FreeBSD__) || \ defined(__wasi__) || \ @@ -666,6 +267,10 @@ typedef __char32_t char32_t; # error _LIBCPP_HAS_THREAD_API_EXTERNAL may only be true when _LIBCPP_HAS_THREADS is true. # endif +# if !_LIBCPP_HAS_THREADS && _LIBCPP_HAS_THREAD_API_C11 +# error _LIBCPP_HAS_THREAD_API_C11 may only be true when _LIBCPP_HAS_THREADS is true. +# endif + # if !_LIBCPP_HAS_MONOTONIC_CLOCK && _LIBCPP_HAS_THREADS # error _LIBCPP_HAS_MONOTONIC_CLOCK may only be false when _LIBCPP_HAS_THREADS is false. # endif @@ -709,60 +314,10 @@ typedef __char32_t char32_t; # endif # if defined(__BIONIC__) || defined(__NuttX__) || defined(__Fuchsia__) || defined(__wasi__) || \ - _LIBCPP_HAS_MUSL_LIBC || defined(__OpenBSD__) || defined(__LLVM_LIBC__) + _LIBCPP_HAS_MUSL_LIBC || defined(__OpenBSD__) || _LIBCPP_LIBC_LLVM_LIBC # define _LIBCPP_PROVIDES_DEFAULT_RUNE_TABLE # endif -# if __has_feature(cxx_atomic) || __has_extension(c_atomic) || __has_keyword(_Atomic) -# define _LIBCPP_HAS_C_ATOMIC_IMP 1 -# define _LIBCPP_HAS_GCC_ATOMIC_IMP 0 -# define _LIBCPP_HAS_EXTERNAL_ATOMIC_IMP 0 -# elif defined(_LIBCPP_COMPILER_GCC) -# define _LIBCPP_HAS_C_ATOMIC_IMP 0 -# define _LIBCPP_HAS_GCC_ATOMIC_IMP 1 -# define _LIBCPP_HAS_EXTERNAL_ATOMIC_IMP 0 -# endif - -# if !_LIBCPP_HAS_C_ATOMIC_IMP && !_LIBCPP_HAS_GCC_ATOMIC_IMP && !_LIBCPP_HAS_EXTERNAL_ATOMIC_IMP -# define _LIBCPP_HAS_ATOMIC_HEADER 0 -# else -# define _LIBCPP_HAS_ATOMIC_HEADER 1 -# ifndef _LIBCPP_ATOMIC_FLAG_TYPE -# define _LIBCPP_ATOMIC_FLAG_TYPE bool -# endif -# endif - -# if __has_cpp_attribute(_Clang::__no_thread_safety_analysis__) -# define _LIBCPP_NO_THREAD_SAFETY_ANALYSIS [[_Clang::__no_thread_safety_analysis__]] -# else -# define _LIBCPP_NO_THREAD_SAFETY_ANALYSIS -# endif - -# if _LIBCPP_STD_VER >= 20 -# define _LIBCPP_CONSTINIT constinit -# elif __has_attribute(__require_constant_initialization__) -# define _LIBCPP_CONSTINIT __attribute__((__require_constant_initialization__)) -# else -# define _LIBCPP_CONSTINIT -# endif - -# if defined(__CUDACC__) || defined(__CUDA_ARCH__) || defined(__CUDA_LIBDEVICE__) -// The CUDA SDK contains an unfortunate definition for the __noinline__ macro, -// which breaks the regular __attribute__((__noinline__)) syntax. Therefore, -// when compiling for CUDA we use the non-underscored version of the noinline -// attribute. -// -// This is a temporary workaround and we still expect the CUDA SDK team to solve -// this issue properly in the SDK headers. -// -// See https://github.com/llvm/llvm-project/pull/73838 for more details. -# define _LIBCPP_NOINLINE __attribute__((noinline)) -# elif __has_attribute(__noinline__) -# define _LIBCPP_NOINLINE __attribute__((__noinline__)) -# else -# define _LIBCPP_NOINLINE -# endif - // We often repeat things just for handling wide characters in the library. // When wide characters are disabled, it can be useful to have a quick way of // disabling it without having to resort to #if-#endif, which has a larger @@ -788,27 +343,6 @@ typedef __char32_t char32_t; # endif // defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_BUILDING_LIBRARY) # endif // _LIBCPP_NO_AUTO_LINK -// Configures the fopen close-on-exec mode character, if any. This string will -// be appended to any mode string used by fstream for fopen/fdopen. -// -// Not all platforms support this, but it helps avoid fd-leaks on platforms that -// do. -# if defined(__BIONIC__) -# define _LIBCPP_FOPEN_CLOEXEC_MODE "e" -# else -# define _LIBCPP_FOPEN_CLOEXEC_MODE -# endif - -# if __has_cpp_attribute(msvc::no_unique_address) -// MSVC implements [[no_unique_address]] as a silent no-op currently. -// (If/when MSVC breaks its C++ ABI, it will be changed to work as intended.) -// However, MSVC implements [[msvc::no_unique_address]] which does what -// [[no_unique_address]] is supposed to do, in general. -# define _LIBCPP_NO_UNIQUE_ADDRESS [[msvc::no_unique_address]] -# else -# define _LIBCPP_NO_UNIQUE_ADDRESS [[__no_unique_address__]] -# endif - // c8rtomb() and mbrtoc8() were added in C++20 and C23. Support for these // functions is gradually being added to existing C libraries. The conditions // below check for known C library versions and conditions under which these @@ -844,210 +378,6 @@ typedef __char32_t char32_t; # define _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(_ClassName) static_assert(true, "") # endif -# if defined(__OBJC__) && defined(_LIBCPP_APPLE_CLANG_VER) -# define _LIBCPP_WORKAROUND_OBJCXX_COMPILER_INTRINSICS -# endif - -# define _PSTL_PRAGMA(x) _Pragma(#x) - -// Enable SIMD for compilers that support OpenMP 4.0 -# if (defined(_OPENMP) && _OPENMP >= 201307) - -# define _PSTL_UDR_PRESENT -# define _PSTL_PRAGMA_SIMD _PSTL_PRAGMA(omp simd) -# define _PSTL_PRAGMA_DECLARE_SIMD _PSTL_PRAGMA(omp declare simd) -# define _PSTL_PRAGMA_SIMD_REDUCTION(PRM) _PSTL_PRAGMA(omp simd reduction(PRM)) -# define _PSTL_PRAGMA_SIMD_SCAN(PRM) _PSTL_PRAGMA(omp simd reduction(inscan, PRM)) -# define _PSTL_PRAGMA_SIMD_INCLUSIVE_SCAN(PRM) _PSTL_PRAGMA(omp scan inclusive(PRM)) -# define _PSTL_PRAGMA_SIMD_EXCLUSIVE_SCAN(PRM) _PSTL_PRAGMA(omp scan exclusive(PRM)) - -// Declaration of reduction functor, where -// NAME - the name of the functor -// OP - type of the callable object with the reduction operation -// omp_in - refers to the local partial result -// omp_out - refers to the final value of the combiner operator -// omp_priv - refers to the private copy of the initial value -// omp_orig - refers to the original variable to be reduced -# define _PSTL_PRAGMA_DECLARE_REDUCTION(NAME, OP) \ - _PSTL_PRAGMA(omp declare reduction(NAME:OP : omp_out(omp_in)) initializer(omp_priv = omp_orig)) - -# elif defined(_LIBCPP_COMPILER_CLANG_BASED) - -# define _PSTL_PRAGMA_SIMD _Pragma("clang loop vectorize(enable) interleave(enable)") -# define _PSTL_PRAGMA_DECLARE_SIMD -# define _PSTL_PRAGMA_SIMD_REDUCTION(PRM) _Pragma("clang loop vectorize(enable) interleave(enable)") -# define _PSTL_PRAGMA_SIMD_SCAN(PRM) _Pragma("clang loop vectorize(enable) interleave(enable)") -# define _PSTL_PRAGMA_SIMD_INCLUSIVE_SCAN(PRM) -# define _PSTL_PRAGMA_SIMD_EXCLUSIVE_SCAN(PRM) -# define _PSTL_PRAGMA_DECLARE_REDUCTION(NAME, OP) - -# else // (defined(_OPENMP) && _OPENMP >= 201307) - -# define _PSTL_PRAGMA_SIMD -# define _PSTL_PRAGMA_DECLARE_SIMD -# define _PSTL_PRAGMA_SIMD_REDUCTION(PRM) -# define _PSTL_PRAGMA_SIMD_SCAN(PRM) -# define _PSTL_PRAGMA_SIMD_INCLUSIVE_SCAN(PRM) -# define _PSTL_PRAGMA_SIMD_EXCLUSIVE_SCAN(PRM) -# define _PSTL_PRAGMA_DECLARE_REDUCTION(NAME, OP) - -# endif // (defined(_OPENMP) && _OPENMP >= 201307) - -# define _PSTL_USE_NONTEMPORAL_STORES_IF_ALLOWED - -// Optional attributes - these are useful for a better QoI, but not required to be available - -# define _LIBCPP_NOALIAS __attribute__((__malloc__)) -# define _LIBCPP_NODEBUG [[__gnu__::__nodebug__]] -# define _LIBCPP_NO_SANITIZE(...) __attribute__((__no_sanitize__(__VA_ARGS__))) -# define _LIBCPP_INIT_PRIORITY_MAX __attribute__((__init_priority__(100))) -# define _LIBCPP_ATTRIBUTE_FORMAT(archetype, format_string_index, first_format_arg_index) \ - __attribute__((__format__(archetype, format_string_index, first_format_arg_index))) -# define _LIBCPP_PACKED __attribute__((__packed__)) - -# if __has_attribute(__no_sanitize__) && !defined(_LIBCPP_COMPILER_GCC) -# define _LIBCPP_NO_CFI __attribute__((__no_sanitize__("cfi"))) -# else -# define _LIBCPP_NO_CFI -# endif - -# if __has_attribute(__using_if_exists__) -# define _LIBCPP_USING_IF_EXISTS __attribute__((__using_if_exists__)) -# else -# define _LIBCPP_USING_IF_EXISTS -# endif - -# if __has_cpp_attribute(_Clang::__no_destroy__) -# define _LIBCPP_NO_DESTROY [[_Clang::__no_destroy__]] -# else -# define _LIBCPP_NO_DESTROY -# endif - -# if __has_attribute(__diagnose_if__) -# define _LIBCPP_DIAGNOSE_WARNING(...) __attribute__((__diagnose_if__(__VA_ARGS__, "warning"))) -# else -# define _LIBCPP_DIAGNOSE_WARNING(...) -# endif - -# if __has_attribute(__diagnose_if__) && !defined(_LIBCPP_APPLE_CLANG_VER) && \ - (!defined(_LIBCPP_CLANG_VER) || _LIBCPP_CLANG_VER >= 2001) -# define _LIBCPP_DIAGNOSE_IF(...) __attribute__((__diagnose_if__(__VA_ARGS__))) -# else -# define _LIBCPP_DIAGNOSE_IF(...) -# endif - -# define _LIBCPP_DIAGNOSE_NULLPTR_IF(condition, condition_description) \ - _LIBCPP_DIAGNOSE_IF( \ - condition, \ - "null passed to callee that requires a non-null argument" condition_description, \ - "warning", \ - "nonnull") - -# if __has_cpp_attribute(_Clang::__lifetimebound__) -# define _LIBCPP_LIFETIMEBOUND [[_Clang::__lifetimebound__]] -# else -# define _LIBCPP_LIFETIMEBOUND -# endif - -// This is to work around https://llvm.org/PR156809 -# ifndef _LIBCPP_CXX03_LANG -# define _LIBCPP_CTOR_LIFETIMEBOUND _LIBCPP_LIFETIMEBOUND -# else -# define _LIBCPP_CTOR_LIFETIMEBOUND -# endif - -# if __has_cpp_attribute(_Clang::__noescape__) -# define _LIBCPP_NOESCAPE [[_Clang::__noescape__]] -# else -# define _LIBCPP_NOESCAPE -# endif - -# if __has_cpp_attribute(_Clang::__no_specializations__) -# define _LIBCPP_NO_SPECIALIZATIONS \ - [[_Clang::__no_specializations__("Users are not allowed to specialize this standard library entity")]] -# else -# define _LIBCPP_NO_SPECIALIZATIONS -# endif - -# if __has_cpp_attribute(_Clang::__preferred_name__) -# define _LIBCPP_PREFERRED_NAME(x) [[_Clang::__preferred_name__(x)]] -# else -# define _LIBCPP_PREFERRED_NAME(x) -# endif - -# if __has_cpp_attribute(_Clang::__scoped_lockable__) -# define _LIBCPP_SCOPED_LOCKABLE [[_Clang::__scoped_lockable__]] -# else -# define _LIBCPP_SCOPED_LOCKABLE -# endif - -# if __has_cpp_attribute(_Clang::__capability__) -# define _LIBCPP_CAPABILITY(...) [[_Clang::__capability__(__VA_ARGS__)]] -# else -# define _LIBCPP_CAPABILITY(...) -# endif - -# if __has_attribute(__acquire_capability__) -# define _LIBCPP_ACQUIRE_CAPABILITY(...) __attribute__((__acquire_capability__(__VA_ARGS__))) -# else -# define _LIBCPP_ACQUIRE_CAPABILITY(...) -# endif - -# if __has_cpp_attribute(_Clang::__try_acquire_capability__) -# define _LIBCPP_TRY_ACQUIRE_CAPABILITY(...) [[_Clang::__try_acquire_capability__(__VA_ARGS__)]] -# else -# define _LIBCPP_TRY_ACQUIRE_CAPABILITY(...) -# endif - -# if __has_cpp_attribute(_Clang::__acquire_shared_capability__) -# define _LIBCPP_ACQUIRE_SHARED_CAPABILITY [[_Clang::__acquire_shared_capability__]] -# else -# define _LIBCPP_ACQUIRE_SHARED_CAPABILITY -# endif - -# if __has_cpp_attribute(_Clang::__try_acquire_shared_capability__) -# define _LIBCPP_TRY_ACQUIRE_SHARED_CAPABILITY(...) [[_Clang::__try_acquire_shared_capability__(__VA_ARGS__)]] -# else -# define _LIBCPP_TRY_ACQUIRE_SHARED_CAPABILITY(...) -# endif - -# if __has_cpp_attribute(_Clang::__release_capability__) -# define _LIBCPP_RELEASE_CAPABILITY [[_Clang::__release_capability__]] -# else -# define _LIBCPP_RELEASE_CAPABILITY -# endif - -# if __has_cpp_attribute(_Clang::__release_shared_capability__) -# define _LIBCPP_RELEASE_SHARED_CAPABILITY [[_Clang::__release_shared_capability__]] -# else -# define _LIBCPP_RELEASE_SHARED_CAPABILITY -# endif - -# if __has_attribute(__requires_capability__) -# define _LIBCPP_REQUIRES_CAPABILITY(...) __attribute__((__requires_capability__(__VA_ARGS__))) -# else -# define _LIBCPP_REQUIRES_CAPABILITY(...) -# endif - -# if defined(_LIBCPP_ABI_MICROSOFT) && __has_declspec_attribute(empty_bases) -# define _LIBCPP_DECLSPEC_EMPTY_BASES __declspec(empty_bases) -# else -# define _LIBCPP_DECLSPEC_EMPTY_BASES -# endif - -// Allow for build-time disabling of unsigned integer sanitization -# if __has_attribute(no_sanitize) && !defined(_LIBCPP_COMPILER_GCC) -# define _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK __attribute__((__no_sanitize__("unsigned-integer-overflow"))) -# else -# define _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK -# endif - -# if __has_feature(nullability) -# define _LIBCPP_DIAGNOSE_NULLPTR _Nonnull -# else -# define _LIBCPP_DIAGNOSE_NULLPTR -# endif - #endif // __cplusplus #endif // _LIBCPP___CONFIG diff --git a/lib/libcxx/include/__configuration/abi.h b/lib/libcxx/include/__configuration/abi.h index d9623df71ddda00aadaeddbe83466a406560ad1f..91a6ccd9e5d10045aedb64d90a6d9f97da41f3ff 100644 --- a/lib/libcxx/include/__configuration/abi.h +++ b/lib/libcxx/include/__configuration/abi.h @@ -52,12 +52,6 @@ #if _LIBCPP_ABI_VERSION >= 2 // TODO: Move the description of the remaining ABI flags to ABIGuarantees.rst or remove them. -// Override the default return value of exception::what() for bad_function_call::what() -// with a string that is specific to bad_function_call (see http://wg21.link/LWG2233). -// This is an ABI break on platforms that sign and authenticate vtable function pointers -// because it changes the mangling of the virtual function located in the vtable, which -// changes how it gets signed. -# define _LIBCPP_ABI_BAD_FUNCTION_CALL_GOOD_WHAT_MESSAGE // According to the Standard, `bitset::operator[] const` returns bool # define _LIBCPP_ABI_BITSET_VECTOR_BOOL_CONST_SUBSCRIPT_RETURN_BOOL @@ -77,11 +71,14 @@ # define _LIBCPP_ABI_NO_REVERSE_ITERATOR_SECOND_MEMBER # define _LIBCPP_ABI_OPTIMIZED_FUNCTION # define _LIBCPP_ABI_REGEX_CONSTANTS_NONZERO +# define _LIBCPP_ABI_VECTOR_LAYOUT_SIZE_BASED # define _LIBCPP_ABI_STRING_OPTIMIZED_EXTERNAL_INSTANTIATION # define _LIBCPP_ABI_USE_WRAP_ITER_IN_STD_ARRAY # define _LIBCPP_ABI_USE_WRAP_ITER_IN_STD_STRING_VIEW # define _LIBCPP_ABI_VARIANT_INDEX_TYPE_OPTIMIZATION # define _LIBCPP_ABI_TRIVIALLY_COPYABLE_BIT_ITERATOR +# define _LIBCPP_ABI_USE_SMALL_DEQUE_BLOCK_SIZE +# define _LIBCPP_ABI_VECTORIZED_MERSENNE_TWISTER_ENGINE #elif _LIBCPP_ABI_VERSION == 1 // Feature macros for disabling pre ABI v1 features. All of these options @@ -91,15 +88,6 @@ # endif #endif -// TODO(LLVM 22): Remove this check -#if defined(_LIBCPP_ABI_NO_ITERATOR_BASES) && !defined(_LIBCPP_ABI_NO_REVERSE_ITERATOR_SECOND_MEMBER) -# ifndef _LIBCPP_ONLY_NO_ITERATOR_BASES -# error "You probably want to define _LIBCPP_ABI_NO_REVERSE_ITERATOR_SECOND_MEMBER. This has been split out from" \ - " _LIBCPP_ABI_NO_ITERATOR_BASES to allow only removing the second iterator member, since they aren't really related." \ - "If you actually want this ABI configuration, please define _LIBCPP_ONLY_NO_ITERATOR_BASES instead." -# endif -#endif - // We had some bugs where we use [[no_unique_address]] together with construct_at, // which causes UB as the call on construct_at could write to overlapping subobjects // @@ -108,7 +96,7 @@ // // To fix the bug we had to change the ABI of some classes to remove [[no_unique_address]] under certain conditions. // The macro below is used for all classes whose ABI have changed as part of fixing these bugs. -#define _LIBCPP_ABI_LLVM18_NO_UNIQUE_ADDRESS __attribute__((__abi_tag__("llvm18_nua"))) +#define _LIBCPP_LLVM18_NO_UNIQUE_ADDRESS_ABI_TAG __attribute__((__abi_tag__("llvm18_nua"))) // [[msvc::no_unique_address]] seems to mostly affect empty classes, so the padding scheme for Itanium doesn't work. #if defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_ABI_NO_COMPRESSED_PAIR_PADDING) diff --git a/lib/libcxx/include/__configuration/attributes.h b/lib/libcxx/include/__configuration/attributes.h new file mode 100644 index 0000000000000000000000000000000000000000..bf23195efc41dae4ab065baf7d4262b739789f80 --- /dev/null +++ b/lib/libcxx/include/__configuration/attributes.h @@ -0,0 +1,476 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP___CONFIGURATION_ATTRIBUTES_H +#define _LIBCPP___CONFIGURATION_ATTRIBUTES_H + +/* zig patch: instead of including __config_site, zig adds -D flags when compiling */ +#include <__configuration/hardening.h> +#include <__configuration/language.h> +#include <__configuration/utility.h> + +#ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER +# pragma GCC system_header +#endif + +#ifndef __has_declspec_attribute +# define __has_declspec_attribute(__x) 0 +#endif + +// Attributes relevant for layout ABI +// ---------------------------------- + +#if __has_cpp_attribute(msvc::no_unique_address) +// MSVC implements [[no_unique_address]] as a silent no-op currently. +// (If/when MSVC breaks its C++ ABI, it will be changed to work as intended.) +// However, MSVC implements [[msvc::no_unique_address]] which does what +// [[no_unique_address]] is supposed to do, in general. +# define _LIBCPP_NO_UNIQUE_ADDRESS [[msvc::no_unique_address]] +#else +# define _LIBCPP_NO_UNIQUE_ADDRESS [[__no_unique_address__]] +#endif + +#define _LIBCPP_PACKED __attribute__((__packed__)) + +// Attributes affecting overload resolution +// ---------------------------------------- + +#if __has_attribute(__enable_if__) +# define _LIBCPP_PREFERRED_OVERLOAD __attribute__((__enable_if__(true, ""))) +#endif + +// Visibility attributes +// --------------------- + +#if defined(_LIBCPP_OBJECT_FORMAT_COFF) + +# ifdef _DLL +# define _LIBCPP_CRT_FUNC __declspec(dllimport) +# else +# define _LIBCPP_CRT_FUNC +# endif + +# if defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) || (defined(__MINGW32__) && !defined(_LIBCPP_BUILDING_LIBRARY)) +# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS +# define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS +# define _LIBCPP_OVERRIDABLE_FUNC_VIS +# define _LIBCPP_EXPORTED_FROM_ABI +# elif defined(_LIBCPP_BUILDING_LIBRARY) +# if defined(__MINGW32__) +# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __declspec(dllexport) +# define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS +# else +# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS +# define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS __declspec(dllexport) +# endif +# define _LIBCPP_OVERRIDABLE_FUNC_VIS __declspec(dllexport) +# define _LIBCPP_EXPORTED_FROM_ABI __declspec(dllexport) +# else +# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __declspec(dllimport) +# define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS +# define _LIBCPP_OVERRIDABLE_FUNC_VIS +# define _LIBCPP_EXPORTED_FROM_ABI __declspec(dllimport) +# endif + +# define _LIBCPP_HIDDEN +# define _LIBCPP_TEMPLATE_DATA_VIS +# define _LIBCPP_NAMESPACE_VISIBILITY + +#else + +# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) +# define _LIBCPP_VISIBILITY(vis) __attribute__((__visibility__(vis))) +# else +# define _LIBCPP_VISIBILITY(vis) +# endif + +# define _LIBCPP_HIDDEN _LIBCPP_VISIBILITY("hidden") +# define _LIBCPP_TEMPLATE_DATA_VIS _LIBCPP_VISIBILITY("default") +# define _LIBCPP_EXPORTED_FROM_ABI _LIBCPP_VISIBILITY("default") +# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS _LIBCPP_VISIBILITY("default") +# define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS + +// TODO: Make this a proper customization point or remove the option to override it. +# ifndef _LIBCPP_OVERRIDABLE_FUNC_VIS +# define _LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_VISIBILITY("default") +# endif + +# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) && __has_attribute(__type_visibility__) +# define _LIBCPP_NAMESPACE_VISIBILITY __attribute__((__type_visibility__("default"))) +# elif !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) +# define _LIBCPP_NAMESPACE_VISIBILITY __attribute__((__visibility__("default"))) +# else +# define _LIBCPP_NAMESPACE_VISIBILITY +# endif + +#endif // defined(_LIBCPP_OBJECT_FORMAT_COFF) + +// hide_from_abi +// ------------- + +#define _LIBCPP_ALWAYS_INLINE __attribute__((__always_inline__)) + +#if __has_attribute(exclude_from_explicit_instantiation) +# define _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION __attribute__((__exclude_from_explicit_instantiation__)) +#else +// Try to approximate the effect of exclude_from_explicit_instantiation +// (which is that entities are not assumed to be provided by explicit +// template instantiations in the dylib) by always inlining those entities. +# define _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION _LIBCPP_ALWAYS_INLINE +#endif + +#if _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_FAST +# define _LIBCPP_HARDENING_SIG f +#elif _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_EXTENSIVE +# define _LIBCPP_HARDENING_SIG s +#elif _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_DEBUG +# define _LIBCPP_HARDENING_SIG d +#else +# define _LIBCPP_HARDENING_SIG n // "none" +#endif + +#if _LIBCPP_ASSERTION_SEMANTIC == _LIBCPP_ASSERTION_SEMANTIC_OBSERVE +# define _LIBCPP_ASSERTION_SEMANTIC_SIG o +#elif _LIBCPP_ASSERTION_SEMANTIC == _LIBCPP_ASSERTION_SEMANTIC_QUICK_ENFORCE +# define _LIBCPP_ASSERTION_SEMANTIC_SIG q +#elif _LIBCPP_ASSERTION_SEMANTIC == _LIBCPP_ASSERTION_SEMANTIC_ENFORCE +# define _LIBCPP_ASSERTION_SEMANTIC_SIG e +#else +# define _LIBCPP_ASSERTION_SEMANTIC_SIG i // `ignore` +#endif + +#if !_LIBCPP_HAS_EXCEPTIONS +# define _LIBCPP_EXCEPTIONS_SIG n +#else +# define _LIBCPP_EXCEPTIONS_SIG e +#endif + +#define _LIBCPP_ODR_SIGNATURE \ + _LIBCPP_CONCAT( \ + _LIBCPP_CONCAT(_LIBCPP_CONCAT(_LIBCPP_HARDENING_SIG, _LIBCPP_ASSERTION_SEMANTIC_SIG), _LIBCPP_EXCEPTIONS_SIG), \ + _LIBCPP_VERSION) + +// This macro marks a symbol as being hidden from libc++'s ABI. This is achieved +// on two levels: +// 1. The symbol is given hidden visibility, which ensures that users won't start exporting +// symbols from their dynamic library by means of using the libc++ headers. This ensures +// that those symbols stay private to the dynamic library in which it is defined. +// +// 2. The symbol is given an ABI tag that encodes the ODR-relevant properties of the library. +// This ensures that no ODR violation can arise from mixing two TUs compiled with different +// versions or configurations of libc++ (such as exceptions vs no-exceptions). Indeed, if the +// program contains two definitions of a function, the ODR requires them to be token-by-token +// equivalent, and the linker is allowed to pick either definition and discard the other one. +// +// For example, if a program contains a copy of `vector::at()` compiled with exceptions enabled +// *and* a copy of `vector::at()` compiled with exceptions disabled (by means of having two TUs +// compiled with different settings), the two definitions are both visible by the linker and they +// have the same name, but they have a meaningfully different implementation (one throws an exception +// and the other aborts the program). This violates the ODR and makes the program ill-formed, and in +// practice what will happen is that the linker will pick one of the definitions at random and will +// discard the other one. This can quite clearly lead to incorrect program behavior. +// +// A similar reasoning holds for many other properties that are ODR-affecting. Essentially any +// property that causes the code of a function to differ from the code in another configuration +// can be considered ODR-affecting. In practice, we don't encode all such properties in the ABI +// tag, but we encode the ones that we think are most important: library version, exceptions, and +// hardening mode. +// +// Note that historically, solving this problem has been achieved in various ways, including +// force-inlining all functions or giving internal linkage to all functions. Both these previous +// solutions suffer from drawbacks that lead notably to code bloat. +// +// Note that we use _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION to ensure that we don't depend +// on _LIBCPP_HIDE_FROM_ABI methods of classes explicitly instantiated in the dynamic library. +// +// Also note that the _LIBCPP_HIDE_FROM_ABI_VIRTUAL macro should be used on virtual functions +// instead of _LIBCPP_HIDE_FROM_ABI. That macro does not use an ABI tag. Indeed, the mangled +// name of a virtual function is part of its ABI, since some architectures like arm64e can sign +// the virtual function pointer in the vtable based on the mangled name of the function. Since +// we use an ABI tag that changes with each released version, the mangled name of the virtual +// function would change, which is incorrect. Note that it doesn't make much sense to change +// the implementation of a virtual function in an ABI-incompatible way in the first place, +// since that would be an ABI break anyway. Hence, the lack of ABI tag should not be noticeable. +// +// The macro can be applied to record and enum types. When the tagged type is nested in +// a record this "parent" record needs to have the macro too. Another use case for applying +// this macro to records and unions is to apply an ABI tag to inline constexpr variables. +// This can be useful for inline variables that are implementation details which are expected +// to change in the future. +// +// TODO: We provide a escape hatch with _LIBCPP_NO_ABI_TAG for folks who want to avoid increasing +// the length of symbols with an ABI tag. In practice, we should remove the escape hatch and +// use compression mangling instead, see https://github.com/itanium-cxx-abi/cxx-abi/issues/70. +#ifndef _LIBCPP_NO_ABI_TAG +# define _LIBCPP_HIDE_FROM_ABI \ + _LIBCPP_HIDDEN _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION \ + __attribute__((__abi_tag__(_LIBCPP_TOSTRING(_LIBCPP_ODR_SIGNATURE)))) +#else +# define _LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDDEN _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION +#endif +#define _LIBCPP_HIDE_FROM_ABI_VIRTUAL _LIBCPP_HIDDEN _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION + +// This macro makes sure that private classes which aren't necessarily part of the ABI change their name every release. +// The intention is _not_ to put it on every private class, but only on classes where type name stability implies ABI +// stability. This is essentially the case for classes that are only accessed through the vtable after instantiation, +// for example the control blocks of `shared_ptr`. These classes can change in ABI breaking ways as long as their name +// (and hence their vtable symbol) changes too. Note that the vtable and RTTI are not marked with +// [[gnu::visibility("hidden")]], since the vtable and RTTI should still be deduplicated across dylibs with the same +// instatiations. +#define _LIBCPP_HIDE_STRUCT_FROM_ABI [[__gnu__::__abi_tag__(_LIBCPP_TOSTRING(_LIBCPP_ODR_SIGNATURE))]] + +// Optional attributes +// ------------------- + +// these are useful for a better QoI, but not required to be available + +#define _LIBCPP_NOALIAS __attribute__((__malloc__)) +#define _LIBCPP_NODEBUG [[__gnu__::__nodebug__]] +#define _LIBCPP_NO_SANITIZE(...) __attribute__((__no_sanitize__(__VA_ARGS__))) +#define _LIBCPP_INIT_PRIORITY_MAX __attribute__((__init_priority__(100))) +#define _LIBCPP_ATTRIBUTE_FORMAT(archetype, format_string_index, first_format_arg_index) \ + __attribute__((__format__(archetype, format_string_index, first_format_arg_index))) + +#if __has_attribute(__no_sanitize__) && !defined(_LIBCPP_COMPILER_GCC) +# define _LIBCPP_NO_CFI __attribute__((__no_sanitize__("cfi"))) +#else +# define _LIBCPP_NO_CFI +#endif + +#if __has_attribute(__using_if_exists__) +# define _LIBCPP_USING_IF_EXISTS __attribute__((__using_if_exists__)) +#else +# define _LIBCPP_USING_IF_EXISTS +#endif + +#if __has_cpp_attribute(_Clang::__no_destroy__) +# define _LIBCPP_NO_DESTROY [[_Clang::__no_destroy__]] +#else +# define _LIBCPP_NO_DESTROY +#endif + +#if __has_attribute(__diagnose_if__) +# define _LIBCPP_DIAGNOSE_WARNING(...) __attribute__((__diagnose_if__(__VA_ARGS__, "warning"))) +#else +# define _LIBCPP_DIAGNOSE_WARNING(...) +#endif + +#if __has_attribute(__diagnose_if__) && !defined(_LIBCPP_APPLE_CLANG_VER) && \ + (!defined(_LIBCPP_CLANG_VER) || _LIBCPP_CLANG_VER >= 2001) +# define _LIBCPP_DIAGNOSE_IF(...) __attribute__((__diagnose_if__(__VA_ARGS__))) +#else +# define _LIBCPP_DIAGNOSE_IF(...) +#endif + +#define _LIBCPP_DIAGNOSE_NULLPTR_IF(condition, condition_description) \ + _LIBCPP_DIAGNOSE_IF( \ + condition, \ + "null passed to callee that requires a non-null argument" condition_description, \ + "warning", \ + "nonnull") + +#if __has_cpp_attribute(_Clang::__lifetimebound__) +# define _LIBCPP_LIFETIMEBOUND [[_Clang::__lifetimebound__]] +#else +# define _LIBCPP_LIFETIMEBOUND +#endif + +// This is to work around https://llvm.org/PR156809 +#ifndef _LIBCPP_CXX03_LANG +# define _LIBCPP_CTOR_LIFETIMEBOUND _LIBCPP_LIFETIMEBOUND +#else +# define _LIBCPP_CTOR_LIFETIMEBOUND +#endif + +#if __has_cpp_attribute(_Clang::__noescape__) +# define _LIBCPP_NOESCAPE [[_Clang::__noescape__]] +#else +# define _LIBCPP_NOESCAPE +#endif + +#if __has_cpp_attribute(_Clang::__no_specializations__) +# define _LIBCPP_NO_SPECIALIZATIONS \ + [[_Clang::__no_specializations__("Users are not allowed to specialize this standard library entity")]] +#else +# define _LIBCPP_NO_SPECIALIZATIONS +#endif + +#if __has_cpp_attribute(_Clang::__preferred_name__) +# define _LIBCPP_PREFERRED_NAME(x) [[_Clang::__preferred_name__(x)]] +#else +# define _LIBCPP_PREFERRED_NAME(x) +#endif + +#if __has_cpp_attribute(_Clang::__scoped_lockable__) +# define _LIBCPP_SCOPED_LOCKABLE [[_Clang::__scoped_lockable__]] +#else +# define _LIBCPP_SCOPED_LOCKABLE +#endif + +#if __has_cpp_attribute(_Clang::__capability__) +# define _LIBCPP_CAPABILITY(...) [[_Clang::__capability__(__VA_ARGS__)]] +#else +# define _LIBCPP_CAPABILITY(...) +#endif + +#if __has_attribute(__acquire_capability__) +# define _LIBCPP_ACQUIRE_CAPABILITY(...) __attribute__((__acquire_capability__(__VA_ARGS__))) +#else +# define _LIBCPP_ACQUIRE_CAPABILITY(...) +#endif + +#if __has_cpp_attribute(_Clang::__try_acquire_capability__) +# define _LIBCPP_TRY_ACQUIRE_CAPABILITY(...) [[_Clang::__try_acquire_capability__(__VA_ARGS__)]] +#else +# define _LIBCPP_TRY_ACQUIRE_CAPABILITY(...) +#endif + +#if __has_cpp_attribute(_Clang::__acquire_shared_capability__) +# define _LIBCPP_ACQUIRE_SHARED_CAPABILITY [[_Clang::__acquire_shared_capability__]] +#else +# define _LIBCPP_ACQUIRE_SHARED_CAPABILITY +#endif + +#if __has_cpp_attribute(_Clang::__try_acquire_shared_capability__) +# define _LIBCPP_TRY_ACQUIRE_SHARED_CAPABILITY(...) [[_Clang::__try_acquire_shared_capability__(__VA_ARGS__)]] +#else +# define _LIBCPP_TRY_ACQUIRE_SHARED_CAPABILITY(...) +#endif + +#if __has_attribute(__release_capability__) +# define _LIBCPP_RELEASE_CAPABILITY(...) __attribute__((__release_capability__(__VA_ARGS__))) +#else +# define _LIBCPP_RELEASE_CAPABILITY(...) +#endif + +#if __has_cpp_attribute(_Clang::__release_shared_capability__) +# define _LIBCPP_RELEASE_SHARED_CAPABILITY [[_Clang::__release_shared_capability__]] +#else +# define _LIBCPP_RELEASE_SHARED_CAPABILITY +#endif + +#if __has_attribute(__requires_capability__) +# define _LIBCPP_REQUIRES_CAPABILITY(...) __attribute__((__requires_capability__(__VA_ARGS__))) +#else +# define _LIBCPP_REQUIRES_CAPABILITY(...) +#endif + +#if __has_cpp_attribute(_Clang::__no_thread_safety_analysis__) +# define _LIBCPP_NO_THREAD_SAFETY_ANALYSIS [[_Clang::__no_thread_safety_analysis__]] +#else +# define _LIBCPP_NO_THREAD_SAFETY_ANALYSIS +#endif + +#if defined(_LIBCPP_ABI_MICROSOFT) && __has_declspec_attribute(empty_bases) +# define _LIBCPP_DECLSPEC_EMPTY_BASES __declspec(empty_bases) +#else +# define _LIBCPP_DECLSPEC_EMPTY_BASES +#endif + +// Allow for build-time disabling of unsigned integer sanitization +#if __has_attribute(no_sanitize) && !defined(_LIBCPP_COMPILER_GCC) +# define _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK __attribute__((__no_sanitize__("unsigned-integer-overflow"))) +#else +# define _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK +#endif + +#if __has_feature(nullability) +# define _LIBCPP_DIAGNOSE_NULLPTR _Nonnull +#else +# define _LIBCPP_DIAGNOSE_NULLPTR +#endif + +#if defined(__CUDACC__) || defined(__CUDA_ARCH__) || defined(__CUDA_LIBDEVICE__) +// The CUDA SDK contains an unfortunate definition for the __noinline__ macro, +// which breaks the regular __attribute__((__noinline__)) syntax. Therefore, +// when compiling for CUDA we use the non-underscored version of the noinline +// attribute. +// +// This is a temporary workaround and we still expect the CUDA SDK team to solve +// this issue properly in the SDK headers. +// +// See https://github.com/llvm/llvm-project/pull/73838 for more details. +# define _LIBCPP_NOINLINE __attribute__((noinline)) +#elif __has_attribute(__noinline__) +# define _LIBCPP_NOINLINE __attribute__((__noinline__)) +#else +# define _LIBCPP_NOINLINE +#endif + +// Deprecation macros +// ------------------ + +// Deprecations warnings are always enabled, except when users explicitly opt-out +// by defining _LIBCPP_DISABLE_DEPRECATION_WARNINGS. +#if !defined(_LIBCPP_DISABLE_DEPRECATION_WARNINGS) +# if __has_attribute(__deprecated__) +# define _LIBCPP_DEPRECATED __attribute__((__deprecated__)) +# define _LIBCPP_DEPRECATED_(m) __attribute__((__deprecated__(m))) +# elif _LIBCPP_STD_VER >= 14 +# define _LIBCPP_DEPRECATED [[deprecated]] +# define _LIBCPP_DEPRECATED_(m) [[deprecated(m)]] +# else +# define _LIBCPP_DEPRECATED +# define _LIBCPP_DEPRECATED_(m) +# endif +#else +# define _LIBCPP_DEPRECATED +# define _LIBCPP_DEPRECATED_(m) +#endif + +#if !defined(_LIBCPP_CXX03_LANG) +# define _LIBCPP_DEPRECATED_IN_CXX11 _LIBCPP_DEPRECATED +#else +# define _LIBCPP_DEPRECATED_IN_CXX11 +#endif + +#if _LIBCPP_STD_VER >= 14 +# define _LIBCPP_DEPRECATED_IN_CXX14 _LIBCPP_DEPRECATED +#else +# define _LIBCPP_DEPRECATED_IN_CXX14 +#endif + +#if _LIBCPP_STD_VER >= 17 +# define _LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_DEPRECATED +#else +# define _LIBCPP_DEPRECATED_IN_CXX17 +#endif + +#if _LIBCPP_STD_VER >= 20 +# define _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_DEPRECATED +#else +# define _LIBCPP_DEPRECATED_IN_CXX20 +#endif + +#if _LIBCPP_STD_VER >= 23 +# define _LIBCPP_DEPRECATED_IN_CXX23 _LIBCPP_DEPRECATED +#else +# define _LIBCPP_DEPRECATED_IN_CXX23 +#endif + +#if _LIBCPP_STD_VER >= 26 +# define _LIBCPP_DEPRECATED_IN_CXX26 _LIBCPP_DEPRECATED +# define _LIBCPP_DEPRECATED_IN_CXX26_(m) _LIBCPP_DEPRECATED_(m) +#else +# define _LIBCPP_DEPRECATED_IN_CXX26 +# define _LIBCPP_DEPRECATED_IN_CXX26_(m) +#endif + +#if _LIBCPP_HAS_CHAR8_T +# define _LIBCPP_DEPRECATED_WITH_CHAR8_T _LIBCPP_DEPRECATED +#else +# define _LIBCPP_DEPRECATED_WITH_CHAR8_T +#endif + +#if __has_cpp_attribute(_Clang::__no_field_protection__) +# define _LIBCPP_DISABLE_POINTER_FIELD_PROTECTION [[_Clang::__no_field_protection__]] +#else +# define _LIBCPP_DISABLE_POINTER_FIELD_PROTECTION +#endif + +#endif // _LIBCPP___CONFIGURATION_ATTRIBUTES_H diff --git a/lib/libcxx/include/__configuration/availability.h b/lib/libcxx/include/__configuration/availability.h index 40e11b331498092e51506a436cc996fe251c7801..735af5d431cb1410ef74a52748dfc07774547dfe 100644 --- a/lib/libcxx/include/__configuration/availability.h +++ b/lib/libcxx/include/__configuration/availability.h @@ -38,6 +38,11 @@ // When availability annotations are disabled, we take for granted that features introduced // in all versions of the library are available. #if !_LIBCPP_HAS_VENDOR_AVAILABILITY_ANNOTATIONS +# define _LIBCPP_INTRODUCED_IN_LLVM_23 1 +# define _LIBCPP_INTRODUCED_IN_LLVM_23_ATTRIBUTE /* nothing */ + +# define _LIBCPP_INTRODUCED_IN_LLVM_23 1 +# define _LIBCPP_INTRODUCED_IN_LLVM_23_ATTRIBUTE /* nothing */ # define _LIBCPP_INTRODUCED_IN_LLVM_22 1 # define _LIBCPP_INTRODUCED_IN_LLVM_22_ATTRIBUTE /* nothing */ @@ -70,15 +75,34 @@ // clang-format off +// LLVM 23 +// TODO: Fill this in +# define _LIBCPP_INTRODUCED_IN_LLVM_23 0 +# define _LIBCPP_INTRODUCED_IN_LLVM_23_ATTRIBUTE __attribute__((unavailable)) + // LLVM 22 // TODO: Fill this in # define _LIBCPP_INTRODUCED_IN_LLVM_22 0 # define _LIBCPP_INTRODUCED_IN_LLVM_22_ATTRIBUTE __attribute__((unavailable)) // LLVM 21 -// TODO: Fill this in -# define _LIBCPP_INTRODUCED_IN_LLVM_21 0 -# define _LIBCPP_INTRODUCED_IN_LLVM_21_ATTRIBUTE __attribute__((unavailable)) +# if (defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 260400) || \ + (defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ < 260400) || \ + (defined(__ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__ < 260400) || \ + (defined(__ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ < 260400) || \ + (defined(__ENVIRONMENT_BRIDGE_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_BRIDGE_OS_VERSION_MIN_REQUIRED__ < 100400) || \ + (defined(__ENVIRONMENT_DRIVERKIT_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_DRIVERKIT_VERSION_MIN_REQUIRED__ < 250400) +# define _LIBCPP_INTRODUCED_IN_LLVM_21 0 +# else +# define _LIBCPP_INTRODUCED_IN_LLVM_21 1 +# endif +# define _LIBCPP_INTRODUCED_IN_LLVM_21_ATTRIBUTE \ + __attribute__((availability(macos, strict, introduced = 26.4))) \ + __attribute__((availability(ios, strict, introduced = 26.4))) \ + __attribute__((availability(tvos, strict, introduced = 26.4))) \ + __attribute__((availability(watchos, strict, introduced = 26.4))) \ + __attribute__((availability(bridgeos, strict, introduced = 10.4))) \ + __attribute__((availability(driverkit, strict, introduced = 25.4))) // LLVM 20 // @@ -87,7 +111,8 @@ (defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ < 260000) || \ (defined(__ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__ < 260000) || \ (defined(__ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ < 260000) || \ - (defined(__ENVIRONMENT_BRIDGE_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_BRIDGE_OS_VERSION_MIN_REQUIRED__ < 100000) + (defined(__ENVIRONMENT_BRIDGE_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_BRIDGE_OS_VERSION_MIN_REQUIRED__ < 100000) || \ + (defined(__ENVIRONMENT_DRIVERKIT_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_DRIVERKIT_VERSION_MIN_REQUIRED__ < 250000) # define _LIBCPP_INTRODUCED_IN_LLVM_20 0 # else # define _LIBCPP_INTRODUCED_IN_LLVM_20 1 @@ -97,14 +122,16 @@ __attribute__((availability(ios, strict, introduced = 26.0))) \ __attribute__((availability(tvos, strict, introduced = 26.0))) \ __attribute__((availability(watchos, strict, introduced = 26.0))) \ - __attribute__((availability(bridgeos, strict, introduced = 10.0))) + __attribute__((availability(bridgeos, strict, introduced = 10.0))) \ + __attribute__((availability(driverkit, strict, introduced = 25.0))) // LLVM 19 # if (defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 150400) || \ (defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ < 180400) || \ (defined(__ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__ < 180400) || \ (defined(__ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ < 110400) || \ - (defined(__ENVIRONMENT_BRIDGE_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_BRIDGE_OS_VERSION_MIN_REQUIRED__ < 90400) + (defined(__ENVIRONMENT_BRIDGE_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_BRIDGE_OS_VERSION_MIN_REQUIRED__ < 90400) || \ + (defined(__ENVIRONMENT_DRIVERKIT_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_DRIVERKIT_VERSION_MIN_REQUIRED__ < 240400) # define _LIBCPP_INTRODUCED_IN_LLVM_19 0 # else # define _LIBCPP_INTRODUCED_IN_LLVM_19 1 @@ -114,7 +141,8 @@ __attribute__((availability(ios, strict, introduced = 18.4))) \ __attribute__((availability(tvos, strict, introduced = 18.4))) \ __attribute__((availability(watchos, strict, introduced = 11.4))) \ - __attribute__((availability(bridgeos, strict, introduced = 9.4))) + __attribute__((availability(bridgeos, strict, introduced = 9.4))) \ + __attribute__((availability(driverkit, strict, introduced = 24.4))) // LLVM 18 # if (defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 150000) || \ @@ -220,51 +248,28 @@ #define _LIBCPP_AVAILABILITY_HAS_NEW_SYNC _LIBCPP_INTRODUCED_IN_LLVM_22 #define _LIBCPP_AVAILABILITY_NEW_SYNC _LIBCPP_INTRODUCED_IN_LLVM_22_ATTRIBUTE -// Enable additional explicit instantiations of iostreams components. This -// reduces the number of weak definitions generated in programs that use -// iostreams by providing a single strong definition in the shared library. -// -// TODO: Enable additional explicit instantiations on GCC once it supports exclude_from_explicit_instantiation, -// or once libc++ doesn't use the attribute anymore. -// TODO: Enable them on Windows once https://llvm.org/PR41018 has been fixed. -#if !defined(_LIBCPP_COMPILER_GCC) && !defined(_WIN32) -# define _LIBCPP_AVAILABILITY_HAS_ADDITIONAL_IOSTREAM_EXPLICIT_INSTANTIATIONS_1 _LIBCPP_INTRODUCED_IN_LLVM_12 -#else -# define _LIBCPP_AVAILABILITY_HAS_ADDITIONAL_IOSTREAM_EXPLICIT_INSTANTIATIONS_1 0 -#endif +// This controls whether `std::__hash_memory` is available in the dylib, which +// is used for some `std::hash` specializations. +#define _LIBCPP_AVAILABILITY_HAS_HASH_MEMORY _LIBCPP_INTRODUCED_IN_LLVM_21 +// No attribute, since we've had hash in the headers before -// This controls the availability of floating-point std::to_chars functions. +// This controls whether we provide a message for `bad_function_call::what()` that specific to `std::bad_function_call`. +// See https://wg21.link/LWG2233. This requires `std::bad_function_call::what()` to be available in the dylib. +#define _LIBCPP_AVAILABILITY_HAS_BAD_FUNCTION_CALL_GOOD_WHAT_MESSAGE _LIBCPP_INTRODUCED_IN_LLVM_21 +// No attribute, since we've had bad_function_call::what() in the headers before + +// This determines whether we assume that the internal std::__bad_variant_access_with_msg class +// (which carries a message describing the cause of the failure in bad_variant_access::what()) +// provides a key function in the dylib. This allows centralizing its vtable and typeinfo instead +// of having all TUs provide a weak definition that then gets deduplicated. When it is not available +// in the dylib, what() is defined inline instead, so the descriptive message is provided regardless. +#define _LIBCPP_AVAILABILITY_HAS_BAD_VARIANT_ACCESS_WITH_MSG_KEY_FUNCTION _LIBCPP_INTRODUCED_IN_LLVM_23 +// No attribute, since we've had bad_variant_access in the headers before + +// This controls the availability of floating-point std::from_chars functions. // These overloads were added later than the integer overloads. -#define _LIBCPP_AVAILABILITY_HAS_TO_CHARS_FLOATING_POINT _LIBCPP_INTRODUCED_IN_LLVM_14 -#define _LIBCPP_AVAILABILITY_TO_CHARS_FLOATING_POINT _LIBCPP_INTRODUCED_IN_LLVM_14_ATTRIBUTE - -// This controls whether the library claims to provide a default verbose -// termination function, and consequently whether the headers will try -// to use it when the mechanism isn't overriden at compile-time. -#define _LIBCPP_AVAILABILITY_HAS_VERBOSE_ABORT _LIBCPP_INTRODUCED_IN_LLVM_15 -#define _LIBCPP_AVAILABILITY_VERBOSE_ABORT _LIBCPP_INTRODUCED_IN_LLVM_15_ATTRIBUTE - -// This controls the availability of the C++17 std::pmr library, -// which is implemented in large part in the built library. -// -// TODO: Enable std::pmr markup once https://llvm.org/PR40340 has been fixed -// Until then, it is possible for folks to try to use `std::pmr` when back-deploying to targets that don't support -// it and it'll be a load-time error, but we don't have a good alternative because the library won't compile if we -// use availability annotations until that bug has been fixed. -#define _LIBCPP_AVAILABILITY_HAS_PMR _LIBCPP_INTRODUCED_IN_LLVM_16 -#define _LIBCPP_AVAILABILITY_PMR - -// These macros controls the availability of __cxa_init_primary_exception -// in the built library, which std::make_exception_ptr might use -// (see libcxx/include/__exception/exception_ptr.h). -#define _LIBCPP_AVAILABILITY_HAS_INIT_PRIMARY_EXCEPTION _LIBCPP_INTRODUCED_IN_LLVM_18 -#define _LIBCPP_AVAILABILITY_INIT_PRIMARY_EXCEPTION _LIBCPP_INTRODUCED_IN_LLVM_18_ATTRIBUTE - -// This controls the availability of C++23 , which -// has a dependency on the built library (it needs access to -// the underlying buffer types of std::cout, std::cerr, and std::clog. -#define _LIBCPP_AVAILABILITY_HAS_PRINT _LIBCPP_INTRODUCED_IN_LLVM_18 -#define _LIBCPP_AVAILABILITY_PRINT _LIBCPP_INTRODUCED_IN_LLVM_18_ATTRIBUTE +#define _LIBCPP_AVAILABILITY_HAS_FROM_CHARS_FLOATING_POINT _LIBCPP_INTRODUCED_IN_LLVM_20 +#define _LIBCPP_AVAILABILITY_FROM_CHARS_FLOATING_POINT _LIBCPP_INTRODUCED_IN_LLVM_20_ATTRIBUTE // This controls the availability of the C++20 time zone database. // The parser code is built in the library. @@ -280,30 +285,50 @@ #define _LIBCPP_AVAILABILITY_HAS_BAD_EXPECTED_ACCESS_KEY_FUNCTION _LIBCPP_INTRODUCED_IN_LLVM_19 #define _LIBCPP_AVAILABILITY_BAD_EXPECTED_ACCESS_KEY_FUNCTION _LIBCPP_INTRODUCED_IN_LLVM_19_ATTRIBUTE -// This controls the availability of floating-point std::from_chars functions. +// These macros controls the availability of __cxa_init_primary_exception +// in the built library, which std::make_exception_ptr might use +// (see libcxx/include/__exception/exception_ptr.h). +#define _LIBCPP_AVAILABILITY_HAS_INIT_PRIMARY_EXCEPTION _LIBCPP_INTRODUCED_IN_LLVM_18 +#define _LIBCPP_AVAILABILITY_INIT_PRIMARY_EXCEPTION _LIBCPP_INTRODUCED_IN_LLVM_18_ATTRIBUTE + +// This controls the availability of the C++17 std::pmr library, +// which is implemented in large part in the built library. +// +// TODO: Enable std::pmr markup once https://llvm.org/PR40340 has been fixed +// Until then, it is possible for folks to try to use `std::pmr` when back-deploying to targets that don't support +// it and it'll be a load-time error, but we don't have a good alternative because the library won't compile if we +// use availability annotations until that bug has been fixed. +#define _LIBCPP_AVAILABILITY_HAS_PMR _LIBCPP_INTRODUCED_IN_LLVM_16 +#define _LIBCPP_AVAILABILITY_PMR + +// This controls whether the library claims to provide a default verbose +// termination function, and consequently whether the headers will try +// to use it when the mechanism isn't overriden at compile-time. +#define _LIBCPP_AVAILABILITY_HAS_VERBOSE_ABORT _LIBCPP_INTRODUCED_IN_LLVM_15 +#define _LIBCPP_AVAILABILITY_VERBOSE_ABORT _LIBCPP_INTRODUCED_IN_LLVM_15_ATTRIBUTE + +// This controls the availability of floating-point std::to_chars functions. // These overloads were added later than the integer overloads. -#define _LIBCPP_AVAILABILITY_HAS_FROM_CHARS_FLOATING_POINT _LIBCPP_INTRODUCED_IN_LLVM_20 -#define _LIBCPP_AVAILABILITY_FROM_CHARS_FLOATING_POINT _LIBCPP_INTRODUCED_IN_LLVM_20_ATTRIBUTE +#define _LIBCPP_AVAILABILITY_HAS_TO_CHARS_FLOATING_POINT _LIBCPP_INTRODUCED_IN_LLVM_14 +#define _LIBCPP_AVAILABILITY_TO_CHARS_FLOATING_POINT _LIBCPP_INTRODUCED_IN_LLVM_14_ATTRIBUTE -// This controls whether `std::__hash_memory` is available in the dylib, which -// is used for some `std::hash` specializations. -#define _LIBCPP_AVAILABILITY_HAS_HASH_MEMORY _LIBCPP_INTRODUCED_IN_LLVM_21 -// No attribute, since we've had hash in the headers before - -// This controls whether we provide a message for `bad_function_call::what()` that specific to `std::bad_function_call`. -// See https://wg21.link/LWG2233. This requires `std::bad_function_call::what()` to be available in the dylib. -#define _LIBCPP_AVAILABILITY_HAS_BAD_FUNCTION_CALL_GOOD_WHAT_MESSAGE _LIBCPP_INTRODUCED_IN_LLVM_21 -// No attribute, since we've had bad_function_call::what() in the headers before - -// Define availability attributes that depend on both -// _LIBCPP_HAS_EXCEPTIONS and _LIBCPP_HAS_RTTI. -#if !_LIBCPP_HAS_EXCEPTIONS || !_LIBCPP_HAS_RTTI -# undef _LIBCPP_AVAILABILITY_HAS_INIT_PRIMARY_EXCEPTION -# undef _LIBCPP_AVAILABILITY_INIT_PRIMARY_EXCEPTION -# define _LIBCPP_AVAILABILITY_HAS_INIT_PRIMARY_EXCEPTION 0 -# define _LIBCPP_AVAILABILITY_INIT_PRIMARY_EXCEPTION +// Enable additional explicit instantiations of iostreams components. This +// reduces the number of weak definitions generated in programs that use +// iostreams by providing a single strong definition in the shared library. +// +// TODO: Enable additional explicit instantiations on GCC once it supports exclude_from_explicit_instantiation, +// or once libc++ doesn't use the attribute anymore. +// TODO: Enable them on Windows once https://llvm.org/PR41018 has been fixed. +#if !defined(_LIBCPP_COMPILER_GCC) && !defined(_WIN32) +# define _LIBCPP_AVAILABILITY_HAS_ADDITIONAL_IOSTREAM_EXPLICIT_INSTANTIATIONS_1 _LIBCPP_INTRODUCED_IN_LLVM_12 +#else +# define _LIBCPP_AVAILABILITY_HAS_ADDITIONAL_IOSTREAM_EXPLICIT_INSTANTIATIONS_1 0 #endif +// Controls whether the implementation for text_encoding::environment() is available +#define _LIBCPP_AVAILABILITY_HAS_TEXT_ENCODING_ENVIRONMENT _LIBCPP_INTRODUCED_IN_LLVM_23 +#define _LIBCPP_AVAILABILITY_TEXT_ENCODING_ENVIRONMENT _LIBCPP_INTRODUCED_IN_LLVM_23_ATTRIBUTE + // Only define a bunch of symbols in the dylib if we need to be compatible with LLVM 7 headers or older # if defined(_LIBCPP_BUILDING_LIBRARY) && _LIBCPP_AVAILABILITY_MINIMUM_HEADER_VERSION < 8 # define _LIBCPP_HIDE_FROM_ABI_SINCE_LLVM8 diff --git a/lib/libcxx/include/__configuration/compiler.h b/lib/libcxx/include/__configuration/compiler.h index 302b7ced675fb379b84c97055e8c3145448f154e..00d62b8271918188cd2b8a3d75273215f93f3dfe 100644 --- a/lib/libcxx/include/__configuration/compiler.h +++ b/lib/libcxx/include/__configuration/compiler.h @@ -33,12 +33,12 @@ // Warn if a compiler version is used that is not supported anymore // LLVM RELEASE Update the minimum compiler versions # if defined(_LIBCPP_CLANG_VER) -# if _LIBCPP_CLANG_VER < 2001 -# warning "Libc++ only supports Clang 20 and later" +# if _LIBCPP_CLANG_VER < 2101 +# warning "Libc++ only supports Clang 21 and later" # endif # elif defined(_LIBCPP_APPLE_CLANG_VER) -# if _LIBCPP_APPLE_CLANG_VER < 1700 -# warning "Libc++ only supports AppleClang 26 and later" +# if _LIBCPP_APPLE_CLANG_VER < 2100 +# warning "Libc++ only supports AppleClang 26.4 and later" # endif # elif defined(_LIBCPP_GCC_VER) # if _LIBCPP_GCC_VER < 1500 @@ -46,6 +46,31 @@ # endif # endif +# ifndef __has_constexpr_builtin +# define __has_constexpr_builtin(x) 0 +# endif + +// This checks wheter a Clang module is built +# ifndef __building_module +# define __building_module(...) 0 +# endif + +// '__is_identifier' returns '0' if '__x' is a reserved identifier provided by +// the compiler and '1' otherwise. +# ifndef __is_identifier +# define __is_identifier(__x) 1 +# endif + +# define __has_keyword(__x) !(__is_identifier(__x)) + +# ifndef __has_warning +# define __has_warning(...) 0 +# endif + +# if !defined(_LIBCPP_COMPILER_CLANG_BASED) && __cplusplus < 201103L +# error "libc++ only supports C++03 with Clang-based compilers. Please enable C++11" +# endif + #endif #endif // _LIBCPP___CONFIGURATION_COMPILER_H diff --git a/lib/libcxx/include/__configuration/diagnostic_suppression.h b/lib/libcxx/include/__configuration/diagnostic_suppression.h new file mode 100644 index 0000000000000000000000000000000000000000..2e497e3a19f1e5b25b6caf2c472c3b283548bc1b --- /dev/null +++ b/lib/libcxx/include/__configuration/diagnostic_suppression.h @@ -0,0 +1,44 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP___CONFIGURATION_DIAGNOSTIC_SUPPRESSION_H +#define _LIBCPP___CONFIGURATION_DIAGNOSTIC_SUPPRESSION_H + +/* zig patch: instead of including __config_site, zig adds -D flags when compiling */ +#include <__configuration/compiler.h> +#include <__configuration/utility.h> + +#ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER +# pragma GCC system_header +#endif + +#ifdef _LIBCPP_COMPILER_CLANG_BASED +# define _LIBCPP_DIAGNOSTIC_PUSH _Pragma("clang diagnostic push") +# define _LIBCPP_DIAGNOSTIC_POP _Pragma("clang diagnostic pop") +# define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED(str) _Pragma(_LIBCPP_TOSTRING(clang diagnostic ignored str)) +# define _LIBCPP_GCC_DIAGNOSTIC_IGNORED(str) +#elif defined(_LIBCPP_COMPILER_GCC) +# define _LIBCPP_DIAGNOSTIC_PUSH _Pragma("GCC diagnostic push") +# define _LIBCPP_DIAGNOSTIC_POP _Pragma("GCC diagnostic pop") +# define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED(str) +# define _LIBCPP_GCC_DIAGNOSTIC_IGNORED(str) _Pragma(_LIBCPP_TOSTRING(GCC diagnostic ignored str)) +#else +# define _LIBCPP_DIAGNOSTIC_PUSH +# define _LIBCPP_DIAGNOSTIC_POP +# define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED(str) +# define _LIBCPP_GCC_DIAGNOSTIC_IGNORED(str) +#endif + +// Macros to enter and leave a state where deprecation warnings are suppressed. +#define _LIBCPP_SUPPRESS_DEPRECATED_PUSH \ + _LIBCPP_DIAGNOSTIC_PUSH _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wdeprecated") \ + _LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wdeprecated-declarations") +#define _LIBCPP_SUPPRESS_DEPRECATED_POP _LIBCPP_DIAGNOSTIC_POP + +#endif // _LIBCPP___CONFIGURATION_DIAGNOSTIC_SUPPRESSION_H diff --git a/lib/libcxx/include/__configuration/hardening.h b/lib/libcxx/include/__configuration/hardening.h index bd172d99accaefcd22a487ff8f8d5e4b94fbfafd..7fd4a910f0784efb7ab415ae58e25f31ab0f5a86 100644 --- a/lib/libcxx/include/__configuration/hardening.h +++ b/lib/libcxx/include/__configuration/hardening.h @@ -17,23 +17,6 @@ # pragma GCC system_header #endif -// TODO(LLVM 23): Remove this. We're making these an error to catch folks who might not have migrated. -// Since hardening went through several changes (many of which impacted user-facing macros), -// we're keeping these checks around for a bit longer than usual. Failure to properly configure -// hardening results in checks being dropped silently, which is a pretty big deal. -#if defined(_LIBCPP_ENABLE_ASSERTIONS) -# error "_LIBCPP_ENABLE_ASSERTIONS has been removed, please use _LIBCPP_HARDENING_MODE= instead (see docs)" -#endif -#if defined(_LIBCPP_ENABLE_HARDENED_MODE) -# error "_LIBCPP_ENABLE_HARDENED_MODE has been removed, please use _LIBCPP_HARDENING_MODE= instead (see docs)" -#endif -#if defined(_LIBCPP_ENABLE_SAFE_MODE) -# error "_LIBCPP_ENABLE_SAFE_MODE has been removed, please use _LIBCPP_HARDENING_MODE= instead (see docs)" -#endif -#if defined(_LIBCPP_ENABLE_DEBUG_MODE) -# error "_LIBCPP_ENABLE_DEBUG_MODE has been removed, please use _LIBCPP_HARDENING_MODE= instead (see docs)" -#endif - // The library provides the macro `_LIBCPP_HARDENING_MODE` which can be set to one of the following values: // // - `_LIBCPP_HARDENING_MODE_NONE`; diff --git a/lib/libcxx/include/__configuration/language.h b/lib/libcxx/include/__configuration/language.h index 6fef4f396bdf463ef4367f6fc4a20e25b50dbba4..5483ae9138be089b90c80f86d6371ed99f8b4d9b 100644 --- a/lib/libcxx/include/__configuration/language.h +++ b/lib/libcxx/include/__configuration/language.h @@ -50,4 +50,46 @@ # define _LIBCPP_HAS_EXCEPTIONS 0 #endif +#if _LIBCPP_STD_VER <= 17 || !defined(__cpp_char8_t) +# define _LIBCPP_HAS_CHAR8_T 0 +#else +# define _LIBCPP_HAS_CHAR8_T 1 +#endif + +#if _LIBCPP_STD_VER <= 11 +# define _LIBCPP_EXPLICIT_SINCE_CXX14 +#else +# define _LIBCPP_EXPLICIT_SINCE_CXX14 explicit +#endif + +#if _LIBCPP_STD_VER >= 14 +# define _LIBCPP_CONSTEXPR_SINCE_CXX14 constexpr +#else +# define _LIBCPP_CONSTEXPR_SINCE_CXX14 +#endif + +#if _LIBCPP_STD_VER >= 17 +# define _LIBCPP_CONSTEXPR_SINCE_CXX17 constexpr +#else +# define _LIBCPP_CONSTEXPR_SINCE_CXX17 +#endif + +#if _LIBCPP_STD_VER >= 20 +# define _LIBCPP_CONSTEXPR_SINCE_CXX20 constexpr +#else +# define _LIBCPP_CONSTEXPR_SINCE_CXX20 +#endif + +#if _LIBCPP_STD_VER >= 23 +# define _LIBCPP_CONSTEXPR_SINCE_CXX23 constexpr +#else +# define _LIBCPP_CONSTEXPR_SINCE_CXX23 +#endif + +#if _LIBCPP_STD_VER >= 26 +# define _LIBCPP_CONSTEXPR_SINCE_CXX26 constexpr +#else +# define _LIBCPP_CONSTEXPR_SINCE_CXX26 +#endif + #endif // _LIBCPP___CONFIGURATION_LANGUAGE_H diff --git a/lib/libcxx/include/__configuration/namespace.h b/lib/libcxx/include/__configuration/namespace.h new file mode 100644 index 0000000000000000000000000000000000000000..f0706631559069505ab01935591b7a9ba0f66ba0 --- /dev/null +++ b/lib/libcxx/include/__configuration/namespace.h @@ -0,0 +1,99 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP___CONFIGURATION_NAMESPACE_H +#define _LIBCPP___CONFIGURATION_NAMESPACE_H + +/* zig patch: instead of including __config_site, zig adds -D flags when compiling */ +#include <__configuration/attributes.h> +#include <__configuration/diagnostic_suppression.h> +#include <__configuration/utility.h> + +#ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER +# pragma GCC system_header +#endif + +// Clang modules take a significant compile time hit when pushing and popping diagnostics. +// Since all the headers are marked as system headers unless _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER is defined, we can +// simply disable this pushing and popping when _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER isn't defined. +#ifdef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER +# define _LIBCPP_PUSH_EXTENSION_DIAGNOSTICS \ + _LIBCPP_DIAGNOSTIC_PUSH \ + _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wc++11-extensions") \ + _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wc++14-extensions") \ + _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wc++17-extensions") \ + _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wc++20-extensions") \ + _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wc++23-extensions") \ + _LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wc++14-extensions") \ + _LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wc++17-extensions") \ + _LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wc++20-extensions") \ + _LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wc++23-extensions") +# define _LIBCPP_POP_EXTENSION_DIAGNOSTICS _LIBCPP_DIAGNOSTIC_POP +# define _LIBCPP_PUSH_ABI_PRAGMA_DIAGNOSTICS \ + _LIBCPP_DIAGNOSTIC_PUSH _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wpragma-clang-attribute") \ + _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wignored-attributes") +# define _LIBCPP_POP_ABI_PRAGMA_DIAGNOSTICS _LIBCPP_DIAGNOSTIC_POP +#else +# define _LIBCPP_PUSH_EXTENSION_DIAGNOSTICS +# define _LIBCPP_POP_EXTENSION_DIAGNOSTICS +# define _LIBCPP_PUSH_ABI_PRAGMA_DIAGNOSTICS +# define _LIBCPP_POP_ABI_PRAGMA_DIAGNOSTICS +#endif + +#define _LIBCPP_END_EXPLICIT_ABI_ANNOTATIONS \ + _LIBCPP_PUSH_ABI_PRAGMA_DIAGNOSTICS \ + _Pragma(_LIBCPP_TOSTRING(clang attribute _LibcxxExplicitABIAnnotations.push( \ + __attribute__((__exclude_from_explicit_instantiation__, \ + __visibility__("hidden"), \ + __abi_tag__(_LIBCPP_TOSTRING(_LIBCPP_ODR_SIGNATURE)))), \ + apply_to = function))) _LIBCPP_POP_ABI_PRAGMA_DIAGNOSTICS + +#define _LIBCPP_BEGIN_EXPLICIT_ABI_ANNOTATIONS _Pragma("clang attribute _LibcxxExplicitABIAnnotations.pop") + +// clang-format off + +// The unversioned namespace is used when we want to be ABI compatible with other standard libraries in some way. There +// are two main categories where that's the case: +// - Historically, we have made exception types ABI compatible with libstdc++ to allow throwing them between libstdc++ +// and libc++. This is not used anymore for new exception types, since there is no use-case for it anymore. +// - Types and functions which are used by the compiler are in the unversioned namespace, since the compiler has to know +// their mangling without the appropriate declaration in some cases. +// If it's not clear whether using the unversioned namespace is the correct thing to do, it's not. The versioned +// namespace (_LIBCPP_BEGIN_NAMESPACE_STD) should almost always be used. +# define _LIBCPP_BEGIN_UNVERSIONED_NAMESPACE_STD \ + _LIBCPP_PUSH_EXTENSION_DIAGNOSTICS _LIBCPP_END_EXPLICIT_ABI_ANNOTATIONS namespace _LIBCPP_NAMESPACE_VISIBILITY std { + +# define _LIBCPP_END_UNVERSIONED_NAMESPACE_STD } _LIBCPP_BEGIN_EXPLICIT_ABI_ANNOTATIONS _LIBCPP_POP_EXTENSION_DIAGNOSTICS + +# define _LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_BEGIN_UNVERSIONED_NAMESPACE_STD inline namespace _LIBCPP_ABI_NAMESPACE { +# define _LIBCPP_END_NAMESPACE_STD } _LIBCPP_END_UNVERSIONED_NAMESPACE_STD + +// TODO: This should really be in the versioned namespace +#define _LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL _LIBCPP_BEGIN_UNVERSIONED_NAMESPACE_STD namespace experimental { +#define _LIBCPP_END_NAMESPACE_EXPERIMENTAL } _LIBCPP_END_UNVERSIONED_NAMESPACE_STD + +#define _LIBCPP_BEGIN_NAMESPACE_LFTS _LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL inline namespace fundamentals_v1 { +#define _LIBCPP_END_NAMESPACE_LFTS } _LIBCPP_END_NAMESPACE_EXPERIMENTAL + +#define _LIBCPP_BEGIN_NAMESPACE_LFTS_V2 _LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL inline namespace fundamentals_v2 { +#define _LIBCPP_END_NAMESPACE_LFTS_V2 } _LIBCPP_END_NAMESPACE_EXPERIMENTAL + +#ifdef _LIBCPP_ABI_NO_FILESYSTEM_INLINE_NAMESPACE +# define _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM _LIBCPP_BEGIN_NAMESPACE_STD namespace filesystem { +# define _LIBCPP_END_NAMESPACE_FILESYSTEM } _LIBCPP_END_NAMESPACE_STD +#else +# define _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM _LIBCPP_BEGIN_NAMESPACE_STD \ + inline namespace __fs { namespace filesystem { + +# define _LIBCPP_END_NAMESPACE_FILESYSTEM }} _LIBCPP_END_NAMESPACE_STD +#endif + +// clang-format on + +#endif // _LIBCPP___CONFIGURATION_NAMESPACE_H diff --git a/lib/libcxx/include/__configuration/platform.h b/lib/libcxx/include/__configuration/platform.h index 7492346fa136c901c661bfc0016fb54911d7c255..cdacde0147fa40d671aa5946c8e108a246da8ae3 100644 --- a/lib/libcxx/include/__configuration/platform.h +++ b/lib/libcxx/include/__configuration/platform.h @@ -30,6 +30,10 @@ // ... add new file formats here ... #endif +#if defined(__MVS__) +# include // for __NATIVE_ASCII_F +#endif + // Need to detect which libc we're using if we're on Linux. #if (defined(__linux__) || defined(__AMDGPU__) || defined(__NVPTX__)) && __has_include() # include diff --git a/lib/libcxx/include/__configuration/pstl.h b/lib/libcxx/include/__configuration/pstl.h new file mode 100644 index 0000000000000000000000000000000000000000..138a2235ddb82189c515c7eac118935b149ec7a5 --- /dev/null +++ b/lib/libcxx/include/__configuration/pstl.h @@ -0,0 +1,66 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP___CONFIGURATION_PSTL_H +#define _LIBCPP___CONFIGURATION_PSTL_H + +/* zig patch: instead of including __config_site, zig adds -D flags when compiling */ + +#ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER +# pragma GCC system_header +#endif + +#define _PSTL_PRAGMA(x) _Pragma(#x) + +// Enable SIMD for compilers that support OpenMP 4.0 +#if (defined(_OPENMP) && _OPENMP >= 201307) + +# define _PSTL_UDR_PRESENT +# define _PSTL_PRAGMA_SIMD _PSTL_PRAGMA(omp simd) +# define _PSTL_PRAGMA_DECLARE_SIMD _PSTL_PRAGMA(omp declare simd) +# define _PSTL_PRAGMA_SIMD_REDUCTION(PRM) _PSTL_PRAGMA(omp simd reduction(PRM)) +# define _PSTL_PRAGMA_SIMD_SCAN(PRM) _PSTL_PRAGMA(omp simd reduction(inscan, PRM)) +# define _PSTL_PRAGMA_SIMD_INCLUSIVE_SCAN(PRM) _PSTL_PRAGMA(omp scan inclusive(PRM)) +# define _PSTL_PRAGMA_SIMD_EXCLUSIVE_SCAN(PRM) _PSTL_PRAGMA(omp scan exclusive(PRM)) + +// Declaration of reduction functor, where +// NAME - the name of the functor +// OP - type of the callable object with the reduction operation +// omp_in - refers to the local partial result +// omp_out - refers to the final value of the combiner operator +// omp_priv - refers to the private copy of the initial value +// omp_orig - refers to the original variable to be reduced +# define _PSTL_PRAGMA_DECLARE_REDUCTION(NAME, OP) \ + _PSTL_PRAGMA(omp declare reduction(NAME:OP : omp_out(omp_in)) initializer(omp_priv = omp_orig)) + +#elif defined(_LIBCPP_COMPILER_CLANG_BASED) + +# define _PSTL_PRAGMA_SIMD _Pragma("clang loop vectorize(enable) interleave(enable)") +# define _PSTL_PRAGMA_DECLARE_SIMD +# define _PSTL_PRAGMA_SIMD_REDUCTION(PRM) _Pragma("clang loop vectorize(enable) interleave(enable)") +# define _PSTL_PRAGMA_SIMD_SCAN(PRM) _Pragma("clang loop vectorize(enable) interleave(enable)") +# define _PSTL_PRAGMA_SIMD_INCLUSIVE_SCAN(PRM) +# define _PSTL_PRAGMA_SIMD_EXCLUSIVE_SCAN(PRM) +# define _PSTL_PRAGMA_DECLARE_REDUCTION(NAME, OP) + +#else // (defined(_OPENMP) && _OPENMP >= 201307) + +# define _PSTL_PRAGMA_SIMD +# define _PSTL_PRAGMA_DECLARE_SIMD +# define _PSTL_PRAGMA_SIMD_REDUCTION(PRM) +# define _PSTL_PRAGMA_SIMD_SCAN(PRM) +# define _PSTL_PRAGMA_SIMD_INCLUSIVE_SCAN(PRM) +# define _PSTL_PRAGMA_SIMD_EXCLUSIVE_SCAN(PRM) +# define _PSTL_PRAGMA_DECLARE_REDUCTION(NAME, OP) + +#endif // (defined(_OPENMP) && _OPENMP >= 201307) + +#define _PSTL_USE_NONTEMPORAL_STORES_IF_ALLOWED + +#endif // _LIBCPP___CONFIGURATION_PSTL_H diff --git a/lib/libcxx/include/__configuration/utility.h b/lib/libcxx/include/__configuration/utility.h new file mode 100644 index 0000000000000000000000000000000000000000..e2e18953bb239bf3a1deed9ecb3f471b462b3c9d --- /dev/null +++ b/lib/libcxx/include/__configuration/utility.h @@ -0,0 +1,26 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP___CONFIGURATION_UTILITY_H +#define _LIBCPP___CONFIGURATION_UTILITY_H + +/* zig patch: instead of including __config_site, zig adds -D flags when compiling */ + +#ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER +# pragma GCC system_header +#endif + +#define _LIBCPP_TOSTRING2(x) #x +#define _LIBCPP_TOSTRING(x) _LIBCPP_TOSTRING2(x) + +#define _LIBCPP_CONCAT_IMPL(_X, _Y) _X##_Y +#define _LIBCPP_CONCAT(_X, _Y) _LIBCPP_CONCAT_IMPL(_X, _Y) +#define _LIBCPP_CONCAT3(X, Y, Z) _LIBCPP_CONCAT(X, _LIBCPP_CONCAT(Y, Z)) + +#endif // _LIBCPP___CONFIGURATION_UTILITY_H diff --git a/lib/libcxx/include/__cstddef/byte.h b/lib/libcxx/include/__cstddef/byte.h index 3d97db1bea2938b2d7a5810f7ac2a8ece8a8481c..295150fd1ead560b019b8a5956709f5f8707d093 100644 --- a/lib/libcxx/include/__cstddef/byte.h +++ b/lib/libcxx/include/__cstddef/byte.h @@ -23,7 +23,7 @@ _LIBCPP_BEGIN_UNVERSIONED_NAMESPACE_STD enum class byte : unsigned char {}; -_LIBCPP_HIDE_FROM_ABI inline constexpr byte operator|(byte __lhs, byte __rhs) noexcept { +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr byte operator|(byte __lhs, byte __rhs) noexcept { return static_cast( static_cast(static_cast(__lhs) | static_cast(__rhs))); } @@ -32,7 +32,7 @@ _LIBCPP_HIDE_FROM_ABI inline constexpr byte& operator|=(byte& __lhs, byte __rhs) return __lhs = __lhs | __rhs; } -_LIBCPP_HIDE_FROM_ABI inline constexpr byte operator&(byte __lhs, byte __rhs) noexcept { +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr byte operator&(byte __lhs, byte __rhs) noexcept { return static_cast( static_cast(static_cast(__lhs) & static_cast(__rhs))); } @@ -41,7 +41,7 @@ _LIBCPP_HIDE_FROM_ABI inline constexpr byte& operator&=(byte& __lhs, byte __rhs) return __lhs = __lhs & __rhs; } -_LIBCPP_HIDE_FROM_ABI inline constexpr byte operator^(byte __lhs, byte __rhs) noexcept { +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr byte operator^(byte __lhs, byte __rhs) noexcept { return static_cast( static_cast(static_cast(__lhs) ^ static_cast(__rhs))); } @@ -50,7 +50,7 @@ _LIBCPP_HIDE_FROM_ABI inline constexpr byte& operator^=(byte& __lhs, byte __rhs) return __lhs = __lhs ^ __rhs; } -_LIBCPP_HIDE_FROM_ABI inline constexpr byte operator~(byte __b) noexcept { +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr byte operator~(byte __b) noexcept { return static_cast(static_cast(~static_cast(__b))); } @@ -60,7 +60,7 @@ _LIBCPP_HIDE_FROM_ABI constexpr byte& operator<<=(byte& __lhs, _Integer __shift) } template ::value, int> = 0> -_LIBCPP_HIDE_FROM_ABI constexpr byte operator<<(byte __lhs, _Integer __shift) noexcept { +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr byte operator<<(byte __lhs, _Integer __shift) noexcept { return static_cast(static_cast(static_cast(__lhs) << __shift)); } @@ -70,7 +70,7 @@ _LIBCPP_HIDE_FROM_ABI constexpr byte& operator>>=(byte& __lhs, _Integer __shift) } template ::value, int> = 0> -_LIBCPP_HIDE_FROM_ABI constexpr byte operator>>(byte __lhs, _Integer __shift) noexcept { +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr byte operator>>(byte __lhs, _Integer __shift) noexcept { return static_cast(static_cast(static_cast(__lhs) >> __shift)); } diff --git a/lib/libcxx/include/__cstddef/max_align_t.h b/lib/libcxx/include/__cstddef/max_align_t.h index 7c09c7e7f301726a22bebce4f327473ce208102d..e44665ec5ebb4abc8dd3dfd934571fd964519d13 100644 --- a/lib/libcxx/include/__cstddef/max_align_t.h +++ b/lib/libcxx/include/__cstddef/max_align_t.h @@ -16,12 +16,14 @@ # pragma GCC system_header #endif -_LIBCPP_BEGIN_NAMESPACE_STD - #if !defined(_LIBCPP_CXX03_LANG) + +_LIBCPP_BEGIN_NAMESPACE_STD + using ::max_align_t _LIBCPP_USING_IF_EXISTS; -#endif _LIBCPP_END_NAMESPACE_STD +#endif + #endif // _LIBCPP___CSTDDEF_MAX_ALIGN_T_H diff --git a/lib/libcxx/include/__debug_utils/sanitizers.h b/lib/libcxx/include/__debug_utils/sanitizers.h index 058feab0269e10d6b67c544b04701bb0712a1e78..e35812cc440d7865c46d514c97878f0da1cd7575 100644 --- a/lib/libcxx/include/__debug_utils/sanitizers.h +++ b/lib/libcxx/include/__debug_utils/sanitizers.h @@ -17,7 +17,32 @@ # pragma GCC system_header #endif -#if __has_feature(address_sanitizer) +// Within libc++, _LIBCPP_ENABLE_ASAN_CONTAINER_CHECKS determines whether the containers should +// provide ASAN container overflow checks. That setting attempts to honour ASAN's documented option +// __SANITIZER_DISABLE_CONTAINER_OVERFLOW__ which can be defined by users to disable container overflow +// checks. +// +// However, since parts of some containers (e.g. std::string) are compiled separately into the built +// library, there are caveats: +// - __SANITIZER_DISABLE_CONTAINER_OVERFLOW__ can't always be honoured, i.e. if the built library +// was compiled with ASAN container checks, it's impossible to turn them off afterwards. We diagnose +// this with an error to avoid the proliferation of invalid configurations that appear to work. +// +// - The container overflow checks themselves are not always available even when the user is compiling +// with -fsanitize=address. If a container is compiled separately like std::string, it can't provide +// container checks unless the separately compiled code was built with container checks enabled. These +// containers need to also conditionalize whether they provide overflow checks on `_LIBCPP_INSTRUMENTED_WITH_ASAN`. +#if __has_feature(address_sanitizer) && !defined(__SANITIZER_DISABLE_CONTAINER_OVERFLOW__) +# define _LIBCPP_ENABLE_ASAN_CONTAINER_CHECKS 1 +#else +# define _LIBCPP_ENABLE_ASAN_CONTAINER_CHECKS 0 +#endif + +#if _LIBCPP_INSTRUMENTED_WITH_ASAN && !_LIBCPP_ENABLE_ASAN_CONTAINER_CHECKS +# error "We can't disable ASAN container checks when libc++ has been built with ASAN container checks enabled" +#endif + +#if _LIBCPP_ENABLE_ASAN_CONTAINER_CHECKS extern "C" { _LIBCPP_EXPORTED_FROM_ABI void @@ -28,12 +53,12 @@ _LIBCPP_EXPORTED_FROM_ABI int __sanitizer_verify_double_ended_contiguous_container(const void*, const void*, const void*, const void*); } -#endif // __has_feature(address_sanitizer) +#endif // _LIBCPP_ENABLE_ASAN_CONTAINER_CHECKS _LIBCPP_BEGIN_NAMESPACE_STD // ASan choices -#if __has_feature(address_sanitizer) +#if _LIBCPP_ENABLE_ASAN_CONTAINER_CHECKS # define _LIBCPP_HAS_ASAN_CONTAINER_ANNOTATIONS_FOR_ALL_ALLOCATORS 1 #endif @@ -57,7 +82,7 @@ _LIBCPP_HIDE_FROM_ABI void __annotate_double_ended_contiguous_container( const void* __last_old_contained, const void* __first_new_contained, const void* __last_new_contained) { -#if !__has_feature(address_sanitizer) +#if !_LIBCPP_ENABLE_ASAN_CONTAINER_CHECKS (void)__first_storage; (void)__last_storage; (void)__first_old_contained; @@ -86,7 +111,7 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void __annotate_contiguous_c const void* __last_storage, const void* __old_last_contained, const void* __new_last_contained) { -#if !__has_feature(address_sanitizer) +#if !_LIBCPP_ENABLE_ASAN_CONTAINER_CHECKS (void)__first_storage; (void)__last_storage; (void)__old_last_contained; diff --git a/lib/libcxx/include/__exception/exception.h b/lib/libcxx/include/__exception/exception.h index ddc34b0fa8fa122be41c1def1989e29b4bfc581a..c5f37d5fd1611770ea81bfb7e9807eb195530428 100644 --- a/lib/libcxx/include/__exception/exception.h +++ b/lib/libcxx/include/__exception/exception.h @@ -22,6 +22,7 @@ #endif _LIBCPP_BEGIN_UNVERSIONED_NAMESPACE_STD +_LIBCPP_BEGIN_EXPLICIT_ABI_ANNOTATIONS #if defined(_LIBCPP_ABI_VCRUNTIME) && (!defined(_HAS_EXCEPTIONS) || _HAS_EXCEPTIONS != 0) // The std::exception class was already included above, but we're explicit about this condition here for clarity. @@ -91,6 +92,7 @@ public: }; #endif // !_LIBCPP_ABI_VCRUNTIME +_LIBCPP_END_EXPLICIT_ABI_ANNOTATIONS _LIBCPP_END_UNVERSIONED_NAMESPACE_STD #endif // _LIBCPP___EXCEPTION_EXCEPTION_H diff --git a/lib/libcxx/include/__exception/exception_ptr.h b/lib/libcxx/include/__exception/exception_ptr.h index 92ff5c701e0d39b061cf7c4bd77e19fbedee8884..4ba107accdb7504f63ca5ea169916b07300e0013 100644 --- a/lib/libcxx/include/__exception/exception_ptr.h +++ b/lib/libcxx/include/__exception/exception_ptr.h @@ -31,7 +31,7 @@ _LIBCPP_PUSH_MACROS #ifndef _LIBCPP_ABI_MICROSOFT -# if _LIBCPP_AVAILABILITY_HAS_INIT_PRIMARY_EXCEPTION +# if _LIBCPP_HAS_EXCEPTIONS && _LIBCPP_HAS_RTTI && _LIBCPP_AVAILABILITY_HAS_INIT_PRIMARY_EXCEPTION namespace __cxxabiv1 { @@ -55,13 +55,12 @@ _LIBCPP_OVERRIDABLE_FUNC_VIS __cxa_exception* __cxa_init_primary_exception( } // namespace __cxxabiv1 -# endif +# endif // _LIBCPP_HAS_EXCEPTIONS && _LIBCPP_HAS_RTTI && _LIBCPP_AVAILABILITY_HAS_INIT_PRIMARY_EXCEPTION -#endif +#endif // !defined(_LIBCPP_ABI_MICROSOFT) _LIBCPP_BEGIN_UNVERSIONED_NAMESPACE_STD - -#ifndef _LIBCPP_ABI_MICROSOFT +_LIBCPP_BEGIN_EXPLICIT_ABI_ANNOTATIONS inline _LIBCPP_HIDE_FROM_ABI void swap(exception_ptr& __x, exception_ptr& __y) _NOEXCEPT; @@ -73,6 +72,8 @@ class _LIBCPP_EXPORTED_FROM_ABI exception_ptr { template friend _LIBCPP_HIDE_FROM_ABI exception_ptr __make_exception_ptr_explicit(_Ep&) _NOEXCEPT; + friend _LIBCPP_EXPORTED_FROM_ABI exception_ptr __copy_exception_ptr(void*, const void*); + public: // exception_ptr is basically a COW string so it is trivially relocatable. using __trivially_relocatable _LIBCPP_NODEBUG = exception_ptr; @@ -112,8 +113,10 @@ inline _LIBCPP_HIDE_FROM_ABI void swap(exception_ptr& __x, exception_ptr& __y) _ std::swap(__x.__ptr_, __y.__ptr_); } +#ifndef _LIBCPP_ABI_MICROSOFT + # if _LIBCPP_HAS_EXCEPTIONS -# if _LIBCPP_AVAILABILITY_HAS_INIT_PRIMARY_EXCEPTION +# if _LIBCPP_HAS_RTTI && _LIBCPP_AVAILABILITY_HAS_INIT_PRIMARY_EXCEPTION template _LIBCPP_HIDE_FROM_ABI exception_ptr __make_exception_ptr_explicit(_Ep& __e) _NOEXCEPT { using _Ep2 = __decay_t<_Ep>; @@ -136,7 +139,7 @@ _LIBCPP_HIDE_FROM_ABI exception_ptr __make_exception_ptr_explicit(_Ep& __e) _NOE return current_exception(); } } -# endif +# endif // _LIBCPP_HAS_RTTI && _LIBCPP_AVAILABILITY_HAS_INIT_PRIMARY_EXCEPTION template _LIBCPP_HIDE_FROM_ABI exception_ptr __make_exception_ptr_via_throw(_Ep& __e) _NOEXCEPT { @@ -164,7 +167,7 @@ _LIBCPP_HIDE_FROM_ABI exception_ptr make_exception_ptr(_Ep __e) _NOEXCEPT { return std::__make_exception_ptr_via_throw(__e); } -# if _LIBCPP_AVAILABILITY_HAS_INIT_PRIMARY_EXCEPTION && !defined(_LIBCPP_CXX03_LANG) +# if _LIBCPP_HAS_RTTI && _LIBCPP_AVAILABILITY_HAS_INIT_PRIMARY_EXCEPTION && !defined(_LIBCPP_CXX03_LANG) return std::__make_exception_ptr_explicit(__e); # else return std::__make_exception_ptr_via_throw(__e); @@ -177,36 +180,9 @@ _LIBCPP_HIDE_FROM_ABI exception_ptr make_exception_ptr(_Ep) _NOEXCEPT { } # endif // _LIBCPP_HAS_EXCEPTIONS -#else // _LIBCPP_ABI_MICROSOFT - -class _LIBCPP_EXPORTED_FROM_ABI exception_ptr { - _LIBCPP_DIAGNOSTIC_PUSH - _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wunused-private-field") - void* __ptr1_; - void* __ptr2_; - _LIBCPP_DIAGNOSTIC_POP - -public: - exception_ptr() _NOEXCEPT; - exception_ptr(nullptr_t) _NOEXCEPT; - exception_ptr(const exception_ptr& __other) _NOEXCEPT; - exception_ptr& operator=(const exception_ptr& __other) _NOEXCEPT; - exception_ptr& operator=(nullptr_t) _NOEXCEPT; - ~exception_ptr() _NOEXCEPT; - explicit operator bool() const _NOEXCEPT; -}; - -_LIBCPP_EXPORTED_FROM_ABI bool operator==(const exception_ptr& __x, const exception_ptr& __y) _NOEXCEPT; - -inline _LIBCPP_HIDE_FROM_ABI bool operator!=(const exception_ptr& __x, const exception_ptr& __y) _NOEXCEPT { - return !(__x == __y); -} - -_LIBCPP_EXPORTED_FROM_ABI void swap(exception_ptr&, exception_ptr&) _NOEXCEPT; +#else // defined(_LIBCPP_ABI_MICROSOFT) _LIBCPP_EXPORTED_FROM_ABI exception_ptr __copy_exception_ptr(void* __except, const void* __ptr); -_LIBCPP_EXPORTED_FROM_ABI exception_ptr current_exception() _NOEXCEPT; -[[__noreturn__]] _LIBCPP_EXPORTED_FROM_ABI void rethrow_exception(exception_ptr); // This is a built-in template function which automagically extracts the required // information. @@ -218,7 +194,9 @@ _LIBCPP_HIDE_FROM_ABI exception_ptr make_exception_ptr(_Ep __e) _NOEXCEPT { return __copy_exception_ptr(std::addressof(__e), __GetExceptionInfo(__e)); } -#endif // _LIBCPP_ABI_MICROSOFT +#endif // defined(_LIBCPP_ABI_MICROSOFT) + +_LIBCPP_END_EXPLICIT_ABI_ANNOTATIONS _LIBCPP_END_UNVERSIONED_NAMESPACE_STD _LIBCPP_POP_MACROS diff --git a/lib/libcxx/include/__exception/nested_exception.h b/lib/libcxx/include/__exception/nested_exception.h index dd84efbccde88c0161b60c995bb0b0a9d520676a..8b33911efd4c68a34d886528efd7a489a08abb24 100644 --- a/lib/libcxx/include/__exception/nested_exception.h +++ b/lib/libcxx/include/__exception/nested_exception.h @@ -14,7 +14,6 @@ #include <__memory/addressof.h> #include <__type_traits/decay.h> #include <__type_traits/enable_if.h> -#include <__type_traits/integral_constant.h> #include <__type_traits/is_base_of.h> #include <__type_traits/is_class.h> #include <__type_traits/is_constructible.h> @@ -28,6 +27,7 @@ #endif _LIBCPP_BEGIN_UNVERSIONED_NAMESPACE_STD +_LIBCPP_BEGIN_EXPLICIT_ABI_ANNOTATIONS class _LIBCPP_EXPORTED_FROM_ABI nested_exception { exception_ptr __ptr_; @@ -81,20 +81,20 @@ template } template -struct __can_dynamic_cast - : _BoolConstant< is_polymorphic<_From>::value && - (!is_base_of<_To, _From>::value || is_convertible::value)> {}; +inline const bool __can_dynamic_cast_v = + is_polymorphic<_From>::value && (!is_base_of<_To, _From>::value || is_convertible::value); -template ::value, int> = 0> +template , int> = 0> inline _LIBCPP_HIDE_FROM_ABI void rethrow_if_nested(const _Ep& __e) { const nested_exception* __nep = dynamic_cast(std::addressof(__e)); if (__nep) __nep->rethrow_nested(); } -template ::value, int> = 0> +template , int> = 0> inline _LIBCPP_HIDE_FROM_ABI void rethrow_if_nested(const _Ep&) {} +_LIBCPP_END_EXPLICIT_ABI_ANNOTATIONS _LIBCPP_END_UNVERSIONED_NAMESPACE_STD #endif // _LIBCPP___EXCEPTION_NESTED_EXCEPTION_H diff --git a/lib/libcxx/include/__exception/operations.h b/lib/libcxx/include/__exception/operations.h index 2b93ad260c30bea7e5a305146b28c5b19676de88..83507a739366296b4ebcdd64f20dc41623019f2e 100644 --- a/lib/libcxx/include/__exception/operations.h +++ b/lib/libcxx/include/__exception/operations.h @@ -16,6 +16,8 @@ #endif _LIBCPP_BEGIN_UNVERSIONED_NAMESPACE_STD +_LIBCPP_BEGIN_EXPLICIT_ABI_ANNOTATIONS + #if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_UNEXPECTED_FUNCTIONS) || \ defined(_LIBCPP_BUILDING_LIBRARY) using unexpected_handler = void (*)(); @@ -37,6 +39,8 @@ class _LIBCPP_EXPORTED_FROM_ABI exception_ptr; [[__nodiscard__]] _LIBCPP_EXPORTED_FROM_ABI exception_ptr current_exception() _NOEXCEPT; [[__noreturn__]] _LIBCPP_EXPORTED_FROM_ABI void rethrow_exception(exception_ptr); + +_LIBCPP_END_EXPLICIT_ABI_ANNOTATIONS _LIBCPP_END_UNVERSIONED_NAMESPACE_STD #endif // _LIBCPP___EXCEPTION_OPERATIONS_H diff --git a/lib/libcxx/include/__exception/terminate.h b/lib/libcxx/include/__exception/terminate.h index 955a49c2b00c36165235feb12fc3568b441784de..8f2f584b18d3533bcb418d292dcc58a0e851d2de 100644 --- a/lib/libcxx/include/__exception/terminate.h +++ b/lib/libcxx/include/__exception/terminate.h @@ -16,7 +16,11 @@ #endif _LIBCPP_BEGIN_UNVERSIONED_NAMESPACE_STD +_LIBCPP_BEGIN_EXPLICIT_ABI_ANNOTATIONS + [[__noreturn__]] _LIBCPP_EXPORTED_FROM_ABI void terminate() _NOEXCEPT; + +_LIBCPP_END_EXPLICIT_ABI_ANNOTATIONS _LIBCPP_END_UNVERSIONED_NAMESPACE_STD #endif // _LIBCPP___EXCEPTION_TERMINATE_H diff --git a/lib/libcxx/include/__expected/bad_expected_access.h b/lib/libcxx/include/__expected/bad_expected_access.h index b1958101d5178e4a0e96f94a560b6cbf35ce3807..d0ba175c04c92f7c8a40c7ff544839c6820c0557 100644 --- a/lib/libcxx/include/__expected/bad_expected_access.h +++ b/lib/libcxx/include/__expected/bad_expected_access.h @@ -23,6 +23,7 @@ _LIBCPP_PUSH_MACROS #if _LIBCPP_STD_VER >= 23 _LIBCPP_BEGIN_NAMESPACE_STD +_LIBCPP_BEGIN_EXPLICIT_ABI_ANNOTATIONS template class bad_expected_access; @@ -66,6 +67,7 @@ private: _Err __unex_; }; +_LIBCPP_END_EXPLICIT_ABI_ANNOTATIONS _LIBCPP_END_NAMESPACE_STD #endif // _LIBCPP_STD_VER >= 23 diff --git a/lib/libcxx/include/__expected/expected.h b/lib/libcxx/include/__expected/expected.h index 24ae33d4e3af8d491fa78926f00b50b46077f727..9b0e0322106ba33e1069396e2635f1cb8c388486 100644 --- a/lib/libcxx/include/__expected/expected.h +++ b/lib/libcxx/include/__expected/expected.h @@ -10,6 +10,7 @@ #define _LIBCPP___EXPECTED_EXPECTED_H #include <__assert> +#include <__concepts/same_as.h> #include <__config> #include <__expected/bad_expected_access.h> #include <__expected/unexpect.h> @@ -36,7 +37,6 @@ #include <__type_traits/is_trivially_destructible.h> #include <__type_traits/is_trivially_relocatable.h> #include <__type_traits/is_void.h> -#include <__type_traits/lazy.h> #include <__type_traits/negation.h> #include <__type_traits/remove_cv.h> #include <__type_traits/remove_cvref.h> @@ -446,6 +446,10 @@ private: _LIBCPP_NO_UNIQUE_ADDRESS __conditional_no_unique_address<__allow_reusing_expected_tail_padding, __repr> __repr_; }; +// Helper to handle comparisons that produce a value whose type is not bool, +// but allows only implicit (and not explicit) conversions to bool. +constexpr bool __into_bool(bool __b) noexcept { return __b; } + template class expected : private __expected_base<_Tp, _Err> { static_assert(!is_reference_v<_Tp> && !is_function_v<_Tp> && !is_same_v, in_place_t> && @@ -684,12 +688,11 @@ public: private: template static constexpr bool __can_assign_from_unexpected = - _And< is_constructible<_Err, _OtherErrQual>, - is_assignable<_Err&, _OtherErrQual>, - _Lazy<_Or, - is_nothrow_constructible<_Err, _OtherErrQual>, - is_nothrow_move_constructible<_Tp>, - is_nothrow_move_constructible<_Err>> >::value; + _And, + is_assignable<_Err&, _OtherErrQual>, + _Or, + is_nothrow_move_constructible<_Tp>, + is_nothrow_move_constructible<_Err>>>::value; public: template @@ -1161,15 +1164,18 @@ public: } } - template - _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(const expected& __x, const _T2& __v) + // The unusual signature avoids constraint recursion via ADL through + // std::expected, see https://llvm.org/PR160431. Note that this only + // triggers with compilers that implement https://wg21.link/CWG2369. + template _Tp2> + _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(const expected<_Tp2, _Err>& __x, const _T2& __v) # if _LIBCPP_STD_VER >= 26 requires(!__is_std_expected<_T2>::value) && requires { { *__x == __v } -> __core_convertible_to; } # endif { - return __x.__has_val() && static_cast(__x.__val() == __v); + return __x.__has_val() && std::__into_bool(__x.__val() == __v); } template @@ -1180,7 +1186,7 @@ public: } # endif { - return !__x.__has_val() && static_cast(__x.__unex() == __e.error()); + return !__x.__has_val() && std::__into_bool(__x.__unex() == __e.error()); } }; @@ -1882,7 +1888,7 @@ public: if (__x.__has_val() != __y.__has_val()) { return false; } else { - return __x.__has_val() || static_cast(__x.__unex() == __y.__unex()); + return __x.__has_val() || std::__into_bool(__x.__unex() == __y.__unex()); } } @@ -1894,7 +1900,7 @@ public: } # endif { - return !__x.__has_val() && static_cast(__x.__unex() == __y.error()); + return !__x.__has_val() && std::__into_bool(__x.__unex() == __y.error()); } }; diff --git a/lib/libcxx/include/__filesystem/directory_entry.h b/lib/libcxx/include/__filesystem/directory_entry.h index fab400b43942964986920df8a52e3ac905de0ed6..d741984b34feee101e5ba48c5d9b2b92ae328741 100644 --- a/lib/libcxx/include/__filesystem/directory_entry.h +++ b/lib/libcxx/include/__filesystem/directory_entry.h @@ -39,6 +39,7 @@ _LIBCPP_PUSH_MACROS #if _LIBCPP_STD_VER >= 17 && _LIBCPP_HAS_FILESYSTEM _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM +_LIBCPP_BEGIN_EXPLICIT_ABI_ANNOTATIONS class directory_entry { typedef filesystem::path _Path; @@ -465,6 +466,7 @@ private: directory_entry __elem_; }; +_LIBCPP_END_EXPLICIT_ABI_ANNOTATIONS _LIBCPP_END_NAMESPACE_FILESYSTEM #endif // _LIBCPP_STD_VER >= 17 && _LIBCPP_HAS_FILESYSTEM diff --git a/lib/libcxx/include/__filesystem/directory_iterator.h b/lib/libcxx/include/__filesystem/directory_iterator.h index b62129807b56740ed4f889b4897496a93126d966..52a5bf59a2c80cdaddb930f7e4932bebee9f012a 100644 --- a/lib/libcxx/include/__filesystem/directory_iterator.h +++ b/lib/libcxx/include/__filesystem/directory_iterator.h @@ -33,6 +33,7 @@ _LIBCPP_PUSH_MACROS #if _LIBCPP_STD_VER >= 17 && _LIBCPP_HAS_FILESYSTEM _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM +_LIBCPP_BEGIN_EXPLICIT_ABI_ANNOTATIONS class _LIBCPP_HIDDEN __dir_stream; class directory_iterator { @@ -129,6 +130,7 @@ operator!=(const directory_iterator& __lhs, const directory_iterator& __rhs) noe return directory_iterator(); } +_LIBCPP_END_EXPLICIT_ABI_ANNOTATIONS _LIBCPP_END_NAMESPACE_FILESYSTEM # if _LIBCPP_STD_VER >= 20 diff --git a/lib/libcxx/include/__filesystem/filesystem_error.h b/lib/libcxx/include/__filesystem/filesystem_error.h index 6f1daf866a5040fe7d7693a9eb682f76e08dcfba..054e38111b4153e00047b0c053ab53fbbf40d024 100644 --- a/lib/libcxx/include/__filesystem/filesystem_error.h +++ b/lib/libcxx/include/__filesystem/filesystem_error.h @@ -26,6 +26,7 @@ #if _LIBCPP_STD_VER >= 17 _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM +_LIBCPP_BEGIN_EXPLICIT_ABI_ANNOTATIONS class _LIBCPP_EXPORTED_FROM_ABI filesystem_error : public system_error { public: @@ -80,6 +81,7 @@ template } # endif +_LIBCPP_END_EXPLICIT_ABI_ANNOTATIONS _LIBCPP_END_NAMESPACE_FILESYSTEM #endif // _LIBCPP_STD_VER >= 17 diff --git a/lib/libcxx/include/__filesystem/operations.h b/lib/libcxx/include/__filesystem/operations.h index f536a1a9d44661b318fa939f1763ea214003f447..77b6e1908066d099c3cdcfda71e52678642cc5d1 100644 --- a/lib/libcxx/include/__filesystem/operations.h +++ b/lib/libcxx/include/__filesystem/operations.h @@ -31,6 +31,7 @@ _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM +_LIBCPP_BEGIN_EXPLICIT_ABI_ANNOTATIONS _LIBCPP_EXPORTED_FROM_ABI path __absolute(const path&, error_code* __ec = nullptr); _LIBCPP_EXPORTED_FROM_ABI path __canonical(const path&, error_code* __ec = nullptr); _LIBCPP_EXPORTED_FROM_ABI bool @@ -67,6 +68,7 @@ _LIBCPP_EXPORTED_FROM_ABI path __temp_directory_path(error_code* __ec = nullptr) _LIBCPP_EXPORTED_FROM_ABI bool __fs_is_empty(const path& __p, error_code* __ec = nullptr); _LIBCPP_EXPORTED_FROM_ABI void __permissions(const path&, perms, perm_options, error_code* = nullptr); _LIBCPP_EXPORTED_FROM_ABI space_info __space(const path&, error_code* __ec = nullptr); +_LIBCPP_END_EXPLICIT_ABI_ANNOTATIONS [[nodiscard]] inline _LIBCPP_HIDE_FROM_ABI path absolute(const path& __p) { return __absolute(__p); } [[nodiscard]] inline _LIBCPP_HIDE_FROM_ABI path absolute(const path& __p, error_code& __ec) { diff --git a/lib/libcxx/include/__filesystem/path.h b/lib/libcxx/include/__filesystem/path.h index 4fd3acad4d43047ab3770861317c5d02ac432335..a63c4ee611ebff93a86e0eb7a376d1b74cdbf021 100644 --- a/lib/libcxx/include/__filesystem/path.h +++ b/lib/libcxx/include/__filesystem/path.h @@ -23,6 +23,7 @@ #include <__type_traits/is_pointer.h> #include <__type_traits/remove_const.h> #include <__type_traits/remove_pointer.h> +#include <__type_traits/void_t.h> #include <__utility/move.h> #include #include @@ -41,6 +42,7 @@ _LIBCPP_PUSH_MACROS #if _LIBCPP_STD_VER >= 17 _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM +_LIBCPP_BEGIN_EXPLICIT_ABI_ANNOTATIONS template struct __can_convert_char { @@ -93,15 +95,12 @@ typedef string __u8_string; struct _NullSentinel {}; -template -using _Void _LIBCPP_NODEBUG = void; - template struct __is_pathable_string : public false_type {}; template struct __is_pathable_string< basic_string<_ECharT, _Traits, _Alloc>, - _Void::__char_type> > + void_t::__char_type> > : public __can_convert_char<_ECharT> { using _Str _LIBCPP_NODEBUG = basic_string<_ECharT, _Traits, _Alloc>; @@ -114,7 +113,7 @@ struct __is_pathable_string< basic_string<_ECharT, _Traits, _Alloc>, template struct __is_pathable_string< basic_string_view<_ECharT, _Traits>, - _Void::__char_type> > + void_t::__char_type> > : public __can_convert_char<_ECharT> { using _Str _LIBCPP_NODEBUG = basic_string_view<_ECharT, _Traits>; @@ -154,7 +153,7 @@ template struct __is_pathable_iter< _Iter, true, - _Void::value_type>::__char_type> > + void_t::value_type>::__char_type> > : __can_convert_char::value_type> { using _ECharT _LIBCPP_NODEBUG = typename iterator_traits<_Iter>::value_type; @@ -261,15 +260,14 @@ struct _PathCVT { template <> struct _PathCVT<__path_value> { - template ::value, int> = 0> + template _LIBCPP_HIDE_FROM_ABI static void __append_range(__path_string& __dest, _Iter __b, _Iter __e) { - for (; __b != __e; ++__b) - __dest.push_back(*__b); - } - - template ::value, int> = 0> - _LIBCPP_HIDE_FROM_ABI static void __append_range(__path_string& __dest, _Iter __b, _Iter __e) { - __dest.append(__b, __e); + if constexpr (__has_forward_iterator_category<_Iter>::value) { + __dest.append(__b, __e); + } else { + for (; __b != __e; ++__b) + __dest.push_back(*__b); + } } template @@ -296,13 +294,7 @@ struct _PathCVT { __char_to_wide(__str, const_cast<__path_value*>(__dest.data()) + __pos, __size); } - template ::value, int> = 0> - _LIBCPP_HIDE_FROM_ABI static void __append_range(__path_string& __dest, _Iter __b, _Iter __e) { - basic_string __tmp(__b, __e); - __append_string(__dest, __tmp); - } - - template ::value, int> = 0> + template _LIBCPP_HIDE_FROM_ABI static void __append_range(__path_string& __dest, _Iter __b, _Iter __e) { basic_string __tmp(__b, __e); __append_string(__dest, __tmp); @@ -449,7 +441,7 @@ public: return *this; } - _LIBCPP_HIDE_FROM_ABI path& assign(string_type&& __s) noexcept { + _LIBCPP_HIDE_FROM_ABI path& assign(string_type&& __s) noexcept _LIBCPP_LIFETIMEBOUND { __pn_ = std::move(__s); return *this; } @@ -460,14 +452,14 @@ public: } template - _LIBCPP_HIDE_FROM_ABI _EnableIfPathable<_Source> assign(const _Source& __src) { + _LIBCPP_HIDE_FROM_ABI _EnableIfPathable<_Source> assign(const _Source& __src) _LIBCPP_LIFETIMEBOUND { __pn_.clear(); _SourceCVT<_Source>::__append_source(__pn_, __src); return *this; } template - _LIBCPP_HIDE_FROM_ABI path& assign(_InputIt __first, _InputIt __last) { + _LIBCPP_HIDE_FROM_ABI path& assign(_InputIt __first, _InputIt __last) _LIBCPP_LIFETIMEBOUND { typedef typename iterator_traits<_InputIt>::value_type _ItVal; __pn_.clear(); _PathCVT<_ItVal>::__append_range(__pn_, __first, __last); @@ -501,12 +493,12 @@ public: } template - _LIBCPP_HIDE_FROM_ABI _EnableIfPathable<_Source> append(const _Source& __src) { + _LIBCPP_HIDE_FROM_ABI _EnableIfPathable<_Source> append(const _Source& __src) _LIBCPP_LIFETIMEBOUND { return operator/=(path(__src)); } template - _LIBCPP_HIDE_FROM_ABI path& append(_InputIt __first, _InputIt __last) { + _LIBCPP_HIDE_FROM_ABI path& append(_InputIt __first, _InputIt __last) _LIBCPP_LIFETIMEBOUND { return operator/=(path(__first, __last)); } # else @@ -530,7 +522,7 @@ public: } template - _LIBCPP_HIDE_FROM_ABI _EnableIfPathable<_Source> append(const _Source& __src) { + _LIBCPP_HIDE_FROM_ABI _EnableIfPathable<_Source> append(const _Source& __src) _LIBCPP_LIFETIMEBOUND { using _Traits = __is_pathable<_Source>; using _CVT = _PathCVT<_SourceChar<_Source> >; bool __source_is_absolute = filesystem::__is_separator(_Traits::__first_or_null(__src)); @@ -543,7 +535,7 @@ public: } template - _LIBCPP_HIDE_FROM_ABI path& append(_InputIt __first, _InputIt __last) { + _LIBCPP_HIDE_FROM_ABI path& append(_InputIt __first, _InputIt __last) _LIBCPP_LIFETIMEBOUND { typedef typename iterator_traits<_InputIt>::value_type _ItVal; static_assert(__can_convert_char<_ItVal>::value, "Must convertible"); using _CVT = _PathCVT<_ItVal>; @@ -594,13 +586,13 @@ public: } template - _LIBCPP_HIDE_FROM_ABI _EnableIfPathable<_Source> concat(const _Source& __x) { + _LIBCPP_HIDE_FROM_ABI _EnableIfPathable<_Source> concat(const _Source& __x) _LIBCPP_LIFETIMEBOUND { _SourceCVT<_Source>::__append_source(__pn_, __x); return *this; } template - _LIBCPP_HIDE_FROM_ABI path& concat(_InputIt __first, _InputIt __last) { + _LIBCPP_HIDE_FROM_ABI path& concat(_InputIt __first, _InputIt __last) _LIBCPP_LIFETIMEBOUND { typedef typename iterator_traits<_InputIt>::value_type _ItVal; _PathCVT<_ItVal>::__append_range(__pn_, __first, __last); return *this; @@ -609,26 +601,26 @@ public: // modifiers _LIBCPP_HIDE_FROM_ABI void clear() noexcept { __pn_.clear(); } - _LIBCPP_HIDE_FROM_ABI path& make_preferred() { + _LIBCPP_HIDE_FROM_ABI path& make_preferred() _LIBCPP_LIFETIMEBOUND { # if defined(_LIBCPP_WIN32API) std::replace(__pn_.begin(), __pn_.end(), L'/', L'\\'); # endif return *this; } - _LIBCPP_HIDE_FROM_ABI path& remove_filename() { + _LIBCPP_HIDE_FROM_ABI path& remove_filename() _LIBCPP_LIFETIMEBOUND { auto __fname = __filename(); if (!__fname.empty()) __pn_.erase(__fname.data() - __pn_.data()); return *this; } - _LIBCPP_HIDE_FROM_ABI path& replace_filename(const path& __replacement) { + _LIBCPP_HIDE_FROM_ABI path& replace_filename(const path& __replacement) _LIBCPP_LIFETIMEBOUND { remove_filename(); return (*this /= __replacement); } - path& replace_extension(const path& __replacement = path()); + path& replace_extension(const path& __replacement = path()) _LIBCPP_LIFETIMEBOUND; friend _LIBCPP_HIDE_FROM_ABI bool operator==(const path& __lhs, const path& __rhs) noexcept { return __lhs.__compare(__rhs.__pn_) == 0; @@ -667,9 +659,11 @@ public: _LIBCPP_HIDE_FROM_ABI void __reserve(size_t __s) { __pn_.reserve(__s); } // native format observers - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI const string_type& native() const noexcept { return __pn_; } + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI const string_type& native() const noexcept _LIBCPP_LIFETIMEBOUND { return __pn_; } - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI const value_type* c_str() const noexcept { return __pn_.c_str(); } + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI const value_type* c_str() const noexcept _LIBCPP_LIFETIMEBOUND { + return __pn_.c_str(); + } _LIBCPP_HIDE_FROM_ABI operator string_type() const { return __pn_; } @@ -874,23 +868,13 @@ public: [[nodiscard]] iterator end() const; # if _LIBCPP_HAS_LOCALIZATION - template < - class _CharT, - class _Traits, - __enable_if_t::value && is_same<_Traits, char_traits >::value, int> = 0> + template _LIBCPP_HIDE_FROM_ABI friend basic_ostream<_CharT, _Traits>& operator<<(basic_ostream<_CharT, _Traits>& __os, const path& __p) { - __os << std::__quoted(__p.native()); - return __os; - } - - template < - class _CharT, - class _Traits, - __enable_if_t::value || !is_same<_Traits, char_traits >::value, int> = 0> - _LIBCPP_HIDE_FROM_ABI friend basic_ostream<_CharT, _Traits>& - operator<<(basic_ostream<_CharT, _Traits>& __os, const path& __p) { - __os << std::__quoted(__p.string<_CharT, _Traits>()); + if constexpr (is_same<_CharT, value_type>::value && is_same<_Traits, char_traits >::value) + __os << std::quoted(__p.native()); + else + __os << std::quoted(__p.string<_CharT, _Traits>()); return __os; } @@ -898,7 +882,7 @@ public: _LIBCPP_HIDE_FROM_ABI friend basic_istream<_CharT, _Traits>& operator>>(basic_istream<_CharT, _Traits>& __is, path& __p) { basic_string<_CharT, _Traits> __tmp; - __is >> std::__quoted(__tmp); + __is >> std::quoted(__tmp); __p = __tmp; return __is; } @@ -916,6 +900,7 @@ inline _LIBCPP_HIDE_FROM_ABI void swap(path& __lhs, path& __rhs) noexcept { __lh [[nodiscard]] _LIBCPP_EXPORTED_FROM_ABI size_t hash_value(const path& __p) noexcept; +_LIBCPP_END_EXPLICIT_ABI_ANNOTATIONS _LIBCPP_END_NAMESPACE_FILESYSTEM _LIBCPP_BEGIN_NAMESPACE_STD diff --git a/lib/libcxx/include/__filesystem/path_iterator.h b/lib/libcxx/include/__filesystem/path_iterator.h index dd408a76ca597cd58f3997102977826f2f714c40..30a9a5a059af7c489ffe4b2f51d5d6fa4a35fd30 100644 --- a/lib/libcxx/include/__filesystem/path_iterator.h +++ b/lib/libcxx/include/__filesystem/path_iterator.h @@ -22,6 +22,7 @@ #if _LIBCPP_STD_VER >= 17 _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM +_LIBCPP_BEGIN_EXPLICIT_ABI_ANNOTATIONS class _LIBCPP_EXPORTED_FROM_ABI path::iterator { public: @@ -103,6 +104,7 @@ inline _LIBCPP_HIDE_FROM_ABI bool operator!=(const path::iterator& __lhs, const return !(__lhs == __rhs); } +_LIBCPP_END_EXPLICIT_ABI_ANNOTATIONS _LIBCPP_END_NAMESPACE_FILESYSTEM #endif // _LIBCPP_STD_VER >= 17 diff --git a/lib/libcxx/include/__filesystem/recursive_directory_iterator.h b/lib/libcxx/include/__filesystem/recursive_directory_iterator.h index 18165b0031e5845bc903ab5e7b0cf13d61235ec4..99665d017a10106affc998f5117d4c75c1391bf0 100644 --- a/lib/libcxx/include/__filesystem/recursive_directory_iterator.h +++ b/lib/libcxx/include/__filesystem/recursive_directory_iterator.h @@ -32,6 +32,7 @@ _LIBCPP_PUSH_MACROS #if _LIBCPP_STD_VER >= 17 && _LIBCPP_HAS_FILESYSTEM _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM +_LIBCPP_BEGIN_EXPLICIT_ABI_ANNOTATIONS class recursive_directory_iterator { public: @@ -139,6 +140,7 @@ begin(recursive_directory_iterator __iter) noexcept { return recursive_directory_iterator(); } +_LIBCPP_END_EXPLICIT_ABI_ANNOTATIONS _LIBCPP_END_NAMESPACE_FILESYSTEM # if _LIBCPP_STD_VER >= 20 diff --git a/lib/libcxx/include/__flat_map/flat_multimap.h b/lib/libcxx/include/__flat_map/flat_multimap.h index 72e3b5f21670c23d1edc5a02acf69acc8a651310..bd3ec81b98b7ffe8b131f3cb04c17b8dcc96a512 100644 --- a/lib/libcxx/include/__flat_map/flat_multimap.h +++ b/lib/libcxx/include/__flat_map/flat_multimap.h @@ -934,15 +934,6 @@ private: containers __containers_; _LIBCPP_NO_UNIQUE_ADDRESS key_compare __compare_; - - struct __key_equiv { - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __key_equiv(key_compare __c) : __comp_(__c) {} - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 bool - operator()(const_reference __x, const_reference __y) const { - return !__comp_(std::get<0>(__x), std::get<0>(__y)) && !__comp_(std::get<0>(__y), std::get<0>(__x)); - } - key_compare __comp_; - }; }; template > diff --git a/lib/libcxx/include/__flat_set/flat_multiset.h b/lib/libcxx/include/__flat_set/flat_multiset.h index b2de63bc3038ca9d47f5a77a02aa3be846ae373e..4324645fb8445f0e83ef3c0432ec26ebc0582150 100644 --- a/lib/libcxx/include/__flat_set/flat_multiset.h +++ b/lib/libcxx/include/__flat_set/flat_multiset.h @@ -745,15 +745,6 @@ private: _KeyContainer __keys_; _LIBCPP_NO_UNIQUE_ADDRESS key_compare __compare_; - - struct __key_equiv { - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __key_equiv(key_compare __c) : __comp_(__c) {} - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 bool - operator()(const_reference __x, const_reference __y) const { - return !__comp_(std::get<0>(__x), std::get<0>(__y)) && !__comp_(std::get<0>(__y), std::get<0>(__x)); - } - key_compare __comp_; - }; }; template > diff --git a/lib/libcxx/include/__format/container_adaptor.h b/lib/libcxx/include/__format/container_adaptor.h index 6a99a028615c6dab9fb45d88887ac8fc6a5100b2..ec8b1dedb190bd21df7af0d9a982f29a5929cc42 100644 --- a/lib/libcxx/include/__format/container_adaptor.h +++ b/lib/libcxx/include/__format/container_adaptor.h @@ -24,10 +24,10 @@ #include <__type_traits/is_const.h> #include <__type_traits/maybe_const.h> -_LIBCPP_BEGIN_NAMESPACE_STD - #if _LIBCPP_STD_VER >= 23 +_LIBCPP_BEGIN_NAMESPACE_STD + // [container.adaptors.format] only specifies the library should provide the // formatter specializations, not which header should provide them. // Since includes a lot of headers, add these headers here instead of @@ -66,8 +66,8 @@ template _Container> struct formatter, _CharT> : public __formatter_container_adaptor, _CharT> {}; -#endif // _LIBCPP_STD_VER >= 23 - _LIBCPP_END_NAMESPACE_STD +#endif // _LIBCPP_STD_VER >= 23 + #endif // _LIBCPP___FORMAT_CONTAINER_ADAPTOR_H diff --git a/lib/libcxx/include/__format/enable_insertable.h b/lib/libcxx/include/__format/enable_insertable.h index 29fe566ff06a3f2208f303fa4c7ac43038235749..d5832021aaf71a4daef832486f04a7a9913d7369 100644 --- a/lib/libcxx/include/__format/enable_insertable.h +++ b/lib/libcxx/include/__format/enable_insertable.h @@ -16,10 +16,10 @@ # pragma GCC system_header #endif -_LIBCPP_BEGIN_NAMESPACE_STD - #if _LIBCPP_STD_VER >= 20 +_LIBCPP_BEGIN_NAMESPACE_STD + namespace __format { /// Opt-in to enable \ref __insertable for a \a _Container. @@ -28,8 +28,8 @@ inline constexpr bool __enable_insertable = false; } // namespace __format -#endif // _LIBCPP_STD_VER >= 20 - _LIBCPP_END_NAMESPACE_STD +#endif // _LIBCPP_STD_VER >= 20 + #endif // _LIBCPP___FORMAT_ENABLE_INSERTABLE_H diff --git a/lib/libcxx/include/__format/escaped_output_table.h b/lib/libcxx/include/__format/escaped_output_table.h index 1401b4637d8396c9522ea3cbdc75ac43caf066a8..7b6a03162c4905bb1e79e626c9ce659265760881 100644 --- a/lib/libcxx/include/__format/escaped_output_table.h +++ b/lib/libcxx/include/__format/escaped_output_table.h @@ -61,19 +61,20 @@ #ifndef _LIBCPP___FORMAT_ESCAPED_OUTPUT_TABLE_H #define _LIBCPP___FORMAT_ESCAPED_OUTPUT_TABLE_H -#include <__algorithm/ranges_upper_bound.h> +#include <__algorithm/upper_bound.h> #include <__config> #include <__cstddef/ptrdiff_t.h> +#include <__iterator/access.h> #include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header #endif -_LIBCPP_BEGIN_NAMESPACE_STD - #if _LIBCPP_STD_VER >= 23 +_LIBCPP_BEGIN_NAMESPACE_STD + namespace __escaped_output_table { // clang-format off @@ -868,7 +869,7 @@ _LIBCPP_HIDE_FROM_ABI inline constexpr uint32_t __entries[735] = { if (__code_point >= 0x000323b0) return true; - ptrdiff_t __i = std::ranges::upper_bound(__entries, (__code_point << 14) | 0x3fffu) - __entries; + ptrdiff_t __i = std::upper_bound(std::begin(__entries), std::end(__entries), (__code_point << 14) | 0x3fffu) - __entries; if (__i == 0) return false; @@ -880,8 +881,8 @@ _LIBCPP_HIDE_FROM_ABI inline constexpr uint32_t __entries[735] = { // clang-format on } // namespace __escaped_output_table -#endif // _LIBCPP_STD_VER >= 23 - _LIBCPP_END_NAMESPACE_STD +#endif // _LIBCPP_STD_VER >= 23 + #endif // _LIBCPP___FORMAT_ESCAPED_OUTPUT_TABLE_H diff --git a/lib/libcxx/include/__format/fmt_pair_like.h b/lib/libcxx/include/__format/fmt_pair_like.h index d2f2f54d5ac0bc884c5b1abf0c05618b1a722099..e7369bdf2000c7b370cf241cb89c71cadaee3094 100644 --- a/lib/libcxx/include/__format/fmt_pair_like.h +++ b/lib/libcxx/include/__format/fmt_pair_like.h @@ -20,10 +20,10 @@ # pragma GCC system_header #endif -_LIBCPP_BEGIN_NAMESPACE_STD - #if _LIBCPP_STD_VER >= 23 +_LIBCPP_BEGIN_NAMESPACE_STD + // [tuple.like] defines a tuple-like exposition only concept. This concept is not related to that. Therefore it uses a // different name for the concept. // @@ -35,8 +35,8 @@ template concept __fmt_pair_like = __is_specialization_v<_Tp, pair> || (__is_specialization_v<_Tp, tuple> && tuple_size_v<_Tp> == 2); -#endif // _LIBCPP_STD_VER >= 23 - _LIBCPP_END_NAMESPACE_STD +#endif // _LIBCPP_STD_VER >= 23 + #endif // _LIBCPP___FORMAT_FMT_PAIR_LIKE_H diff --git a/lib/libcxx/include/__format/format_context.h b/lib/libcxx/include/__format/format_context.h index 9732ea9bf7f85b2184dc0702bbd0723f1d8cd897..cf3131b80e52f9eb74c3546dddfd2f3904454c0f 100644 --- a/lib/libcxx/include/__format/format_context.h +++ b/lib/libcxx/include/__format/format_context.h @@ -40,10 +40,6 @@ _LIBCPP_BEGIN_NAMESPACE_STD #if _LIBCPP_STD_VER >= 20 -template - requires output_iterator<_OutIt, const _CharT&> -class basic_format_context; - # if _LIBCPP_HAS_LOCALIZATION /** * Helper to create a basic_format_context. @@ -71,15 +67,16 @@ using wformat_context = basic_format_context< back_insert_iterator<__format::__o # endif template - requires output_iterator<_OutIt, const _CharT&> -class _LIBCPP_PREFERRED_NAME(format_context) - _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wformat_context)) basic_format_context { +class _LIBCPP_PREFERRED_NAME(format_context) _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wformat_context)) + basic_format_context { public: using iterator = _OutIt; using char_type = _CharT; template using formatter_type = formatter<_Tp, _CharT>; + static_assert(output_iterator<_OutIt, const _CharT&>, "[format.context]/p3 requires OutIt to be an output_iterator"); + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI basic_format_arg arg(size_t __id) const noexcept { return __args_.get(__id); } diff --git a/lib/libcxx/include/__format/format_error.h b/lib/libcxx/include/__format/format_error.h index b92e6d1de00e26628809fd07a4573a224582f8b9..853b4c1c3e75b1333307b4500c4214d8364ab78b 100644 --- a/lib/libcxx/include/__format/format_error.h +++ b/lib/libcxx/include/__format/format_error.h @@ -19,6 +19,7 @@ #endif _LIBCPP_BEGIN_NAMESPACE_STD +_LIBCPP_BEGIN_EXPLICIT_ABI_ANNOTATIONS #if _LIBCPP_STD_VER >= 20 @@ -45,6 +46,7 @@ _LIBCPP_DIAGNOSTIC_POP #endif // _LIBCPP_STD_VER >= 20 +_LIBCPP_END_EXPLICIT_ABI_ANNOTATIONS _LIBCPP_END_NAMESPACE_STD #endif // _LIBCPP___FORMAT_FORMAT_ERROR_H diff --git a/lib/libcxx/include/__format/format_functions.h b/lib/libcxx/include/__format/format_functions.h index 873265bc17c24c4acb3757efbdb6cc8d9355371b..b58e487d7511ef587ba0406576c788f3bcaf78f9 100644 --- a/lib/libcxx/include/__format/format_functions.h +++ b/lib/libcxx/include/__format/format_functions.h @@ -11,7 +11,7 @@ #define _LIBCPP___FORMAT_FORMAT_FUNCTIONS #include <__algorithm/clamp.h> -#include <__algorithm/ranges_find_first_of.h> +#include <__algorithm/find_first_of.h> #include <__chrono/statically_widen.h> #include <__concepts/convertible_to.h> #include <__concepts/same_as.h> @@ -26,7 +26,7 @@ #include <__format/format_string.h> #include <__format/format_to_n_result.h> #include <__format/formatter.h> -#include <__format/formatter_bool.h> +#include <__format/formatter_bool_impl.h> #include <__format/formatter_char.h> #include <__format/formatter_floating_point.h> #include <__format/formatter_integer.h> @@ -342,7 +342,7 @@ _LIBCPP_HIDE_FROM_ABI constexpr typename _Ctx::iterator __vformat_to(_ParseCtx&& # if _LIBCPP_STD_VER >= 26 template -struct __runtime_format_string { +struct __dynamic_format_string { private: basic_string_view<_CharT> __str_; @@ -350,15 +350,15 @@ private: friend struct basic_format_string; public: - _LIBCPP_HIDE_FROM_ABI __runtime_format_string(basic_string_view<_CharT> __s) noexcept : __str_(__s) {} + _LIBCPP_HIDE_FROM_ABI __dynamic_format_string(basic_string_view<_CharT> __s) noexcept : __str_(__s) {} - __runtime_format_string(const __runtime_format_string&) = delete; - __runtime_format_string& operator=(const __runtime_format_string&) = delete; + __dynamic_format_string(const __dynamic_format_string&) = delete; + __dynamic_format_string& operator=(const __dynamic_format_string&) = delete; }; -_LIBCPP_HIDE_FROM_ABI inline __runtime_format_string runtime_format(string_view __fmt) noexcept { return __fmt; } +_LIBCPP_HIDE_FROM_ABI inline __dynamic_format_string dynamic_format(string_view __fmt) noexcept { return __fmt; } # if _LIBCPP_HAS_WIDE_CHARACTERS -_LIBCPP_HIDE_FROM_ABI inline __runtime_format_string runtime_format(wstring_view __fmt) noexcept { +_LIBCPP_HIDE_FROM_ABI inline __dynamic_format_string dynamic_format(wstring_view __fmt) noexcept { return __fmt; } # endif @@ -375,7 +375,7 @@ struct basic_format_string { _LIBCPP_HIDE_FROM_ABI constexpr basic_string_view<_CharT> get() const noexcept { return __str_; } # if _LIBCPP_STD_VER >= 26 - _LIBCPP_HIDE_FROM_ABI basic_format_string(__runtime_format_string<_CharT> __s) noexcept : __str_(__s.__str_) {} + _LIBCPP_HIDE_FROM_ABI basic_format_string(__dynamic_format_string<_CharT> __s) noexcept : __str_(__s.__str_) {} # endif private: @@ -459,8 +459,12 @@ template basic_string_view<_CharT> __fmt, basic_format_args>, _CharT>> __args) { // Fold strings not containing '{' or '}' to just return the string - if (bool __is_identity = [&] [[__gnu__::__pure__]] // Make sure the compiler knows this call can be eliminated - { return std::ranges::find_first_of(__fmt, array{'{', '}'}) == __fmt.end(); }(); + if (bool __is_identity = + [&] [[__gnu__::__pure__]] // Make sure the compiler knows this call can be eliminated + { + char __vals[] = {'{', '}'}; + return std::find_first_of(__fmt.begin(), __fmt.end(), std::begin(__vals), std::end(__vals)) == __fmt.end(); + }(); __builtin_constant_p(__is_identity) && __is_identity) return basic_string<_CharT>{__fmt}; diff --git a/lib/libcxx/include/__format/formatter_bool.h b/lib/libcxx/include/__format/formatter_bool.h index 33a148a54668b0ab68e1f21b45c2a17251736f0b..2280ff131bcde82a3a1a51c62354946213c702b2 100644 --- a/lib/libcxx/include/__format/formatter_bool.h +++ b/lib/libcxx/include/__format/formatter_bool.h @@ -10,19 +10,10 @@ #ifndef _LIBCPP___FORMAT_FORMATTER_BOOL_H #define _LIBCPP___FORMAT_FORMATTER_BOOL_H -#include <__algorithm/copy.h> -#include <__assert> #include <__config> #include <__format/concepts.h> -#include <__format/format_parse_context.h> #include <__format/formatter.h> -#include <__format/formatter_integral.h> #include <__format/parser_std_format_spec.h> -#include <__utility/unreachable.h> - -#if _LIBCPP_HAS_LOCALIZATION -# include <__locale> -#endif #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header @@ -32,9 +23,12 @@ _LIBCPP_BEGIN_NAMESPACE_STD #if _LIBCPP_STD_VER >= 20 +template <__fmt_char_type _CharT, class _FormatContext> +_LIBCPP_HIDE_FROM_ABI typename _FormatContext::iterator +__formatter_bool_format(bool __value, __format_spec::__parser<_CharT>, _FormatContext&); + template <__fmt_char_type _CharT> struct formatter { -public: template _LIBCPP_HIDE_FROM_ABI constexpr typename _ParseContext::iterator parse(_ParseContext& __ctx) { typename _ParseContext::iterator __result = __parser_.__parse(__ctx, __format_spec::__fields_integral); @@ -44,26 +38,7 @@ public: template _LIBCPP_HIDE_FROM_ABI typename _FormatContext::iterator format(bool __value, _FormatContext& __ctx) const { - switch (__parser_.__type_) { - case __format_spec::__type::__default: - case __format_spec::__type::__string: - return __formatter::__format_bool(__value, __ctx, __parser_.__get_parsed_std_specifications(__ctx)); - - case __format_spec::__type::__binary_lower_case: - case __format_spec::__type::__binary_upper_case: - case __format_spec::__type::__octal: - case __format_spec::__type::__decimal: - case __format_spec::__type::__hexadecimal_lower_case: - case __format_spec::__type::__hexadecimal_upper_case: - // Promotes bool to an integral type. This reduces the number of - // instantiations of __format_integer reducing code size. - return __formatter::__format_integer( - static_cast(__value), __ctx, __parser_.__get_parsed_std_specifications(__ctx)); - - default: - _LIBCPP_ASSERT_INTERNAL(false, "The parse function should have validated the type"); - __libcpp_unreachable(); - } + return std::__formatter_bool_format(__value, __parser_, __ctx); } __format_spec::__parser<_CharT> __parser_; diff --git a/lib/libcxx/include/__format/formatter_bool_impl.h b/lib/libcxx/include/__format/formatter_bool_impl.h new file mode 100644 index 0000000000000000000000000000000000000000..ef1c1a0e77b50db9bb04ecd7e6b2e57463dd6bb7 --- /dev/null +++ b/lib/libcxx/include/__format/formatter_bool_impl.h @@ -0,0 +1,60 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP___FORMAT_FORMATTER_BOOL_IMPL_H +#define _LIBCPP___FORMAT_FORMATTER_BOOL_IMPL_H + +#include <__assert> +#include <__config> +#include <__format/concepts.h> +#include <__format/formatter_bool.h> +#include <__format/formatter_integral.h> +#include <__format/parser_std_format_spec.h> +#include <__utility/unreachable.h> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +#if _LIBCPP_STD_VER >= 20 + +_LIBCPP_BEGIN_NAMESPACE_STD + +// This function is separated from formatter to avoid pulling in a bunch of code from that we aren't +// required to provide in other headers where we need formatter itself to be complete. +template <__fmt_char_type _CharT, class _FormatContext> +_LIBCPP_HIDE_FROM_ABI typename _FormatContext::iterator +__formatter_bool_format(bool __value, __format_spec::__parser<_CharT> __parser, _FormatContext& __ctx) { + switch (__parser.__type_) { + case __format_spec::__type::__default: + case __format_spec::__type::__string: + return __formatter::__format_bool(__value, __ctx, __parser.__get_parsed_std_specifications(__ctx)); + + case __format_spec::__type::__binary_lower_case: + case __format_spec::__type::__binary_upper_case: + case __format_spec::__type::__octal: + case __format_spec::__type::__decimal: + case __format_spec::__type::__hexadecimal_lower_case: + case __format_spec::__type::__hexadecimal_upper_case: + // Promotes bool to an integral type. This reduces the number of + // instantiations of __format_integer reducing code size. + return __formatter::__format_integer( + static_cast(__value), __ctx, __parser.__get_parsed_std_specifications(__ctx)); + + default: + _LIBCPP_ASSERT_INTERNAL(false, "The parse function should have validated the type"); + __libcpp_unreachable(); + } +} + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_STD_VER >= 20 + +#endif // _LIBCPP___FORMAT_FORMATTER_BOOL_IMPL_H diff --git a/lib/libcxx/include/__format/formatter_floating_point.h b/lib/libcxx/include/__format/formatter_floating_point.h index b200bc58baa21f5894cbfc24fe1cf757d38ca738..f4de8b927651ae7cab5802467039558e742e5762 100644 --- a/lib/libcxx/include/__format/formatter_floating_point.h +++ b/lib/libcxx/include/__format/formatter_floating_point.h @@ -32,12 +32,12 @@ #include <__format/formatter_output.h> #include <__format/parser_std_format_spec.h> #include <__iterator/concepts.h> +#include <__math/traits.h> #include <__memory/allocator.h> #include <__system_error/errc.h> #include <__type_traits/conditional.h> #include <__utility/move.h> #include <__utility/unreachable.h> -#include #if _LIBCPP_HAS_LOCALIZATION # include <__locale> @@ -637,10 +637,10 @@ _LIBCPP_HIDE_FROM_ABI auto __write_using_trailing_zeros( template _LIBCPP_HIDE_FROM_ABI typename _FormatContext::iterator __format_floating_point(_Tp __value, _FormatContext& __ctx, __format_spec::__parsed_specifications<_CharT> __specs) { - bool __negative = std::signbit(__value); + bool __negative = __math::signbit(__value); - if (!std::isfinite(__value)) [[unlikely]] - return __formatter::__format_floating_point_non_finite(__ctx.out(), __specs, __negative, std::isnan(__value)); + if (!__math::isfinite(__value)) [[unlikely]] + return __formatter::__format_floating_point_non_finite(__ctx.out(), __specs, __negative, __math::isnan(__value)); // Depending on the std-format-spec string the sign and the value // might not be outputted together: diff --git a/lib/libcxx/include/__format/formatter_tuple.h b/lib/libcxx/include/__format/formatter_tuple.h index 0b095e6f71af4b1bb95f0b83f3de75d70441c0b5..c46d02ef381e1a4e7d4d5ca371a540c7cb1190e7 100644 --- a/lib/libcxx/include/__format/formatter_tuple.h +++ b/lib/libcxx/include/__format/formatter_tuple.h @@ -31,10 +31,10 @@ # pragma GCC system_header #endif -_LIBCPP_BEGIN_NAMESPACE_STD - #if _LIBCPP_STD_VER >= 23 +_LIBCPP_BEGIN_NAMESPACE_STD + template <__fmt_char_type _CharT, class _Tuple, formattable<_CharT>... _Args> struct __formatter_tuple { _LIBCPP_HIDE_FROM_ABI constexpr void set_separator(basic_string_view<_CharT> __separator) noexcept { @@ -141,8 +141,8 @@ struct formatter, _CharT> : public __formatter_tuple<_CharT, pair template <__fmt_char_type _CharT, formattable<_CharT>... _Args> struct formatter, _CharT> : public __formatter_tuple<_CharT, tuple<_Args...>, _Args...> {}; -#endif // _LIBCPP_STD_VER >= 23 - _LIBCPP_END_NAMESPACE_STD +#endif // _LIBCPP_STD_VER >= 23 + #endif // _LIBCPP___FORMAT_FORMATTER_TUPLE_H diff --git a/lib/libcxx/include/__format/range_default_formatter.h b/lib/libcxx/include/__format/range_default_formatter.h index 2d2190657b1af22d1a76a5188849db51b8960b17..fbad9022821c01a4138fd6920abdaf889d345b0f 100644 --- a/lib/libcxx/include/__format/range_default_formatter.h +++ b/lib/libcxx/include/__format/range_default_formatter.h @@ -22,6 +22,7 @@ #include <__format/formatter.h> #include <__format/range_format.h> #include <__format/range_formatter.h> +#include <__fwd/format.h> #include <__iterator/back_insert_iterator.h> #include <__ranges/concepts.h> #include <__ranges/data.h> @@ -32,10 +33,10 @@ #include <__utility/pair.h> #include -_LIBCPP_BEGIN_NAMESPACE_STD - #if _LIBCPP_STD_VER >= 23 +_LIBCPP_BEGIN_NAMESPACE_STD + template concept __const_formattable_range = ranges::input_range && formattable, _CharT>; @@ -168,8 +169,8 @@ template requires(format_kind<_Rp> != range_format::disabled && formattable, _CharT>) struct formatter<_Rp, _CharT> : __range_default_formatter, _Rp, _CharT> {}; -#endif // _LIBCPP_STD_VER >= 23 - _LIBCPP_END_NAMESPACE_STD +#endif // _LIBCPP_STD_VER >= 23 + #endif // _LIBCPP___FORMAT_RANGE_DEFAULT_FORMATTER_H diff --git a/lib/libcxx/include/__format/range_format.h b/lib/libcxx/include/__format/range_format.h index fe43923f9d9403eb36b3f8616d3ab350614e64fa..8bace8ecaad8b956e62f95cd5d41f20f6124aa7b 100644 --- a/lib/libcxx/include/__format/range_format.h +++ b/lib/libcxx/include/__format/range_format.h @@ -17,27 +17,13 @@ #include <__concepts/same_as.h> #include <__config> #include <__format/fmt_pair_like.h> +#include <__fwd/format.h> #include <__ranges/concepts.h> #include <__type_traits/remove_cvref.h> -_LIBCPP_BEGIN_NAMESPACE_STD - #if _LIBCPP_STD_VER >= 23 -_LIBCPP_DIAGNOSTIC_PUSH -_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wshadow") -_LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wshadow") -// This shadows map, set, and string. -enum class range_format { disabled, map, set, sequence, string, debug_string }; -_LIBCPP_DIAGNOSTIC_POP - -template -constexpr range_format format_kind = [] { - // [format.range.fmtkind]/1 - // A program that instantiates the primary template of format_kind is ill-formed. - static_assert(sizeof(_Rp) != sizeof(_Rp), "create a template specialization of format_kind for your type"); - return range_format::disabled; -}(); +_LIBCPP_BEGIN_NAMESPACE_STD template requires same_as<_Rp, remove_cvref_t<_Rp>> @@ -64,8 +50,8 @@ inline constexpr range_format format_kind<_Rp> = [] { return range_format::sequence; }(); -#endif // _LIBCPP_STD_VER >= 23 - _LIBCPP_END_NAMESPACE_STD +#endif // _LIBCPP_STD_VER >= 23 + #endif diff --git a/lib/libcxx/include/__format/range_formatter.h b/lib/libcxx/include/__format/range_formatter.h index 06d2b4cb4b9f48548cc11c8187b5ed0e81cafd27..a963a9fc704ffe98f2e393429416f0437ba893d5 100644 --- a/lib/libcxx/include/__format/range_formatter.h +++ b/lib/libcxx/include/__format/range_formatter.h @@ -34,10 +34,10 @@ #include <__type_traits/remove_cvref.h> #include -_LIBCPP_BEGIN_NAMESPACE_STD - #if _LIBCPP_STD_VER >= 23 +_LIBCPP_BEGIN_NAMESPACE_STD + template requires same_as, _Tp> && formattable<_Tp, _CharT> struct range_formatter { @@ -215,6 +215,8 @@ private: switch (*__begin) { case _CharT('m'): if constexpr (__fmt_pair_like<_Tp>) { + __underlying_.set_separator(_LIBCPP_STATICALLY_WIDEN(_CharT, ": ")); + __underlying_.set_brackets({}, {}); set_brackets(_LIBCPP_STATICALLY_WIDEN(_CharT, "{"), _LIBCPP_STATICALLY_WIDEN(_CharT, "}")); set_separator(_LIBCPP_STATICALLY_WIDEN(_CharT, ", ")); ++__begin; @@ -258,8 +260,8 @@ private: basic_string_view<_CharT> __closing_bracket_ = _LIBCPP_STATICALLY_WIDEN(_CharT, "]"); }; -#endif // _LIBCPP_STD_VER >= 23 - _LIBCPP_END_NAMESPACE_STD +#endif // _LIBCPP_STD_VER >= 23 + #endif // _LIBCPP___FORMAT_RANGE_FORMATTER_H diff --git a/lib/libcxx/include/__format/unicode.h b/lib/libcxx/include/__format/unicode.h index 46096fda1e8ae97bc8a34348d0ad8dfc0671d6ea..dbb87f2d711b0a8a788717a850ca464f13f735f4 100644 --- a/lib/libcxx/include/__format/unicode.h +++ b/lib/libcxx/include/__format/unicode.h @@ -101,7 +101,7 @@ inline constexpr __consume_result __consume_result_error{__replacement_character return __unicode::__is_code_point(__value) && !__unicode::__is_surrogate(__value); } -template +template requires same_as, char> _LIBCPP_HIDE_FROM_ABI constexpr bool __is_continuation(_Iterator __char, int __count) { do { diff --git a/lib/libcxx/include/__functional/binary_negate.h b/lib/libcxx/include/__functional/binary_negate.h index 73acfb37a7ee145f5e7f54d2ee039c6d365306e0..f7784fb1f1f11b9575cf51fea41d827cd523d748 100644 --- a/lib/libcxx/include/__functional/binary_negate.h +++ b/lib/libcxx/include/__functional/binary_negate.h @@ -17,10 +17,10 @@ # pragma GCC system_header #endif -_LIBCPP_BEGIN_NAMESPACE_STD - #if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_NEGATORS) +_LIBCPP_BEGIN_NAMESPACE_STD + template class _LIBCPP_DEPRECATED_IN_CXX17 binary_negate : public __binary_function(__pred); } -#endif // _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_NEGATORS) - _LIBCPP_END_NAMESPACE_STD +#endif // _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_NEGATORS) + #endif // _LIBCPP___FUNCTIONAL_BINARY_NEGATE_H diff --git a/lib/libcxx/include/__functional/bind_front.h b/lib/libcxx/include/__functional/bind_front.h index 427accf96339d6a352b7b1848c88031906d18611..97f8f4c458702e275051b8b26e5741b1b6531472 100644 --- a/lib/libcxx/include/__functional/bind_front.h +++ b/lib/libcxx/include/__functional/bind_front.h @@ -17,6 +17,8 @@ #include <__type_traits/decay.h> #include <__type_traits/enable_if.h> #include <__type_traits/is_constructible.h> +#include <__type_traits/is_member_pointer.h> +#include <__type_traits/is_pointer.h> #include <__utility/forward.h> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) @@ -49,6 +51,53 @@ template #endif // _LIBCPP_STD_VER >= 20 +#if _LIBCPP_STD_VER >= 26 + +template +struct __nttp_bind_front_t; + +template +struct __nttp_bind_front_t<_Fn, index_sequence<_Indices...>, _BoundArgs...> { + tuple<_BoundArgs...> __bound_args_; + + template + _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(this _Self&& __self, _Args&&... __args) noexcept(noexcept(std::invoke( + _Fn, std::get<_Indices>(std::forward<_Self>(__self).__bound_args_)..., std::forward<_Args>(__args)...))) + -> decltype(std::invoke( + _Fn, std::get<_Indices>(std::forward<_Self>(__self).__bound_args_)..., std::forward<_Args>(__args)...)) { + return std::invoke( + _Fn, std::get<_Indices>(std::forward<_Self>(__self).__bound_args_)..., std::forward<_Args>(__args)...); + } +}; + +template +struct __nttp_bind_without_bound_args_t { + template + _LIBCPP_HIDE_FROM_ABI static constexpr auto + operator()(_Args&&... __args) noexcept(noexcept(std::invoke(_Fn, std::forward<_Args>(__args)...))) + -> decltype(std::invoke(_Fn, std::forward<_Args>(__args)...)) { + return std::invoke(_Fn, std::forward<_Args>(__args)...); + } +}; + +template +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto bind_front(_Args&&... __args) { + static_assert((is_constructible_v, _Args> && ...), + "bind_front requires all decay_t to be constructible from respective Args"); + static_assert((is_move_constructible_v> && ...), + "bind_front requires all decay_t to be move constructible"); + if constexpr (using _Ty = decltype(_Fn); is_pointer_v<_Ty> || is_member_pointer_v<_Ty>) + static_assert(_Fn != nullptr, "bind_front: f cannot be equal to nullptr"); + + if constexpr (sizeof...(_Args) == 0) + return __nttp_bind_without_bound_args_t<_Fn>{}; + else + return __nttp_bind_front_t<_Fn, index_sequence_for<_Args...>, decay_t<_Args>...>{ + .__bound_args_{std::forward<_Args>(__args)...}}; +} + +#endif // _LIBCPP_STD_VER >= 26 + _LIBCPP_END_NAMESPACE_STD #endif // _LIBCPP___FUNCTIONAL_BIND_FRONT_H diff --git a/lib/libcxx/include/__functional/binder1st.h b/lib/libcxx/include/__functional/binder1st.h index 77a032245096b7366e3e3254e8e74ab6b446b76c..023c8c6b8c35b4172f214434ff163e6d07ad3b18 100644 --- a/lib/libcxx/include/__functional/binder1st.h +++ b/lib/libcxx/include/__functional/binder1st.h @@ -17,10 +17,10 @@ # pragma GCC system_header #endif -_LIBCPP_BEGIN_NAMESPACE_STD - #if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_BINDERS) +_LIBCPP_BEGIN_NAMESPACE_STD + template class _LIBCPP_DEPRECATED_IN_CXX11 binder1st : public __unary_function { @@ -47,8 +47,8 @@ bind1st(const _Operation& __op, const _Tp& __x) { return binder1st<_Operation>(__op, __x); } -#endif // _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_BINDERS) - _LIBCPP_END_NAMESPACE_STD +#endif // _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_BINDERS) + #endif // _LIBCPP___FUNCTIONAL_BINDER1ST_H diff --git a/lib/libcxx/include/__functional/binder2nd.h b/lib/libcxx/include/__functional/binder2nd.h index 8cc644151aff5920fb689a3ba020f3593a6c6d5f..e814c5dcbc70406016367012be767ed993583319 100644 --- a/lib/libcxx/include/__functional/binder2nd.h +++ b/lib/libcxx/include/__functional/binder2nd.h @@ -17,10 +17,10 @@ # pragma GCC system_header #endif -_LIBCPP_BEGIN_NAMESPACE_STD - #if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_BINDERS) +_LIBCPP_BEGIN_NAMESPACE_STD + template class _LIBCPP_DEPRECATED_IN_CXX11 binder2nd : public __unary_function { @@ -47,8 +47,8 @@ bind2nd(const _Operation& __op, const _Tp& __x) { return binder2nd<_Operation>(__op, __x); } -#endif // _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_BINDERS) - _LIBCPP_END_NAMESPACE_STD +#endif // _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_BINDERS) + #endif // _LIBCPP___FUNCTIONAL_BINDER2ND_H diff --git a/lib/libcxx/include/__functional/compose.h b/lib/libcxx/include/__functional/compose.h index 4b86dd37cd48a4af6ee0aca37af85dcb1c655cb1..20b30660b507bc2157c10750d4bc27e116c0d0d7 100644 --- a/lib/libcxx/include/__functional/compose.h +++ b/lib/libcxx/include/__functional/compose.h @@ -20,10 +20,10 @@ # pragma GCC system_header #endif -_LIBCPP_BEGIN_NAMESPACE_STD - #if _LIBCPP_STD_VER >= 20 +_LIBCPP_BEGIN_NAMESPACE_STD + struct __compose_op { template _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Fn1&& __f1, _Fn2&& __f2, _Args&&... __args) const noexcept(noexcept( @@ -46,8 +46,8 @@ _LIBCPP_HIDE_FROM_ABI constexpr auto __compose(_Fn1&& __f1, _Fn2&& __f2) noexcep return __compose_t, decay_t<_Fn2>>(std::forward<_Fn1>(__f1), std::forward<_Fn2>(__f2)); } -#endif // _LIBCPP_STD_VER >= 20 - _LIBCPP_END_NAMESPACE_STD +#endif // _LIBCPP_STD_VER >= 20 + #endif // _LIBCPP___FUNCTIONAL_COMPOSE_H diff --git a/lib/libcxx/include/__functional/function.h b/lib/libcxx/include/__functional/function.h index 121417f90ff01e71bc2a86536845bbaee7c37add..90072e952848456b6e1e6662b99deda06e860a7a 100644 --- a/lib/libcxx/include/__functional/function.h +++ b/lib/libcxx/include/__functional/function.h @@ -17,6 +17,7 @@ #include <__functional/binary_function.h> #include <__functional/unary_function.h> #include <__memory/addressof.h> +#include <__new/placement_new_delete.h> #include <__type_traits/aligned_storage.h> #include <__type_traits/decay.h> #include <__type_traits/invoke.h> @@ -44,6 +45,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD // bad_function_call _LIBCPP_DIAGNOSTIC_PUSH +_LIBCPP_BEGIN_EXPLICIT_ABI_ANNOTATIONS # if !_LIBCPP_AVAILABILITY_HAS_BAD_FUNCTION_CALL_KEY_FUNCTION _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wweak-vtables") # endif @@ -65,6 +67,7 @@ public: const char* what() const _NOEXCEPT override; # endif }; +_LIBCPP_END_EXPLICIT_ABI_ANNOTATIONS _LIBCPP_DIAGNOSTIC_POP [[__noreturn__]] inline _LIBCPP_HIDE_FROM_ABI void __throw_bad_function_call() { @@ -128,6 +131,7 @@ namespace __function { template class __base; +_LIBCPP_BEGIN_EXPLICIT_ABI_ANNOTATIONS template class __base<_Rp(_ArgTypes...)> { public: @@ -146,6 +150,7 @@ public: virtual const std::type_info& target_type() const _NOEXCEPT = 0; # endif // _LIBCPP_HAS_RTTI }; +_LIBCPP_END_EXPLICIT_ABI_ANNOTATIONS // __func implements __base for a given functor type. @@ -527,9 +532,13 @@ public: # if _LIBCPP_HAS_BLOCKS_RUNTIME +_LIBCPP_BEGIN_EXPLICIT_ABI_ANNOTATIONS + extern "C" void* _Block_copy(const void*); extern "C" void _Block_release(const void*); +_LIBCPP_END_EXPLICIT_ABI_ANNOTATIONS + template class __func<_Rp1 (^)(_ArgTypes1...), _Rp(_ArgTypes...)> : public __base<_Rp(_ArgTypes...)> { typedef _Rp1 (^__block_type)(_ArgTypes1...); @@ -540,7 +549,7 @@ public: # if __has_feature(objc_arc) : __f_(__f) # else - : __f_(reinterpret_cast<__block_type>(__f ? _Block_copy(__f) : nullptr)) + : __f_(reinterpret_cast<__block_type>(__f ? __function::_Block_copy(__f) : nullptr)) # endif { } @@ -563,7 +572,7 @@ public: _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual void destroy() _NOEXCEPT { # if !__has_feature(objc_arc) if (__f_) - _Block_release(__f_); + __function::_Block_release(__f_); # endif __f_ = 0; } @@ -684,7 +693,7 @@ public: template function(_Rp (*)(_Ap...)) -> function<_Rp(_Ap...)>; -template ::type> +template > function(_Fp) -> function<_Stripped>; # endif // _LIBCPP_STD_VER >= 17 diff --git a/lib/libcxx/include/__functional/hash.h b/lib/libcxx/include/__functional/hash.h index d81ff1abbdaba44c905fb66cd0f3d30fe3ed8330..c794f57356ae76671d595e13ca7f36fe5dbd26e4 100644 --- a/lib/libcxx/include/__functional/hash.h +++ b/lib/libcxx/include/__functional/hash.h @@ -23,7 +23,6 @@ #include <__type_traits/is_integral.h> #include <__type_traits/is_unqualified.h> #include <__type_traits/underlying_type.h> -#include <__utility/pair.h> #include <__utility/swap.h> #include #include @@ -41,6 +40,11 @@ inline _LIBCPP_HIDE_FROM_ABI _Size __loadword(const void* __p) { return __r; } +struct _PairT { + size_t first; + size_t second; +}; + // We use murmur2 when size_t is 32 bits, and cityhash64 when size_t // is 64 bits. This is because cityhash64 uses 64bit x 64bit // multiplication, which can be very slow on 32-bit systems. @@ -104,9 +108,9 @@ struct __murmur2_or_cityhash<_Size, 64> { _Size __y = std::__loadword<_Size>(__s + __len - 16) + std::__loadword<_Size>(__s + __len - 56); _Size __z = __hash_len_16(std::__loadword<_Size>(__s + __len - 48) + __len, std::__loadword<_Size>(__s + __len - 24)); - pair<_Size, _Size> __v = __weak_hash_len_32_with_seeds(__s + __len - 64, __len, __z); - pair<_Size, _Size> __w = __weak_hash_len_32_with_seeds(__s + __len - 32, __y + __k1, __x); - __x = __x * __k1 + std::__loadword<_Size>(__s); + _PairT __v = __weak_hash_len_32_with_seeds(__s + __len - 64, __len, __z); + _PairT __w = __weak_hash_len_32_with_seeds(__s + __len - 32, __y + __k1, __x); + __x = __x * __k1 + std::__loadword<_Size>(__s); // Decrease len to the nearest multiple of 64, and operate on 64-byte chunks. __len = (__len - 1) & ~static_cast<_Size>(63); @@ -192,7 +196,7 @@ private: // Return a 16-byte hash for 48 bytes. Quick and dirty. // Callers do best to use "random-looking" values for a and b. - _LIBCPP_HIDE_FROM_ABI _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK static pair<_Size, _Size> + _LIBCPP_HIDE_FROM_ABI _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK static _PairT __weak_hash_len_32_with_seeds(_Size __w, _Size __x, _Size __y, _Size __z, _Size __a, _Size __b) { __a += __w; __b = __rotate(__b + __a + __z, 21); @@ -200,11 +204,14 @@ private: __a += __x; __a += __y; __b += __rotate(__a, 44); - return pair<_Size, _Size>(__a + __z, __b + __c); + _PairT __ret; + __ret.first = __a + __z; + __ret.second = __b + __c; + return __ret; } // Return a 16-byte hash for s[0] ... s[31], a, and b. Quick and dirty. - _LIBCPP_HIDE_FROM_ABI _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK static pair<_Size, _Size> + _LIBCPP_HIDE_FROM_ABI _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK static _PairT __weak_hash_len_32_with_seeds(const char* __s, _Size __a, _Size __b) { return __weak_hash_len_32_with_seeds( std::__loadword<_Size>(__s), @@ -242,7 +249,9 @@ private: }; #if _LIBCPP_AVAILABILITY_HAS_HASH_MEMORY +_LIBCPP_BEGIN_EXPLICIT_ABI_ANNOTATIONS [[__gnu__::__pure__]] _LIBCPP_EXPORTED_FROM_ABI size_t __hash_memory(_LIBCPP_NOESCAPE const void*, size_t) _NOEXCEPT; +_LIBCPP_END_EXPLICIT_ABI_ANNOTATIONS #else _LIBCPP_HIDE_FROM_ABI inline size_t __hash_memory(const void* __ptr, size_t __size) _NOEXCEPT { return __murmur2_or_cityhash()(__ptr, __size); @@ -325,11 +334,6 @@ struct __scalar_hash<_Tp, 4> : public __unary_function<_Tp, size_t> { } }; -struct _PairT { - size_t first; - size_t second; -}; - _LIBCPP_HIDE_FROM_ABI inline size_t __hash_combine(size_t __lhs, size_t __rhs) _NOEXCEPT { typedef __scalar_hash<_PairT> _HashT; const _PairT __p = {__lhs, __rhs}; diff --git a/lib/libcxx/include/__functional/invoke.h b/lib/libcxx/include/__functional/invoke.h index ab201e94206e10bb61568d0654792f6768b5bfd9..f7d6a23a4e520dd04fc17cd11f586eb522a773f6 100644 --- a/lib/libcxx/include/__functional/invoke.h +++ b/lib/libcxx/include/__functional/invoke.h @@ -19,19 +19,17 @@ # pragma GCC system_header #endif -_LIBCPP_BEGIN_NAMESPACE_STD - #if _LIBCPP_STD_VER >= 17 +_LIBCPP_BEGIN_NAMESPACE_STD + template _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 invoke_result_t<_Fn, _Args...> invoke(_Fn&& __f, _Args&&... __args) noexcept(is_nothrow_invocable_v<_Fn, _Args...>) { return std::__invoke(std::forward<_Fn>(__f), std::forward<_Args>(__args)...); } -#endif // _LIBCPP_STD_VER >= 17 - -#if _LIBCPP_STD_VER >= 23 +# if _LIBCPP_STD_VER >= 23 template requires is_invocable_r_v<_Result, _Fn, _Args...> _LIBCPP_HIDE_FROM_ABI constexpr _Result @@ -48,8 +46,10 @@ invoke_r(_Fn&& __f, _Args&&... __args) noexcept(is_nothrow_invocable_r_v<_Result return std::invoke(std::forward<_Fn>(__f), std::forward<_Args>(__args)...); } } -#endif +# endif _LIBCPP_END_NAMESPACE_STD +#endif // _LIBCPP_STD_VER >= 17 + #endif // _LIBCPP___FUNCTIONAL_INVOKE_H diff --git a/lib/libcxx/include/__functional/is_transparent.h b/lib/libcxx/include/__functional/is_transparent.h index c2c6fbce2465b0d1075ee52affc92aefcf5604c1..a62b4cac952c04894e80e4f42a1863d5d04ec728 100644 --- a/lib/libcxx/include/__functional/is_transparent.h +++ b/lib/libcxx/include/__functional/is_transparent.h @@ -21,11 +21,11 @@ _LIBCPP_BEGIN_NAMESPACE_STD #if _LIBCPP_STD_VER >= 14 -template +template inline const bool __is_transparent_v = false; -template -inline const bool __is_transparent_v<_Tp, _Key, __void_t > = true; +template +inline const bool __is_transparent_v<_Comparator, __void_t > = true; #endif diff --git a/lib/libcxx/include/__functional/mem_fun_ref.h b/lib/libcxx/include/__functional/mem_fun_ref.h index 68223772a1587572427276a8efa4e7eab3ace916..bfae51454ec51bc3800ebe7ff8446fd1726dcf7b 100644 --- a/lib/libcxx/include/__functional/mem_fun_ref.h +++ b/lib/libcxx/include/__functional/mem_fun_ref.h @@ -18,10 +18,10 @@ # pragma GCC system_header #endif -_LIBCPP_BEGIN_NAMESPACE_STD - #if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_BINDERS) +_LIBCPP_BEGIN_NAMESPACE_STD + template class _LIBCPP_DEPRECATED_IN_CXX11 mem_fun_t : public __unary_function<_Tp*, _Sp> { _Sp (_Tp::*__p_)(); @@ -138,8 +138,8 @@ mem_fun_ref(_Sp (_Tp::*__f)(_Ap) const) { return const_mem_fun1_ref_t<_Sp, _Tp, _Ap>(__f); } -#endif // _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_BINDERS) - _LIBCPP_END_NAMESPACE_STD +#endif // _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_BINDERS) + #endif // _LIBCPP___FUNCTIONAL_MEM_FUN_REF_H diff --git a/lib/libcxx/include/__functional/operations.h b/lib/libcxx/include/__functional/operations.h index c0e719bb581b6696a548cc4e15bc1dd525ef832a..7a80dce648fa176ece954ddcb872ecccf8abb044 100644 --- a/lib/libcxx/include/__functional/operations.h +++ b/lib/libcxx/include/__functional/operations.h @@ -379,8 +379,8 @@ struct less { typedef void is_transparent; }; -template -struct __make_transparent<_Tp, less<_Tp> > { +template +struct __make_transparent<_ArgumentType, less<_ArgumentType> > { using type _LIBCPP_NODEBUG = less<>; }; @@ -477,8 +477,8 @@ struct greater { template inline const bool __desugars_to_v<__greater_tag, greater<>, _Tp, _Up> = true; -template -struct __make_transparent<_Tp, greater<_Tp>> { +template +struct __make_transparent<_ArgumentType, greater<_ArgumentType>> { using type _LIBCPP_NODEBUG = greater<>; }; diff --git a/lib/libcxx/include/__functional/perfect_forward.h b/lib/libcxx/include/__functional/perfect_forward.h index 37c3d15b4bec05b6af9fcae9172f2683c643ff3a..c0408b410e2f9542284681ce42a2c94c8270bc6b 100644 --- a/lib/libcxx/include/__functional/perfect_forward.h +++ b/lib/libcxx/include/__functional/perfect_forward.h @@ -28,10 +28,10 @@ _LIBCPP_PUSH_MACROS #include <__undef_macros> -_LIBCPP_BEGIN_NAMESPACE_STD - #if _LIBCPP_STD_VER >= 17 +_LIBCPP_BEGIN_NAMESPACE_STD + template struct __perfect_forward_impl; @@ -96,10 +96,10 @@ public: template using __perfect_forward _LIBCPP_NODEBUG = __perfect_forward_impl<_Op, index_sequence_for<_Args...>, _Args...>; -#endif // _LIBCPP_STD_VER >= 17 - _LIBCPP_END_NAMESPACE_STD +#endif // _LIBCPP_STD_VER >= 17 + _LIBCPP_POP_MACROS #endif // _LIBCPP___FUNCTIONAL_PERFECT_FORWARD_H diff --git a/lib/libcxx/include/__functional/pointer_to_binary_function.h b/lib/libcxx/include/__functional/pointer_to_binary_function.h index eb0e7674eea93981f42dc5e372aa877a69257669..89e0fa5fe2ac177178292f1439d98d0c6815caf2 100644 --- a/lib/libcxx/include/__functional/pointer_to_binary_function.h +++ b/lib/libcxx/include/__functional/pointer_to_binary_function.h @@ -17,10 +17,10 @@ # pragma GCC system_header #endif -_LIBCPP_BEGIN_NAMESPACE_STD - #if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_BINDERS) +_LIBCPP_BEGIN_NAMESPACE_STD + template class _LIBCPP_DEPRECATED_IN_CXX11 pointer_to_binary_function : public __binary_function<_Arg1, _Arg2, _Result> { _Result (*__f_)(_Arg1, _Arg2); @@ -36,8 +36,8 @@ ptr_fun(_Result (*__f)(_Arg1, _Arg2)) { return pointer_to_binary_function<_Arg1, _Arg2, _Result>(__f); } -#endif - _LIBCPP_END_NAMESPACE_STD +#endif + #endif // _LIBCPP___FUNCTIONAL_POINTER_TO_BINARY_FUNCTION_H diff --git a/lib/libcxx/include/__functional/pointer_to_unary_function.h b/lib/libcxx/include/__functional/pointer_to_unary_function.h index 459d24abdd7e723fbbe22bc9e9aa91b31f21cc88..b7778e4502dbc23531d1ec0eb2d419dd8bc790fb 100644 --- a/lib/libcxx/include/__functional/pointer_to_unary_function.h +++ b/lib/libcxx/include/__functional/pointer_to_unary_function.h @@ -17,10 +17,10 @@ # pragma GCC system_header #endif -_LIBCPP_BEGIN_NAMESPACE_STD - #if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_BINDERS) +_LIBCPP_BEGIN_NAMESPACE_STD + template class _LIBCPP_DEPRECATED_IN_CXX11 pointer_to_unary_function : public __unary_function<_Arg, _Result> { _Result (*__f_)(_Arg); @@ -36,8 +36,8 @@ ptr_fun(_Result (*__f)(_Arg)) { return pointer_to_unary_function<_Arg, _Result>(__f); } -#endif // _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_BINDERS) - _LIBCPP_END_NAMESPACE_STD +#endif // _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_BINDERS) + #endif // _LIBCPP___FUNCTIONAL_POINTER_TO_UNARY_FUNCTION_H diff --git a/lib/libcxx/include/__functional/ranges_operations.h b/lib/libcxx/include/__functional/ranges_operations.h index dc9da061af2649d3ea1e261907d0712963e9d3b4..66fe053b15634c73d433dfaa7215b9d006801f7c 100644 --- a/lib/libcxx/include/__functional/ranges_operations.h +++ b/lib/libcxx/include/__functional/ranges_operations.h @@ -21,10 +21,10 @@ # pragma GCC system_header #endif -_LIBCPP_BEGIN_NAMESPACE_STD - #if _LIBCPP_STD_VER >= 20 +_LIBCPP_BEGIN_NAMESPACE_STD + namespace ranges { struct equal_to { @@ -115,8 +115,8 @@ inline const bool __is_generic_transparent_comparator_v = true; template <> inline const bool __is_generic_transparent_comparator_v = true; -#endif // _LIBCPP_STD_VER >= 20 - _LIBCPP_END_NAMESPACE_STD +#endif // _LIBCPP_STD_VER >= 20 + #endif // _LIBCPP___FUNCTIONAL_RANGES_OPERATIONS_H diff --git a/lib/libcxx/include/__functional/unary_negate.h b/lib/libcxx/include/__functional/unary_negate.h index a93abc8e6b1c6b5a734585233b3042e7b300f929..761f0be5f85625f1a9857fb87f73751df3e5762e 100644 --- a/lib/libcxx/include/__functional/unary_negate.h +++ b/lib/libcxx/include/__functional/unary_negate.h @@ -17,10 +17,10 @@ # pragma GCC system_header #endif -_LIBCPP_BEGIN_NAMESPACE_STD - #if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_NEGATORS) +_LIBCPP_BEGIN_NAMESPACE_STD + template class _LIBCPP_DEPRECATED_IN_CXX17 unary_negate : public __unary_function { _Predicate __pred_; @@ -40,8 +40,8 @@ not1(const _Predicate& __pred) { return unary_negate<_Predicate>(__pred); } -#endif // _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_NEGATORS) - _LIBCPP_END_NAMESPACE_STD +#endif // _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_NEGATORS) + #endif // _LIBCPP___FUNCTIONAL_UNARY_NEGATE_H diff --git a/lib/libcxx/include/__fwd/format.h b/lib/libcxx/include/__fwd/format.h index b7f4cecb65c1e98677b7fba8fd6e3e1128982ffe..dd3260e36f4e475950080ef4127b714207421a10 100644 --- a/lib/libcxx/include/__fwd/format.h +++ b/lib/libcxx/include/__fwd/format.h @@ -11,28 +11,45 @@ #define _LIBCPP___FWD_FORMAT_H #include <__config> -#include <__iterator/concepts.h> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header #endif -_LIBCPP_BEGIN_NAMESPACE_STD - #if _LIBCPP_STD_VER >= 20 +_LIBCPP_BEGIN_NAMESPACE_STD + template class basic_format_arg; template - requires output_iterator<_OutIt, const _CharT&> class basic_format_context; template struct formatter; -#endif // _LIBCPP_STD_VER >= 20 +# if _LIBCPP_STD_VER >= 23 + +_LIBCPP_DIAGNOSTIC_PUSH +_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wshadow") +_LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wshadow") +// This shadows map, set, and string. +enum class range_format { disabled, map, set, sequence, string, debug_string }; +_LIBCPP_DIAGNOSTIC_POP + +template +constexpr range_format format_kind = [] { + // [format.range.fmtkind]/1 + // A program that instantiates the primary template of format_kind is ill-formed. + static_assert(sizeof(_Rp) != sizeof(_Rp), "create a template specialization of format_kind for your type"); + return range_format::disabled; +}(); + +# endif // _LIBCPP_STD_VER >= 23 _LIBCPP_END_NAMESPACE_STD +#endif // _LIBCPP_STD_VER >= 20 + #endif // _LIBCPP___FWD_FORMAT_H diff --git a/lib/libcxx/include/__fwd/map.h b/lib/libcxx/include/__fwd/map.h deleted file mode 100644 index 940298dd3e5635203e4e49e902654439fa6c6038..0000000000000000000000000000000000000000 --- a/lib/libcxx/include/__fwd/map.h +++ /dev/null @@ -1,31 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___FWD_MAP_H -#define _LIBCPP___FWD_MAP_H - -#include <__config> -#include <__fwd/functional.h> -#include <__fwd/memory.h> -#include <__fwd/pair.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template , class _Allocator = allocator > > -class map; - -template , class _Allocator = allocator > > -class multimap; - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___FWD_MAP_H diff --git a/lib/libcxx/include/__fwd/set.h b/lib/libcxx/include/__fwd/set.h deleted file mode 100644 index d5ef8d56b0015042d731fc3116971d92b6b51611..0000000000000000000000000000000000000000 --- a/lib/libcxx/include/__fwd/set.h +++ /dev/null @@ -1,30 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___FWD_SET_H -#define _LIBCPP___FWD_SET_H - -#include <__config> -#include <__fwd/functional.h> -#include <__fwd/memory.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template , class _Allocator = allocator<_Key> > -class set; - -template , class _Allocator = allocator<_Key> > -class multiset; - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___FWD_SET_H diff --git a/lib/libcxx/include/__fwd/span.h b/lib/libcxx/include/__fwd/span.h index 5d473ee51c6b74042b5eee553834f608d61d3a55..8610915edd02ec4f465be82fa5ea1a2902563f84 100644 --- a/lib/libcxx/include/__fwd/span.h +++ b/lib/libcxx/include/__fwd/span.h @@ -21,18 +21,18 @@ _LIBCPP_PUSH_MACROS #include <__undef_macros> -_LIBCPP_BEGIN_NAMESPACE_STD - #if _LIBCPP_STD_VER >= 20 +_LIBCPP_BEGIN_NAMESPACE_STD + inline constexpr size_t dynamic_extent = numeric_limits::max(); template class span; -#endif - _LIBCPP_END_NAMESPACE_STD +#endif + _LIBCPP_POP_MACROS #endif // _LIBCPP___FWD_SPAN_H diff --git a/lib/libcxx/include/__fwd/variant.h b/lib/libcxx/include/__fwd/variant.h index fef7071b3264680cb72eba6ee0454516dd577e4a..a484248fe542c3b9a109c3b3e1d0c1fed163d283 100644 --- a/lib/libcxx/include/__fwd/variant.h +++ b/lib/libcxx/include/__fwd/variant.h @@ -16,10 +16,10 @@ # pragma GCC system_header #endif -_LIBCPP_BEGIN_NAMESPACE_STD - #if _LIBCPP_STD_VER >= 17 +_LIBCPP_BEGIN_NAMESPACE_STD + template class variant; @@ -61,8 +61,8 @@ _LIBCPP_HIDE_FROM_ABI constexpr const _Tp& get(const variant<_Types...>&); template _LIBCPP_HIDE_FROM_ABI constexpr const _Tp&& get(const variant<_Types...>&&); -#endif // _LIBCPP_STD_VER >= 17 - _LIBCPP_END_NAMESPACE_STD +#endif // _LIBCPP_STD_VER >= 17 + #endif // _LIBCPP___FWD_VARIANT_H diff --git a/lib/libcxx/include/__hash_table b/lib/libcxx/include/__hash_table index ef487fb06dd5ed80a4cb5bc1f8b980e8d9207fe5..0ce4cf3edd6fde90fda37fe754daaa09e9837b4e 100644 --- a/lib/libcxx/include/__hash_table +++ b/lib/libcxx/include/__hash_table @@ -41,6 +41,8 @@ #include <__type_traits/is_swappable.h> #include <__type_traits/remove_const.h> #include <__type_traits/remove_cvref.h> +#include <__utility/exception_guard.h> +#include <__utility/exchange.h> #include <__utility/forward.h> #include <__utility/move.h> #include <__utility/pair.h> @@ -73,7 +75,9 @@ struct __is_hash_value_type : false_type {}; template struct __is_hash_value_type<_One> : __is_hash_value_type_imp<__remove_cvref_t<_One> > {}; +_LIBCPP_BEGIN_EXPLICIT_ABI_ANNOTATIONS _LIBCPP_EXPORTED_FROM_ABI size_t __next_prime(size_t __n); +_LIBCPP_END_EXPLICIT_ABI_ANNOTATIONS template struct __hash_node_base { @@ -524,9 +528,7 @@ public: _LIBCPP_HIDE_FROM_ABI __bucket_list_deallocator(__bucket_list_deallocator&& __x) _NOEXCEPT_(is_nothrow_move_constructible::value) - : __size_(std::move(__x.__size_)), __alloc_(std::move(__x.__alloc_)) { - __x.size() = 0; - } + : __size_(std::__exchange(__x.__size_, 0)), __alloc_(std::move(__x.__alloc_)) {} _LIBCPP_HIDE_FROM_ABI size_type& size() _NOEXCEPT { return __size_; } _LIBCPP_HIDE_FROM_ABI size_type size() const _NOEXCEPT { return __size_; } @@ -696,6 +698,17 @@ private: _LIBCPP_HIDE_FROM_ABI void __copy_construct(__next_pointer __other_iter) { __next_pointer __own_iter = __first_node_.__ptr(); + // If copying a node throws, the nodes that have already been constructed and linked into the + // list have to be deallocated. When this is called from the copy constructor the enclosing + // __hash_table is not fully constructed yet, so its destructor would not run to release them. + // This is also reached from operator= when assigning into an empty table; there the table + // stays alive, so we must leave it in a valid empty state: besides releasing the nodes we + // clear the bucket pointers, which were made to point into the now-deallocated node list. + auto __guard = std::__make_exception_guard([&] { + __deallocate_node_list(__first_node_.__next_); + __first_node_.__next_ = nullptr; + std::fill_n(__bucket_list_.get(), bucket_count(), nullptr); + }); { __node_holder __new_node = __construct_node_hash(__other_iter->__hash(), __other_iter->__upcast()->__get_value()); __own_iter->__next_ = static_cast<__next_pointer>(__new_node.release()); @@ -706,6 +719,7 @@ private: __other_iter = __other_iter->__next_; __own_iter = __own_iter->__next_; __copy_construct(__other_iter, __own_iter, __current_chash); + __guard.__complete(); } public: diff --git a/lib/libcxx/include/__iterator/access.h b/lib/libcxx/include/__iterator/access.h index d42855f925487346d71f154e271777fc8aa0865a..c01d3fa2baa8ddbe379d02491d29b1822585a997 100644 --- a/lib/libcxx/include/__iterator/access.h +++ b/lib/libcxx/include/__iterator/access.h @@ -20,47 +20,49 @@ _LIBCPP_BEGIN_NAMESPACE_STD template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _Tp* begin(_Tp (&__array)[_Np]) _NOEXCEPT { +[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _Tp* begin(_Tp (&__array)[_Np]) _NOEXCEPT { return __array; } template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _Tp* end(_Tp (&__array)[_Np]) _NOEXCEPT { +[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _Tp* end(_Tp (&__array)[_Np]) _NOEXCEPT { return __array + _Np; } #if !defined(_LIBCPP_CXX03_LANG) template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 auto begin(_Cp& __c) -> decltype(__c.begin()) { +[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 auto begin(_Cp& __c) -> decltype(__c.begin()) { return __c.begin(); } template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 auto begin(const _Cp& __c) -> decltype(__c.begin()) { +[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 auto begin(const _Cp& __c) + -> decltype(__c.begin()) { return __c.begin(); } template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 auto end(_Cp& __c) -> decltype(__c.end()) { +[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 auto end(_Cp& __c) -> decltype(__c.end()) { return __c.end(); } template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 auto end(const _Cp& __c) -> decltype(__c.end()) { +[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 auto end(const _Cp& __c) -> decltype(__c.end()) { return __c.end(); } # if _LIBCPP_STD_VER >= 14 template -_LIBCPP_HIDE_FROM_ABI constexpr auto -cbegin(const _Cp& __c) noexcept(noexcept(std::begin(__c))) -> decltype(std::begin(__c)) { +[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI constexpr auto cbegin(const _Cp& __c) noexcept(noexcept(std::begin(__c))) + -> decltype(std::begin(__c)) { return std::begin(__c); } template -_LIBCPP_HIDE_FROM_ABI constexpr auto cend(const _Cp& __c) noexcept(noexcept(std::end(__c))) -> decltype(std::end(__c)) { +[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI constexpr auto cend(const _Cp& __c) noexcept(noexcept(std::end(__c))) + -> decltype(std::end(__c)) { return std::end(__c); } @@ -69,22 +71,22 @@ _LIBCPP_HIDE_FROM_ABI constexpr auto cend(const _Cp& __c) noexcept(noexcept(std: #else // defined(_LIBCPP_CXX03_LANG) template -_LIBCPP_HIDE_FROM_ABI typename _Cp::iterator begin(_Cp& __c) { +[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI typename _Cp::iterator begin(_Cp& __c) { return __c.begin(); } template -_LIBCPP_HIDE_FROM_ABI typename _Cp::const_iterator begin(const _Cp& __c) { +[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI typename _Cp::const_iterator begin(const _Cp& __c) { return __c.begin(); } template -_LIBCPP_HIDE_FROM_ABI typename _Cp::iterator end(_Cp& __c) { +[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI typename _Cp::iterator end(_Cp& __c) { return __c.end(); } template -_LIBCPP_HIDE_FROM_ABI typename _Cp::const_iterator end(const _Cp& __c) { +[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI typename _Cp::const_iterator end(const _Cp& __c) { return __c.end(); } diff --git a/lib/libcxx/include/__iterator/back_insert_iterator.h b/lib/libcxx/include/__iterator/back_insert_iterator.h index d051c08751d39a475d3de7e52e58b01909d9881e..456653ab36f339512ae892c382059d1e01935949 100644 --- a/lib/libcxx/include/__iterator/back_insert_iterator.h +++ b/lib/libcxx/include/__iterator/back_insert_iterator.h @@ -58,7 +58,9 @@ public: return *this; } #endif // _LIBCPP_CXX03_LANG - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 back_insert_iterator& operator*() { return *this; } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 back_insert_iterator& operator*() { + return *this; + } _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 back_insert_iterator& operator++() { return *this; } _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 back_insert_iterator operator++(int) { return *this; } diff --git a/lib/libcxx/include/__iterator/bounded_iter.h b/lib/libcxx/include/__iterator/bounded_iter.h index d2a09061126bdd5ac3ded95119aec988ec741fdb..9e5d929c8f1911f03319df8af310db0bc74c0586 100644 --- a/lib/libcxx/include/__iterator/bounded_iter.h +++ b/lib/libcxx/include/__iterator/bounded_iter.h @@ -53,9 +53,6 @@ _LIBCPP_BEGIN_NAMESPACE_STD // optimizations deleting non-redundant bounds checks. template struct __bounded_iter { - static_assert(__libcpp_is_contiguous_iterator<_Iterator>::value, - "Only contiguous iterators can be adapted by __bounded_iter."); - using value_type = typename iterator_traits<_Iterator>::value_type; using difference_type = typename iterator_traits<_Iterator>::difference_type; using pointer = typename iterator_traits<_Iterator>::pointer; @@ -117,7 +114,7 @@ public: // that the iterator is always within `[begin, end]`, we only need to check it's not pointing to // `end`. This is easier for the optimizer because it aligns with the `iter != container.end()` // checks that typical callers already use (see https://llvm.org/PR78829). - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 reference operator*() const _NOEXCEPT { + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 reference operator*() const _NOEXCEPT { _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS( __current_ != __end_, "__bounded_iter::operator*: Attempt to dereference an iterator at the end"); return *__current_; @@ -129,7 +126,8 @@ public: return std::__to_address(__current_); } - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 reference operator[](difference_type __n) const _NOEXCEPT { + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 reference + operator[](difference_type __n) const _NOEXCEPT { _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS( __n >= __begin_ - __current_, "__bounded_iter::operator[]: Attempt to index an iterator past the start"); _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS( @@ -172,13 +170,13 @@ public: __current_ += __n; return *this; } - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 friend __bounded_iter + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 friend __bounded_iter operator+(__bounded_iter const& __self, difference_type __n) _NOEXCEPT { __bounded_iter __tmp(__self); __tmp += __n; return __tmp; } - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 friend __bounded_iter + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 friend __bounded_iter operator+(difference_type __n, __bounded_iter const& __self) _NOEXCEPT { __bounded_iter __tmp(__self); __tmp += __n; @@ -193,13 +191,13 @@ public: __current_ -= __n; return *this; } - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 friend __bounded_iter + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 friend __bounded_iter operator-(__bounded_iter const& __self, difference_type __n) _NOEXCEPT { __bounded_iter __tmp(__self); __tmp -= __n; return __tmp; } - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 friend difference_type + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 friend difference_type operator-(__bounded_iter const& __x, __bounded_iter const& __y) _NOEXCEPT { return __x.__current_ - __y.__current_; } diff --git a/lib/libcxx/include/__iterator/capacity_aware_iterator.h b/lib/libcxx/include/__iterator/capacity_aware_iterator.h new file mode 100644 index 0000000000000000000000000000000000000000..a516feef60f36e057a9082f975f46a717650e642 --- /dev/null +++ b/lib/libcxx/include/__iterator/capacity_aware_iterator.h @@ -0,0 +1,186 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP___CAPACITY_AWARE_ITERATOR_H +#define _LIBCPP___CAPACITY_AWARE_ITERATOR_H + +#include <__assert> +#include <__compare/ordering.h> +#include <__compare/three_way_comparable.h> +#include <__config> +#include <__cstddef/size_t.h> +#include <__iterator/concepts.h> +#include <__iterator/incrementable_traits.h> +#include <__iterator/iterator_traits.h> +#include <__memory/pointer_traits.h> +#include <__type_traits/is_constructible.h> +#include <__type_traits/is_convertible.h> +#include <__utility/move.h> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + +#if _LIBCPP_STD_VER >= 26 + +_LIBCPP_BEGIN_NAMESPACE_STD + +// __capacity_aware_iterator is an iterator that wraps a contiguous iterator and encodes the maximum number of +// elements that can appear in a range of such iterators. That maximum number of elements must be known at compile-time. +// As of writing, the only standard library containers which fulfill these requirements are inplace_vector and optional. +// +// It also embeds a tag type to prevent mixing iterators from e.g. different containers. This also allows for some +// algorithms to detect this iterator and perform optimizations based on the added semantic information. + +template +class __capacity_aware_iterator { +private: + _Iter __iter_; + + template + friend class __capacity_aware_iterator; + +public: + static_assert(contiguous_iterator<_Iter>, "__capacity_aware_iterator can only be used with contiguous iterators"); + + using iterator_category = iterator_traits<_Iter>::iterator_category; + using iterator_concept = contiguous_iterator_tag; + using difference_type = iter_difference_t<_Iter>; + using pointer = iterator_traits<_Iter>::pointer; + using reference = iter_reference_t<_Iter>; + using value_type = iter_value_t<_Iter>; + + _LIBCPP_HIDE_FROM_ABI constexpr __capacity_aware_iterator() + requires is_default_constructible_v<_Iter> + = default; + + template + requires is_convertible_v<_Iter2, _Iter> + _LIBCPP_HIDE_FROM_ABI constexpr __capacity_aware_iterator( + const __capacity_aware_iterator<_Iter2, _Tag, _RangeMaxElements>& __y) noexcept + : __iter_(__y.__iter_) {} + + template + _LIBCPP_HIDE_FROM_ABI friend constexpr auto __make_capacity_aware_iterator(_It __iter) noexcept; + +private: + _LIBCPP_HIDE_FROM_ABI constexpr explicit __capacity_aware_iterator(_Iter __iter) : __iter_(std::move(__iter)) {} + +public: + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr decltype(auto) operator*() const noexcept { return *__iter_; } + _LIBCPP_HIDE_FROM_ABI constexpr decltype(auto) operator->() const noexcept { return std::__to_address(__iter_); } + + _LIBCPP_HIDE_FROM_ABI constexpr __capacity_aware_iterator& operator++() noexcept { + ++__iter_; + return *this; + } + + _LIBCPP_HIDE_FROM_ABI constexpr __capacity_aware_iterator operator++(int) noexcept { + __capacity_aware_iterator __tmp(*this); + ++*this; + return __tmp; + } + + _LIBCPP_HIDE_FROM_ABI constexpr __capacity_aware_iterator& operator--() noexcept { + --__iter_; + return *this; + } + + _LIBCPP_HIDE_FROM_ABI constexpr __capacity_aware_iterator operator--(int) noexcept { + __capacity_aware_iterator __tmp(*this); + --*this; + return __tmp; + } + + _LIBCPP_HIDE_FROM_ABI constexpr __capacity_aware_iterator& operator+=(difference_type __n) noexcept { + _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS( + static_cast(__n >= 0 ? __n : -__n) <= _RangeMaxElements, + "__capacity_aware_iterator::operator+=: Attempting to move iterator past its container's possible range"); + + __iter_ += __n; + return *this; + } + + _LIBCPP_HIDE_FROM_ABI constexpr __capacity_aware_iterator& operator-=(difference_type __n) noexcept { + _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS( + static_cast(__n >= 0 ? __n : -__n) <= _RangeMaxElements, + "__capacity_aware_iterator::operator-=: Attempting to move iterator past its container's possible range"); + + __iter_ -= __n; + return *this; + } + + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr decltype(auto) operator[](difference_type __n) const noexcept { + _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS( + static_cast(__n >= 0 ? __n : -__n) < _RangeMaxElements, + "__capacity_aware_iterator::operator[]: Attempting to index iterator past its container's possible range"); + return *(*this + __n); + } + + _LIBCPP_HIDE_FROM_ABI friend constexpr bool + operator==(const __capacity_aware_iterator& __x, const __capacity_aware_iterator& __y) noexcept { + return __x.__iter_ == __y.__iter_; + } + + _LIBCPP_HIDE_FROM_ABI friend constexpr auto + operator<=>(const __capacity_aware_iterator& __x, const __capacity_aware_iterator& __y) noexcept { + if constexpr (three_way_comparable_with<_Iter, _Iter, strong_ordering>) { + return __x.__iter_ <=> __y.__iter_; + } else { + if (__x.__iter_ < __y.__iter_) { + return strong_ordering::less; + } else if (__x.__iter_ == __y.__iter_) { + return strong_ordering::equal; + } + return strong_ordering::greater; + } + } + + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI friend constexpr __capacity_aware_iterator + operator+(const __capacity_aware_iterator& __i, difference_type __n) noexcept { + auto __tmp = __i; + __tmp += __n; + return __tmp; + } + + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI friend constexpr __capacity_aware_iterator + operator+(difference_type __n, const __capacity_aware_iterator& __i) noexcept { + auto __tmp = __i; + __tmp += __n; + return __tmp; + } + + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI friend constexpr __capacity_aware_iterator + operator-(const __capacity_aware_iterator& __i, difference_type __n) noexcept { + auto __tmp = __i; + __tmp -= __n; + return __tmp; + } + + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI friend constexpr difference_type + operator-(const __capacity_aware_iterator& __x, const __capacity_aware_iterator& __y) noexcept { + return difference_type(__x.__iter_ - __y.__iter_); + } +}; + +template +_LIBCPP_HIDE_FROM_ABI constexpr auto __make_capacity_aware_iterator(_It __iter) noexcept { + return __capacity_aware_iterator<_It, _Tag2, _RangeMaxElems2>(__iter); +} + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_STD_VER >= 26 + +_LIBCPP_POP_MACROS + +#endif // _LIBCPP___CAPACITY_AWARE_ITERATOR_H diff --git a/lib/libcxx/include/__iterator/common_iterator.h b/lib/libcxx/include/__iterator/common_iterator.h index a59063d245d9cbabe2e499f90e31f71fd9a1fc78..b234b3810308feaef78c7fbec36cb713a434807d 100644 --- a/lib/libcxx/include/__iterator/common_iterator.h +++ b/lib/libcxx/include/__iterator/common_iterator.h @@ -17,6 +17,7 @@ #include <__concepts/copyable.h> #include <__concepts/derived_from.h> #include <__concepts/equality_comparable.h> +#include <__concepts/referenceable.h> #include <__concepts/same_as.h> #include <__config> #include <__iterator/concepts.h> @@ -28,7 +29,6 @@ #include <__memory/addressof.h> #include <__type_traits/conditional.h> #include <__type_traits/is_pointer.h> -#include <__type_traits/is_referenceable.h> #include <__utility/declval.h> #include @@ -111,7 +111,7 @@ public: return *this; } - _LIBCPP_HIDE_FROM_ABI constexpr decltype(auto) operator*() { + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr decltype(auto) operator*() { _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS( std::holds_alternative<_Iter>(__hold_), "Attempted to dereference a non-dereferenceable common_iterator"); return *std::__unchecked_get<_Iter>(__hold_); @@ -237,7 +237,7 @@ public: return std::__unchecked_get<_Sent>(__x.__hold_) - std::__unchecked_get<_I2>(__y.__hold_); } - _LIBCPP_HIDE_FROM_ABI friend constexpr decltype(auto) + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI friend constexpr decltype(auto) iter_move(const common_iterator& __i) noexcept(noexcept(ranges::iter_move(std::declval()))) requires input_iterator<_Iter> { diff --git a/lib/libcxx/include/__iterator/concepts.h b/lib/libcxx/include/__iterator/concepts.h index 3b439204436368cac81aedc015cf66d2571bd33d..9aa2334844a931ad14d9de723f1399d9bf485205 100644 --- a/lib/libcxx/include/__iterator/concepts.h +++ b/lib/libcxx/include/__iterator/concepts.h @@ -20,6 +20,8 @@ #include <__concepts/invocable.h> #include <__concepts/movable.h> #include <__concepts/predicate.h> +#include <__concepts/primary_template.h> +#include <__concepts/referenceable.h> #include <__concepts/regular.h> #include <__concepts/relation.h> #include <__concepts/same_as.h> @@ -38,10 +40,7 @@ #include <__type_traits/integral_constant.h> #include <__type_traits/invoke.h> #include <__type_traits/is_pointer.h> -#include <__type_traits/is_primary_template.h> #include <__type_traits/is_reference.h> -#include <__type_traits/is_referenceable.h> -#include <__type_traits/is_valid_expansion.h> #include <__type_traits/remove_cv.h> #include <__type_traits/remove_cvref.h> #include <__utility/forward.h> @@ -80,7 +79,7 @@ template concept __specialization_of_projected = requires { typename __projected_iterator_t<_Tp>; typename __projected_projection_t<_Tp>; -} && __is_primary_template<_Tp>::value; +} && __primary_template<_Tp>; template struct __indirect_value_t_impl { @@ -153,8 +152,7 @@ concept sized_sentinel_for = template struct __iter_traits_cache { - using type _LIBCPP_NODEBUG = - _If<__is_primary_template >::value, _Iter, iterator_traits<_Iter> >; + using type _LIBCPP_NODEBUG = _If<__primary_template >, _Iter, iterator_traits<_Iter> >; }; template using _ITER_TRAITS _LIBCPP_NODEBUG = typename __iter_traits_cache<_Iter>::type; @@ -169,12 +167,13 @@ struct __iter_concept_category_test { }; struct __iter_concept_random_fallback { template - using _Apply _LIBCPP_NODEBUG = - __enable_if_t<__is_primary_template >::value, random_access_iterator_tag>; + using _Apply _LIBCPP_NODEBUG = __enable_if_t<__primary_template >, random_access_iterator_tag>; }; template -struct __test_iter_concept : _IsValidExpansion<_Tester::template _Apply, _Iter>, _Tester {}; + struct __test_iter_concept : bool_constant < requires { + typename _Tester::template _Apply<_Iter>; +} >, _Tester{}; template struct __iter_concept_cache { diff --git a/lib/libcxx/include/__iterator/counted_iterator.h b/lib/libcxx/include/__iterator/counted_iterator.h index 65e178bc0cf21c8e270489768efa0760181ee8af..211670d7ad91f15154fc7a03516c4cf8be5d1f85 100644 --- a/lib/libcxx/include/__iterator/counted_iterator.h +++ b/lib/libcxx/include/__iterator/counted_iterator.h @@ -98,18 +98,18 @@ public: return *this; } - _LIBCPP_HIDE_FROM_ABI constexpr const _Iter& base() const& noexcept { return __current_; } + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr const _Iter& base() const& noexcept { return __current_; } - _LIBCPP_HIDE_FROM_ABI constexpr _Iter base() && { return std::move(__current_); } + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Iter base() && { return std::move(__current_); } - _LIBCPP_HIDE_FROM_ABI constexpr iter_difference_t<_Iter> count() const noexcept { return __count_; } + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr iter_difference_t<_Iter> count() const noexcept { return __count_; } - _LIBCPP_HIDE_FROM_ABI constexpr decltype(auto) operator*() { + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr decltype(auto) operator*() { _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__count_ > 0, "Iterator is equal to or past end."); return *__current_; } - _LIBCPP_HIDE_FROM_ABI constexpr decltype(auto) operator*() const + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr decltype(auto) operator*() const requires __dereferenceable { _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__count_ > 0, "Iterator is equal to or past end."); @@ -169,13 +169,13 @@ public: return __tmp; } - _LIBCPP_HIDE_FROM_ABI constexpr counted_iterator operator+(iter_difference_t<_Iter> __n) const + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr counted_iterator operator+(iter_difference_t<_Iter> __n) const requires random_access_iterator<_Iter> { return counted_iterator(__current_ + __n, __count_ - __n); } - _LIBCPP_HIDE_FROM_ABI friend constexpr counted_iterator + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI friend constexpr counted_iterator operator+(iter_difference_t<_Iter> __n, const counted_iterator& __x) requires random_access_iterator<_Iter> { @@ -191,24 +191,24 @@ public: return *this; } - _LIBCPP_HIDE_FROM_ABI constexpr counted_iterator operator-(iter_difference_t<_Iter> __n) const + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr counted_iterator operator-(iter_difference_t<_Iter> __n) const requires random_access_iterator<_Iter> { return counted_iterator(__current_ - __n, __count_ + __n); } template _I2> - _LIBCPP_HIDE_FROM_ABI friend constexpr iter_difference_t<_I2> + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI friend constexpr iter_difference_t<_I2> operator-(const counted_iterator& __lhs, const counted_iterator<_I2>& __rhs) { return __rhs.__count_ - __lhs.__count_; } - _LIBCPP_HIDE_FROM_ABI friend constexpr iter_difference_t<_Iter> + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI friend constexpr iter_difference_t<_Iter> operator-(const counted_iterator& __lhs, default_sentinel_t) { return -__lhs.__count_; } - _LIBCPP_HIDE_FROM_ABI friend constexpr iter_difference_t<_Iter> + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI friend constexpr iter_difference_t<_Iter> operator-(default_sentinel_t, const counted_iterator& __rhs) { return __rhs.__count_; } @@ -226,7 +226,7 @@ public: return *this; } - _LIBCPP_HIDE_FROM_ABI constexpr decltype(auto) operator[](iter_difference_t<_Iter> __n) const + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr decltype(auto) operator[](iter_difference_t<_Iter> __n) const requires random_access_iterator<_Iter> { _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__n < __count_, "Subscript argument must be less than size."); @@ -249,7 +249,7 @@ public: return __rhs.__count_ <=> __lhs.__count_; } - _LIBCPP_HIDE_FROM_ABI friend constexpr decltype(auto) + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI friend constexpr decltype(auto) iter_move(const counted_iterator& __i) noexcept(noexcept(ranges::iter_move(__i.__current_))) requires input_iterator<_Iter> { diff --git a/lib/libcxx/include/__iterator/data.h b/lib/libcxx/include/__iterator/data.h index 5f2624c2b819ed08a70e0ddae61ed8b64cf56958..7efa57e1a22a772ae69334ec6c9547e507c82bfa 100644 --- a/lib/libcxx/include/__iterator/data.h +++ b/lib/libcxx/include/__iterator/data.h @@ -17,32 +17,34 @@ # pragma GCC system_header #endif -_LIBCPP_BEGIN_NAMESPACE_STD - #if _LIBCPP_STD_VER >= 17 +_LIBCPP_BEGIN_NAMESPACE_STD + template -constexpr _LIBCPP_HIDE_FROM_ABI auto data(_Cont& __c) noexcept(noexcept(__c.data())) -> decltype(__c.data()) { +[[nodiscard]] constexpr _LIBCPP_HIDE_FROM_ABI auto data(_Cont& __c) noexcept(noexcept(__c.data())) + -> decltype(__c.data()) { return __c.data(); } template -constexpr _LIBCPP_HIDE_FROM_ABI auto data(const _Cont& __c) noexcept(noexcept(__c.data())) -> decltype(__c.data()) { +[[nodiscard]] constexpr _LIBCPP_HIDE_FROM_ABI auto data(const _Cont& __c) noexcept(noexcept(__c.data())) + -> decltype(__c.data()) { return __c.data(); } template -_LIBCPP_HIDE_FROM_ABI constexpr _Tp* data(_Tp (&__array)[_Sz]) noexcept { +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Tp* data(_Tp (&__array)[_Sz]) noexcept { return __array; } template -_LIBCPP_HIDE_FROM_ABI constexpr const _Ep* data(initializer_list<_Ep> __il) noexcept { +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr const _Ep* data(initializer_list<_Ep> __il) noexcept { return __il.begin(); } -#endif - _LIBCPP_END_NAMESPACE_STD +#endif // _LIBCPP_STD_VER >= 17 + #endif // _LIBCPP___ITERATOR_DATA_H diff --git a/lib/libcxx/include/__iterator/default_sentinel.h b/lib/libcxx/include/__iterator/default_sentinel.h index 3b65f442f1a85ba5f8b68402ff8a694aa1ca797a..84fcf71c0767dd0dfe158f518d59a6e43920d587 100644 --- a/lib/libcxx/include/__iterator/default_sentinel.h +++ b/lib/libcxx/include/__iterator/default_sentinel.h @@ -16,15 +16,15 @@ # pragma GCC system_header #endif -_LIBCPP_BEGIN_NAMESPACE_STD - #if _LIBCPP_STD_VER >= 20 +_LIBCPP_BEGIN_NAMESPACE_STD + struct default_sentinel_t {}; inline constexpr default_sentinel_t default_sentinel{}; -#endif // _LIBCPP_STD_VER >= 20 - _LIBCPP_END_NAMESPACE_STD +#endif // _LIBCPP_STD_VER >= 20 + #endif // _LIBCPP___ITERATOR_DEFAULT_SENTINEL_H diff --git a/lib/libcxx/include/__iterator/distance.h b/lib/libcxx/include/__iterator/distance.h index 1a9fbf27f776b4830dd0b51b992a60cde21a9012..c7c4ff22d6e9fb8eb95d1eb30bbf21b6ef1d0aa7 100644 --- a/lib/libcxx/include/__iterator/distance.h +++ b/lib/libcxx/include/__iterator/distance.h @@ -67,7 +67,8 @@ __distance(_InputIter __first, _Sent __last) { } template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 typename iterator_traits<_InputIter>::difference_type +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 +typename iterator_traits<_InputIter>::difference_type distance(_InputIter __first, _InputIter __last) { return std::__distance(__first, __last); } @@ -80,12 +81,12 @@ namespace ranges { struct __distance { template _Sp> requires(!sized_sentinel_for<_Sp, _Ip>) - _LIBCPP_HIDE_FROM_ABI constexpr iter_difference_t<_Ip> operator()(_Ip __first, _Sp __last) const { + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr iter_difference_t<_Ip> operator()(_Ip __first, _Sp __last) const { return std::__distance(std::move(__first), std::move(__last)); } template > _Sp> - _LIBCPP_HIDE_FROM_ABI constexpr iter_difference_t<_Ip> operator()(_Ip&& __first, _Sp __last) const { + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr iter_difference_t<_Ip> operator()(_Ip&& __first, _Sp __last) const { if constexpr (sized_sentinel_for<_Sp, __remove_cvref_t<_Ip>>) { return __last - __first; } else { @@ -94,7 +95,7 @@ struct __distance { } template - _LIBCPP_HIDE_FROM_ABI constexpr range_difference_t<_Rp> operator()(_Rp&& __r) const { + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr range_difference_t<_Rp> operator()(_Rp&& __r) const { if constexpr (sized_range<_Rp>) { return static_cast>(ranges::size(__r)); } else { diff --git a/lib/libcxx/include/__iterator/empty.h b/lib/libcxx/include/__iterator/empty.h index f2c653bcb329bab56ca2506a879a68d1304b54a6..b763048f547e5a2984e05756c9d0edd4e151bac5 100644 --- a/lib/libcxx/include/__iterator/empty.h +++ b/lib/libcxx/include/__iterator/empty.h @@ -17,10 +17,10 @@ # pragma GCC system_header #endif -_LIBCPP_BEGIN_NAMESPACE_STD - #if _LIBCPP_STD_VER >= 17 +_LIBCPP_BEGIN_NAMESPACE_STD + template [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto empty(const _Cont& __c) noexcept(noexcept(__c.empty())) -> decltype(__c.empty()) { @@ -37,8 +37,8 @@ template return __il.size() == 0; } -#endif // _LIBCPP_STD_VER >= 17 - _LIBCPP_END_NAMESPACE_STD +#endif // _LIBCPP_STD_VER >= 17 + #endif // _LIBCPP___ITERATOR_EMPTY_H diff --git a/lib/libcxx/include/__iterator/erase_if_container.h b/lib/libcxx/include/__iterator/erase_if_container.h index 0f87f50cd1c160486adeff4c2a6085a90e84a650..8d92d3f1b9dbe2ac0fcea3760ff1d0909ffe4c7e 100644 --- a/lib/libcxx/include/__iterator/erase_if_container.h +++ b/lib/libcxx/include/__iterator/erase_if_container.h @@ -22,7 +22,8 @@ _LIBCPP_PUSH_MACROS _LIBCPP_BEGIN_NAMESPACE_STD template -_LIBCPP_HIDE_FROM_ABI typename _Container::size_type __libcpp_erase_if_container(_Container& __c, _Predicate& __pred) { +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 typename _Container::size_type +__libcpp_erase_if_container(_Container& __c, _Predicate& __pred) { typename _Container::size_type __old_size = __c.size(); const typename _Container::iterator __last = __c.end(); diff --git a/lib/libcxx/include/__iterator/front_insert_iterator.h b/lib/libcxx/include/__iterator/front_insert_iterator.h index 2ab5383a1d91aaa576fbabf242a3a790b6b2f0ce..477f1c711256bb05a3932dac4a90af651c8842f7 100644 --- a/lib/libcxx/include/__iterator/front_insert_iterator.h +++ b/lib/libcxx/include/__iterator/front_insert_iterator.h @@ -58,14 +58,16 @@ public: return *this; } #endif // _LIBCPP_CXX03_LANG - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 front_insert_iterator& operator*() { return *this; } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 front_insert_iterator& operator*() { + return *this; + } _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 front_insert_iterator& operator++() { return *this; } _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 front_insert_iterator operator++(int) { return *this; } }; _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(front_insert_iterator); template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 front_insert_iterator<_Container> +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 front_insert_iterator<_Container> front_inserter(_Container& __x) { return front_insert_iterator<_Container>(__x); } diff --git a/lib/libcxx/include/__iterator/incrementable_traits.h b/lib/libcxx/include/__iterator/incrementable_traits.h index 37c8daddf8a861c26cca5d12b8679fb15b3285c0..692ce76285f6c1696c61901006743f714ef76067 100644 --- a/lib/libcxx/include/__iterator/incrementable_traits.h +++ b/lib/libcxx/include/__iterator/incrementable_traits.h @@ -11,11 +11,11 @@ #define _LIBCPP___ITERATOR_INCREMENTABLE_TRAITS_H #include <__concepts/arithmetic.h> +#include <__concepts/primary_template.h> #include <__config> #include <__cstddef/ptrdiff_t.h> #include <__type_traits/conditional.h> #include <__type_traits/is_object.h> -#include <__type_traits/is_primary_template.h> #include <__type_traits/make_signed.h> #include <__type_traits/remove_cvref.h> #include <__utility/declval.h> @@ -24,10 +24,10 @@ # pragma GCC system_header #endif -_LIBCPP_BEGIN_NAMESPACE_STD - #if _LIBCPP_STD_VER >= 20 +_LIBCPP_BEGIN_NAMESPACE_STD + // [incrementable.traits] template struct incrementable_traits {}; @@ -68,12 +68,12 @@ struct iterator_traits; // generated from the primary template, and `iterator_traits::difference_type` otherwise. template using iter_difference_t = - typename conditional_t<__is_primary_template > >::value, + typename conditional_t<__primary_template > >, incrementable_traits >, iterator_traits > >::difference_type; -#endif // _LIBCPP_STD_VER >= 20 - _LIBCPP_END_NAMESPACE_STD +#endif // _LIBCPP_STD_VER >= 20 + #endif // _LIBCPP___ITERATOR_INCREMENTABLE_TRAITS_H diff --git a/lib/libcxx/include/__iterator/insert_iterator.h b/lib/libcxx/include/__iterator/insert_iterator.h index 6a5818b478771c9fc27e703faafbe7b518446398..f70fe570722a0cf7be2937df4da7e06d988c8f5f 100644 --- a/lib/libcxx/include/__iterator/insert_iterator.h +++ b/lib/libcxx/include/__iterator/insert_iterator.h @@ -71,13 +71,13 @@ public: return *this; } #endif // _LIBCPP_CXX03_LANG - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 insert_iterator& operator*() { return *this; } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 insert_iterator& operator*() { return *this; } _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 insert_iterator& operator++() { return *this; } _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 insert_iterator& operator++(int) { return *this; } }; template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 insert_iterator<_Container> +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 insert_iterator<_Container> inserter(_Container& __x, __insert_iterator_iter_t<_Container> __i) { return insert_iterator<_Container>(__x, __i); } diff --git a/lib/libcxx/include/__iterator/istream_iterator.h b/lib/libcxx/include/__iterator/istream_iterator.h index f4b13f09c7e2dbaa2eb0c504dc9834a9708f54b5..0b759eebfb00b39260826f648e928f7c653d1e82 100644 --- a/lib/libcxx/include/__iterator/istream_iterator.h +++ b/lib/libcxx/include/__iterator/istream_iterator.h @@ -60,7 +60,7 @@ public: // LWG3600 Changed the wording of the copy constructor. In libc++ this constructor // can still be trivial after this change. - _LIBCPP_HIDE_FROM_ABI const _Tp& operator*() const { return __value_; } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI const _Tp& operator*() const { return __value_; } _LIBCPP_HIDE_FROM_ABI const _Tp* operator->() const { return std::addressof((operator*())); } _LIBCPP_HIDE_FROM_ABI istream_iterator& operator++() { if (!(*__in_stream_ >> __value_)) diff --git a/lib/libcxx/include/__iterator/istreambuf_iterator.h b/lib/libcxx/include/__iterator/istreambuf_iterator.h index 4fc87a84f0192b06774093bbeba0b0dcd4d7eec7..c554a05f6717c85a0551077da1bd22a9e9255c19 100644 --- a/lib/libcxx/include/__iterator/istreambuf_iterator.h +++ b/lib/libcxx/include/__iterator/istreambuf_iterator.h @@ -73,14 +73,16 @@ public: _LIBCPP_HIDE_FROM_ABI istreambuf_iterator(streambuf_type* __s) _NOEXCEPT : __sbuf_(__s) {} _LIBCPP_HIDE_FROM_ABI istreambuf_iterator(const __proxy& __p) _NOEXCEPT : __sbuf_(__p.__sbuf_) {} - _LIBCPP_HIDE_FROM_ABI char_type operator*() const { return static_cast(__sbuf_->sgetc()); } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI char_type operator*() const { + return static_cast(__sbuf_->sgetc()); + } _LIBCPP_HIDE_FROM_ABI istreambuf_iterator& operator++() { __sbuf_->sbumpc(); return *this; } _LIBCPP_HIDE_FROM_ABI __proxy operator++(int) { return __proxy(__sbuf_->sbumpc(), __sbuf_); } - _LIBCPP_HIDE_FROM_ABI bool equal(const istreambuf_iterator& __b) const { + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI bool equal(const istreambuf_iterator& __b) const { return __test_for_eof() == __b.__test_for_eof(); } diff --git a/lib/libcxx/include/__iterator/iter_move.h b/lib/libcxx/include/__iterator/iter_move.h index a726b6e329e9065b9541ee66971f8655e3bb824f..b371f09fe111fe09bdf3a23d2223dc38b9d5b909 100644 --- a/lib/libcxx/include/__iterator/iter_move.h +++ b/lib/libcxx/include/__iterator/iter_move.h @@ -11,10 +11,10 @@ #define _LIBCPP___ITERATOR_ITER_MOVE_H #include <__concepts/class_or_enum.h> +#include <__concepts/referenceable.h> #include <__config> #include <__iterator/iterator_traits.h> #include <__type_traits/is_reference.h> -#include <__type_traits/is_referenceable.h> #include <__type_traits/remove_cvref.h> #include <__utility/declval.h> #include <__utility/forward.h> @@ -27,10 +27,10 @@ _LIBCPP_PUSH_MACROS #include <__undef_macros> -_LIBCPP_BEGIN_NAMESPACE_STD - #if _LIBCPP_STD_VER >= 20 +_LIBCPP_BEGIN_NAMESPACE_STD + // [iterator.cust.move] namespace ranges { @@ -95,10 +95,10 @@ template <__dereferenceable _Tp> } using iter_rvalue_reference_t = decltype(ranges::iter_move(std::declval<_Tp&>())); -#endif // _LIBCPP_STD_VER >= 20 - _LIBCPP_END_NAMESPACE_STD +#endif // _LIBCPP_STD_VER >= 20 + _LIBCPP_POP_MACROS #endif // _LIBCPP___ITERATOR_ITER_MOVE_H diff --git a/lib/libcxx/include/__iterator/iter_swap.h b/lib/libcxx/include/__iterator/iter_swap.h index 01ab1b97d6501f85893a59da1a171ff689b0a8ee..f4a5744a7eddbed0b451f888d7ffd1742b6e0da1 100644 --- a/lib/libcxx/include/__iterator/iter_swap.h +++ b/lib/libcxx/include/__iterator/iter_swap.h @@ -29,10 +29,10 @@ _LIBCPP_PUSH_MACROS #include <__undef_macros> -_LIBCPP_BEGIN_NAMESPACE_STD - #if _LIBCPP_STD_VER >= 20 +_LIBCPP_BEGIN_NAMESPACE_STD + // [iter.cust.swap] namespace ranges { @@ -99,10 +99,10 @@ concept indirectly_swappable = ranges::iter_swap(__i2, __i1); }; -#endif // _LIBCPP_STD_VER >= 20 - _LIBCPP_END_NAMESPACE_STD +#endif // _LIBCPP_STD_VER >= 20 + _LIBCPP_POP_MACROS #endif // _LIBCPP___ITERATOR_ITER_SWAP_H diff --git a/lib/libcxx/include/__iterator/iterator_traits.h b/lib/libcxx/include/__iterator/iterator_traits.h index ebf315a53b6b7d02fe2b0890671ea15bf24e6939..4327317b23d463ae87803e0be382e25a5f7e13d6 100644 --- a/lib/libcxx/include/__iterator/iterator_traits.h +++ b/lib/libcxx/include/__iterator/iterator_traits.h @@ -15,6 +15,8 @@ #include <__concepts/convertible_to.h> #include <__concepts/copyable.h> #include <__concepts/equality_comparable.h> +#include <__concepts/primary_template.h> +#include <__concepts/referenceable.h> #include <__concepts/same_as.h> #include <__concepts/totally_ordered.h> #include <__config> @@ -30,9 +32,7 @@ #include <__type_traits/integral_constant.h> #include <__type_traits/is_convertible.h> #include <__type_traits/is_object.h> -#include <__type_traits/is_primary_template.h> #include <__type_traits/is_reference.h> -#include <__type_traits/is_referenceable.h> #include <__type_traits/nat.h> #include <__type_traits/remove_const.h> #include <__type_traits/remove_cv.h> @@ -468,7 +468,7 @@ using __iterator_reference _LIBCPP_NODEBUG = typename iterator_traits<_Iter>::re // This has to be in this file and not readable_traits.h to break the include cycle between the two. template using iter_value_t = - typename conditional_t<__is_primary_template > >::value, + typename conditional_t<__primary_template > >, indirectly_readable_traits >, iterator_traits > >::value_type; diff --git a/lib/libcxx/include/__iterator/move_iterator.h b/lib/libcxx/include/__iterator/move_iterator.h index 2b64680a3474a034c411a5ac4d7344d4de480b07..aa5570c018737e37a44d4ef8da307b42f4767c73 100644 --- a/lib/libcxx/include/__iterator/move_iterator.h +++ b/lib/libcxx/include/__iterator/move_iterator.h @@ -13,6 +13,7 @@ #include <__compare/compare_three_way_result.h> #include <__compare/three_way_comparable.h> #include <__concepts/assignable.h> +#include <__concepts/constructible.h> #include <__concepts/convertible_to.h> #include <__concepts/derived_from.h> #include <__concepts/same_as.h> @@ -27,7 +28,6 @@ #include <__type_traits/conditional.h> #include <__type_traits/enable_if.h> #include <__type_traits/is_assignable.h> -#include <__type_traits/is_constructible.h> #include <__type_traits/is_convertible.h> #include <__type_traits/is_reference.h> #include <__type_traits/is_same.h> @@ -122,7 +122,7 @@ public: #if _LIBCPP_STD_VER >= 20 _LIBCPP_HIDE_FROM_ABI constexpr move_iterator() - requires is_constructible_v<_Iter> + requires default_initializable<_Iter> : __current_() {} template @@ -136,11 +136,11 @@ public: return *this; } - _LIBCPP_HIDE_FROM_ABI constexpr const _Iter& base() const& noexcept { return __current_; } - _LIBCPP_HIDE_FROM_ABI constexpr _Iter base() && { return std::move(__current_); } + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr const _Iter& base() const& noexcept { return __current_; } + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Iter base() && { return std::move(__current_); } - _LIBCPP_HIDE_FROM_ABI constexpr reference operator*() const { return ranges::iter_move(__current_); } - _LIBCPP_HIDE_FROM_ABI constexpr reference operator[](difference_type __n) const { + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr reference operator*() const { return ranges::iter_move(__current_); } + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr reference operator[](difference_type __n) const { return ranges::iter_move(__current_ + __n); } @@ -169,12 +169,13 @@ public: return *this; } - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 _Iter base() const { return __current_; } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 _Iter base() const { return __current_; } - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 reference operator*() const { + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 reference operator*() const { return static_cast(*__current_); } - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 reference operator[](difference_type __n) const { + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 reference + operator[](difference_type __n) const { return static_cast(__current_[__n]); } @@ -194,14 +195,16 @@ public: --__current_; return __tmp; } - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 move_iterator operator+(difference_type __n) const { + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 move_iterator + operator+(difference_type __n) const { return move_iterator(__current_ + __n); } _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 move_iterator& operator+=(difference_type __n) { __current_ += __n; return *this; } - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 move_iterator operator-(difference_type __n) const { + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 move_iterator + operator-(difference_type __n) const { return move_iterator(__current_ - __n); } _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 move_iterator& operator-=(difference_type __n) { @@ -218,18 +221,18 @@ public: } template _Sent> - friend _LIBCPP_HIDE_FROM_ABI constexpr iter_difference_t<_Iter> + [[nodiscard]] friend _LIBCPP_HIDE_FROM_ABI constexpr iter_difference_t<_Iter> operator-(const move_sentinel<_Sent>& __x, const move_iterator& __y) { return __x.base() - __y.base(); } template _Sent> - friend _LIBCPP_HIDE_FROM_ABI constexpr iter_difference_t<_Iter> + [[nodiscard]] friend _LIBCPP_HIDE_FROM_ABI constexpr iter_difference_t<_Iter> operator-(const move_iterator& __x, const move_sentinel<_Sent>& __y) { return __x.base() - __y.base(); } - friend _LIBCPP_HIDE_FROM_ABI constexpr iter_rvalue_reference_t<_Iter> + [[nodiscard]] friend _LIBCPP_HIDE_FROM_ABI constexpr iter_rvalue_reference_t<_Iter> iter_move(const move_iterator& __i) noexcept(noexcept(ranges::iter_move(__i.__current_))) { return ranges::iter_move(__i.__current_); } @@ -299,13 +302,14 @@ operator<=>(const move_iterator<_Iter1>& __x, #ifndef _LIBCPP_CXX03_LANG template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 auto -operator-(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y) -> decltype(__x.base() - __y.base()) { +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI +_LIBCPP_CONSTEXPR_SINCE_CXX17 auto operator-(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y) + -> decltype(__x.base() - __y.base()) { return __x.base() - __y.base(); } #else template -inline _LIBCPP_HIDE_FROM_ABI typename move_iterator<_Iter1>::difference_type +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI typename move_iterator<_Iter1>::difference_type operator-(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y) { return __x.base() - __y.base(); } @@ -313,7 +317,7 @@ operator-(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y) { #if _LIBCPP_STD_VER >= 20 template -inline _LIBCPP_HIDE_FROM_ABI constexpr move_iterator<_Iter> +[[nodiscard]] inline _LIBCPP_HIDE_FROM_ABI constexpr move_iterator<_Iter> operator+(iter_difference_t<_Iter> __n, const move_iterator<_Iter>& __x) requires requires { { __x.base() + __n } -> same_as<_Iter>; @@ -323,7 +327,7 @@ operator+(iter_difference_t<_Iter> __n, const move_iterator<_Iter>& __x) } #else template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 move_iterator<_Iter> +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 move_iterator<_Iter> operator+(typename move_iterator<_Iter>::difference_type __n, const move_iterator<_Iter>& __x) { return move_iterator<_Iter>(__x.base() + __n); } @@ -336,7 +340,8 @@ inline constexpr bool disable_sized_sentinel_for, move_ite #endif // _LIBCPP_STD_VER >= 20 template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 move_iterator<_Iter> make_move_iterator(_Iter __i) { +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI +_LIBCPP_CONSTEXPR_SINCE_CXX17 move_iterator<_Iter> make_move_iterator(_Iter __i) { return move_iterator<_Iter>(std::move(__i)); } diff --git a/lib/libcxx/include/__iterator/move_sentinel.h b/lib/libcxx/include/__iterator/move_sentinel.h index c77ca5f1a9142f982bb62f02fb5358ae9c5d04a1..876b2b24507c7c2a33008aa0c6a28d395ef485fc 100644 --- a/lib/libcxx/include/__iterator/move_sentinel.h +++ b/lib/libcxx/include/__iterator/move_sentinel.h @@ -22,10 +22,10 @@ _LIBCPP_PUSH_MACROS #include <__undef_macros> -_LIBCPP_BEGIN_NAMESPACE_STD - #if _LIBCPP_STD_VER >= 20 +_LIBCPP_BEGIN_NAMESPACE_STD + template class move_sentinel { public: @@ -44,7 +44,7 @@ public: return *this; } - _LIBCPP_HIDE_FROM_ABI constexpr _Sent base() const { return __last_; } + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Sent base() const { return __last_; } private: _Sent __last_ = _Sent(); @@ -52,10 +52,10 @@ private: _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(move_sentinel); -#endif // _LIBCPP_STD_VER >= 20 - _LIBCPP_END_NAMESPACE_STD +#endif // _LIBCPP_STD_VER >= 20 + _LIBCPP_POP_MACROS #endif // _LIBCPP___ITERATOR_MOVE_SENTINEL_H diff --git a/lib/libcxx/include/__iterator/ostream_iterator.h b/lib/libcxx/include/__iterator/ostream_iterator.h index 64e79f010f64afcdde98f4e318066984c5054f28..ba47fce95e84591e9792bd0af98b18f2e4d49246 100644 --- a/lib/libcxx/include/__iterator/ostream_iterator.h +++ b/lib/libcxx/include/__iterator/ostream_iterator.h @@ -59,7 +59,7 @@ public: return *this; } - _LIBCPP_HIDE_FROM_ABI ostream_iterator& operator*() { return *this; } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI ostream_iterator& operator*() { return *this; } _LIBCPP_HIDE_FROM_ABI ostream_iterator& operator++() { return *this; } _LIBCPP_HIDE_FROM_ABI ostream_iterator& operator++(int) { return *this; } }; diff --git a/lib/libcxx/include/__iterator/ostreambuf_iterator.h b/lib/libcxx/include/__iterator/ostreambuf_iterator.h index 4a3b2fa0244909af24e89bd20e8fbfbb5088649c..a23f0b1f65f937d0464c90481b8ef4436496f24a 100644 --- a/lib/libcxx/include/__iterator/ostreambuf_iterator.h +++ b/lib/libcxx/include/__iterator/ostreambuf_iterator.h @@ -10,6 +10,8 @@ #ifndef _LIBCPP___ITERATOR_OSTREAMBUF_ITERATOR_H #define _LIBCPP___ITERATOR_OSTREAMBUF_ITERATOR_H +#include <__algorithm/in_out_result.h> +#include <__algorithm/specialized_algorithms.h> #include <__config> #include <__cstddef/ptrdiff_t.h> #include <__fwd/ios.h> @@ -17,6 +19,7 @@ #include <__fwd/streambuf.h> #include <__iterator/iterator.h> #include <__iterator/iterator_traits.h> +#include <__type_traits/is_same.h> #include // for forward declaration of ostreambuf_iterator #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) @@ -54,16 +57,36 @@ public: __sbuf_ = nullptr; return *this; } - _LIBCPP_HIDE_FROM_ABI ostreambuf_iterator& operator*() { return *this; } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI ostreambuf_iterator& operator*() { return *this; } _LIBCPP_HIDE_FROM_ABI ostreambuf_iterator& operator++() { return *this; } _LIBCPP_HIDE_FROM_ABI ostreambuf_iterator& operator++(int) { return *this; } - _LIBCPP_HIDE_FROM_ABI bool failed() const _NOEXCEPT { return __sbuf_ == nullptr; } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI bool failed() const _NOEXCEPT { return __sbuf_ == nullptr; } #if _LIBCPP_HAS_LOCALIZATION template friend _LIBCPP_HIDE_FROM_ABI ostreambuf_iterator<_Ch, _Tr> __pad_and_output( ostreambuf_iterator<_Ch, _Tr> __s, const _Ch* __ob, const _Ch* __op, const _Ch* __oe, ios_base& __iob, _Ch __fl); #endif // _LIBCPP_HAS_LOCALIZATION + + template + friend struct __specialized_algorithm; +}; + +template +struct __specialized_algorithm<_Algorithm::__copy, + __iterator_pair<_InCharT*, _InCharT*>, + __single_iterator > > { + static const bool __has_algorithm = is_same::value; + + _LIBCPP_HIDE_FROM_ABI static __in_out_result<_InCharT*, ostreambuf_iterator<_CharT, _Traits> > + operator()(_InCharT* __first, _InCharT* __last, ostreambuf_iterator<_CharT, _Traits> __result) { + auto __size = __last - __first; + if (__result.__sbuf_ && __size > 0) { + if (__result.__sbuf_->sputn(__first, __last - __first) != __size) + __result.__sbuf_ = nullptr; + } + return {__last, __result}; + } }; _LIBCPP_END_NAMESPACE_STD diff --git a/lib/libcxx/include/__iterator/ranges_iterator_traits.h b/lib/libcxx/include/__iterator/ranges_iterator_traits.h index 9a31b651eb5da0447a5ab100d6775a1940306d55..b92f45f7a8757e51a682edad8d7f09811d7152a3 100644 --- a/lib/libcxx/include/__iterator/ranges_iterator_traits.h +++ b/lib/libcxx/include/__iterator/ranges_iterator_traits.h @@ -19,10 +19,10 @@ # pragma GCC system_header #endif -_LIBCPP_BEGIN_NAMESPACE_STD - #if _LIBCPP_STD_VER >= 23 +_LIBCPP_BEGIN_NAMESPACE_STD + template using __range_key_type _LIBCPP_NODEBUG = __remove_const_t::first_type>; @@ -33,8 +33,8 @@ template using __range_to_alloc_type _LIBCPP_NODEBUG = pair::first_type, typename ranges::range_value_t<_Range>::second_type>; -#endif - _LIBCPP_END_NAMESPACE_STD +#endif + #endif // _LIBCPP___ITERATOR_RANGES_ITERATOR_TRAITS_H diff --git a/lib/libcxx/include/__iterator/readable_traits.h b/lib/libcxx/include/__iterator/readable_traits.h index 25e74567fff11dd93782468170c84a3a24c18452..ed169c46351bc22c7c3b5c03596be5737766aa2e 100644 --- a/lib/libcxx/include/__iterator/readable_traits.h +++ b/lib/libcxx/include/__iterator/readable_traits.h @@ -10,12 +10,12 @@ #ifndef _LIBCPP___ITERATOR_READABLE_TRAITS_H #define _LIBCPP___ITERATOR_READABLE_TRAITS_H +#include <__concepts/primary_template.h> #include <__concepts/same_as.h> #include <__config> #include <__type_traits/conditional.h> #include <__type_traits/is_array.h> #include <__type_traits/is_object.h> -#include <__type_traits/is_primary_template.h> #include <__type_traits/remove_cv.h> #include <__type_traits/remove_cvref.h> #include <__type_traits/remove_extent.h> @@ -24,10 +24,10 @@ # pragma GCC system_header #endif -_LIBCPP_BEGIN_NAMESPACE_STD - #if _LIBCPP_STD_VER >= 20 +_LIBCPP_BEGIN_NAMESPACE_STD + // [readable.traits] template struct __cond_value_type {}; @@ -74,8 +74,8 @@ template <__has_member_value_type _Tp> same_as, remove_cv_t> struct indirectly_readable_traits<_Tp> : __cond_value_type {}; -#endif // _LIBCPP_STD_VER >= 20 - _LIBCPP_END_NAMESPACE_STD +#endif // _LIBCPP_STD_VER >= 20 + #endif // _LIBCPP___ITERATOR_READABLE_TRAITS_H diff --git a/lib/libcxx/include/__iterator/reverse_access.h b/lib/libcxx/include/__iterator/reverse_access.h index f6e60c3fb75b3484a9ec2e8aa69f6a1c368568ed..b1574bc66511956d4187174aeb300f3181a1748c 100644 --- a/lib/libcxx/include/__iterator/reverse_access.h +++ b/lib/libcxx/include/__iterator/reverse_access.h @@ -18,62 +18,69 @@ # pragma GCC system_header #endif -_LIBCPP_BEGIN_NAMESPACE_STD - #if _LIBCPP_STD_VER >= 14 +_LIBCPP_BEGIN_NAMESPACE_STD + template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 reverse_iterator<_Tp*> rbegin(_Tp (&__array)[_Np]) { +[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI +_LIBCPP_CONSTEXPR_SINCE_CXX17 reverse_iterator<_Tp*> rbegin(_Tp (&__array)[_Np]) { return reverse_iterator<_Tp*>(__array + _Np); } template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 reverse_iterator<_Tp*> rend(_Tp (&__array)[_Np]) { +[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 reverse_iterator<_Tp*> rend(_Tp (&__array)[_Np]) { return reverse_iterator<_Tp*>(__array); } template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 reverse_iterator rbegin(initializer_list<_Ep> __il) { +[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 reverse_iterator +rbegin(initializer_list<_Ep> __il) { return reverse_iterator(__il.end()); } template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 reverse_iterator rend(initializer_list<_Ep> __il) { +[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 reverse_iterator +rend(initializer_list<_Ep> __il) { return reverse_iterator(__il.begin()); } template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 auto rbegin(_Cp& __c) -> decltype(__c.rbegin()) { +[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 auto rbegin(_Cp& __c) -> decltype(__c.rbegin()) { return __c.rbegin(); } template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 auto rbegin(const _Cp& __c) -> decltype(__c.rbegin()) { +[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 auto rbegin(const _Cp& __c) + -> decltype(__c.rbegin()) { return __c.rbegin(); } template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 auto rend(_Cp& __c) -> decltype(__c.rend()) { +[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 auto rend(_Cp& __c) -> decltype(__c.rend()) { return __c.rend(); } template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 auto rend(const _Cp& __c) -> decltype(__c.rend()) { +[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 auto rend(const _Cp& __c) + -> decltype(__c.rend()) { return __c.rend(); } template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 auto crbegin(const _Cp& __c) -> decltype(std::rbegin(__c)) { +[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 auto crbegin(const _Cp& __c) + -> decltype(std::rbegin(__c)) { return std::rbegin(__c); } template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 auto crend(const _Cp& __c) -> decltype(std::rend(__c)) { +[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 auto crend(const _Cp& __c) + -> decltype(std::rend(__c)) { return std::rend(__c); } -#endif // _LIBCPP_STD_VER >= 14 - _LIBCPP_END_NAMESPACE_STD +#endif // _LIBCPP_STD_VER >= 14 + #endif // _LIBCPP___ITERATOR_REVERSE_ACCESS_H diff --git a/lib/libcxx/include/__iterator/reverse_iterator.h b/lib/libcxx/include/__iterator/reverse_iterator.h index 834695dd16703879a2c010b5f6ce3fef06c1db7d..64bdaf9ae58961a5f25443ddb790e52aeb642323 100644 --- a/lib/libcxx/include/__iterator/reverse_iterator.h +++ b/lib/libcxx/include/__iterator/reverse_iterator.h @@ -15,21 +15,13 @@ #include <__compare/three_way_comparable.h> #include <__concepts/convertible_to.h> #include <__config> -#include <__iterator/advance.h> #include <__iterator/concepts.h> #include <__iterator/incrementable_traits.h> #include <__iterator/iter_move.h> #include <__iterator/iter_swap.h> #include <__iterator/iterator.h> #include <__iterator/iterator_traits.h> -#include <__iterator/next.h> -#include <__iterator/prev.h> -#include <__iterator/readable_traits.h> -#include <__iterator/segmented_iterator.h> #include <__memory/addressof.h> -#include <__ranges/access.h> -#include <__ranges/concepts.h> -#include <__ranges/subrange.h> #include <__type_traits/conditional.h> #include <__type_traits/enable_if.h> #include <__type_traits/is_assignable.h> @@ -38,7 +30,6 @@ #include <__type_traits/is_pointer.h> #include <__type_traits/is_same.h> #include <__utility/declval.h> -#include <__utility/move.h> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header @@ -121,8 +112,8 @@ public: return *this; } #endif - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 _Iter base() const { return current; } - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 reference operator*() const { + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 _Iter base() const { return current; } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 reference operator*() const { _Iter __tmp = current; return *--__tmp; } @@ -161,25 +152,29 @@ public: ++current; return __tmp; } - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 reverse_iterator operator+(difference_type __n) const { + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 reverse_iterator + operator+(difference_type __n) const { return reverse_iterator(current - __n); } _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 reverse_iterator& operator+=(difference_type __n) { current -= __n; return *this; } - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 reverse_iterator operator-(difference_type __n) const { + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 reverse_iterator + operator-(difference_type __n) const { return reverse_iterator(current + __n); } _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 reverse_iterator& operator-=(difference_type __n) { current += __n; return *this; } - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 reference operator[](difference_type __n) const { + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 reference + operator[](difference_type __n) const { return *(*this + __n); } #if _LIBCPP_STD_VER >= 20 + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI friend constexpr iter_rvalue_reference_t<_Iter> iter_move(const reverse_iterator& __i) noexcept( is_nothrow_copy_constructible_v<_Iter> && noexcept(ranges::iter_move(--std::declval<_Iter&>()))) { auto __tmp = __i.base(); @@ -280,21 +275,21 @@ operator<=>(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& #ifndef _LIBCPP_CXX03_LANG template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 auto -operator-(const reverse_iterator<_Iter1>& __x, - const reverse_iterator<_Iter2>& __y) -> decltype(__y.base() - __x.base()) { +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI +_LIBCPP_CONSTEXPR_SINCE_CXX17 auto operator-(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y) + -> decltype(__y.base() - __x.base()) { return __y.base() - __x.base(); } #else template -inline _LIBCPP_HIDE_FROM_ABI typename reverse_iterator<_Iter1>::difference_type +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI typename reverse_iterator<_Iter1>::difference_type operator-(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y) { return __y.base() - __x.base(); } #endif template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 reverse_iterator<_Iter> +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 reverse_iterator<_Iter> operator+(typename reverse_iterator<_Iter>::difference_type __n, const reverse_iterator<_Iter>& __x) { return reverse_iterator<_Iter>(__x.base() - __n); } @@ -307,21 +302,12 @@ inline constexpr bool disable_sized_sentinel_for, rever #if _LIBCPP_STD_VER >= 14 template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 reverse_iterator<_Iter> make_reverse_iterator(_Iter __i) { +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI +_LIBCPP_CONSTEXPR_SINCE_CXX17 reverse_iterator<_Iter> make_reverse_iterator(_Iter __i) { return reverse_iterator<_Iter>(__i); } #endif -#if _LIBCPP_STD_VER >= 20 -template -_LIBCPP_HIDE_FROM_ABI constexpr ranges::subrange>, - reverse_iterator>> -__reverse_range(_Range&& __range) { - auto __first = ranges::begin(__range); - return {std::make_reverse_iterator(ranges::next(__first, ranges::end(__range))), std::make_reverse_iterator(__first)}; -} -#endif - template struct __unwrap_iter_impl >, __b> { using _UnwrappedIter _LIBCPP_NODEBUG = decltype(__unwrap_iter_impl<_Iter>::__unwrap(std::declval<_Iter>())); diff --git a/lib/libcxx/include/__iterator/segmented_iterator.h b/lib/libcxx/include/__iterator/segmented_iterator.h index dc56a740130b56f94e8d93779daa2e00f5458b6a..149092f3135cc3bd0c0cf3465e7343f30eea12e2 100644 --- a/lib/libcxx/include/__iterator/segmented_iterator.h +++ b/lib/libcxx/include/__iterator/segmented_iterator.h @@ -42,8 +42,6 @@ #include <__config> #include <__cstddef/size_t.h> -#include <__iterator/iterator_traits.h> -#include <__type_traits/integral_constant.h> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header diff --git a/lib/libcxx/include/__iterator/size.h b/lib/libcxx/include/__iterator/size.h index 84e2e3b21f1d5da3776eb45c9e112fa5a3c3a1c1..eb441e25b0197c4163024b2ffcad2a3b4c7694f9 100644 --- a/lib/libcxx/include/__iterator/size.h +++ b/lib/libcxx/include/__iterator/size.h @@ -20,25 +20,26 @@ # pragma GCC system_header #endif -_LIBCPP_BEGIN_NAMESPACE_STD - #if _LIBCPP_STD_VER >= 17 +_LIBCPP_BEGIN_NAMESPACE_STD + template +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto size(const _Cont& __c) noexcept(noexcept(__c.size())) -> decltype(__c.size()) { return __c.size(); } template -_LIBCPP_HIDE_FROM_ABI constexpr size_t size(const _Tp (&)[_Sz]) noexcept { +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr size_t size(const _Tp (&)[_Sz]) noexcept { return _Sz; } # if _LIBCPP_STD_VER >= 20 template -_LIBCPP_HIDE_FROM_ABI constexpr auto -ssize(const _Cont& __c) noexcept(noexcept(static_cast>>( - __c.size()))) -> common_type_t> { +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto ssize(const _Cont& __c) noexcept( + noexcept(static_cast>>(__c.size()))) + -> common_type_t> { return static_cast>>(__c.size()); } @@ -47,14 +48,14 @@ ssize(const _Cont& __c) noexcept(noexcept(static_cast -_LIBCPP_HIDE_FROM_ABI constexpr ptrdiff_t ssize(const _Tp (&)[_Sz]) noexcept { +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr ptrdiff_t ssize(const _Tp (&)[_Sz]) noexcept { return _Sz; } _LIBCPP_DIAGNOSTIC_POP # endif -#endif // _LIBCPP_STD_VER >= 17 - _LIBCPP_END_NAMESPACE_STD +#endif // _LIBCPP_STD_VER >= 17 + #endif // _LIBCPP___ITERATOR_SIZE_H diff --git a/lib/libcxx/include/__iterator/static_bounded_iter.h b/lib/libcxx/include/__iterator/static_bounded_iter.h index d8fc7d185e7bc1d53b83fd31f8bca02585bfbe61..a048073b5a897c640927889cf3baa971e6ccbb3e 100644 --- a/lib/libcxx/include/__iterator/static_bounded_iter.h +++ b/lib/libcxx/include/__iterator/static_bounded_iter.h @@ -128,7 +128,7 @@ private: public: // Dereference and indexing operations. - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 reference operator*() const _NOEXCEPT { + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 reference operator*() const _NOEXCEPT { _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS( __current() != __end(), "__static_bounded_iter::operator*: Attempt to dereference an iterator at the end"); return *__current(); @@ -140,7 +140,8 @@ public: return std::__to_address(__current()); } - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 reference operator[](difference_type __n) const _NOEXCEPT { + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 reference + operator[](difference_type __n) const _NOEXCEPT { _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS( __n >= __begin() - __current(), "__static_bounded_iter::operator[]: Attempt to index an iterator past the start"); @@ -186,13 +187,13 @@ public: __current() += __n; return *this; } - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 friend __static_bounded_iter + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 friend __static_bounded_iter operator+(__static_bounded_iter const& __self, difference_type __n) _NOEXCEPT { __static_bounded_iter __tmp(__self); __tmp += __n; return __tmp; } - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 friend __static_bounded_iter + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 friend __static_bounded_iter operator+(difference_type __n, __static_bounded_iter const& __self) _NOEXCEPT { __static_bounded_iter __tmp(__self); __tmp += __n; @@ -208,13 +209,13 @@ public: __current() -= __n; return *this; } - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 friend __static_bounded_iter + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 friend __static_bounded_iter operator-(__static_bounded_iter const& __self, difference_type __n) _NOEXCEPT { __static_bounded_iter __tmp(__self); __tmp -= __n; return __tmp; } - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 friend difference_type + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 friend difference_type operator-(__static_bounded_iter const& __x, __static_bounded_iter const& __y) _NOEXCEPT { return __x.__current() - __y.__current(); } diff --git a/lib/libcxx/include/__iterator/wrap_iter.h b/lib/libcxx/include/__iterator/wrap_iter.h index 98745f600a6eccb9a548e22ced7efc076c80d95c..d4eccbed473f9b9caf1434f3c9fa6a728252160e 100644 --- a/lib/libcxx/include/__iterator/wrap_iter.h +++ b/lib/libcxx/include/__iterator/wrap_iter.h @@ -15,7 +15,6 @@ #include <__config> #include <__cstddef/size_t.h> #include <__iterator/iterator_traits.h> -#include <__memory/addressof.h> #include <__memory/pointer_traits.h> #include <__type_traits/conjunction.h> #include <__type_traits/disjunction.h> @@ -34,18 +33,17 @@ _LIBCPP_BEGIN_NAMESPACE_STD template class __wrap_iter { public: - typedef _Iter iterator_type; - typedef typename iterator_traits::value_type value_type; - typedef typename iterator_traits::difference_type difference_type; - typedef typename iterator_traits::pointer pointer; - typedef typename iterator_traits::reference reference; - typedef typename iterator_traits::iterator_category iterator_category; + typedef typename iterator_traits<_Iter>::value_type value_type; + typedef typename iterator_traits<_Iter>::difference_type difference_type; + typedef typename iterator_traits<_Iter>::pointer pointer; + typedef typename iterator_traits<_Iter>::reference reference; + typedef typename iterator_traits<_Iter>::iterator_category iterator_category; #if _LIBCPP_STD_VER >= 20 typedef contiguous_iterator_tag iterator_concept; #endif private: - iterator_type __i_; + _Iter __i_; public: _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 __wrap_iter() _NOEXCEPT : __i_() {} @@ -57,7 +55,9 @@ public: int> = 0> _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 __wrap_iter(const __wrap_iter<_OtherIter>& __u) _NOEXCEPT : __i_(__u.__i_) {} - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 reference operator*() const _NOEXCEPT { return *__i_; } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 reference operator*() const _NOEXCEPT { + return *__i_; + } _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pointer operator->() const _NOEXCEPT { return std::__to_address(__i_); } @@ -80,7 +80,8 @@ public: --(*this); return __tmp; } - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 __wrap_iter operator+(difference_type __n) const _NOEXCEPT { + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 __wrap_iter + operator+(difference_type __n) const _NOEXCEPT { __wrap_iter __w(*this); __w += __n; return __w; @@ -89,21 +90,21 @@ public: __i_ += __n; return *this; } - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 __wrap_iter operator-(difference_type __n) const _NOEXCEPT { + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 __wrap_iter + operator-(difference_type __n) const _NOEXCEPT { return *this + (-__n); } _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 __wrap_iter& operator-=(difference_type __n) _NOEXCEPT { *this += -__n; return *this; } - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 reference operator[](difference_type __n) const _NOEXCEPT { + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 reference + operator[](difference_type __n) const _NOEXCEPT { return __i_[__n]; } - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 iterator_type base() const _NOEXCEPT { return __i_; } - private: - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit __wrap_iter(iterator_type __x) _NOEXCEPT : __i_(__x) {} + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit __wrap_iter(_Iter __x) _NOEXCEPT : __i_(__x) {} template friend class __wrap_iter; @@ -117,137 +118,125 @@ private: friend class span; template friend struct array; - template - friend struct __optional_iterator; -}; - -template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool -operator==(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT { - return __x.base() == __y.base(); -} - -template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool -operator==(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT { - return __x.base() == __y.base(); -} - -template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool -operator<(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT { - return __x.base() < __y.base(); -} - -template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool -operator<(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT { - return __x.base() < __y.base(); -} #if _LIBCPP_STD_VER <= 17 -template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool -operator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT { - return !(__x == __y); -} - -template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool -operator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT { - return !(__x == __y); -} -template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool -operator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT { - return __y < __x; -} - -template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool -operator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT { - return __y < __x; -} - -template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool -operator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT { - return !(__x < __y); -} - -template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool -operator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT { - return !(__x < __y); -} - -template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool -operator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT { - return !(__y < __x); -} - -template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool -operator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT { - return !(__y < __x); -} + _LIBCPP_HIDE_FROM_ABI friend _LIBCPP_CONSTEXPR bool + operator==(const __wrap_iter& __x, const __wrap_iter& __y) _NOEXCEPT { + return __x.__i_ == __y.__i_; + } + + template + _LIBCPP_HIDE_FROM_ABI friend _LIBCPP_CONSTEXPR bool + operator==(const __wrap_iter& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT { + return __x.__i_ == __y.__i_; + } + + _LIBCPP_HIDE_FROM_ABI friend _LIBCPP_CONSTEXPR bool + operator<(const __wrap_iter& __x, const __wrap_iter& __y) _NOEXCEPT { + return __x.__i_ < __y.__i_; + } + + template + _LIBCPP_HIDE_FROM_ABI friend _LIBCPP_CONSTEXPR bool + operator<(const __wrap_iter& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT { + return __x.__i_ < __y.__i_; + } + + _LIBCPP_HIDE_FROM_ABI friend _LIBCPP_CONSTEXPR bool + operator!=(const __wrap_iter& __x, const __wrap_iter& __y) _NOEXCEPT { + return !(__x == __y); + } + + template + _LIBCPP_HIDE_FROM_ABI friend _LIBCPP_CONSTEXPR bool + operator!=(const __wrap_iter& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT { + return !(__x == __y); + } + + _LIBCPP_HIDE_FROM_ABI friend _LIBCPP_CONSTEXPR bool + operator>(const __wrap_iter& __x, const __wrap_iter& __y) _NOEXCEPT { + return __y < __x; + } + + template + _LIBCPP_HIDE_FROM_ABI friend _LIBCPP_CONSTEXPR bool + operator>(const __wrap_iter& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT { + return __y < __x; + } + + _LIBCPP_HIDE_FROM_ABI friend _LIBCPP_CONSTEXPR bool + operator>=(const __wrap_iter& __x, const __wrap_iter& __y) _NOEXCEPT { + return !(__x < __y); + } + + template + _LIBCPP_HIDE_FROM_ABI friend _LIBCPP_CONSTEXPR bool + operator>=(const __wrap_iter& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT { + return !(__x < __y); + } + + _LIBCPP_HIDE_FROM_ABI friend _LIBCPP_CONSTEXPR bool + operator<=(const __wrap_iter& __x, const __wrap_iter& __y) _NOEXCEPT { + return !(__y < __x); + } + + template + _LIBCPP_HIDE_FROM_ABI friend _LIBCPP_CONSTEXPR bool + operator<=(const __wrap_iter& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT { + return !(__y < __x); + } #else -template -_LIBCPP_HIDE_FROM_ABI constexpr strong_ordering -operator<=>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) noexcept { - if constexpr (three_way_comparable_with<_Iter1, _Iter2, strong_ordering>) { - return __x.base() <=> __y.base(); - } else { - if (__x.base() < __y.base()) - return strong_ordering::less; - - if (__x.base() == __y.base()) - return strong_ordering::equal; - - return strong_ordering::greater; + _LIBCPP_HIDE_FROM_ABI friend bool operator==(const __wrap_iter&, const __wrap_iter&) = default; + + template + _LIBCPP_HIDE_FROM_ABI friend constexpr bool + operator==(const __wrap_iter& __x, const __wrap_iter<_Iter2>& __y) noexcept { + return __x.__i_ == __y.__i_; + } + + template + _LIBCPP_HIDE_FROM_ABI friend constexpr strong_ordering + operator<=>(const __wrap_iter& __x, const __wrap_iter<_Iter2>& __y) noexcept { + if constexpr (three_way_comparable_with<_Iter, _Iter2, strong_ordering>) { + return __x.__i_ <=> __y.__i_; + } else { + if (__x.__i_ < __y.__i_) + return strong_ordering::less; + + if (__x.__i_ == __y.__i_) + return strong_ordering::equal; + + return strong_ordering::greater; + } } -} #endif // _LIBCPP_STD_VER >= 20 -template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 #ifndef _LIBCPP_CXX03_LANG - auto - operator-(const __wrap_iter<_Iter1>& __x, - const __wrap_iter<_Iter2>& __y) _NOEXCEPT->decltype(__x.base() - __y.base()) + template + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI friend _LIBCPP_CONSTEXPR_SINCE_CXX14 auto + operator-(const __wrap_iter& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT->decltype(__x.__i_ - __y.__i_) #else -typename __wrap_iter<_Iter1>::difference_type -operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT + template + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI friend _LIBCPP_CONSTEXPR_SINCE_CXX14 + typename __wrap_iter::difference_type operator-(const __wrap_iter& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT #endif // C++03 -{ - return __x.base() - __y.base(); -} + { + return __x.__i_ - __y.__i_; + } -template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 __wrap_iter<_Iter1> -operator+(typename __wrap_iter<_Iter1>::difference_type __n, __wrap_iter<_Iter1> __x) _NOEXCEPT { - __x += __n; - return __x; -} + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI friend _LIBCPP_CONSTEXPR_SINCE_CXX14 __wrap_iter + operator+(typename __wrap_iter::difference_type __n, __wrap_iter __x) _NOEXCEPT { + __x += __n; + return __x; + } +}; #if _LIBCPP_STD_VER <= 17 template struct __libcpp_is_contiguous_iterator<__wrap_iter<_It> > : true_type {}; #endif -template -struct pointer_traits<__wrap_iter<_It> > { - typedef __wrap_iter<_It> pointer; - typedef typename pointer_traits<_It>::element_type element_type; - typedef typename pointer_traits<_It>::difference_type difference_type; - - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR static element_type* to_address(pointer __w) _NOEXCEPT { - return std::__to_address(__w.base()); - } -}; - _LIBCPP_END_NAMESPACE_STD #endif // _LIBCPP___ITERATOR_WRAP_ITER_H diff --git a/lib/libcxx/include/__locale b/lib/libcxx/include/__locale index 5b1787451fb2594e105554be2b8fda6d008ede6e..bb8f8e7bbf5d9cc82d9d45fd539ee1760da33482 100644 --- a/lib/libcxx/include/__locale +++ b/lib/libcxx/include/__locale @@ -11,6 +11,7 @@ #define _LIBCPP___LOCALE #include <__config> +#include <__configuration/availability.h> #if _LIBCPP_HAS_LOCALIZATION @@ -26,6 +27,7 @@ # include # include # include +# include // Some platforms require more includes than others. Keep the includes on all plaforms for now. # include @@ -42,6 +44,7 @@ # endif _LIBCPP_BEGIN_NAMESPACE_STD +_LIBCPP_BEGIN_EXPLICIT_ABI_ANNOTATIONS class _LIBCPP_EXPORTED_FROM_ABI locale; @@ -88,7 +91,7 @@ public: const locale& operator=(const locale&) _NOEXCEPT; template - _LIBCPP_HIDE_FROM_ABI locale combine(const locale& __other) const { + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI locale combine(const locale& __other) const { if (!std::has_facet<_Facet>(__other)) __throw_runtime_error("locale::combine: locale missing facet"); @@ -96,21 +99,29 @@ public: } // locale operations: - string name() const; + [[__nodiscard__]] string name() const; bool operator==(const locale&) const; # if _LIBCPP_STD_VER <= 17 _LIBCPP_HIDE_FROM_ABI bool operator!=(const locale& __y) const { return !(*this == __y); } # endif template + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI bool operator()(const basic_string<_CharT, _Traits, _Allocator>& __x, const basic_string<_CharT, _Traits, _Allocator>& __y) const { return std::use_facet >(*this).compare( __x.data(), __x.data() + __x.size(), __y.data(), __y.data() + __y.size()) < 0; } +# if _LIBCPP_STD_VER >= 26 + [[nodiscard]] _LIBCPP_AVAILABILITY_TEXT_ENCODING_ENVIRONMENT + _LIBCPP_HIDE_FROM_ABI std::text_encoding encoding() const { + std::string __name = name(); + return std::__get_locale_encoding(__name.c_str()); + } +# endif // global locale objects: static locale global(const locale&); - static const locale& classic(); + [[__nodiscard__]] static const locale& classic(); private: class __imp; @@ -118,6 +129,9 @@ private: template friend struct __no_destroy; + + friend ios_base; + _LIBCPP_HIDE_FROM_ABI explicit locale(__private_constructor_tag, __imp* __loc) : __locale_(__loc) {} void __install_ctor(const locale&, facet*, long); @@ -168,12 +182,12 @@ inline _LIBCPP_HIDE_FROM_ABI locale::locale(const locale& __other, _Facet* __f) } template -inline _LIBCPP_HIDE_FROM_ABI bool has_facet(const locale& __l) _NOEXCEPT { +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI bool has_facet(const locale& __l) _NOEXCEPT { return __l.has_facet(_Facet::id); } template -inline _LIBCPP_HIDE_FROM_ABI const _Facet& use_facet(const locale& __l) { +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI const _Facet& use_facet(const locale& __l) { return static_cast(*__l.use_facet(_Facet::id)); } @@ -187,19 +201,21 @@ public: _LIBCPP_HIDE_FROM_ABI explicit collate(size_t __refs = 0) : locale::facet(__refs) {} - _LIBCPP_HIDE_FROM_ABI int + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI int compare(const char_type* __lo1, const char_type* __hi1, const char_type* __lo2, const char_type* __hi2) const { return do_compare(__lo1, __hi1, __lo2, __hi2); } // FIXME(EricWF): The _LIBCPP_ALWAYS_INLINE is needed on Windows to work // around a dllimport bug that expects an external instantiation. - _LIBCPP_HIDE_FROM_ABI _LIBCPP_ALWAYS_INLINE string_type + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_ALWAYS_INLINE string_type transform(const char_type* __lo, const char_type* __hi) const { return do_transform(__lo, __hi); } - _LIBCPP_HIDE_FROM_ABI long hash(const char_type* __lo, const char_type* __hi) const { return do_hash(__lo, __hi); } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI long hash(const char_type* __lo, const char_type* __hi) const { + return do_hash(__lo, __hi); + } static locale::id id; @@ -318,6 +334,8 @@ public: # endif // defined(__BIONIC__) # elif defined(__GLIBC__) typedef unsigned short mask; + _LIBCPP_DIAGNOSTIC_PUSH + _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wmodules-ambiguous-internal-linkage") static const mask space = _ISspace; static const mask print = _ISprint; static const mask cntrl = _IScntrl; @@ -328,6 +346,7 @@ public: static const mask punct = _ISpunct; static const mask xdigit = _ISxdigit; static const mask blank = _ISblank; + _LIBCPP_DIAGNOSTIC_POP # if defined(__mips__) || (BYTE_ORDER == BIG_ENDIAN) static const mask __regex_word = static_cast(_ISbit(15)); # else @@ -459,39 +478,43 @@ public: _LIBCPP_HIDE_FROM_ABI explicit ctype(size_t __refs = 0) : locale::facet(__refs) {} - _LIBCPP_HIDE_FROM_ABI bool is(mask __m, char_type __c) const { return do_is(__m, __c); } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI bool is(mask __m, char_type __c) const { return do_is(__m, __c); } _LIBCPP_HIDE_FROM_ABI const char_type* is(const char_type* __low, const char_type* __high, mask* __vec) const { return do_is(__low, __high, __vec); } - _LIBCPP_HIDE_FROM_ABI const char_type* scan_is(mask __m, const char_type* __low, const char_type* __high) const { + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI const char_type* + scan_is(mask __m, const char_type* __low, const char_type* __high) const { return do_scan_is(__m, __low, __high); } - _LIBCPP_HIDE_FROM_ABI const char_type* scan_not(mask __m, const char_type* __low, const char_type* __high) const { + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI const char_type* + scan_not(mask __m, const char_type* __low, const char_type* __high) const { return do_scan_not(__m, __low, __high); } - _LIBCPP_HIDE_FROM_ABI char_type toupper(char_type __c) const { return do_toupper(__c); } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI char_type toupper(char_type __c) const { return do_toupper(__c); } _LIBCPP_HIDE_FROM_ABI const char_type* toupper(char_type* __low, const char_type* __high) const { return do_toupper(__low, __high); } - _LIBCPP_HIDE_FROM_ABI char_type tolower(char_type __c) const { return do_tolower(__c); } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI char_type tolower(char_type __c) const { return do_tolower(__c); } _LIBCPP_HIDE_FROM_ABI const char_type* tolower(char_type* __low, const char_type* __high) const { return do_tolower(__low, __high); } - _LIBCPP_HIDE_FROM_ABI char_type widen(char __c) const { return do_widen(__c); } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI char_type widen(char __c) const { return do_widen(__c); } _LIBCPP_HIDE_FROM_ABI const char* widen(const char* __low, const char* __high, char_type* __to) const { return do_widen(__low, __high, __to); } - _LIBCPP_HIDE_FROM_ABI char narrow(char_type __c, char __dfault) const { return do_narrow(__c, __dfault); } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI char narrow(char_type __c, char __dfault) const { + return do_narrow(__c, __dfault); + } _LIBCPP_HIDE_FROM_ABI const char_type* narrow(const char_type* __low, const char_type* __high, char __dfault, char* __to) const { @@ -530,7 +553,7 @@ public: explicit ctype(const mask* __tab = nullptr, bool __del = false, size_t __refs = 0); - _LIBCPP_HIDE_FROM_ABI bool is(mask __m, char_type __c) const { + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI bool is(mask __m, char_type __c) const { return std::__libcpp_isascii(__c) ? (__tab_[static_cast(__c)] & __m) != 0 : false; } @@ -540,39 +563,43 @@ public: return __low; } - _LIBCPP_HIDE_FROM_ABI const char_type* scan_is(mask __m, const char_type* __low, const char_type* __high) const { + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI const char_type* + scan_is(mask __m, const char_type* __low, const char_type* __high) const { for (; __low != __high; ++__low) if (std::__libcpp_isascii(*__low) && (__tab_[static_cast(*__low)] & __m)) break; return __low; } - _LIBCPP_HIDE_FROM_ABI const char_type* scan_not(mask __m, const char_type* __low, const char_type* __high) const { + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI const char_type* + scan_not(mask __m, const char_type* __low, const char_type* __high) const { for (; __low != __high; ++__low) if (!std::__libcpp_isascii(*__low) || !(__tab_[static_cast(*__low)] & __m)) break; return __low; } - _LIBCPP_HIDE_FROM_ABI char_type toupper(char_type __c) const { return do_toupper(__c); } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI char_type toupper(char_type __c) const { return do_toupper(__c); } _LIBCPP_HIDE_FROM_ABI const char_type* toupper(char_type* __low, const char_type* __high) const { return do_toupper(__low, __high); } - _LIBCPP_HIDE_FROM_ABI char_type tolower(char_type __c) const { return do_tolower(__c); } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI char_type tolower(char_type __c) const { return do_tolower(__c); } _LIBCPP_HIDE_FROM_ABI const char_type* tolower(char_type* __low, const char_type* __high) const { return do_tolower(__low, __high); } - _LIBCPP_HIDE_FROM_ABI char_type widen(char __c) const { return do_widen(__c); } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI char_type widen(char __c) const { return do_widen(__c); } _LIBCPP_HIDE_FROM_ABI const char* widen(const char* __low, const char* __high, char_type* __to) const { return do_widen(__low, __high, __to); } - _LIBCPP_HIDE_FROM_ABI char narrow(char_type __c, char __dfault) const { return do_narrow(__c, __dfault); } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI char narrow(char_type __c, char __dfault) const { + return do_narrow(__c, __dfault); + } _LIBCPP_HIDE_FROM_ABI const char* narrow(const char_type* __low, const char_type* __high, char __dfault, char* __to) const { @@ -586,8 +613,8 @@ public: # else static const size_t table_size = 256; # endif - _LIBCPP_HIDE_FROM_ABI const mask* table() const _NOEXCEPT { return __tab_; } - static const mask* classic_table() _NOEXCEPT; + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI const mask* table() const _NOEXCEPT { return __tab_; } + [[__nodiscard__]] static const mask* classic_table() _NOEXCEPT; protected: ~ctype() override; @@ -650,72 +677,72 @@ protected: # endif // _LIBCPP_HAS_WIDE_CHARACTERS template -inline _LIBCPP_HIDE_FROM_ABI bool isspace(_CharT __c, const locale& __loc) { +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI bool isspace(_CharT __c, const locale& __loc) { return std::use_facet >(__loc).is(ctype_base::space, __c); } template -inline _LIBCPP_HIDE_FROM_ABI bool isprint(_CharT __c, const locale& __loc) { +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI bool isprint(_CharT __c, const locale& __loc) { return std::use_facet >(__loc).is(ctype_base::print, __c); } template -inline _LIBCPP_HIDE_FROM_ABI bool iscntrl(_CharT __c, const locale& __loc) { +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI bool iscntrl(_CharT __c, const locale& __loc) { return std::use_facet >(__loc).is(ctype_base::cntrl, __c); } template -inline _LIBCPP_HIDE_FROM_ABI bool isupper(_CharT __c, const locale& __loc) { +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI bool isupper(_CharT __c, const locale& __loc) { return std::use_facet >(__loc).is(ctype_base::upper, __c); } template -inline _LIBCPP_HIDE_FROM_ABI bool islower(_CharT __c, const locale& __loc) { +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI bool islower(_CharT __c, const locale& __loc) { return std::use_facet >(__loc).is(ctype_base::lower, __c); } template -inline _LIBCPP_HIDE_FROM_ABI bool isalpha(_CharT __c, const locale& __loc) { +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI bool isalpha(_CharT __c, const locale& __loc) { return std::use_facet >(__loc).is(ctype_base::alpha, __c); } template -inline _LIBCPP_HIDE_FROM_ABI bool isdigit(_CharT __c, const locale& __loc) { +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI bool isdigit(_CharT __c, const locale& __loc) { return std::use_facet >(__loc).is(ctype_base::digit, __c); } template -inline _LIBCPP_HIDE_FROM_ABI bool ispunct(_CharT __c, const locale& __loc) { +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI bool ispunct(_CharT __c, const locale& __loc) { return std::use_facet >(__loc).is(ctype_base::punct, __c); } template -inline _LIBCPP_HIDE_FROM_ABI bool isxdigit(_CharT __c, const locale& __loc) { +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI bool isxdigit(_CharT __c, const locale& __loc) { return std::use_facet >(__loc).is(ctype_base::xdigit, __c); } template -inline _LIBCPP_HIDE_FROM_ABI bool isalnum(_CharT __c, const locale& __loc) { +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI bool isalnum(_CharT __c, const locale& __loc) { return std::use_facet >(__loc).is(ctype_base::alnum, __c); } template -inline _LIBCPP_HIDE_FROM_ABI bool isgraph(_CharT __c, const locale& __loc) { +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI bool isgraph(_CharT __c, const locale& __loc) { return std::use_facet >(__loc).is(ctype_base::graph, __c); } template -_LIBCPP_HIDE_FROM_ABI bool isblank(_CharT __c, const locale& __loc) { +[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI bool isblank(_CharT __c, const locale& __loc) { return std::use_facet >(__loc).is(ctype_base::blank, __c); } template -inline _LIBCPP_HIDE_FROM_ABI _CharT toupper(_CharT __c, const locale& __loc) { +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _CharT toupper(_CharT __c, const locale& __loc) { return std::use_facet >(__loc).toupper(__c); } template -inline _LIBCPP_HIDE_FROM_ABI _CharT tolower(_CharT __c, const locale& __loc) { +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _CharT tolower(_CharT __c, const locale& __loc) { return std::use_facet >(__loc).tolower(__c); } @@ -770,16 +797,16 @@ public: return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt); } - _LIBCPP_HIDE_FROM_ABI int encoding() const _NOEXCEPT { return do_encoding(); } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI int encoding() const _NOEXCEPT { return do_encoding(); } - _LIBCPP_HIDE_FROM_ABI bool always_noconv() const _NOEXCEPT { return do_always_noconv(); } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI bool always_noconv() const _NOEXCEPT { return do_always_noconv(); } _LIBCPP_HIDE_FROM_ABI int length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const { return do_length(__st, __frm, __end, __mx); } - _LIBCPP_HIDE_FROM_ABI int max_length() const _NOEXCEPT { return do_max_length(); } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI int max_length() const _NOEXCEPT { return do_max_length(); } static locale::id id; @@ -852,16 +879,16 @@ public: return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt); } - _LIBCPP_HIDE_FROM_ABI int encoding() const _NOEXCEPT { return do_encoding(); } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI int encoding() const _NOEXCEPT { return do_encoding(); } - _LIBCPP_HIDE_FROM_ABI bool always_noconv() const _NOEXCEPT { return do_always_noconv(); } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI bool always_noconv() const _NOEXCEPT { return do_always_noconv(); } _LIBCPP_HIDE_FROM_ABI int length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const { return do_length(__st, __frm, __end, __mx); } - _LIBCPP_HIDE_FROM_ABI int max_length() const _NOEXCEPT { return do_max_length(); } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI int max_length() const _NOEXCEPT { return do_max_length(); } static locale::id id; @@ -933,16 +960,16 @@ public: return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt); } - _LIBCPP_HIDE_FROM_ABI int encoding() const _NOEXCEPT { return do_encoding(); } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI int encoding() const _NOEXCEPT { return do_encoding(); } - _LIBCPP_HIDE_FROM_ABI bool always_noconv() const _NOEXCEPT { return do_always_noconv(); } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI bool always_noconv() const _NOEXCEPT { return do_always_noconv(); } _LIBCPP_HIDE_FROM_ABI int length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const { return do_length(__st, __frm, __end, __mx); } - _LIBCPP_HIDE_FROM_ABI int max_length() const _NOEXCEPT { return do_max_length(); } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI int max_length() const _NOEXCEPT { return do_max_length(); } static locale::id id; @@ -976,10 +1003,11 @@ protected: # if _LIBCPP_HAS_CHAR8_T -// template <> class codecvt // C++20 +// template <> class codecvt // C++20, deprecated in C++20 template <> -class _LIBCPP_EXPORTED_FROM_ABI codecvt : public locale::facet, public codecvt_base { +class _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_EXPORTED_FROM_ABI codecvt + : public locale::facet, public codecvt_base { public: typedef char16_t intern_type; typedef char8_t extern_type; @@ -1014,16 +1042,16 @@ public: return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt); } - _LIBCPP_HIDE_FROM_ABI int encoding() const _NOEXCEPT { return do_encoding(); } + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI int encoding() const _NOEXCEPT { return do_encoding(); } - _LIBCPP_HIDE_FROM_ABI bool always_noconv() const _NOEXCEPT { return do_always_noconv(); } + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI bool always_noconv() const _NOEXCEPT { return do_always_noconv(); } _LIBCPP_HIDE_FROM_ABI int length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const { return do_length(__st, __frm, __end, __mx); } - _LIBCPP_HIDE_FROM_ABI int max_length() const _NOEXCEPT { return do_max_length(); } + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI int max_length() const _NOEXCEPT { return do_max_length(); } static locale::id id; @@ -1096,16 +1124,16 @@ public: return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt); } - _LIBCPP_HIDE_FROM_ABI int encoding() const _NOEXCEPT { return do_encoding(); } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI int encoding() const _NOEXCEPT { return do_encoding(); } - _LIBCPP_HIDE_FROM_ABI bool always_noconv() const _NOEXCEPT { return do_always_noconv(); } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI bool always_noconv() const _NOEXCEPT { return do_always_noconv(); } _LIBCPP_HIDE_FROM_ABI int length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const { return do_length(__st, __frm, __end, __mx); } - _LIBCPP_HIDE_FROM_ABI int max_length() const _NOEXCEPT { return do_max_length(); } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI int max_length() const _NOEXCEPT { return do_max_length(); } static locale::id id; @@ -1139,10 +1167,11 @@ protected: # if _LIBCPP_HAS_CHAR8_T -// template <> class codecvt // C++20 +// template <> class codecvt // C++20, deprecated in C++20 template <> -class _LIBCPP_EXPORTED_FROM_ABI codecvt : public locale::facet, public codecvt_base { +class _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_EXPORTED_FROM_ABI codecvt + : public locale::facet, public codecvt_base { public: typedef char32_t intern_type; typedef char8_t extern_type; @@ -1177,16 +1206,16 @@ public: return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt); } - _LIBCPP_HIDE_FROM_ABI int encoding() const _NOEXCEPT { return do_encoding(); } + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI int encoding() const _NOEXCEPT { return do_encoding(); } - _LIBCPP_HIDE_FROM_ABI bool always_noconv() const _NOEXCEPT { return do_always_noconv(); } + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI bool always_noconv() const _NOEXCEPT { return do_always_noconv(); } _LIBCPP_HIDE_FROM_ABI int length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const { return do_length(__st, __frm, __end, __mx); } - _LIBCPP_HIDE_FROM_ABI int max_length() const _NOEXCEPT { return do_max_length(); } + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI int max_length() const _NOEXCEPT { return do_max_length(); } static locale::id id; @@ -1248,8 +1277,10 @@ _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname; // d extern template class _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname; // deprecated in C++20 # if _LIBCPP_HAS_CHAR8_T -extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname; // C++20 -extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname; // C++20 +extern template class _LIBCPP_DEPRECATED_IN_CXX20 +_LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname; // C++20, deprecated in C++20 +extern template class _LIBCPP_DEPRECATED_IN_CXX20 +_LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname; // C++20, deprecated in C++20 # endif template @@ -1409,11 +1440,11 @@ public: explicit numpunct(size_t __refs = 0); - _LIBCPP_HIDE_FROM_ABI char_type decimal_point() const { return do_decimal_point(); } - _LIBCPP_HIDE_FROM_ABI char_type thousands_sep() const { return do_thousands_sep(); } - _LIBCPP_HIDE_FROM_ABI string grouping() const { return do_grouping(); } - _LIBCPP_HIDE_FROM_ABI string_type truename() const { return do_truename(); } - _LIBCPP_HIDE_FROM_ABI string_type falsename() const { return do_falsename(); } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI char_type decimal_point() const { return do_decimal_point(); } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI char_type thousands_sep() const { return do_thousands_sep(); } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI string grouping() const { return do_grouping(); } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI string_type truename() const { return do_truename(); } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI string_type falsename() const { return do_falsename(); } static locale::id id; @@ -1439,11 +1470,11 @@ public: explicit numpunct(size_t __refs = 0); - _LIBCPP_HIDE_FROM_ABI char_type decimal_point() const { return do_decimal_point(); } - _LIBCPP_HIDE_FROM_ABI char_type thousands_sep() const { return do_thousands_sep(); } - _LIBCPP_HIDE_FROM_ABI string grouping() const { return do_grouping(); } - _LIBCPP_HIDE_FROM_ABI string_type truename() const { return do_truename(); } - _LIBCPP_HIDE_FROM_ABI string_type falsename() const { return do_falsename(); } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI char_type decimal_point() const { return do_decimal_point(); } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI char_type thousands_sep() const { return do_thousands_sep(); } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI string grouping() const { return do_grouping(); } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI string_type truename() const { return do_truename(); } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI string_type falsename() const { return do_falsename(); } static locale::id id; @@ -1494,6 +1525,7 @@ protected: }; # endif // _LIBCPP_HAS_WIDE_CHARACTERS +_LIBCPP_END_EXPLICIT_ABI_ANNOTATIONS _LIBCPP_END_NAMESPACE_STD #endif // _LIBCPP_HAS_LOCALIZATION diff --git a/lib/libcxx/include/__locale_dir/check_grouping.h b/lib/libcxx/include/__locale_dir/check_grouping.h index 93e9e404bb5f38dd8e957a56df20ed50fa98b350..fe0f4f4b1780a522fbc54d309c9ed9910ff151ab 100644 --- a/lib/libcxx/include/__locale_dir/check_grouping.h +++ b/lib/libcxx/include/__locale_dir/check_grouping.h @@ -20,10 +20,12 @@ # endif _LIBCPP_BEGIN_NAMESPACE_STD +_LIBCPP_BEGIN_EXPLICIT_ABI_ANNOTATIONS _LIBCPP_EXPORTED_FROM_ABI void __check_grouping(const string& __grouping, unsigned* __g, unsigned* __g_end, ios_base::iostate& __err); +_LIBCPP_END_EXPLICIT_ABI_ANNOTATIONS _LIBCPP_END_NAMESPACE_STD #endif // _LIBCPP_HAS_LOCALIZATION diff --git a/lib/libcxx/include/__locale_dir/get_c_locale.h b/lib/libcxx/include/__locale_dir/get_c_locale.h index e8bac9a87095b5ece9c8f81f914e6f4d01ac2309..677827f2d8f1d88ff9112295e8093bb6c055d87c 100644 --- a/lib/libcxx/include/__locale_dir/get_c_locale.h +++ b/lib/libcxx/include/__locale_dir/get_c_locale.h @@ -29,7 +29,9 @@ _LIBCPP_BEGIN_NAMESPACE_STD # else # define _LIBCPP_GET_C_LOCALE __cloc() // Get the C locale object +_LIBCPP_BEGIN_EXPLICIT_ABI_ANNOTATIONS _LIBCPP_EXPORTED_FROM_ABI __locale::__locale_t __cloc(); +_LIBCPP_END_EXPLICIT_ABI_ANNOTATIONS # define __cloc_defined # endif diff --git a/lib/libcxx/include/__locale_dir/locale_base_api.h b/lib/libcxx/include/__locale_dir/locale_base_api.h index 0474c1db359dea406b4313e22fe12daaf6c61aad..f973d95ef244d58dafc774d6ceb9a68ceeb08300 100644 --- a/lib/libcxx/include/__locale_dir/locale_base_api.h +++ b/lib/libcxx/include/__locale_dir/locale_base_api.h @@ -102,6 +102,8 @@ // // int __snprintf(char*, size_t, __locale_t, const char*, ...); // required by the headers // int __asprintf(char**, __locale_t, const char*, ...); // required by the headers +// +// const char* __get_locale_encoding(__locale_t); // } #if _LIBCPP_HAS_LOCALIZATION @@ -112,10 +114,14 @@ # include <__locale_dir/support/freebsd.h> # elif defined(__NetBSD__) # include <__locale_dir/support/netbsd.h> +# elif defined(__OpenBSD__) +# include <__locale_dir/support/openbsd.h> # elif defined(_LIBCPP_MSVCRT_LIKE) # include <__locale_dir/support/windows.h> # elif defined(__Fuchsia__) # include <__locale_dir/support/fuchsia.h> +# elif _LIBCPP_LIBC_LLVM_LIBC +# include <__locale_dir/support/llvm_libc.h> # elif defined(__linux__) # include <__locale_dir/support/linux.h> # elif _LIBCPP_LIBC_NEWLIB @@ -128,17 +134,14 @@ // (by providing global non-reserved names) and the new API. As we move individual platforms // towards the new way of defining the locale base API, this should disappear since each platform // will define those directly. -# if defined(__MVS__) -# include <__locale_dir/locale_base_api/ibm.h> -# elif defined(__OpenBSD__) -# include <__locale_dir/locale_base_api/openbsd.h> -# endif +# include <__locale_dir/locale_base_api/ibm.h> # include <__locale_dir/locale_base_api/bsd_locale_fallbacks.h> # include <__cstddef/size_t.h> # include <__utility/forward.h> # include +# include # include # include # if _LIBCPP_HAS_WIDE_CHARACTERS @@ -228,8 +231,8 @@ inline _LIBCPP_HIDE_FROM_ABI wint_t __towupper(wint_t __ch, __locale_t __loc) { inline _LIBCPP_HIDE_FROM_ABI wint_t __towlower(wint_t __ch, __locale_t __loc) { return towlower_l(__ch, __loc); } # endif -inline _LIBCPP_HIDE_FROM_ABI size_t -__strftime(char* __s, size_t __max, const char* __format, const tm* __tm, __locale_t __loc) { +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_ATTRIBUTE_FORMAT(__strftime__, 3, 0) size_t + __strftime(char* __s, size_t __max, const char* __format, const tm* __tm, __locale_t __loc) { return strftime_l(__s, __max, __format, __tm, __loc); } @@ -268,7 +271,12 @@ __mbsrtowcs(wchar_t* __dest, const char** __src, size_t __len, mbstate_t* __ps, return __libcpp_mbsrtowcs_l(__dest, __src, __len, __ps, __loc); } # endif // _LIBCPP_HAS_WIDE_CHARACTERS -# endif // _LIBCPP_BUILDING_LIBRARY + +inline _LIBCPP_HIDE_FROM_ABI const char* __get_locale_encoding(__locale_t __loc) { + return ::nl_langinfo_l(CODESET, __loc); +} + +# endif // _LIBCPP_BUILDING_LIBRARY _LIBCPP_DIAGNOSTIC_PUSH _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wgcc-compat") diff --git a/lib/libcxx/include/__locale_dir/locale_base_api/android.h b/lib/libcxx/include/__locale_dir/locale_base_api/android.h deleted file mode 100644 index 36b8d93e1b228cadc4fbe656f095a6c5a10226d3..0000000000000000000000000000000000000000 --- a/lib/libcxx/include/__locale_dir/locale_base_api/android.h +++ /dev/null @@ -1,45 +0,0 @@ -// -*- C++ -*- -//===-----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___LOCALE_DIR_LOCALE_BASE_API_ANDROID_H -#define _LIBCPP___LOCALE_DIR_LOCALE_BASE_API_ANDROID_H - -#include - -// FIXME: Is this actually required? -extern "C" { -#include -} - -#include - -// If we do not have this header, we are in a platform build rather than an NDK -// build, which will always be at least as new as the ToT NDK, in which case we -// don't need any of the inlines below since libc provides them. -#if __has_include() -# include -// In NDK versions later than 16, locale-aware functions are provided by -// legacy_stdlib_inlines.h -# if __NDK_MAJOR__ <= 16 -# if __ANDROID_API__ < 26 - -inline _LIBCPP_HIDE_FROM_ABI float strtof_l(const char* __nptr, char** __endptr, locale_t) { - return ::strtof(__nptr, __endptr); -} - -inline _LIBCPP_HIDE_FROM_ABI double strtod_l(const char* __nptr, char** __endptr, locale_t) { - return ::strtod(__nptr, __endptr); -} - -# endif // __ANDROID_API__ < 26 - -# endif // __NDK_MAJOR__ <= 16 -#endif // __has_include() - -#endif // _LIBCPP___LOCALE_DIR_LOCALE_BASE_API_ANDROID_H diff --git a/lib/libcxx/include/__locale_dir/locale_base_api/ibm.h b/lib/libcxx/include/__locale_dir/locale_base_api/ibm.h new file mode 100644 index 0000000000000000000000000000000000000000..47a83eac7df36a695632080bd30261511505847e --- /dev/null +++ b/lib/libcxx/include/__locale_dir/locale_base_api/ibm.h @@ -0,0 +1,97 @@ +// -*- C++ -*- +//===-----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP___LOCALE_DIR_LOCALE_BASE_API_IBM_H +#define _LIBCPP___LOCALE_DIR_LOCALE_BASE_API_IBM_H + +#if defined(__MVS__) +# include <__support/ibm/locale_mgmt_zos.h> +#endif // defined(__MVS__) + +#include +#include +#include + +#include "cstdlib" + +#if defined(__MVS__) +# include +// POSIX routines +# include <__support/xlocale/__posix_l_fallback.h> +#endif // defined(__MVS__) + +namespace { + +struct __setAndRestore { + explicit __setAndRestore(locale_t locale) { + if (locale == (locale_t)0) { + __cloc = newlocale(LC_ALL_MASK, "C", /* base */ (locale_t)0); + __stored = uselocale(__cloc); + } else { + __stored = uselocale(locale); + } + } + + ~__setAndRestore() { + uselocale(__stored); + if (__cloc) + freelocale(__cloc); + } + +private: + locale_t __stored = (locale_t)0; + locale_t __cloc = (locale_t)0; +}; + +} // namespace + +// The following are not POSIX routines. These are quick-and-dirty hacks +// to make things pretend to work +inline _LIBCPP_HIDE_FROM_ABI double strtod_l(const char* __nptr, char** __endptr, locale_t locale) { + __setAndRestore __newloc(locale); + return ::strtod(__nptr, __endptr); +} + +inline _LIBCPP_HIDE_FROM_ABI float strtof_l(const char* __nptr, char** __endptr, locale_t locale) { + __setAndRestore __newloc(locale); + return ::strtof(__nptr, __endptr); +} + +inline _LIBCPP_HIDE_FROM_ABI long double strtold_l(const char* __nptr, char** __endptr, locale_t locale) { + __setAndRestore __newloc(locale); + return ::strtold(__nptr, __endptr); +} + +inline _LIBCPP_HIDE_FROM_ABI +_LIBCPP_ATTRIBUTE_FORMAT(__printf__, 2, 0) int vasprintf(char** strp, const char* fmt, va_list ap) { + const size_t buff_size = 256; + if ((*strp = (char*)malloc(buff_size)) == nullptr) { + return -1; + } + + va_list ap_copy; + // va_copy may not be provided by the C library in C++03 mode. +#if defined(_LIBCPP_CXX03_LANG) && __has_builtin(__builtin_va_copy) + __builtin_va_copy(ap_copy, ap); +#else + va_copy(ap_copy, ap); +#endif + int str_size = vsnprintf(*strp, buff_size, fmt, ap_copy); + va_end(ap_copy); + + if ((size_t)str_size >= buff_size) { + if ((*strp = (char*)realloc(*strp, str_size + 1)) == nullptr) { + return -1; + } + str_size = vsnprintf(*strp, str_size + 1, fmt, ap); + } + return str_size; +} + +#endif // _LIBCPP___LOCALE_DIR_LOCALE_BASE_API_IBM_H diff --git a/lib/libcxx/include/__locale_dir/locale_base_api/musl.h b/lib/libcxx/include/__locale_dir/locale_base_api/musl.h deleted file mode 100644 index 1653214cdba1e3984a0cd3f9ff5fa1e5a0f41064..0000000000000000000000000000000000000000 --- a/lib/libcxx/include/__locale_dir/locale_base_api/musl.h +++ /dev/null @@ -1,31 +0,0 @@ -// -*- C++ -*- -//===-----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// -// This adds support for the extended locale functions that are currently -// missing from the Musl C library. -// -// This only works when the specified locale is "C" or "POSIX", but that's -// about as good as we can do without implementing full xlocale support -// in Musl. -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___LOCALE_DIR_LOCALE_BASE_API_MUSL_H -#define _LIBCPP___LOCALE_DIR_LOCALE_BASE_API_MUSL_H - -#include -#include - -inline _LIBCPP_HIDE_FROM_ABI long long strtoll_l(const char* __nptr, char** __endptr, int __base, locale_t) { - return ::strtoll(__nptr, __endptr, __base); -} - -inline _LIBCPP_HIDE_FROM_ABI unsigned long long strtoull_l(const char* __nptr, char** __endptr, int __base, locale_t) { - return ::strtoull(__nptr, __endptr, __base); -} - -#endif // _LIBCPP___LOCALE_DIR_LOCALE_BASE_API_MUSL_H diff --git a/lib/libcxx/include/__locale_dir/locale_base_api/openbsd.h b/lib/libcxx/include/__locale_dir/locale_base_api/openbsd.h deleted file mode 100644 index d4fb224e0c80a09b0ae2134eeb2d8216f454e5a4..0000000000000000000000000000000000000000 --- a/lib/libcxx/include/__locale_dir/locale_base_api/openbsd.h +++ /dev/null @@ -1,19 +0,0 @@ -// -*- C++ -*- -//===-----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___LOCALE_DIR_LOCALE_BASE_API_OPENBSD_H -#define _LIBCPP___LOCALE_DIR_LOCALE_BASE_API_OPENBSD_H - -#include <__support/xlocale/__strtonum_fallback.h> -#include -#include -#include -#include - -#endif // _LIBCPP___LOCALE_DIR_LOCALE_BASE_API_OPENBSD_H diff --git a/lib/libcxx/include/__locale_dir/messages.h b/lib/libcxx/include/__locale_dir/messages.h index 686f472840c222226b2e53fa1e3757c47ded8f13..986a57d8b17b23bf4867ac7908623bb867c0667c 100644 --- a/lib/libcxx/include/__locale_dir/messages.h +++ b/lib/libcxx/include/__locale_dir/messages.h @@ -33,6 +33,7 @@ # endif _LIBCPP_BEGIN_NAMESPACE_STD +_LIBCPP_BEGIN_EXPLICIT_ABI_ANNOTATIONS class _LIBCPP_EXPORTED_FROM_ABI messages_base { public: @@ -49,11 +50,12 @@ public: _LIBCPP_HIDE_FROM_ABI explicit messages(size_t __refs = 0) : locale::facet(__refs) {} - _LIBCPP_HIDE_FROM_ABI catalog open(const basic_string& __nm, const locale& __loc) const { + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI catalog open(const basic_string& __nm, const locale& __loc) const { return do_open(__nm, __loc); } - _LIBCPP_HIDE_FROM_ABI string_type get(catalog __c, int __set, int __msgid, const string_type& __dflt) const { + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI string_type + get(catalog __c, int __set, int __msgid, const string_type& __dflt) const { return do_get(__c, __set, __msgid, __dflt); } @@ -136,6 +138,7 @@ extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS messages_byname; extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS messages_byname; # endif +_LIBCPP_END_EXPLICIT_ABI_ANNOTATIONS _LIBCPP_END_NAMESPACE_STD #endif // _LIBCPP_HAS_LOCALIZATION diff --git a/lib/libcxx/include/__locale_dir/money.h b/lib/libcxx/include/__locale_dir/money.h index 12ba38467d805fc43ea8907ec5e72fde82f2ec2d..ba1cccb131f20cc7ff85d4014dec184e73984b7f 100644 --- a/lib/libcxx/include/__locale_dir/money.h +++ b/lib/libcxx/include/__locale_dir/money.h @@ -32,6 +32,7 @@ _LIBCPP_PUSH_MACROS # include <__undef_macros> _LIBCPP_BEGIN_NAMESPACE_STD +_LIBCPP_BEGIN_EXPLICIT_ABI_ANNOTATIONS // money_base @@ -55,15 +56,15 @@ public: _LIBCPP_HIDE_FROM_ABI explicit moneypunct(size_t __refs = 0) : locale::facet(__refs) {} - _LIBCPP_HIDE_FROM_ABI char_type decimal_point() const { return do_decimal_point(); } - _LIBCPP_HIDE_FROM_ABI char_type thousands_sep() const { return do_thousands_sep(); } - _LIBCPP_HIDE_FROM_ABI string grouping() const { return do_grouping(); } - _LIBCPP_HIDE_FROM_ABI string_type curr_symbol() const { return do_curr_symbol(); } - _LIBCPP_HIDE_FROM_ABI string_type positive_sign() const { return do_positive_sign(); } - _LIBCPP_HIDE_FROM_ABI string_type negative_sign() const { return do_negative_sign(); } - _LIBCPP_HIDE_FROM_ABI int frac_digits() const { return do_frac_digits(); } - _LIBCPP_HIDE_FROM_ABI pattern pos_format() const { return do_pos_format(); } - _LIBCPP_HIDE_FROM_ABI pattern neg_format() const { return do_neg_format(); } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI char_type decimal_point() const { return do_decimal_point(); } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI char_type thousands_sep() const { return do_thousands_sep(); } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI string grouping() const { return do_grouping(); } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI string_type curr_symbol() const { return do_curr_symbol(); } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI string_type positive_sign() const { return do_positive_sign(); } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI string_type negative_sign() const { return do_negative_sign(); } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI int frac_digits() const { return do_frac_digits(); } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI pattern pos_format() const { return do_pos_format(); } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI pattern neg_format() const { return do_neg_format(); } static locale::id id; static const bool intl = _International; @@ -864,6 +865,7 @@ extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS money_put; extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS money_put; # endif +_LIBCPP_END_EXPLICIT_ABI_ANNOTATIONS _LIBCPP_END_NAMESPACE_STD _LIBCPP_POP_MACROS diff --git a/lib/libcxx/include/__locale_dir/num.h b/lib/libcxx/include/__locale_dir/num.h index b7ea02e7cb7f7e464182372e4a53cb244dad4381..5b3b917384121430df2f384bd7848e6a300ac0ed 100644 --- a/lib/libcxx/include/__locale_dir/num.h +++ b/lib/libcxx/include/__locale_dir/num.h @@ -42,6 +42,7 @@ _LIBCPP_PUSH_MACROS # include <__undef_macros> _LIBCPP_BEGIN_NAMESPACE_STD +_LIBCPP_BEGIN_EXPLICIT_ABI_ANNOTATIONS struct _LIBCPP_EXPORTED_FROM_ABI __num_get_base { static const int __num_get_buf_sz = 40; @@ -95,9 +96,8 @@ struct __num_get : protected __num_get_base { _LIBCPP_DIAGNOSTIC_PUSH _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wpsabi") using __vec = __simd_vector; - __vec __chars = std::__broadcast<__vec>(__val); __vec __cmp = std::__partial_load<__vec, __int_chr_cnt>(__atoms); - auto __res = __chars == __cmp; + auto __res = __vec(__val) == __cmp; if (std::__none_of(__res)) return __int_chr_cnt; return std::min(__int_chr_cnt, std::__find_first_set(__res)); @@ -1008,6 +1008,7 @@ extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS num_put; extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS num_put; # endif +_LIBCPP_END_EXPLICIT_ABI_ANNOTATIONS _LIBCPP_END_NAMESPACE_STD _LIBCPP_POP_MACROS diff --git a/lib/libcxx/include/__locale_dir/pad_and_output.h b/lib/libcxx/include/__locale_dir/pad_and_output.h index bdd4d2856dad69704a66f2282069f4203a6d4065..4b845792a3087f4e71e5b1eebe35ab5c2e94f1d2 100644 --- a/lib/libcxx/include/__locale_dir/pad_and_output.h +++ b/lib/libcxx/include/__locale_dir/pad_and_output.h @@ -55,13 +55,7 @@ _LIBCPP_HIDE_FROM_ABI ostreambuf_iterator<_CharT, _Traits> __pad_and_output( __ns -= __sz; else __ns = 0; - streamsize __np = __op - __ob; - if (__np > 0) { - if (__s.__sbuf_->sputn(__ob, __np) != __np) { - __s.__sbuf_ = nullptr; - return __s; - } - } + __s = std::copy(__ob, __op, __s); if (__ns > 0) { basic_string<_CharT, _Traits> __sp(__ns, __fl); if (__s.__sbuf_->sputn(__sp.data(), __ns) != __ns) { @@ -69,13 +63,7 @@ _LIBCPP_HIDE_FROM_ABI ostreambuf_iterator<_CharT, _Traits> __pad_and_output( return __s; } } - __np = __oe - __op; - if (__np > 0) { - if (__s.__sbuf_->sputn(__op, __np) != __np) { - __s.__sbuf_ = nullptr; - return __s; - } - } + __s = std::copy(__op, __oe, __s); __iob.width(0); return __s; } diff --git a/lib/libcxx/include/__locale_dir/support/bsd_like.h b/lib/libcxx/include/__locale_dir/support/bsd_like.h index 6f533b4e1eab1607343958912cd636f1acff6925..6632ca51e1eaad964dbe61c71439b48a88cb7cae 100644 --- a/lib/libcxx/include/__locale_dir/support/bsd_like.h +++ b/lib/libcxx/include/__locale_dir/support/bsd_like.h @@ -15,6 +15,7 @@ #include <__utility/forward.h> #include // std::lconv #include +#include #include #include #include @@ -133,8 +134,8 @@ inline _LIBCPP_HIDE_FROM_ABI size_t __wcsxfrm(wchar_t* __dest, const wchar_t* __ } # endif // _LIBCPP_HAS_WIDE_CHARACTERS -inline _LIBCPP_HIDE_FROM_ABI size_t -__strftime(char* __s, size_t __max, const char* __format, const struct tm* __tm, __locale_t __loc) { +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_ATTRIBUTE_FORMAT(__strftime__, 3, 0) size_t + __strftime(char* __s, size_t __max, const char* __format, const struct tm* __tm, __locale_t __loc) { return ::strftime_l(__s, __max, __format, __tm, __loc); } @@ -180,7 +181,11 @@ __mbsrtowcs(wchar_t* __dest, const char** __src, size_t __len, mbstate_t* __ps, return ::mbsrtowcs_l(__dest, __src, __len, __ps, __loc); } # endif // _LIBCPP_HAS_WIDE_CHARACTERS -#endif // _LIBCPP_BUILDING_LIBRARY + +inline _LIBCPP_HIDE_FROM_ABI const char* __get_locale_encoding(__locale_t __loc) { + return ::nl_langinfo_l(CODESET, __loc); +} +#endif // _LIBCPP_BUILDING_LIBRARY _LIBCPP_DIAGNOSTIC_PUSH _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wgcc-compat") diff --git a/lib/libcxx/include/__locale_dir/support/fuchsia.h b/lib/libcxx/include/__locale_dir/support/fuchsia.h index 528bfeb0cb6e141a9caf15c26662a6f204ca695e..1fe292a908a9cb6640e104df46eb29f9ecf0cd00 100644 --- a/lib/libcxx/include/__locale_dir/support/fuchsia.h +++ b/lib/libcxx/include/__locale_dir/support/fuchsia.h @@ -15,6 +15,7 @@ #include #include #include +#include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header @@ -69,6 +70,10 @@ inline _LIBCPP_HIDE_FROM_ABI __lconv_t* __localeconv(__locale_t& __loc) { return std::localeconv(); } +inline _LIBCPP_HIDE_FROM_ABI const char* __get_locale_encoding(__locale_t __loc) { + return ::nl_langinfo_l(CODESET, __loc); +} + // // Other functions // diff --git a/lib/libcxx/include/__locale_dir/support/linux.h b/lib/libcxx/include/__locale_dir/support/linux.h index 1a589be49bf1d8434587f694fd528204bf6d8d0d..6a91a001c239c455f26332ed2053458ea04a83ee 100644 --- a/lib/libcxx/include/__locale_dir/support/linux.h +++ b/lib/libcxx/include/__locale_dir/support/linux.h @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -148,8 +149,8 @@ inline _LIBCPP_HIDE_FROM_ABI size_t __wcsxfrm(wchar_t* __dest, const wchar_t* __ } # endif // _LIBCPP_HAS_WIDE_CHARACTERS -inline _LIBCPP_HIDE_FROM_ABI size_t -__strftime(char* __s, size_t __max, const char* __format, const struct tm* __tm, __locale_t __loc) { +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_ATTRIBUTE_FORMAT(__strftime__, 3, 0) size_t + __strftime(char* __s, size_t __max, const char* __format, const struct tm* __tm, __locale_t __loc) { return strftime_l(__s, __max, __format, __tm, __loc); } @@ -211,7 +212,15 @@ __mbsrtowcs(wchar_t* __dest, const char** __src, size_t __len, mbstate_t* __ps, return std::mbsrtowcs(__dest, __src, __len, __ps); } # endif // _LIBCPP_HAS_WIDE_CHARACTERS -#endif // _LIBCPP_BUILDING_LIBRARY + +inline _LIBCPP_HIDE_FROM_ABI const char* __get_locale_encoding([[maybe_unused]] __locale_t __loc) { +# if defined(__ANDROID__) + return "UTF-8"; +# else + return ::nl_langinfo_l(CODESET, __loc); +# endif +} +#endif // _LIBCPP_BUILDING_LIBRARY #ifndef _LIBCPP_COMPILER_GCC // GCC complains that this can't be always_inline due to C-style varargs _LIBCPP_HIDE_FROM_ABI diff --git a/lib/libcxx/include/__locale_dir/support/newlib.h b/lib/libcxx/include/__locale_dir/support/newlib.h index 05c8a449cfb05df7e2f8389d1bf1c537847f695c..7fe48572b458748aa2f17246f0d190e1dd60789a 100644 --- a/lib/libcxx/include/__locale_dir/support/newlib.h +++ b/lib/libcxx/include/__locale_dir/support/newlib.h @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -76,6 +77,10 @@ inline _LIBCPP_HIDE_FROM_ABI __lconv_t* __localeconv(__locale_t& __loc) { __locale_guard __current(__loc); return std::localeconv(); } + +inline _LIBCPP_HIDE_FROM_ABI const char* __get_locale_encoding(__locale_t __loc) { + return ::nl_langinfo_l(CODESET, __loc); +} #endif // _LIBCPP_BUILDING_LIBRARY // @@ -147,8 +152,8 @@ inline _LIBCPP_HIDE_FROM_ABI size_t __wcsxfrm(wchar_t* __dest, const wchar_t* __ } # endif // _LIBCPP_HAS_WIDE_CHARACTERS -inline _LIBCPP_HIDE_FROM_ABI -size_t __strftime(char* __s, size_t __max, const char* __format, const struct tm* __tm, __locale_t __loc) { +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_ATTRIBUTE_FORMAT(__strftime__, 3, 0) size_t + __strftime(char* __s, size_t __max, const char* __format, const struct tm* __tm, __locale_t __loc) { return strftime_l(__s, __max, __format, __tm, __loc); } diff --git a/lib/libcxx/include/__locale_dir/support/no_locale/characters.h b/lib/libcxx/include/__locale_dir/support/no_locale/characters.h index 73eba3ec542c72a6eca5bd0df832824e64c1e979..ffe6697916914619850271235a4706678b87f203 100644 --- a/lib/libcxx/include/__locale_dir/support/no_locale/characters.h +++ b/lib/libcxx/include/__locale_dir/support/no_locale/characters.h @@ -16,6 +16,7 @@ #include #include #if _LIBCPP_HAS_WIDE_CHARACTERS +# include # include #endif @@ -23,13 +24,14 @@ # pragma GCC system_header #endif +#if defined(_LIBCPP_BUILDING_LIBRARY) + _LIBCPP_BEGIN_NAMESPACE_STD namespace __locale { // // Character manipulation functions // -#if defined(_LIBCPP_BUILDING_LIBRARY) inline _LIBCPP_HIDE_FROM_ABI int __toupper(int __c, __locale_t) { return std::toupper(__c); } inline _LIBCPP_HIDE_FROM_ABI int __tolower(int __c, __locale_t) { return std::tolower(__c); } @@ -80,13 +82,13 @@ inline _LIBCPP_HIDE_FROM_ABI size_t __wcsxfrm(wchar_t* __dest, const wchar_t* __ } # endif // _LIBCPP_HAS_WIDE_CHARACTERS -inline _LIBCPP_HIDE_FROM_ABI size_t -__strftime(char* __s, size_t __max, const char* __format, const struct tm* __tm, __locale_t) { +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_ATTRIBUTE_FORMAT(__strftime__, 3, 0) size_t + __strftime(char* __s, size_t __max, const char* __format, const struct tm* __tm, __locale_t) { return std::strftime(__s, __max, __format, __tm); } -#endif // _LIBCPP_BUILDING_LIBRARY } // namespace __locale _LIBCPP_END_NAMESPACE_STD +#endif // _LIBCPP_BUILDING_LIBRARY #endif // _LIBCPP___LOCALE_DIR_SUPPORT_NO_LOCALE_CHARACTERS_H diff --git a/lib/libcxx/include/__locale_dir/support/no_locale/conversions.h b/lib/libcxx/include/__locale_dir/support/no_locale/conversions.h new file mode 100644 index 0000000000000000000000000000000000000000..bb501515c4d4ed396355ce3c693c3df9ab1f245b --- /dev/null +++ b/lib/libcxx/include/__locale_dir/support/no_locale/conversions.h @@ -0,0 +1,73 @@ +//===-----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP___LOCALE_DIR_SUPPORT_NO_LOCALE_CONVERSIONS_H +#define _LIBCPP___LOCALE_DIR_SUPPORT_NO_LOCALE_CONVERSIONS_H + +#include <__config> +#include <__cstddef/size_t.h> +#include <__std_mbstate_t.h> +#include +#if _LIBCPP_HAS_WIDE_CHARACTERS +# include +#endif + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +#if defined(_LIBCPP_BUILDING_LIBRARY) + +_LIBCPP_BEGIN_NAMESPACE_STD +namespace __locale { + +inline _LIBCPP_HIDE_FROM_ABI decltype(MB_CUR_MAX) __mb_len_max(__locale_t) { return MB_CUR_MAX; } + +# if _LIBCPP_HAS_WIDE_CHARACTERS +inline _LIBCPP_HIDE_FROM_ABI wint_t __btowc(int __c, __locale_t) { return std::btowc(__c); } + +inline _LIBCPP_HIDE_FROM_ABI int __wctob(wint_t __c, __locale_t) { return std::wctob(__c); } + +inline _LIBCPP_HIDE_FROM_ABI size_t +__wcsnrtombs(char* __dest, const wchar_t** __src, size_t __nwc, size_t __len, mbstate_t* __ps, __locale_t) { + return ::wcsnrtombs(__dest, __src, __nwc, __len, __ps); // Non-standard +} + +inline _LIBCPP_HIDE_FROM_ABI size_t __wcrtomb(char* __s, wchar_t __wc, mbstate_t* __ps, __locale_t) { + return std::wcrtomb(__s, __wc, __ps); +} + +inline _LIBCPP_HIDE_FROM_ABI size_t +__mbsnrtowcs(wchar_t* __dest, const char** __src, size_t __nms, size_t __len, mbstate_t* __ps, __locale_t) { + return ::mbsnrtowcs(__dest, __src, __nms, __len, __ps); // Non-standard +} + +inline _LIBCPP_HIDE_FROM_ABI size_t +__mbrtowc(wchar_t* __pwc, const char* __s, size_t __n, mbstate_t* __ps, __locale_t) { + return std::mbrtowc(__pwc, __s, __n, __ps); +} + +inline _LIBCPP_HIDE_FROM_ABI int __mbtowc(wchar_t* __pwc, const char* __pmb, size_t __max, __locale_t) { + return std::mbtowc(__pwc, __pmb, __max); +} + +inline _LIBCPP_HIDE_FROM_ABI size_t __mbrlen(const char* __s, size_t __n, mbstate_t* __ps, __locale_t) { + return std::mbrlen(__s, __n, __ps); +} + +inline _LIBCPP_HIDE_FROM_ABI size_t +__mbsrtowcs(wchar_t* __dest, const char** __src, size_t __len, mbstate_t* __ps, __locale_t) { + return std::mbsrtowcs(__dest, __src, __len, __ps); +} +# endif // _LIBCPP_HAS_WIDE_CHARACTERS + +} // namespace __locale +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_BUILDING_LIBRARY +#endif // _LIBCPP___LOCALE_DIR_SUPPORT_NO_LOCALE_CONVERSIONS_H diff --git a/lib/libcxx/include/__locale_dir/support/no_locale/formatting.h b/lib/libcxx/include/__locale_dir/support/no_locale/formatting.h new file mode 100644 index 0000000000000000000000000000000000000000..7185e9a4e60049eebd062784eb1e484682ab88d0 --- /dev/null +++ b/lib/libcxx/include/__locale_dir/support/no_locale/formatting.h @@ -0,0 +1,50 @@ +//===-----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP___LOCALE_DIR_SUPPORT_NO_LOCALE_FORMATTING_H +#define _LIBCPP___LOCALE_DIR_SUPPORT_NO_LOCALE_FORMATTING_H + +#include <__config> +#include <__utility/forward.h> +#include + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD +namespace __locale { + +_LIBCPP_DIAGNOSTIC_PUSH +_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wgcc-compat") +_LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wformat-nonliteral") // GCC doesn't support [[gnu::format]] on variadic templates +#ifdef _LIBCPP_COMPILER_CLANG_BASED +# define _LIBCPP_VARIADIC_ATTRIBUTE_FORMAT(...) _LIBCPP_ATTRIBUTE_FORMAT(__VA_ARGS__) +#else +# define _LIBCPP_VARIADIC_ATTRIBUTE_FORMAT(...) /* nothing */ +#endif + +template +_LIBCPP_HIDE_FROM_ABI _LIBCPP_VARIADIC_ATTRIBUTE_FORMAT(__printf__, 4, 5) int __snprintf( + char* __s, size_t __n, __locale_t, const char* __format, _Args&&... __args) { + return std::snprintf(__s, __n, __format, std::forward<_Args>(__args)...); +} + +template +_LIBCPP_HIDE_FROM_ABI _LIBCPP_VARIADIC_ATTRIBUTE_FORMAT(__printf__, 3, 4) int __asprintf( + char** __s, __locale_t, const char* __format, _Args&&... __args) { + return ::asprintf(__s, __format, std::forward<_Args>(__args)...); // non-standard +} + +_LIBCPP_DIAGNOSTIC_POP +#undef _LIBCPP_VARIADIC_ATTRIBUTE_FORMAT + +} // namespace __locale +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___LOCALE_DIR_SUPPORT_NO_LOCALE_FORMATTING_H diff --git a/lib/libcxx/include/__locale_dir/support/openbsd.h b/lib/libcxx/include/__locale_dir/support/openbsd.h new file mode 100644 index 0000000000000000000000000000000000000000..0ec5b12f2ebdde33772c303d0390d9f9dfa053f5 --- /dev/null +++ b/lib/libcxx/include/__locale_dir/support/openbsd.h @@ -0,0 +1,229 @@ +// -*- C++ -*- +//===-----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP___LOCALE_DIR_LOCALE_BASE_API_OPENBSD_H +#define _LIBCPP___LOCALE_DIR_LOCALE_BASE_API_OPENBSD_H + +#include <__config> +#include <__cstddef/size_t.h> +#include <__std_mbstate_t.h> +#include <__utility/forward.h> +#include // std::lconv +#include +#include +#include +#include +#include +#if _LIBCPP_HAS_WIDE_CHARACTERS +# include +# include +#endif + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD +namespace __locale { + +struct __locale_guard { + __locale_guard(locale_t& __loc) : __old_loc_(::uselocale(__loc)) {} + + ~__locale_guard() { + if (__old_loc_) + ::uselocale(__old_loc_); + } + + locale_t __old_loc_; + + __locale_guard(__locale_guard const&) = delete; + __locale_guard& operator=(__locale_guard const&) = delete; +}; + +// +// Locale management +// +#define _LIBCPP_COLLATE_MASK LC_COLLATE_MASK +#define _LIBCPP_CTYPE_MASK LC_CTYPE_MASK +#define _LIBCPP_MONETARY_MASK LC_MONETARY_MASK +#define _LIBCPP_NUMERIC_MASK LC_NUMERIC_MASK +#define _LIBCPP_TIME_MASK LC_TIME_MASK +#define _LIBCPP_MESSAGES_MASK LC_MESSAGES_MASK +#define _LIBCPP_ALL_MASK LC_ALL_MASK +#define _LIBCPP_LC_ALL LC_ALL + +using __locale_t _LIBCPP_NODEBUG = ::locale_t; +#if defined(_LIBCPP_BUILDING_LIBRARY) +using __lconv_t _LIBCPP_NODEBUG = std::lconv; + +inline __locale_t __newlocale(int __category_mask, const char* __locale, __locale_t __base) { + return ::newlocale(__category_mask, __locale, __base); +} + +inline void __freelocale(__locale_t __loc) { ::freelocale(__loc); } + +inline char* __setlocale(int __category, char const* __locale) { return ::setlocale(__category, __locale); } + +inline __lconv_t* __localeconv(__locale_t& __loc) { + __locale_guard __current(__loc); + return ::localeconv(); +} +#endif // _LIBCPP_BUILDING_LIBRARY + +// +// Strtonum functions +// +inline float __strtof(const char* __nptr, char** __endptr, __locale_t) { return ::strtof(__nptr, __endptr); } + +inline double __strtod(const char* __nptr, char** __endptr, __locale_t) { return ::strtod(__nptr, __endptr); } + +inline long double __strtold(const char* __nptr, char** __endptr, __locale_t) { return ::strtold(__nptr, __endptr); } + +// +// Character manipulation functions +// +#if defined(_LIBCPP_BUILDING_LIBRARY) +inline int __toupper(int __c, __locale_t __loc) { return ::toupper_l(__c, __loc); } + +inline int __tolower(int __c, __locale_t __loc) { return ::tolower_l(__c, __loc); } + +inline int __strcoll(const char* __s1, const char* __s2, __locale_t __loc) { return ::strcoll_l(__s1, __s2, __loc); } + +inline size_t __strxfrm(char* __dest, const char* __src, size_t __n, __locale_t __loc) { + return ::strxfrm_l(__dest, __src, __n, __loc); +} + +# if _LIBCPP_HAS_WIDE_CHARACTERS +inline int __iswctype(wint_t __c, wctype_t __type, __locale_t __loc) { return ::iswctype_l(__c, __type, __loc); } + +inline int __iswspace(wint_t __c, __locale_t __loc) { return ::iswspace_l(__c, __loc); } + +inline int __iswprint(wint_t __c, __locale_t __loc) { return ::iswprint_l(__c, __loc); } + +inline int __iswcntrl(wint_t __c, __locale_t __loc) { return ::iswcntrl_l(__c, __loc); } + +inline int __iswupper(wint_t __c, __locale_t __loc) { return ::iswupper_l(__c, __loc); } + +inline int __iswlower(wint_t __c, __locale_t __loc) { return ::iswlower_l(__c, __loc); } + +inline int __iswalpha(wint_t __c, __locale_t __loc) { return ::iswalpha_l(__c, __loc); } + +inline int __iswblank(wint_t __c, __locale_t __loc) { return ::iswblank_l(__c, __loc); } + +inline int __iswdigit(wint_t __c, __locale_t __loc) { return ::iswdigit_l(__c, __loc); } + +inline int __iswpunct(wint_t __c, __locale_t __loc) { return ::iswpunct_l(__c, __loc); } + +inline int __iswxdigit(wint_t __c, __locale_t __loc) { return ::iswxdigit_l(__c, __loc); } + +inline wint_t __towupper(wint_t __c, __locale_t __loc) { return ::towupper_l(__c, __loc); } + +inline wint_t __towlower(wint_t __c, __locale_t __loc) { return ::towlower_l(__c, __loc); } + +inline int __wcscoll(const wchar_t* __ws1, const wchar_t* __ws2, __locale_t __loc) { + return ::wcscoll_l(__ws1, __ws2, __loc); +} + +inline size_t __wcsxfrm(wchar_t* __dest, const wchar_t* __src, size_t __n, __locale_t __loc) { + return ::wcsxfrm_l(__dest, __src, __n, __loc); +} +# endif // _LIBCPP_HAS_WIDE_CHARACTERS + +inline _LIBCPP_ATTRIBUTE_FORMAT(__strftime__, 3, 0) size_t + __strftime(char* __s, size_t __max, const char* __format, const struct tm* __tm, __locale_t __loc) { + return ::strftime_l(__s, __max, __format, __tm, __loc); +} + +// +// Other functions +// +inline decltype(MB_CUR_MAX) __mb_len_max(__locale_t __loc) { + __locale_guard __current(__loc); + return MB_CUR_MAX; +} + +# if _LIBCPP_HAS_WIDE_CHARACTERS +inline wint_t __btowc(int __c, __locale_t __loc) { + __locale_guard __current(__loc); + return btowc(__c); +} + +inline int __wctob(wint_t __c, __locale_t __loc) { + __locale_guard __current(__loc); + return wctob(__c); +} + +inline size_t +__wcsnrtombs(char* __dest, const wchar_t** __src, size_t __nwc, size_t __len, mbstate_t* __ps, __locale_t __loc) { + __locale_guard __current(__loc); + return wcsnrtombs(__dest, __src, __nwc, __len, __ps); // wcsnrtombs is a POSIX extension +} + +inline size_t __wcrtomb(char* __s, wchar_t __wc, mbstate_t* __ps, __locale_t __loc) { + __locale_guard __current(__loc); + return wcrtomb(__s, __wc, __ps); +} + +inline size_t +__mbsnrtowcs(wchar_t* __dest, const char** __src, size_t __nms, size_t __len, mbstate_t* __ps, __locale_t __loc) { + __locale_guard __current(__loc); + return mbsnrtowcs(__dest, __src, __nms, __len, __ps); // mbsnrtowcs is a POSIX extension +} + +inline size_t __mbrtowc(wchar_t* __pwc, const char* __s, size_t __n, mbstate_t* __ps, __locale_t __loc) { + __locale_guard __current(__loc); + return mbrtowc(__pwc, __s, __n, __ps); +} + +inline int __mbtowc(wchar_t* __pwc, const char* __pmb, size_t __max, __locale_t __loc) { + __locale_guard __current(__loc); + return mbtowc(__pwc, __pmb, __max); +} + +inline size_t __mbrlen(const char* __s, size_t __n, mbstate_t* __ps, __locale_t __loc) { + __locale_guard __current(__loc); + return mbrlen(__s, __n, __ps); +} + +inline size_t __mbsrtowcs(wchar_t* __dest, const char** __src, size_t __len, mbstate_t* __ps, __locale_t __loc) { + __locale_guard __current(__loc); + return mbsrtowcs(__dest, __src, __len, __ps); +} +# endif // _LIBCPP_HAS_WIDE_CHARACTERS +#endif // _LIBCPP_BUILDING_LIBRARY + +_LIBCPP_DIAGNOSTIC_PUSH +_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wgcc-compat") +_LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wformat-nonliteral") // GCC doesn't support [[gnu::format]] on variadic templates +#ifdef _LIBCPP_COMPILER_CLANG_BASED +# define _LIBCPP_VARIADIC_ATTRIBUTE_FORMAT(...) _LIBCPP_ATTRIBUTE_FORMAT(__VA_ARGS__) +#else +# define _LIBCPP_VARIADIC_ATTRIBUTE_FORMAT(...) /* nothing */ +#endif + +template +_LIBCPP_VARIADIC_ATTRIBUTE_FORMAT(__printf__, 4, 5) +int __snprintf(char* __s, size_t __n, __locale_t __loc, const char* __format, _Args&&... __args) { + __locale_guard __current(__loc); + return ::snprintf(__s, __n, __format, std::forward<_Args>(__args)...); +} + +template +_LIBCPP_VARIADIC_ATTRIBUTE_FORMAT(__printf__, 3, 4) +int __asprintf(char** __s, __locale_t __loc, const char* __format, _Args&&... __args) { + __locale_guard __current(__loc); + return ::asprintf(__s, __format, std::forward<_Args>(__args)...); // non-standard +} +_LIBCPP_DIAGNOSTIC_POP +#undef _LIBCPP_VARIADIC_ATTRIBUTE_FORMAT + +} // namespace __locale +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___LOCALE_DIR_LOCALE_BASE_API_OPENBSD_H diff --git a/lib/libcxx/include/__locale_dir/support/windows.h b/lib/libcxx/include/__locale_dir/support/windows.h index 644ef68adf5455073d81a85f8e3a25846f253a05..6675cfb740b293c01a636d85e38dd9b46951a5f6 100644 --- a/lib/libcxx/include/__locale_dir/support/windows.h +++ b/lib/libcxx/include/__locale_dir/support/windows.h @@ -27,6 +27,7 @@ #endif _LIBCPP_BEGIN_NAMESPACE_STD +_LIBCPP_BEGIN_EXPLICIT_ABI_ANNOTATIONS namespace __locale { using __lconv_t _LIBCPP_NODEBUG = std::lconv; @@ -163,6 +164,7 @@ inline _LIBCPP_HIDE_FROM_ABI char* __setlocale(int __category, const char* __loc return __new_locale; } _LIBCPP_EXPORTED_FROM_ABI __lconv_t* __localeconv(__locale_t& __loc); +_LIBCPP_EXPORTED_FROM_ABI const char* __get_locale_encoding(__locale_t __loc); #endif // _LIBCPP_BUILDING_LIBRARY // @@ -230,10 +232,11 @@ inline _LIBCPP_HIDE_FROM_ABI size_t __wcsxfrm(wchar_t* __dest, const wchar_t* __ # endif // _LIBCPP_HAS_WIDE_CHARACTERS # if defined(__MINGW32__) && __MSVCRT_VERSION__ < 0x0800 -_LIBCPP_EXPORTED_FROM_ABI size_t __strftime(char*, size_t, const char*, const struct tm*, __locale_t); +_LIBCPP_EXPORTED_FROM_ABI _LIBCPP_ATTRIBUTE_FORMAT(__strftime__, 3, 0) size_t + __strftime(char*, size_t, const char*, const struct tm*, __locale_t); # else -inline _LIBCPP_HIDE_FROM_ABI size_t -__strftime(char* __ret, size_t __n, const char* __format, const struct tm* __tm, __locale_t __loc) { +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_ATTRIBUTE_FORMAT(__strftime__, 3, 0) size_t + __strftime(char* __ret, size_t __n, const char* __format, const struct tm* __tm, __locale_t __loc) { return ::_strftime_l(__ret, __n, __format, __tm, __loc); } # endif @@ -303,6 +306,7 @@ struct __locale_guard { #endif // _LIBCPP_BUILDING_LIBRARY } // namespace __locale +_LIBCPP_END_EXPLICIT_ABI_ANNOTATIONS _LIBCPP_END_NAMESPACE_STD #endif // _LIBCPP___LOCALE_DIR_SUPPORT_WINDOWS_H diff --git a/lib/libcxx/include/__locale_dir/time.h b/lib/libcxx/include/__locale_dir/time.h index 78698e96519186788f7dd831e20228e887057278..7db1cc660cd3090363b21e21f805b75319b2bf4c 100644 --- a/lib/libcxx/include/__locale_dir/time.h +++ b/lib/libcxx/include/__locale_dir/time.h @@ -22,6 +22,7 @@ # endif _LIBCPP_BEGIN_NAMESPACE_STD +_LIBCPP_BEGIN_EXPLICIT_ABI_ANNOTATIONS template _LIBCPP_HIDE_FROM_ABI int __get_up_to_n_digits( @@ -755,6 +756,7 @@ extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS time_put_byname; extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS time_put_byname; # endif +_LIBCPP_END_EXPLICIT_ABI_ANNOTATIONS _LIBCPP_END_NAMESPACE_STD #endif // _LIBCPP_HAS_LOCALIZATION diff --git a/lib/libcxx/include/__locale_dir/wbuffer_convert.h b/lib/libcxx/include/__locale_dir/wbuffer_convert.h index a6818aadf5d0b536da244743ae55b5c8faf89c87..9c87fac6cf1933c554facb98f191847fe5784234 100644 --- a/lib/libcxx/include/__locale_dir/wbuffer_convert.h +++ b/lib/libcxx/include/__locale_dir/wbuffer_convert.h @@ -27,6 +27,7 @@ _LIBCPP_PUSH_MACROS # include <__undef_macros> _LIBCPP_BEGIN_NAMESPACE_STD +_LIBCPP_BEGIN_EXPLICIT_ABI_ANNOTATIONS template > class _LIBCPP_DEPRECATED_IN_CXX17 wbuffer_convert : public basic_streambuf<_Elem, _Tr> { @@ -67,7 +68,7 @@ public: _LIBCPP_HIDE_FROM_ABI ~wbuffer_convert(); - _LIBCPP_HIDE_FROM_ABI streambuf* rdbuf() const { return __bufptr_; } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI streambuf* rdbuf() const { return __bufptr_; } _LIBCPP_HIDE_FROM_ABI streambuf* rdbuf(streambuf* __bytebuf) { streambuf* __r = __bufptr_; __bufptr_ = __bytebuf; @@ -77,7 +78,7 @@ public: wbuffer_convert(const wbuffer_convert&) = delete; wbuffer_convert& operator=(const wbuffer_convert&) = delete; - _LIBCPP_HIDE_FROM_ABI state_type state() const { return __st_; } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI state_type state() const { return __st_; } protected: _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual int_type underflow(); @@ -419,6 +420,7 @@ wbuffer_convert<_Codecvt, _Elem, _Tr>* wbuffer_convert<_Codecvt, _Elem, _Tr>::__ _LIBCPP_SUPPRESS_DEPRECATED_POP +_LIBCPP_END_EXPLICIT_ABI_ANNOTATIONS _LIBCPP_END_NAMESPACE_STD _LIBCPP_POP_MACROS diff --git a/lib/libcxx/include/__locale_dir/wstring_convert.h b/lib/libcxx/include/__locale_dir/wstring_convert.h index 42a56eb8573eaf2b0fe4977d01a4abacc95d2806..05b81e0a880edeb20e295fa50121950d6622508c 100644 --- a/lib/libcxx/include/__locale_dir/wstring_convert.h +++ b/lib/libcxx/include/__locale_dir/wstring_convert.h @@ -64,28 +64,30 @@ public: wstring_convert(const wstring_convert& __wc) = delete; wstring_convert& operator=(const wstring_convert& __wc) = delete; - _LIBCPP_HIDE_FROM_ABI wide_string from_bytes(char __byte) { return from_bytes(&__byte, &__byte + 1); } - _LIBCPP_HIDE_FROM_ABI wide_string from_bytes(const char* __ptr) { + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI wide_string from_bytes(char __byte) { + return from_bytes(&__byte, &__byte + 1); + } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI wide_string from_bytes(const char* __ptr) { return from_bytes(__ptr, __ptr + char_traits::length(__ptr)); } - _LIBCPP_HIDE_FROM_ABI wide_string from_bytes(const byte_string& __str) { + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI wide_string from_bytes(const byte_string& __str) { return from_bytes(__str.data(), __str.data() + __str.size()); } - _LIBCPP_HIDE_FROM_ABI wide_string from_bytes(const char* __first, const char* __last); + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI wide_string from_bytes(const char* __first, const char* __last); - _LIBCPP_HIDE_FROM_ABI byte_string to_bytes(_Elem __wchar) { + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI byte_string to_bytes(_Elem __wchar) { return to_bytes(std::addressof(__wchar), std::addressof(__wchar) + 1); } - _LIBCPP_HIDE_FROM_ABI byte_string to_bytes(const _Elem* __wptr) { + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI byte_string to_bytes(const _Elem* __wptr) { return to_bytes(__wptr, __wptr + char_traits<_Elem>::length(__wptr)); } - _LIBCPP_HIDE_FROM_ABI byte_string to_bytes(const wide_string& __wstr) { + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI byte_string to_bytes(const wide_string& __wstr) { return to_bytes(__wstr.data(), __wstr.data() + __wstr.size()); } - _LIBCPP_HIDE_FROM_ABI byte_string to_bytes(const _Elem* __first, const _Elem* __last); + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI byte_string to_bytes(const _Elem* __first, const _Elem* __last); - _LIBCPP_HIDE_FROM_ABI size_t converted() const _NOEXCEPT { return __cvtcount_; } - _LIBCPP_HIDE_FROM_ABI state_type state() const { return __cvtstate_; } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI size_t converted() const _NOEXCEPT { return __cvtcount_; } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI state_type state() const { return __cvtstate_; } }; _LIBCPP_SUPPRESS_DEPRECATED_PUSH @@ -174,9 +176,11 @@ wstring_convert<_Codecvt, _Elem, _WideAlloc, _ByteAlloc>::from_bytes(const char* return __wide_err_string_; } +_LIBCPP_SUPPRESS_DEPRECATED_PUSH template typename wstring_convert<_Codecvt, _Elem, _WideAlloc, _ByteAlloc>::byte_string wstring_convert<_Codecvt, _Elem, _WideAlloc, _ByteAlloc>::to_bytes(const _Elem* __frm, const _Elem* __frm_end) { + _LIBCPP_SUPPRESS_DEPRECATED_POP __cvtcount_ = 0; if (__cvtptr_ != nullptr) { byte_string __bs(2 * (__frm_end - __frm), char()); diff --git a/lib/libcxx/include/__log_hardening_failure b/lib/libcxx/include/__log_hardening_failure index d1805306f6b6e997cbcc9e2f5be2137c87461895..2b6065e9a19fbd430f19461d5877c9dd5a5fab85 100644 --- a/lib/libcxx/include/__log_hardening_failure +++ b/lib/libcxx/include/__log_hardening_failure @@ -24,7 +24,9 @@ _LIBCPP_BEGIN_NAMESPACE_STD // This function should never be called directly from the code -- it should only be called through the // `_LIBCPP_LOG_HARDENING_FAILURE` macro. +_LIBCPP_BEGIN_EXPLICIT_ABI_ANNOTATIONS [[__gnu__::__cold__]] _LIBCPP_EXPORTED_FROM_ABI void __log_hardening_failure(const char* __message) noexcept; +_LIBCPP_END_EXPLICIT_ABI_ANNOTATIONS // _LIBCPP_LOG_HARDENING_FAILURE(message) // diff --git a/lib/libcxx/include/__math/abs.h b/lib/libcxx/include/__math/abs.h index b780159f11ebf3b507de22b6dc35a953d9b2221d..a478d955d0b5630feefae93a28f46b54063b3598 100644 --- a/lib/libcxx/include/__math/abs.h +++ b/lib/libcxx/include/__math/abs.h @@ -63,6 +63,19 @@ template return __builtin_llabs(__x); } +#if _LIBCPP_HAS_INT128 +[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI inline __int128_t abs(__int128_t __x) _NOEXCEPT { return __x < 0 ? -__x : __x; } +#endif + +#if defined(__BITINT_MAXWIDTH__) +// _BitInt does not integer-promote, so without a same-type overload a narrow +// signed _BitInt would be an ambiguous call against abs(int/long/long long). +template +[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _BitInt(_Np) abs(_BitInt(_Np) __x) _NOEXCEPT { + return __x < 0 ? -__x : __x; +} +#endif + } // namespace __math _LIBCPP_END_NAMESPACE_STD diff --git a/lib/libcxx/include/__math/gamma.h b/lib/libcxx/include/__math/gamma.h index 693e111a84e99dfa1197cc6d2ed81ce0edcbdb86..a742ea42d9009dbc4e41808e27647a232bef0873 100644 --- a/lib/libcxx/include/__math/gamma.h +++ b/lib/libcxx/include/__math/gamma.h @@ -55,6 +55,34 @@ inline _LIBCPP_HIDE_FROM_ABI double tgamma(_A1 __x) _NOEXCEPT { return __builtin_tgamma((double)__x); } +// __lgamma_r +// +// POSIX systems provide a function named lgamma_r which is a reentrant version of lgamma. Use that +// whenever possible. However, we avoid re-declaring the actual function since different platforms +// declare it differently in the first place: instead use `asm` to get the compiler to call the right +// function. + +#if defined(_LIBCPP_MSVCRT_LIKE) // reentrant version is not available on Windows + +inline _LIBCPP_HIDE_FROM_ABI double __lgamma_r(double __d) _NOEXCEPT { return __builtin_lgamma(__d); } + +#else + +_LIBCPP_BEGIN_EXPLICIT_ABI_ANNOTATIONS +# if defined(_LIBCPP_OBJECT_FORMAT_MACHO) +double __lgamma_r_shim(double, int*) _NOEXCEPT __asm__("_lgamma_r"); +# else +double __lgamma_r_shim(double, int*) _NOEXCEPT __asm__("lgamma_r"); +# endif +_LIBCPP_END_EXPLICIT_ABI_ANNOTATIONS + +inline _LIBCPP_HIDE_FROM_ABI double __lgamma_r(double __d) _NOEXCEPT { + int __sign; + return __math::__lgamma_r_shim(__d, &__sign); +} + +#endif + } // namespace __math _LIBCPP_END_NAMESPACE_STD diff --git a/lib/libcxx/include/__math/special_functions.h b/lib/libcxx/include/__math/special_functions.h index 0b1c753a659adec9f408c37fced4427f6a372d1f..64d16aa88d2ee89a53a2f6113ee197da91767fc0 100644 --- a/lib/libcxx/include/__math/special_functions.h +++ b/lib/libcxx/include/__math/special_functions.h @@ -21,10 +21,10 @@ # pragma GCC system_header #endif -_LIBCPP_BEGIN_NAMESPACE_STD - #if _LIBCPP_STD_VER >= 17 +_LIBCPP_BEGIN_NAMESPACE_STD + template _LIBCPP_HIDE_FROM_ABI _Real __hermite(unsigned __n, _Real __x) { // The Hermite polynomial H_n(x). @@ -49,7 +49,7 @@ _LIBCPP_HIDE_FROM_ABI _Real __hermite(unsigned __n, _Real __x) { } if (!__math::isfinite(__H_n)) { - // Overflow occured. Two possible cases: + // Overflow occurred. Two possible cases: // n is odd: return infinity of the same sign as x. // n is even: return +Inf _Real __inf = std::numeric_limits<_Real>::infinity(); @@ -77,8 +77,8 @@ _LIBCPP_HIDE_FROM_ABI double hermite(unsigned __n, _Integer __x) { return std::hermite(__n, static_cast(__x)); } -#endif // _LIBCPP_STD_VER >= 17 - _LIBCPP_END_NAMESPACE_STD +#endif // _LIBCPP_STD_VER >= 17 + #endif // _LIBCPP___MATH_SPECIAL_FUNCTIONS_H diff --git a/lib/libcxx/include/__mbstate_t.h b/lib/libcxx/include/__mbstate_t.h index c23ea7113ca708e168bdc837f5c7b3ec554b3df4..1ce5f0cd6da1d02f6d9f8d918884d65c11e77156 100644 --- a/lib/libcxx/include/__mbstate_t.h +++ b/lib/libcxx/include/__mbstate_t.h @@ -39,10 +39,14 @@ # define __NEED_mbstate_t # include # undef __NEED_mbstate_t +#elif _LIBCPP_LIBC_LLVM_LIBC +# include #elif __has_include() # include // works on most Unixes #elif __has_include() # include // works on Darwin +#elif __has_include() +# include // works for Android #elif __has_include_next() # include_next // use the C standard provider of mbstate_t if present #elif __has_include_next() diff --git a/lib/libcxx/include/__mdspan/aligned_accessor.h b/lib/libcxx/include/__mdspan/aligned_accessor.h index 2b8d4c52d87374f099f77d09830df47cbcf0c778..934b0d42abe4d1e8bf7b6d941673b5f75ff6508a 100644 --- a/lib/libcxx/include/__mdspan/aligned_accessor.h +++ b/lib/libcxx/include/__mdspan/aligned_accessor.h @@ -33,10 +33,10 @@ _LIBCPP_PUSH_MACROS #include <__undef_macros> -_LIBCPP_BEGIN_NAMESPACE_STD - #if _LIBCPP_STD_VER >= 26 +_LIBCPP_BEGIN_NAMESPACE_STD + template struct aligned_accessor { static_assert(_ByteAlignment != 0 && (_ByteAlignment & (_ByteAlignment - 1)) == 0, @@ -78,10 +78,10 @@ struct aligned_accessor { } }; -#endif // _LIBCPP_STD_VER >= 26 - _LIBCPP_END_NAMESPACE_STD +#endif // _LIBCPP_STD_VER >= 26 + _LIBCPP_POP_MACROS #endif // _LIBCPP___MDSPAN_ALIGNED_ACCESSOR_H diff --git a/lib/libcxx/include/__mdspan/extents.h b/lib/libcxx/include/__mdspan/extents.h index d16bbd2af44f1af82dc936d0f833a268f8aa6c37..99366b9ca9cc48cfe9fd0c73626d1dda2b19dbdb 100644 --- a/lib/libcxx/include/__mdspan/extents.h +++ b/lib/libcxx/include/__mdspan/extents.h @@ -21,12 +21,16 @@ #include <__config> #include <__concepts/arithmetic.h> +#include <__concepts/same_as.h> #include <__type_traits/common_type.h> #include <__type_traits/integer_traits.h> #include <__type_traits/is_convertible.h> #include <__type_traits/is_nothrow_constructible.h> #include <__type_traits/is_signed.h> #include <__type_traits/make_unsigned.h> +#include <__type_traits/remove_cvref.h> +#include <__utility/as_const.h> +#include <__utility/forward.h> #include <__utility/integer_sequence.h> #include <__utility/unreachable.h> #include @@ -46,25 +50,6 @@ _LIBCPP_BEGIN_NAMESPACE_STD #if _LIBCPP_STD_VER >= 23 namespace __mdspan_detail { - -// ------------------------------------------------------------------ -// ------------ __static_array -------------------------------------- -// ------------------------------------------------------------------ -// array like class which provides an array of static values with get -template -struct __static_array { - static constexpr array<_Tp, sizeof...(_Values)> __array = {_Values...}; - -public: - _LIBCPP_HIDE_FROM_ABI static constexpr size_t __size() { return sizeof...(_Values); } - _LIBCPP_HIDE_FROM_ABI static constexpr _Tp __get(size_t __index) noexcept { return __array[__index]; } - - template - _LIBCPP_HIDE_FROM_ABI static constexpr _Tp __get() { - return __get(_Index); - } -}; - // ------------------------------------------------------------------ // ------------ __possibly_empty_array ----------------------------- // ------------------------------------------------------------------ @@ -117,35 +102,28 @@ struct __static_partial_sums { // array like class which has a mix of static and runtime values but // only stores the runtime values. // The type of the static and the runtime values can be different. -// The position of a dynamic value is indicated through a tag value. -template +// The position of a dynamic value is indicated by dynamic_extent. +template struct __maybe_static_array { - static_assert(is_convertible<_TStatic, _TDynamic>::value, + static_assert(is_convertible_v<_TStatic, _TDynamic>, "__maybe_static_array: _TStatic must be convertible to _TDynamic"); - static_assert(is_convertible<_TDynamic, _TStatic>::value, + static_assert(is_convertible_v<_TDynamic, _TStatic>, "__maybe_static_array: _TDynamic must be convertible to _TStatic"); private: // Static values member static constexpr size_t __size_ = sizeof...(_Values); - static constexpr size_t __size_dynamic_ = ((_Values == _DynTag) + ... + 0); - using _StaticValues _LIBCPP_NODEBUG = __static_array<_TStatic, _Values...>; + static constexpr size_t __size_dynamic_ = ((_Values == dynamic_extent) + ... + 0); using _DynamicValues _LIBCPP_NODEBUG = __possibly_empty_array<_TDynamic, __size_dynamic_>; - // Dynamic values member + static constexpr array<_TStatic, sizeof...(_Values)> __static_values_ = {_Values...}; _LIBCPP_NO_UNIQUE_ADDRESS _DynamicValues __dyn_vals_; // static mapping of indices to the position in the dynamic values array - using _DynamicIdxMap _LIBCPP_NODEBUG = __static_partial_sums(_Values == _DynTag)...>; - - template - _LIBCPP_HIDE_FROM_ABI static constexpr _DynamicValues __zeros(index_sequence<_Indices...>) noexcept { - return _DynamicValues{((void)_Indices, 0)...}; - } + using _DynamicIdxMap _LIBCPP_NODEBUG = __static_partial_sums(_Values == dynamic_extent)...>; public: - _LIBCPP_HIDE_FROM_ABI constexpr __maybe_static_array() noexcept - : __dyn_vals_{__zeros(make_index_sequence<__size_dynamic_>())} {} + _LIBCPP_HIDE_FROM_ABI constexpr __maybe_static_array() noexcept : __dyn_vals_{} {} // constructors from dynamic values only -- this covers the case for rank() == 0 template @@ -169,8 +147,8 @@ public: static_assert(sizeof...(_DynVals) == __size_, "Invalid number of values."); _TDynamic __values[__size_] = {static_cast<_TDynamic>(__vals)...}; for (size_t __i = 0; __i < __size_; __i++) { - _TStatic __static_val = _StaticValues::__get(__i); - if (__static_val == _DynTag) { + _TStatic __static_val = __static_values_[__i]; + if (__static_val == dynamic_extent) { __dyn_vals_[_DynamicIdxMap::__get(__i)] = __values[__i]; } else // Not catching this could lead to out of bounds errors later @@ -188,8 +166,8 @@ public: _LIBCPP_HIDE_FROM_ABI constexpr __maybe_static_array(const span<_Tp, _Size>& __vals) { static_assert(_Size == __size_ || __size_ == dynamic_extent); for (size_t __i = 0; __i < __size_; __i++) { - _TStatic __static_val = _StaticValues::__get(__i); - if (__static_val == _DynTag) { + _TStatic __static_val = __static_values_[__i]; + if (__static_val == dynamic_extent) { __dyn_vals_[_DynamicIdxMap::__get(__i)] = static_cast<_TDynamic>(__vals[__i]); } else // Not catching this could lead to out of bounds errors later @@ -205,13 +183,15 @@ public: // access functions _LIBCPP_HIDE_FROM_ABI static constexpr _TStatic __static_value(size_t __i) noexcept { _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__i < __size_, "extents access: index must be less than rank"); - return _StaticValues::__get(__i); + return __static_values_[__i]; } _LIBCPP_HIDE_FROM_ABI constexpr _TDynamic __value(size_t __i) const { _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__i < __size_, "extents access: index must be less than rank"); - _TStatic __static_val = _StaticValues::__get(__i); - return __static_val == _DynTag ? __dyn_vals_[_DynamicIdxMap::__get(__i)] : static_cast<_TDynamic>(__static_val); + _TStatic __static_val = __static_values_[__i]; + return __static_val == dynamic_extent + ? __dyn_vals_[_DynamicIdxMap::__get(__i)] + : static_cast<_TDynamic>(__static_val); } _LIBCPP_HIDE_FROM_ABI constexpr _TDynamic operator[](size_t __i) const { _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__i < __size_, "extents access: index must be less than rank"); @@ -252,19 +232,6 @@ _LIBCPP_HIDE_FROM_ABI constexpr bool __is_representable_as(_From __value) { return true; } -template -_LIBCPP_HIDE_FROM_ABI constexpr bool __are_representable_as(_From... __values) { - return (__mdspan_detail::__is_representable_as<_To>(__values) && ... && true); -} - -template -_LIBCPP_HIDE_FROM_ABI constexpr bool __are_representable_as(span<_From, _Size> __values) { - for (size_t __i = 0; __i < _Size; __i++) - if (!__mdspan_detail::__is_representable_as<_To>(__values[__i])) - return false; - return true; -} - } // namespace __mdspan_detail // ------------------------------------------------------------------ @@ -293,10 +260,45 @@ private: static constexpr rank_type __rank_dynamic_ = ((_Extents == dynamic_extent) + ... + 0); // internal storage type using __maybe_static_array - using _Values _LIBCPP_NODEBUG = - __mdspan_detail::__maybe_static_array<_IndexType, size_t, dynamic_extent, _Extents...>; + using _Values _LIBCPP_NODEBUG = __mdspan_detail::__maybe_static_array<_IndexType, size_t, _Extents...>; [[no_unique_address]] _Values __vals_; + template + _LIBCPP_HIDE_FROM_ABI static constexpr index_type __checked_index_cast(_OtherIndexType&& __value) noexcept { + using _OtherType = remove_cvref_t<_OtherIndexType>; + if constexpr (integral<_OtherType> && !same_as<_OtherType, bool>) { + _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS( + __mdspan_detail::__is_representable_as(__value), + "extents ctor: arguments must be representable as index_type and nonnegative"); + return static_cast(__value); + } else { + auto __converted_val = static_cast(std::forward<_OtherIndexType>(__value)); + if constexpr (is_signed_v) { + _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS( + __converted_val >= 0, "extents ctor: arguments must be representable as index_type and nonnegative"); + } + return __converted_val; + } + } + + template + _LIBCPP_HIDE_FROM_ABI static constexpr _Values + __representability_checked_cast(_OtherIndexTypes&&... __values) noexcept { + return _Values{__checked_index_cast(std::forward<_OtherIndexTypes>(__values))...}; + } + + template + _LIBCPP_HIDE_FROM_ABI static constexpr _Values + __representability_checked_cast(const array<_OtherIndexType, _Size>& __exts, index_sequence<_Idxs...>) noexcept { + return __representability_checked_cast(__exts[_Idxs]...); + } + + template + _LIBCPP_HIDE_FROM_ABI static constexpr _Values + __representability_checked_cast(const span<_OtherIndexType, _Size>& __exts, index_sequence<_Idxs...>) noexcept { + return __representability_checked_cast(std::as_const(__exts[_Idxs])...); + } + public: // [mdspan.extents.obs], observers of multidimensional index space [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static constexpr rank_type rank() noexcept { return __rank_; } @@ -319,12 +321,9 @@ public: (is_nothrow_constructible_v && ...) && (sizeof...(_OtherIndexTypes) == __rank_ || sizeof...(_OtherIndexTypes) == __rank_dynamic_)) _LIBCPP_HIDE_FROM_ABI constexpr explicit extents(_OtherIndexTypes... __dynvals) noexcept - : __vals_(static_cast(__dynvals)...) { - // Not catching this could lead to out of bounds errors later - // e.g. mdspan m(ptr, dextents(200u)); leads to an extent of -56 on m - _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__mdspan_detail::__are_representable_as(__dynvals...), - "extents ctor: arguments must be representable as index_type and nonnegative"); - } + // Not catching this could lead to out of bounds errors later + // e.g. mdspan m(ptr, dextents(200u)); leads to an extent of -56 on m + : __vals_(__representability_checked_cast(std::move(__dynvals)...)) {} template requires(is_convertible_v && @@ -332,12 +331,9 @@ public: (_Size == __rank_ || _Size == __rank_dynamic_)) explicit(_Size != __rank_dynamic_) _LIBCPP_HIDE_FROM_ABI constexpr extents(const array<_OtherIndexType, _Size>& __exts) noexcept - : __vals_(span(__exts)) { - // Not catching this could lead to out of bounds errors later - // e.g. mdspan m(ptr, dextents(array(200))); leads to an extent of -56 on m - _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__mdspan_detail::__are_representable_as(span(__exts)), - "extents ctor: arguments must be representable as index_type and nonnegative"); - } + // Not catching this could lead to out of bounds errors later + // e.g. mdspan m(ptr, dextents(200u)); leads to an extent of -56 on m + : __vals_(__representability_checked_cast(__exts, make_index_sequence<_Size>())) {} template requires(is_convertible_v && @@ -345,13 +341,9 @@ public: (_Size == __rank_ || _Size == __rank_dynamic_)) explicit(_Size != __rank_dynamic_) _LIBCPP_HIDE_FROM_ABI constexpr extents(const span<_OtherIndexType, _Size>& __exts) noexcept - : __vals_(__exts) { - // Not catching this could lead to out of bounds errors later - // e.g. array a{200u}; mdspan> m(ptr, extents(span(a))); leads to an extent of -56 - // on m - _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__mdspan_detail::__are_representable_as(__exts), - "extents ctor: arguments must be representable as index_type and nonnegative"); - } + // Not catching this could lead to out of bounds errors later + // e.g. mdspan m(ptr, dextents(200u)); leads to an extent of -56 on m + : __vals_(__representability_checked_cast(__exts, make_index_sequence<_Size>())) {} private: // Function to construct extents storage from other extents. @@ -433,6 +425,15 @@ public: } return true; } + + template + _LIBCPP_HIDE_FROM_ABI static constexpr auto __index_cast(_OtherIndexType&& __i) noexcept { + using _OtherIndex = remove_cvref_t<_OtherIndexType>; + if constexpr (integral<_OtherIndex> && !same_as<_OtherIndex, bool>) + return __i; + else + return static_cast(std::forward<_OtherIndexType>(__i)); + } }; // Recursive helper classes to implement dextents alias for extents @@ -465,15 +466,9 @@ using dims = dextents<_IndexType, _Rank>; # endif // Deduction guide for extents -# if _LIBCPP_STD_VER >= 26 template requires(is_convertible_v<_IndexTypes, size_t> && ...) explicit extents(_IndexTypes...) -> extents...>; -# else -template - requires(is_convertible_v<_IndexTypes, size_t> && ...) -explicit extents(_IndexTypes...) -> extents; -# endif namespace __mdspan_detail { diff --git a/lib/libcxx/include/__mdspan/layout_left.h b/lib/libcxx/include/__mdspan/layout_left.h index 2f515afb6c8608829f25a98c431222197da48448..fb1b59555b254b98cdf951c27c74883427bdc740 100644 --- a/lib/libcxx/include/__mdspan/layout_left.h +++ b/lib/libcxx/include/__mdspan/layout_left.h @@ -47,9 +47,9 @@ public: "layout_left::mapping template argument must be a specialization of extents."); using extents_type = _Extents; - using index_type = typename extents_type::index_type; - using size_type = typename extents_type::size_type; - using rank_type = typename extents_type::rank_type; + using index_type = extents_type::index_type; + using size_type = extents_type::size_type; + using rank_type = extents_type::rank_type; using layout_type = layout_left; private: diff --git a/lib/libcxx/include/__mdspan/layout_right.h b/lib/libcxx/include/__mdspan/layout_right.h index ccfbd23e28ad760b07b304cfaf0d3210f1d4c60f..7cb828022ea8e0cbf843568ce67a3e94c7607ee2 100644 --- a/lib/libcxx/include/__mdspan/layout_right.h +++ b/lib/libcxx/include/__mdspan/layout_right.h @@ -47,9 +47,9 @@ public: "layout_right::mapping template argument must be a specialization of extents."); using extents_type = _Extents; - using index_type = typename extents_type::index_type; - using size_type = typename extents_type::size_type; - using rank_type = typename extents_type::rank_type; + using index_type = extents_type::index_type; + using size_type = extents_type::size_type; + using rank_type = extents_type::rank_type; using layout_type = layout_right; private: diff --git a/lib/libcxx/include/__mdspan/layout_stride.h b/lib/libcxx/include/__mdspan/layout_stride.h index eb22475756fde3c60bb20aa82421e2f10c4b788f..5ee4672e0d1cfb49e9c1166e6c996f5dfc7c3364 100644 --- a/lib/libcxx/include/__mdspan/layout_stride.h +++ b/lib/libcxx/include/__mdspan/layout_stride.h @@ -72,9 +72,9 @@ public: "layout_stride::mapping template argument must be a specialization of extents."); using extents_type = _Extents; - using index_type = typename extents_type::index_type; - using size_type = typename extents_type::size_type; - using rank_type = typename extents_type::rank_type; + using index_type = extents_type::index_type; + using size_type = extents_type::size_type; + using rank_type = extents_type::rank_type; using layout_type = layout_stride; private: @@ -296,38 +296,26 @@ public: } _LIBCPP_HIDE_FROM_ABI static constexpr bool is_always_unique() noexcept { return true; } - _LIBCPP_HIDE_FROM_ABI static constexpr bool is_always_exhaustive() noexcept { return false; } + _LIBCPP_HIDE_FROM_ABI static constexpr bool is_always_exhaustive() noexcept { + if constexpr (__rank_ == 0) + return true; + for (size_t __r = 0; __r < __rank_; ++__r) + if (extents_type::static_extent(__r) == 0) + return true; + return false; + } _LIBCPP_HIDE_FROM_ABI static constexpr bool is_always_strided() noexcept { return true; } _LIBCPP_HIDE_FROM_ABI static constexpr bool is_unique() noexcept { return true; } - // The answer of this function is fairly complex in the case where one or more - // extents are zero. - // Technically it is meaningless to query is_exhaustive() in that case, but unfortunately - // the way the standard defines this function, we can't give a simple true or false then. _LIBCPP_HIDE_FROM_ABI constexpr bool is_exhaustive() const noexcept { - if constexpr (__rank_ == 0) + if constexpr (is_always_exhaustive()) return true; - else { - index_type __span_size = required_span_size(); - if (__span_size == static_cast(0)) { - if constexpr (__rank_ == 1) - return __strides_[0] == 1; - else { - rank_type __r_largest = 0; - for (rank_type __r = 1; __r < __rank_; __r++) - if (__strides_[__r] > __strides_[__r_largest]) - __r_largest = __r; - for (rank_type __r = 0; __r < __rank_; __r++) - if (__extents_.extent(__r) == 0 && __r != __r_largest) - return false; - return true; - } - } else { - return required_span_size() == [&](index_sequence<_Pos...>) { - return (__extents_.extent(_Pos) * ... * static_cast(1)); - }(make_index_sequence<__rank_>()); - } - } + index_type __span_size = required_span_size(); + if (__span_size == static_cast(0)) + return true; + return __span_size == [&](index_sequence<_Pos...>) { + return (__extents_.extent(_Pos) * ... * static_cast(1)); + }(make_index_sequence<__rank_>()); } _LIBCPP_HIDE_FROM_ABI static constexpr bool is_strided() noexcept { return true; } diff --git a/lib/libcxx/include/__mdspan/mdspan.h b/lib/libcxx/include/__mdspan/mdspan.h index 449baea43f2d763a52917a338497d07c267c366a..3b78f792770f0618b708cf9e78beb120a00dbdd4 100644 --- a/lib/libcxx/include/__mdspan/mdspan.h +++ b/lib/libcxx/include/__mdspan/mdspan.h @@ -30,6 +30,7 @@ #include <__type_traits/is_constructible.h> #include <__type_traits/is_convertible.h> #include <__type_traits/is_nothrow_constructible.h> +#include <__type_traits/is_object.h> #include <__type_traits/is_pointer.h> #include <__type_traits/is_same.h> #include <__type_traits/rank.h> @@ -37,9 +38,11 @@ #include <__type_traits/remove_cv.h> #include <__type_traits/remove_pointer.h> #include <__type_traits/remove_reference.h> +#include <__utility/as_const.h> #include <__utility/integer_sequence.h> #include #include +#include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header @@ -66,6 +69,9 @@ class mdspan { private: static_assert(__mdspan_detail::__is_extents_v<_Extents>, "mdspan: Extents template parameter must be a specialization of extents."); + static_assert( + is_object_v<_ElementType> && requires { sizeof(_ElementType); }, + "mdspan: ElementType template parameter must be a complete object type"); static_assert(!is_array_v<_ElementType>, "mdspan: ElementType template parameter may not be an array type"); static_assert(!is_abstract_v<_ElementType>, "mdspan: ElementType template parameter may not be an abstract class"); static_assert(is_same_v<_ElementType, typename _AccessorPolicy::element_type>, @@ -78,14 +84,14 @@ public: using extents_type = _Extents; using layout_type = _LayoutPolicy; using accessor_type = _AccessorPolicy; - using mapping_type = typename layout_type::template mapping; + using mapping_type = layout_type::template mapping; using element_type = _ElementType; using value_type = remove_cv_t; - using index_type = typename extents_type::index_type; - using size_type = typename extents_type::size_type; - using rank_type = typename extents_type::rank_type; - using data_handle_type = typename accessor_type::data_handle_type; - using reference = typename accessor_type::reference; + using index_type = extents_type::index_type; + using size_type = extents_type::size_type; + using rank_type = extents_type::rank_type; + using data_handle_type = accessor_type::data_handle_type; + using reference = accessor_type::reference; [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static constexpr rank_type rank() noexcept { return extents_type::rank(); } [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static constexpr rank_type rank_dynamic() noexcept { @@ -187,11 +193,11 @@ public: (is_nothrow_constructible_v && ...) && (sizeof...(_OtherIndexTypes) == rank())) [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr reference operator[](_OtherIndexTypes... __indices) const { - // Note the standard layouts would also check this, but user provided ones may not, so we - // check the precondition here - _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__mdspan_detail::__is_multidimensional_index_in(extents(), __indices...), - "mdspan: operator[] out of bounds access"); - return __acc_.access(__ptr_, __map_(static_cast(std::move(__indices))...)); + return [&](_IndexTypes... __idxs) -> reference { + _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__mdspan_detail::__is_multidimensional_index_in(extents(), __idxs...), + "mdspan: operator[] out of bounds access"); + return __acc_.access(__ptr_, __map_(static_cast(std::move(__idxs))...)); + }(extents_type::__index_cast(std::move(__indices))...); } template @@ -200,7 +206,7 @@ public: [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr reference operator[](const array< _OtherIndexType, rank()>& __indices) const { return __acc_.access(__ptr_, [&](index_sequence<_Idxs...>) { - return __map_(__indices[_Idxs]...); + return __map_(extents_type::__index_cast(__indices[_Idxs])...); }(make_index_sequence())); } @@ -209,10 +215,41 @@ public: is_nothrow_constructible_v) [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr reference operator[](span<_OtherIndexType, rank()> __indices) const { return __acc_.access(__ptr_, [&](index_sequence<_Idxs...>) { - return __map_(__indices[_Idxs]...); + return __map_(extents_type::__index_cast(__indices[_Idxs])...); }(make_index_sequence())); } +# if _LIBCPP_STD_VER >= 26 + template + requires((is_convertible_v<_OtherIndexTypes, index_type> && ...) && + (is_nothrow_constructible_v && ...) && + (sizeof...(_OtherIndexTypes) == rank())) + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr reference at(_OtherIndexTypes... __indices) const { + if (!__mdspan_detail::__is_multidimensional_index_in(__map_.extents(), __indices...)) { + __throw_out_of_range(); + } + return (*this)[extents_type::__index_cast(std::move(__indices))...]; + } + + template + requires(is_convertible_v && + is_nothrow_constructible_v) + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr reference at(const array<_OtherIndexType, rank()>& __indices) const { + return [&](index_sequence<_Idxs...>) -> reference { + return at(extents_type::__index_cast(__indices[_Idxs])...); + }(make_index_sequence()); + } + + template + requires(is_convertible_v && + is_nothrow_constructible_v) + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr reference at(span<_OtherIndexType, rank()> __indices) const { + return [&](index_sequence<_Idxs...>) -> reference { + return at(extents_type::__index_cast(std::as_const(__indices[_Idxs]))...); + }(make_index_sequence()); + } +# endif + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr size_type size() const noexcept { // Could leave this as only checked in debug mode: semantically size() is never // guaranteed to be related to any accessible range @@ -269,19 +306,16 @@ private: template friend class mdspan; + +# if _LIBCPP_STD_VER >= 26 + _LIBCPP_HIDE_FROM_ABI void __throw_out_of_range() const { std::__throw_out_of_range("mdspan"); } +# endif }; -# if _LIBCPP_STD_VER >= 26 template requires((is_convertible_v<_OtherIndexTypes, size_t> && ...) && (sizeof...(_OtherIndexTypes) > 0)) explicit mdspan(_ElementType*, _OtherIndexTypes...) -> mdspan<_ElementType, extents...>>; -# else -template - requires((is_convertible_v<_OtherIndexTypes, size_t> && ...) && (sizeof...(_OtherIndexTypes) > 0)) -explicit mdspan(_ElementType*, _OtherIndexTypes...) - -> mdspan<_ElementType, dextents>; -# endif template requires(is_pointer_v>) @@ -309,7 +343,7 @@ mdspan(_ElementType*, const _MappingType&) -> mdspan<_ElementType, typename _MappingType::extents_type, typename _MappingType::layout_type>; template -mdspan(const typename _AccessorType::data_handle_type, const _MappingType&, const _AccessorType&) +mdspan(typename _AccessorType::data_handle_type, const _MappingType&, const _AccessorType&) -> mdspan -#include - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -#if _LIBCPP_HAS_LIBRARY_ALIGNED_ALLOCATION - -// Low-level helpers to call the aligned allocation and deallocation functions -// on the target platform. This is used to implement libc++'s own memory -// allocation routines -- if you need to allocate memory inside the library, -// chances are that you want to use `__libcpp_allocate` instead. -// -// Returns the allocated memory, or `nullptr` on failure. -inline _LIBCPP_HIDE_FROM_ABI void* __libcpp_aligned_alloc(std::size_t __alignment, std::size_t __size) { -# if defined(_LIBCPP_MSVCRT_LIKE) - return ::_aligned_malloc(__size, __alignment); -# elif _LIBCPP_STD_VER >= 17 && _LIBCPP_HAS_C11_ALIGNED_ALLOC - // aligned_alloc() requires that __size is a multiple of __alignment, - // but for C++ [new.delete.general], only states "if the value of an - // alignment argument passed to any of these functions is not a valid - // alignment value, the behavior is undefined". - // To handle calls such as ::operator new(1, std::align_val_t(128)), we - // round __size up to the next multiple of __alignment. - size_t __rounded_size = (__size + __alignment - 1) & ~(__alignment - 1); - // Rounding up could have wrapped around to zero, so we have to add another - // max() ternary to the actual call site to avoid succeeded in that case. - return ::aligned_alloc(__alignment, __size > __rounded_size ? __size : __rounded_size); -# else - void* __result = nullptr; - (void)::posix_memalign(&__result, __alignment, __size); - // If posix_memalign fails, __result is unmodified so we still return `nullptr`. - return __result; -# endif -} - -inline _LIBCPP_HIDE_FROM_ABI void __libcpp_aligned_free(void* __ptr) { -# if defined(_LIBCPP_MSVCRT_LIKE) - ::_aligned_free(__ptr); -# else - ::free(__ptr); -# endif -} - -#endif // _LIBCPP_HAS_LIBRARY_ALIGNED_ALLOCATION - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___MEMORY_ALIGNED_ALLOC_H diff --git a/lib/libcxx/include/__memory/allocator_traits.h b/lib/libcxx/include/__memory/allocator_traits.h index b38d7293a3fd397be3b31457d6f11defa513fa93..7038885a8b24f69141d122f5dcc7a2cf4ad5d824 100644 --- a/lib/libcxx/include/__memory/allocator_traits.h +++ b/lib/libcxx/include/__memory/allocator_traits.h @@ -11,6 +11,7 @@ #define _LIBCPP___MEMORY_ALLOCATOR_TRAITS_H #include <__config> +#include <__cstddef/ptrdiff_t.h> #include <__cstddef/size_t.h> #include <__fwd/memory.h> #include <__memory/construct_at.h> @@ -223,8 +224,13 @@ _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(allocation_result); #endif // _LIBCPP_STD_VER +template +struct allocator_traits; + +// We have a base class that can be specialized for different allocators, since the metaprogramming to get the aliases +// is quite expensive and the definition of these aliases is usually quite trivial in the end. template -struct allocator_traits { +struct __allocator_traits_base { using allocator_type = _Alloc; using value_type = typename allocator_type::value_type; using pointer = __pointer; @@ -253,6 +259,60 @@ struct allocator_traits { using other = allocator_traits::other>; }; #endif // _LIBCPP_CXX03_LANG +}; + +template +struct __allocator_traits_base > { + using allocator_type = allocator<_Tp>; + using value_type = _Tp; + using pointer = _Tp*; + using const_pointer = const _Tp*; + using void_pointer = void*; + using const_void_pointer = const void*; + using difference_type = ptrdiff_t; + using size_type = size_t; + using propagate_on_container_copy_assignment = false_type; + using propagate_on_container_move_assignment = true_type; + using propagate_on_container_swap = false_type; + using is_always_equal = true_type; + +#ifndef _LIBCPP_CXX03_LANG + template + using rebind_alloc = allocator<_Up>; + template + using rebind_traits = allocator_traits >; +#else + template + struct rebind_alloc { + using other = allocator<_Up>; + }; + template + struct rebind_traits { + using other = allocator_traits >; + }; +#endif +}; + +template +struct allocator_traits : __allocator_traits_base<_Alloc> { + using __base _LIBCPP_NODEBUG = __allocator_traits_base<_Alloc>; + + using allocator_type = typename __base::allocator_type; + using value_type = typename __base::value_type; + using pointer = typename __base::pointer; + using const_pointer = typename __base::const_pointer; + using void_pointer = typename __base::void_pointer; + using const_void_pointer = typename __base::const_void_pointer; + using difference_type = typename __base::difference_type; + using size_type = typename __base::size_type; + using propagate_on_container_copy_assignment = typename __base::propagate_on_container_copy_assignment; + using propagate_on_container_move_assignment = typename __base::propagate_on_container_move_assignment; + using is_always_equal = typename __base::is_always_equal; + + template + using rebind_alloc = typename __base::template rebind_alloc<_Tp>; + template + using rebind_traits = typename __base::template rebind_traits<_Tp>; [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 static pointer allocate(allocator_type& __a, size_type __n) { diff --git a/lib/libcxx/include/__memory/compressed_pair.h b/lib/libcxx/include/__memory/compressed_pair.h index f1f1c920453cf6ad117f798cfda7e3fa96eb87ce..8fa0e64714f2bba6e6c9a8a0773758c0dd049e1b 100644 --- a/lib/libcxx/include/__memory/compressed_pair.h +++ b/lib/libcxx/include/__memory/compressed_pair.h @@ -20,8 +20,6 @@ # pragma GCC system_header #endif -_LIBCPP_BEGIN_NAMESPACE_STD - // ================================================================================================================== // // The utilites here are for staying ABI compatible with the legacy `__compressed_pair`. They should not be used // // for new data structures. Use `_LIBCPP_NO_UNIQUE_ADDRESS` for new data structures instead (but make sure you // @@ -59,6 +57,8 @@ _LIBCPP_BEGIN_NAMESPACE_STD #ifndef _LIBCPP_ABI_NO_COMPRESSED_PAIR_PADDING +_LIBCPP_BEGIN_NAMESPACE_STD + template inline const size_t __compressed_pair_alignment = _LIBCPP_ALIGNOF(_Tp); @@ -94,16 +94,6 @@ class __compressed_pair_padding<_ToPad, true> {}; _LIBCPP_NO_UNIQUE_ADDRESS ::std::__compressed_pair_padding _LIBCPP_CONCAT3(__padding1_, __LINE__, _); \ _LIBCPP_NO_UNIQUE_ADDRESS T2 Initializer2; \ _LIBCPP_NO_UNIQUE_ADDRESS ::std::__compressed_pair_padding _LIBCPP_CONCAT3(__padding2_, __LINE__, _) - -# define _LIBCPP_COMPRESSED_TRIPLE(T1, Initializer1, T2, Initializer2, T3, Initializer3) \ - _LIBCPP_NO_UNIQUE_ADDRESS \ - __attribute__((__aligned__(::std::__compressed_pair_alignment), \ - __aligned__(::std::__compressed_pair_alignment))) T1 Initializer1; \ - _LIBCPP_NO_UNIQUE_ADDRESS ::std::__compressed_pair_padding _LIBCPP_CONCAT3(__padding1_, __LINE__, _); \ - _LIBCPP_NO_UNIQUE_ADDRESS T2 Initializer2; \ - _LIBCPP_NO_UNIQUE_ADDRESS ::std::__compressed_pair_padding _LIBCPP_CONCAT3(__padding2_, __LINE__, _); \ - _LIBCPP_NO_UNIQUE_ADDRESS T3 Initializer3; \ - _LIBCPP_NO_UNIQUE_ADDRESS ::std::__compressed_pair_padding _LIBCPP_CONCAT3(__padding3_, __LINE__, _) # else # define _LIBCPP_COMPRESSED_PAIR(T1, Initializer1, T2, Initializer2) \ struct { \ @@ -112,31 +102,16 @@ class __compressed_pair_padding<_ToPad, true> {}; _LIBCPP_NO_UNIQUE_ADDRESS T2 Initializer2; \ _LIBCPP_NO_UNIQUE_ADDRESS ::std::__compressed_pair_padding _LIBCPP_CONCAT3(__padding2_, __LINE__, _); \ } - -# define _LIBCPP_COMPRESSED_TRIPLE(T1, Initializer1, T2, Initializer2, T3, Initializer3) \ - struct { \ - _LIBCPP_NO_UNIQUE_ADDRESS T1 Initializer1; \ - _LIBCPP_NO_UNIQUE_ADDRESS ::std::__compressed_pair_padding _LIBCPP_CONCAT3(__padding1_, __LINE__, _); \ - _LIBCPP_NO_UNIQUE_ADDRESS T2 Initializer2; \ - _LIBCPP_NO_UNIQUE_ADDRESS ::std::__compressed_pair_padding _LIBCPP_CONCAT3(__padding2_, __LINE__, _); \ - _LIBCPP_NO_UNIQUE_ADDRESS T3 Initializer3; \ - _LIBCPP_NO_UNIQUE_ADDRESS ::std::__compressed_pair_padding _LIBCPP_CONCAT3(__padding3_, __LINE__, _); \ - } # endif +_LIBCPP_END_NAMESPACE_STD + #else # define _LIBCPP_COMPRESSED_ELEMENT(T1, Initializer1) _LIBCPP_NO_UNIQUE_ADDRESS T1 Initializer1 # define _LIBCPP_COMPRESSED_PAIR(T1, Name1, T2, Name2) \ _LIBCPP_NO_UNIQUE_ADDRESS T1 Name1; \ _LIBCPP_NO_UNIQUE_ADDRESS T2 Name2 - -# define _LIBCPP_COMPRESSED_TRIPLE(T1, Name1, T2, Name2, T3, Name3) \ - _LIBCPP_NO_UNIQUE_ADDRESS T1 Name1; \ - _LIBCPP_NO_UNIQUE_ADDRESS T2 Name2; \ - _LIBCPP_NO_UNIQUE_ADDRESS T3 Name3 #endif // _LIBCPP_ABI_NO_COMPRESSED_PAIR_PADDING -_LIBCPP_END_NAMESPACE_STD - #endif // _LIBCPP___MEMORY_COMPRESSED_PAIR_H diff --git a/lib/libcxx/include/__memory/inout_ptr.h b/lib/libcxx/include/__memory/inout_ptr.h index 0fa685afb2ee639627e957d4ac1b62e243a95d80..f654b44e03f620aad7005169ee53f2d1ea0b0305 100644 --- a/lib/libcxx/include/__memory/inout_ptr.h +++ b/lib/libcxx/include/__memory/inout_ptr.h @@ -11,10 +11,9 @@ #define _LIBCPP___INOUT_PTR_H #include <__config> +#include <__fwd/memory.h> #include <__memory/addressof.h> #include <__memory/pointer_traits.h> -#include <__memory/shared_ptr.h> -#include <__memory/unique_ptr.h> #include <__type_traits/is_pointer.h> #include <__type_traits/is_same.h> #include <__type_traits/is_specialization.h> @@ -30,10 +29,10 @@ _LIBCPP_PUSH_MACROS #include <__undef_macros> -_LIBCPP_BEGIN_NAMESPACE_STD - #if _LIBCPP_STD_VER >= 23 +_LIBCPP_BEGIN_NAMESPACE_STD + template class inout_ptr_t { static_assert(!__is_specialization_v<_Smart, shared_ptr>, "std::shared_ptr<> is not supported with std::inout_ptr."); @@ -101,10 +100,10 @@ template return std::inout_ptr_t<_Smart, _Ptr, _Args&&...>(__s, std::forward<_Args>(__args)...); } -#endif // _LIBCPP_STD_VER >= 23 - _LIBCPP_END_NAMESPACE_STD +#endif // _LIBCPP_STD_VER >= 23 + _LIBCPP_POP_MACROS #endif // _LIBCPP___INOUT_PTR_H diff --git a/lib/libcxx/include/__memory/is_sufficiently_aligned.h b/lib/libcxx/include/__memory/is_sufficiently_aligned.h index 93d24aaf78f0bbddd325c0b6ad2331a78986d660..b8725880028db156fb895d112241eced08102349 100644 --- a/lib/libcxx/include/__memory/is_sufficiently_aligned.h +++ b/lib/libcxx/include/__memory/is_sufficiently_aligned.h @@ -20,11 +20,16 @@ _LIBCPP_BEGIN_NAMESPACE_STD +template +[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI bool __is_sufficiently_aligned(_Tp* __ptr) { + return reinterpret_cast(__ptr) % _Alignment == 0; +} + #if _LIBCPP_STD_VER >= 26 template [[nodiscard]] _LIBCPP_HIDE_FROM_ABI bool is_sufficiently_aligned(_Tp* __ptr) { - return reinterpret_cast(__ptr) % _Alignment == 0; + return std::__is_sufficiently_aligned<_Alignment>(__ptr); } #endif // _LIBCPP_STD_VER >= 26 diff --git a/lib/libcxx/include/__memory/out_ptr.h b/lib/libcxx/include/__memory/out_ptr.h index 23a77f6a0f7e92c3569fd2a5692184b14b0d6a39..12960b76717db178e7f873a8c366ebd495af9b9c 100644 --- a/lib/libcxx/include/__memory/out_ptr.h +++ b/lib/libcxx/include/__memory/out_ptr.h @@ -11,10 +11,9 @@ #define _LIBCPP___OUT_PTR_H #include <__config> +#include <__fwd/memory.h> #include <__memory/addressof.h> #include <__memory/pointer_traits.h> -#include <__memory/shared_ptr.h> -#include <__memory/unique_ptr.h> #include <__type_traits/is_pointer.h> #include <__type_traits/is_specialization.h> #include <__type_traits/is_void.h> @@ -29,10 +28,10 @@ _LIBCPP_PUSH_MACROS #include <__undef_macros> -_LIBCPP_BEGIN_NAMESPACE_STD - #if _LIBCPP_STD_VER >= 23 +_LIBCPP_BEGIN_NAMESPACE_STD + template class out_ptr_t { static_assert(!__is_specialization_v<_Smart, shared_ptr> || sizeof...(_Args) > 0, @@ -93,10 +92,10 @@ template return std::out_ptr_t<_Smart, _Ptr, _Args&&...>(__s, std::forward<_Args>(__args)...); } -#endif // _LIBCPP_STD_VER >= 23 - _LIBCPP_END_NAMESPACE_STD +#endif // _LIBCPP_STD_VER >= 23 + _LIBCPP_POP_MACROS #endif // _LIBCPP___OUT_PTR_H diff --git a/lib/libcxx/include/__memory/pointer_traits.h b/lib/libcxx/include/__memory/pointer_traits.h index 62fcd93263b023a81833b6315aa4713e3109590c..44567839ed91d59ad43dbae4663be828e8a85574 100644 --- a/lib/libcxx/include/__memory/pointer_traits.h +++ b/lib/libcxx/include/__memory/pointer_traits.h @@ -14,12 +14,10 @@ #include <__cstddef/ptrdiff_t.h> #include <__memory/addressof.h> #include <__type_traits/conditional.h> -#include <__type_traits/conjunction.h> #include <__type_traits/decay.h> #include <__type_traits/detected_or.h> #include <__type_traits/enable_if.h> #include <__type_traits/integral_constant.h> -#include <__type_traits/is_class.h> #include <__type_traits/is_function.h> #include <__type_traits/is_void.h> #include <__type_traits/nat.h> @@ -139,9 +137,6 @@ using __rebind_pointer_t _LIBCPP_NODEBUG = typename pointer_traits<_From>::templ // to_address -template -struct __to_address_helper; - template _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _Tp* __to_address(_Tp* __p) _NOEXCEPT { static_assert(!is_function<_Tp>::value, "_Tp is a function type"); @@ -149,48 +144,38 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _Tp* __to_address(_Tp* __p) _NOEXCEPT { } template -struct _HasToAddress : false_type {}; +inline const bool __has_to_address_v = false; template -struct _HasToAddress<_Pointer, decltype((void)pointer_traits<_Pointer>::to_address(std::declval())) > - : true_type {}; +inline const bool + __has_to_address_v<_Pointer, + decltype((void)pointer_traits<_Pointer>::to_address(std::declval()))> = true; template -struct _HasArrow : false_type {}; +inline const bool __has_arrow_v = false; template -struct _HasArrow<_Pointer, decltype((void)std::declval().operator->()) > : true_type {}; +inline const bool __has_arrow_v<_Pointer, decltype((void)std::declval().operator->()) > = true; -template -struct _IsFancyPointer { - static const bool value = _HasArrow<_Pointer>::value || _HasToAddress<_Pointer>::value; -}; - -// enable_if is needed here to avoid instantiating checks for fancy pointers on raw pointers -template , _IsFancyPointer<_Pointer> >::value, int> = 0> -_LIBCPP_HIDE_FROM_ABI -_LIBCPP_CONSTEXPR __decay_t::__call(std::declval()))> +template , int> = 0> +_LIBCPP_CONSTEXPR __decay_t::to_address(std::declval()))> __to_address(const _Pointer& __p) _NOEXCEPT { - return __to_address_helper<_Pointer>::__call(__p); + return pointer_traits<_Pointer>::to_address(__p); } -template -struct __to_address_helper { - _LIBCPP_HIDE_FROM_ABI - _LIBCPP_CONSTEXPR static decltype(std::__to_address(std::declval().operator->())) - __call(const _Pointer& __p) _NOEXCEPT { - return std::__to_address(__p.operator->()); - } -}; +template +struct __to_address_arrow_result; + +template && __has_arrow_v<_Pointer>, int> = 0> +_LIBCPP_CONSTEXPR typename __to_address_arrow_result<_Pointer>::type __to_address(const _Pointer& __p) _NOEXCEPT { + return std::__to_address(__p.operator->()); +} +// The return type needs to see all `__to_address` overloads, so this is delayed until after all the overloads have been +// defined. This could also be moved to a trailing return type, but that's not available in C++03. template -struct __to_address_helper<_Pointer, - decltype((void)pointer_traits<_Pointer>::to_address(std::declval()))> { - _LIBCPP_HIDE_FROM_ABI - _LIBCPP_CONSTEXPR static decltype(pointer_traits<_Pointer>::to_address(std::declval())) - __call(const _Pointer& __p) _NOEXCEPT { - return pointer_traits<_Pointer>::to_address(__p); - } +struct __to_address_arrow_result { + using type _LIBCPP_NODEBUG = __decay_t().operator->()))>; }; #if _LIBCPP_STD_VER >= 20 diff --git a/lib/libcxx/include/__memory/ranges_uninitialized_algorithms.h b/lib/libcxx/include/__memory/ranges_uninitialized_algorithms.h index 57a7a4616826e584d5ee2fdfe479851e63e34578..796e6175af632e50db78a0d3904d2e6c993484e7 100644 --- a/lib/libcxx/include/__memory/ranges_uninitialized_algorithms.h +++ b/lib/libcxx/include/__memory/ranges_uninitialized_algorithms.h @@ -44,14 +44,16 @@ namespace ranges { struct __uninitialized_default_construct { template <__nothrow_forward_iterator _ForwardIterator, __nothrow_sentinel_for<_ForwardIterator> _Sentinel> requires default_initializable> - _LIBCPP_HIDE_FROM_ABI _ForwardIterator operator()(_ForwardIterator __first, _Sentinel __last) const { + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 _ForwardIterator + operator()(_ForwardIterator __first, _Sentinel __last) const { using _ValueType = remove_reference_t>; return std::__uninitialized_default_construct<_ValueType>(std::move(__first), std::move(__last)); } template <__nothrow_forward_range _ForwardRange> requires default_initializable> - _LIBCPP_HIDE_FROM_ABI borrowed_iterator_t<_ForwardRange> operator()(_ForwardRange&& __range) const { + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 borrowed_iterator_t<_ForwardRange> + operator()(_ForwardRange&& __range) const { return (*this)(ranges::begin(__range), ranges::end(__range)); } }; @@ -65,7 +67,7 @@ inline constexpr auto uninitialized_default_construct = __uninitialized_default_ struct __uninitialized_default_construct_n { template <__nothrow_forward_iterator _ForwardIterator> requires default_initializable> - _LIBCPP_HIDE_FROM_ABI _ForwardIterator + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 _ForwardIterator operator()(_ForwardIterator __first, iter_difference_t<_ForwardIterator> __n) const { using _ValueType = remove_reference_t>; return std::__uninitialized_default_construct_n<_ValueType>(std::move(__first), __n); @@ -81,14 +83,16 @@ inline constexpr auto uninitialized_default_construct_n = __uninitialized_defaul struct __uninitialized_value_construct { template <__nothrow_forward_iterator _ForwardIterator, __nothrow_sentinel_for<_ForwardIterator> _Sentinel> requires default_initializable> - _LIBCPP_HIDE_FROM_ABI _ForwardIterator operator()(_ForwardIterator __first, _Sentinel __last) const { + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 _ForwardIterator + operator()(_ForwardIterator __first, _Sentinel __last) const { using _ValueType = remove_reference_t>; return std::__uninitialized_value_construct<_ValueType>(std::move(__first), std::move(__last)); } template <__nothrow_forward_range _ForwardRange> requires default_initializable> - _LIBCPP_HIDE_FROM_ABI borrowed_iterator_t<_ForwardRange> operator()(_ForwardRange&& __range) const { + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 borrowed_iterator_t<_ForwardRange> + operator()(_ForwardRange&& __range) const { return (*this)(ranges::begin(__range), ranges::end(__range)); } }; @@ -102,7 +106,7 @@ inline constexpr auto uninitialized_value_construct = __uninitialized_value_cons struct __uninitialized_value_construct_n { template <__nothrow_forward_iterator _ForwardIterator> requires default_initializable> - _LIBCPP_HIDE_FROM_ABI _ForwardIterator + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 _ForwardIterator operator()(_ForwardIterator __first, iter_difference_t<_ForwardIterator> __n) const { using _ValueType = remove_reference_t>; return std::__uninitialized_value_construct_n<_ValueType>(std::move(__first), __n); @@ -118,14 +122,16 @@ inline constexpr auto uninitialized_value_construct_n = __uninitialized_value_co struct __uninitialized_fill { template <__nothrow_forward_iterator _ForwardIterator, __nothrow_sentinel_for<_ForwardIterator> _Sentinel, class _Tp> requires constructible_from, const _Tp&> - _LIBCPP_HIDE_FROM_ABI _ForwardIterator operator()(_ForwardIterator __first, _Sentinel __last, const _Tp& __x) const { + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 _ForwardIterator + operator()(_ForwardIterator __first, _Sentinel __last, const _Tp& __x) const { using _ValueType = remove_reference_t>; return std::__uninitialized_fill<_ValueType>(std::move(__first), std::move(__last), __x); } template <__nothrow_forward_range _ForwardRange, class _Tp> requires constructible_from, const _Tp&> - _LIBCPP_HIDE_FROM_ABI borrowed_iterator_t<_ForwardRange> operator()(_ForwardRange&& __range, const _Tp& __x) const { + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 borrowed_iterator_t<_ForwardRange> + operator()(_ForwardRange&& __range, const _Tp& __x) const { return (*this)(ranges::begin(__range), ranges::end(__range), __x); } }; @@ -139,7 +145,7 @@ inline constexpr auto uninitialized_fill = __uninitialized_fill{}; struct __uninitialized_fill_n { template <__nothrow_forward_iterator _ForwardIterator, class _Tp> requires constructible_from, const _Tp&> - _LIBCPP_HIDE_FROM_ABI _ForwardIterator + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 _ForwardIterator operator()(_ForwardIterator __first, iter_difference_t<_ForwardIterator> __n, const _Tp& __x) const { using _ValueType = remove_reference_t>; return std::__uninitialized_fill_n<_ValueType>(std::move(__first), __n, __x); @@ -161,20 +167,20 @@ struct __uninitialized_copy { __nothrow_forward_iterator _OutputIterator, __nothrow_sentinel_for<_OutputIterator> _Sentinel2> requires constructible_from, iter_reference_t<_InputIterator>> - _LIBCPP_HIDE_FROM_ABI uninitialized_copy_result<_InputIterator, _OutputIterator> + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 uninitialized_copy_result<_InputIterator, _OutputIterator> operator()(_InputIterator __ifirst, _Sentinel1 __ilast, _OutputIterator __ofirst, _Sentinel2 __olast) const { using _ValueType = remove_reference_t>; auto __stop_copying = [&__olast](auto&& __out_iter) -> bool { return __out_iter == __olast; }; - auto __result = std::__uninitialized_copy<_ValueType>( + return std::__uninitialized_copy<_ValueType>( std::move(__ifirst), std::move(__ilast), std::move(__ofirst), __stop_copying); - return {std::move(__result.first), std::move(__result.second)}; } template requires constructible_from, range_reference_t<_InputRange>> - _LIBCPP_HIDE_FROM_ABI uninitialized_copy_result, borrowed_iterator_t<_OutputRange>> - operator()(_InputRange&& __in_range, _OutputRange&& __out_range) const { + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 + uninitialized_copy_result, borrowed_iterator_t<_OutputRange>> + operator()(_InputRange&& __in_range, _OutputRange&& __out_range) const { return (*this)( ranges::begin(__in_range), ranges::end(__in_range), ranges::begin(__out_range), ranges::end(__out_range)); } @@ -194,16 +200,14 @@ struct __uninitialized_copy_n { __nothrow_forward_iterator _OutputIterator, __nothrow_sentinel_for<_OutputIterator> _Sentinel> requires constructible_from, iter_reference_t<_InputIterator>> - _LIBCPP_HIDE_FROM_ABI uninitialized_copy_n_result<_InputIterator, _OutputIterator> + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 uninitialized_copy_n_result<_InputIterator, _OutputIterator> operator()(_InputIterator __ifirst, iter_difference_t<_InputIterator> __n, _OutputIterator __ofirst, _Sentinel __olast) const { using _ValueType = remove_reference_t>; auto __stop_copying = [&__olast](auto&& __out_iter) -> bool { return __out_iter == __olast; }; - auto __result = - std::__uninitialized_copy_n<_ValueType>(std::move(__ifirst), __n, std::move(__ofirst), __stop_copying); - return {std::move(__result.first), std::move(__result.second)}; + return std::__uninitialized_copy_n<_ValueType>(std::move(__ifirst), __n, std::move(__ofirst), __stop_copying); } }; @@ -222,20 +226,20 @@ struct __uninitialized_move { __nothrow_forward_iterator _OutputIterator, __nothrow_sentinel_for<_OutputIterator> _Sentinel2> requires constructible_from, iter_rvalue_reference_t<_InputIterator>> - _LIBCPP_HIDE_FROM_ABI uninitialized_move_result<_InputIterator, _OutputIterator> + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 uninitialized_move_result<_InputIterator, _OutputIterator> operator()(_InputIterator __ifirst, _Sentinel1 __ilast, _OutputIterator __ofirst, _Sentinel2 __olast) const { using _ValueType = remove_reference_t>; auto __iter_move = [](auto&& __iter) -> decltype(auto) { return ranges::iter_move(__iter); }; auto __stop_moving = [&__olast](auto&& __out_iter) -> bool { return __out_iter == __olast; }; - auto __result = std::__uninitialized_move<_ValueType>( + return std::__uninitialized_move<_ValueType>( std::move(__ifirst), std::move(__ilast), std::move(__ofirst), __stop_moving, __iter_move); - return {std::move(__result.first), std::move(__result.second)}; } template requires constructible_from, range_rvalue_reference_t<_InputRange>> - _LIBCPP_HIDE_FROM_ABI uninitialized_move_result, borrowed_iterator_t<_OutputRange>> - operator()(_InputRange&& __in_range, _OutputRange&& __out_range) const { + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 + uninitialized_move_result, borrowed_iterator_t<_OutputRange>> + operator()(_InputRange&& __in_range, _OutputRange&& __out_range) const { return (*this)( ranges::begin(__in_range), ranges::end(__in_range), ranges::begin(__out_range), ranges::end(__out_range)); } @@ -255,7 +259,7 @@ struct __uninitialized_move_n { __nothrow_forward_iterator _OutputIterator, __nothrow_sentinel_for<_OutputIterator> _Sentinel> requires constructible_from, iter_rvalue_reference_t<_InputIterator>> - _LIBCPP_HIDE_FROM_ABI uninitialized_move_n_result<_InputIterator, _OutputIterator> + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 uninitialized_move_n_result<_InputIterator, _OutputIterator> operator()(_InputIterator __ifirst, iter_difference_t<_InputIterator> __n, _OutputIterator __ofirst, @@ -263,9 +267,8 @@ struct __uninitialized_move_n { using _ValueType = remove_reference_t>; auto __iter_move = [](auto&& __iter) -> decltype(auto) { return ranges::iter_move(__iter); }; auto __stop_moving = [&__olast](auto&& __out_iter) -> bool { return __out_iter == __olast; }; - auto __result = std::__uninitialized_move_n<_ValueType>( + return std::__uninitialized_move_n<_ValueType>( std::move(__ifirst), __n, std::move(__ofirst), __stop_moving, __iter_move); - return {std::move(__result.first), std::move(__result.second)}; } }; diff --git a/lib/libcxx/include/__memory/raw_storage_iterator.h b/lib/libcxx/include/__memory/raw_storage_iterator.h index dff0fed3b7565ed03759bd9390af1712446d1c60..a813d4a67835a0befd76d603fd9442f90c783707 100644 --- a/lib/libcxx/include/__memory/raw_storage_iterator.h +++ b/lib/libcxx/include/__memory/raw_storage_iterator.h @@ -21,13 +21,13 @@ # pragma GCC system_header #endif +#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_RAW_STORAGE_ITERATOR) + _LIBCPP_PUSH_MACROS #include <__undef_macros> _LIBCPP_BEGIN_NAMESPACE_STD -#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_RAW_STORAGE_ITERATOR) - template class _LIBCPP_DEPRECATED_IN_CXX17 raw_storage_iterator : public __iterator_base, output_iterator_tag, void, void, void, void> { @@ -71,10 +71,10 @@ public: # endif }; -#endif // _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_RAW_STORAGE_ITERATOR) - _LIBCPP_END_NAMESPACE_STD _LIBCPP_POP_MACROS +#endif // _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_RAW_STORAGE_ITERATOR) + #endif // _LIBCPP___MEMORY_RAW_STORAGE_ITERATOR_H diff --git a/lib/libcxx/include/__memory/shared_count.h b/lib/libcxx/include/__memory/shared_count.h index b40d8c9cf77d141286f278bdc0c7e828e3fc9ff0..4fd81287d854c7cdd7b7688e176f392880bb2de5 100644 --- a/lib/libcxx/include/__memory/shared_count.h +++ b/lib/libcxx/include/__memory/shared_count.h @@ -18,6 +18,7 @@ #endif _LIBCPP_BEGIN_NAMESPACE_STD +_LIBCPP_BEGIN_EXPLICIT_ABI_ANNOTATIONS // NOTE: Relaxed and acq/rel atomics (for increment and decrement respectively) // should be sufficient for thread safety. @@ -111,6 +112,7 @@ private: virtual void __on_zero_shared_weak() _NOEXCEPT = 0; }; +_LIBCPP_END_EXPLICIT_ABI_ANNOTATIONS _LIBCPP_END_NAMESPACE_STD #endif // _LIBCPP___MEMORY_SHARED_COUNT_H diff --git a/lib/libcxx/include/__memory/shared_ptr.h b/lib/libcxx/include/__memory/shared_ptr.h index 4fbd0af98463e6094d75c4af28dc52daf04e399f..4112c1175b9e134b97d995528155b88fb24b9f8d 100644 --- a/lib/libcxx/include/__memory/shared_ptr.h +++ b/lib/libcxx/include/__memory/shared_ptr.h @@ -10,6 +10,7 @@ #ifndef _LIBCPP___MEMORY_SHARED_PTR_H #define _LIBCPP___MEMORY_SHARED_PTR_H +#include <__atomic/memory_order.h> #include <__compare/compare_three_way.h> #include <__compare/ordering.h> #include <__config> @@ -27,19 +28,17 @@ #include <__memory/allocator_destructor.h> #include <__memory/allocator_traits.h> #include <__memory/auto_ptr.h> -#include <__memory/compressed_pair.h> #include <__memory/construct_at.h> #include <__memory/destroy.h> #include <__memory/pointer_traits.h> #include <__memory/shared_count.h> #include <__memory/uninitialized_algorithms.h> +#include <__memory/uninitialized_multidimensional_algorithms.h> #include <__memory/unique_ptr.h> #include <__type_traits/add_reference.h> #include <__type_traits/conditional.h> #include <__type_traits/conjunction.h> -#include <__type_traits/disjunction.h> #include <__type_traits/enable_if.h> -#include <__type_traits/integral_constant.h> #include <__type_traits/is_array.h> #include <__type_traits/is_constructible.h> #include <__type_traits/is_convertible.h> @@ -47,10 +46,11 @@ #include <__type_traits/is_reference.h> #include <__type_traits/is_same.h> #include <__type_traits/nat.h> -#include <__type_traits/negation.h> #include <__type_traits/remove_cv.h> #include <__type_traits/remove_extent.h> +#include <__type_traits/remove_pointer.h> #include <__type_traits/remove_reference.h> +#include <__type_traits/void_t.h> #include <__utility/declval.h> #include <__utility/exception_guard.h> #include <__utility/forward.h> @@ -58,9 +58,6 @@ #include <__utility/swap.h> #include <__verbose_abort> #include -#if _LIBCPP_HAS_ATOMIC_HEADER -# include <__atomic/memory_order.h> -#endif #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header @@ -70,6 +67,7 @@ _LIBCPP_PUSH_MACROS #include <__undef_macros> _LIBCPP_BEGIN_NAMESPACE_STD +_LIBCPP_BEGIN_EXPLICIT_ABI_ANNOTATIONS class _LIBCPP_EXPORTED_FROM_ABI bad_weak_ptr : public std::exception { public: @@ -92,127 +90,91 @@ template class weak_ptr; template -class __shared_ptr_pointer : public __shared_weak_count { - _LIBCPP_COMPRESSED_TRIPLE(_Tp, __ptr_, _Dp, __deleter_, _Alloc, __alloc_); +class _LIBCPP_HIDE_STRUCT_FROM_ABI __shared_ptr_pointer final : public __shared_weak_count { + _LIBCPP_NO_UNIQUE_ADDRESS _Alloc __alloc_; + _LIBCPP_NO_UNIQUE_ADDRESS _Dp __deleter_; + _LIBCPP_NO_UNIQUE_ADDRESS _Tp __ptr_; public: _LIBCPP_HIDE_FROM_ABI __shared_ptr_pointer(_Tp __p, _Dp __d, _Alloc __a) - : __ptr_(__p), __deleter_(std::move(__d)), __alloc_(std::move(__a)) {} + : __alloc_(std::move(__a)), __deleter_(std::move(__d)), __ptr_(__p) {} #if _LIBCPP_HAS_RTTI - _LIBCPP_HIDE_FROM_ABI_VIRTUAL const void* __get_deleter(const type_info&) const _NOEXCEPT override; + _LIBCPP_HIDE_FROM_ABI_VIRTUAL const void* __get_deleter(const type_info& __t) const _NOEXCEPT override { + return __t == typeid(_Dp) ? std::addressof(__deleter_) : nullptr; + } #endif private: - _LIBCPP_HIDE_FROM_ABI_VIRTUAL void __on_zero_shared() _NOEXCEPT override; - _LIBCPP_HIDE_FROM_ABI_VIRTUAL void __on_zero_shared_weak() _NOEXCEPT override; + _LIBCPP_HIDE_FROM_ABI_VIRTUAL void __on_zero_shared() _NOEXCEPT override { + __deleter_(__ptr_); + __ptr_.~_Tp(); + __deleter_.~_Dp(); + } + + _LIBCPP_HIDE_FROM_ABI_VIRTUAL void __on_zero_shared_weak() _NOEXCEPT override { + using __alloc_t = __allocator_traits_rebind_t<_Alloc, __shared_ptr_pointer>; + + __alloc_t __a(__alloc_); + __alloc_.~_Alloc(); + __a.deallocate(pointer_traits::pointer>::pointer_to(*this), 1); + } }; -#if _LIBCPP_HAS_RTTI - -template -const void* __shared_ptr_pointer<_Tp, _Dp, _Alloc>::__get_deleter(const type_info& __t) const _NOEXCEPT { - return __t == typeid(_Dp) ? std::addressof(__deleter_) : nullptr; -} - -#endif // _LIBCPP_HAS_RTTI - -template -void __shared_ptr_pointer<_Tp, _Dp, _Alloc>::__on_zero_shared() _NOEXCEPT { - __deleter_(__ptr_); - __deleter_.~_Dp(); -} - -template -void __shared_ptr_pointer<_Tp, _Dp, _Alloc>::__on_zero_shared_weak() _NOEXCEPT { - typedef typename __allocator_traits_rebind<_Alloc, __shared_ptr_pointer>::type _Al; - typedef allocator_traits<_Al> _ATraits; - typedef pointer_traits _PTraits; - - _Al __a(__alloc_); - __alloc_.~_Alloc(); - __a.deallocate(_PTraits::pointer_to(*this), 1); -} - // This tag is used to instantiate an allocator type. The various shared_ptr control blocks // detect that the allocator has been instantiated for this type and perform alternative // initialization/destruction based on that. struct __for_overwrite_tag {}; template -struct __shared_ptr_emplace : __shared_weak_count { +struct _LIBCPP_HIDE_STRUCT_FROM_ABI __shared_ptr_emplace : __shared_weak_count { + using __alloc_traits _LIBCPP_NODEBUG = allocator_traits<_Alloc>; + using __value_type _LIBCPP_NODEBUG = __remove_cv_t<_Tp>; + + template + _LIBCPP_HIDE_FROM_ABI explicit __shared_ptr_emplace(_Alloc __a, _Args&&... __args) : __alloc_(std::move(__a)) { + allocator_traits<_Alloc>::construct(__alloc_, __get_elem(), std::forward<_Args>(__args)...); + } + + _LIBCPP_HIDE_FROM_ABI __value_type* __get_elem() _NOEXCEPT { return reinterpret_cast<__value_type*>(__buffer_); } + +private: + _LIBCPP_HIDE_FROM_ABI_VIRTUAL void __on_zero_shared() _NOEXCEPT override { + allocator_traits<_Alloc>::destroy(__alloc_, __get_elem()); + } + + _LIBCPP_HIDE_FROM_ABI_VIRTUAL void __on_zero_shared_weak() _NOEXCEPT override { + using __alloc_t = __allocator_traits_rebind_t<_Alloc, __shared_ptr_emplace>; + __alloc_t __tmp(__alloc_); + __alloc_.~_Alloc(); + allocator_traits<__alloc_t>::deallocate( + __tmp, pointer_traits::pointer>::pointer_to(*this), 1); + } + + _LIBCPP_NO_UNIQUE_ADDRESS _Alloc __alloc_; + _ALIGNAS_TYPE(__value_type) char __buffer_[sizeof(__value_type)]; +}; + +template +struct _LIBCPP_HIDE_STRUCT_FROM_ABI __shared_ptr_emplace_for_overwrite : __shared_weak_count { using __value_type _LIBCPP_NODEBUG = __remove_cv_t<_Tp>; - template ::value, int> = 0> - _LIBCPP_HIDE_FROM_ABI explicit __shared_ptr_emplace(_Alloc __a, _Args&&...) : __storage_(std::move(__a)) { - static_assert( - sizeof...(_Args) == 0, "No argument should be provided to the control block when using _for_overwrite"); - ::new (static_cast(__get_elem())) __value_type; - } - - template ::value, int> = 0> - _LIBCPP_HIDE_FROM_ABI explicit __shared_ptr_emplace(_Alloc __a, _Args&&... __args) : __storage_(std::move(__a)) { - using _TpAlloc = typename __allocator_traits_rebind<_Alloc, __value_type>::type; - _TpAlloc __tmp(*__get_alloc()); - allocator_traits<_TpAlloc>::construct(__tmp, __get_elem(), std::forward<_Args>(__args)...); - } - - _LIBCPP_HIDE_FROM_ABI _Alloc* __get_alloc() _NOEXCEPT { return __storage_.__get_alloc(); } - - _LIBCPP_HIDE_FROM_ABI __value_type* __get_elem() _NOEXCEPT { return __storage_.__get_elem(); } - -private: - template ::value, int> = 0> - _LIBCPP_HIDE_FROM_ABI void __on_zero_shared_impl() _NOEXCEPT { - __get_elem()->~__value_type(); - } - - template ::value, int> = 0> - _LIBCPP_HIDE_FROM_ABI void __on_zero_shared_impl() _NOEXCEPT { - using _TpAlloc = typename __allocator_traits_rebind<_Allocator, __remove_cv_t<_Tp> >::type; - _TpAlloc __tmp(*__get_alloc()); - allocator_traits<_TpAlloc>::destroy(__tmp, __get_elem()); - } - - _LIBCPP_HIDE_FROM_ABI_VIRTUAL void __on_zero_shared() _NOEXCEPT override { __on_zero_shared_impl(); } + _LIBCPP_HIDE_FROM_ABI explicit __shared_ptr_emplace_for_overwrite(_Alloc __a) : __alloc_(std::move(__a)) {} + _LIBCPP_HIDE_FROM_ABI_VIRTUAL void __on_zero_shared() _NOEXCEPT override { __value_.~__value_type(); } _LIBCPP_HIDE_FROM_ABI_VIRTUAL void __on_zero_shared_weak() _NOEXCEPT override { - using _ControlBlockAlloc = typename __allocator_traits_rebind<_Alloc, __shared_ptr_emplace>::type; - using _ControlBlockPointer = typename allocator_traits<_ControlBlockAlloc>::pointer; - _ControlBlockAlloc __tmp(*__get_alloc()); - __storage_.~_Storage(); - allocator_traits<_ControlBlockAlloc>::deallocate(__tmp, pointer_traits<_ControlBlockPointer>::pointer_to(*this), 1); + using __alloc_t = __allocator_traits_rebind_t<_Alloc, __shared_ptr_emplace_for_overwrite>; + using __alloc_traits = allocator_traits<__alloc_t>; + __alloc_t __tmp(__alloc_); + __alloc_.~_Alloc(); + __alloc_traits::deallocate(__tmp, pointer_traits::pointer_to(*this), 1); } - // TODO: It should be possible to refactor this to remove `_Storage` entirely. - // This class implements the control block for non-array shared pointers created - // through `std::allocate_shared` and `std::make_shared`. - struct _Storage { - struct _Data { - _LIBCPP_COMPRESSED_PAIR(_Alloc, __alloc_, __value_type, __elem_); - }; + _LIBCPP_HIDE_FROM_ABI __value_type* __get_elem() _NOEXCEPT { return std::addressof(__value_); } - _ALIGNAS_TYPE(_Data) char __buffer_[sizeof(_Data)]; - - _LIBCPP_HIDE_FROM_ABI explicit _Storage(_Alloc&& __a) { ::new ((void*)__get_alloc()) _Alloc(std::move(__a)); } - _LIBCPP_HIDE_FROM_ABI ~_Storage() { __get_alloc()->~_Alloc(); } - - _LIBCPP_HIDE_FROM_ABI _Alloc* __get_alloc() _NOEXCEPT { - return std::addressof(reinterpret_cast<_Data*>(__buffer_)->__alloc_); - } - - _LIBCPP_HIDE_FROM_ABI _LIBCPP_NO_CFI __value_type* __get_elem() _NOEXCEPT { - return std::addressof(reinterpret_cast<_Data*>(__buffer_)->__elem_); - } - }; - - _Storage __storage_; +private: + _LIBCPP_NO_UNIQUE_ADDRESS _Alloc __alloc_; + _LIBCPP_NO_UNIQUE_ADDRESS __value_type __value_; }; struct __shared_ptr_dummy_rebind_allocator_type; @@ -233,16 +195,16 @@ class enable_shared_from_this; // when either Y* is convertible to T* or Y is U[N] and T is cv U[]. #if _LIBCPP_STD_VER >= 17 template -struct __bounded_convertible_to_unbounded : false_type {}; +inline const bool __bounded_convertible_to_unbounded_v = false; template -struct __bounded_convertible_to_unbounded<_Up[_Np], _Tp> : is_same<__remove_cv_t<_Tp>, _Up[]> {}; +inline const bool __bounded_convertible_to_unbounded_v<_Up[_Np], _Tp> = is_same_v, _Up[]>; template -struct __compatible_with : _Or< is_convertible<_Yp*, _Tp*>, __bounded_convertible_to_unbounded<_Yp, _Tp> > {}; +inline const bool __compatible_with_v = is_convertible_v<_Yp*, _Tp*> || __bounded_convertible_to_unbounded_v<_Yp, _Tp>; #else template -struct __compatible_with : is_convertible<_Yp*, _Tp*> {}; +inline const bool __compatible_with_v = is_convertible<_Yp*, _Tp*>::value; #endif // _LIBCPP_STD_VER >= 17 // Constructors that take raw pointers have a different set of "compatible" constraints @@ -252,49 +214,46 @@ struct __compatible_with : is_convertible<_Yp*, _Tp*> {}; // - If T is not an array type, then Y* is convertible to T*. #if _LIBCPP_STD_VER >= 17 template -struct __raw_pointer_compatible_with : _And< _Not>, is_convertible<_Yp*, _Tp*> > {}; +inline const bool __raw_pointer_compatible_with_v = !is_array_v<_Tp> && is_convertible_v<_Yp*, _Tp*>; template -struct __raw_pointer_compatible_with<_Yp, _Up[_Np], __enable_if_t< is_convertible<_Yp (*)[_Np], _Up (*)[_Np]>::value> > - : true_type {}; +inline const bool + __raw_pointer_compatible_with_v<_Yp, _Up[_Np], enable_if_t>> = true; template -struct __raw_pointer_compatible_with<_Yp, _Up[], __enable_if_t< is_convertible<_Yp (*)[], _Up (*)[]>::value> > - : true_type {}; +inline const bool __raw_pointer_compatible_with_v<_Yp, _Up[], enable_if_t>> = + true; #else template -struct __raw_pointer_compatible_with : is_convertible<_Yp*, _Tp*> {}; +inline const bool __raw_pointer_compatible_with_v = is_convertible<_Yp*, _Tp*>::value; #endif // _LIBCPP_STD_VER >= 17 template -struct __is_deletable : false_type {}; +inline const bool __is_deletable_v = false; template -struct __is_deletable<_Ptr, decltype(delete std::declval<_Ptr>())> : true_type {}; +inline const bool __is_deletable_v<_Ptr, decltype(delete std::declval<_Ptr>())> = true; template -struct __is_array_deletable : false_type {}; +inline const bool __is_array_deletable_v = false; template -struct __is_array_deletable<_Ptr, decltype(delete[] std::declval<_Ptr>())> : true_type {}; +inline const bool __is_array_deletable_v<_Ptr, decltype(delete[] std::declval<_Ptr>())> = true; -template ()(std::declval<_Pt>()))> -true_type __well_formed_deleter_test(int); - -template -false_type __well_formed_deleter_test(...); +template +inline const bool __well_formed_deleter_v = false; template -struct __well_formed_deleter : decltype(std::__well_formed_deleter_test<_Dp, _Pt>(0)) {}; +inline const bool __well_formed_deleter_v<_Dp, _Pt, __void_t()(std::declval<_Pt>()))> > = + true; template -struct __shared_ptr_deleter_ctor_reqs { - static const bool value = __raw_pointer_compatible_with<_Yp, _Tp>::value && is_move_constructible<_Dp>::value && - __well_formed_deleter<_Dp, _Yp*>::value; -}; +inline const bool __shared_ptr_deleter_ctor_reqs_v = + __raw_pointer_compatible_with_v<_Yp, _Tp> && is_move_constructible<_Dp>::value && + __well_formed_deleter_v<_Dp, _Yp*>; template -using __shared_ptr_nullptr_deleter_ctor_reqs _LIBCPP_NODEBUG = - _And, __well_formed_deleter<_Dp, nullptr_t> >; +inline const bool __shared_ptr_nullptr_deleter_ctor_reqs_v = + is_move_constructible<_Dp>::value && __well_formed_deleter_v<_Dp, nullptr_t>; #if defined(_LIBCPP_ABI_ENABLE_SHARED_PTR_TRIVIAL_ABI) # define _LIBCPP_SHARED_PTR_TRIVIAL_ABI __attribute__((__trivial_abi__)) @@ -328,16 +287,15 @@ public: _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR shared_ptr(nullptr_t) _NOEXCEPT : __ptr_(nullptr), __cntrl_(nullptr) {} template + __enable_if_t<__raw_pointer_compatible_with_v<_Yp, _Tp> // In C++03 we get errors when trying to do SFINAE with the // delete operator, so we always pretend that it's deletable. // The same happens on GCC. -#if !defined(_LIBCPP_CXX03_LANG) && !defined(_LIBCPP_COMPILER_GCC) - , - _If::value, __is_array_deletable<_Yp*>, __is_deletable<_Yp*> > +#if !defined(_LIBCPP_CXX03_LANG) + && (is_array<_Tp>::value ? __is_array_deletable_v<_Yp*> : __is_deletable_v<_Yp*>) #endif - >::value, - int> = 0> + , + int> = 0> _LIBCPP_HIDE_FROM_ABI explicit shared_ptr(_Yp* __p) : __ptr_(__p) { unique_ptr<_Yp> __hold(__p); typedef typename __shared_ptr_default_allocator<_Yp>::type _AllocT; @@ -347,7 +305,7 @@ public: __enable_weak_this(__p, __p); } - template ::value, int> = 0> + template , int> = 0> _LIBCPP_HIDE_FROM_ABI shared_ptr(_Yp* __p, _Dp __d) : __ptr_(__p) { auto __guard = std::__make_exception_guard([&] { __d(__p); }); typedef typename __shared_ptr_default_allocator<_Yp>::type _AllocT; @@ -361,10 +319,7 @@ public: __guard.__complete(); } - template ::value, int> = 0> + template , int> = 0> _LIBCPP_HIDE_FROM_ABI shared_ptr(_Yp* __p, _Dp __d, _Alloc __a) : __ptr_(__p) { auto __guard = std::__make_exception_guard([&] { __d(__p); }); typedef __shared_ptr_pointer<_Yp*, _Dp, _Alloc> _CntrlBlk; @@ -387,7 +342,7 @@ public: _LIBCPP_HIDE_FROM_ABI shared_ptr( nullptr_t __p, _Dp __d, - __enable_if_t<__shared_ptr_nullptr_deleter_ctor_reqs<_Dp>::value, __nullptr_sfinae_tag> = __nullptr_sfinae_tag()) + __enable_if_t<__shared_ptr_nullptr_deleter_ctor_reqs_v<_Dp>, __nullptr_sfinae_tag> = __nullptr_sfinae_tag()) : __ptr_(nullptr) { auto __guard = std::__make_exception_guard([&] { __d(__p); }); typedef typename __shared_ptr_default_allocator<_Tp>::type _AllocT; @@ -405,7 +360,7 @@ public: nullptr_t __p, _Dp __d, _Alloc __a, - __enable_if_t<__shared_ptr_nullptr_deleter_ctor_reqs<_Dp>::value, __nullptr_sfinae_tag> = __nullptr_sfinae_tag()) + __enable_if_t<__shared_ptr_nullptr_deleter_ctor_reqs_v<_Dp>, __nullptr_sfinae_tag> = __nullptr_sfinae_tag()) : __ptr_(nullptr) { auto __guard = std::__make_exception_guard([&] { __d(__p); }); typedef __shared_ptr_pointer _CntrlBlk; @@ -447,7 +402,7 @@ public: __cntrl_->__add_shared(); } - template ::value, int> = 0> + template , int> = 0> _LIBCPP_HIDE_FROM_ABI shared_ptr(const shared_ptr<_Yp>& __r) _NOEXCEPT : __ptr_(__r.__ptr_), __cntrl_(__r.__cntrl_) { if (__cntrl_) __cntrl_->__add_shared(); @@ -458,13 +413,13 @@ public: __r.__cntrl_ = nullptr; } - template ::value, int> = 0> + template , int> = 0> _LIBCPP_HIDE_FROM_ABI shared_ptr(shared_ptr<_Yp>&& __r) _NOEXCEPT : __ptr_(__r.__ptr_), __cntrl_(__r.__cntrl_) { __r.__ptr_ = nullptr; __r.__cntrl_ = nullptr; } - template ::value, int> = 0> + template , int> = 0> _LIBCPP_HIDE_FROM_ABI explicit shared_ptr(const weak_ptr<_Yp>& __r) : __ptr_(__r.__ptr_), __cntrl_(__r.__cntrl_ ? __r.__cntrl_->lock() : __r.__cntrl_) { if (__cntrl_ == nullptr) @@ -483,7 +438,7 @@ public: template ::value && + __enable_if_t<__compatible_with_v<_Yp, _Tp> && is_convertible::pointer, element_type*>::value, int> = 0> _LIBCPP_HIDE_FROM_ABI shared_ptr(unique_ptr<_Yp, _Dp>&& __r) : __ptr_(__r.get()) { @@ -506,7 +461,7 @@ public: return *this; } - template ::value, int> = 0> + template , int> = 0> _LIBCPP_HIDE_FROM_ABI shared_ptr<_Tp>& operator=(const shared_ptr<_Yp>& __r) _NOEXCEPT { shared_ptr(__r).swap(*this); return *this; @@ -517,7 +472,7 @@ public: return *this; } - template ::value, int> = 0> + template , int> = 0> _LIBCPP_HIDE_FROM_ABI shared_ptr<_Tp>& operator=(shared_ptr<_Yp>&& __r) { shared_ptr(std::move(__r)).swap(*this); return *this; @@ -535,8 +490,8 @@ public: template , - is_convertible::pointer, element_type*> >::value, + __enable_if_t<__compatible_with_v<_Yp, _Tp> && + is_convertible::pointer, element_type*>::value, int> = 0> _LIBCPP_HIDE_FROM_ABI shared_ptr<_Tp>& operator=(unique_ptr<_Yp, _Dp>&& __r) { shared_ptr(std::move(__r)).swap(*this); @@ -550,20 +505,17 @@ public: _LIBCPP_HIDE_FROM_ABI void reset() _NOEXCEPT { shared_ptr().swap(*this); } - template ::value, int> = 0> + template , int> = 0> _LIBCPP_HIDE_FROM_ABI void reset(_Yp* __p) { shared_ptr(__p).swap(*this); } - template ::value, int> = 0> + template , int> = 0> _LIBCPP_HIDE_FROM_ABI void reset(_Yp* __p, _Dp __d) { shared_ptr(__p, __d).swap(*this); } - template ::value, int> = 0> + template , int> = 0> _LIBCPP_HIDE_FROM_ABI void reset(_Yp* __p, _Dp __d, _Alloc __a) { shared_ptr(__p, __d, __a).swap(*this); } @@ -647,7 +599,26 @@ private: } } - _LIBCPP_HIDE_FROM_ABI void __enable_weak_this(...) _NOEXCEPT {} + template + static __type_identity<_Vp> __get_shared_from_this_impl(const enable_shared_from_this<_Vp>*); + + template + struct __get_shared_from_this { + using type _LIBCPP_NODEBUG = __nat; + }; + + template + struct __get_shared_from_this<_Vp, __void_t(nullptr)))> > { + using type _LIBCPP_NODEBUG = const enable_shared_from_this(nullptr)))::type>*; + }; + + template < + class _Yp, + class _OrigPtr, + __enable_if_t >::type>::value, + int> = 0> + _LIBCPP_HIDE_FROM_ABI void __enable_weak_this(_Yp, _OrigPtr) {} template struct __shared_ptr_default_delete : default_delete<_Yp> {}; @@ -674,15 +645,22 @@ shared_ptr(unique_ptr<_Tp, _Dp>) -> shared_ptr<_Tp>; // // std::allocate_shared and std::make_shared // -template ::value, int> = 0> -[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI shared_ptr<_Tp> allocate_shared(const _Alloc& __a, _Args&&... __args) { - using _ControlBlock = __shared_ptr_emplace<_Tp, _Alloc>; + +template +_LIBCPP_HIDE_FROM_ABI shared_ptr<_Tp> __allocate_shared_impl(const _Alloc& __alloc, _Args&&... __args) { using _ControlBlockAllocator = typename __allocator_traits_rebind<_Alloc, _ControlBlock>::type; - __allocation_guard<_ControlBlockAllocator> __guard(__a, 1); - ::new ((void*)std::addressof(*__guard.__get())) _ControlBlock(__a, std::forward<_Args>(__args)...); + __allocation_guard<_ControlBlockAllocator> __guard(__alloc, 1); + ::new ((void*)std::addressof(*__guard.__get())) _ControlBlock(__alloc, std::forward<_Args>(__args)...); auto __control_block = __guard.__release_ptr(); return shared_ptr<_Tp>::__create_with_control_block( - (*__control_block).__get_elem(), std::addressof(*__control_block)); + __control_block->__get_elem(), std::__to_address(__control_block)); +} + +template ::value, int> = 0> +[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI shared_ptr<_Tp> allocate_shared(const _Alloc& __a, _Args&&... __args) { + using _CanonicalAlloc = __allocator_traits_rebind_t<_Alloc, __remove_cv_t<_Tp> >; + using _ControlBlock = __shared_ptr_emplace<_Tp, _CanonicalAlloc>; + return std::__allocate_shared_impl<_ControlBlock, _Tp>(_CanonicalAlloc(__a), std::forward<_Args>(__args)...); } template ::value, int> = 0> @@ -694,9 +672,9 @@ template ::value, int> = template ::value, int> = 0> [[nodiscard]] _LIBCPP_HIDE_FROM_ABI shared_ptr<_Tp> allocate_shared_for_overwrite(const _Alloc& __a) { - using _ForOverwriteAllocator = __allocator_traits_rebind_t<_Alloc, __for_overwrite_tag>; - _ForOverwriteAllocator __alloc(__a); - return std::allocate_shared<_Tp>(__alloc); + using _CanonicalAlloc = __allocator_traits_rebind_t<_Alloc, remove_cv_t<_Tp>>; + using _ControlBlock = __shared_ptr_emplace_for_overwrite<_Tp, _CanonicalAlloc>; + return std::__allocate_shared_impl<_ControlBlock, _Tp>(_CanonicalAlloc(__a)); } template ::value, int> = 0> @@ -752,7 +730,7 @@ struct __unbounded_array_control_block<_Tp[], _Alloc> : __shared_weak_count { // [1]: https://en.wikipedia.org/wiki/Data_structure_alignment#Computing_padding size_t __bytes = __elements == 0 ? sizeof(__unbounded_array_control_block) : (__elements - 1) * sizeof(_Tp) + sizeof(__unbounded_array_control_block); - constexpr size_t __align = alignof(_Tp); + constexpr size_t __align = alignof(__unbounded_array_control_block); return (__bytes + __align - 1) & ~(__align - 1); } @@ -1171,44 +1149,93 @@ private: __shared_weak_count* __cntrl_; public: - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR weak_ptr() _NOEXCEPT; + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR weak_ptr() _NOEXCEPT : __ptr_(nullptr), __cntrl_(nullptr) {} - template ::value, int> = 0> - _LIBCPP_HIDE_FROM_ABI weak_ptr(shared_ptr<_Yp> const& __r) _NOEXCEPT; + template , int> = 0> + _LIBCPP_HIDE_FROM_ABI weak_ptr(shared_ptr<_Yp> const& __r) _NOEXCEPT : __ptr_(__r.__ptr_), __cntrl_(__r.__cntrl_) { + if (__cntrl_) + __cntrl_->__add_weak(); + } - _LIBCPP_HIDE_FROM_ABI weak_ptr(weak_ptr const& __r) _NOEXCEPT; + _LIBCPP_HIDE_FROM_ABI weak_ptr(weak_ptr const& __r) _NOEXCEPT : __ptr_(__r.__ptr_), __cntrl_(__r.__cntrl_) { + if (__cntrl_) + __cntrl_->__add_weak(); + } - template ::value, int> = 0> - _LIBCPP_HIDE_FROM_ABI weak_ptr(weak_ptr<_Yp> const& __r) _NOEXCEPT; + template , int> = 0> + _LIBCPP_HIDE_FROM_ABI weak_ptr(weak_ptr<_Yp> const& __r) _NOEXCEPT : __ptr_(nullptr), __cntrl_(nullptr) { + shared_ptr<_Yp> __s = __r.lock(); + *this = weak_ptr<_Tp>(__s); + } - _LIBCPP_HIDE_FROM_ABI weak_ptr(weak_ptr&& __r) _NOEXCEPT; + _LIBCPP_HIDE_FROM_ABI weak_ptr(weak_ptr&& __r) _NOEXCEPT : __ptr_(__r.__ptr_), __cntrl_(__r.__cntrl_) { + __r.__ptr_ = nullptr; + __r.__cntrl_ = nullptr; + } - template ::value, int> = 0> - _LIBCPP_HIDE_FROM_ABI weak_ptr(weak_ptr<_Yp>&& __r) _NOEXCEPT; + template , int> = 0> + _LIBCPP_HIDE_FROM_ABI weak_ptr(weak_ptr<_Yp>&& __r) _NOEXCEPT : __ptr_(nullptr), __cntrl_(nullptr) { + shared_ptr<_Yp> __s = __r.lock(); + *this = weak_ptr<_Tp>(__s); + __r.reset(); + } - _LIBCPP_HIDE_FROM_ABI ~weak_ptr(); + _LIBCPP_HIDE_FROM_ABI ~weak_ptr() { + if (__cntrl_) + __cntrl_->__release_weak(); + } - _LIBCPP_HIDE_FROM_ABI weak_ptr& operator=(weak_ptr const& __r) _NOEXCEPT; - template ::value, int> = 0> - _LIBCPP_HIDE_FROM_ABI weak_ptr& operator=(weak_ptr<_Yp> const& __r) _NOEXCEPT; + _LIBCPP_HIDE_FROM_ABI weak_ptr& operator=(weak_ptr const& __r) _NOEXCEPT { + weak_ptr(__r).swap(*this); + return *this; + } - _LIBCPP_HIDE_FROM_ABI weak_ptr& operator=(weak_ptr&& __r) _NOEXCEPT; - template ::value, int> = 0> - _LIBCPP_HIDE_FROM_ABI weak_ptr& operator=(weak_ptr<_Yp>&& __r) _NOEXCEPT; + template , int> = 0> + _LIBCPP_HIDE_FROM_ABI weak_ptr& operator=(weak_ptr<_Yp> const& __r) _NOEXCEPT { + weak_ptr(__r).swap(*this); + return *this; + } - template ::value, int> = 0> - _LIBCPP_HIDE_FROM_ABI weak_ptr& operator=(shared_ptr<_Yp> const& __r) _NOEXCEPT; + _LIBCPP_HIDE_FROM_ABI weak_ptr& operator=(weak_ptr&& __r) _NOEXCEPT { + weak_ptr(std::move(__r)).swap(*this); + return *this; + } - _LIBCPP_HIDE_FROM_ABI void swap(weak_ptr& __r) _NOEXCEPT; - _LIBCPP_HIDE_FROM_ABI void reset() _NOEXCEPT; + template , int> = 0> + _LIBCPP_HIDE_FROM_ABI weak_ptr& operator=(weak_ptr<_Yp>&& __r) _NOEXCEPT { + weak_ptr(std::move(__r)).swap(*this); + return *this; + } + + template , int> = 0> + _LIBCPP_HIDE_FROM_ABI weak_ptr& operator=(shared_ptr<_Yp> const& __r) _NOEXCEPT { + weak_ptr(__r).swap(*this); + return *this; + } + + _LIBCPP_HIDE_FROM_ABI void swap(weak_ptr& __r) _NOEXCEPT { + std::swap(__ptr_, __r.__ptr_); + std::swap(__cntrl_, __r.__cntrl_); + } + + _LIBCPP_HIDE_FROM_ABI void reset() _NOEXCEPT { weak_ptr().swap(*this); } [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI long use_count() const _NOEXCEPT { return __cntrl_ ? __cntrl_->use_count() : 0; } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI bool expired() const _NOEXCEPT { return __cntrl_ == nullptr || __cntrl_->use_count() == 0; } - [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI shared_ptr<_Tp> lock() const _NOEXCEPT; + + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI shared_ptr<_Tp> lock() const _NOEXCEPT { + shared_ptr<_Tp> __r; + __r.__cntrl_ = __cntrl_ ? __cntrl_->lock() : __cntrl_; + if (__r.__cntrl_) + __r.__ptr_ = __ptr_; + return __r; + } + template [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI bool owner_before(const shared_ptr<_Up>& __r) const _NOEXCEPT { return __cntrl_ < __r.__cntrl_; @@ -1229,107 +1256,11 @@ template weak_ptr(shared_ptr<_Tp>) -> weak_ptr<_Tp>; #endif -template -inline _LIBCPP_CONSTEXPR weak_ptr<_Tp>::weak_ptr() _NOEXCEPT : __ptr_(nullptr), __cntrl_(nullptr) {} - -template -inline weak_ptr<_Tp>::weak_ptr(weak_ptr const& __r) _NOEXCEPT : __ptr_(__r.__ptr_), __cntrl_(__r.__cntrl_) { - if (__cntrl_) - __cntrl_->__add_weak(); -} - -template -template ::value, int> > -inline weak_ptr<_Tp>::weak_ptr(shared_ptr<_Yp> const& __r) _NOEXCEPT : __ptr_(__r.__ptr_), __cntrl_(__r.__cntrl_) { - if (__cntrl_) - __cntrl_->__add_weak(); -} - -template -template ::value, int> > -inline weak_ptr<_Tp>::weak_ptr(weak_ptr<_Yp> const& __r) _NOEXCEPT : __ptr_(nullptr), __cntrl_(nullptr) { - shared_ptr<_Yp> __s = __r.lock(); - *this = weak_ptr<_Tp>(__s); -} - -template -inline weak_ptr<_Tp>::weak_ptr(weak_ptr&& __r) _NOEXCEPT : __ptr_(__r.__ptr_), __cntrl_(__r.__cntrl_) { - __r.__ptr_ = nullptr; - __r.__cntrl_ = nullptr; -} - -template -template ::value, int> > -inline weak_ptr<_Tp>::weak_ptr(weak_ptr<_Yp>&& __r) _NOEXCEPT : __ptr_(nullptr), __cntrl_(nullptr) { - shared_ptr<_Yp> __s = __r.lock(); - *this = weak_ptr<_Tp>(__s); - __r.reset(); -} - -template -weak_ptr<_Tp>::~weak_ptr() { - if (__cntrl_) - __cntrl_->__release_weak(); -} - -template -inline weak_ptr<_Tp>& weak_ptr<_Tp>::operator=(weak_ptr const& __r) _NOEXCEPT { - weak_ptr(__r).swap(*this); - return *this; -} - -template -template ::value, int> > -inline weak_ptr<_Tp>& weak_ptr<_Tp>::operator=(weak_ptr<_Yp> const& __r) _NOEXCEPT { - weak_ptr(__r).swap(*this); - return *this; -} - -template -inline weak_ptr<_Tp>& weak_ptr<_Tp>::operator=(weak_ptr&& __r) _NOEXCEPT { - weak_ptr(std::move(__r)).swap(*this); - return *this; -} - -template -template ::value, int> > -inline weak_ptr<_Tp>& weak_ptr<_Tp>::operator=(weak_ptr<_Yp>&& __r) _NOEXCEPT { - weak_ptr(std::move(__r)).swap(*this); - return *this; -} - -template -template ::value, int> > -inline weak_ptr<_Tp>& weak_ptr<_Tp>::operator=(shared_ptr<_Yp> const& __r) _NOEXCEPT { - weak_ptr(__r).swap(*this); - return *this; -} - -template -inline void weak_ptr<_Tp>::swap(weak_ptr& __r) _NOEXCEPT { - std::swap(__ptr_, __r.__ptr_); - std::swap(__cntrl_, __r.__cntrl_); -} - template inline _LIBCPP_HIDE_FROM_ABI void swap(weak_ptr<_Tp>& __x, weak_ptr<_Tp>& __y) _NOEXCEPT { __x.swap(__y); } -template -inline void weak_ptr<_Tp>::reset() _NOEXCEPT { - weak_ptr().swap(*this); -} - -template -shared_ptr<_Tp> weak_ptr<_Tp>::lock() const _NOEXCEPT { - shared_ptr<_Tp> __r; - __r.__cntrl_ = __cntrl_ ? __cntrl_->lock() : __cntrl_; - if (__r.__cntrl_) - __r.__ptr_ = __ptr_; - return __r; -} - #if _LIBCPP_STD_VER >= 17 template struct owner_less; @@ -1536,6 +1467,7 @@ inline _LIBCPP_HIDE_FROM_ABI bool atomic_compare_exchange_weak_explicit( #endif // _LIBCPP_HAS_THREADS +_LIBCPP_END_EXPLICIT_ABI_ANNOTATIONS _LIBCPP_END_NAMESPACE_STD _LIBCPP_POP_MACROS diff --git a/lib/libcxx/include/__memory/temporary_buffer.h b/lib/libcxx/include/__memory/temporary_buffer.h index d18717f52d1cddcf2f99e931271482127010e0ad..3c572e43db6412af24bfb391e706790cc39fbb67 100644 --- a/lib/libcxx/include/__memory/temporary_buffer.h +++ b/lib/libcxx/include/__memory/temporary_buffer.h @@ -26,6 +26,9 @@ _LIBCPP_BEGIN_NAMESPACE_STD template [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_NO_CFI _LIBCPP_DEPRECATED_IN_CXX17 pair<_Tp*, ptrdiff_t> get_temporary_buffer(ptrdiff_t __n) _NOEXCEPT { + if (__n <= 0) + return pair<_Tp*, ptrdiff_t>(); + __unique_temporary_buffer<_Tp> __unique_buf = std::__allocate_unique_temporary_buffer<_Tp>(__n); pair<_Tp*, ptrdiff_t> __result(__unique_buf.get(), __unique_buf.get_deleter().__count_); __unique_buf.release(); diff --git a/lib/libcxx/include/__memory/uninitialized_algorithms.h b/lib/libcxx/include/__memory/uninitialized_algorithms.h index 9182db4b412e3223afac89d18b7d5251bb5909c4..f184b2b9dd92540d4b2ae4b42cece92aeecdc2f4 100644 --- a/lib/libcxx/include/__memory/uninitialized_algorithms.h +++ b/lib/libcxx/include/__memory/uninitialized_algorithms.h @@ -11,11 +11,10 @@ #define _LIBCPP___MEMORY_UNINITIALIZED_ALGORITHMS_H #include <__algorithm/copy.h> -#include <__algorithm/move.h> +#include <__algorithm/in_out_result.h> #include <__algorithm/unwrap_iter.h> #include <__algorithm/unwrap_range.h> #include <__config> -#include <__cstddef/size_t.h> #include <__fwd/memory.h> #include <__iterator/iterator_traits.h> #include <__iterator/reverse_iterator.h> @@ -25,15 +24,13 @@ #include <__memory/destroy.h> #include <__memory/pointer_traits.h> #include <__type_traits/enable_if.h> -#include <__type_traits/extent.h> -#include <__type_traits/is_array.h> #include <__type_traits/is_constant_evaluated.h> +#include <__type_traits/is_reference.h> #include <__type_traits/is_same.h> #include <__type_traits/is_trivially_assignable.h> #include <__type_traits/is_trivially_constructible.h> #include <__type_traits/is_trivially_relocatable.h> #include <__type_traits/remove_const.h> -#include <__type_traits/remove_extent.h> #include <__utility/exception_guard.h> #include <__utility/move.h> #include <__utility/pair.h> @@ -57,7 +54,8 @@ struct __always_false { // uninitialized_copy template -inline _LIBCPP_HIDE_FROM_ABI pair<_InputIterator, _ForwardIterator> __uninitialized_copy( +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __in_out_result<_InputIterator, _ForwardIterator> +__uninitialized_copy( _InputIterator __ifirst, _Sentinel1 __ilast, _ForwardIterator __ofirst, _EndPredicate __stop_copying) { _ForwardIterator __idx = __ofirst; auto __guard = std::__make_exception_guard([&] { std::__destroy(__ofirst, __idx); }); @@ -65,22 +63,22 @@ inline _LIBCPP_HIDE_FROM_ABI pair<_InputIterator, _ForwardIterator> __uninitiali ::new (static_cast(std::addressof(*__idx))) _ValueType(*__ifirst); __guard.__complete(); - return pair<_InputIterator, _ForwardIterator>(std::move(__ifirst), std::move(__idx)); + return {std::move(__ifirst), std::move(__idx)}; } template -_LIBCPP_HIDE_FROM_ABI _ForwardIterator +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 _ForwardIterator uninitialized_copy(_InputIterator __ifirst, _InputIterator __ilast, _ForwardIterator __ofirst) { typedef typename iterator_traits<_ForwardIterator>::value_type _ValueType; auto __result = std::__uninitialized_copy<_ValueType>( std::move(__ifirst), std::move(__ilast), std::move(__ofirst), __always_false()); - return std::move(__result.second); + return std::move(__result.__out_); } // uninitialized_copy_n template -inline _LIBCPP_HIDE_FROM_ABI pair<_InputIterator, _ForwardIterator> +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __in_out_result<_InputIterator, _ForwardIterator> __uninitialized_copy_n(_InputIterator __ifirst, _Size __n, _ForwardIterator __ofirst, _EndPredicate __stop_copying) { _ForwardIterator __idx = __ofirst; auto __guard = std::__make_exception_guard([&] { std::__destroy(__ofirst, __idx); }); @@ -88,22 +86,22 @@ __uninitialized_copy_n(_InputIterator __ifirst, _Size __n, _ForwardIterator __of ::new (static_cast(std::addressof(*__idx))) _ValueType(*__ifirst); __guard.__complete(); - return pair<_InputIterator, _ForwardIterator>(std::move(__ifirst), std::move(__idx)); + return {std::move(__ifirst), std::move(__idx)}; } template -inline _LIBCPP_HIDE_FROM_ABI _ForwardIterator +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 _ForwardIterator uninitialized_copy_n(_InputIterator __ifirst, _Size __n, _ForwardIterator __ofirst) { typedef typename iterator_traits<_ForwardIterator>::value_type _ValueType; auto __result = std::__uninitialized_copy_n<_ValueType>(std::move(__ifirst), __n, std::move(__ofirst), __always_false()); - return std::move(__result.second); + return std::move(__result.__out_); } // uninitialized_fill template -inline _LIBCPP_HIDE_FROM_ABI _ForwardIterator +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 _ForwardIterator __uninitialized_fill(_ForwardIterator __first, _Sentinel __last, const _Tp& __x) { _ForwardIterator __idx = __first; auto __guard = std::__make_exception_guard([&] { std::__destroy(__first, __idx); }); @@ -115,7 +113,7 @@ __uninitialized_fill(_ForwardIterator __first, _Sentinel __last, const _Tp& __x) } template -inline _LIBCPP_HIDE_FROM_ABI void +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void uninitialized_fill(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __x) { typedef typename iterator_traits<_ForwardIterator>::value_type _ValueType; (void)std::__uninitialized_fill<_ValueType>(__first, __last, __x); @@ -124,7 +122,7 @@ uninitialized_fill(_ForwardIterator __first, _ForwardIterator __last, const _Tp& // uninitialized_fill_n template -inline _LIBCPP_HIDE_FROM_ABI _ForwardIterator +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 _ForwardIterator __uninitialized_fill_n(_ForwardIterator __first, _Size __n, const _Tp& __x) { _ForwardIterator __idx = __first; auto __guard = std::__make_exception_guard([&] { std::__destroy(__first, __idx); }); @@ -136,7 +134,7 @@ __uninitialized_fill_n(_ForwardIterator __first, _Size __n, const _Tp& __x) { } template -inline _LIBCPP_HIDE_FROM_ABI _ForwardIterator +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 _ForwardIterator uninitialized_fill_n(_ForwardIterator __first, _Size __n, const _Tp& __x) { typedef typename iterator_traits<_ForwardIterator>::value_type _ValueType; return std::__uninitialized_fill_n<_ValueType>(__first, __n, __x); @@ -144,10 +142,18 @@ uninitialized_fill_n(_ForwardIterator __first, _Size __n, const _Tp& __x) { #if _LIBCPP_STD_VER >= 17 +template +_LIBCPP_HIDE_FROM_ABI constexpr decltype(auto) __deref_move(_Iter& __it) { + if constexpr (is_lvalue_reference_v) + return std::move(*__it); + else + return *__it; +} + // uninitialized_default_construct template -inline _LIBCPP_HIDE_FROM_ABI _ForwardIterator +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 _ForwardIterator __uninitialized_default_construct(_ForwardIterator __first, _Sentinel __last) { auto __idx = __first; auto __guard = std::__make_exception_guard([&] { std::__destroy(__first, __idx); }); @@ -159,7 +165,8 @@ __uninitialized_default_construct(_ForwardIterator __first, _Sentinel __last) { } template -inline _LIBCPP_HIDE_FROM_ABI void uninitialized_default_construct(_ForwardIterator __first, _ForwardIterator __last) { +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void +uninitialized_default_construct(_ForwardIterator __first, _ForwardIterator __last) { using _ValueType = typename iterator_traits<_ForwardIterator>::value_type; (void)std::__uninitialized_default_construct<_ValueType>(std::move(__first), std::move(__last)); } @@ -167,7 +174,8 @@ inline _LIBCPP_HIDE_FROM_ABI void uninitialized_default_construct(_ForwardIterat // uninitialized_default_construct_n template -inline _LIBCPP_HIDE_FROM_ABI _ForwardIterator __uninitialized_default_construct_n(_ForwardIterator __first, _Size __n) { +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 _ForwardIterator +__uninitialized_default_construct_n(_ForwardIterator __first, _Size __n) { auto __idx = __first; auto __guard = std::__make_exception_guard([&] { std::__destroy(__first, __idx); }); for (; __n > 0; ++__idx, (void)--__n) @@ -178,7 +186,8 @@ inline _LIBCPP_HIDE_FROM_ABI _ForwardIterator __uninitialized_default_construct_ } template -inline _LIBCPP_HIDE_FROM_ABI _ForwardIterator uninitialized_default_construct_n(_ForwardIterator __first, _Size __n) { +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 _ForwardIterator +uninitialized_default_construct_n(_ForwardIterator __first, _Size __n) { using _ValueType = typename iterator_traits<_ForwardIterator>::value_type; return std::__uninitialized_default_construct_n<_ValueType>(std::move(__first), __n); } @@ -186,7 +195,7 @@ inline _LIBCPP_HIDE_FROM_ABI _ForwardIterator uninitialized_default_construct_n( // uninitialized_value_construct template -inline _LIBCPP_HIDE_FROM_ABI _ForwardIterator +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 _ForwardIterator __uninitialized_value_construct(_ForwardIterator __first, _Sentinel __last) { auto __idx = __first; auto __guard = std::__make_exception_guard([&] { std::__destroy(__first, __idx); }); @@ -198,7 +207,8 @@ __uninitialized_value_construct(_ForwardIterator __first, _Sentinel __last) { } template -inline _LIBCPP_HIDE_FROM_ABI void uninitialized_value_construct(_ForwardIterator __first, _ForwardIterator __last) { +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void +uninitialized_value_construct(_ForwardIterator __first, _ForwardIterator __last) { using _ValueType = typename iterator_traits<_ForwardIterator>::value_type; (void)std::__uninitialized_value_construct<_ValueType>(std::move(__first), std::move(__last)); } @@ -206,7 +216,8 @@ inline _LIBCPP_HIDE_FROM_ABI void uninitialized_value_construct(_ForwardIterator // uninitialized_value_construct_n template -inline _LIBCPP_HIDE_FROM_ABI _ForwardIterator __uninitialized_value_construct_n(_ForwardIterator __first, _Size __n) { +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 _ForwardIterator +__uninitialized_value_construct_n(_ForwardIterator __first, _Size __n) { auto __idx = __first; auto __guard = std::__make_exception_guard([&] { std::__destroy(__first, __idx); }); for (; __n > 0; ++__idx, (void)--__n) @@ -217,7 +228,8 @@ inline _LIBCPP_HIDE_FROM_ABI _ForwardIterator __uninitialized_value_construct_n( } template -inline _LIBCPP_HIDE_FROM_ABI _ForwardIterator uninitialized_value_construct_n(_ForwardIterator __first, _Size __n) { +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 _ForwardIterator +uninitialized_value_construct_n(_ForwardIterator __first, _Size __n) { using _ValueType = typename iterator_traits<_ForwardIterator>::value_type; return std::__uninitialized_value_construct_n<_ValueType>(std::move(__first), __n); } @@ -230,12 +242,12 @@ template -inline _LIBCPP_HIDE_FROM_ABI pair<_InputIterator, _ForwardIterator> __uninitialized_move( - _InputIterator __ifirst, - _Sentinel1 __ilast, - _ForwardIterator __ofirst, - _EndPredicate __stop_moving, - _IterMove __iter_move) { +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __in_out_result<_InputIterator, _ForwardIterator> +__uninitialized_move(_InputIterator __ifirst, + _Sentinel1 __ilast, + _ForwardIterator __ofirst, + _EndPredicate __stop_moving, + _IterMove __iter_move) { auto __idx = __ofirst; auto __guard = std::__make_exception_guard([&] { std::__destroy(__ofirst, __idx); }); for (; __ifirst != __ilast && !__stop_moving(__idx); ++__idx, (void)++__ifirst) { @@ -247,14 +259,14 @@ inline _LIBCPP_HIDE_FROM_ABI pair<_InputIterator, _ForwardIterator> __uninitiali } template -inline _LIBCPP_HIDE_FROM_ABI _ForwardIterator +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 _ForwardIterator uninitialized_move(_InputIterator __ifirst, _InputIterator __ilast, _ForwardIterator __ofirst) { using _ValueType = typename iterator_traits<_ForwardIterator>::value_type; - auto __iter_move = [](auto&& __iter) -> decltype(auto) { return std::move(*__iter); }; + auto __iter_move = [](auto&& __iter) -> decltype(auto) { return std::__deref_move(__iter); }; auto __result = std::__uninitialized_move<_ValueType>( std::move(__ifirst), std::move(__ilast), std::move(__ofirst), __always_false(), __iter_move); - return std::move(__result.second); + return std::move(__result.__out_); } // uninitialized_move_n @@ -265,7 +277,8 @@ template -inline _LIBCPP_HIDE_FROM_ABI pair<_InputIterator, _ForwardIterator> __uninitialized_move_n( +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __in_out_result<_InputIterator, _ForwardIterator> +__uninitialized_move_n( _InputIterator __ifirst, _Size __n, _ForwardIterator __ofirst, _EndPredicate __stop_moving, _IterMove __iter_move) { auto __idx = __ofirst; auto __guard = std::__make_exception_guard([&] { std::__destroy(__ofirst, __idx); }); @@ -277,166 +290,14 @@ inline _LIBCPP_HIDE_FROM_ABI pair<_InputIterator, _ForwardIterator> __uninitiali } template -inline _LIBCPP_HIDE_FROM_ABI pair<_InputIterator, _ForwardIterator> +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 pair<_InputIterator, _ForwardIterator> uninitialized_move_n(_InputIterator __ifirst, _Size __n, _ForwardIterator __ofirst) { using _ValueType = typename iterator_traits<_ForwardIterator>::value_type; - auto __iter_move = [](auto&& __iter) -> decltype(auto) { return std::move(*__iter); }; + auto __iter_move = [](auto&& __iter) -> decltype(auto) { return std::__deref_move(__iter); }; - return std::__uninitialized_move_n<_ValueType>( + auto __result = std::__uninitialized_move_n<_ValueType>( std::move(__ifirst), __n, std::move(__ofirst), __always_false(), __iter_move); -} - -// TODO: Rewrite this to iterate left to right and use reverse_iterators when calling -// Destroys every element in the range [first, last) FROM RIGHT TO LEFT using allocator -// destruction. If elements are themselves C-style arrays, they are recursively destroyed -// in the same manner. -// -// This function assumes that destructors do not throw, and that the allocator is bound to -// the correct type. -template ::value, int> = 0> -_LIBCPP_HIDE_FROM_ABI constexpr void -__allocator_destroy_multidimensional(_Alloc& __alloc, _BidirIter __first, _BidirIter __last) noexcept { - using _ValueType = typename iterator_traits<_BidirIter>::value_type; - static_assert(is_same_v::value_type, _ValueType>, - "The allocator should already be rebound to the correct type"); - - if (__first == __last) - return; - - if constexpr (is_array_v<_ValueType>) { - static_assert(!__is_unbounded_array_v<_ValueType>, - "arrays of unbounded arrays don't exist, but if they did we would mess up here"); - - using _Element = remove_extent_t<_ValueType>; - __allocator_traits_rebind_t<_Alloc, _Element> __elem_alloc(__alloc); - do { - --__last; - decltype(auto) __array = *__last; - std::__allocator_destroy_multidimensional(__elem_alloc, __array, __array + extent_v<_ValueType>); - } while (__last != __first); - } else { - do { - --__last; - allocator_traits<_Alloc>::destroy(__alloc, std::addressof(*__last)); - } while (__last != __first); - } -} - -// Constructs the object at the given location using the allocator's construct method. -// -// If the object being constructed is an array, each element of the array is allocator-constructed, -// recursively. If an exception is thrown during the construction of an array, the initialized -// elements are destroyed in reverse order of initialization using allocator destruction. -// -// This function assumes that the allocator is bound to the correct type. -template -_LIBCPP_HIDE_FROM_ABI constexpr void __allocator_construct_at_multidimensional(_Alloc& __alloc, _Tp* __loc) { - static_assert(is_same_v::value_type, _Tp>, - "The allocator should already be rebound to the correct type"); - - if constexpr (is_array_v<_Tp>) { - using _Element = remove_extent_t<_Tp>; - __allocator_traits_rebind_t<_Alloc, _Element> __elem_alloc(__alloc); - size_t __i = 0; - _Tp& __array = *__loc; - - // If an exception is thrown, destroy what we have constructed so far in reverse order. - auto __guard = std::__make_exception_guard([&]() { - std::__allocator_destroy_multidimensional(__elem_alloc, __array, __array + __i); - }); - - for (; __i != extent_v<_Tp>; ++__i) { - std::__allocator_construct_at_multidimensional(__elem_alloc, std::addressof(__array[__i])); - } - __guard.__complete(); - } else { - allocator_traits<_Alloc>::construct(__alloc, __loc); - } -} - -// Constructs the object at the given location using the allocator's construct method, passing along -// the provided argument. -// -// If the object being constructed is an array, the argument is also assumed to be an array. Each -// each element of the array being constructed is allocator-constructed from the corresponding -// element of the argument array. If an exception is thrown during the construction of an array, -// the initialized elements are destroyed in reverse order of initialization using allocator -// destruction. -// -// This function assumes that the allocator is bound to the correct type. -template -_LIBCPP_HIDE_FROM_ABI constexpr void -__allocator_construct_at_multidimensional(_Alloc& __alloc, _Tp* __loc, _Arg const& __arg) { - static_assert(is_same_v::value_type, _Tp>, - "The allocator should already be rebound to the correct type"); - - if constexpr (is_array_v<_Tp>) { - static_assert(is_array_v<_Arg>, - "Provided non-array initialization argument to __allocator_construct_at_multidimensional when " - "trying to construct an array."); - - using _Element = remove_extent_t<_Tp>; - __allocator_traits_rebind_t<_Alloc, _Element> __elem_alloc(__alloc); - size_t __i = 0; - _Tp& __array = *__loc; - - // If an exception is thrown, destroy what we have constructed so far in reverse order. - auto __guard = std::__make_exception_guard([&]() { - std::__allocator_destroy_multidimensional(__elem_alloc, __array, __array + __i); - }); - for (; __i != extent_v<_Tp>; ++__i) { - std::__allocator_construct_at_multidimensional(__elem_alloc, std::addressof(__array[__i]), __arg[__i]); - } - __guard.__complete(); - } else { - allocator_traits<_Alloc>::construct(__alloc, __loc, __arg); - } -} - -// Given a range starting at it and containing n elements, initializes each element in the -// range from left to right using the construct method of the allocator (rebound to the -// correct type). -// -// If an exception is thrown, the initialized elements are destroyed in reverse order of -// initialization using allocator_traits destruction. If the elements in the range are C-style -// arrays, they are initialized element-wise using allocator construction, and recursively so. -template ::difference_type> -_LIBCPP_HIDE_FROM_ABI constexpr void -__uninitialized_allocator_fill_n_multidimensional(_Alloc& __alloc, _BidirIter __it, _Size __n, _Tp const& __value) { - using _ValueType = typename iterator_traits<_BidirIter>::value_type; - __allocator_traits_rebind_t<_Alloc, _ValueType> __value_alloc(__alloc); - _BidirIter __begin = __it; - - // If an exception is thrown, destroy what we have constructed so far in reverse order. - auto __guard = - std::__make_exception_guard([&]() { std::__allocator_destroy_multidimensional(__value_alloc, __begin, __it); }); - for (; __n != 0; --__n, ++__it) { - std::__allocator_construct_at_multidimensional(__value_alloc, std::addressof(*__it), __value); - } - __guard.__complete(); -} - -// Same as __uninitialized_allocator_fill_n_multidimensional, but doesn't pass any initialization argument -// to the allocator's construct method, which results in value initialization. -template ::difference_type> -_LIBCPP_HIDE_FROM_ABI constexpr void -__uninitialized_allocator_value_construct_n_multidimensional(_Alloc& __alloc, _BidirIter __it, _Size __n) { - using _ValueType = typename iterator_traits<_BidirIter>::value_type; - __allocator_traits_rebind_t<_Alloc, _ValueType> __value_alloc(__alloc); - _BidirIter __begin = __it; - - // If an exception is thrown, destroy what we have constructed so far in reverse order. - auto __guard = - std::__make_exception_guard([&]() { std::__allocator_destroy_multidimensional(__value_alloc, __begin, __it); }); - for (; __n != 0; --__n, ++__it) { - std::__allocator_construct_at_multidimensional(__value_alloc, std::addressof(*__it)); - } - __guard.__complete(); + return {std::move(__result.__in_), std::move(__result.__out_)}; } #endif // _LIBCPP_STD_VER >= 17 @@ -486,7 +347,7 @@ inline const bool __allocator_has_trivial_copy_construct_v, _Ty template ::value && is_trivially_copy_assignable<_In>::value && + __enable_if_t::value && is_trivially_assignable<_Out&, _In&>::value && is_same<__remove_const_t<_In>, __remove_const_t<_Out> >::value && __allocator_has_trivial_copy_construct_v<_Alloc, _In>, int> = 0> diff --git a/lib/libcxx/include/__memory/uninitialized_multidimensional_algorithms.h b/lib/libcxx/include/__memory/uninitialized_multidimensional_algorithms.h new file mode 100644 index 0000000000000000000000000000000000000000..2496ce6af1e151ce3bfde91da5b4fed035f50658 --- /dev/null +++ b/lib/libcxx/include/__memory/uninitialized_multidimensional_algorithms.h @@ -0,0 +1,194 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP___MEMORY_UNINITIALIZED_MULTIDIMENSIONAL_ALGORITHMS_H +#define _LIBCPP___MEMORY_UNINITIALIZED_MULTIDIMENSIONAL_ALGORITHMS_H + +#include <__config> +#include <__cstddef/size_t.h> +#include <__iterator/iterator_traits.h> +#include <__memory/addressof.h> +#include <__memory/allocator_traits.h> +#include <__type_traits/enable_if.h> +#include <__type_traits/extent.h> +#include <__type_traits/is_array.h> +#include <__type_traits/is_same.h> +#include <__type_traits/remove_extent.h> +#include <__utility/exception_guard.h> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + +#if _LIBCPP_STD_VER >= 17 + +_LIBCPP_BEGIN_NAMESPACE_STD + +// TODO: Rewrite this to iterate left to right and use reverse_iterators when calling +// Destroys every element in the range [first, last) FROM RIGHT TO LEFT using allocator +// destruction. If elements are themselves C-style arrays, they are recursively destroyed +// in the same manner. +// +// This function assumes that destructors do not throw, and that the allocator is bound to +// the correct type. +template ::value, int> = 0> +_LIBCPP_HIDE_FROM_ABI constexpr void +__allocator_destroy_multidimensional(_Alloc& __alloc, _BidirIter __first, _BidirIter __last) noexcept { + using _ValueType = typename iterator_traits<_BidirIter>::value_type; + static_assert(is_same_v::value_type, _ValueType>, + "The allocator should already be rebound to the correct type"); + + if (__first == __last) + return; + + if constexpr (is_array_v<_ValueType>) { + static_assert(!__is_unbounded_array_v<_ValueType>, + "arrays of unbounded arrays don't exist, but if they did we would mess up here"); + + using _Element = remove_extent_t<_ValueType>; + __allocator_traits_rebind_t<_Alloc, _Element> __elem_alloc(__alloc); + do { + --__last; + decltype(auto) __array = *__last; + std::__allocator_destroy_multidimensional(__elem_alloc, __array, __array + extent_v<_ValueType>); + } while (__last != __first); + } else { + do { + --__last; + allocator_traits<_Alloc>::destroy(__alloc, std::addressof(*__last)); + } while (__last != __first); + } +} + +// Constructs the object at the given location using the allocator's construct method. +// +// If the object being constructed is an array, each element of the array is allocator-constructed, +// recursively. If an exception is thrown during the construction of an array, the initialized +// elements are destroyed in reverse order of initialization using allocator destruction. +// +// This function assumes that the allocator is bound to the correct type. +template +_LIBCPP_HIDE_FROM_ABI constexpr void __allocator_construct_at_multidimensional(_Alloc& __alloc, _Tp* __loc) { + static_assert(is_same_v::value_type, _Tp>, + "The allocator should already be rebound to the correct type"); + + if constexpr (is_array_v<_Tp>) { + using _Element = remove_extent_t<_Tp>; + __allocator_traits_rebind_t<_Alloc, _Element> __elem_alloc(__alloc); + size_t __i = 0; + _Tp& __array = *__loc; + + // If an exception is thrown, destroy what we have constructed so far in reverse order. + auto __guard = std::__make_exception_guard([&]() { + std::__allocator_destroy_multidimensional(__elem_alloc, __array, __array + __i); + }); + + for (; __i != extent_v<_Tp>; ++__i) { + std::__allocator_construct_at_multidimensional(__elem_alloc, std::addressof(__array[__i])); + } + __guard.__complete(); + } else { + allocator_traits<_Alloc>::construct(__alloc, __loc); + } +} + +// Constructs the object at the given location using the allocator's construct method, passing along +// the provided argument. +// +// If the object being constructed is an array, the argument is also assumed to be an array. Each +// each element of the array being constructed is allocator-constructed from the corresponding +// element of the argument array. If an exception is thrown during the construction of an array, +// the initialized elements are destroyed in reverse order of initialization using allocator +// destruction. +// +// This function assumes that the allocator is bound to the correct type. +template +_LIBCPP_HIDE_FROM_ABI constexpr void +__allocator_construct_at_multidimensional(_Alloc& __alloc, _Tp* __loc, _Arg const& __arg) { + static_assert(is_same_v::value_type, _Tp>, + "The allocator should already be rebound to the correct type"); + + if constexpr (is_array_v<_Tp>) { + static_assert(is_array_v<_Arg>, + "Provided non-array initialization argument to __allocator_construct_at_multidimensional when " + "trying to construct an array."); + + using _Element = remove_extent_t<_Tp>; + __allocator_traits_rebind_t<_Alloc, _Element> __elem_alloc(__alloc); + size_t __i = 0; + _Tp& __array = *__loc; + + // If an exception is thrown, destroy what we have constructed so far in reverse order. + auto __guard = std::__make_exception_guard([&]() { + std::__allocator_destroy_multidimensional(__elem_alloc, __array, __array + __i); + }); + for (; __i != extent_v<_Tp>; ++__i) { + std::__allocator_construct_at_multidimensional(__elem_alloc, std::addressof(__array[__i]), __arg[__i]); + } + __guard.__complete(); + } else { + allocator_traits<_Alloc>::construct(__alloc, __loc, __arg); + } +} + +// Given a range starting at it and containing n elements, initializes each element in the +// range from left to right using the construct method of the allocator (rebound to the +// correct type). +// +// If an exception is thrown, the initialized elements are destroyed in reverse order of +// initialization using allocator_traits destruction. If the elements in the range are C-style +// arrays, they are initialized element-wise using allocator construction, and recursively so. +template ::difference_type> +_LIBCPP_HIDE_FROM_ABI constexpr void +__uninitialized_allocator_fill_n_multidimensional(_Alloc& __alloc, _BidirIter __it, _Size __n, _Tp const& __value) { + using _ValueType = typename iterator_traits<_BidirIter>::value_type; + __allocator_traits_rebind_t<_Alloc, _ValueType> __value_alloc(__alloc); + _BidirIter __begin = __it; + + // If an exception is thrown, destroy what we have constructed so far in reverse order. + auto __guard = + std::__make_exception_guard([&]() { std::__allocator_destroy_multidimensional(__value_alloc, __begin, __it); }); + for (; __n != 0; --__n, ++__it) { + std::__allocator_construct_at_multidimensional(__value_alloc, std::addressof(*__it), __value); + } + __guard.__complete(); +} + +// Same as __uninitialized_allocator_fill_n_multidimensional, but doesn't pass any initialization argument +// to the allocator's construct method, which results in value initialization. +template ::difference_type> +_LIBCPP_HIDE_FROM_ABI constexpr void +__uninitialized_allocator_value_construct_n_multidimensional(_Alloc& __alloc, _BidirIter __it, _Size __n) { + using _ValueType = typename iterator_traits<_BidirIter>::value_type; + __allocator_traits_rebind_t<_Alloc, _ValueType> __value_alloc(__alloc); + _BidirIter __begin = __it; + + // If an exception is thrown, destroy what we have constructed so far in reverse order. + auto __guard = + std::__make_exception_guard([&]() { std::__allocator_destroy_multidimensional(__value_alloc, __begin, __it); }); + for (; __n != 0; --__n, ++__it) { + std::__allocator_construct_at_multidimensional(__value_alloc, std::addressof(*__it)); + } + __guard.__complete(); +} + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_STD_VER >= 17 + +_LIBCPP_POP_MACROS + +#endif // _LIBCPP___MEMORY_UNINITIALIZED_MULTIDIMENSIONAL_ALGORITHMS_H diff --git a/lib/libcxx/include/__memory/unique_ptr.h b/lib/libcxx/include/__memory/unique_ptr.h index 6a4ec0a466ba7b804eb902d6c5ecbcace558b869..46256b8fa8805b8f45075f03bbf573ed0109b0ae 100644 --- a/lib/libcxx/include/__memory/unique_ptr.h +++ b/lib/libcxx/include/__memory/unique_ptr.h @@ -27,7 +27,6 @@ #include <__type_traits/add_reference.h> #include <__type_traits/common_type.h> #include <__type_traits/conditional.h> -#include <__type_traits/dependent_type.h> #include <__type_traits/enable_if.h> #include <__type_traits/integral_constant.h> #include <__type_traits/is_array.h> @@ -43,7 +42,8 @@ #include <__type_traits/is_trivially_relocatable.h> #include <__type_traits/is_void.h> #include <__type_traits/remove_extent.h> -#include <__type_traits/type_identity.h> +#include <__type_traits/remove_reference.h> +#include <__type_traits/void_t.h> #include <__utility/declval.h> #include <__utility/forward.h> #include <__utility/move.h> @@ -95,27 +95,17 @@ inline const bool __is_default_deleter_v = false; template inline const bool __is_default_deleter_v > = true; -template -struct __unique_ptr_deleter_sfinae { - static_assert(!is_reference<_Deleter>::value, "incorrect specialization"); - typedef const _Deleter& __lval_ref_type; - typedef _Deleter&& __good_rval_ref_type; - typedef true_type __enable_rval_overload; -}; +template +inline const bool __can_dereference = false; -template -struct __unique_ptr_deleter_sfinae<_Deleter const&> { - typedef const _Deleter& __lval_ref_type; - typedef const _Deleter&& __bad_rval_ref_type; - typedef false_type __enable_rval_overload; -}; +template +inline const bool __can_dereference<_Tp, decltype((void)*std::declval<_Tp>())> = true; -template -struct __unique_ptr_deleter_sfinae<_Deleter&> { - typedef _Deleter& __lval_ref_type; - typedef _Deleter&& __bad_rval_ref_type; - typedef false_type __enable_rval_overload; -}; +template +inline const bool __can_add_pointer = false; + +template +inline const bool __can_add_pointer<_Tp, __void_t<_Tp*> > = true; #if defined(_LIBCPP_ABI_ENABLE_UNIQUE_PTR_TRIVIAL_ABI) # define _LIBCPP_UNIQUE_PTR_TRIVIAL_ABI __attribute__((__trivial_abi__)) @@ -125,13 +115,14 @@ struct __unique_ptr_deleter_sfinae<_Deleter&> { template > class _LIBCPP_UNIQUE_PTR_TRIVIAL_ABI unique_ptr { + static_assert(__can_add_pointer<_Tp>, "unique_ptr requires T* to be a valid type"); + static_assert(!is_rvalue_reference<_Dp>::value, "the specified deleter type cannot be an rvalue reference"); + public: typedef _Tp element_type; typedef _Dp deleter_type; using pointer _LIBCPP_NODEBUG = __pointer<_Tp, deleter_type>; - static_assert(!is_rvalue_reference::value, "the specified deleter type cannot be an rvalue reference"); - // A unique_ptr contains the following members which may be trivially relocatable: // - pointer : this may be trivially relocatable, so it's checked // - deleter_type: this may be trivially relocatable, so it's checked @@ -146,24 +137,6 @@ public: private: _LIBCPP_COMPRESSED_PAIR(pointer, __ptr_, deleter_type, __deleter_); - using _DeleterSFINAE _LIBCPP_NODEBUG = __unique_ptr_deleter_sfinae<_Dp>; - - template - using _LValRefType _LIBCPP_NODEBUG = typename __dependent_type<_DeleterSFINAE, _Dummy>::__lval_ref_type; - - template - using _GoodRValRefType _LIBCPP_NODEBUG = typename __dependent_type<_DeleterSFINAE, _Dummy>::__good_rval_ref_type; - - template - using _BadRValRefType _LIBCPP_NODEBUG = typename __dependent_type<_DeleterSFINAE, _Dummy>::__bad_rval_ref_type; - - template , _Dummy>::type> - using _EnableIfDeleterDefaultConstructible _LIBCPP_NODEBUG = - __enable_if_t::value && !is_pointer<_Deleter>::value>; - - template - using _EnableIfDeleterConstructible _LIBCPP_NODEBUG = __enable_if_t::value>; - template using _EnableIfMoveConvertible _LIBCPP_NODEBUG = __enable_if_t< is_convertible::value && !is_array<_Up>::value >; @@ -177,31 +150,33 @@ private: using _EnableIfDeleterAssignable _LIBCPP_NODEBUG = __enable_if_t< is_assignable<_Dp&, _UDel&&>::value >; public: - template > + template ::value && !is_pointer<_Deleter>::value, int> = 0> _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR unique_ptr() _NOEXCEPT : __ptr_(), __deleter_() {} - template > + template ::value && !is_pointer<_Deleter>::value, int> = 0> _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR unique_ptr(nullptr_t) _NOEXCEPT : __ptr_(), __deleter_() {} - template > + template ::value && !is_pointer<_Deleter>::value, int> = 0> _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 explicit unique_ptr(pointer __p) _NOEXCEPT : __ptr_(__p), __deleter_() {} - template > > - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unique_ptr(pointer __p, _LValRefType<_Dummy> __d) _NOEXCEPT + template ::value, int> = 0> + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unique_ptr(pointer __p, const deleter_type& __d) _NOEXCEPT : __ptr_(__p), __deleter_(__d) {} - template > > - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unique_ptr(pointer __p, _GoodRValRefType<_Dummy> __d) _NOEXCEPT + template ::value && is_move_constructible<_Deleter>::value, int> = 0> + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unique_ptr(pointer __p, deleter_type&& __d) _NOEXCEPT : __ptr_(__p), - __deleter_(std::move(__d)) { - static_assert(!is_reference::value, "rvalue deleter bound to reference"); - } + __deleter_(std::move(__d)) {} - template > > - _LIBCPP_HIDE_FROM_ABI unique_ptr(pointer __p, _BadRValRefType<_Dummy> __d) = delete; + template ::value, int> = 0> + _LIBCPP_HIDE_FROM_ABI unique_ptr(pointer, __libcpp_remove_reference_t&&) = delete; _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unique_ptr(unique_ptr&& __u) _NOEXCEPT : __ptr_(__u.release()), @@ -222,7 +197,7 @@ public: #endif _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unique_ptr& operator=(unique_ptr&& __u) _NOEXCEPT { - reset(__u.release()); + reset(__u.release()); // NOLINT(misc-uniqueptr-reset-release) __deleter_ = std::forward(__u.get_deleter()); return *this; } @@ -258,6 +233,7 @@ public: return *this; } + template , int> = 0> [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 __add_lvalue_reference_t<_Tp> operator*() const _NOEXCEPT_(_NOEXCEPT_(*std::declval())) { return *__ptr_; @@ -434,27 +410,6 @@ private: (is_same::value && is_convertible<_FromElem (*)[], element_type (*)[]>::value) > {}; - typedef __unique_ptr_deleter_sfinae<_Dp> _DeleterSFINAE; - - template - using _LValRefType _LIBCPP_NODEBUG = typename __dependent_type<_DeleterSFINAE, _Dummy>::__lval_ref_type; - - template - using _GoodRValRefType _LIBCPP_NODEBUG = typename __dependent_type<_DeleterSFINAE, _Dummy>::__good_rval_ref_type; - - template - using _BadRValRefType _LIBCPP_NODEBUG = typename __dependent_type<_DeleterSFINAE, _Dummy>::__bad_rval_ref_type; - - template , _Dummy>::type> - using _EnableIfDeleterDefaultConstructible _LIBCPP_NODEBUG = - __enable_if_t::value && !is_pointer<_Deleter>::value>; - - template - using _EnableIfDeleterConstructible _LIBCPP_NODEBUG = __enable_if_t::value>; - - template - using _EnableIfPointerConvertible _LIBCPP_NODEBUG = __enable_if_t< _CheckArrayPointerConversion<_Pp>::value >; - template using _EnableIfMoveConvertible _LIBCPP_NODEBUG = __enable_if_t< is_array<_Up>::value && is_same::value && @@ -470,17 +425,19 @@ private: using _EnableIfDeleterAssignable _LIBCPP_NODEBUG = __enable_if_t< is_assignable<_Dp&, _UDel&&>::value >; public: - template > + template ::value && !is_pointer<_Deleter>::value, int> = 0> _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR unique_ptr() _NOEXCEPT : __ptr_(), __deleter_() {} - template > + template ::value && !is_pointer<_Deleter>::value, int> = 0> _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR unique_ptr(nullptr_t) _NOEXCEPT : __ptr_(), __deleter_() {} - template , - class = _EnableIfPointerConvertible<_Pp> > - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 explicit unique_ptr(_Pp __ptr) _NOEXCEPT + template ::value && !is_pointer<_Deleter>::value, int> = 0, + __enable_if_t<_CheckArrayPointerConversion<_Ptr>::value, int> = 0> + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 explicit unique_ptr(_Ptr __ptr) _NOEXCEPT : __ptr_(__ptr), __deleter_() {} @@ -490,43 +447,38 @@ public: : __ptr_(__ptr), __checker_(__size) {} - template >, - class = _EnableIfPointerConvertible<_Pp> > - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unique_ptr(_Pp __ptr, _LValRefType<_Dummy> __deleter) _NOEXCEPT + template ::value, int> = 0, + __enable_if_t<_CheckArrayPointerConversion<_Ptr>::value, int> = 0> + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unique_ptr(_Ptr __ptr, const deleter_type& __deleter) _NOEXCEPT : __ptr_(__ptr), __deleter_(__deleter) {} - template > > - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unique_ptr(nullptr_t, _LValRefType<_Dummy> __deleter) _NOEXCEPT + template ::value, int> = 0> + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unique_ptr(nullptr_t, const deleter_type& __deleter) _NOEXCEPT : __ptr_(nullptr), __deleter_(__deleter) {} - template >, - class = _EnableIfPointerConvertible<_Pp> > - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 - unique_ptr(_Pp __ptr, _GoodRValRefType<_Dummy> __deleter) _NOEXCEPT + template ::value && is_move_constructible<_Deleter>::value, int> = 0, + __enable_if_t<_CheckArrayPointerConversion<_Ptr>::value, int> = 0> + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unique_ptr(_Ptr __ptr, deleter_type&& __deleter) _NOEXCEPT : __ptr_(__ptr), - __deleter_(std::move(__deleter)) { - static_assert(!is_reference::value, "rvalue deleter bound to reference"); - } + __deleter_(std::move(__deleter)) {} - template > > - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 - unique_ptr(nullptr_t, _GoodRValRefType<_Dummy> __deleter) _NOEXCEPT + template ::value && is_move_constructible<_Deleter>::value, int> = 0> + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unique_ptr(nullptr_t, deleter_type&& __deleter) _NOEXCEPT : __ptr_(nullptr), - __deleter_(std::move(__deleter)) { - static_assert(!is_reference::value, "rvalue deleter bound to reference"); - } + __deleter_(std::move(__deleter)) {} - template >, - class = _EnableIfPointerConvertible<_Pp> > - _LIBCPP_HIDE_FROM_ABI unique_ptr(_Pp __ptr, _BadRValRefType<_Dummy> __deleter) = delete; + template ::value, int> = 0, + __enable_if_t<_CheckArrayPointerConversion<_Ptr>::value, int> = 0> + _LIBCPP_HIDE_FROM_ABI unique_ptr(_Ptr, __libcpp_remove_reference_t&&) = delete; _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unique_ptr(unique_ptr&& __u) _NOEXCEPT : __ptr_(__u.release()), @@ -534,7 +486,7 @@ public: __checker_(std::move(__u.__checker_)) {} _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unique_ptr& operator=(unique_ptr&& __u) _NOEXCEPT { - reset(__u.release()); + reset(__u.release()); // NOLINT(misc-uniqueptr-reset-release) __deleter_ = std::forward(__u.get_deleter()); __checker_ = std::move(__u.__checker_); return *this; diff --git a/lib/libcxx/include/__memory/uses_allocator_construction.h b/lib/libcxx/include/__memory/uses_allocator_construction.h index 6733f5cf6fc354ad69fa74e6f0011c0f7b5ed6d1..e9653f6c4ea5ebb9ee4ad16734af6f93ea42fcd2 100644 --- a/lib/libcxx/include/__memory/uses_allocator_construction.h +++ b/lib/libcxx/include/__memory/uses_allocator_construction.h @@ -27,10 +27,10 @@ _LIBCPP_PUSH_MACROS #include <__undef_macros> -_LIBCPP_BEGIN_NAMESPACE_STD - #if _LIBCPP_STD_VER >= 17 +_LIBCPP_BEGIN_NAMESPACE_STD + template inline constexpr bool __is_cv_std_pair = __is_pair_v>; @@ -202,9 +202,7 @@ __uninitialized_construct_using_allocator(_Type* __ptr, const _Alloc& __alloc, _ __uses_allocator_construction_args<_Type>::__apply(__alloc, std::forward<_Args>(__args)...)); } -#endif // _LIBCPP_STD_VER >= 17 - -#if _LIBCPP_STD_VER >= 20 +# if _LIBCPP_STD_VER >= 20 template _LIBCPP_HIDE_FROM_ABI constexpr auto uses_allocator_construction_args(const _Alloc& __alloc, _Args&&... __args) noexcept @@ -225,10 +223,12 @@ uninitialized_construct_using_allocator(_Type* __ptr, const _Alloc& __alloc, _Ar return /*--*/ std::__uninitialized_construct_using_allocator(__ptr, __alloc, std::forward<_Args>(__args)...); } -#endif // _LIBCPP_STD_VER >= 20 +# endif // _LIBCPP_STD_VER >= 20 _LIBCPP_END_NAMESPACE_STD +#endif // _LIBCPP_STD_VER >= 17 + _LIBCPP_POP_MACROS #endif // _LIBCPP___MEMORY_USES_ALLOCATOR_CONSTRUCTION_H diff --git a/lib/libcxx/include/__memory/valid_range.h b/lib/libcxx/include/__memory/valid_range.h new file mode 100644 index 0000000000000000000000000000000000000000..32c98588fe39af8d19d772bcb750041a84939459 --- /dev/null +++ b/lib/libcxx/include/__memory/valid_range.h @@ -0,0 +1,74 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP___MEMORY_VALID_RANGE_H +#define _LIBCPP___MEMORY_VALID_RANGE_H + +#include <__algorithm/comp.h> +#include <__assert> +#include <__config> +#include <__iterator/iterator_traits.h> +#include <__memory/assume_aligned.h> +#include <__memory/pointer_traits.h> +#include <__type_traits/is_constant_evaluated.h> +#include <__type_traits/is_same.h> +#include <__type_traits/remove_cvref.h> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +// A valid range as defined by the C++ Standard has the following constraints: +// - [__first, __last) is dereferenceable +// - __last is reachable from __first +// - if __first and __last are contiguous iterators, the pointers they "decay to" are correctly aligned according to the +// language rules for pointers + +// This function attempts to detect invalid ranges as defined above. Specifically, it checks bullet (2). This also means +// that it doesn't return whether a range is actually valid, but only whether a range is definitely not valid. +// The checks may be extended in the future. +template +_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI _LIBCPP_NO_SANITIZE("address") bool +__is_valid_range(const _Tp* __first, const _Tp* __last) { + if (__libcpp_is_constant_evaluated()) { + // If this is not a constant during constant evaluation, that is because __first and __last are not + // part of the same allocation. If they are part of the same allocation, we must still make sure they + // are ordered properly. + return __builtin_constant_p(__first <= __last) && __first <= __last; + } + + return !__less<>()(__last, __first); +} + +// This function allows the compiler to assume that [__first, __last) is a valid range as defined above. +// +// In practice, we only add explicit assumptions for bullets (1) and (3). These assumptions allow (currently only +// clang-based compilers) to auto-vectorize algorithms that contain early returns. +template +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void +__assume_valid_range([[__maybe_unused__]] _Iter&& __first, [[__maybe_unused__]] _Sent&& __last) { +#if defined(_LIBCPP_CLANG_VER) && _LIBCPP_CLANG_VER >= 2300 && !defined(_LIBCPP_CXX03_LANG) + if constexpr (__libcpp_is_contiguous_iterator<__remove_cvref_t<_Iter>>::value && + is_same<__remove_cvref_t<_Iter>, __remove_cvref_t<_Sent>>::value) { + _LIBCPP_ASSERT_INTERNAL(std::__is_valid_range(std::__to_address(__first), std::__to_address(__last)), + "Valid range assumption does not hold"); + if (!__libcpp_is_constant_evaluated()) { + using __value_type = typename iterator_traits<__remove_cvref_t<_Iter>>::value_type; + __builtin_assume_dereferenceable(std::__to_address(__first), (__last - __first) * sizeof(__value_type)); + (void)std::__assume_aligned<_LIBCPP_ALIGNOF(__value_type)>(std::__to_address(__first)); + (void)std::__assume_aligned<_LIBCPP_ALIGNOF(__value_type)>(std::__to_address(__last)); + } + } +#endif +} + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___MEMORY_VALID_RANGE_H diff --git a/lib/libcxx/include/__memory_resource/memory_resource.h b/lib/libcxx/include/__memory_resource/memory_resource.h index 5b42ae54890b1b65ce9483dd6039739bb9fa0ce3..c5726bd2bcdb5ad3c4536e1a5300db357f9654f5 100644 --- a/lib/libcxx/include/__memory_resource/memory_resource.h +++ b/lib/libcxx/include/__memory_resource/memory_resource.h @@ -21,6 +21,7 @@ #if _LIBCPP_STD_VER >= 17 _LIBCPP_BEGIN_NAMESPACE_STD +_LIBCPP_BEGIN_EXPLICIT_ABI_ANNOTATIONS namespace pmr { @@ -84,6 +85,7 @@ null_memory_resource() noexcept; } // namespace pmr +_LIBCPP_END_EXPLICIT_ABI_ANNOTATIONS _LIBCPP_END_NAMESPACE_STD #endif // _LIBCPP_STD_VER >= 17 diff --git a/lib/libcxx/include/__memory_resource/monotonic_buffer_resource.h b/lib/libcxx/include/__memory_resource/monotonic_buffer_resource.h index 9c7b07df52f8a945e13e0b0dd4921180fb0c7fb5..a6d292386169b937d1cc8050037d69dd98659afa 100644 --- a/lib/libcxx/include/__memory_resource/monotonic_buffer_resource.h +++ b/lib/libcxx/include/__memory_resource/monotonic_buffer_resource.h @@ -21,6 +21,7 @@ #if _LIBCPP_STD_VER >= 17 _LIBCPP_BEGIN_NAMESPACE_STD +_LIBCPP_BEGIN_EXPLICIT_ABI_ANNOTATIONS namespace pmr { @@ -112,6 +113,7 @@ private: } // namespace pmr +_LIBCPP_END_EXPLICIT_ABI_ANNOTATIONS _LIBCPP_END_NAMESPACE_STD #endif // _LIBCPP_STD_VER >= 17 diff --git a/lib/libcxx/include/__memory_resource/synchronized_pool_resource.h b/lib/libcxx/include/__memory_resource/synchronized_pool_resource.h index 1c929675bb3b39cad7b9f155ba0041a205a8ea38..97a0f28ad41294eb64ef1ab8ebdbfe8cf040748a 100644 --- a/lib/libcxx/include/__memory_resource/synchronized_pool_resource.h +++ b/lib/libcxx/include/__memory_resource/synchronized_pool_resource.h @@ -24,6 +24,7 @@ #if _LIBCPP_STD_VER >= 17 _LIBCPP_BEGIN_NAMESPACE_STD +_LIBCPP_BEGIN_EXPLICIT_ABI_ANNOTATIONS namespace pmr { @@ -88,6 +89,7 @@ private: } // namespace pmr +_LIBCPP_END_EXPLICIT_ABI_ANNOTATIONS _LIBCPP_END_NAMESPACE_STD #endif // _LIBCPP_STD_VER >= 17 diff --git a/lib/libcxx/include/__memory_resource/unsynchronized_pool_resource.h b/lib/libcxx/include/__memory_resource/unsynchronized_pool_resource.h index 89198a1b7c96edd152548b13dadfeb3e4e5c1c79..589afaf2faa22ff1bafa9d4e3007cb2edb4724d6 100644 --- a/lib/libcxx/include/__memory_resource/unsynchronized_pool_resource.h +++ b/lib/libcxx/include/__memory_resource/unsynchronized_pool_resource.h @@ -22,6 +22,7 @@ #if _LIBCPP_STD_VER >= 17 _LIBCPP_BEGIN_NAMESPACE_STD +_LIBCPP_BEGIN_EXPLICIT_ABI_ANNOTATIONS namespace pmr { @@ -99,6 +100,7 @@ private: } // namespace pmr +_LIBCPP_END_EXPLICIT_ABI_ANNOTATIONS _LIBCPP_END_NAMESPACE_STD #endif // _LIBCPP_STD_VER >= 17 diff --git a/lib/libcxx/include/__mutex/lock_guard.h b/lib/libcxx/include/__mutex/lock_guard.h index 67a25ed2f8a89a311098548bc4a0c9b5077af174..29022e8c23ececaabc414ccf612cfedcfd5374b1 100644 --- a/lib/libcxx/include/__mutex/lock_guard.h +++ b/lib/libcxx/include/__mutex/lock_guard.h @@ -34,7 +34,7 @@ public: [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI lock_guard(mutex_type& __m, adopt_lock_t) _LIBCPP_REQUIRES_CAPABILITY(__m) : __m_(__m) {} - _LIBCPP_RELEASE_CAPABILITY _LIBCPP_HIDE_FROM_ABI ~lock_guard() { __m_.unlock(); } + _LIBCPP_RELEASE_CAPABILITY() _LIBCPP_HIDE_FROM_ABI ~lock_guard() { __m_.unlock(); } lock_guard(lock_guard const&) = delete; lock_guard& operator=(lock_guard const&) = delete; diff --git a/lib/libcxx/include/__mutex/mutex.h b/lib/libcxx/include/__mutex/mutex.h index e9cedf8db1cca084aa170f7113be13cec5a330a2..f71cba03cd4dc2079d4452b72df382b15818de07 100644 --- a/lib/libcxx/include/__mutex/mutex.h +++ b/lib/libcxx/include/__mutex/mutex.h @@ -20,6 +20,7 @@ #if _LIBCPP_HAS_THREADS _LIBCPP_BEGIN_NAMESPACE_STD +_LIBCPP_BEGIN_EXPLICIT_ABI_ANNOTATIONS class _LIBCPP_EXPORTED_FROM_ABI _LIBCPP_CAPABILITY("mutex") mutex { __libcpp_mutex_t __m_ = _LIBCPP_MUTEX_INITIALIZER; @@ -38,7 +39,7 @@ public: _LIBCPP_ACQUIRE_CAPABILITY() void lock(); [[__nodiscard__]] _LIBCPP_TRY_ACQUIRE_CAPABILITY(true) bool try_lock() _NOEXCEPT; - _LIBCPP_RELEASE_CAPABILITY void unlock() _NOEXCEPT; + _LIBCPP_RELEASE_CAPABILITY() void unlock() _NOEXCEPT; typedef __libcpp_mutex_t* native_handle_type; [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI native_handle_type native_handle() { return &__m_; } @@ -46,6 +47,7 @@ public: static_assert(is_nothrow_default_constructible::value, "the default constructor for std::mutex must be nothrow"); +_LIBCPP_END_EXPLICIT_ABI_ANNOTATIONS _LIBCPP_END_NAMESPACE_STD #endif // _LIBCPP_HAS_THREADS diff --git a/lib/libcxx/include/__mutex/once_flag.h b/lib/libcxx/include/__mutex/once_flag.h index ad15b2eb6df687f9bc059ccd0dc102ce7a93242e..9999852b8b78aa3589661c880c7c686fd135f288 100644 --- a/lib/libcxx/include/__mutex/once_flag.h +++ b/lib/libcxx/include/__mutex/once_flag.h @@ -113,7 +113,9 @@ void _LIBCPP_HIDE_FROM_ABI __call_once_proxy(void* __vp) { (*__p)(); } +_LIBCPP_BEGIN_EXPLICIT_ABI_ANNOTATIONS _LIBCPP_EXPORTED_FROM_ABI void __call_once(volatile once_flag::_State_type&, void*, void (*)(void*)); +_LIBCPP_END_EXPLICIT_ABI_ANNOTATIONS template inline _LIBCPP_HIDE_FROM_ABI _ValueType __libcpp_acquire_load(_ValueType const* __value) { diff --git a/lib/libcxx/include/__mutex/unique_lock.h b/lib/libcxx/include/__mutex/unique_lock.h index 69689226396738668705b23deef6dd816aadb7ec..055ece847b3ce411bf9ccacbf3c66b0fe114b7e3 100644 --- a/lib/libcxx/include/__mutex/unique_lock.h +++ b/lib/libcxx/include/__mutex/unique_lock.h @@ -84,13 +84,13 @@ public: } _LIBCPP_HIDE_FROM_ABI void lock(); - _LIBCPP_HIDE_FROM_ABI bool try_lock(); + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI bool try_lock(); template - _LIBCPP_HIDE_FROM_ABI bool try_lock_for(const chrono::duration<_Rep, _Period>& __d); + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI bool try_lock_for(const chrono::duration<_Rep, _Period>& __d); template - _LIBCPP_HIDE_FROM_ABI bool try_lock_until(const chrono::time_point<_Clock, _Duration>& __t); + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI bool try_lock_until(const chrono::time_point<_Clock, _Duration>& __t); _LIBCPP_HIDE_FROM_ABI void unlock(); @@ -106,9 +106,9 @@ public: return __m; } - _LIBCPP_HIDE_FROM_ABI bool owns_lock() const _NOEXCEPT { return __owns_; } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI bool owns_lock() const _NOEXCEPT { return __owns_; } _LIBCPP_HIDE_FROM_ABI explicit operator bool() const _NOEXCEPT { return __owns_; } - _LIBCPP_HIDE_FROM_ABI mutex_type* mutex() const _NOEXCEPT { return __m_; } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI mutex_type* mutex() const _NOEXCEPT { return __m_; } }; _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(unique_lock); diff --git a/lib/libcxx/include/__new/exceptions.h b/lib/libcxx/include/__new/exceptions.h index 1aadc23120cbb21b789850e9ef6b37b696de5c88..28561187fb55548c2a820ea614e1be93fe3bae51 100644 --- a/lib/libcxx/include/__new/exceptions.h +++ b/lib/libcxx/include/__new/exceptions.h @@ -24,6 +24,8 @@ #endif _LIBCPP_BEGIN_UNVERSIONED_NAMESPACE_STD +_LIBCPP_BEGIN_EXPLICIT_ABI_ANNOTATIONS + #if !defined(_LIBCPP_ABI_VCRUNTIME) class _LIBCPP_EXPORTED_FROM_ABI bad_alloc : public exception { @@ -74,6 +76,7 @@ public: _LIBCPP_VERBOSE_ABORT("bad_array_new_length was thrown in -fno-exceptions mode"); #endif } +_LIBCPP_END_EXPLICIT_ABI_ANNOTATIONS _LIBCPP_END_UNVERSIONED_NAMESPACE_STD #endif // _LIBCPP___NEW_EXCEPTIONS_H diff --git a/lib/libcxx/include/__new/new_handler.h b/lib/libcxx/include/__new/new_handler.h index 05f4e846c3ef96af18a1a730b0e6236cb5995413..fc6aabec61b64a8ff315ad3d5adce7acd0d0173b 100644 --- a/lib/libcxx/include/__new/new_handler.h +++ b/lib/libcxx/include/__new/new_handler.h @@ -19,9 +19,13 @@ # include #else _LIBCPP_BEGIN_UNVERSIONED_NAMESPACE_STD +_LIBCPP_BEGIN_EXPLICIT_ABI_ANNOTATIONS + typedef void (*new_handler)(); _LIBCPP_EXPORTED_FROM_ABI new_handler set_new_handler(new_handler) _NOEXCEPT; _LIBCPP_EXPORTED_FROM_ABI new_handler get_new_handler() _NOEXCEPT; + +_LIBCPP_END_EXPLICIT_ABI_ANNOTATIONS _LIBCPP_END_UNVERSIONED_NAMESPACE_STD #endif // _LIBCPP_ABI_VCRUNTIME diff --git a/lib/libcxx/include/__new/placement_new_delete.h b/lib/libcxx/include/__new/placement_new_delete.h index 42c9f34036775503ae5affd2483b0858e8469305..74692f36fd04c6edd2e4e97b3053fef8fc4fe4ff 100644 --- a/lib/libcxx/include/__new/placement_new_delete.h +++ b/lib/libcxx/include/__new/placement_new_delete.h @@ -27,8 +27,8 @@ operator new(std::size_t, void* __p) _NOEXCEPT { operator new[](std::size_t, void* __p) _NOEXCEPT { return __p; } -inline _LIBCPP_HIDE_FROM_ABI void operator delete(void*, void*) _NOEXCEPT {} -inline _LIBCPP_HIDE_FROM_ABI void operator delete[](void*, void*) _NOEXCEPT {} +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void operator delete(void*, void*) _NOEXCEPT {} +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void operator delete[](void*, void*) _NOEXCEPT {} #endif #endif // _LIBCPP___NEW_PLACEMENT_NEW_DELETE_H diff --git a/lib/libcxx/include/__node_handle b/lib/libcxx/include/__node_handle index b20b0c73a0518357af53f2c0d9a700e648c6c51e..993283cc926daf4e883eb47090c4d3511fa9f3e6 100644 --- a/lib/libcxx/include/__node_handle +++ b/lib/libcxx/include/__node_handle @@ -31,29 +31,29 @@ private: public: // [container.node.cons], constructors, copy, and assignment constexpr node-handle() noexcept : ptr_(), alloc_() {} - node-handle(node-handle&&) noexcept; - node-handle& operator=(node-handle&&); + constexpr node-handle(node-handle&&) noexcept; // constexpr since C++26 + constexpr node-handle& operator=(node-handle&&); // constexpr since C++26 // [container.node.dtor], destructor - ~node-handle(); + constexpr ~node-handle(); // constexpr since C++26 // [container.node.observers], observers - value_type& value() const; // not present for map containers - key_type& key() const; // not present for set containers - mapped_type& mapped() const; // not present for set containers + value_type& value() const; // not present for map containers + key_type& key() const; // not present for set containers + constexpr mapped_type& mapped() const; // not present for set containers, constexpr since C++26 - allocator_type get_allocator() const; - explicit operator bool() const noexcept; - [[nodiscard]] bool empty() const noexcept; // nodiscard since C++20 + constexpr allocator_type get_allocator() const; // constexpr since C++26 + constexpr explicit operator bool() const noexcept; // constexpr since C++26 + [[nodiscard]] constexpr bool empty() const noexcept; // nodiscard since C++20, constexpr since C++26 // [container.node.modifiers], modifiers - void swap(node-handle&) + constexpr void swap(node-handle&) noexcept(ator_traits::propagate_on_container_swap::value || - ator_traits::is_always_equal::value); + ator_traits::is_always_equal::value); // constexpr since C++26 - friend void swap(node-handle& x, node-handle& y) noexcept(noexcept(x.swap(y))) { + constexpr friend void swap(node-handle& x, node-handle& y) noexcept(noexcept(x.swap(y))) { x.swap(y); - } + } // constexpr since C++26 }; */ @@ -63,6 +63,7 @@ public: #include <__memory/allocator_traits.h> #include <__memory/pointer_traits.h> #include <__type_traits/is_specialization.h> +#include <__utility/exchange.h> #include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) @@ -72,10 +73,10 @@ public: _LIBCPP_PUSH_MACROS #include <__undef_macros> -_LIBCPP_BEGIN_NAMESPACE_STD - #if _LIBCPP_STD_VER >= 17 +_LIBCPP_BEGIN_NAMESPACE_STD + // Specialized in __tree & __hash_table for their _NodeType. template struct __generic_container_node_destructor; @@ -99,12 +100,12 @@ private: __node_pointer_type __ptr_ = nullptr; optional __alloc_; - _LIBCPP_HIDE_FROM_ABI void __release_ptr() { + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void __release_ptr() { __ptr_ = nullptr; __alloc_ = std::nullopt; } - _LIBCPP_HIDE_FROM_ABI void __destroy_node_pointer() { + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void __destroy_node_pointer() { if (__ptr_ != nullptr) { typedef typename __allocator_traits_rebind< allocator_type, _NodeType>::type __node_alloc_type; __node_alloc_type __alloc(*__alloc_); @@ -113,19 +114,17 @@ private: } } - _LIBCPP_HIDE_FROM_ABI __basic_node_handle(__node_pointer_type __ptr, allocator_type const& __alloc) + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 + __basic_node_handle(__node_pointer_type __ptr, allocator_type const& __alloc) : __ptr_(__ptr), __alloc_(__alloc) {} public: - _LIBCPP_HIDE_FROM_ABI __basic_node_handle() = default; + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __basic_node_handle() = default; - _LIBCPP_HIDE_FROM_ABI __basic_node_handle(__basic_node_handle&& __other) noexcept - : __ptr_(__other.__ptr_), __alloc_(std::move(__other.__alloc_)) { - __other.__ptr_ = nullptr; - __other.__alloc_ = std::nullopt; - } + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __basic_node_handle(__basic_node_handle&& __other) noexcept + : __ptr_(std::exchange(__other.__ptr_, nullptr)), __alloc_(std::exchange(__other.__alloc_, std::nullopt)) {} - _LIBCPP_HIDE_FROM_ABI __basic_node_handle& operator=(__basic_node_handle&& __other) { + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __basic_node_handle& operator=(__basic_node_handle&& __other) { _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR( __alloc_ == std::nullopt || __alloc_traits::propagate_on_container_move_assignment::value || __alloc_ == __other.__alloc_, @@ -133,24 +132,23 @@ public: "node_type::operator=(node_type&&)"); __destroy_node_pointer(); - __ptr_ = __other.__ptr_; + __ptr_ = std::exchange(__other.__ptr_, nullptr); if (__alloc_traits::propagate_on_container_move_assignment::value || __alloc_ == std::nullopt) __alloc_ = std::move(__other.__alloc_); - __other.__ptr_ = nullptr; __other.__alloc_ = std::nullopt; return *this; } - _LIBCPP_HIDE_FROM_ABI allocator_type get_allocator() const { return *__alloc_; } + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 allocator_type get_allocator() const { return *__alloc_; } - _LIBCPP_HIDE_FROM_ABI explicit operator bool() const { return __ptr_ != nullptr; } + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 explicit operator bool() const { return __ptr_ != nullptr; } - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI bool empty() const { return __ptr_ == nullptr; } + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 bool empty() const { return __ptr_ == nullptr; } - _LIBCPP_HIDE_FROM_ABI void swap(__basic_node_handle& __other) noexcept( + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void swap(__basic_node_handle& __other) noexcept( __alloc_traits::propagate_on_container_swap::value || __alloc_traits::is_always_equal::value) { using std::swap; swap(__ptr_, __other.__ptr_); @@ -159,19 +157,21 @@ public: swap(__alloc_, __other.__alloc_); } - _LIBCPP_HIDE_FROM_ABI friend void + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 friend void swap(__basic_node_handle& __a, __basic_node_handle& __b) noexcept(noexcept(__a.swap(__b))) { __a.swap(__b); } - _LIBCPP_HIDE_FROM_ABI ~__basic_node_handle() { __destroy_node_pointer(); } + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 ~__basic_node_handle() { __destroy_node_pointer(); } }; template struct __set_node_handle_specifics { typedef typename _NodeType::__node_value_type value_type; - _LIBCPP_HIDE_FROM_ABI value_type& value() const { return static_cast<_Derived const*>(this)->__ptr_->__get_value(); } + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 value_type& value() const { + return static_cast<_Derived const*>(this)->__ptr_->__get_value(); + } }; template @@ -179,6 +179,7 @@ struct __map_node_handle_specifics { using key_type = __remove_const_t; using mapped_type = typename _NodeType::__node_value_type::second_type; + // This method is not constexpr as per the standard. _LIBCPP_HIDE_FROM_ABI key_type& key() const { return const_cast(static_cast<_Derived const*>(this)->__ptr_->__get_value().first); } @@ -201,10 +202,10 @@ struct __insert_return_type { _NodeType node; }; -#endif // _LIBCPP_STD_VER >= 17 - _LIBCPP_END_NAMESPACE_STD +#endif // _LIBCPP_STD_VER >= 17 + _LIBCPP_POP_MACROS #endif // _LIBCPP___NODE_HANDLE diff --git a/lib/libcxx/include/__numeric/accumulate.h b/lib/libcxx/include/__numeric/accumulate.h index fedc1c46dfd0224b02b668a9040f4a261c11a33a..1e6a5f378a886bc39e84b76429afc6e5e74ac7c7 100644 --- a/lib/libcxx/include/__numeric/accumulate.h +++ b/lib/libcxx/include/__numeric/accumulate.h @@ -23,7 +23,7 @@ _LIBCPP_PUSH_MACROS _LIBCPP_BEGIN_NAMESPACE_STD template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Tp +[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Tp accumulate(_InputIterator __first, _InputIterator __last, _Tp __init) { for (; __first != __last; ++__first) #if _LIBCPP_STD_VER >= 20 @@ -35,7 +35,7 @@ accumulate(_InputIterator __first, _InputIterator __last, _Tp __init) { } template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Tp +[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Tp accumulate(_InputIterator __first, _InputIterator __last, _Tp __init, _BinaryOperation __binary_op) { for (; __first != __last; ++__first) #if _LIBCPP_STD_VER >= 20 diff --git a/lib/libcxx/include/__numeric/gcd_lcm.h b/lib/libcxx/include/__numeric/gcd_lcm.h index 5ab870fa7349c71c10a9e9c4196c4cc68521fc68..753b42621fcc1fc0ee4a1e3b7d9b2e16824f6de0 100644 --- a/lib/libcxx/include/__numeric/gcd_lcm.h +++ b/lib/libcxx/include/__numeric/gcd_lcm.h @@ -47,7 +47,7 @@ constexpr _LIBCPP_HIDE_FROM_ABI _Result __abs_in_type(_Source __t) noexcept { } template -constexpr _LIBCPP_HIDE_FROM_ABI common_type_t<_Tp, _Up> gcd(_Tp __m, _Up __n) { +[[nodiscard]] constexpr _LIBCPP_HIDE_FROM_ABI common_type_t<_Tp, _Up> gcd(_Tp __m, _Up __n) { static_assert(is_integral<_Tp>::value && is_integral<_Up>::value, "Arguments to gcd must be integer types"); static_assert(!is_same<__remove_cv_t<_Tp>, bool>::value, "First argument to gcd cannot be bool"); static_assert(!is_same<__remove_cv_t<_Up>, bool>::value, "Second argument to gcd cannot be bool"); @@ -95,7 +95,7 @@ constexpr _LIBCPP_HIDE_FROM_ABI common_type_t<_Tp, _Up> gcd(_Tp __m, _Up __n) { } template -constexpr _LIBCPP_HIDE_FROM_ABI common_type_t<_Tp, _Up> lcm(_Tp __m, _Up __n) { +[[nodiscard]] constexpr _LIBCPP_HIDE_FROM_ABI common_type_t<_Tp, _Up> lcm(_Tp __m, _Up __n) { static_assert(is_integral<_Tp>::value && is_integral<_Up>::value, "Arguments to lcm must be integer types"); static_assert(!is_same<__remove_cv_t<_Tp>, bool>::value, "First argument to lcm cannot be bool"); static_assert(!is_same<__remove_cv_t<_Up>, bool>::value, "Second argument to lcm cannot be bool"); diff --git a/lib/libcxx/include/__numeric/inner_product.h b/lib/libcxx/include/__numeric/inner_product.h index 0deab3d421b771305b5573540ecd063d15c3da1d..734a51b69098dd39d185c3d2c77c477ba92c6993 100644 --- a/lib/libcxx/include/__numeric/inner_product.h +++ b/lib/libcxx/include/__numeric/inner_product.h @@ -23,7 +23,7 @@ _LIBCPP_PUSH_MACROS _LIBCPP_BEGIN_NAMESPACE_STD template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Tp +[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Tp inner_product(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _Tp __init) { for (; __first1 != __last1; ++__first1, (void)++__first2) #if _LIBCPP_STD_VER >= 20 @@ -35,7 +35,7 @@ inner_product(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 } template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Tp inner_product( +[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Tp inner_product( _InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, diff --git a/lib/libcxx/include/__numeric/pstl.h b/lib/libcxx/include/__numeric/pstl.h index fe7b2cc7a82cc468483a0a835e6191ab33da99be..ecbc9f534833335478d300458ef576bc115e5c71 100644 --- a/lib/libcxx/include/__numeric/pstl.h +++ b/lib/libcxx/include/__numeric/pstl.h @@ -41,7 +41,7 @@ template , enable_if_t, int> = 0> -_LIBCPP_HIDE_FROM_ABI _Tp reduce( +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI _Tp reduce( _ExecutionPolicy&& __policy, _ForwardIterator __first, _ForwardIterator __last, _Tp __init, _BinaryOperation __op) { _LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator, "reduce requires ForwardIterators"); using _Implementation = __pstl::__dispatch<__pstl::__reduce, __pstl::__current_configuration, _RawPolicy>; @@ -58,7 +58,7 @@ template , enable_if_t, int> = 0> -_LIBCPP_HIDE_FROM_ABI _Tp +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI _Tp reduce(_ExecutionPolicy&& __policy, _ForwardIterator __first, _ForwardIterator __last, _Tp __init) { _LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator, "reduce requires ForwardIterators"); using _Implementation = __pstl::__dispatch<__pstl::__reduce, __pstl::__current_configuration, _RawPolicy>; @@ -70,7 +70,7 @@ template , enable_if_t, int> = 0> -_LIBCPP_HIDE_FROM_ABI __iterator_value_type<_ForwardIterator> +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI __iterator_value_type<_ForwardIterator> reduce(_ExecutionPolicy&& __policy, _ForwardIterator __first, _ForwardIterator __last) { _LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator, "reduce requires ForwardIterators"); using _Implementation = __pstl::__dispatch<__pstl::__reduce, __pstl::__current_configuration, _RawPolicy>; @@ -90,7 +90,7 @@ template , enable_if_t, int> = 0> -_LIBCPP_HIDE_FROM_ABI _Tp transform_reduce( +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI _Tp transform_reduce( _ExecutionPolicy&& __policy, _ForwardIterator1 __first1, _ForwardIterator1 __last1, @@ -120,7 +120,7 @@ template , enable_if_t, int> = 0> -_LIBCPP_HIDE_FROM_ABI _Tp transform_reduce( +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI _Tp transform_reduce( _ExecutionPolicy&& __policy, _ForwardIterator1 __first1, _ForwardIterator1 __last1, @@ -147,7 +147,7 @@ template , enable_if_t, int> = 0> -_LIBCPP_HIDE_FROM_ABI _Tp transform_reduce( +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI _Tp transform_reduce( _ExecutionPolicy&& __policy, _ForwardIterator __first, _ForwardIterator __last, diff --git a/lib/libcxx/include/__numeric/ranges_iota.h b/lib/libcxx/include/__numeric/ranges_iota.h index bf53dd85fecefa99406ff7cd1fe4617affdb28a2..c67e6e92826af89cbada221d25ef0417f16f1e55 100644 --- a/lib/libcxx/include/__numeric/ranges_iota.h +++ b/lib/libcxx/include/__numeric/ranges_iota.h @@ -26,9 +26,10 @@ _LIBCPP_PUSH_MACROS #include <__undef_macros> -_LIBCPP_BEGIN_NAMESPACE_STD - #if _LIBCPP_STD_VER >= 23 + +_LIBCPP_BEGIN_NAMESPACE_STD + namespace ranges { template using iota_result = ranges::out_value_result<_Out, _Tp>; @@ -56,10 +57,10 @@ public: inline constexpr auto iota = __iota_fn{}; } // namespace ranges -#endif // _LIBCPP_STD_VER >= 23 - _LIBCPP_END_NAMESPACE_STD +#endif // _LIBCPP_STD_VER >= 23 + _LIBCPP_POP_MACROS #endif // _LIBCPP___NUMERIC_RANGES_IOTA_H diff --git a/lib/libcxx/include/__numeric/reduce.h b/lib/libcxx/include/__numeric/reduce.h index 6c205bf581fb95b04c5fd252e7b20aa5fbc3a00c..853ca6fb61860eb1958979423df0ee0fdab0481c 100644 --- a/lib/libcxx/include/__numeric/reduce.h +++ b/lib/libcxx/include/__numeric/reduce.h @@ -22,32 +22,34 @@ _LIBCPP_PUSH_MACROS #include <__undef_macros> -_LIBCPP_BEGIN_NAMESPACE_STD - #if _LIBCPP_STD_VER >= 17 + +_LIBCPP_BEGIN_NAMESPACE_STD + template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Tp -reduce(_InputIterator __first, _InputIterator __last, _Tp __init, _BinaryOp __b) { +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI +_LIBCPP_CONSTEXPR_SINCE_CXX20 _Tp reduce(_InputIterator __first, _InputIterator __last, _Tp __init, _BinaryOp __b) { for (; __first != __last; ++__first) __init = __b(std::move(__init), *__first); return __init; } template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Tp +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Tp reduce(_InputIterator __first, _InputIterator __last, _Tp __init) { return std::reduce(__first, __last, __init, std::plus<>()); } template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 typename iterator_traits<_InputIterator>::value_type +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 typename iterator_traits<_InputIterator>::value_type reduce(_InputIterator __first, _InputIterator __last) { return std::reduce(__first, __last, typename iterator_traits<_InputIterator>::value_type{}); } -#endif _LIBCPP_END_NAMESPACE_STD +#endif // _LIBCPP_STD_VER >= 17 + _LIBCPP_POP_MACROS #endif // _LIBCPP___NUMERIC_REDUCE_H diff --git a/lib/libcxx/include/__numeric/saturation_arithmetic.h b/lib/libcxx/include/__numeric/saturation_arithmetic.h index 4491bab2b147903dca0d509f3c6ae04e2323ab14..34f784e4a9cf102361ba22106886511e94b5b450 100644 --- a/lib/libcxx/include/__numeric/saturation_arithmetic.h +++ b/lib/libcxx/include/__numeric/saturation_arithmetic.h @@ -29,7 +29,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD #if _LIBCPP_STD_VER >= 20 template <__signed_or_unsigned_integer _Tp> -_LIBCPP_HIDE_FROM_ABI constexpr _Tp __add_sat(_Tp __x, _Tp __y) noexcept { +_LIBCPP_HIDE_FROM_ABI constexpr _Tp __saturating_add(_Tp __x, _Tp __y) noexcept { # if defined(_LIBCPP_CLANG_VER) && _LIBCPP_CLANG_VER >= 2101 return __builtin_elementwise_add_sat(__x, __y); # else @@ -51,7 +51,7 @@ _LIBCPP_HIDE_FROM_ABI constexpr _Tp __add_sat(_Tp __x, _Tp __y) noexcept { } template <__signed_or_unsigned_integer _Tp> -_LIBCPP_HIDE_FROM_ABI constexpr _Tp __sub_sat(_Tp __x, _Tp __y) noexcept { +_LIBCPP_HIDE_FROM_ABI constexpr _Tp __saturating_sub(_Tp __x, _Tp __y) noexcept { # if defined(_LIBCPP_CLANG_VER) && _LIBCPP_CLANG_VER >= 2101 return __builtin_elementwise_sub_sat(__x, __y); # else @@ -74,7 +74,7 @@ _LIBCPP_HIDE_FROM_ABI constexpr _Tp __sub_sat(_Tp __x, _Tp __y) noexcept { } template <__signed_or_unsigned_integer _Tp> -_LIBCPP_HIDE_FROM_ABI constexpr _Tp __mul_sat(_Tp __x, _Tp __y) noexcept { +_LIBCPP_HIDE_FROM_ABI constexpr _Tp __saturating_mul(_Tp __x, _Tp __y) noexcept { if (_Tp __mul; !__builtin_mul_overflow(__x, __y, std::addressof(__mul))) return __mul; // Handle overflow @@ -90,7 +90,7 @@ _LIBCPP_HIDE_FROM_ABI constexpr _Tp __mul_sat(_Tp __x, _Tp __y) noexcept { } template <__signed_or_unsigned_integer _Tp> -_LIBCPP_HIDE_FROM_ABI constexpr _Tp __div_sat(_Tp __x, _Tp __y) noexcept { +_LIBCPP_HIDE_FROM_ABI constexpr _Tp __saturating_div(_Tp __x, _Tp __y) noexcept { _LIBCPP_ASSERT_UNCATEGORIZED(__y != 0, "Division by 0 is undefined"); if constexpr (__unsigned_integer<_Tp>) { return __x / __y; @@ -103,7 +103,7 @@ _LIBCPP_HIDE_FROM_ABI constexpr _Tp __div_sat(_Tp __x, _Tp __y) noexcept { } template <__signed_or_unsigned_integer _Rp, __signed_or_unsigned_integer _Tp> -_LIBCPP_HIDE_FROM_ABI constexpr _Rp __saturate_cast(_Tp __x) noexcept { +_LIBCPP_HIDE_FROM_ABI constexpr _Rp __saturating_cast(_Tp __x) noexcept { // Saturation is impossible edge case when ((min _Rp) < (min _Tp) && (max _Rp) > (max _Tp)) and it is expected to be // optimized out by the compiler. @@ -121,28 +121,28 @@ _LIBCPP_HIDE_FROM_ABI constexpr _Rp __saturate_cast(_Tp __x) noexcept { #if _LIBCPP_STD_VER >= 26 template <__signed_or_unsigned_integer _Tp> -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Tp add_sat(_Tp __x, _Tp __y) noexcept { - return std::__add_sat(__x, __y); +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Tp saturating_add(_Tp __x, _Tp __y) noexcept { + return std::__saturating_add(__x, __y); } template <__signed_or_unsigned_integer _Tp> -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Tp sub_sat(_Tp __x, _Tp __y) noexcept { - return std::__sub_sat(__x, __y); +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Tp saturating_sub(_Tp __x, _Tp __y) noexcept { + return std::__saturating_sub(__x, __y); } template <__signed_or_unsigned_integer _Tp> -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Tp mul_sat(_Tp __x, _Tp __y) noexcept { - return std::__mul_sat(__x, __y); +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Tp saturating_mul(_Tp __x, _Tp __y) noexcept { + return std::__saturating_mul(__x, __y); } template <__signed_or_unsigned_integer _Tp> -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Tp div_sat(_Tp __x, _Tp __y) noexcept { - return std::__div_sat(__x, __y); +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Tp saturating_div(_Tp __x, _Tp __y) noexcept { + return std::__saturating_div(__x, __y); } template <__signed_or_unsigned_integer _Rp, __signed_or_unsigned_integer _Tp> -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Rp saturate_cast(_Tp __x) noexcept { - return std::__saturate_cast<_Rp>(__x); +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Rp saturating_cast(_Tp __x) noexcept { + return std::__saturating_cast<_Rp>(__x); } #endif // _LIBCPP_STD_VER >= 26 diff --git a/lib/libcxx/include/__numeric/transform_reduce.h b/lib/libcxx/include/__numeric/transform_reduce.h index f1150510f0c36fcd691bc084336b8ff156f10a2e..53ed6aaf32d1ec85b602e11088c02b5826729b7a 100644 --- a/lib/libcxx/include/__numeric/transform_reduce.h +++ b/lib/libcxx/include/__numeric/transform_reduce.h @@ -21,19 +21,20 @@ _LIBCPP_PUSH_MACROS #include <__undef_macros> -_LIBCPP_BEGIN_NAMESPACE_STD - #if _LIBCPP_STD_VER >= 17 + +_LIBCPP_BEGIN_NAMESPACE_STD + template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Tp -transform_reduce(_InputIterator __first, _InputIterator __last, _Tp __init, _BinaryOp __b, _UnaryOp __u) { +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 +_Tp transform_reduce(_InputIterator __first, _InputIterator __last, _Tp __init, _BinaryOp __b, _UnaryOp __u) { for (; __first != __last; ++__first) __init = __b(std::move(__init), __u(*__first)); return __init; } template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Tp transform_reduce( +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Tp transform_reduce( _InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, @@ -46,14 +47,15 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Tp transform_reduce( } template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Tp +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Tp transform_reduce(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _Tp __init) { return std::transform_reduce(__first1, __last1, __first2, std::move(__init), std::plus<>(), std::multiplies<>()); } -#endif _LIBCPP_END_NAMESPACE_STD +#endif // _LIBCPP_STD_VER >= 17 + _LIBCPP_POP_MACROS #endif // _LIBCPP___NUMERIC_TRANSFORM_REDUCE_H diff --git a/lib/libcxx/include/__ostream/basic_ostream.h b/lib/libcxx/include/__ostream/basic_ostream.h index 62770be72f98323c204fe9a67646ac59d6276035..43c9399758bf12683cdc318c0a98d619cbb1d3f8 100644 --- a/lib/libcxx/include/__ostream/basic_ostream.h +++ b/lib/libcxx/include/__ostream/basic_ostream.h @@ -41,6 +41,7 @@ _LIBCPP_PUSH_MACROS # include <__undef_macros> _LIBCPP_BEGIN_NAMESPACE_STD +_LIBCPP_BEGIN_EXPLICIT_ABI_ANNOTATIONS template class basic_ostream : virtual public basic_ios<_CharT, _Traits> { @@ -672,6 +673,7 @@ extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_ostream; extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_ostream; # endif +_LIBCPP_END_EXPLICIT_ABI_ANNOTATIONS _LIBCPP_END_NAMESPACE_STD _LIBCPP_POP_MACROS diff --git a/lib/libcxx/include/__ostream/print.h b/lib/libcxx/include/__ostream/print.h index c5906c41b95b56a99fbbe5d1b4257673007e1ba8..5b4ab60a45eeaefe5afdd938389e351a4d2d8fe0 100644 --- a/lib/libcxx/include/__ostream/print.h +++ b/lib/libcxx/include/__ostream/print.h @@ -82,12 +82,14 @@ _LIBCPP_HIDE_FROM_ABI inline void vprint_nonunicode(ostream& __os, string_view _ // native Unicode API; // Whether the returned FILE* is "a terminal capable of displaying Unicode" // is determined in the same way as the print(FILE*, ...) overloads. +_LIBCPP_BEGIN_EXPLICIT_ABI_ANNOTATIONS _LIBCPP_EXPORTED_FROM_ABI FILE* __get_ostream_file(ostream& __os); +_LIBCPP_END_EXPLICIT_ABI_ANNOTATIONS # if _LIBCPP_HAS_UNICODE template // TODO PRINT template or availability markup fires too eagerly (http://llvm.org/PR61563). _LIBCPP_HIDE_FROM_ABI void __vprint_unicode(ostream& __os, string_view __fmt, format_args __args, bool __write_nl) { -# if _LIBCPP_AVAILABILITY_HAS_PRINT == 0 +# ifndef _LIBCPP_WIN32API return std::__vprint_nonunicode(__os, __fmt, __args, __write_nl); # else FILE* __file = std::__get_ostream_file(__os); @@ -110,13 +112,10 @@ _LIBCPP_HIDE_FROM_ABI void __vprint_unicode(ostream& __os, string_view __fmt, fo # endif // _LIBCPP_HAS_EXCEPTIONS ostream::sentry __s(__os); if (__s) { -# ifndef _LIBCPP_WIN32API - __print::__vprint_unicode_posix(__file, __fmt, __args, __write_nl, true); -# elif _LIBCPP_HAS_WIDE_CHARACTERS - __print::__vprint_unicode_windows(__file, __fmt, __args, __write_nl, true); -# else -# error "Windows builds with wchar_t disabled are not supported." -# endif + auto __result = std::vformat(__fmt, __args); + if (__write_nl) + __result.push_back('\n'); + __print::__output_unicode_windows(__file, __result); } # if _LIBCPP_HAS_EXCEPTIONS @@ -124,7 +123,7 @@ _LIBCPP_HIDE_FROM_ABI void __vprint_unicode(ostream& __os, string_view __fmt, fo __os.__set_badbit_and_consider_rethrow(); } # endif // _LIBCPP_HAS_EXCEPTIONS -# endif // _LIBCPP_AVAILABILITY_HAS_PRINT +# endif // _LIBCPP_WIN32API } template // TODO PRINT template or availability markup fires too eagerly (http://llvm.org/PR61563). diff --git a/lib/libcxx/include/__pstl/backend_fwd.h b/lib/libcxx/include/__pstl/backend_fwd.h index a7d53b6a1c989426354ab311a0011f88cc6659e2..a84a768cad57075294dd9541f6164a7c1d1c98aa 100644 --- a/lib/libcxx/include/__pstl/backend_fwd.h +++ b/lib/libcxx/include/__pstl/backend_fwd.h @@ -109,6 +109,13 @@ struct __is_partitioned; // optional // operator()(_Policy&&, _ForwardIterator __first, _ForwardIterator __last, _Predicate __pred) const noexcept; +template +struct __find_first_of; +// template +// optional<_ForwardIterator1> +// operator()(_Policy&&, _ForwardIterator1 __first1, _ForwardIterator1 __last1, +// _ForwardIterator2 __first2, _ForwardIterator2 __last2, _Predicate __pred) const noexcept; + template struct __for_each; // template @@ -159,6 +166,13 @@ struct __generate_n; // optional<__empty> // operator()(_Policy&&, _ForwardIterator __first, _Size __n, _Generator __gen) const noexcept; +template +struct __reverse_copy; +// template +// optional<_ForwardIterator> +// operator()(_Policy&&, _BidirectionalIterator __first, _BidirectionalIterator __last, +// _ForwardIterator __result) const noexcept; + template struct __merge; // template @@ -297,6 +311,12 @@ struct __reduce; // operator()(_Policy&&, _ForwardIterator __first, _ForwardIterator __last, // _Tp __init, _BinaryOperation __op) const noexcept; +template +struct __is_sorted; +// template +// optional +// operator()(_Policy&& __policy, _ForwardIterator __first, _ForwardIterator __last, _Comp&& __comp) const noexcept; + } // namespace __pstl _LIBCPP_END_NAMESPACE_STD diff --git a/lib/libcxx/include/__pstl/backends/default.h b/lib/libcxx/include/__pstl/backends/default.h index 43b1f1ce3870aa1a457bb398001bff16054661eb..5c78d4efa412b90464128c4cd306405da1129708 100644 --- a/lib/libcxx/include/__pstl/backends/default.h +++ b/lib/libcxx/include/__pstl/backends/default.h @@ -12,15 +12,21 @@ #include <__algorithm/copy_n.h> #include <__algorithm/equal.h> #include <__algorithm/fill_n.h> +#include <__algorithm/find.h> +#include <__algorithm/find_if.h> #include <__algorithm/for_each_n.h> +#include <__algorithm/is_sorted.h> #include <__config> #include <__functional/identity.h> #include <__functional/not_fn.h> #include <__functional/operations.h> #include <__iterator/concepts.h> #include <__iterator/iterator_traits.h> +#include <__iterator/next.h> +#include <__iterator/reverse_iterator.h> #include <__pstl/backend_fwd.h> #include <__pstl/dispatch.h> +#include <__type_traits/desugars_to.h> #include <__utility/empty.h> #include <__utility/forward.h> #include <__utility/move.h> @@ -55,6 +61,7 @@ namespace __pstl { // - all_of // - none_of // - is_partitioned +// - find_first_of // // for_each family // --------------- @@ -80,6 +87,7 @@ namespace __pstl { // - count // - equal(3 legs) // - equal +// - is_sorted // - reduce // // transform and transform_binary family @@ -89,6 +97,7 @@ namespace __pstl { // - move // - copy // - copy_n +// - reverse_copy // - rotate_copy // @@ -178,6 +187,30 @@ struct __is_partitioned<__default_backend_tag, _ExecutionPolicy> { } }; +template +struct __find_first_of<__default_backend_tag, _ExecutionPolicy> { + template + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI optional<_ForwardIterator1> + operator()(_Policy&& __policy, + _ForwardIterator1 __first1, + _ForwardIterator1 __last1, + _ForwardIterator2 __first2, + _ForwardIterator2 __last2, + _Predicate&& __pred) const noexcept { + using _FindIf = __dispatch<__find_if, __current_configuration, _ExecutionPolicy>; + using _Ref1 = __iterator_reference<_ForwardIterator1>; + using _Ref2 = __iterator_reference<_ForwardIterator2>; + return _FindIf()(__policy, std::move(__first1), std::move(__last1), [&](_Ref1 __element) { + if constexpr (__desugars_to_v<__equal_tag, _Predicate, _Ref1, _Ref2>) { + // bypass an equality predicate and call directly to std::find() to allow more vectorization + return std::find(__first2, __last2, __element) != __last2; + } else { + return std::find_if(__first2, __last2, [&](_Ref2 __value) { return __pred(__element, __value); }) != __last2; + } + }); + } +}; + ////////////////////////////////////////////////////////////// // for_each family ////////////////////////////////////////////////////////////// @@ -388,6 +421,35 @@ struct __reduce<__default_backend_tag, _ExecutionPolicy> { } }; +template +struct __is_sorted<__default_backend_tag, _ExecutionPolicy> { + template + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI optional + operator()(_Policy&& __policy, _ForwardIterator __first, _ForwardIterator __last, _Comp&& __comp) const noexcept { + if constexpr (__has_bidirectional_iterator_category<_ForwardIterator>::value) { + if (__first == __last) + return true; // Empty, sorted by definition + _ForwardIterator __first2 = std::next(__first); + if (__first2 == __last) + return true; // Only one element, sorted by definition + --__last; // Make two iterator ranges: [__first, __first + n - 1) and [__first + 1, __first + n) + using _TransformReduce = __dispatch<__transform_reduce_binary, __current_configuration, _ExecutionPolicy>; + using _Ref = __iterator_reference<_ForwardIterator>; + return _TransformReduce()( + __policy, + std::move(__first), + std::move(__last), + std::move(__first2), + true, + std::logical_and{}, + [&](_Ref __left, _Ref __right) -> bool { return !__comp(__right, __left); }); + } else { + // Currently anything outside bidirectional iterators has to be processed serially + return std::is_sorted(std::move(__first), std::move(__last), std::forward<_Comp>(__comp)); + } + } +}; + ////////////////////////////////////////////////////////////// // transform family ////////////////////////////////////////////////////////////// @@ -497,6 +559,22 @@ struct __rotate_copy<__default_backend_tag, _ExecutionPolicy> { } }; +template +struct __reverse_copy<__default_backend_tag, _ExecutionPolicy> { + template + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI optional<_ForwardIterator> + operator()(_Policy&& __policy, + _BidirectionalIterator __first, + _BidirectionalIterator __last, + _ForwardIterator __result) const noexcept { + using _Copy = __dispatch<__copy, __current_configuration, _ExecutionPolicy>; + return _Copy()(__policy, + std::reverse_iterator<_BidirectionalIterator>(std::move(__last)), + std::reverse_iterator<_BidirectionalIterator>(std::move(__first)), + std::move(__result)); + } +}; + } // namespace __pstl _LIBCPP_END_NAMESPACE_STD diff --git a/lib/libcxx/include/__pstl/backends/libdispatch.h b/lib/libcxx/include/__pstl/backends/libdispatch.h index 88d4231d29a0ac7c2a6bcd9421eef87c6fbd8ec8..33fd5de66fbb150bd864fbc18ce4941d8cec520e 100644 --- a/lib/libcxx/include/__pstl/backends/libdispatch.h +++ b/lib/libcxx/include/__pstl/backends/libdispatch.h @@ -48,6 +48,7 @@ _LIBCPP_PUSH_MACROS #if _LIBCPP_STD_VER >= 17 _LIBCPP_BEGIN_NAMESPACE_STD +_LIBCPP_BEGIN_EXPLICIT_ABI_ANNOTATIONS namespace __pstl { namespace __libdispatch { @@ -393,6 +394,7 @@ struct __fill<__libdispatch_backend_tag, _ExecutionPolicy> : __cpu_parallel_fill<__libdispatch_backend_tag, _ExecutionPolicy> {}; } // namespace __pstl +_LIBCPP_END_EXPLICIT_ABI_ANNOTATIONS _LIBCPP_END_NAMESPACE_STD #endif // _LIBCPP_STD_VER >= 17 diff --git a/lib/libcxx/include/__random/bernoulli_distribution.h b/lib/libcxx/include/__random/bernoulli_distribution.h index 8d1bfad9e7d29d2df1ea827e474a37ceb3ef5e94..54ca0ee0f75044c3f5c06148aeb939452e5ac31c 100644 --- a/lib/libcxx/include/__random/bernoulli_distribution.h +++ b/lib/libcxx/include/__random/bernoulli_distribution.h @@ -36,7 +36,7 @@ public: _LIBCPP_HIDE_FROM_ABI explicit param_type(double __p = 0.5) : __p_(__p) {} - _LIBCPP_HIDE_FROM_ABI double p() const { return __p_; } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI double p() const { return __p_; } friend _LIBCPP_HIDE_FROM_ABI bool operator==(const param_type& __x, const param_type& __y) { return __x.__p_ == __y.__p_; @@ -60,20 +60,20 @@ public: // generating functions template - _LIBCPP_HIDE_FROM_ABI result_type operator()(_URNG& __g) { + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type operator()(_URNG& __g) { return (*this)(__g, __p_); } template - _LIBCPP_HIDE_FROM_ABI result_type operator()(_URNG& __g, const param_type& __p); + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type operator()(_URNG& __g, const param_type& __p); // property functions - _LIBCPP_HIDE_FROM_ABI double p() const { return __p_.p(); } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI double p() const { return __p_.p(); } - _LIBCPP_HIDE_FROM_ABI param_type param() const { return __p_; } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI param_type param() const { return __p_; } _LIBCPP_HIDE_FROM_ABI void param(const param_type& __p) { __p_ = __p; } - _LIBCPP_HIDE_FROM_ABI result_type min() const { return false; } - _LIBCPP_HIDE_FROM_ABI result_type max() const { return true; } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type min() const { return false; } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type max() const { return true; } friend _LIBCPP_HIDE_FROM_ABI bool operator==(const bernoulli_distribution& __x, const bernoulli_distribution& __y) { return __x.__p_ == __y.__p_; diff --git a/lib/libcxx/include/__random/binomial_distribution.h b/lib/libcxx/include/__random/binomial_distribution.h index 0712e4ef4a4f66c09a3a317280095e3d1b51e5c3..e4fe92143741afb04056a6d233ef5547ec574429 100644 --- a/lib/libcxx/include/__random/binomial_distribution.h +++ b/lib/libcxx/include/__random/binomial_distribution.h @@ -10,6 +10,7 @@ #define _LIBCPP___RANDOM_BINOMIAL_DISTRIBUTION_H #include <__config> +#include <__math/gamma.h> #include <__random/is_valid.h> #include <__random/uniform_real_distribution.h> #include @@ -44,8 +45,8 @@ public: _LIBCPP_HIDE_FROM_ABI explicit param_type(result_type __t = 1, double __p = 0.5); - _LIBCPP_HIDE_FROM_ABI result_type t() const { return __t_; } - _LIBCPP_HIDE_FROM_ABI double p() const { return __p_; } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type t() const { return __t_; } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI double p() const { return __p_; } friend _LIBCPP_HIDE_FROM_ABI bool operator==(const param_type& __x, const param_type& __y) { return __x.__t_ == __y.__t_ && __x.__p_ == __y.__p_; @@ -73,21 +74,21 @@ public: // generating functions template - _LIBCPP_HIDE_FROM_ABI result_type operator()(_URNG& __g) { + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type operator()(_URNG& __g) { return (*this)(__g, __p_); } template - _LIBCPP_HIDE_FROM_ABI result_type operator()(_URNG& __g, const param_type& __p); + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type operator()(_URNG& __g, const param_type& __p); // property functions - _LIBCPP_HIDE_FROM_ABI result_type t() const { return __p_.t(); } - _LIBCPP_HIDE_FROM_ABI double p() const { return __p_.p(); } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type t() const { return __p_.t(); } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI double p() const { return __p_.p(); } - _LIBCPP_HIDE_FROM_ABI param_type param() const { return __p_; } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI param_type param() const { return __p_; } _LIBCPP_HIDE_FROM_ABI void param(const param_type& __p) { __p_ = __p; } - _LIBCPP_HIDE_FROM_ABI result_type min() const { return 0; } - _LIBCPP_HIDE_FROM_ABI result_type max() const { return t(); } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type min() const { return 0; } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type max() const { return t(); } friend _LIBCPP_HIDE_FROM_ABI bool operator==(const binomial_distribution& __x, const binomial_distribution& __y) { return __x.__p_ == __y.__p_; @@ -97,33 +98,13 @@ public: } }; -// Some libc declares the math functions to be `noexcept`. -#if _LIBCPP_GLIBC_PREREQ(2, 8) || defined(__LLVM_LIBC__) -# define _LIBCPP_LGAMMA_R_NOEXCEPT _NOEXCEPT -#else -# define _LIBCPP_LGAMMA_R_NOEXCEPT -#endif - -#if !defined(_LIBCPP_MSVCRT_LIKE) -extern "C" double lgamma_r(double, int*) _LIBCPP_LGAMMA_R_NOEXCEPT; -#endif - -inline _LIBCPP_HIDE_FROM_ABI double __libcpp_lgamma(double __d) { -#if defined(_LIBCPP_MSVCRT_LIKE) - return lgamma(__d); -#else - int __sign; - return lgamma_r(__d, &__sign); -#endif -} - template binomial_distribution<_IntType>::param_type::param_type(result_type __t, double __p) : __t_(__t), __p_(__p) { if (0 < __p_ && __p_ < 1) { __r0_ = static_cast((__t_ + 1) * __p_); - __pr_ = std::exp( - std::__libcpp_lgamma(__t_ + 1.) - std::__libcpp_lgamma(__r0_ + 1.) - std::__libcpp_lgamma(__t_ - __r0_ + 1.) + - __r0_ * std::log(__p_) + (__t_ - __r0_) * std::log(1 - __p_)); + __pr_ = + std::exp(__math::__lgamma_r(__t_ + 1.) - __math::__lgamma_r(__r0_ + 1.) - + __math::__lgamma_r(__t_ - __r0_ + 1.) + __r0_ * std::log(__p_) + (__t_ - __r0_) * std::log(1 - __p_)); __odds_ratio_ = __p_ / (1 - __p_); } } diff --git a/lib/libcxx/include/__random/cauchy_distribution.h b/lib/libcxx/include/__random/cauchy_distribution.h index 0ad887dd8d645627ee59dd9fc564a96b345fd89e..65e83095c544595e31592c61d548e53d6c80fa63 100644 --- a/lib/libcxx/include/__random/cauchy_distribution.h +++ b/lib/libcxx/include/__random/cauchy_distribution.h @@ -43,8 +43,8 @@ public: _LIBCPP_HIDE_FROM_ABI explicit param_type(result_type __a = 0, result_type __b = 1) : __a_(__a), __b_(__b) {} - _LIBCPP_HIDE_FROM_ABI result_type a() const { return __a_; } - _LIBCPP_HIDE_FROM_ABI result_type b() const { return __b_; } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type a() const { return __a_; } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type b() const { return __b_; } friend _LIBCPP_HIDE_FROM_ABI bool operator==(const param_type& __x, const param_type& __y) { return __x.__a_ == __y.__a_ && __x.__b_ == __y.__b_; @@ -70,21 +70,21 @@ public: // generating functions template - _LIBCPP_HIDE_FROM_ABI result_type operator()(_URNG& __g) { + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type operator()(_URNG& __g) { return (*this)(__g, __p_); } template - _LIBCPP_HIDE_FROM_ABI result_type operator()(_URNG& __g, const param_type& __p); + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type operator()(_URNG& __g, const param_type& __p); // property functions - _LIBCPP_HIDE_FROM_ABI result_type a() const { return __p_.a(); } - _LIBCPP_HIDE_FROM_ABI result_type b() const { return __p_.b(); } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type a() const { return __p_.a(); } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type b() const { return __p_.b(); } - _LIBCPP_HIDE_FROM_ABI param_type param() const { return __p_; } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI param_type param() const { return __p_; } _LIBCPP_HIDE_FROM_ABI void param(const param_type& __p) { __p_ = __p; } - _LIBCPP_HIDE_FROM_ABI result_type min() const { return -numeric_limits::infinity(); } - _LIBCPP_HIDE_FROM_ABI result_type max() const { return numeric_limits::infinity(); } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type min() const { return -numeric_limits::infinity(); } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type max() const { return numeric_limits::infinity(); } friend _LIBCPP_HIDE_FROM_ABI bool operator==(const cauchy_distribution& __x, const cauchy_distribution& __y) { return __x.__p_ == __y.__p_; diff --git a/lib/libcxx/include/__random/chi_squared_distribution.h b/lib/libcxx/include/__random/chi_squared_distribution.h index 4ce2c17c354c503910f042cbf0ca1cddbb8ef3d1..8088dfe9d65bd65394c9dff2f031126925da62a5 100644 --- a/lib/libcxx/include/__random/chi_squared_distribution.h +++ b/lib/libcxx/include/__random/chi_squared_distribution.h @@ -41,7 +41,7 @@ public: _LIBCPP_HIDE_FROM_ABI explicit param_type(result_type __n = 1) : __n_(__n) {} - _LIBCPP_HIDE_FROM_ABI result_type n() const { return __n_; } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type n() const { return __n_; } friend _LIBCPP_HIDE_FROM_ABI bool operator==(const param_type& __x, const param_type& __y) { return __x.__n_ == __y.__n_; @@ -65,22 +65,22 @@ public: // generating functions template - _LIBCPP_HIDE_FROM_ABI result_type operator()(_URNG& __g) { + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type operator()(_URNG& __g) { return (*this)(__g, __p_); } template - _LIBCPP_HIDE_FROM_ABI result_type operator()(_URNG& __g, const param_type& __p) { + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type operator()(_URNG& __g, const param_type& __p) { return gamma_distribution(__p.n() / 2, 2)(__g); } // property functions - _LIBCPP_HIDE_FROM_ABI result_type n() const { return __p_.n(); } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type n() const { return __p_.n(); } - _LIBCPP_HIDE_FROM_ABI param_type param() const { return __p_; } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI param_type param() const { return __p_; } _LIBCPP_HIDE_FROM_ABI void param(const param_type& __p) { __p_ = __p; } - _LIBCPP_HIDE_FROM_ABI result_type min() const { return 0; } - _LIBCPP_HIDE_FROM_ABI result_type max() const { return numeric_limits::infinity(); } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type min() const { return 0; } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type max() const { return numeric_limits::infinity(); } friend _LIBCPP_HIDE_FROM_ABI bool operator==(const chi_squared_distribution& __x, const chi_squared_distribution& __y) { diff --git a/lib/libcxx/include/__random/discard_block_engine.h b/lib/libcxx/include/__random/discard_block_engine.h index 12d1ff318ccd2451d15d1e6e795253fc2402b4f9..ba9dae56806d935fb34b9afb3d1d0e0360786549 100644 --- a/lib/libcxx/include/__random/discard_block_engine.h +++ b/lib/libcxx/include/__random/discard_block_engine.h @@ -54,8 +54,8 @@ public: static constexpr result_type _Max = _Engine::max(); #endif - _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR result_type min() { return _Engine::min(); } - _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR result_type max() { return _Engine::max(); } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR result_type min() { return _Engine::min(); } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR result_type max() { return _Engine::max(); } // constructors and seeding functions _LIBCPP_HIDE_FROM_ABI discard_block_engine() : __n_(0) {} @@ -64,10 +64,9 @@ public: _LIBCPP_HIDE_FROM_ABI explicit discard_block_engine(_Engine&& __e) : __e_(std::move(__e)), __n_(0) {} #endif // _LIBCPP_CXX03_LANG _LIBCPP_HIDE_FROM_ABI explicit discard_block_engine(result_type __sd) : __e_(__sd), __n_(0) {} - template < - class _Sseq, - __enable_if_t<__is_seed_sequence<_Sseq, discard_block_engine>::value && !is_convertible<_Sseq, _Engine>::value, - int> = 0> + template && !is_convertible<_Sseq, _Engine>::value, + int> = 0> _LIBCPP_HIDE_FROM_ABI explicit discard_block_engine(_Sseq& __q) : __e_(__q), __n_(0) {} _LIBCPP_HIDE_FROM_ABI void seed() { __e_.seed(); @@ -77,21 +76,21 @@ public: __e_.seed(__sd); __n_ = 0; } - template ::value, int> = 0> + template , int> = 0> _LIBCPP_HIDE_FROM_ABI void seed(_Sseq& __q) { __e_.seed(__q); __n_ = 0; } // generating functions - _LIBCPP_HIDE_FROM_ABI result_type operator()(); + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type operator()(); _LIBCPP_HIDE_FROM_ABI void discard(unsigned long long __z) { for (; __z; --__z) - operator()(); + (void)operator()(); } // property functions - _LIBCPP_HIDE_FROM_ABI const _Engine& base() const _NOEXCEPT { return __e_; } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI const _Engine& base() const _NOEXCEPT { return __e_; } template friend bool diff --git a/lib/libcxx/include/__random/discrete_distribution.h b/lib/libcxx/include/__random/discrete_distribution.h index 528de4245ef5149e1affe24997430e953db069c7..1ade6fd8bf1af4aa84254d43dadf2300d677befb 100644 --- a/lib/libcxx/include/__random/discrete_distribution.h +++ b/lib/libcxx/include/__random/discrete_distribution.h @@ -52,7 +52,7 @@ public: template _LIBCPP_HIDE_FROM_ABI param_type(size_t __nw, double __xmin, double __xmax, _UnaryOperation __fw); - _LIBCPP_HIDE_FROM_ABI vector probabilities() const; + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI vector probabilities() const; friend _LIBCPP_HIDE_FROM_ABI bool operator==(const param_type& __x, const param_type& __y) { return __x.__p_ == __y.__p_; @@ -92,20 +92,20 @@ public: // generating functions template - _LIBCPP_HIDE_FROM_ABI result_type operator()(_URNG& __g) { + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type operator()(_URNG& __g) { return (*this)(__g, __p_); } template - _LIBCPP_HIDE_FROM_ABI result_type operator()(_URNG& __g, const param_type& __p); + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type operator()(_URNG& __g, const param_type& __p); // property functions - _LIBCPP_HIDE_FROM_ABI vector probabilities() const { return __p_.probabilities(); } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI vector probabilities() const { return __p_.probabilities(); } - _LIBCPP_HIDE_FROM_ABI param_type param() const { return __p_; } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI param_type param() const { return __p_; } _LIBCPP_HIDE_FROM_ABI void param(const param_type& __p) { __p_ = __p; } - _LIBCPP_HIDE_FROM_ABI result_type min() const { return 0; } - _LIBCPP_HIDE_FROM_ABI result_type max() const { return __p_.__p_.size(); } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type min() const { return 0; } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type max() const { return __p_.__p_.size(); } friend _LIBCPP_HIDE_FROM_ABI bool operator==(const discrete_distribution& __x, const discrete_distribution& __y) { return __x.__p_ == __y.__p_; diff --git a/lib/libcxx/include/__random/exponential_distribution.h b/lib/libcxx/include/__random/exponential_distribution.h index a5ce6ce332f9f86002386f8f4d4f0a3d816ad358..17f566ec6a2f85be056fb12b69a3bb1e2ffdfc02 100644 --- a/lib/libcxx/include/__random/exponential_distribution.h +++ b/lib/libcxx/include/__random/exponential_distribution.h @@ -43,7 +43,7 @@ public: _LIBCPP_HIDE_FROM_ABI explicit param_type(result_type __lambda = 1) : __lambda_(__lambda) {} - _LIBCPP_HIDE_FROM_ABI result_type lambda() const { return __lambda_; } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type lambda() const { return __lambda_; } friend _LIBCPP_HIDE_FROM_ABI bool operator==(const param_type& __x, const param_type& __y) { return __x.__lambda_ == __y.__lambda_; @@ -67,20 +67,20 @@ public: // generating functions template - _LIBCPP_HIDE_FROM_ABI result_type operator()(_URNG& __g) { + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type operator()(_URNG& __g) { return (*this)(__g, __p_); } template - _LIBCPP_HIDE_FROM_ABI result_type operator()(_URNG& __g, const param_type& __p); + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type operator()(_URNG& __g, const param_type& __p); // property functions - _LIBCPP_HIDE_FROM_ABI result_type lambda() const { return __p_.lambda(); } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type lambda() const { return __p_.lambda(); } - _LIBCPP_HIDE_FROM_ABI param_type param() const { return __p_; } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI param_type param() const { return __p_; } _LIBCPP_HIDE_FROM_ABI void param(const param_type& __p) { __p_ = __p; } - _LIBCPP_HIDE_FROM_ABI result_type min() const { return 0; } - _LIBCPP_HIDE_FROM_ABI result_type max() const { return numeric_limits::infinity(); } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type min() const { return 0; } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type max() const { return numeric_limits::infinity(); } friend _LIBCPP_HIDE_FROM_ABI bool operator==(const exponential_distribution& __x, const exponential_distribution& __y) { diff --git a/lib/libcxx/include/__random/extreme_value_distribution.h b/lib/libcxx/include/__random/extreme_value_distribution.h index 26d4bc67c2b609b554c39ebeb4d136ebc12d625d..e59079b7d6c22847c3fb1dbd76e05c875ef8144d 100644 --- a/lib/libcxx/include/__random/extreme_value_distribution.h +++ b/lib/libcxx/include/__random/extreme_value_distribution.h @@ -43,8 +43,8 @@ public: _LIBCPP_HIDE_FROM_ABI explicit param_type(result_type __a = 0, result_type __b = 1) : __a_(__a), __b_(__b) {} - _LIBCPP_HIDE_FROM_ABI result_type a() const { return __a_; } - _LIBCPP_HIDE_FROM_ABI result_type b() const { return __b_; } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type a() const { return __a_; } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type b() const { return __b_; } friend _LIBCPP_HIDE_FROM_ABI bool operator==(const param_type& __x, const param_type& __y) { return __x.__a_ == __y.__a_ && __x.__b_ == __y.__b_; @@ -70,21 +70,21 @@ public: // generating functions template - _LIBCPP_HIDE_FROM_ABI result_type operator()(_URNG& __g) { + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type operator()(_URNG& __g) { return (*this)(__g, __p_); } template - _LIBCPP_HIDE_FROM_ABI result_type operator()(_URNG& __g, const param_type& __p); + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type operator()(_URNG& __g, const param_type& __p); // property functions - _LIBCPP_HIDE_FROM_ABI result_type a() const { return __p_.a(); } - _LIBCPP_HIDE_FROM_ABI result_type b() const { return __p_.b(); } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type a() const { return __p_.a(); } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type b() const { return __p_.b(); } - _LIBCPP_HIDE_FROM_ABI param_type param() const { return __p_; } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI param_type param() const { return __p_; } _LIBCPP_HIDE_FROM_ABI void param(const param_type& __p) { __p_ = __p; } - _LIBCPP_HIDE_FROM_ABI result_type min() const { return -numeric_limits::infinity(); } - _LIBCPP_HIDE_FROM_ABI result_type max() const { return numeric_limits::infinity(); } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type min() const { return -numeric_limits::infinity(); } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type max() const { return numeric_limits::infinity(); } friend _LIBCPP_HIDE_FROM_ABI bool operator==(const extreme_value_distribution& __x, const extreme_value_distribution& __y) { diff --git a/lib/libcxx/include/__random/fisher_f_distribution.h b/lib/libcxx/include/__random/fisher_f_distribution.h index 84362fd0b4414331af15385b9c8a69740874507b..f36817dea50306495f0c18e2e27eaf9012fc855d 100644 --- a/lib/libcxx/include/__random/fisher_f_distribution.h +++ b/lib/libcxx/include/__random/fisher_f_distribution.h @@ -42,8 +42,8 @@ public: _LIBCPP_HIDE_FROM_ABI explicit param_type(result_type __m = 1, result_type __n = 1) : __m_(__m), __n_(__n) {} - _LIBCPP_HIDE_FROM_ABI result_type m() const { return __m_; } - _LIBCPP_HIDE_FROM_ABI result_type n() const { return __n_; } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type m() const { return __m_; } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type n() const { return __n_; } friend _LIBCPP_HIDE_FROM_ABI bool operator==(const param_type& __x, const param_type& __y) { return __x.__m_ == __y.__m_ && __x.__n_ == __y.__n_; @@ -69,21 +69,21 @@ public: // generating functions template - _LIBCPP_HIDE_FROM_ABI result_type operator()(_URNG& __g) { + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type operator()(_URNG& __g) { return (*this)(__g, __p_); } template - _LIBCPP_HIDE_FROM_ABI result_type operator()(_URNG& __g, const param_type& __p); + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type operator()(_URNG& __g, const param_type& __p); // property functions - _LIBCPP_HIDE_FROM_ABI result_type m() const { return __p_.m(); } - _LIBCPP_HIDE_FROM_ABI result_type n() const { return __p_.n(); } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type m() const { return __p_.m(); } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type n() const { return __p_.n(); } - _LIBCPP_HIDE_FROM_ABI param_type param() const { return __p_; } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI param_type param() const { return __p_; } _LIBCPP_HIDE_FROM_ABI void param(const param_type& __p) { __p_ = __p; } - _LIBCPP_HIDE_FROM_ABI result_type min() const { return 0; } - _LIBCPP_HIDE_FROM_ABI result_type max() const { return numeric_limits::infinity(); } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type min() const { return 0; } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type max() const { return numeric_limits::infinity(); } friend _LIBCPP_HIDE_FROM_ABI bool operator==(const fisher_f_distribution& __x, const fisher_f_distribution& __y) { return __x.__p_ == __y.__p_; diff --git a/lib/libcxx/include/__random/gamma_distribution.h b/lib/libcxx/include/__random/gamma_distribution.h index 10a6cb8a8eb2c6d35c47ae45b3a65b91f76d7448..aa418fd66702eaf9dde4ec437be682e0b0d04c09 100644 --- a/lib/libcxx/include/__random/gamma_distribution.h +++ b/lib/libcxx/include/__random/gamma_distribution.h @@ -45,8 +45,8 @@ public: _LIBCPP_HIDE_FROM_ABI explicit param_type(result_type __alpha = 1, result_type __beta = 1) : __alpha_(__alpha), __beta_(__beta) {} - _LIBCPP_HIDE_FROM_ABI result_type alpha() const { return __alpha_; } - _LIBCPP_HIDE_FROM_ABI result_type beta() const { return __beta_; } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type alpha() const { return __alpha_; } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type beta() const { return __beta_; } friend _LIBCPP_HIDE_FROM_ABI bool operator==(const param_type& __x, const param_type& __y) { return __x.__alpha_ == __y.__alpha_ && __x.__beta_ == __y.__beta_; @@ -72,21 +72,21 @@ public: // generating functions template - _LIBCPP_HIDE_FROM_ABI result_type operator()(_URNG& __g) { + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type operator()(_URNG& __g) { return (*this)(__g, __p_); } template - _LIBCPP_HIDE_FROM_ABI result_type operator()(_URNG& __g, const param_type& __p); + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type operator()(_URNG& __g, const param_type& __p); // property functions - _LIBCPP_HIDE_FROM_ABI result_type alpha() const { return __p_.alpha(); } - _LIBCPP_HIDE_FROM_ABI result_type beta() const { return __p_.beta(); } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type alpha() const { return __p_.alpha(); } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type beta() const { return __p_.beta(); } - _LIBCPP_HIDE_FROM_ABI param_type param() const { return __p_; } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI param_type param() const { return __p_; } _LIBCPP_HIDE_FROM_ABI void param(const param_type& __p) { __p_ = __p; } - _LIBCPP_HIDE_FROM_ABI result_type min() const { return 0; } - _LIBCPP_HIDE_FROM_ABI result_type max() const { return numeric_limits::infinity(); } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type min() const { return 0; } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type max() const { return numeric_limits::infinity(); } friend _LIBCPP_HIDE_FROM_ABI bool operator==(const gamma_distribution& __x, const gamma_distribution& __y) { return __x.__p_ == __y.__p_; diff --git a/lib/libcxx/include/__random/generate_canonical.h b/lib/libcxx/include/__random/generate_canonical.h index 738de1517e286741ae8059350339937da231a9d1..091ff92dfa144fee3397afe573d28483e0dafd8d 100644 --- a/lib/libcxx/include/__random/generate_canonical.h +++ b/lib/libcxx/include/__random/generate_canonical.h @@ -27,7 +27,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD // generate_canonical template -_LIBCPP_HIDE_FROM_ABI _RealType generate_canonical(_URNG& __g) { +[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _RealType generate_canonical(_URNG& __g) { const size_t __dt = numeric_limits<_RealType>::digits; const size_t __b = __dt < __bits ? __dt : __bits; #ifdef _LIBCPP_CXX03_LANG diff --git a/lib/libcxx/include/__random/geometric_distribution.h b/lib/libcxx/include/__random/geometric_distribution.h index c04ec2acb560773e7fb3127bc5f246a6e216eb00..bb50e345927173690fa33eb74a6335c769ece2b8 100644 --- a/lib/libcxx/include/__random/geometric_distribution.h +++ b/lib/libcxx/include/__random/geometric_distribution.h @@ -40,7 +40,7 @@ public: _LIBCPP_HIDE_FROM_ABI explicit param_type(double __p = 0.5) : __p_(__p) {} - _LIBCPP_HIDE_FROM_ABI double p() const { return __p_; } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI double p() const { return __p_; } friend _LIBCPP_HIDE_FROM_ABI bool operator==(const param_type& __x, const param_type& __y) { return __x.__p_ == __y.__p_; @@ -64,22 +64,22 @@ public: // generating functions template - _LIBCPP_HIDE_FROM_ABI result_type operator()(_URNG& __g) { + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type operator()(_URNG& __g) { return (*this)(__g, __p_); } template - _LIBCPP_HIDE_FROM_ABI result_type operator()(_URNG& __g, const param_type& __p) { + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type operator()(_URNG& __g, const param_type& __p) { return negative_binomial_distribution(1, __p.p())(__g); } // property functions - _LIBCPP_HIDE_FROM_ABI double p() const { return __p_.p(); } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI double p() const { return __p_.p(); } - _LIBCPP_HIDE_FROM_ABI param_type param() const { return __p_; } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI param_type param() const { return __p_; } _LIBCPP_HIDE_FROM_ABI void param(const param_type& __p) { __p_ = __p; } - _LIBCPP_HIDE_FROM_ABI result_type min() const { return 0; } - _LIBCPP_HIDE_FROM_ABI result_type max() const { return numeric_limits::max(); } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type min() const { return 0; } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type max() const { return numeric_limits::max(); } friend _LIBCPP_HIDE_FROM_ABI bool operator==(const geometric_distribution& __x, const geometric_distribution& __y) { return __x.__p_ == __y.__p_; diff --git a/lib/libcxx/include/__random/independent_bits_engine.h b/lib/libcxx/include/__random/independent_bits_engine.h index 74848570494140c72a98fe9fc3c1ff6b5304e961..51f61edd9988e8f3d99559b10fbe19ff1f6d9fc5 100644 --- a/lib/libcxx/include/__random/independent_bits_engine.h +++ b/lib/libcxx/include/__random/independent_bits_engine.h @@ -82,8 +82,8 @@ public: static_assert(_Min < _Max, "independent_bits_engine invalid parameters"); // engine characteristics - _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR result_type min() { return _Min; } - _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR result_type max() { return _Max; } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR result_type min() { return _Min; } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR result_type max() { return _Max; } // constructors and seeding functions _LIBCPP_HIDE_FROM_ABI independent_bits_engine() {} @@ -94,25 +94,47 @@ public: _LIBCPP_HIDE_FROM_ABI explicit independent_bits_engine(result_type __sd) : __e_(__sd) {} template < class _Sseq, - __enable_if_t<__is_seed_sequence<_Sseq, independent_bits_engine>::value && !is_convertible<_Sseq, _Engine>::value, + __enable_if_t<__is_seed_sequence_v<_Sseq, independent_bits_engine> && !is_convertible<_Sseq, _Engine>::value, int> = 0> _LIBCPP_HIDE_FROM_ABI explicit independent_bits_engine(_Sseq& __q) : __e_(__q) {} _LIBCPP_HIDE_FROM_ABI void seed() { __e_.seed(); } _LIBCPP_HIDE_FROM_ABI void seed(result_type __sd) { __e_.seed(__sd); } - template ::value, int> = 0> + template , int> = 0> _LIBCPP_HIDE_FROM_ABI void seed(_Sseq& __q) { __e_.seed(__q); } // generating functions - _LIBCPP_HIDE_FROM_ABI result_type operator()() { return __eval(integral_constant()); } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type operator()() { + if _LIBCPP_CONSTEXPR (_Rp != 0) { + result_type __sp = 0; + for (size_t __k = 0; __k < __n0; ++__k) { + _Engine_result_type __u; + do { + __u = __e_() - _Engine::min(); + } while (__u >= __y0); + __sp = static_cast(__lshift<__w0>(__sp) + (__u & __mask0)); + } + for (size_t __k = __n0; __k < __n; ++__k) { + _Engine_result_type __u; + do { + __u = __e_() - _Engine::min(); + } while (__u >= __y1); + __sp = static_cast(__lshift<__w0 + 1>(__sp) + (__u & __mask1)); + } + return __sp; + } else { + return static_cast(__e_() & __mask0); + } + } + _LIBCPP_HIDE_FROM_ABI void discard(unsigned long long __z) { for (; __z; --__z) - operator()(); + (void)operator()(); } // property functions - _LIBCPP_HIDE_FROM_ABI const _Engine& base() const _NOEXCEPT { return __e_; } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI const _Engine& base() const _NOEXCEPT { return __e_; } template friend bool operator==(const independent_bits_engine<_Eng, _Wp, _UInt>& __x, @@ -131,9 +153,6 @@ public: operator>>(basic_istream<_CharT, _Traits>& __is, independent_bits_engine<_Eng, _Wp, _UInt>& __x); private: - _LIBCPP_HIDE_FROM_ABI result_type __eval(false_type); - _LIBCPP_HIDE_FROM_ABI result_type __eval(true_type); - template = 0> _LIBCPP_HIDE_FROM_ABI static result_type __lshift(result_type __x) { return __x << __count; @@ -145,31 +164,6 @@ private: } }; -template -inline _UIntType independent_bits_engine<_Engine, __w, _UIntType>::__eval(false_type) { - return static_cast(__e_() & __mask0); -} - -template -_UIntType independent_bits_engine<_Engine, __w, _UIntType>::__eval(true_type) { - result_type __sp = 0; - for (size_t __k = 0; __k < __n0; ++__k) { - _Engine_result_type __u; - do { - __u = __e_() - _Engine::min(); - } while (__u >= __y0); - __sp = static_cast(__lshift<__w0>(__sp) + (__u & __mask0)); - } - for (size_t __k = __n0; __k < __n; ++__k) { - _Engine_result_type __u; - do { - __u = __e_() - _Engine::min(); - } while (__u >= __y1); - __sp = static_cast(__lshift<__w0 + 1>(__sp) + (__u & __mask1)); - } - return __sp; -} - template inline _LIBCPP_HIDE_FROM_ABI bool operator==(const independent_bits_engine<_Eng, _Wp, _UInt>& __x, const independent_bits_engine<_Eng, _Wp, _UInt>& __y) { diff --git a/lib/libcxx/include/__random/is_seed_sequence.h b/lib/libcxx/include/__random/is_seed_sequence.h index c7171cff2eda097beae2194da8e3f006a0ededc8..8b675cccd44747421680c45b163cda295c2ef67b 100644 --- a/lib/libcxx/include/__random/is_seed_sequence.h +++ b/lib/libcxx/include/__random/is_seed_sequence.h @@ -21,10 +21,8 @@ _LIBCPP_BEGIN_NAMESPACE_STD template -struct __is_seed_sequence { - static _LIBCPP_CONSTEXPR const bool value = - !is_convertible<_Sseq, typename _Engine::result_type>::value && !is_same<__remove_cv_t<_Sseq>, _Engine>::value; -}; +inline const bool __is_seed_sequence_v = + !is_convertible<_Sseq, typename _Engine::result_type>::value && !is_same<__remove_cv_t<_Sseq>, _Engine>::value; _LIBCPP_END_NAMESPACE_STD diff --git a/lib/libcxx/include/__random/linear_congruential_engine.h b/lib/libcxx/include/__random/linear_congruential_engine.h index f74129d9b8ffecd8ed8b6572c58113c236c0334c..03beea93050e486881d9c41e8cc116196c32119e 100644 --- a/lib/libcxx/include/__random/linear_congruential_engine.h +++ b/lib/libcxx/include/__random/linear_congruential_engine.h @@ -254,8 +254,8 @@ public: static inline _LIBCPP_CONSTEXPR const result_type multiplier = __a; static inline _LIBCPP_CONSTEXPR const result_type increment = __c; static inline _LIBCPP_CONSTEXPR const result_type modulus = __m; - _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR result_type min() { return _Min; } - _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR result_type max() { return _Max; } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR result_type min() { return _Min; } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR result_type max() { return _Max; } static inline _LIBCPP_CONSTEXPR const result_type default_seed = 1u; // constructors and seeding functions @@ -265,28 +265,43 @@ public: #else _LIBCPP_HIDE_FROM_ABI explicit linear_congruential_engine(result_type __s = default_seed) { seed(__s); } #endif - template ::value, int> = 0> + template , int> = 0> _LIBCPP_HIDE_FROM_ABI explicit linear_congruential_engine(_Sseq& __q) { seed(__q); } + _LIBCPP_HIDE_FROM_ABI void seed(result_type __s = default_seed) { - seed(integral_constant(), integral_constant(), __s); + if _LIBCPP_CONSTEXPR (__m == 0) { + if _LIBCPP_CONSTEXPR (__c == 0) + __x_ = __s == 0 ? 1 : __s; + else + __x_ = __s; + } else { + if _LIBCPP_CONSTEXPR (__c == 0) + __x_ = __s % __m == 0 ? 1 : __s % __m; + else + __x_ = __s % __m; + } } - template ::value, int> = 0> + + template , int> = 0> _LIBCPP_HIDE_FROM_ABI void seed(_Sseq& __q) { - __seed( - __q, - integral_constant 0x100000000ull))>()); + const _LIBCPP_CONSTEXPR unsigned __k = + 1 + (__m == 0 ? (sizeof(result_type) * __CHAR_BIT__ - 1) / 32 : (__m > 0x100000000ull)); + static_assert(__k <= 2); + uint32_t __ar[__k + 3]; + __q.generate(__ar, __ar + __k + 3); + result_type __s = static_cast((__ar[3] + (__k == 1 ? 0 : (uint64_t)__ar[4] << 32)) % __m); + __x_ = __c == 0 && __s == 0 ? result_type(1) : __s; } // generating functions - _LIBCPP_HIDE_FROM_ABI result_type operator()() { + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type operator()() { return __x_ = static_cast(__lce_ta<__a, __c, __m, _Mp>::next(__x_)); } _LIBCPP_HIDE_FROM_ABI void discard(unsigned long long __z) { for (; __z; --__z) - operator()(); + (void)operator()(); } friend _LIBCPP_HIDE_FROM_ABI bool @@ -299,16 +314,6 @@ public: } private: - _LIBCPP_HIDE_FROM_ABI void seed(true_type, true_type, result_type __s) { __x_ = __s == 0 ? 1 : __s; } - _LIBCPP_HIDE_FROM_ABI void seed(true_type, false_type, result_type __s) { __x_ = __s; } - _LIBCPP_HIDE_FROM_ABI void seed(false_type, true_type, result_type __s) { __x_ = __s % __m == 0 ? 1 : __s % __m; } - _LIBCPP_HIDE_FROM_ABI void seed(false_type, false_type, result_type __s) { __x_ = __s % __m; } - - template - _LIBCPP_HIDE_FROM_ABI void __seed(_Sseq& __q, integral_constant); - template - _LIBCPP_HIDE_FROM_ABI void __seed(_Sseq& __q, integral_constant); - template friend basic_ostream<_CharT, _Traits>& operator<<(basic_ostream<_CharT, _Traits>& __os, const linear_congruential_engine<_Up, _Ap, _Cp, _Np>&); @@ -318,26 +323,6 @@ private: operator>>(basic_istream<_CharT, _Traits>& __is, linear_congruential_engine<_Up, _Ap, _Cp, _Np>& __x); }; -template -template -void linear_congruential_engine<_UIntType, __a, __c, __m>::__seed(_Sseq& __q, integral_constant) { - const unsigned __k = 1; - uint32_t __ar[__k + 3]; - __q.generate(__ar, __ar + __k + 3); - result_type __s = static_cast(__ar[3] % __m); - __x_ = __c == 0 && __s == 0 ? result_type(1) : __s; -} - -template -template -void linear_congruential_engine<_UIntType, __a, __c, __m>::__seed(_Sseq& __q, integral_constant) { - const unsigned __k = 2; - uint32_t __ar[__k + 3]; - __q.generate(__ar, __ar + __k + 3); - result_type __s = static_cast((__ar[3] + ((uint64_t)__ar[4] << 32)) % __m); - __x_ = __c == 0 && __s == 0 ? result_type(1) : __s; -} - template inline _LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>& operator<<(basic_ostream<_CharT, _Traits>& __os, const linear_congruential_engine<_UIntType, __a, __c, __m>& __x) { diff --git a/lib/libcxx/include/__random/lognormal_distribution.h b/lib/libcxx/include/__random/lognormal_distribution.h index e6ca5b4612a2d806b0078a18d3e9e8b25054f761..a94918a6a6a447bd3b6254a31bf38a2a02100efc 100644 --- a/lib/libcxx/include/__random/lognormal_distribution.h +++ b/lib/libcxx/include/__random/lognormal_distribution.h @@ -43,8 +43,8 @@ public: _LIBCPP_HIDE_FROM_ABI explicit param_type(result_type __m = 0, result_type __s = 1) : __m_(__m), __s_(__s) {} - _LIBCPP_HIDE_FROM_ABI result_type m() const { return __m_; } - _LIBCPP_HIDE_FROM_ABI result_type s() const { return __s_; } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type m() const { return __m_; } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type s() const { return __s_; } friend _LIBCPP_HIDE_FROM_ABI bool operator==(const param_type& __x, const param_type& __y) { return __x.__m_ == __y.__m_ && __x.__s_ == __y.__s_; @@ -68,28 +68,28 @@ public: // generating functions template - _LIBCPP_HIDE_FROM_ABI result_type operator()(_URNG& __g) { + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type operator()(_URNG& __g) { return std::exp(__nd_(__g)); } template - _LIBCPP_HIDE_FROM_ABI result_type operator()(_URNG& __g, const param_type& __p) { + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type operator()(_URNG& __g, const param_type& __p) { typename normal_distribution::param_type __pn(__p.m(), __p.s()); return std::exp(__nd_(__g, __pn)); } // property functions - _LIBCPP_HIDE_FROM_ABI result_type m() const { return __nd_.mean(); } - _LIBCPP_HIDE_FROM_ABI result_type s() const { return __nd_.stddev(); } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type m() const { return __nd_.mean(); } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type s() const { return __nd_.stddev(); } - _LIBCPP_HIDE_FROM_ABI param_type param() const { return param_type(__nd_.mean(), __nd_.stddev()); } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI param_type param() const { return param_type(__nd_.mean(), __nd_.stddev()); } _LIBCPP_HIDE_FROM_ABI void param(const param_type& __p) { typename normal_distribution::param_type __pn(__p.m(), __p.s()); __nd_.param(__pn); } - _LIBCPP_HIDE_FROM_ABI result_type min() const { return 0; } - _LIBCPP_HIDE_FROM_ABI result_type max() const { return numeric_limits::infinity(); } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type min() const { return 0; } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type max() const { return numeric_limits::infinity(); } friend _LIBCPP_HIDE_FROM_ABI bool operator==(const lognormal_distribution& __x, const lognormal_distribution& __y) { return __x.__nd_ == __y.__nd_; diff --git a/lib/libcxx/include/__random/mersenne_twister_engine.h b/lib/libcxx/include/__random/mersenne_twister_engine.h index 332e830e731dc7041560b0e098b7930887a70d50..8e49b3b267aa8c4fb8fa0c4ad9bb45d7152163b0 100644 --- a/lib/libcxx/include/__random/mersenne_twister_engine.h +++ b/lib/libcxx/include/__random/mersenne_twister_engine.h @@ -161,8 +161,8 @@ public: static inline _LIBCPP_CONSTEXPR const result_type tempering_c = __c; static inline _LIBCPP_CONSTEXPR const size_t tempering_l = __l; static inline _LIBCPP_CONSTEXPR const result_type initialization_multiplier = __f; - _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR result_type min() { return _Min; } - _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR result_type max() { return _Max; } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR result_type min() { return _Min; } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR result_type max() { return _Max; } static inline _LIBCPP_CONSTEXPR const result_type default_seed = 5489u; // constructors and seeding functions @@ -172,7 +172,7 @@ public: #else _LIBCPP_HIDE_FROM_ABI explicit mersenne_twister_engine(result_type __sd = default_seed) { seed(__sd); } #endif - template ::value, int> = 0> + template , int> = 0> _LIBCPP_HIDE_FROM_ABI explicit mersenne_twister_engine(_Sseq& __q) { seed(__q); } @@ -181,21 +181,68 @@ public: for (size_t __i = 1; __i < __n; ++__i) __x_[__i] = (__f * (__x_[__i - 1] ^ __rshift<__w - 2>(__x_[__i - 1])) + __i) & _Max; __i_ = 0; +#ifdef _LIBCPP_ABI_VECTORIZED_MERSENNE_TWISTER_ENGINE + __update_all_states(); +#endif } - template ::value, int> = 0> + template , int> = 0> _LIBCPP_HIDE_FROM_ABI void seed(_Sseq& __q) { - __seed(__q, integral_constant()); + const unsigned __k = 1 + (__w - 1) / 32; + static_assert(__k <= 2); + uint32_t __ar[__n * __k]; + __q.generate(__ar, __ar + __n * __k); + for (size_t __i = 0; __i < __n; ++__i) { + if _LIBCPP_CONSTEXPR (__k == 1) { + __x_[__i] = static_cast(__ar[__i] & _Max); + } else { + __x_[__i] = static_cast((__ar[2 * __i] + ((uint64_t)__ar[2 * __i + 1] << 32)) & _Max); + } + } + const result_type __mask = __r == _Dt ? result_type(~0) : (result_type(1) << __r) - result_type(1); + __i_ = 0; + if ((__x_[0] & ~__mask) == 0) { + for (size_t __i = 1; __i < __n; ++__i) + if (__x_[__i] != 0) + return; + __x_[0] = result_type(1) << (__w - 1); + } +#ifdef _LIBCPP_ABI_VECTORIZED_MERSENNE_TWISTER_ENGINE + __update_all_states(); +#endif + } + + void __update_state(size_t __i, size_t __k) { + const size_t __j = (__i + 1) % __n; + const result_type __mask = __r == _Dt ? result_type(~0) : (result_type(1) << __r) - result_type(1); + const result_type __yp = (__x_[__i] & ~__mask) | (__x_[__j] & __mask); + __x_[__i] = __x_[__k] ^ __rshift<1>(__yp) ^ (__a * (__yp & 1)); + } + + void __update_state(size_t __i) { __update_state(__i, (__i + __m) % __n); } + + void __update_all_states() { + size_t __i = 0; + // This is split into two loops to help the compiler vectorize the code + for (; __i != (__n - __m); ++__i) + __update_state(__i); + for (size_t __j = 0; __i != __n; ++__i, ++__j) + __update_state(__i, __j); } // generating functions - _LIBCPP_HIDE_FROM_ABI result_type operator()() { - const size_t __j = (__i_ + 1) % __n; - const result_type __mask = __r == _Dt ? result_type(~0) : (result_type(1) << __r) - result_type(1); - const result_type __yp = (__x_[__i_] & ~__mask) | (__x_[__j] & __mask); - const size_t __k = (__i_ + __m) % __n; - __x_[__i_] = __x_[__k] ^ __rshift<1>(__yp) ^ (__a * (__yp & 1)); - result_type __z = __x_[__i_] ^ (__rshift<__u>(__x_[__i_]) & __d); - __i_ = __j; + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type operator()() { +#ifdef _LIBCPP_ABI_VECTORIZED_MERSENNE_TWISTER_ENGINE + result_type __val = __x_[__i_]; + if (++__i_ == __n) [[__unlikely__]] { + __update_all_states(); + __i_ = 0; + } +#else + __update_state(__i_); + result_type __val = __x_[__i_]; + __i_ = (__i_ + 1) % __n; +#endif + result_type __z = __val ^ (__rshift<__u>(__val) & __d); __z ^= __lshift<__s>(__z) & __b; __z ^= __lshift<__t>(__z) & __c; return __z ^ __rshift<__l>(__z); @@ -203,7 +250,7 @@ public: _LIBCPP_HIDE_FROM_ABI void discard(unsigned long long __z) { for (; __z; --__z) - operator()(); + (void)operator()(); } template & __x); private: - template - _LIBCPP_HIDE_FROM_ABI void __seed(_Sseq& __q, integral_constant) { - const unsigned __k = 1; - uint32_t __ar[__n * __k]; - __q.generate(__ar, __ar + __n * __k); - for (size_t __i = 0; __i < __n; ++__i) - __x_[__i] = static_cast(__ar[__i] & _Max); - const result_type __mask = __r == _Dt ? result_type(~0) : (result_type(1) << __r) - result_type(1); - __i_ = 0; - if ((__x_[0] & ~__mask) == 0) { - for (size_t __i = 1; __i < __n; ++__i) - if (__x_[__i] != 0) - return; - __x_[0] = result_type(1) << (__w - 1); + template + _LIBCPP_HIDE_FROM_ABI static result_type __lshift(result_type __x) { + if _LIBCPP_CONSTEXPR (__count < __w) { + return (__x << __count) & _Max; + } else { + return result_type(0); } } - template - _LIBCPP_HIDE_FROM_ABI void __seed(_Sseq& __q, integral_constant) { - const unsigned __k = 2; - uint32_t __ar[__n * __k]; - __q.generate(__ar, __ar + __n * __k); - for (size_t __i = 0; __i < __n; ++__i) - __x_[__i] = static_cast((__ar[2 * __i] + ((uint64_t)__ar[2 * __i + 1] << 32)) & _Max); - const result_type __mask = __r == _Dt ? result_type(~0) : (result_type(1) << __r) - result_type(1); - __i_ = 0; - if ((__x_[0] & ~__mask) == 0) { - for (size_t __i = 1; __i < __n; ++__i) - if (__x_[__i] != 0) - return; - __x_[0] = result_type(1) << (__w - 1); + template + _LIBCPP_HIDE_FROM_ABI static result_type __rshift(result_type __x) { + if _LIBCPP_CONSTEXPR (__count < _Dt) { + return __x >> __count; + } else { + return result_type(0); } } - - template = 0> _LIBCPP_HIDE_FROM_ABI static result_type __lshift(result_type __x) { - return (__x << __count) & _Max; - } - - template = __w), int> = 0> - _LIBCPP_HIDE_FROM_ABI static result_type __lshift(result_type) { - return result_type(0); - } - - template = 0> _LIBCPP_HIDE_FROM_ABI static result_type __rshift(result_type __x) { - return __x >> __count; - } - - template = _Dt), int> = 0> - _LIBCPP_HIDE_FROM_ABI static result_type __rshift(result_type) { - return result_type(0); - } }; template - _LIBCPP_HIDE_FROM_ABI result_type operator()(_URNG& __g) { + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type operator()(_URNG& __g) { return (*this)(__g, __p_); } template - _LIBCPP_HIDE_FROM_ABI result_type operator()(_URNG& __g, const param_type& __p); + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type operator()(_URNG& __g, const param_type& __p); // property functions - _LIBCPP_HIDE_FROM_ABI result_type k() const { return __p_.k(); } - _LIBCPP_HIDE_FROM_ABI double p() const { return __p_.p(); } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type k() const { return __p_.k(); } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI double p() const { return __p_.p(); } - _LIBCPP_HIDE_FROM_ABI param_type param() const { return __p_; } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI param_type param() const { return __p_; } _LIBCPP_HIDE_FROM_ABI void param(const param_type& __p) { __p_ = __p; } - _LIBCPP_HIDE_FROM_ABI result_type min() const { return 0; } - _LIBCPP_HIDE_FROM_ABI result_type max() const { return numeric_limits::max(); } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type min() const { return 0; } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type max() const { return numeric_limits::max(); } friend _LIBCPP_HIDE_FROM_ABI bool operator==(const negative_binomial_distribution& __x, const negative_binomial_distribution& __y) { diff --git a/lib/libcxx/include/__random/normal_distribution.h b/lib/libcxx/include/__random/normal_distribution.h index a735d8307a3e0875a26e2d074954c21aca2278b6..4ebfd750a5f8a4f3ffdd20e434d2518fa16ff65a 100644 --- a/lib/libcxx/include/__random/normal_distribution.h +++ b/lib/libcxx/include/__random/normal_distribution.h @@ -44,8 +44,8 @@ public: _LIBCPP_HIDE_FROM_ABI explicit param_type(result_type __mean = 0, result_type __stddev = 1) : __mean_(__mean), __stddev_(__stddev) {} - _LIBCPP_HIDE_FROM_ABI result_type mean() const { return __mean_; } - _LIBCPP_HIDE_FROM_ABI result_type stddev() const { return __stddev_; } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type mean() const { return __mean_; } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type stddev() const { return __stddev_; } friend _LIBCPP_HIDE_FROM_ABI bool operator==(const param_type& __x, const param_type& __y) { return __x.__mean_ == __y.__mean_ && __x.__stddev_ == __y.__stddev_; @@ -73,21 +73,21 @@ public: // generating functions template - _LIBCPP_HIDE_FROM_ABI result_type operator()(_URNG& __g) { + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type operator()(_URNG& __g) { return (*this)(__g, __p_); } template - _LIBCPP_HIDE_FROM_ABI result_type operator()(_URNG& __g, const param_type& __p); + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type operator()(_URNG& __g, const param_type& __p); // property functions - _LIBCPP_HIDE_FROM_ABI result_type mean() const { return __p_.mean(); } - _LIBCPP_HIDE_FROM_ABI result_type stddev() const { return __p_.stddev(); } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type mean() const { return __p_.mean(); } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type stddev() const { return __p_.stddev(); } - _LIBCPP_HIDE_FROM_ABI param_type param() const { return __p_; } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI param_type param() const { return __p_; } _LIBCPP_HIDE_FROM_ABI void param(const param_type& __p) { __p_ = __p; } - _LIBCPP_HIDE_FROM_ABI result_type min() const { return -numeric_limits::infinity(); } - _LIBCPP_HIDE_FROM_ABI result_type max() const { return numeric_limits::infinity(); } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type min() const { return -numeric_limits::infinity(); } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type max() const { return numeric_limits::infinity(); } friend _LIBCPP_HIDE_FROM_ABI bool operator==(const normal_distribution& __x, const normal_distribution& __y) { return __x.__p_ == __y.__p_ && __x.__v_hot_ == __y.__v_hot_ && (!__x.__v_hot_ || __x.__v_ == __y.__v_); diff --git a/lib/libcxx/include/__random/piecewise_constant_distribution.h b/lib/libcxx/include/__random/piecewise_constant_distribution.h index 3faf339325f7472a34eee43908cca79c8851c59e..54e327857c783c1dca33c09ec59b10cab66264d2 100644 --- a/lib/libcxx/include/__random/piecewise_constant_distribution.h +++ b/lib/libcxx/include/__random/piecewise_constant_distribution.h @@ -59,8 +59,8 @@ public: _LIBCPP_HIDE_FROM_ABI param_type(param_type const&) = default; _LIBCPP_HIDE_FROM_ABI param_type& operator=(const param_type& __rhs); - _LIBCPP_HIDE_FROM_ABI vector intervals() const { return __b_; } - _LIBCPP_HIDE_FROM_ABI vector densities() const { return __densities_; } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI vector intervals() const { return __b_; } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI vector densities() const { return __densities_; } friend _LIBCPP_HIDE_FROM_ABI bool operator==(const param_type& __x, const param_type& __y) { return __x.__densities_ == __y.__densities_ && __x.__b_ == __y.__b_; @@ -109,21 +109,21 @@ public: // generating functions template - _LIBCPP_HIDE_FROM_ABI result_type operator()(_URNG& __g) { + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type operator()(_URNG& __g) { return (*this)(__g, __p_); } template - _LIBCPP_HIDE_FROM_ABI result_type operator()(_URNG& __g, const param_type& __p); + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type operator()(_URNG& __g, const param_type& __p); // property functions - _LIBCPP_HIDE_FROM_ABI vector intervals() const { return __p_.intervals(); } - _LIBCPP_HIDE_FROM_ABI vector densities() const { return __p_.densities(); } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI vector intervals() const { return __p_.intervals(); } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI vector densities() const { return __p_.densities(); } - _LIBCPP_HIDE_FROM_ABI param_type param() const { return __p_; } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI param_type param() const { return __p_; } _LIBCPP_HIDE_FROM_ABI void param(const param_type& __p) { __p_ = __p; } - _LIBCPP_HIDE_FROM_ABI result_type min() const { return __p_.__b_.front(); } - _LIBCPP_HIDE_FROM_ABI result_type max() const { return __p_.__b_.back(); } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type min() const { return __p_.__b_.front(); } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type max() const { return __p_.__b_.back(); } friend _LIBCPP_HIDE_FROM_ABI bool operator==(const piecewise_constant_distribution& __x, const piecewise_constant_distribution& __y) { diff --git a/lib/libcxx/include/__random/piecewise_linear_distribution.h b/lib/libcxx/include/__random/piecewise_linear_distribution.h index 8aa3f19ca90047f4792e2be407bc32dbd99f3909..ddf6416704395fefe6e1df92b8def5553ccb23bf 100644 --- a/lib/libcxx/include/__random/piecewise_linear_distribution.h +++ b/lib/libcxx/include/__random/piecewise_linear_distribution.h @@ -60,8 +60,8 @@ public: _LIBCPP_HIDE_FROM_ABI param_type(param_type const&) = default; _LIBCPP_HIDE_FROM_ABI param_type& operator=(const param_type& __rhs); - _LIBCPP_HIDE_FROM_ABI vector intervals() const { return __b_; } - _LIBCPP_HIDE_FROM_ABI vector densities() const { return __densities_; } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI vector intervals() const { return __b_; } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI vector densities() const { return __densities_; } friend _LIBCPP_HIDE_FROM_ABI bool operator==(const param_type& __x, const param_type& __y) { return __x.__densities_ == __y.__densities_ && __x.__b_ == __y.__b_; @@ -110,21 +110,21 @@ public: // generating functions template - _LIBCPP_HIDE_FROM_ABI result_type operator()(_URNG& __g) { + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type operator()(_URNG& __g) { return (*this)(__g, __p_); } template - _LIBCPP_HIDE_FROM_ABI result_type operator()(_URNG& __g, const param_type& __p); + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type operator()(_URNG& __g, const param_type& __p); // property functions - _LIBCPP_HIDE_FROM_ABI vector intervals() const { return __p_.intervals(); } - _LIBCPP_HIDE_FROM_ABI vector densities() const { return __p_.densities(); } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI vector intervals() const { return __p_.intervals(); } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI vector densities() const { return __p_.densities(); } - _LIBCPP_HIDE_FROM_ABI param_type param() const { return __p_; } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI param_type param() const { return __p_; } _LIBCPP_HIDE_FROM_ABI void param(const param_type& __p) { __p_ = __p; } - _LIBCPP_HIDE_FROM_ABI result_type min() const { return __p_.__b_.front(); } - _LIBCPP_HIDE_FROM_ABI result_type max() const { return __p_.__b_.back(); } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type min() const { return __p_.__b_.front(); } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type max() const { return __p_.__b_.back(); } friend _LIBCPP_HIDE_FROM_ABI bool operator==(const piecewise_linear_distribution& __x, const piecewise_linear_distribution& __y) { diff --git a/lib/libcxx/include/__random/poisson_distribution.h b/lib/libcxx/include/__random/poisson_distribution.h index 85398c751b453a9674578f0d4f65cd6346081897..118f148e9b6dad97d1787be201a8556e4241df1a 100644 --- a/lib/libcxx/include/__random/poisson_distribution.h +++ b/lib/libcxx/include/__random/poisson_distribution.h @@ -53,7 +53,7 @@ public: _LIBCPP_HIDE_FROM_ABI explicit param_type(double __mean = 1.0); - _LIBCPP_HIDE_FROM_ABI double mean() const { return __mean_; } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI double mean() const { return __mean_; } friend _LIBCPP_HIDE_FROM_ABI bool operator==(const param_type& __x, const param_type& __y) { return __x.__mean_ == __y.__mean_; @@ -79,20 +79,20 @@ public: // generating functions template - _LIBCPP_HIDE_FROM_ABI result_type operator()(_URNG& __g) { + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type operator()(_URNG& __g) { return (*this)(__g, __p_); } template - _LIBCPP_HIDE_FROM_ABI result_type operator()(_URNG& __g, const param_type& __p); + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type operator()(_URNG& __g, const param_type& __p); // property functions - _LIBCPP_HIDE_FROM_ABI double mean() const { return __p_.mean(); } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI double mean() const { return __p_.mean(); } - _LIBCPP_HIDE_FROM_ABI param_type param() const { return __p_; } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI param_type param() const { return __p_; } _LIBCPP_HIDE_FROM_ABI void param(const param_type& __p) { __p_ = __p; } - _LIBCPP_HIDE_FROM_ABI result_type min() const { return 0; } - _LIBCPP_HIDE_FROM_ABI result_type max() const { return numeric_limits::max(); } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type min() const { return 0; } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type max() const { return numeric_limits::max(); } friend _LIBCPP_HIDE_FROM_ABI bool operator==(const poisson_distribution& __x, const poisson_distribution& __y) { return __x.__p_ == __y.__p_; diff --git a/lib/libcxx/include/__random/random_device.h b/lib/libcxx/include/__random/random_device.h index 33ec585cc0efb9ae7ac17c3f5236fa45769d2caa..f28e5fca140e5624cbfaac52edbffe9e63f62ee4 100644 --- a/lib/libcxx/include/__random/random_device.h +++ b/lib/libcxx/include/__random/random_device.h @@ -19,27 +19,24 @@ _LIBCPP_PUSH_MACROS #include <__undef_macros> -_LIBCPP_BEGIN_NAMESPACE_STD - #if _LIBCPP_HAS_RANDOM_DEVICE +_LIBCPP_BEGIN_NAMESPACE_STD +_LIBCPP_BEGIN_EXPLICIT_ABI_ANNOTATIONS + class _LIBCPP_EXPORTED_FROM_ABI random_device { # ifdef _LIBCPP_USING_DEV_RANDOM int __f_; # elif !defined(_LIBCPP_ABI_NO_RANDOM_DEVICE_COMPATIBILITY_LAYOUT) - _LIBCPP_DIAGNOSTIC_PUSH - _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wunused-private-field") - // Apple platforms used to use the `_LIBCPP_USING_DEV_RANDOM` code path, and now // use `arc4random()` as of this comment. In order to avoid breaking the ABI, we // retain the same layout as before. # if defined(__APPLE__) - int __padding_; // padding to fake the `__f_` field above + [[__maybe_unused__]] int __padding_; // padding to fake the `__f_` field above # endif // ... vendors can add workarounds here if they switch to a different representation ... - _LIBCPP_DIAGNOSTIC_POP # endif public: @@ -50,8 +47,8 @@ public: static _LIBCPP_CONSTEXPR const result_type _Min = 0; static _LIBCPP_CONSTEXPR const result_type _Max = 0xFFFFFFFFu; - _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR result_type min() { return _Min; } - _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR result_type max() { return _Max; } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR result_type min() { return _Min; } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR result_type max() { return _Max; } // constructors # ifndef _LIBCPP_CXX03_LANG @@ -63,19 +60,20 @@ public: ~random_device(); // generating functions - result_type operator()(); + [[__nodiscard__]] result_type operator()(); // property functions - double entropy() const _NOEXCEPT; + [[__nodiscard__]] double entropy() const _NOEXCEPT; random_device(const random_device&) = delete; void operator=(const random_device&) = delete; }; -#endif // _LIBCPP_HAS_RANDOM_DEVICE - +_LIBCPP_END_EXPLICIT_ABI_ANNOTATIONS _LIBCPP_END_NAMESPACE_STD +#endif // _LIBCPP_HAS_RANDOM_DEVICE + _LIBCPP_POP_MACROS #endif // _LIBCPP___RANDOM_RANDOM_DEVICE_H diff --git a/lib/libcxx/include/__random/seed_seq.h b/lib/libcxx/include/__random/seed_seq.h index b1ccc8329b8f984f26628a92c81cf445ea30c93e..f5748b7193048928f7a78424e9040c004262d069 100644 --- a/lib/libcxx/include/__random/seed_seq.h +++ b/lib/libcxx/include/__random/seed_seq.h @@ -56,7 +56,7 @@ public: _LIBCPP_HIDE_FROM_ABI void generate(_RandomAccessIterator __first, _RandomAccessIterator __last); // property functions - _LIBCPP_HIDE_FROM_ABI size_t size() const _NOEXCEPT { return __v_.size(); } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI size_t size() const _NOEXCEPT { return __v_.size(); } template _LIBCPP_HIDE_FROM_ABI void param(_OutputIterator __dest) const { std::copy(__v_.begin(), __v_.end(), __dest); @@ -65,7 +65,7 @@ public: seed_seq(const seed_seq&) = delete; void operator=(const seed_seq&) = delete; - _LIBCPP_HIDE_FROM_ABI static result_type _Tp(result_type __x) { return __x ^ (__x >> 27); } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static result_type _Tp(result_type __x) { return __x ^ (__x >> 27); } private: template diff --git a/lib/libcxx/include/__random/shuffle_order_engine.h b/lib/libcxx/include/__random/shuffle_order_engine.h index 64d73033a16091408c15c160da181f2af0244fb6..3d8c323d096b5859137c6ee3aad6744e40a05cb4 100644 --- a/lib/libcxx/include/__random/shuffle_order_engine.h +++ b/lib/libcxx/include/__random/shuffle_order_engine.h @@ -76,8 +76,8 @@ public: static _LIBCPP_CONSTEXPR const result_type _Max = _Engine::max(); #endif static_assert(_Min < _Max, "shuffle_order_engine invalid parameters"); - _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR result_type min() { return _Min; } - _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR result_type max() { return _Max; } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR result_type min() { return _Min; } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR result_type max() { return _Max; } static _LIBCPP_CONSTEXPR const unsigned long long _Rp = _Max - _Min + 1ull; @@ -88,10 +88,9 @@ public: _LIBCPP_HIDE_FROM_ABI explicit shuffle_order_engine(_Engine&& __e) : __e_(std::move(__e)) { __init(); } #endif // _LIBCPP_CXX03_LANG _LIBCPP_HIDE_FROM_ABI explicit shuffle_order_engine(result_type __sd) : __e_(__sd) { __init(); } - template < - class _Sseq, - __enable_if_t<__is_seed_sequence<_Sseq, shuffle_order_engine>::value && !is_convertible<_Sseq, _Engine>::value, - int> = 0> + template && !is_convertible<_Sseq, _Engine>::value, + int> = 0> _LIBCPP_HIDE_FROM_ABI explicit shuffle_order_engine(_Sseq& __q) : __e_(__q) { __init(); } @@ -103,21 +102,35 @@ public: __e_.seed(__sd); __init(); } - template ::value, int> = 0> + template , int> = 0> _LIBCPP_HIDE_FROM_ABI void seed(_Sseq& __q) { __e_.seed(__q); __init(); } // generating functions - _LIBCPP_HIDE_FROM_ABI result_type operator()() { return __eval(integral_constant()); } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type operator()() { + if _LIBCPP_CONSTEXPR (_Rp != 0 || !(__k & 1)) { + using _Ratio = __uratio<__k, _Rp != 0 ? _Rp : 0x8000000000000000ull>; + if _LIBCPP_CONSTEXPR (_Ratio::num > 0xFFFFFFFFFFFFFFFFull / (_Max - _Min)) { + return __evalf<_Ratio::num, _Ratio::den>(); + } else { + const size_t __j = static_cast(_Ratio::num * (__y_ - _Min) / _Ratio::den); + __y_ = __v_[__j]; + __v_[__j] = __e_(); + return __y_; + } + } else + return __evalf<__k, 0>(); + } + _LIBCPP_HIDE_FROM_ABI void discard(unsigned long long __z) { for (; __z; --__z) - operator()(); + (void)operator()(); } // property functions - _LIBCPP_HIDE_FROM_ABI const _Engine& base() const _NOEXCEPT { return __e_; } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI const _Engine& base() const _NOEXCEPT { return __e_; } private: template @@ -140,29 +153,6 @@ private: __y_ = __e_(); } - _LIBCPP_HIDE_FROM_ABI result_type __eval(false_type) { return __eval2(integral_constant()); } - _LIBCPP_HIDE_FROM_ABI result_type __eval(true_type) { return __eval(__uratio<__k, _Rp>()); } - - _LIBCPP_HIDE_FROM_ABI result_type __eval2(false_type) { return __eval(__uratio<__k / 2, 0x8000000000000000ull>()); } - _LIBCPP_HIDE_FROM_ABI result_type __eval2(true_type) { return __evalf<__k, 0>(); } - - template ::num > 0xFFFFFFFFFFFFFFFFull / (_Max - _Min)), int> = 0> - _LIBCPP_HIDE_FROM_ABI result_type __eval(__uratio<_Np, _Dp>) { - return __evalf<__uratio<_Np, _Dp>::num, __uratio<_Np, _Dp>::den>(); - } - - template ::num <= 0xFFFFFFFFFFFFFFFFull / (_Max - _Min), int> = 0> - _LIBCPP_HIDE_FROM_ABI result_type __eval(__uratio<_Np, _Dp>) { - const size_t __j = static_cast(__uratio<_Np, _Dp>::num * (__y_ - _Min) / __uratio<_Np, _Dp>::den); - __y_ = __v_[__j]; - __v_[__j] = __e_(); - return __y_; - } - template _LIBCPP_HIDE_FROM_ABI result_type __evalf() { const double __fp = __d == 0 ? __n / (2. * 0x8000000000000000ull) : __n / (double)__d; diff --git a/lib/libcxx/include/__random/student_t_distribution.h b/lib/libcxx/include/__random/student_t_distribution.h index dc199506862b8138a056a198aa962a1df1decc22..16579962ce925b43d72a9209c2e758042cc93136 100644 --- a/lib/libcxx/include/__random/student_t_distribution.h +++ b/lib/libcxx/include/__random/student_t_distribution.h @@ -43,7 +43,7 @@ public: _LIBCPP_HIDE_FROM_ABI explicit param_type(result_type __n = 1) : __n_(__n) {} - _LIBCPP_HIDE_FROM_ABI result_type n() const { return __n_; } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type n() const { return __n_; } friend _LIBCPP_HIDE_FROM_ABI bool operator==(const param_type& __x, const param_type& __y) { return __x.__n_ == __y.__n_; @@ -68,20 +68,20 @@ public: // generating functions template - _LIBCPP_HIDE_FROM_ABI result_type operator()(_URNG& __g) { + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type operator()(_URNG& __g) { return (*this)(__g, __p_); } template - _LIBCPP_HIDE_FROM_ABI result_type operator()(_URNG& __g, const param_type& __p); + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type operator()(_URNG& __g, const param_type& __p); // property functions - _LIBCPP_HIDE_FROM_ABI result_type n() const { return __p_.n(); } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type n() const { return __p_.n(); } - _LIBCPP_HIDE_FROM_ABI param_type param() const { return __p_; } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI param_type param() const { return __p_; } _LIBCPP_HIDE_FROM_ABI void param(const param_type& __p) { __p_ = __p; } - _LIBCPP_HIDE_FROM_ABI result_type min() const { return -numeric_limits::infinity(); } - _LIBCPP_HIDE_FROM_ABI result_type max() const { return numeric_limits::infinity(); } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type min() const { return -numeric_limits::infinity(); } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type max() const { return numeric_limits::infinity(); } friend _LIBCPP_HIDE_FROM_ABI bool operator==(const student_t_distribution& __x, const student_t_distribution& __y) { return __x.__p_ == __y.__p_; diff --git a/lib/libcxx/include/__random/subtract_with_carry_engine.h b/lib/libcxx/include/__random/subtract_with_carry_engine.h index c2b17cc889769b38a10172435593a4c7ee537de3..4f9b31a074ee06cb7883a230fde6a2d798c2d695 100644 --- a/lib/libcxx/include/__random/subtract_with_carry_engine.h +++ b/lib/libcxx/include/__random/subtract_with_carry_engine.h @@ -75,8 +75,8 @@ public: static inline _LIBCPP_CONSTEXPR const size_t word_size = __w; static inline _LIBCPP_CONSTEXPR const size_t short_lag = __s; static inline _LIBCPP_CONSTEXPR const size_t long_lag = __r; - _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR result_type min() { return _Min; } - _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR result_type max() { return _Max; } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR result_type min() { return _Min; } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR result_type max() { return _Max; } static inline _LIBCPP_CONSTEXPR const result_type default_seed = 19780503u; // constructors and seeding functions @@ -86,23 +86,46 @@ public: #else _LIBCPP_HIDE_FROM_ABI explicit subtract_with_carry_engine(result_type __sd = default_seed) { seed(__sd); } #endif - template ::value, int> = 0> + template , int> = 0> _LIBCPP_HIDE_FROM_ABI explicit subtract_with_carry_engine(_Sseq& __q) { seed(__q); } + _LIBCPP_HIDE_FROM_ABI void seed(result_type __sd = default_seed) { - seed(__sd, integral_constant()); + linear_congruential_engine __e(__sd == 0u ? default_seed : __sd); + for (size_t __i = 0; __i < __r; ++__i) { + if _LIBCPP_CONSTEXPR ((1 + (__w - 1) / 32) == 1) { + __x_[__i] = static_cast(__e() & _Max); + } else { + result_type __e0 = __e(); + __x_[__i] = static_cast((__e0 + ((uint64_t)__e() << 32)) & _Max); + } + } + __c_ = __x_[__r - 1] == 0; + __i_ = 0; } - template ::value, int> = 0> + + template , int> = 0> _LIBCPP_HIDE_FROM_ABI void seed(_Sseq& __q) { - __seed(__q, integral_constant()); + const unsigned __k = 1 + (__w - 1) / 32; + static_assert(__k <= 2); + uint32_t __ar[__r * __k]; + __q.generate(__ar, __ar + __r * __k); + for (size_t __i = 0; __i < __r; ++__i) { + if _LIBCPP_CONSTEXPR (__k == 1) + __x_[__i] = static_cast(__ar[__i] & _Max); + else + __x_[__i] = static_cast((__ar[2 * __i] + ((uint64_t)__ar[2 * __i + 1] << 32)) & _Max); + } + __c_ = __x_[__r - 1] == 0; + __i_ = 0; } // generating functions - _LIBCPP_HIDE_FROM_ABI result_type operator()(); + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type operator()(); _LIBCPP_HIDE_FROM_ABI void discard(unsigned long long __z) { for (; __z; --__z) - operator()(); + (void)operator()(); } template @@ -120,60 +143,8 @@ public: template friend basic_istream<_CharT, _Traits>& operator>>(basic_istream<_CharT, _Traits>& __is, subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x); - -private: - _LIBCPP_HIDE_FROM_ABI void seed(result_type __sd, integral_constant); - _LIBCPP_HIDE_FROM_ABI void seed(result_type __sd, integral_constant); - template - _LIBCPP_HIDE_FROM_ABI void __seed(_Sseq& __q, integral_constant); - template - _LIBCPP_HIDE_FROM_ABI void __seed(_Sseq& __q, integral_constant); }; -template -void subtract_with_carry_engine<_UIntType, __w, __s, __r>::seed(result_type __sd, integral_constant) { - linear_congruential_engine __e(__sd == 0u ? default_seed : __sd); - for (size_t __i = 0; __i < __r; ++__i) - __x_[__i] = static_cast(__e() & _Max); - __c_ = __x_[__r - 1] == 0; - __i_ = 0; -} - -template -void subtract_with_carry_engine<_UIntType, __w, __s, __r>::seed(result_type __sd, integral_constant) { - linear_congruential_engine __e(__sd == 0u ? default_seed : __sd); - for (size_t __i = 0; __i < __r; ++__i) { - result_type __e0 = __e(); - __x_[__i] = static_cast((__e0 + ((uint64_t)__e() << 32)) & _Max); - } - __c_ = __x_[__r - 1] == 0; - __i_ = 0; -} - -template -template -void subtract_with_carry_engine<_UIntType, __w, __s, __r>::__seed(_Sseq& __q, integral_constant) { - const unsigned __k = 1; - uint32_t __ar[__r * __k]; - __q.generate(__ar, __ar + __r * __k); - for (size_t __i = 0; __i < __r; ++__i) - __x_[__i] = static_cast(__ar[__i] & _Max); - __c_ = __x_[__r - 1] == 0; - __i_ = 0; -} - -template -template -void subtract_with_carry_engine<_UIntType, __w, __s, __r>::__seed(_Sseq& __q, integral_constant) { - const unsigned __k = 2; - uint32_t __ar[__r * __k]; - __q.generate(__ar, __ar + __r * __k); - for (size_t __i = 0; __i < __r; ++__i) - __x_[__i] = static_cast((__ar[2 * __i] + ((uint64_t)__ar[2 * __i + 1] << 32)) & _Max); - __c_ = __x_[__r - 1] == 0; - __i_ = 0; -} - template _UIntType subtract_with_carry_engine<_UIntType, __w, __s, __r>::operator()() { const result_type& __xs = __x_[(__i_ + (__r - __s)) % __r]; diff --git a/lib/libcxx/include/__random/uniform_int_distribution.h b/lib/libcxx/include/__random/uniform_int_distribution.h index fa2c33755b7398d68531a854ec71e7955383b79c..22b172094d571def686f0595b82722bb7cbf1728 100644 --- a/lib/libcxx/include/__random/uniform_int_distribution.h +++ b/lib/libcxx/include/__random/uniform_int_distribution.h @@ -151,8 +151,8 @@ public: _LIBCPP_HIDE_FROM_ABI explicit param_type(result_type __a = 0, result_type __b = numeric_limits::max()) : __a_(__a), __b_(__b) {} - _LIBCPP_HIDE_FROM_ABI result_type a() const { return __a_; } - _LIBCPP_HIDE_FROM_ABI result_type b() const { return __b_; } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type a() const { return __a_; } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type b() const { return __b_; } _LIBCPP_HIDE_FROM_ABI friend bool operator==(const param_type& __x, const param_type& __y) { return __x.__a_ == __y.__a_ && __x.__b_ == __y.__b_; @@ -179,21 +179,21 @@ public: // generating functions template - _LIBCPP_HIDE_FROM_ABI result_type operator()(_URNG& __g) { + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type operator()(_URNG& __g) { return (*this)(__g, __p_); } template - _LIBCPP_HIDE_FROM_ABI result_type operator()(_URNG& __g, const param_type& __p); + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type operator()(_URNG& __g, const param_type& __p); // property functions - _LIBCPP_HIDE_FROM_ABI result_type a() const { return __p_.a(); } - _LIBCPP_HIDE_FROM_ABI result_type b() const { return __p_.b(); } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type a() const { return __p_.a(); } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type b() const { return __p_.b(); } - _LIBCPP_HIDE_FROM_ABI param_type param() const { return __p_; } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI param_type param() const { return __p_; } _LIBCPP_HIDE_FROM_ABI void param(const param_type& __p) { __p_ = __p; } - _LIBCPP_HIDE_FROM_ABI result_type min() const { return a(); } - _LIBCPP_HIDE_FROM_ABI result_type max() const { return b(); } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type min() const { return a(); } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type max() const { return b(); } _LIBCPP_HIDE_FROM_ABI friend bool operator==(const uniform_int_distribution& __x, const uniform_int_distribution& __y) { diff --git a/lib/libcxx/include/__random/uniform_random_bit_generator.h b/lib/libcxx/include/__random/uniform_random_bit_generator.h index 75ffc27f9fcd854a5027bd173e0cd78362599999..738a293f1e7e59f9075322444561c3030eef0851 100644 --- a/lib/libcxx/include/__random/uniform_random_bit_generator.h +++ b/lib/libcxx/include/__random/uniform_random_bit_generator.h @@ -23,10 +23,10 @@ _LIBCPP_PUSH_MACROS #include <__undef_macros> -_LIBCPP_BEGIN_NAMESPACE_STD - #if _LIBCPP_STD_VER >= 20 +_LIBCPP_BEGIN_NAMESPACE_STD + // [rand.req.urng] template concept uniform_random_bit_generator = invocable<_Gen&> && unsigned_integral> && requires { @@ -35,10 +35,10 @@ concept uniform_random_bit_generator = invocable<_Gen&> && unsigned_integral::value; }; -#endif // _LIBCPP_STD_VER >= 20 - _LIBCPP_END_NAMESPACE_STD +#endif // _LIBCPP_STD_VER >= 20 + _LIBCPP_POP_MACROS #endif // _LIBCPP___RANDOM_UNIFORM_RANDOM_BIT_GENERATOR_H diff --git a/lib/libcxx/include/__random/uniform_real_distribution.h b/lib/libcxx/include/__random/uniform_real_distribution.h index 9407827b2a5d57563913ff22682954b50d83372c..f648bc0b8e076d336014707ae08bb5febdb5de59 100644 --- a/lib/libcxx/include/__random/uniform_real_distribution.h +++ b/lib/libcxx/include/__random/uniform_real_distribution.h @@ -42,8 +42,8 @@ public: _LIBCPP_HIDE_FROM_ABI explicit param_type(result_type __a = 0, result_type __b = 1) : __a_(__a), __b_(__b) {} - _LIBCPP_HIDE_FROM_ABI result_type a() const { return __a_; } - _LIBCPP_HIDE_FROM_ABI result_type b() const { return __b_; } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type a() const { return __a_; } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type b() const { return __b_; } friend _LIBCPP_HIDE_FROM_ABI bool operator==(const param_type& __x, const param_type& __y) { return __x.__a_ == __y.__a_ && __x.__b_ == __y.__b_; @@ -69,21 +69,21 @@ public: // generating functions template - _LIBCPP_HIDE_FROM_ABI result_type operator()(_URNG& __g) { + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type operator()(_URNG& __g) { return (*this)(__g, __p_); } template - _LIBCPP_HIDE_FROM_ABI result_type operator()(_URNG& __g, const param_type& __p); + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type operator()(_URNG& __g, const param_type& __p); // property functions - _LIBCPP_HIDE_FROM_ABI result_type a() const { return __p_.a(); } - _LIBCPP_HIDE_FROM_ABI result_type b() const { return __p_.b(); } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type a() const { return __p_.a(); } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type b() const { return __p_.b(); } - _LIBCPP_HIDE_FROM_ABI param_type param() const { return __p_; } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI param_type param() const { return __p_; } _LIBCPP_HIDE_FROM_ABI void param(const param_type& __p) { __p_ = __p; } - _LIBCPP_HIDE_FROM_ABI result_type min() const { return a(); } - _LIBCPP_HIDE_FROM_ABI result_type max() const { return b(); } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type min() const { return a(); } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type max() const { return b(); } friend _LIBCPP_HIDE_FROM_ABI bool operator==(const uniform_real_distribution& __x, const uniform_real_distribution& __y) { diff --git a/lib/libcxx/include/__random/weibull_distribution.h b/lib/libcxx/include/__random/weibull_distribution.h index 1d65b09ca663fc141bf414806f021a8dc7b579c4..333699cac1be4756d7c98d4b55a1a623c67c6c84 100644 --- a/lib/libcxx/include/__random/weibull_distribution.h +++ b/lib/libcxx/include/__random/weibull_distribution.h @@ -43,8 +43,8 @@ public: _LIBCPP_HIDE_FROM_ABI explicit param_type(result_type __a = 1, result_type __b = 1) : __a_(__a), __b_(__b) {} - _LIBCPP_HIDE_FROM_ABI result_type a() const { return __a_; } - _LIBCPP_HIDE_FROM_ABI result_type b() const { return __b_; } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type a() const { return __a_; } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type b() const { return __b_; } friend _LIBCPP_HIDE_FROM_ABI bool operator==(const param_type& __x, const param_type& __y) { return __x.__a_ == __y.__a_ && __x.__b_ == __y.__b_; @@ -70,23 +70,23 @@ public: // generating functions template - _LIBCPP_HIDE_FROM_ABI result_type operator()(_URNG& __g) { + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type operator()(_URNG& __g) { return (*this)(__g, __p_); } template - _LIBCPP_HIDE_FROM_ABI result_type operator()(_URNG& __g, const param_type& __p) { + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type operator()(_URNG& __g, const param_type& __p) { return __p.b() * std::pow(exponential_distribution()(__g), 1 / __p.a()); } // property functions - _LIBCPP_HIDE_FROM_ABI result_type a() const { return __p_.a(); } - _LIBCPP_HIDE_FROM_ABI result_type b() const { return __p_.b(); } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type a() const { return __p_.a(); } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type b() const { return __p_.b(); } - _LIBCPP_HIDE_FROM_ABI param_type param() const { return __p_; } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI param_type param() const { return __p_; } _LIBCPP_HIDE_FROM_ABI void param(const param_type& __p) { __p_ = __p; } - _LIBCPP_HIDE_FROM_ABI result_type min() const { return 0; } - _LIBCPP_HIDE_FROM_ABI result_type max() const { return numeric_limits::infinity(); } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type min() const { return 0; } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI result_type max() const { return numeric_limits::infinity(); } friend _LIBCPP_HIDE_FROM_ABI bool operator==(const weibull_distribution& __x, const weibull_distribution& __y) { return __x.__p_ == __y.__p_; diff --git a/lib/libcxx/include/__ranges/access.h b/lib/libcxx/include/__ranges/access.h index bbacef3eae6be16880900bc6592d239fee52c729..28555ef6ba0d9d8fddfb9624295b2a998e947bf8 100644 --- a/lib/libcxx/include/__ranges/access.h +++ b/lib/libcxx/include/__ranges/access.h @@ -27,10 +27,10 @@ # pragma GCC system_header #endif -_LIBCPP_BEGIN_NAMESPACE_STD - #if _LIBCPP_STD_VER >= 20 +_LIBCPP_BEGIN_NAMESPACE_STD + namespace ranges { template concept __can_borrow = is_lvalue_reference_v<_Tp> || enable_borrowed_range>; @@ -203,8 +203,8 @@ inline constexpr auto cend = __cend::__fn{}; } // namespace __cpo } // namespace ranges -#endif // _LIBCPP_STD_VER >= 20 - _LIBCPP_END_NAMESPACE_STD +#endif // _LIBCPP_STD_VER >= 20 + #endif // _LIBCPP___RANGES_ACCESS_H diff --git a/lib/libcxx/include/__ranges/adjacent_transform_view.h b/lib/libcxx/include/__ranges/adjacent_transform_view.h index 11b1176824fa357e63d69314ca90e77a65b05cf7..e0c20b7a95513c16057d96dcdf359c538b585e88 100644 --- a/lib/libcxx/include/__ranges/adjacent_transform_view.h +++ b/lib/libcxx/include/__ranges/adjacent_transform_view.h @@ -19,6 +19,7 @@ #include <__concepts/derived_from.h> #include <__concepts/equality_comparable.h> #include <__concepts/invocable.h> +#include <__concepts/referenceable.h> #include <__cstddef/size_t.h> #include <__functional/bind_back.h> #include <__functional/invoke.h> @@ -45,7 +46,6 @@ #include <__type_traits/decay.h> #include <__type_traits/is_nothrow_constructible.h> #include <__type_traits/is_object.h> -#include <__type_traits/is_referenceable.h> #include <__type_traits/make_unsigned.h> #include <__type_traits/maybe_const.h> #include <__utility/declval.h> @@ -105,22 +105,22 @@ public: _LIBCPP_HIDE_FROM_ABI constexpr explicit adjacent_transform_view(_View __base, _Fn __fun) : __inner_(std::move(__base)), __fun_(std::in_place, std::move(__fun)) {} - _LIBCPP_HIDE_FROM_ABI constexpr _View base() const& + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _View base() const& requires copy_constructible<_View> { return __inner_.base(); } - _LIBCPP_HIDE_FROM_ABI constexpr _View base() && { return std::move(__inner_).base(); } + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _View base() && { return std::move(__inner_).base(); } - _LIBCPP_HIDE_FROM_ABI constexpr auto begin() { return __iterator(*this, __inner_.begin()); } + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto begin() { return __iterator(*this, __inner_.begin()); } - _LIBCPP_HIDE_FROM_ABI constexpr auto begin() const + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto begin() const requires range && regular_invocable<__apply_n, range_reference_t> { return __iterator(*this, __inner_.begin()); } - _LIBCPP_HIDE_FROM_ABI constexpr auto end() { + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto end() { if constexpr (common_range<_InnerView>) { return __iterator(*this, __inner_.end()); } else { @@ -128,7 +128,7 @@ public: } } - _LIBCPP_HIDE_FROM_ABI constexpr auto end() const + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto end() const requires range && regular_invocable<__apply_n, range_reference_t> { if constexpr (common_range) { @@ -138,13 +138,13 @@ public: } } - _LIBCPP_HIDE_FROM_ABI constexpr auto size() + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto size() requires sized_range<_InnerView> { return __inner_.size(); } - _LIBCPP_HIDE_FROM_ABI constexpr auto size() const + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto size() const requires sized_range { return __inner_.size(); @@ -202,7 +202,7 @@ public: requires _Const && convertible_to<__inner_iterator, __inner_iterator> : __parent_(__i.__parent_), __inner_(std::move(__i.__inner_)) {} - _LIBCPP_HIDE_FROM_ABI constexpr decltype(auto) operator*() const + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr decltype(auto) operator*() const noexcept(__noexcept_dereference(make_index_sequence<_Np>{})) { return std::apply( [&](const auto&... __iters) -> decltype(auto) { return std::invoke(*__parent_->__fun_, *__iters...); }, @@ -249,7 +249,7 @@ public: return *this; } - _LIBCPP_HIDE_FROM_ABI constexpr decltype(auto) operator[](difference_type __n) const + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr decltype(auto) operator[](difference_type __n) const requires random_access_range<_Base> { return std::apply( @@ -291,25 +291,26 @@ public: return __x.__inner_ <=> __y.__inner_; } - _LIBCPP_HIDE_FROM_ABI friend constexpr __iterator operator+(const __iterator& __i, difference_type __n) + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI friend constexpr __iterator operator+(const __iterator& __i, difference_type __n) requires random_access_range<_Base> { return __iterator(*__i.__parent_, __i.__inner_ + __n); } - _LIBCPP_HIDE_FROM_ABI friend constexpr __iterator operator+(difference_type __n, const __iterator& __i) + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI friend constexpr __iterator operator+(difference_type __n, const __iterator& __i) requires random_access_range<_Base> { return __iterator(*__i.__parent_, __i.__inner_ + __n); } - _LIBCPP_HIDE_FROM_ABI friend constexpr __iterator operator-(const __iterator& __i, difference_type __n) + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI friend constexpr __iterator operator-(const __iterator& __i, difference_type __n) requires random_access_range<_Base> { return __iterator(*__i.__parent_, __i.__inner_ - __n); } - _LIBCPP_HIDE_FROM_ABI friend constexpr difference_type operator-(const __iterator& __x, const __iterator& __y) + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI friend constexpr difference_type + operator-(const __iterator& __x, const __iterator& __y) requires sized_sentinel_for<__inner_iterator<_Const>, __inner_iterator<_Const>> { return __x.__inner_ - __y.__inner_; @@ -344,14 +345,14 @@ public: template requires sized_sentinel_for<__inner_sentinel<_Const>, __inner_iterator<_OtherConst>> - _LIBCPP_HIDE_FROM_ABI friend constexpr range_difference_t<__maybe_const<_OtherConst, _InnerView>> + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI friend constexpr range_difference_t<__maybe_const<_OtherConst, _InnerView>> operator-(const __iterator<_OtherConst>& __x, const __sentinel& __y) { return __x.__inner_ - __y.__inner_; } template requires sized_sentinel_for<__inner_sentinel<_Const>, __inner_iterator<_OtherConst>> - _LIBCPP_HIDE_FROM_ABI friend constexpr range_difference_t<__maybe_const<_OtherConst, _InnerView>> + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI friend constexpr range_difference_t<__maybe_const<_OtherConst, _InnerView>> operator-(const __sentinel& __x, const __iterator<_OtherConst>& __y) { return __x.__inner_ - __y.__inner_; } @@ -364,14 +365,14 @@ template struct __fn : __range_adaptor_closure<__fn<_Np>> { template requires(_Np == 0 && forward_range<_Range &&>) - _LIBCPP_HIDE_FROM_ABI static constexpr auto + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static constexpr auto operator()(_Range&&, _Fn&& __fn) noexcept(noexcept(views::zip_transform(std::forward<_Fn>(__fn)))) -> decltype(views::zip_transform(std::forward<_Fn>(__fn))) { return views::zip_transform(std::forward<_Fn>(__fn)); } template - _LIBCPP_HIDE_FROM_ABI static constexpr auto operator()(_Range&& __range, _Fn&& __fn) noexcept( + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static constexpr auto operator()(_Range&& __range, _Fn&& __fn) noexcept( noexcept(adjacent_transform_view, decay_t<_Fn>, _Np>( std::forward<_Range>(__range), std::forward<_Fn>(__fn)))) -> decltype(adjacent_transform_view, decay_t<_Fn>, _Np>( diff --git a/lib/libcxx/include/__ranges/adjacent_view.h b/lib/libcxx/include/__ranges/adjacent_view.h index 40474b85c794ff7dc0b4518d0f9e3a43c56a97b9..ac1366adb4efc23e48be24ea94c2598e3166f03a 100644 --- a/lib/libcxx/include/__ranges/adjacent_view.h +++ b/lib/libcxx/include/__ranges/adjacent_view.h @@ -81,26 +81,26 @@ public: _LIBCPP_HIDE_FROM_ABI constexpr explicit adjacent_view(_View __base) : __base_(std::move(__base)) {} - _LIBCPP_HIDE_FROM_ABI constexpr _View base() const& + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _View base() const& requires copy_constructible<_View> { return __base_; } - _LIBCPP_HIDE_FROM_ABI constexpr _View base() && { return std::move(__base_); } - _LIBCPP_HIDE_FROM_ABI constexpr auto begin() + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _View base() && { return std::move(__base_); } + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto begin() requires(!__simple_view<_View>) { return __iterator(ranges::begin(__base_), ranges::end(__base_)); } - _LIBCPP_HIDE_FROM_ABI constexpr auto begin() const + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto begin() const requires range // LWG4482 This is under-constrained. { return __iterator(ranges::begin(__base_), ranges::end(__base_)); } - _LIBCPP_HIDE_FROM_ABI constexpr auto end() + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto end() requires(!__simple_view<_View>) { if constexpr (common_range<_View>) { @@ -110,7 +110,7 @@ public: } } - _LIBCPP_HIDE_FROM_ABI constexpr auto end() const + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto end() const requires range // LWG4482 This is under-constrained. { if constexpr (common_range) { @@ -120,7 +120,7 @@ public: } } - _LIBCPP_HIDE_FROM_ABI constexpr auto size() + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto size() requires sized_range<_View> { using _ST = decltype(ranges::size(__base_)); @@ -130,7 +130,7 @@ public: return static_cast<_ST>(__sz); } - _LIBCPP_HIDE_FROM_ABI constexpr auto size() const + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto size() const requires sized_range { using _ST = decltype(ranges::size(__base_)); @@ -205,7 +205,7 @@ public: requires _Const && convertible_to, iterator_t> : __iterator(std::move(__i), make_index_sequence<_Np>{}) {} - _LIBCPP_HIDE_FROM_ABI constexpr auto operator*() const { + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator*() const { return std::__tuple_transform([](auto& __i) -> decltype(auto) { return *__i; }, __current_); } @@ -257,7 +257,7 @@ public: return *this; } - _LIBCPP_HIDE_FROM_ABI constexpr auto operator[](difference_type __n) const + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator[](difference_type __n) const requires random_access_range<_Base> { return std::__tuple_transform([&](auto& __i) -> decltype(auto) { return __i[__n]; }, __current_); @@ -297,7 +297,7 @@ public: return __x.__current_.back() <=> __y.__current_.back(); } - _LIBCPP_HIDE_FROM_ABI friend constexpr __iterator operator+(const __iterator& __i, difference_type __n) + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI friend constexpr __iterator operator+(const __iterator& __i, difference_type __n) requires random_access_range<_Base> { auto __r = __i; @@ -305,13 +305,13 @@ public: return __r; } - _LIBCPP_HIDE_FROM_ABI friend constexpr __iterator operator+(difference_type __n, const __iterator& __i) + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI friend constexpr __iterator operator+(difference_type __n, const __iterator& __i) requires random_access_range<_Base> { return __i + __n; } - _LIBCPP_HIDE_FROM_ABI friend constexpr __iterator operator-(const __iterator& __i, difference_type __n) + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI friend constexpr __iterator operator-(const __iterator& __i, difference_type __n) requires random_access_range<_Base> { auto __r = __i; @@ -319,7 +319,8 @@ public: return __r; } - _LIBCPP_HIDE_FROM_ABI friend constexpr difference_type operator-(const __iterator& __x, const __iterator& __y) + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI friend constexpr difference_type + operator-(const __iterator& __x, const __iterator& __y) requires sized_sentinel_for, iterator_t<_Base>> { return __x.__current_.back() - __y.__current_.back(); @@ -366,14 +367,14 @@ public: template requires sized_sentinel_for, iterator_t<__maybe_const<_OtherConst, _View>>> - _LIBCPP_HIDE_FROM_ABI friend constexpr range_difference_t<__maybe_const<_OtherConst, _View>> + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI friend constexpr range_difference_t<__maybe_const<_OtherConst, _View>> operator-(const __iterator<_OtherConst>& __x, const __sentinel& __y) { return __x.__current_.back() - __y.__end_; } template requires sized_sentinel_for, iterator_t<__maybe_const<_OtherConst, _View>>> - _LIBCPP_HIDE_FROM_ABI friend constexpr range_difference_t<__maybe_const<_OtherConst, _View>> + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI friend constexpr range_difference_t<__maybe_const<_OtherConst, _View>> operator-(const __sentinel& __y, const __iterator<_OtherConst>& __x) { return __y.__end_ - __x.__current_.back(); } @@ -389,12 +390,12 @@ template struct __fn : __range_adaptor_closure<__fn<_Np>> { template requires(_Np == 0 && forward_range<_Range &&>) - _LIBCPP_HIDE_FROM_ABI static constexpr auto operator()(_Range&&) noexcept { + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static constexpr auto operator()(_Range&&) noexcept { return empty_view>{}; } template - _LIBCPP_HIDE_FROM_ABI static constexpr auto operator()(_Ranges&& __range) noexcept( + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static constexpr auto operator()(_Ranges&& __range) noexcept( noexcept(adjacent_view, _Np>(std::forward<_Ranges>(__range)))) -> decltype(adjacent_view, _Np>(std::forward<_Ranges>(__range))) { return adjacent_view, _Np>(std::forward<_Ranges>(__range)); diff --git a/lib/libcxx/include/__ranges/all.h b/lib/libcxx/include/__ranges/all.h index 023cee6caa9a2a1d20d99f92c60fb0b84c1a001b..5ee9901cb1584cebd04c4edac99838b86cbb7411 100644 --- a/lib/libcxx/include/__ranges/all.h +++ b/lib/libcxx/include/__ranges/all.h @@ -29,10 +29,10 @@ # pragma GCC system_header #endif -_LIBCPP_BEGIN_NAMESPACE_STD - #if _LIBCPP_STD_VER >= 20 +_LIBCPP_BEGIN_NAMESPACE_STD + namespace ranges::views { namespace __all { @@ -71,8 +71,8 @@ using all_t = decltype(views::all(std::declval<_Range>())); } // namespace ranges::views -#endif // _LIBCPP_STD_VER >= 20 - _LIBCPP_END_NAMESPACE_STD +#endif // _LIBCPP_STD_VER >= 20 + #endif // _LIBCPP___RANGES_ALL_H diff --git a/lib/libcxx/include/__ranges/chunk_by_view.h b/lib/libcxx/include/__ranges/chunk_by_view.h index 8007f76f0c1e68887ccc7abe1d7a43f7d744f544..07824d11e79be63f10b6565689dc416443a8d753 100644 --- a/lib/libcxx/include/__ranges/chunk_by_view.h +++ b/lib/libcxx/include/__ranges/chunk_by_view.h @@ -54,7 +54,7 @@ namespace ranges { template , iterator_t<_View>> _Pred> requires view<_View> && is_object_v<_Pred> -class _LIBCPP_ABI_LLVM18_NO_UNIQUE_ADDRESS chunk_by_view : public view_interface> { +class _LIBCPP_LLVM18_NO_UNIQUE_ADDRESS_ABI_TAG chunk_by_view : public view_interface> { _LIBCPP_NO_UNIQUE_ADDRESS _View __base_ = _View(); _LIBCPP_NO_UNIQUE_ADDRESS __movable_box<_Pred> __pred_; diff --git a/lib/libcxx/include/__ranges/concat_view.h b/lib/libcxx/include/__ranges/concat_view.h new file mode 100644 index 0000000000000000000000000000000000000000..3bbe9db12e0f80068d6d6e42b6329769f008bd5f --- /dev/null +++ b/lib/libcxx/include/__ranges/concat_view.h @@ -0,0 +1,651 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP___RANGES_CONCAT_VIEW_H +#define _LIBCPP___RANGES_CONCAT_VIEW_H + +#include <__assert> +#include <__concepts/common_reference_with.h> +#include <__concepts/constructible.h> +#include <__concepts/convertible_to.h> +#include <__concepts/copyable.h> +#include <__concepts/derived_from.h> +#include <__concepts/equality_comparable.h> +#include <__concepts/swappable.h> +#include <__config> +#include <__iterator/concepts.h> +#include <__iterator/default_sentinel.h> +#include <__iterator/distance.h> +#include <__iterator/incrementable_traits.h> +#include <__iterator/iter_move.h> +#include <__iterator/iter_swap.h> +#include <__iterator/iterator_traits.h> +#include <__iterator/next.h> +#include <__ranges/access.h> +#include <__ranges/all.h> +#include <__ranges/concepts.h> +#include <__ranges/movable_box.h> +#include <__ranges/range_adaptor.h> +#include <__ranges/size.h> +#include <__ranges/view_interface.h> +#include <__tuple/tuple_transform.h> +#include <__type_traits/conditional.h> +#include <__type_traits/decay.h> +#include <__type_traits/is_nothrow_constructible.h> +#include <__type_traits/make_unsigned.h> +#include <__type_traits/maybe_const.h> +#include <__utility/forward.h> +#include <__utility/in_place.h> +#include <__utility/move.h> +#include +#include + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + +_LIBCPP_BEGIN_NAMESPACE_STD + +#if _LIBCPP_STD_VER >= 26 + +namespace ranges { + +# ifdef __cpp_pack_indexing +template +using __extract_last _LIBCPP_NODEBUG = _Tp...[sizeof...(_Tp) - 1]; +# else +template +struct __extract_last_impl : __extract_last_impl<_Tail...> {}; +template +struct __extract_last_impl<_Tp> { + using type _LIBCPP_NODEBUG = _Tp; +}; + +template +using __extract_last _LIBCPP_NODEBUG = __extract_last_impl<_Tp...>::type; +# endif + +template +struct __all_but_first_model_sized_range; + +template +struct __all_but_first_model_sized_range<_Const, _Head, _Tail...> { + static constexpr bool value = (sized_range<__maybe_const<_Const, _Tail>> && ...); +}; + +template +concept __all_random_access = (random_access_range<__maybe_const<_Const, _Views>> && ...); + +template +concept __all_bidirectional = (bidirectional_range<__maybe_const<_Const, _Views>> && ...); + +template +concept __all_forward = (forward_range<__maybe_const<_Const, _Views>> && ...); + +template +struct __all_common_ignore_last { + static constexpr bool value = + common_range<__maybe_const<_Const, _First>> && __all_common_ignore_last<_Const, _Tail...>::value; +}; + +template +struct __all_common_ignore_last<_Const, _Tail> { + static constexpr bool value = true; +}; + +template +concept __concat_is_random_access = + (__all_random_access<_Const, _Rs...>) && (__all_common_ignore_last<_Const, _Rs...>::value); + +template +concept __concat_is_bidirectional = + (__all_bidirectional<_Const, _Rs...>) && (__all_common_ignore_last<_Const, _Rs...>::value); + +template + requires((view<_Views> && ...) && (sizeof...(_Views) > 0) && __concatable<_Views...>) +class concat_view : public view_interface> { + tuple<_Views...> __views_; + + template + class __iterator; + +public: + _LIBCPP_HIDE_FROM_ABI constexpr concat_view() = default; + + _LIBCPP_HIDE_FROM_ABI constexpr explicit concat_view(_Views... __views) : __views_(std::move(__views)...) {} + + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr __iterator begin() + requires(!(__simple_view<_Views> && ...)) + { + __iterator __it(this, in_place_index<0>, ranges::begin(std::get<0>(__views_))); + __it.template __satisfy<0>(); + return __it; + } + + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr __iterator begin() const + requires((range && ...) && __concatable) + { + __iterator __it(this, in_place_index<0>, ranges::begin(std::get<0>(__views_))); + __it.template __satisfy<0>(); + return __it; + } + + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto end() + requires(!(__simple_view<_Views> && ...)) + { + if constexpr (__all_forward && common_range<__maybe_const>>) { + constexpr auto __n = sizeof...(_Views); + return __iterator(this, in_place_index<__n - 1>, ranges::end(std::get<__n - 1>(__views_))); + } else { + return default_sentinel; + } + } + + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto end() const + requires((range && ...) && __concatable) + { + if constexpr (__all_forward && common_range<__maybe_const>>) { + constexpr auto __n = sizeof...(_Views); + return __iterator(this, in_place_index<__n - 1>, ranges::end(std::get<__n - 1>(__views_))); + } else { + return default_sentinel; + } + } + + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto size() + requires(sized_range<_Views> && ...) + { + return std::apply( + [](auto... __sizes) { return (make_unsigned_t>(__sizes) + ...); }, + std::__tuple_transform(ranges::size, __views_)); + } + + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto size() const + requires(sized_range && ...) + { + return std::apply( + [](auto... __sizes) { return (make_unsigned_t>(__sizes) + ...); }, + std::__tuple_transform(ranges::size, __views_)); + } +}; + +template +concat_view(_Views&&...) -> concat_view...>; + +template +struct __concat_view_iterator_category {}; + +template + requires __all_forward<_Const, _Views...> +struct __concat_view_iterator_category<_Const, _Views...> { +private: + constexpr static bool __derive_pack_random_iterator = + (derived_from>>::iterator_category, + random_access_iterator_tag> && + ...); + constexpr static bool __derive_pack_bidirectional_iterator = + (derived_from>>::iterator_category, + bidirectional_iterator_tag> && + ...); + constexpr static bool __derive_pack_forward_iterator = + (derived_from>>::iterator_category, + forward_iterator_tag> && + ...); + +public: + using iterator_category = + _If...>>, + input_iterator_tag, + _If<__derive_pack_random_iterator, + random_access_iterator_tag, + _If<__derive_pack_bidirectional_iterator, + bidirectional_iterator_tag, + _If<__derive_pack_forward_iterator, forward_iterator_tag, input_iterator_tag > > > >; +}; + +template + requires((view<_Views> && ...) && (sizeof...(_Views) > 0) && __concatable<_Views...>) +template +class concat_view<_Views...>::__iterator : public __concat_view_iterator_category<_Const, _Views...> { +public: + using iterator_concept = + _If<__concat_is_random_access<_Const, _Views...>, + random_access_iterator_tag, + _If<__concat_is_bidirectional<_Const, _Views...>, + bidirectional_iterator_tag, + _If< __all_forward<_Const, _Views...>, forward_iterator_tag, input_iterator_tag > > >; + using value_type = __concat_value_t<__maybe_const<_Const, _Views>...>; + using difference_type = common_type_t>...>; + +private: + using __base_iter _LIBCPP_NODEBUG = variant>...>; + __base_iter __it_; + __maybe_const<_Const, concat_view>* __parent_ = nullptr; + + template + _LIBCPP_HIDE_FROM_ABI constexpr void __satisfy() { + if constexpr (_Idx < (sizeof...(_Views) - 1)) { + if (std::get<_Idx>(__it_) == ranges::end(std::get<_Idx>(__parent_->__views_))) { + __it_.template emplace<_Idx + 1>(ranges::begin(std::get<_Idx + 1>(__parent_->__views_))); + __satisfy<_Idx + 1>(); + } + } + } + + template + _LIBCPP_HIDE_FROM_ABI constexpr void __prev() { + if constexpr (_Idx == 0) { + --std::get<0>(__it_); + } else { + if (std::get<_Idx>(__it_) == ranges::begin(std::get<_Idx>(__parent_->__views_))) { + __it_.template emplace<_Idx - 1>(ranges::end(std::get<_Idx - 1>(__parent_->__views_))); + __prev<_Idx - 1>(); + } else { + --std::get<_Idx>(__it_); + } + } + } + + template + _LIBCPP_HIDE_FROM_ABI constexpr void __advance_fwd(difference_type __offset, difference_type __steps) { + using __underlying_diff_type = iter_difference_t>; + if constexpr (_Idx == sizeof...(_Views) - 1) { + std::get<_Idx>(__it_) += static_cast<__underlying_diff_type>(__steps); + } else { + auto __n_size = ranges::distance(std::get<_Idx>(__parent_->__views_)); + if (__offset + __steps < __n_size) { + std::get<_Idx>(__it_) += static_cast<__underlying_diff_type>(__steps); + } else { + __it_.template emplace<_Idx + 1>(ranges::begin(std::get<_Idx + 1>(__parent_->__views_))); + __advance_fwd<_Idx + 1>(0, __offset + __steps - __n_size); + } + } + } + + template + _LIBCPP_HIDE_FROM_ABI constexpr void __advance_bwd(difference_type __offset, difference_type __steps) { + using __underlying_diff_type = iter_difference_t>; + if constexpr (_Idx == 0) { + std::get<_Idx>(__it_) -= static_cast<__underlying_diff_type>(__steps); + } else { + if (__offset >= __steps) { + std::get<_Idx>(__it_) -= static_cast<__underlying_diff_type>(__steps); + } else { + auto __prev_size = ranges::distance(std::get<_Idx - 1>(__parent_->__views_)); + __it_.template emplace<_Idx - 1>(ranges::end(std::get<_Idx - 1>(__parent_->__views_))); + __advance_bwd<_Idx - 1>(__prev_size, __steps - __offset); + } + } + } + + template + _LIBCPP_HIDE_FROM_ABI constexpr auto __invoke_at_index(_Func&& __func) const { + // TODO(GCC 16): Just capture `this` when GCC PR113563 and PR121008 are fixed. + return [&__func, &__view_iter = *this](this auto&& __self) { + if (_Is == __view_iter.__it_.index()) { + return __func.template operator()<_Is>(); + } + if constexpr (_Is + 1 < sizeof...(_Views)) { + return __self.template operator()<_Is + 1>(); + } + __builtin_unreachable(); + }.template operator()<0>(); + } + + template + _LIBCPP_HIDE_FROM_ABI constexpr void __apply_at_index(size_t __index, _Func&& __func, index_sequence<_Is...>) const { + ((__index == _Is ? (static_cast(__func(integral_constant{})), 0) : 0), ...); + } + + template + _LIBCPP_HIDE_FROM_ABI constexpr void __apply_at_index(size_t __index, _Func&& __func) const { + __apply_at_index(__index, std::forward<_Func>(__func), make_index_sequence<_Idx>{}); + } + + template + _LIBCPP_HIDE_FROM_ABI explicit constexpr __iterator(__maybe_const<_Const, concat_view>* __parent, _Args&&... __args) + requires constructible_from<__base_iter, _Args&&...> + : __it_(std::forward<_Args>(__args)...), __parent_(__parent) {} + + friend class concat_view; + friend class __iterator; + +public: + _LIBCPP_HIDE_FROM_ABI __iterator() = default; + + _LIBCPP_HIDE_FROM_ABI constexpr __iterator(__iterator __i) + requires _Const && (convertible_to, iterator_t> && ...) + : __it_([&__src = __i.__it_](size_t __idx, index_sequence<_Indices...>) -> __base_iter { + _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS( + !__src.valueless_by_exception(), "Trying to convert from a valueless iterator of concat_view."); + using __src_lref = decltype((__src)); + using __construction_fptr = __base_iter (*)(__src_lref); + static constexpr __construction_fptr __vtable[]{[](__src_lref __src_var) -> __base_iter { + return __base_iter(in_place_index<_Indices>, std::__unchecked_get<_Indices>(std::move(__src_var))); + }...}; + return __vtable[__idx](__src); + }(__i.__it_.index(), make_index_sequence>{})), + __parent_(__i.__parent_) {} + + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr decltype(auto) operator*() const { + _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS( + !__it_.valueless_by_exception(), "Trying to dereference a valueless iterator of concat_view."); + return __variant_detail::__visitation::__variant::__visit_value( + [](auto&& __it) -> __concat_reference_t<__maybe_const<_Const, _Views>...> { return *__it; }, __it_); + } + + _LIBCPP_HIDE_FROM_ABI constexpr __iterator& operator++() { + _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS( + !__it_.valueless_by_exception(), "Trying to increment a valueless iterator of concat_view."); + size_t __active_index = __it_.index(); + __apply_at_index>(__active_index, [&](auto __index_constant) { + constexpr size_t __i = __index_constant.value; + ++std::__unchecked_get<__i>(__it_); + __satisfy<__i>(); + }); + return *this; + } + + _LIBCPP_HIDE_FROM_ABI constexpr void operator++(int) { ++*this; } + + _LIBCPP_HIDE_FROM_ABI constexpr __iterator operator++(int) + requires(__all_forward<_Const, _Views...>) + { + auto __tmp = *this; + ++*this; + return __tmp; + } + + _LIBCPP_HIDE_FROM_ABI constexpr __iterator& operator--() + requires __concat_is_bidirectional<_Const, _Views...> + { + _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS( + !__it_.valueless_by_exception(), "Trying to decrement a valueless iterator of concat_view."); + size_t __active_index = __it_.index(); + __apply_at_index>(__active_index, [&](auto __index_constant) { + constexpr size_t __i = __index_constant.value; + __prev<__i>(); + }); + return *this; + } + + _LIBCPP_HIDE_FROM_ABI constexpr __iterator operator--(int) + requires __concat_is_bidirectional<_Const, _Views...> + { + auto __tmp = *this; + --*this; + return __tmp; + } + + _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(const __iterator& __x, const __iterator& __y) + requires(equality_comparable>> && ...) + { + _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(!__x.__it_.valueless_by_exception() && !__y.__it_.valueless_by_exception(), + "Trying to compare a valueless iterator of concat_view."); + return __x.__it_ == __y.__it_; + } + + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr decltype(auto) operator[](difference_type __n) const + requires __concat_is_random_access<_Const, _Views...> + { + return *((*this) + __n); + } + + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI friend constexpr __iterator operator+(const __iterator& __it, difference_type __n) + requires __concat_is_random_access<_Const, _Views...> + { + auto __temp = __it; + __temp += __n; + return __temp; + } + + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI friend constexpr __iterator operator+(difference_type __n, const __iterator& __it) + requires __concat_is_random_access<_Const, _Views...> + { + return __it + __n; + } + + _LIBCPP_HIDE_FROM_ABI constexpr __iterator& operator+=(difference_type __n) + requires __concat_is_random_access<_Const, _Views...> + { + _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS( + !__it_.valueless_by_exception(), "Trying to increment a valueless iterator of concat_view."); + size_t __active_index = __it_.index(); + if (__n > 0) { + __apply_at_index__views_)>>(__active_index, [&](auto __index_constant) { + constexpr size_t __i = __index_constant.value; + auto& __active_view = std::get<__i>(__parent_->__views_); + difference_type __idx = std::get<__i>(__it_) - ranges::begin(__active_view); + __advance_fwd<__i>(__idx, __n); + }); + + } + + else if (__n < 0) { + __apply_at_index__views_)>>(__active_index, [&](auto __index_constant) { + constexpr size_t __i = __index_constant.value; + auto& __active_view = std::get<__i>(__parent_->__views_); + difference_type __idx = std::get<__i>(__it_) - ranges::begin(__active_view); + __advance_bwd<__i>(__idx, -__n); + }); + } + + return *this; + } + + _LIBCPP_HIDE_FROM_ABI constexpr __iterator& operator-=(difference_type __n) + requires __concat_is_random_access<_Const, _Views...> + { + *this += -__n; + return *this; + } + + _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(const __iterator& __it, default_sentinel_t) { + _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS( + !__it.__it_.valueless_by_exception(), + "Trying to compare a valueless iterator of concat_view with the default sentinel."); + constexpr auto __last_idx = sizeof...(_Views) - 1; + return __it.__it_.index() == __last_idx && + std::__unchecked_get<__last_idx>(__it.__it_) == ranges::end(std::get<__last_idx>(__it.__parent_->__views_)); + } + + _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator<(const __iterator& __x, const __iterator& __y) + requires(__all_random_access<_Const, _Views> && ...) + { + _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(!__x.__it_.valueless_by_exception() && !__y.__it_.valueless_by_exception(), + "Trying to compare a valueless iterator of concat_view."); + return __x.__it_ < __y.__it_; + } + + _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator>(const __iterator& __x, const __iterator& __y) + requires(__all_random_access<_Const, _Views> && ...) + { + _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(!__x.__it_.valueless_by_exception() && !__y.__it_.valueless_by_exception(), + "Trying to compare a valueless iterator of concat_view."); + return __x.__it_ > __y.__it_; + } + + _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator<=(const __iterator& __x, const __iterator& __y) + requires(__all_random_access<_Const, _Views> && ...) + { + _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(!__x.__it_.valueless_by_exception() && !__y.__it_.valueless_by_exception(), + "Trying to compare a valueless iterator of concat_view."); + return __x.__it_ <= __y.__it_; + } + + _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator>=(const __iterator& __x, const __iterator& __y) + requires(__all_random_access<_Const, _Views> && ...) + { + _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(!__x.__it_.valueless_by_exception() && !__y.__it_.valueless_by_exception(), + "Trying to compare a valueless iterator of concat_view."); + return __x.__it_ >= __y.__it_; + } + + _LIBCPP_HIDE_FROM_ABI friend constexpr auto operator<=>(const __iterator& __x, const __iterator& __y) + requires((__all_random_access<_Const, _Views> && ...) && + (three_way_comparable>> && ...)) + { + _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(!__x.__it_.valueless_by_exception() && !__y.__it_.valueless_by_exception(), + "Trying to compare a valueless iterator of concat_view."); + return __x.__it_ <=> __y.__it_; + } + + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI friend constexpr decltype(auto) iter_move(const __iterator& __it) noexcept( + + ((is_nothrow_invocable_v< decltype(ranges::iter_move), const iterator_t<__maybe_const<_Const, _Views>>& > && + is_nothrow_convertible_v< range_rvalue_reference_t<__maybe_const<_Const, _Views>>, + __concat_rvalue_reference_t<__maybe_const<_Const, _Views>...> >) && + ...)) + + { + _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS( + !__it.__it_.valueless_by_exception(), "Trying to apply iter_move to a valueless iterator of concat_view."); + return __variant_detail::__visitation::__variant::__visit_value( + [](const auto& __i) -> __concat_rvalue_reference_t<__maybe_const<_Const, _Views>...> { + return ranges::iter_move(__i); + }, + __it.__it_); + } + + _LIBCPP_HIDE_FROM_ABI friend constexpr void iter_swap(const __iterator& __x, const __iterator& __y) + + noexcept((noexcept(ranges::swap(*__x, *__y))) && + (noexcept(ranges::iter_swap(std::declval>>(), + std::declval>>())) && + ...)) + + requires swappable_with, iter_reference_t<__iterator>> && + (... && indirectly_swappable>>) + { + _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS( + !__x.__it_.valueless_by_exception() && !__y.__it_.valueless_by_exception(), + "Trying to swap iterators of concat_view where at least one iterator is valueless."); + __variant_detail::__visitation::__variant::__visit_value( + [&](const auto& __it1, const auto& __it2) { + if constexpr (is_same_v) { + ranges::iter_swap(__it1, __it2); + } else { + ranges::swap(*__x, *__y); + } + }, + __x.__it_, + __y.__it_); + } + + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI friend constexpr difference_type + operator-(const __iterator& __x, const __iterator& __y) + requires __concat_is_random_access<_Const, _Views...> + { + _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS( + !__x.__it_.valueless_by_exception() && !__y.__it_.valueless_by_exception(), + "Trying to subtract two iterators of concat_view where at least one iterator is valueless."); + return __x.__invoke_at_index([&]() -> difference_type { + return __y.__invoke_at_index([&]() -> difference_type { + if constexpr (__index_x > __index_y) { + auto __dx = ranges::distance( + ranges::begin(std::get<__index_x>(__x.__parent_->__views_)), std::get<__index_x>(__x.__it_)); + auto __dy = ranges::distance( + std::get<__index_y>(__y.__it_), ranges::end(std::get<__index_y>(__y.__parent_->__views_))); + difference_type __s = [&](this auto&& __self) -> difference_type { + if constexpr (__start < __end) { + return ranges::size(std::get<__start>(__x.__parent_->__views_)) + + __self.template operator()<__start + 1, __end>(); + } + return 0; + }.template operator()<__index_y + 1, __index_x>(); + return __dy + __s + __dx; + } else if constexpr (__index_x < __index_y) { + return -(__y - __x); + } else { + return std::get<__index_x>(__x.__it_) - std::get<__index_y>(__y.__it_); + } + }); + }); + } + + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI friend constexpr __iterator operator-(const __iterator& __it, difference_type __n) + requires __concat_is_random_access<_Const, _Views...> + { + _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS( + !__it.__it_.valueless_by_exception(), "Trying to subtract a valuess iterators of concat_view."); + auto __temp = __it; + __temp -= __n; + return __temp; + } + + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI friend constexpr difference_type + operator-(const __iterator& __x, default_sentinel_t) + requires(sized_sentinel_for>, iterator_t<__maybe_const<_Const, _Views>>> && + ...) && + (__all_but_first_model_sized_range<_Const, _Views...>::value) + { + _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS( + !__x.__it_.valueless_by_exception(), + "Trying to subtract a valuess iterators of concat_view from the default sentinel."); + return __x.__invoke_at_index([&]() -> difference_type { + auto __dx = + ranges::distance(std::get<__index_x>(__x.__it_), ranges::end(std::get<__index_x>(__x.__parent_->__views_))); + difference_type __s = [&](this auto&& __self) -> difference_type { + if constexpr (__start < __end) { + return ranges::size(std::get<__start>(__x.__parent_->__views_)) + + __self.template operator()<__start + 1, __end>(); + } + return 0; + }.template operator()<__index_x + 1, sizeof...(_Views)>(); + return -(__dx + __s); + }); + } + + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI friend constexpr difference_type + operator-(default_sentinel_t, const __iterator& __x) + requires(sized_sentinel_for>, iterator_t<__maybe_const<_Const, _Views>>> && + ...) && + (__all_but_first_model_sized_range<_Const, _Views...>::value) + { + return -(__x - default_sentinel); + } +}; + +namespace views { +namespace __concat { +struct __fn { + template + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static constexpr auto + operator()(_Range&& __range) noexcept(noexcept(views::all((std::forward<_Range>(__range))))) + -> decltype(views::all((std::forward<_Range>(__range)))) { + return views::all(std::forward<_Range>(__range)); + } + + template + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static constexpr auto + operator()(_FirstRange&& __first, _TailRanges&&... __tail) noexcept( + noexcept(concat_view(std::forward<_FirstRange>(__first), std::forward<_TailRanges>(__tail)...))) + -> decltype(concat_view(std::forward<_FirstRange>(__first), std::forward<_TailRanges>(__tail)...)) { + return concat_view(std::forward<_FirstRange>(__first), std::forward<_TailRanges>(__tail)...); + } +}; +} // namespace __concat + +inline namespace __cpo { +inline constexpr auto concat = __concat::__fn{}; +} // namespace __cpo +} // namespace views + +} // namespace ranges + +#endif // _LIBCPP_STD_VER >= 26 + +_LIBCPP_END_NAMESPACE_STD + +_LIBCPP_POP_MACROS + +#endif // _LIBCPP___RANGES_CONCAT_VIEW_H diff --git a/lib/libcxx/include/__ranges/concepts.h b/lib/libcxx/include/__ranges/concepts.h index bf75fe8a6fef49a71387c9cfdc3c9eb212597fa6..e1c855860c50a0d2680f9d17ca20e094b827e8dc 100644 --- a/lib/libcxx/include/__ranges/concepts.h +++ b/lib/libcxx/include/__ranges/concepts.h @@ -39,10 +39,10 @@ # pragma GCC system_header #endif -_LIBCPP_BEGIN_NAMESPACE_STD - #if _LIBCPP_STD_VER >= 20 +_LIBCPP_BEGIN_NAMESPACE_STD + namespace ranges { // [range.range] @@ -175,8 +175,8 @@ concept __concatable = requires { } // namespace ranges -#endif // _LIBCPP_STD_VER >= 20 - _LIBCPP_END_NAMESPACE_STD +#endif // _LIBCPP_STD_VER >= 20 + #endif // _LIBCPP___RANGES_CONCEPTS_H diff --git a/lib/libcxx/include/__ranges/container_compatible_range.h b/lib/libcxx/include/__ranges/container_compatible_range.h index a58f1119885e3e84eb39f4d2bd5aa43d20468bef..ecf46f49232aa7e1f701e68c904369f234b1c0e1 100644 --- a/lib/libcxx/include/__ranges/container_compatible_range.h +++ b/lib/libcxx/include/__ranges/container_compatible_range.h @@ -18,16 +18,16 @@ # pragma GCC system_header #endif -_LIBCPP_BEGIN_NAMESPACE_STD - #if _LIBCPP_STD_VER >= 23 +_LIBCPP_BEGIN_NAMESPACE_STD + template concept _ContainerCompatibleRange = ranges::input_range<_Range> && convertible_to, _Tp>; -#endif // _LIBCPP_STD_VER >= 23 - _LIBCPP_END_NAMESPACE_STD +#endif // _LIBCPP_STD_VER >= 23 + #endif // _LIBCPP___RANGES_CONTAINER_COMPATIBLE_RANGE_H diff --git a/lib/libcxx/include/__ranges/dangling.h b/lib/libcxx/include/__ranges/dangling.h index 613084d5fb9fc120f8ee53cd6c4da256e94956f6..fdd41351add4529c50ce2713c812c148b343daa5 100644 --- a/lib/libcxx/include/__ranges/dangling.h +++ b/lib/libcxx/include/__ranges/dangling.h @@ -19,10 +19,10 @@ # pragma GCC system_header #endif -_LIBCPP_BEGIN_NAMESPACE_STD - #if _LIBCPP_STD_VER >= 20 +_LIBCPP_BEGIN_NAMESPACE_STD + namespace ranges { struct dangling { dangling() = default; @@ -35,8 +35,8 @@ using borrowed_iterator_t = _If, iterator_t<_Rp>, dangling>; // borrowed_subrange_t defined in <__ranges/subrange.h> } // namespace ranges -#endif // _LIBCPP_STD_VER >= 20 - _LIBCPP_END_NAMESPACE_STD +#endif // _LIBCPP_STD_VER >= 20 + #endif // _LIBCPP___RANGES_DANGLING_H diff --git a/lib/libcxx/include/__ranges/data.h b/lib/libcxx/include/__ranges/data.h index 50db3cffeeed8a26ab69e46c76ba6b19d3ce52dd..354a0aa15903e9b0ff3e64d97b2bc75ddebd0f59 100644 --- a/lib/libcxx/include/__ranges/data.h +++ b/lib/libcxx/include/__ranges/data.h @@ -28,10 +28,10 @@ # pragma GCC system_header #endif -_LIBCPP_BEGIN_NAMESPACE_STD - #if _LIBCPP_STD_VER >= 20 +_LIBCPP_BEGIN_NAMESPACE_STD + // [range.prim.data] namespace ranges { @@ -51,12 +51,12 @@ concept __ranges_begin_invocable = !__member_data<_Tp> && __can_borrow<_Tp> && r struct __fn { template <__member_data _Tp> - _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp&& __t) const noexcept(noexcept(__t.data())) { + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp&& __t) const noexcept(noexcept(__t.data())) { return __t.data(); } template <__ranges_begin_invocable _Tp> - _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp&& __t) const + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp&& __t) const noexcept(noexcept(std::to_address(ranges::begin(__t)))) { return std::to_address(ranges::begin(__t)); } @@ -95,8 +95,8 @@ inline constexpr auto cdata = __cdata::__fn{}; } // namespace __cpo } // namespace ranges -#endif // _LIBCPP_STD_VER >= 20 - _LIBCPP_END_NAMESPACE_STD +#endif // _LIBCPP_STD_VER >= 20 + #endif // _LIBCPP___RANGES_DATA_H diff --git a/lib/libcxx/include/__ranges/drop_view.h b/lib/libcxx/include/__ranges/drop_view.h index feb3705d2df6c058da47a1d779d07950da112fcc..e3754e64d536f14a09edc5399992adf279b404b6 100644 --- a/lib/libcxx/include/__ranges/drop_view.h +++ b/lib/libcxx/include/__ranges/drop_view.h @@ -74,8 +74,7 @@ public: requires default_initializable<_View> = default; - _LIBCPP_HIDE_FROM_ABI constexpr _LIBCPP_EXPLICIT_SINCE_CXX23 - drop_view(_View __base, range_difference_t<_View> __count) + _LIBCPP_HIDE_FROM_ABI constexpr explicit drop_view(_View __base, range_difference_t<_View> __count) : __count_(__count), __base_(std::move(__base)) { _LIBCPP_ASSERT_UNCATEGORIZED(__count_ >= 0, "count must be greater than or equal to zero."); } diff --git a/lib/libcxx/include/__ranges/drop_while_view.h b/lib/libcxx/include/__ranges/drop_while_view.h index 1fe4e17f8048b2dd9777b7aa7246bf65d2b710d3..caa24643b477f707321836391200ce6d31445655 100644 --- a/lib/libcxx/include/__ranges/drop_while_view.h +++ b/lib/libcxx/include/__ranges/drop_while_view.h @@ -48,13 +48,13 @@ namespace ranges { template requires input_range<_View> && is_object_v<_Pred> && indirect_unary_predicate> -class _LIBCPP_ABI_LLVM18_NO_UNIQUE_ADDRESS drop_while_view : public view_interface> { +class _LIBCPP_LLVM18_NO_UNIQUE_ADDRESS_ABI_TAG drop_while_view : public view_interface> { public: _LIBCPP_HIDE_FROM_ABI drop_while_view() requires default_initializable<_View> && default_initializable<_Pred> = default; - _LIBCPP_HIDE_FROM_ABI constexpr _LIBCPP_EXPLICIT_SINCE_CXX23 drop_while_view(_View __base, _Pred __pred) + _LIBCPP_HIDE_FROM_ABI constexpr explicit drop_while_view(_View __base, _Pred __pred) : __base_(std::move(__base)), __pred_(std::in_place, std::move(__pred)) {} [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _View base() const& diff --git a/lib/libcxx/include/__ranges/elements_of.h b/lib/libcxx/include/__ranges/elements_of.h index 3f89f49d182aede8996c49176edba83c9011e6c1..de6aa786e6b1de9d489fead439ea795b9e7f01d9 100644 --- a/lib/libcxx/include/__ranges/elements_of.h +++ b/lib/libcxx/include/__ranges/elements_of.h @@ -23,10 +23,10 @@ _LIBCPP_PUSH_MACROS #include <__undef_macros> -_LIBCPP_BEGIN_NAMESPACE_STD - #if _LIBCPP_STD_VER >= 23 +_LIBCPP_BEGIN_NAMESPACE_STD + namespace ranges { template > @@ -40,10 +40,10 @@ elements_of(_Range&&, _Allocator = _Allocator()) -> elements_of<_Range&&, _Alloc } // namespace ranges -#endif // _LIBCPP_STD_VER >= 23 - _LIBCPP_END_NAMESPACE_STD +#endif // _LIBCPP_STD_VER >= 23 + _LIBCPP_POP_MACROS #endif // _LIBCPP___RANGES_ELEMENTS_OF_H diff --git a/lib/libcxx/include/__ranges/elements_view.h b/lib/libcxx/include/__ranges/elements_view.h index b1419f2a1dd913002bd0c299532f42ed835a4cab..33c152bbd03b4f1aea08a1efb8460b09ee687a17 100644 --- a/lib/libcxx/include/__ranges/elements_view.h +++ b/lib/libcxx/include/__ranges/elements_view.h @@ -77,57 +77,57 @@ public: _LIBCPP_HIDE_FROM_ABI constexpr explicit elements_view(_View __base) : __base_(std::move(__base)) {} - _LIBCPP_HIDE_FROM_ABI constexpr _View base() const& + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _View base() const& requires copy_constructible<_View> { return __base_; } - _LIBCPP_HIDE_FROM_ABI constexpr _View base() && { return std::move(__base_); } + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _View base() && { return std::move(__base_); } - _LIBCPP_HIDE_FROM_ABI constexpr auto begin() + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto begin() requires(!__simple_view<_View>) { return __iterator(ranges::begin(__base_)); } - _LIBCPP_HIDE_FROM_ABI constexpr auto begin() const + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto begin() const requires range { return __iterator(ranges::begin(__base_)); } - _LIBCPP_HIDE_FROM_ABI constexpr auto end() + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto end() requires(!__simple_view<_View> && !common_range<_View>) { return __sentinel{ranges::end(__base_)}; } - _LIBCPP_HIDE_FROM_ABI constexpr auto end() + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto end() requires(!__simple_view<_View> && common_range<_View>) { return __iterator{ranges::end(__base_)}; } - _LIBCPP_HIDE_FROM_ABI constexpr auto end() const + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto end() const requires range { return __sentinel{ranges::end(__base_)}; } - _LIBCPP_HIDE_FROM_ABI constexpr auto end() const + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto end() const requires common_range { return __iterator{ranges::end(__base_)}; } - _LIBCPP_HIDE_FROM_ABI constexpr auto size() + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto size() requires sized_range<_View> { return ranges::size(__base_); } - _LIBCPP_HIDE_FROM_ABI constexpr auto size() const + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto size() const requires sized_range { return ranges::size(__base_); @@ -211,11 +211,11 @@ public: requires _Const && convertible_to, iterator_t<_Base>> : __current_(std::move(__i.__current_)) {} - _LIBCPP_HIDE_FROM_ABI constexpr const iterator_t<_Base>& base() const& noexcept { return __current_; } + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr const iterator_t<_Base>& base() const& noexcept { return __current_; } - _LIBCPP_HIDE_FROM_ABI constexpr iterator_t<_Base> base() && { return std::move(__current_); } + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr iterator_t<_Base> base() && { return std::move(__current_); } - _LIBCPP_HIDE_FROM_ABI constexpr decltype(auto) operator*() const { return __get_element(__current_); } + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr decltype(auto) operator*() const { return __get_element(__current_); } _LIBCPP_HIDE_FROM_ABI constexpr __iterator& operator++() { ++__current_; @@ -261,7 +261,7 @@ public: return *this; } - _LIBCPP_HIDE_FROM_ABI constexpr decltype(auto) operator[](difference_type __n) const + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr decltype(auto) operator[](difference_type __n) const requires random_access_range<_Base> { return __get_element(__current_ + __n); @@ -303,25 +303,26 @@ public: return __x.__current_ <=> __y.__current_; } - _LIBCPP_HIDE_FROM_ABI friend constexpr __iterator operator+(const __iterator& __x, difference_type __y) + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI friend constexpr __iterator operator+(const __iterator& __x, difference_type __y) requires random_access_range<_Base> { return __iterator{__x} += __y; } - _LIBCPP_HIDE_FROM_ABI friend constexpr __iterator operator+(difference_type __x, const __iterator& __y) + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI friend constexpr __iterator operator+(difference_type __x, const __iterator& __y) requires random_access_range<_Base> { return __y + __x; } - _LIBCPP_HIDE_FROM_ABI friend constexpr __iterator operator-(const __iterator& __x, difference_type __y) + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI friend constexpr __iterator operator-(const __iterator& __x, difference_type __y) requires random_access_range<_Base> { return __iterator{__x} -= __y; } - _LIBCPP_HIDE_FROM_ABI friend constexpr difference_type operator-(const __iterator& __x, const __iterator& __y) + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI friend constexpr difference_type + operator-(const __iterator& __x, const __iterator& __y) requires sized_sentinel_for, iterator_t<_Base>> { return __x.__current_ - __y.__current_; @@ -365,14 +366,14 @@ public: template requires sized_sentinel_for, iterator_t<__maybe_const<_OtherConst, _View>>> - _LIBCPP_HIDE_FROM_ABI friend constexpr range_difference_t<__maybe_const<_OtherConst, _View>> + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI friend constexpr range_difference_t<__maybe_const<_OtherConst, _View>> operator-(const __iterator<_OtherConst>& __x, const __sentinel& __y) { return __get_current(__x) - __y.__end_; } template requires sized_sentinel_for, iterator_t<__maybe_const<_OtherConst, _View>>> - _LIBCPP_HIDE_FROM_ABI friend constexpr range_difference_t<__maybe_const<_OtherConst, _View>> + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI friend constexpr range_difference_t<__maybe_const<_OtherConst, _View>> operator-(const __sentinel& __x, const __iterator<_OtherConst>& __y) { return __x.__end_ - __get_current(__y); } diff --git a/lib/libcxx/include/__ranges/empty.h b/lib/libcxx/include/__ranges/empty.h index 5c1004042aba5165cd1b94f5879ee3d54603c5b0..f2f12329d224c4e34651baa824625d6353993b83 100644 --- a/lib/libcxx/include/__ranges/empty.h +++ b/lib/libcxx/include/__ranges/empty.h @@ -20,10 +20,10 @@ # pragma GCC system_header #endif -_LIBCPP_BEGIN_NAMESPACE_STD - #if _LIBCPP_STD_VER >= 20 +_LIBCPP_BEGIN_NAMESPACE_STD + // [range.prim.empty] namespace ranges { @@ -64,8 +64,8 @@ inline constexpr auto empty = __empty::__fn{}; } // namespace __cpo } // namespace ranges -#endif // _LIBCPP_STD_VER >= 20 - _LIBCPP_END_NAMESPACE_STD +#endif // _LIBCPP_STD_VER >= 20 + #endif // _LIBCPP___RANGES_EMPTY_H diff --git a/lib/libcxx/include/__ranges/enable_borrowed_range.h b/lib/libcxx/include/__ranges/enable_borrowed_range.h index 1d068335e20af2ce3c5aa202cb9abcf6548b5009..70eb4e87c8a6ac609589113c712010baa2ccd53b 100644 --- a/lib/libcxx/include/__ranges/enable_borrowed_range.h +++ b/lib/libcxx/include/__ranges/enable_borrowed_range.h @@ -20,10 +20,10 @@ # pragma GCC system_header #endif -_LIBCPP_BEGIN_NAMESPACE_STD - #if _LIBCPP_STD_VER >= 20 +_LIBCPP_BEGIN_NAMESPACE_STD + namespace ranges { // [range.range], ranges @@ -33,8 +33,8 @@ inline constexpr bool enable_borrowed_range = false; } // namespace ranges -#endif // _LIBCPP_STD_VER >= 20 - _LIBCPP_END_NAMESPACE_STD +#endif // _LIBCPP_STD_VER >= 20 + #endif // _LIBCPP___RANGES_ENABLE_BORROWED_RANGE_H diff --git a/lib/libcxx/include/__ranges/enable_view.h b/lib/libcxx/include/__ranges/enable_view.h index 6dee6ea3fa3d21af08484fed6254755e86cb1236..2c58cb6293d2b101cf2154fe69ff3ab4f2e03abc 100644 --- a/lib/libcxx/include/__ranges/enable_view.h +++ b/lib/libcxx/include/__ranges/enable_view.h @@ -20,10 +20,10 @@ # pragma GCC system_header #endif -_LIBCPP_BEGIN_NAMESPACE_STD - #if _LIBCPP_STD_VER >= 20 +_LIBCPP_BEGIN_NAMESPACE_STD + namespace ranges { struct view_base {}; @@ -43,8 +43,8 @@ inline constexpr bool enable_view = derived_from<_Tp, view_base> || requires { } // namespace ranges -#endif // _LIBCPP_STD_VER >= 20 - _LIBCPP_END_NAMESPACE_STD +#endif // _LIBCPP_STD_VER >= 20 + #endif // _LIBCPP___RANGES_ENABLE_VIEW_H diff --git a/lib/libcxx/include/__ranges/enumerate_view.h b/lib/libcxx/include/__ranges/enumerate_view.h new file mode 100644 index 0000000000000000000000000000000000000000..bb7696897af004b49c8ccda8324be89115272e52 --- /dev/null +++ b/lib/libcxx/include/__ranges/enumerate_view.h @@ -0,0 +1,350 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP___RANGES_ENUMERATE_VIEW_H +#define _LIBCPP___RANGES_ENUMERATE_VIEW_H + +#include <__concepts/constructible.h> +#include <__concepts/convertible_to.h> +#include <__config> +#include <__iterator/concepts.h> +#include <__iterator/distance.h> +#include <__iterator/iter_move.h> +#include <__iterator/iterator_traits.h> +#include <__ranges/access.h> +#include <__ranges/all.h> +#include <__ranges/concepts.h> +#include <__ranges/enable_borrowed_range.h> +#include <__ranges/range_adaptor.h> +#include <__ranges/size.h> +#include <__ranges/view_interface.h> +#include <__type_traits/maybe_const.h> +#include <__utility/forward.h> +#include <__utility/move.h> +#include + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + +_LIBCPP_BEGIN_NAMESPACE_STD + +#if _LIBCPP_STD_VER >= 23 + +namespace ranges { + +// [concept.object] + +template +concept __range_with_movable_references = + input_range<_Rp> && std::move_constructible> && + std::move_constructible>; + +// [range.enumerate.view] + +template + requires __range_with_movable_references<_View> +class enumerate_view : public view_interface> { + _View __base_ = _View(); + + // [range.enumerate.iterator] + template + class __iterator; + + // [range.enumerate.sentinel] + template + class __sentinel; + +public: + _LIBCPP_HIDE_FROM_ABI constexpr enumerate_view() + requires default_initializable<_View> + = default; + _LIBCPP_HIDE_FROM_ABI constexpr explicit enumerate_view(_View __base) : __base_(std::move(__base)) {} + + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto begin() + requires(!__simple_view<_View>) + { + return __iterator(ranges::begin(__base_), 0); + } + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto begin() const + requires __range_with_movable_references + { + return __iterator(ranges::begin(__base_), 0); + } + + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto end() + requires(!__simple_view<_View>) + { + if constexpr (forward_range<_View> && common_range<_View> && sized_range<_View>) + return __iterator(ranges::end(__base_), ranges::distance(__base_)); + else + return __sentinel(ranges::end(__base_)); + } + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto end() const + requires __range_with_movable_references + { + if constexpr (forward_range<_View> && common_range && sized_range) + return __iterator(ranges::end(__base_), ranges::distance(__base_)); + else + return __sentinel(ranges::end(__base_)); + } + + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto size() + requires sized_range<_View> + { + return ranges::size(__base_); + } + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto size() const + requires sized_range + { + return ranges::size(__base_); + } + + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _View base() const& + requires copy_constructible<_View> + { + return __base_; + } + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _View base() && { return std::move(__base_); } +}; + +template +enumerate_view(_Range&&) -> enumerate_view>; + +// [range.enumerate.iterator] + +template + requires __range_with_movable_references<_View> +template +class enumerate_view<_View>::__iterator { + using _Base _LIBCPP_NODEBUG = __maybe_const<_Const, _View>; + + static consteval auto __get_iterator_concept() { + if constexpr (random_access_range<_Base>) { + return random_access_iterator_tag{}; + } else if constexpr (bidirectional_range<_Base>) { + return bidirectional_iterator_tag{}; + } else if constexpr (forward_range<_Base>) { + return forward_iterator_tag{}; + } else { + return input_iterator_tag{}; + } + } + + friend class enumerate_view<_View>; + +public: + using iterator_category = input_iterator_tag; + using iterator_concept = decltype(__get_iterator_concept()); + using difference_type = range_difference_t<_Base>; + using value_type = tuple>; + +private: + using __reference_type _LIBCPP_NODEBUG = tuple>; + + iterator_t<_Base> __current_ = iterator_t<_Base>(); + difference_type __pos_ = 0; + + _LIBCPP_HIDE_FROM_ABI constexpr explicit __iterator(iterator_t<_Base> __current, difference_type __pos) + : __current_(std::move(__current)), __pos_(__pos) {} + +public: + _LIBCPP_HIDE_FROM_ABI __iterator() + requires default_initializable> + = default; + + _LIBCPP_HIDE_FROM_ABI constexpr __iterator(__iterator __i) + requires _Const && convertible_to, iterator_t<_Base>> + : __current_(std::move(__i.__current_)), __pos_(__i.__pos_) {} + + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr const iterator_t<_Base>& base() const& noexcept { return __current_; } + + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr iterator_t<_Base> base() && { return std::move(__current_); } + + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr difference_type index() const noexcept { return __pos_; } + + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator*() const { return __reference_type(__pos_, *__current_); } + + _LIBCPP_HIDE_FROM_ABI constexpr __iterator& operator++() { + ++__current_; + ++__pos_; + return *this; + } + + _LIBCPP_HIDE_FROM_ABI constexpr void operator++(int) { return ++*this; } + + _LIBCPP_HIDE_FROM_ABI constexpr __iterator operator++(int) + requires forward_range<_Base> + { + auto __temp = *this; + ++*this; + return __temp; + } + + _LIBCPP_HIDE_FROM_ABI constexpr __iterator& operator--() + requires bidirectional_range<_Base> + { + --__current_; + --__pos_; + return *this; + } + + _LIBCPP_HIDE_FROM_ABI constexpr __iterator operator--(int) + requires bidirectional_range<_Base> + { + auto __temp = *this; + --*this; + return *__temp; + } + + _LIBCPP_HIDE_FROM_ABI constexpr __iterator& operator+=(difference_type __n) + requires random_access_range<_Base> + { + __current_ += __n; + __pos_ += __n; + return *this; + } + + _LIBCPP_HIDE_FROM_ABI constexpr __iterator& operator-=(difference_type __n) + requires random_access_range<_Base> + { + __current_ -= __n; + __pos_ -= __n; + return *this; + } + + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator[](difference_type __n) const + requires random_access_range<_Base> + { + return __reference_type(__pos_ + __n, __current_[__n]); + } + + _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(const __iterator& __x, const __iterator& __y) noexcept { + return __x.__pos_ == __y.__pos_; + } + + _LIBCPP_HIDE_FROM_ABI friend constexpr strong_ordering + operator<=>(const __iterator& __x, const __iterator& __y) noexcept { + return __x.__pos_ <=> __y.__pos_; + } + + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI friend constexpr __iterator operator+(const __iterator& __i, difference_type __n) + requires random_access_range<_Base> + { + auto __temp = __i; + __temp += __n; + return __temp; + } + + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI friend constexpr __iterator operator+(difference_type __n, const __iterator& __i) + requires random_access_range<_Base> + { + return __i + __n; + } + + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI friend constexpr __iterator operator-(const __iterator& __i, difference_type __n) + requires random_access_range<_Base> + { + auto __temp = __i; + __temp -= __n; + return __temp; + } + + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI friend constexpr difference_type + operator-(const __iterator& __x, const __iterator& __y) noexcept { + return __x.__pos_ - __y.__pos_; + } + + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI friend constexpr auto iter_move(const __iterator& __i) noexcept( + noexcept(ranges::iter_move(__i.__current_)) && is_nothrow_move_constructible_v>) { + return tuple>(__i.__pos_, ranges::iter_move(__i.__current_)); + } +}; + +// [range.enumerate.sentinel] + +template + requires __range_with_movable_references<_View> +template +class enumerate_view<_View>::__sentinel { + using _Base _LIBCPP_NODEBUG = __maybe_const<_Const, _View>; + + sentinel_t<_Base> __end_ = sentinel_t<_Base>(); + + _LIBCPP_HIDE_FROM_ABI constexpr explicit __sentinel(sentinel_t<_Base> __end) : __end_(std::move(__end)) {} + + friend class enumerate_view<_View>; + +public: + _LIBCPP_HIDE_FROM_ABI __sentinel() = default; + + _LIBCPP_HIDE_FROM_ABI constexpr __sentinel(__sentinel __other) + requires _Const && convertible_to, sentinel_t<_Base>> + : __end_(std::move(__other.__end_)) {} + + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr sentinel_t<_Base> base() const { return __end_; } + + template + requires sentinel_for, iterator_t<__maybe_const<_OtherConst, _View>>> + _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(const __iterator<_OtherConst>& __x, const __sentinel& __y) { + return __x.__current_ == __y.__end_; + } + + template + requires sized_sentinel_for, iterator_t<__maybe_const<_OtherConst, _View>>> + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI friend constexpr range_difference_t<__maybe_const<_OtherConst, _View>> + operator-(const __iterator<_OtherConst>& __x, const __sentinel& __y) { + return __x.__current_ - __y.__end_; + } + + template + requires sized_sentinel_for, iterator_t<__maybe_const<_OtherConst, _View>>> + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI friend constexpr range_difference_t<__maybe_const<_OtherConst, _View>> + operator-(const __sentinel& __x, const __iterator<_OtherConst>& __y) { + return __x.__end_ - __y.__current_; + } +}; + +template +constexpr bool enable_borrowed_range> = enable_borrowed_range<_View>; + +namespace views { +namespace __enumerate { + +// [range.enumerate.overview] + +struct __fn : __range_adaptor_closure<__fn> { + template + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static constexpr auto + operator()(_Range&& __range) noexcept(noexcept(enumerate_view>(std::forward<_Range>(__range)))) + -> decltype(/*--------------------------*/ enumerate_view>(std::forward<_Range>(__range))) { + return /*---------------------------------*/ enumerate_view>(std::forward<_Range>(__range)); + } +}; + +} // namespace __enumerate + +inline namespace __cpo { + +inline constexpr auto enumerate = __enumerate::__fn{}; + +} // namespace __cpo +} // namespace views +} // namespace ranges + +#endif // _LIBCPP_STD_VER >= 23 + +_LIBCPP_END_NAMESPACE_STD + +_LIBCPP_POP_MACROS + +#endif // _LIBCPP___RANGES_ENUMERATE_VIEW_H diff --git a/lib/libcxx/include/__ranges/filter_view.h b/lib/libcxx/include/__ranges/filter_view.h index 3ad69ea100931ebe43b403ba2cf2e1f4047635fb..7ec53dac4a84f9928be45e4182cf44d50bc17249 100644 --- a/lib/libcxx/include/__ranges/filter_view.h +++ b/lib/libcxx/include/__ranges/filter_view.h @@ -54,7 +54,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD namespace ranges { template > _Pred> requires view<_View> && is_object_v<_Pred> -class _LIBCPP_ABI_LLVM18_NO_UNIQUE_ADDRESS filter_view : public view_interface> { +class _LIBCPP_LLVM18_NO_UNIQUE_ADDRESS_ABI_TAG filter_view : public view_interface> { _LIBCPP_NO_UNIQUE_ADDRESS _View __base_ = _View(); _LIBCPP_NO_UNIQUE_ADDRESS __movable_box<_Pred> __pred_; @@ -72,7 +72,7 @@ public: requires default_initializable<_View> && default_initializable<_Pred> = default; - _LIBCPP_HIDE_FROM_ABI constexpr _LIBCPP_EXPLICIT_SINCE_CXX23 filter_view(_View __base, _Pred __pred) + _LIBCPP_HIDE_FROM_ABI constexpr explicit filter_view(_View __base, _Pred __pred) : __base_(std::move(__base)), __pred_(in_place, std::move(__pred)) {} template diff --git a/lib/libcxx/include/__ranges/from_range.h b/lib/libcxx/include/__ranges/from_range.h index a6cb9e3d439ebf97d41ae69aa9a58844e4b9778a..c02bddc3d9f9efaa93f381d5d93c5f767db0418b 100644 --- a/lib/libcxx/include/__ranges/from_range.h +++ b/lib/libcxx/include/__ranges/from_range.h @@ -16,18 +16,18 @@ # pragma GCC system_header #endif -_LIBCPP_BEGIN_NAMESPACE_STD - #if _LIBCPP_STD_VER >= 23 +_LIBCPP_BEGIN_NAMESPACE_STD + struct from_range_t { explicit from_range_t() = default; }; inline constexpr from_range_t from_range{}; -#endif // _LIBCPP_STD_VER >= 23 - _LIBCPP_END_NAMESPACE_STD +#endif // _LIBCPP_STD_VER >= 23 + #endif // _LIBCPP___RANGES_FROM_RANGE_H diff --git a/lib/libcxx/include/__ranges/iota_view.h b/lib/libcxx/include/__ranges/iota_view.h index 6b2576ec6b23db0a7fc2b95e06cfdc53802d3340..38e0ccaf2849e24349e62076844bc843001a704d 100644 --- a/lib/libcxx/include/__ranges/iota_view.h +++ b/lib/libcxx/include/__ranges/iota_view.h @@ -316,8 +316,8 @@ public: _LIBCPP_HIDE_FROM_ABI constexpr explicit iota_view(_Start __value) : __value_(std::move(__value)) {} - _LIBCPP_HIDE_FROM_ABI constexpr _LIBCPP_EXPLICIT_SINCE_CXX23 - iota_view(type_identity_t<_Start> __value, type_identity_t<_BoundSentinel> __bound_sentinel) + _LIBCPP_HIDE_FROM_ABI constexpr explicit iota_view(type_identity_t<_Start> __value, + type_identity_t<_BoundSentinel> __bound_sentinel) : __value_(std::move(__value)), __bound_sentinel_(std::move(__bound_sentinel)) { // Validate the precondition if possible. if constexpr (totally_ordered_with<_Start, _BoundSentinel>) { @@ -326,15 +326,15 @@ public: } } - _LIBCPP_HIDE_FROM_ABI constexpr _LIBCPP_EXPLICIT_SINCE_CXX23 iota_view(__iterator __first, __iterator __last) + _LIBCPP_HIDE_FROM_ABI constexpr explicit iota_view(__iterator __first, __iterator __last) requires same_as<_Start, _BoundSentinel> : iota_view(std::move(__first.__value_), std::move(__last.__value_)) {} - _LIBCPP_HIDE_FROM_ABI constexpr _LIBCPP_EXPLICIT_SINCE_CXX23 iota_view(__iterator __first, _BoundSentinel __last) + _LIBCPP_HIDE_FROM_ABI constexpr explicit iota_view(__iterator __first, _BoundSentinel __last) requires same_as<_BoundSentinel, unreachable_sentinel_t> : iota_view(std::move(__first.__value_), std::move(__last)) {} - _LIBCPP_HIDE_FROM_ABI constexpr _LIBCPP_EXPLICIT_SINCE_CXX23 iota_view(__iterator __first, __sentinel __last) + _LIBCPP_HIDE_FROM_ABI constexpr explicit iota_view(__iterator __first, __sentinel __last) requires(!same_as<_Start, _BoundSentinel> && !same_as<_BoundSentinel, unreachable_sentinel_t>) : iota_view(std::move(__first.__value_), std::move(__last.__bound_sentinel_)) {} @@ -357,7 +357,7 @@ public: [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto size() const requires(same_as<_Start, _BoundSentinel> && __advanceable<_Start>) || - (integral<_Start> && integral<_BoundSentinel>) || sized_sentinel_for<_BoundSentinel, _Start> + (__integer_like<_Start> && __integer_like<_BoundSentinel>) || sized_sentinel_for<_BoundSentinel, _Start> { if constexpr (__integer_like<_Start> && __integer_like<_BoundSentinel>) { return (__value_ < 0) diff --git a/lib/libcxx/include/__ranges/istream_view.h b/lib/libcxx/include/__ranges/istream_view.h index ab05cb6ef1fe3833fd61f3fb6f4337ce59a9cc91..7c64463108e1a89136a4c6077734a2dd1bd68f27 100644 --- a/lib/libcxx/include/__ranges/istream_view.h +++ b/lib/libcxx/include/__ranges/istream_view.h @@ -46,12 +46,12 @@ public: _LIBCPP_HIDE_FROM_ABI constexpr explicit basic_istream_view(basic_istream<_CharT, _Traits>& __stream) : __stream_(std::addressof(__stream)) {} - _LIBCPP_HIDE_FROM_ABI constexpr auto begin() { + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto begin() { *__stream_ >> __value_; return __iterator{*this}; } - _LIBCPP_HIDE_FROM_ABI constexpr default_sentinel_t end() const noexcept { return default_sentinel; } + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr default_sentinel_t end() const noexcept { return default_sentinel; } private: basic_istream<_CharT, _Traits>* __stream_; @@ -82,7 +82,7 @@ public: _LIBCPP_HIDE_FROM_ABI void operator++(int) { ++*this; } - _LIBCPP_HIDE_FROM_ABI _Val& operator*() const { return __parent_->__value_; } + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI _Val& operator*() const { return __parent_->__value_; } _LIBCPP_HIDE_FROM_ABI friend bool operator==(const __iterator& __x, default_sentinel_t) { return !*__x.__get_parent_stream(); @@ -113,7 +113,7 @@ struct __fn { template > requires derived_from<_UnCVRef, basic_istream> - _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Up&& __u) const + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Up&& __u) const noexcept(noexcept(basic_istream_view<_Tp, typename _UnCVRef::char_type, typename _UnCVRef::traits_type>(std::forward<_Up>(__u)))) -> decltype( basic_istream_view<_Tp, typename _UnCVRef::char_type, diff --git a/lib/libcxx/include/__ranges/join_view.h b/lib/libcxx/include/__ranges/join_view.h index 364f056d8d2cf0ba3cbf3288c1fb6faa4fe5b8fa..f80b75c839d4a6276aac67f5c0c73695b65f1b66 100644 --- a/lib/libcxx/include/__ranges/join_view.h +++ b/lib/libcxx/include/__ranges/join_view.h @@ -100,15 +100,15 @@ public: _LIBCPP_HIDE_FROM_ABI constexpr explicit join_view(_View __base) : __base_(std::move(__base)) {} - _LIBCPP_HIDE_FROM_ABI constexpr _View base() const& + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _View base() const& requires copy_constructible<_View> { return __base_; } - _LIBCPP_HIDE_FROM_ABI constexpr _View base() && { return std::move(__base_); } + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _View base() && { return std::move(__base_); } - _LIBCPP_HIDE_FROM_ABI constexpr auto begin() { + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto begin() { if constexpr (forward_range<_View>) { constexpr bool __use_const = __simple_view<_View> && is_reference_v>; return __iterator<__use_const>{*this, ranges::begin(__base_)}; @@ -119,14 +119,14 @@ public: } template - _LIBCPP_HIDE_FROM_ABI constexpr auto begin() const + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto begin() const requires forward_range && is_reference_v> && input_range> { return __iterator{*this, ranges::begin(__base_)}; } - _LIBCPP_HIDE_FROM_ABI constexpr auto end() { + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto end() { if constexpr (forward_range<_View> && is_reference_v<_InnerRange> && forward_range<_InnerRange> && common_range<_View> && common_range<_InnerRange>) return __iterator<__simple_view<_View>>{*this, ranges::end(__base_)}; @@ -135,7 +135,7 @@ public: } template - _LIBCPP_HIDE_FROM_ABI constexpr auto end() const + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto end() const requires forward_range && is_reference_v> && input_range> { @@ -276,7 +276,7 @@ public: requires _Const && convertible_to, _Outer> && convertible_to, _Inner> : __outer_(std::move(__i.__outer_)), __inner_(std::move(__i.__inner_)), __parent_(__i.__parent_) {} - _LIBCPP_HIDE_FROM_ABI constexpr decltype(auto) operator*() const { return **__inner_; } + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr decltype(auto) operator*() const { return **__inner_; } _LIBCPP_HIDE_FROM_ABI constexpr _Inner operator->() const requires __has_arrow<_Inner> && copyable<_Inner> @@ -339,7 +339,7 @@ public: return __x.__outer_ == __y.__outer_ && __x.__inner_ == __y.__inner_; } - _LIBCPP_HIDE_FROM_ABI friend constexpr decltype(auto) + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI friend constexpr decltype(auto) iter_move(const __iterator& __i) noexcept(noexcept(ranges::iter_move(*__i.__inner_))) { return ranges::iter_move(*__i.__inner_); } diff --git a/lib/libcxx/include/__ranges/join_with_view.h b/lib/libcxx/include/__ranges/join_with_view.h index 8ed989a6646871e9f5990e7eb879b9e45b29257e..3ce9011762e2614e6cef6d7813800532692d9793 100644 --- a/lib/libcxx/include/__ranges/join_with_view.h +++ b/lib/libcxx/include/__ranges/join_with_view.h @@ -372,7 +372,7 @@ public: return __tmp; } - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(const __iterator& __x, const __iterator& __y) + _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(const __iterator& __x, const __iterator& __y) requires __ref_is_glvalue && forward_range<_Base> && equality_comparable<_InnerIter> { return __x.__outer_it_ == __y.__outer_it_ && __x.__inner_it_ == __y.__inner_it_; @@ -420,8 +420,7 @@ public: template requires sentinel_for, iterator_t<__maybe_const<_OtherConst, _View>>> - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI friend constexpr bool - operator==(const __iterator<_OtherConst>& __x, const __sentinel& __y) { + _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(const __iterator<_OtherConst>& __x, const __sentinel& __y) { return __get_outer_of(__x) == __y.__end_; } }; diff --git a/lib/libcxx/include/__ranges/lazy_split_view.h b/lib/libcxx/include/__ranges/lazy_split_view.h index cca9191d26818cfea09681c59f962e82b3a84fc5..27a9d5e77abf1848b9ef63aec352887e14a0ddc2 100644 --- a/lib/libcxx/include/__ranges/lazy_split_view.h +++ b/lib/libcxx/include/__ranges/lazy_split_view.h @@ -86,23 +86,23 @@ public: requires default_initializable<_View> && default_initializable<_Pattern> = default; - _LIBCPP_HIDE_FROM_ABI constexpr _LIBCPP_EXPLICIT_SINCE_CXX23 lazy_split_view(_View __base, _Pattern __pattern) + _LIBCPP_HIDE_FROM_ABI constexpr explicit lazy_split_view(_View __base, _Pattern __pattern) : __base_(std::move(__base)), __pattern_(std::move(__pattern)) {} template requires constructible_from<_View, views::all_t<_Range>> && constructible_from<_Pattern, single_view>> - _LIBCPP_HIDE_FROM_ABI constexpr _LIBCPP_EXPLICIT_SINCE_CXX23 lazy_split_view(_Range&& __r, range_value_t<_Range> __e) + _LIBCPP_HIDE_FROM_ABI constexpr explicit lazy_split_view(_Range&& __r, range_value_t<_Range> __e) : __base_(views::all(std::forward<_Range>(__r))), __pattern_(views::single(std::move(__e))) {} - _LIBCPP_HIDE_FROM_ABI constexpr _View base() const& + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _View base() const& requires copy_constructible<_View> { return __base_; } - _LIBCPP_HIDE_FROM_ABI constexpr _View base() && { return std::move(__base_); } + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _View base() && { return std::move(__base_); } - _LIBCPP_HIDE_FROM_ABI constexpr auto begin() { + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto begin() { if constexpr (forward_range<_View>) { return __outer_iterator < __simple_view<_View> && __simple_view < _Pattern >> {*this, ranges::begin(__base_)}; } else { @@ -111,19 +111,19 @@ public: } } - _LIBCPP_HIDE_FROM_ABI constexpr auto begin() const + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto begin() const requires forward_range<_View> && forward_range { return __outer_iterator{*this, ranges::begin(__base_)}; } - _LIBCPP_HIDE_FROM_ABI constexpr auto end() + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto end() requires forward_range<_View> && common_range<_View> { return __outer_iterator < __simple_view<_View> && __simple_view < _Pattern >> {*this, ranges::end(__base_)}; } - _LIBCPP_HIDE_FROM_ABI constexpr auto end() const { + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto end() const { if constexpr (forward_range<_View> && forward_range && common_range) { return __outer_iterator{*this, ranges::end(__base_)}; } else { @@ -188,8 +188,10 @@ private: _LIBCPP_HIDE_FROM_ABI value_type() = default; _LIBCPP_HIDE_FROM_ABI constexpr explicit value_type(__outer_iterator __i) : __i_(std::move(__i)) {} - _LIBCPP_HIDE_FROM_ABI constexpr __inner_iterator<_Const> begin() const { return __inner_iterator<_Const>{__i_}; } - _LIBCPP_HIDE_FROM_ABI constexpr default_sentinel_t end() const noexcept { return default_sentinel; } + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr __inner_iterator<_Const> begin() const { + return __inner_iterator<_Const>{__i_}; + } + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr default_sentinel_t end() const noexcept { return default_sentinel; } }; _LIBCPP_HIDE_FROM_ABI __outer_iterator() = default; @@ -206,7 +208,7 @@ private: requires _Const && convertible_to, iterator_t<_Base>> : __parent_(__i.__parent_), __current_(std::move(__i.__current_)) {} - _LIBCPP_HIDE_FROM_ABI constexpr value_type operator*() const { return value_type{*this}; } + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr value_type operator*() const { return value_type{*this}; } _LIBCPP_HIDE_FROM_ABI constexpr __outer_iterator& operator++() { const auto __end = ranges::end(__parent_->__base_); @@ -342,14 +344,16 @@ private: _LIBCPP_HIDE_FROM_ABI constexpr explicit __inner_iterator(__outer_iterator<_Const> __i) : __i_(std::move(__i)) {} - _LIBCPP_HIDE_FROM_ABI constexpr const iterator_t<_Base>& base() const& noexcept { return __i_.__current(); } - _LIBCPP_HIDE_FROM_ABI constexpr iterator_t<_Base> base() && + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr const iterator_t<_Base>& base() const& noexcept { + return __i_.__current(); + } + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr iterator_t<_Base> base() && requires forward_range<_View> { return std::move(__i_.__current()); } - _LIBCPP_HIDE_FROM_ABI constexpr decltype(auto) operator*() const { return *__i_.__current(); } + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr decltype(auto) operator*() const { return *__i_.__current(); } _LIBCPP_HIDE_FROM_ABI constexpr __inner_iterator& operator++() { __incremented_ = true; @@ -385,7 +389,7 @@ private: return __x.__is_done(); } - _LIBCPP_HIDE_FROM_ABI friend constexpr decltype(auto) + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI friend constexpr decltype(auto) iter_move(const __inner_iterator& __i) noexcept(noexcept(ranges::iter_move(__i.__outer_current()))) { return ranges::iter_move(__i.__outer_current()); } diff --git a/lib/libcxx/include/__ranges/owning_view.h b/lib/libcxx/include/__ranges/owning_view.h index 1ab81afee774a0311bf2ce5f96327e003fe002ea..cb6ea660551aef0c8ddeebaa20558a8293cf660b 100644 --- a/lib/libcxx/include/__ranges/owning_view.h +++ b/lib/libcxx/include/__ranges/owning_view.h @@ -30,10 +30,10 @@ _LIBCPP_PUSH_MACROS #include <__undef_macros> -_LIBCPP_BEGIN_NAMESPACE_STD - #if _LIBCPP_STD_VER >= 20 +_LIBCPP_BEGIN_NAMESPACE_STD + namespace ranges { template requires movable<_Rp> && (!__is_std_initializer_list>) @@ -107,10 +107,10 @@ inline constexpr bool enable_borrowed_range> = enable_borrowed_ } // namespace ranges -#endif // _LIBCPP_STD_VER >= 20 - _LIBCPP_END_NAMESPACE_STD +#endif // _LIBCPP_STD_VER >= 20 + _LIBCPP_POP_MACROS #endif // _LIBCPP___RANGES_OWNING_VIEW_H diff --git a/lib/libcxx/include/__ranges/range_adaptor.h b/lib/libcxx/include/__ranges/range_adaptor.h index 4bcb53e1a58465a84afffaabae7a2044b443a4d3..6aac4f15f750677a401efc69a25bedcd821e465a 100644 --- a/lib/libcxx/include/__ranges/range_adaptor.h +++ b/lib/libcxx/include/__ranges/range_adaptor.h @@ -34,10 +34,10 @@ _LIBCPP_PUSH_MACROS #include <__undef_macros> -_LIBCPP_BEGIN_NAMESPACE_STD - #if _LIBCPP_STD_VER >= 20 +_LIBCPP_BEGIN_NAMESPACE_STD + namespace ranges { // CRTP base that one can derive from in order to be considered a range adaptor closure @@ -90,10 +90,10 @@ class _LIBCPP_NO_SPECIALIZATIONS range_adaptor_closure : public __range_adaptor_ } // namespace ranges -#endif // _LIBCPP_STD_VER >= 20 - _LIBCPP_END_NAMESPACE_STD +#endif // _LIBCPP_STD_VER >= 20 + _LIBCPP_POP_MACROS #endif // _LIBCPP___RANGES_RANGE_ADAPTOR_H diff --git a/lib/libcxx/include/__ranges/ref_view.h b/lib/libcxx/include/__ranges/ref_view.h index 109a10cec299e00d1043c88d8f48cd6c8e38b1c2..ea7e9cb3b6da99304d25e806f7088035a8fd3bb5 100644 --- a/lib/libcxx/include/__ranges/ref_view.h +++ b/lib/libcxx/include/__ranges/ref_view.h @@ -32,10 +32,10 @@ # pragma GCC system_header #endif -_LIBCPP_BEGIN_NAMESPACE_STD - #if _LIBCPP_STD_VER >= 20 +_LIBCPP_BEGIN_NAMESPACE_STD + namespace ranges { template requires is_object_v<_Range> @@ -82,8 +82,8 @@ template inline constexpr bool enable_borrowed_range> = true; } // namespace ranges -#endif // _LIBCPP_STD_VER >= 20 - _LIBCPP_END_NAMESPACE_STD +#endif // _LIBCPP_STD_VER >= 20 + #endif // _LIBCPP___RANGES_REF_VIEW_H diff --git a/lib/libcxx/include/__ranges/repeat_view.h b/lib/libcxx/include/__ranges/repeat_view.h index 9192183f4801341d6d8d87c719561920b082d886..48e8f70cc10c67e50d4b552262cbfc9032626163 100644 --- a/lib/libcxx/include/__ranges/repeat_view.h +++ b/lib/libcxx/include/__ranges/repeat_view.h @@ -40,10 +40,10 @@ _LIBCPP_PUSH_MACROS #include <__undef_macros> -_LIBCPP_BEGIN_NAMESPACE_STD - #if _LIBCPP_STD_VER >= 23 +_LIBCPP_BEGIN_NAMESPACE_STD + namespace ranges { template @@ -74,7 +74,7 @@ struct __fn; template requires(is_object_v<_Tp> && same_as<_Tp, remove_cv_t<_Tp>> && (__integer_like_with_usable_difference_type<_Bound> || same_as<_Bound, unreachable_sentinel_t>)) -class _LIBCPP_ABI_LLVM18_NO_UNIQUE_ADDRESS repeat_view : public view_interface> { +class _LIBCPP_LLVM18_NO_UNIQUE_ADDRESS_ABI_TAG repeat_view : public view_interface> { friend struct views::__take::__fn; friend struct views::__drop::__fn; class __iterator; @@ -265,10 +265,10 @@ inline constexpr bool __is_repeat_specialization> = tru } // namespace ranges -#endif // _LIBCPP_STD_VER >= 23 - _LIBCPP_END_NAMESPACE_STD +#endif // _LIBCPP_STD_VER >= 23 + _LIBCPP_POP_MACROS #endif // _LIBCPP___RANGES_REPEAT_VIEW_H diff --git a/lib/libcxx/include/__ranges/reverse_view.h b/lib/libcxx/include/__ranges/reverse_view.h index c36ba77dd8f6d7d0bc21516b271300b9a41badec..b016cc231f2b5887117641d5f87ce8401bcc2931 100644 --- a/lib/libcxx/include/__ranges/reverse_view.h +++ b/lib/libcxx/include/__ranges/reverse_view.h @@ -59,13 +59,13 @@ public: _LIBCPP_HIDE_FROM_ABI constexpr explicit reverse_view(_View __view) : __base_(std::move(__view)) {} - _LIBCPP_HIDE_FROM_ABI constexpr _View base() const& + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _View base() const& requires copy_constructible<_View> { return __base_; } - _LIBCPP_HIDE_FROM_ABI constexpr _View base() && { return std::move(__base_); } + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _View base() && { return std::move(__base_); } _LIBCPP_HIDE_FROM_ABI constexpr reverse_iterator> begin() { if constexpr (_UseCache) @@ -78,35 +78,35 @@ public: return __tmp; } - _LIBCPP_HIDE_FROM_ABI constexpr reverse_iterator> begin() + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr reverse_iterator> begin() requires common_range<_View> { return std::make_reverse_iterator(ranges::end(__base_)); } - _LIBCPP_HIDE_FROM_ABI constexpr auto begin() const + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto begin() const requires common_range { return std::make_reverse_iterator(ranges::end(__base_)); } - _LIBCPP_HIDE_FROM_ABI constexpr reverse_iterator> end() { + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr reverse_iterator> end() { return std::make_reverse_iterator(ranges::begin(__base_)); } - _LIBCPP_HIDE_FROM_ABI constexpr auto end() const + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto end() const requires common_range { return std::make_reverse_iterator(ranges::begin(__base_)); } - _LIBCPP_HIDE_FROM_ABI constexpr auto size() + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto size() requires sized_range<_View> { return ranges::size(__base_); } - _LIBCPP_HIDE_FROM_ABI constexpr auto size() const + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto size() const requires sized_range { return ranges::size(__base_); diff --git a/lib/libcxx/include/__ranges/single_view.h b/lib/libcxx/include/__ranges/single_view.h index 213c507138e6892d4e9ac93b32239f7c5b4d2370..b86a8d6790b012776128927648a7a76b3de4a8b6 100644 --- a/lib/libcxx/include/__ranges/single_view.h +++ b/lib/libcxx/include/__ranges/single_view.h @@ -41,7 +41,7 @@ template template # endif requires is_object_v<_Tp> -class _LIBCPP_ABI_LLVM18_NO_UNIQUE_ADDRESS single_view : public view_interface> { +class _LIBCPP_LLVM18_NO_UNIQUE_ADDRESS_ABI_TAG single_view : public view_interface> { _LIBCPP_NO_UNIQUE_ADDRESS __movable_box<_Tp> __value_; public: diff --git a/lib/libcxx/include/__ranges/size.h b/lib/libcxx/include/__ranges/size.h index 5da3a6ff268e80d5aecc597e3e7d92891aad21f2..2697560ccbfa5dc90adfdedf578365cce83f1adf 100644 --- a/lib/libcxx/include/__ranges/size.h +++ b/lib/libcxx/include/__ranges/size.h @@ -29,10 +29,10 @@ # pragma GCC system_header #endif -_LIBCPP_BEGIN_NAMESPACE_STD - #if _LIBCPP_STD_VER >= 20 +_LIBCPP_BEGIN_NAMESPACE_STD + namespace ranges { template inline constexpr bool disable_sized_range = false; @@ -131,8 +131,8 @@ inline constexpr auto ssize = __ssize::__fn{}; } // namespace __cpo } // namespace ranges -#endif // _LIBCPP_STD_VER >= 20 - _LIBCPP_END_NAMESPACE_STD +#endif // _LIBCPP_STD_VER >= 20 + #endif // _LIBCPP___RANGES_SIZE_H diff --git a/lib/libcxx/include/__ranges/split_view.h b/lib/libcxx/include/__ranges/split_view.h index 2ec908ba4070ecacf3df6166af3131363c981767..10148e0e64764661cc96518524a68ec0a8082dc6 100644 --- a/lib/libcxx/include/__ranges/split_view.h +++ b/lib/libcxx/include/__ranges/split_view.h @@ -78,32 +78,31 @@ public: requires default_initializable<_View> && default_initializable<_Pattern> = default; - _LIBCPP_HIDE_FROM_ABI constexpr _LIBCPP_EXPLICIT_SINCE_CXX23 split_view(_View __base, _Pattern __pattern) + _LIBCPP_HIDE_FROM_ABI constexpr explicit split_view(_View __base, _Pattern __pattern) : __base_(std::move(__base)), __pattern_(std::move((__pattern))) {} template requires constructible_from<_View, views::all_t<_Range>> && constructible_from<_Pattern, single_view>> - _LIBCPP_HIDE_FROM_ABI constexpr _LIBCPP_EXPLICIT_SINCE_CXX23 - split_view(_Range&& __range, range_value_t<_Range> __elem) + _LIBCPP_HIDE_FROM_ABI constexpr explicit split_view(_Range&& __range, range_value_t<_Range> __elem) : __base_(views::all(std::forward<_Range>(__range))), __pattern_(views::single(std::move(__elem))) {} - _LIBCPP_HIDE_FROM_ABI constexpr _View base() const& + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _View base() const& requires copy_constructible<_View> { return __base_; } - _LIBCPP_HIDE_FROM_ABI constexpr _View base() && { return std::move(__base_); } + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _View base() && { return std::move(__base_); } - _LIBCPP_HIDE_FROM_ABI constexpr __iterator begin() { + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr __iterator begin() { if (!__cached_begin_.__has_value()) { __cached_begin_.__emplace(__find_next(ranges::begin(__base_))); } return {*this, ranges::begin(__base_), *__cached_begin_}; } - _LIBCPP_HIDE_FROM_ABI constexpr auto end() { + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto end() { if constexpr (common_range<_View>) { return __iterator{*this, ranges::end(__base_), {}}; } else { @@ -142,9 +141,9 @@ public: split_view<_View, _Pattern>& __parent, iterator_t<_View> __current, subrange> __next) : __parent_(std::addressof(__parent)), __cur_(std::move(__current)), __next_(std::move(__next)) {} - _LIBCPP_HIDE_FROM_ABI constexpr iterator_t<_View> base() const { return __cur_; } + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr iterator_t<_View> base() const { return __cur_; } - _LIBCPP_HIDE_FROM_ABI constexpr value_type operator*() const { return {__cur_, __next_.begin()}; } + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr value_type operator*() const { return {__cur_, __next_.begin()}; } _LIBCPP_HIDE_FROM_ABI constexpr __iterator& operator++() { __cur_ = __next_.begin(); diff --git a/lib/libcxx/include/__ranges/stride_view.h b/lib/libcxx/include/__ranges/stride_view.h new file mode 100644 index 0000000000000000000000000000000000000000..780bb25743c1532f64ee13a186839f646e77c93a --- /dev/null +++ b/lib/libcxx/include/__ranges/stride_view.h @@ -0,0 +1,410 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP___RANGES_STRIDE_VIEW_H +#define _LIBCPP___RANGES_STRIDE_VIEW_H + +#include <__assert> +#include <__compare/three_way_comparable.h> +#include <__concepts/constructible.h> +#include <__concepts/convertible_to.h> +#include <__concepts/derived_from.h> +#include <__concepts/equality_comparable.h> +#include <__config> +#include <__functional/bind_back.h> +#include <__iterator/advance.h> +#include <__iterator/concepts.h> +#include <__iterator/default_sentinel.h> +#include <__iterator/distance.h> +#include <__iterator/iter_move.h> +#include <__iterator/iter_swap.h> +#include <__iterator/iterator_traits.h> +#include <__ranges/access.h> +#include <__ranges/all.h> +#include <__ranges/concepts.h> +#include <__ranges/enable_borrowed_range.h> +#include <__ranges/range_adaptor.h> +#include <__ranges/view_interface.h> +#include <__type_traits/make_unsigned.h> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + +_LIBCPP_BEGIN_NAMESPACE_STD + +#if _LIBCPP_STD_VER >= 23 + +namespace ranges { + +template +_LIBCPP_HIDE_FROM_ABI constexpr _Value __div_ceil(_Value __left, _Value __right) { + _Value __r = __left / __right; + if (__left % __right) { + ++__r; + } + return __r; +} + +template + requires view<_View> +class stride_view : public view_interface> { + _LIBCPP_NO_UNIQUE_ADDRESS _View __base_ = _View(); + range_difference_t<_View> __stride_ = 0; + + template + class __iterator; + +public: + _LIBCPP_HIDE_FROM_ABI constexpr explicit stride_view(_View __base, range_difference_t<_View> __stride) + : __base_(std::move(__base)), __stride_(__stride) { + _LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN(__stride > 0, "The value of stride must be greater than 0"); + } + + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _View base() const& + requires copy_constructible<_View> + { + return __base_; + } + + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _View base() && { return std::move(__base_); } + + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr range_difference_t<_View> stride() const noexcept { return __stride_; } + + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto begin() + requires(!__simple_view<_View>) + { + return __iterator(this, ranges::begin(__base_), 0); + } + + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto begin() const + requires range + { + return __iterator(this, ranges::begin(__base_), 0); + } + + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto end() + requires(!__simple_view<_View>) + { + if constexpr (common_range<_View> && sized_range<_View> && forward_range<_View>) { + auto __missing = (__stride_ - ranges::distance(__base_) % __stride_) % __stride_; + return __iterator(this, ranges::end(__base_), __missing); + } else if constexpr (common_range<_View> && !bidirectional_range<_View>) { + return __iterator(this, ranges::end(__base_), 0); + } else { + return default_sentinel; + } + } + + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto end() const + requires(range) + { + if constexpr (common_range && sized_range && forward_range) { + auto __missing = (__stride_ - ranges::distance(__base_) % __stride_) % __stride_; + return __iterator(this, ranges::end(__base_), __missing); + } else if constexpr (common_range && !bidirectional_range) { + return __iterator(this, ranges::end(__base_), 0); + } else { + return default_sentinel; + } + } + + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto size() + requires sized_range<_View> + { + return std::__to_unsigned_like(ranges::__div_ceil(ranges::distance(__base_), __stride_)); + } + + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto size() const + requires sized_range + { + return std::__to_unsigned_like(ranges::__div_ceil(ranges::distance(__base_), __stride_)); + } +}; // class stride_view + +template +stride_view(_Range&&, range_difference_t<_Range>) -> stride_view>; + +template +struct __stride_iterator_category {}; + +template +struct __stride_iterator_category<_View> { + using _Cat _LIBCPP_NODEBUG = typename iterator_traits>::iterator_category; + using iterator_category = + _If, + /* then */ random_access_iterator_tag, + /* else */ _Cat >; +}; + +template + requires view<_View> +template +class stride_view<_View>::__iterator : public __stride_iterator_category<__maybe_const<_Const, _View>> { + using _Parent _LIBCPP_NODEBUG = __maybe_const<_Const, stride_view<_View>>; + using _Base _LIBCPP_NODEBUG = __maybe_const<_Const, _View>; + + _LIBCPP_NO_UNIQUE_ADDRESS iterator_t<_Base> __current_ = iterator_t<_Base>(); + _LIBCPP_NO_UNIQUE_ADDRESS ranges::sentinel_t<_Base> __end_ = ranges::sentinel_t<_Base>(); + range_difference_t<_Base> __stride_ = 0; + range_difference_t<_Base> __missing_ = 0; + + friend stride_view; + + _LIBCPP_HIDE_FROM_ABI constexpr __iterator( + _Parent* __parent, ranges::iterator_t<_Base> __current, range_difference_t<_Base> __missing) + : __current_(std::move(__current)), + __end_(ranges::end(__parent->__base_)), + __stride_(__parent->__stride_), + __missing_(__missing) {} + + static consteval auto __get_stride_view_iterator_concept() { + if constexpr (random_access_range<_Base>) { + return random_access_iterator_tag{}; + } else if constexpr (bidirectional_range<_Base>) { + return bidirectional_iterator_tag{}; + } else if constexpr (forward_range<_Base>) { + return forward_iterator_tag{}; + } else { + return input_iterator_tag{}; + } + } + +public: + using difference_type = range_difference_t<_Base>; + using value_type = range_value_t<_Base>; + using iterator_concept = decltype(__get_stride_view_iterator_concept()); + // using iterator_category = inherited; + + _LIBCPP_HIDE_FROM_ABI __iterator() + requires default_initializable> + = default; + + _LIBCPP_HIDE_FROM_ABI constexpr __iterator(__iterator __i) + requires _Const && convertible_to, iterator_t<_Base>> && + convertible_to, sentinel_t<_Base>> + : __current_(std::move(__i.__current_)), + __end_(std::move(__i.__end_)), + __stride_(__i.__stride_), + __missing_(__i.__missing_) {} + + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr iterator_t<_Base> const& base() const& noexcept { return __current_; } + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr iterator_t<_Base> base() && { return std::move(__current_); } + + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr decltype(auto) operator*() const { + _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__current_ != __end_, "Cannot dereference an iterator at the end."); + return *__current_; + } + + _LIBCPP_HIDE_FROM_ABI constexpr __iterator& operator++() { + _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__current_ != __end_, "Cannot increment an iterator already at the end."); + __missing_ = ranges::advance(__current_, __stride_, __end_); + return *this; + } + + _LIBCPP_HIDE_FROM_ABI constexpr void operator++(int) { + _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__current_ != __end_, "Cannot increment an iterator already at the end."); + ++*this; + } + _LIBCPP_HIDE_FROM_ABI constexpr __iterator operator++(int) + requires forward_range<_Base> + { + _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__current_ != __end_, "Cannot increment an iterator already at the end."); + auto __tmp = *this; + ++*this; + return __tmp; + } + + _LIBCPP_HIDE_FROM_ABI constexpr __iterator& operator--() + requires bidirectional_range<_Base> + { + ranges::advance(__current_, __missing_ - __stride_); + __missing_ = 0; + return *this; + } + _LIBCPP_HIDE_FROM_ABI constexpr __iterator operator--(int) + requires bidirectional_range<_Base> + { + auto __tmp = *this; + --*this; + return __tmp; + } + + _LIBCPP_HIDE_FROM_ABI constexpr __iterator& operator+=(difference_type __n) + requires random_access_range<_Base> + { + if (__n > 0) { + _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(ranges::distance(__current_, __end_) > __stride_ * (__n - 1), + "Advancing the iterator beyond the end is not allowed."); + ranges::advance(__current_, __stride_ * (__n - 1)); + __missing_ = ranges::advance(__current_, __stride_, __end_); + + } else if (__n < 0) { + ranges::advance(__current_, __stride_ * __n + __missing_); + __missing_ = 0; + } + return *this; + } + + _LIBCPP_HIDE_FROM_ABI constexpr __iterator& operator-=(difference_type __n) + requires random_access_range<_Base> + { + return *this += -__n; + } + + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr decltype(auto) operator[](difference_type __n) const + requires random_access_range<_Base> + { + return *(*this + __n); + } + + _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(__iterator const& __x, default_sentinel_t) { + return __x.__current_ == __x.__end_; + } + + _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(__iterator const& __x, __iterator const& __y) + requires equality_comparable> + { + return __x.__current_ == __y.__current_; + } + + _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator<(__iterator const& __x, __iterator const& __y) + requires random_access_range<_Base> + { + return __x.__current_ < __y.__current_; + } + + _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator>(__iterator const& __x, __iterator const& __y) + requires random_access_range<_Base> + { + return __y < __x; + } + + _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator<=(__iterator const& __x, __iterator const& __y) + requires random_access_range<_Base> + { + return !(__y < __x); + } + + _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator>=(__iterator const& __x, __iterator const& __y) + requires random_access_range<_Base> + { + return !(__x < __y); + } + + _LIBCPP_HIDE_FROM_ABI friend constexpr auto operator<=>(__iterator const& __x, __iterator const& __y) + requires random_access_range<_Base> && three_way_comparable> + { + return __x.__current_ <=> __y.__current_; + } + + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI friend constexpr __iterator operator+(__iterator const& __i, difference_type __s) + requires random_access_range<_Base> + { + auto __r = __i; + __r += __s; + return __r; + } + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI friend constexpr __iterator operator+(difference_type __s, __iterator const& __i) + requires random_access_range<_Base> + { + auto __r = __i; + __r += __s; + return __r; + } + + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI friend constexpr __iterator operator-(__iterator const& __i, difference_type __s) + requires random_access_range<_Base> + { + auto __r = __i; + __r -= __s; + return __r; + } + + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI friend constexpr difference_type + operator-(__iterator const& __x, __iterator const& __y) + requires sized_sentinel_for, iterator_t<_Base>> + { + if constexpr (forward_range<_Base>) { + auto __n = __x.__current_ - __y.__current_; + return (__n + __x.__missing_ - __y.__missing_) / __x.__stride_; + } + auto __n = __x.__current_ - __y.__current_; + if (__n < 0) { + return -ranges::__div_ceil(-__n, __x.__stride_); + } + return ranges::__div_ceil(__n, __x.__stride_); + } + + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI friend constexpr difference_type + operator-(default_sentinel_t, __iterator const& __x) + requires sized_sentinel_for, iterator_t<_Base>> + { + return ranges::__div_ceil(__x.__end_ - __x.__current_, __x.__stride_); + } + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI friend constexpr difference_type + operator-(__iterator const& __x, default_sentinel_t __y) + requires sized_sentinel_for, iterator_t<_Base>> + { + return -(__y - __x); + } + + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI friend constexpr range_rvalue_reference_t<_Base> + iter_move(__iterator const& __it) noexcept(noexcept(ranges::iter_move(__it.__current_))) { + return ranges::iter_move(__it.__current_); + } + + _LIBCPP_HIDE_FROM_ABI friend constexpr void + iter_swap(__iterator const& __x, + __iterator const& __y) noexcept(noexcept(ranges::iter_swap(__x.__current_, __y.__current_))) + requires indirectly_swappable> + { + return ranges::iter_swap(__x.__current_, __y.__current_); + } +}; // class stride_view::__iterator + +template +inline constexpr bool enable_borrowed_range> = enable_borrowed_range<_Tp>; + +namespace views { +namespace __stride_view { +struct __fn { + // clang-format off + template + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI + constexpr auto operator()(_Range&& __range, range_difference_t<_Range> __n) const + noexcept(noexcept(stride_view{std::forward<_Range>(__range), __n})) + -> decltype( stride_view{std::forward<_Range>(__range), __n}) + { return stride_view(std::forward<_Range>(__range), __n); } + // clang-format on + + template + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Np&& __n) const { + return __pipeable(std::__bind_back(*this, std::forward<_Np>(__n))); + } +}; +} // namespace __stride_view + +inline namespace __cpo { +inline constexpr auto stride = __stride_view::__fn{}; +} // namespace __cpo +} // namespace views + +} // namespace ranges + +#endif // _LIBCPP_STD_VER >= 23 + +_LIBCPP_END_NAMESPACE_STD + +_LIBCPP_POP_MACROS + +#endif // _LIBCPP___RANGES_STRIDE_VIEW_H diff --git a/lib/libcxx/include/__ranges/subrange.h b/lib/libcxx/include/__ranges/subrange.h index df8766216dbe24fa433401e8a910555cc14fdc14..41ab267417e905a8bf4decbc2ea520d49d873e55 100644 --- a/lib/libcxx/include/__ranges/subrange.h +++ b/lib/libcxx/include/__ranges/subrange.h @@ -49,10 +49,10 @@ _LIBCPP_PUSH_MACROS #include <__undef_macros> -_LIBCPP_BEGIN_NAMESPACE_STD - #if _LIBCPP_STD_VER >= 20 +_LIBCPP_BEGIN_NAMESPACE_STD + namespace ranges { template concept __uses_nonqualification_pointer_conversion = @@ -131,7 +131,7 @@ public: return _Pair(__begin_, __end_); } - _LIBCPP_HIDE_FROM_ABI constexpr _Iter begin() const + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Iter begin() const requires copyable<_Iter> { return __begin_; @@ -143,11 +143,11 @@ public: return std::move(__begin_); } - _LIBCPP_HIDE_FROM_ABI constexpr _Sent end() const { return __end_; } + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Sent end() const { return __end_; } [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool empty() const { return __begin_ == __end_; } - _LIBCPP_HIDE_FROM_ABI constexpr make_unsigned_t> size() const + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr make_unsigned_t> size() const requires(_Kind == subrange_kind::sized) { if constexpr (_StoreSize) @@ -201,11 +201,12 @@ template _Sent> subrange(_Iter, _Sent, make_unsigned_t>) -> subrange<_Iter, _Sent, subrange_kind::sized>; template -subrange(_Range&&) -> subrange, - sentinel_t<_Range>, - (sized_range<_Range> || sized_sentinel_for, iterator_t<_Range>>) - ? subrange_kind::sized - : subrange_kind::unsized>; +subrange(_Range&&) + -> subrange, + sentinel_t<_Range>, + (sized_range<_Range> || sized_sentinel_for, iterator_t<_Range>>) + ? subrange_kind::sized + : subrange_kind::unsized>; template subrange(_Range&&, make_unsigned_t>) @@ -213,7 +214,7 @@ subrange(_Range&&, make_unsigned_t>) template requires((_Index == 0 && copyable<_Iter>) || _Index == 1) -_LIBCPP_HIDE_FROM_ABI constexpr auto get(const subrange<_Iter, _Sent, _Kind>& __subrange) { +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto get(const subrange<_Iter, _Sent, _Kind>& __subrange) { if constexpr (_Index == 0) return __subrange.begin(); else @@ -222,7 +223,7 @@ _LIBCPP_HIDE_FROM_ABI constexpr auto get(const subrange<_Iter, _Sent, _Kind>& __ template requires(_Index < 2) -_LIBCPP_HIDE_FROM_ABI constexpr auto get(subrange<_Iter, _Sent, _Kind>&& __subrange) { +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto get(subrange<_Iter, _Sent, _Kind>&& __subrange) { if constexpr (_Index == 0) return __subrange.begin(); else @@ -265,10 +266,10 @@ struct tuple_element<1, const ranges::subrange<_Ip, _Sp, _Kp>> { using type _LIBCPP_NODEBUG = _Sp; }; -#endif // _LIBCPP_STD_VER >= 20 - _LIBCPP_END_NAMESPACE_STD +#endif // _LIBCPP_STD_VER >= 20 + _LIBCPP_POP_MACROS #endif // _LIBCPP___RANGES_SUBRANGE_H diff --git a/lib/libcxx/include/__ranges/take_view.h b/lib/libcxx/include/__ranges/take_view.h index 13cb4a285d9dfebe6c86fe8bfe87b2a4260e5586..999f686537f2c2923899cca250ad98ddadff77f2 100644 --- a/lib/libcxx/include/__ranges/take_view.h +++ b/lib/libcxx/include/__ranges/take_view.h @@ -69,8 +69,7 @@ public: requires default_initializable<_View> = default; - _LIBCPP_HIDE_FROM_ABI constexpr _LIBCPP_EXPLICIT_SINCE_CXX23 - take_view(_View __base, range_difference_t<_View> __count) + _LIBCPP_HIDE_FROM_ABI constexpr explicit take_view(_View __base, range_difference_t<_View> __count) : __base_(std::move(__base)), __count_(__count) { _LIBCPP_ASSERT_UNCATEGORIZED(__count >= 0, "count has to be greater than or equal to zero"); } diff --git a/lib/libcxx/include/__ranges/take_while_view.h b/lib/libcxx/include/__ranges/take_while_view.h index 4977f139fc5556de3b850d152e836a70f06655ee..0aee306807c8b34de9799b13523def2eecde3fa1 100644 --- a/lib/libcxx/include/__ranges/take_while_view.h +++ b/lib/libcxx/include/__ranges/take_while_view.h @@ -46,7 +46,7 @@ namespace ranges { template requires input_range<_View> && is_object_v<_Pred> && indirect_unary_predicate> -class _LIBCPP_ABI_LLVM18_NO_UNIQUE_ADDRESS take_while_view : public view_interface> { +class _LIBCPP_LLVM18_NO_UNIQUE_ADDRESS_ABI_TAG take_while_view : public view_interface> { template class __sentinel; @@ -58,38 +58,38 @@ public: requires default_initializable<_View> && default_initializable<_Pred> = default; - _LIBCPP_HIDE_FROM_ABI constexpr _LIBCPP_EXPLICIT_SINCE_CXX23 take_while_view(_View __base, _Pred __pred) + _LIBCPP_HIDE_FROM_ABI constexpr explicit take_while_view(_View __base, _Pred __pred) : __base_(std::move(__base)), __pred_(std::in_place, std::move(__pred)) {} - _LIBCPP_HIDE_FROM_ABI constexpr _View base() const& + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _View base() const& requires copy_constructible<_View> { return __base_; } - _LIBCPP_HIDE_FROM_ABI constexpr _View base() && { return std::move(__base_); } + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _View base() && { return std::move(__base_); } - _LIBCPP_HIDE_FROM_ABI constexpr const _Pred& pred() const { return *__pred_; } + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr const _Pred& pred() const { return *__pred_; } - _LIBCPP_HIDE_FROM_ABI constexpr auto begin() + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto begin() requires(!__simple_view<_View>) { return ranges::begin(__base_); } - _LIBCPP_HIDE_FROM_ABI constexpr auto begin() const + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto begin() const requires range && indirect_unary_predicate> { return ranges::begin(__base_); } - _LIBCPP_HIDE_FROM_ABI constexpr auto end() + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto end() requires(!__simple_view<_View>) { return __sentinel(ranges::end(__base_), std::addressof(*__pred_)); } - _LIBCPP_HIDE_FROM_ABI constexpr auto end() const + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto end() const requires range && indirect_unary_predicate> { return __sentinel(ranges::end(__base_), std::addressof(*__pred_)); @@ -120,7 +120,7 @@ public: requires _Const && convertible_to, sentinel_t<_Base>> : __end_(std::move(__s.__end_)), __pred_(__s.__pred_) {} - _LIBCPP_HIDE_FROM_ABI constexpr sentinel_t<_Base> base() const { return __end_; } + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr sentinel_t<_Base> base() const { return __end_; } _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(const iterator_t<_Base>& __x, const __sentinel& __y) { return __x == __y.__end_ || !std::invoke(*__y.__pred_, *__x); diff --git a/lib/libcxx/include/__ranges/transform_view.h b/lib/libcxx/include/__ranges/transform_view.h index ab1adf9cdbe687a63c8fd481cdaa290813c169e6..06ace86bbfafae40a49a81a14e49bed722ca40a7 100644 --- a/lib/libcxx/include/__ranges/transform_view.h +++ b/lib/libcxx/include/__ranges/transform_view.h @@ -16,6 +16,7 @@ #include <__concepts/derived_from.h> #include <__concepts/equality_comparable.h> #include <__concepts/invocable.h> +#include <__concepts/referenceable.h> #include <__config> #include <__functional/bind_back.h> #include <__functional/invoke.h> @@ -37,7 +38,6 @@ #include <__type_traits/is_nothrow_constructible.h> #include <__type_traits/is_object.h> #include <__type_traits/is_reference.h> -#include <__type_traits/is_referenceable.h> #include <__type_traits/maybe_const.h> #include <__type_traits/remove_cvref.h> #include <__utility/forward.h> @@ -71,7 +71,7 @@ template template # endif requires __transform_view_constraints<_View, _Fn> -class _LIBCPP_ABI_LLVM18_NO_UNIQUE_ADDRESS transform_view : public view_interface> { +class _LIBCPP_LLVM18_NO_UNIQUE_ADDRESS_ABI_TAG transform_view : public view_interface> { template class __iterator; template @@ -85,46 +85,56 @@ public: requires default_initializable<_View> && default_initializable<_Fn> = default; - _LIBCPP_HIDE_FROM_ABI constexpr _LIBCPP_EXPLICIT_SINCE_CXX23 transform_view(_View __base, _Fn __func) + _LIBCPP_HIDE_FROM_ABI constexpr explicit transform_view(_View __base, _Fn __func) : __func_(std::in_place, std::move(__func)), __base_(std::move(__base)) {} - _LIBCPP_HIDE_FROM_ABI constexpr _View base() const& + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _View base() const& requires copy_constructible<_View> { return __base_; } - _LIBCPP_HIDE_FROM_ABI constexpr _View base() && { return std::move(__base_); } - _LIBCPP_HIDE_FROM_ABI constexpr __iterator begin() { return __iterator{*this, ranges::begin(__base_)}; } - _LIBCPP_HIDE_FROM_ABI constexpr __iterator begin() const + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _View base() && { return std::move(__base_); } + + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr __iterator begin() { + return __iterator{*this, ranges::begin(__base_)}; + } + + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr __iterator begin() const requires range && __regular_invocable_with_range_ref { return __iterator(*this, ranges::begin(__base_)); } - _LIBCPP_HIDE_FROM_ABI constexpr __sentinel end() { return __sentinel(ranges::end(__base_)); } - _LIBCPP_HIDE_FROM_ABI constexpr __iterator end() + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr __sentinel end() { + return __sentinel(ranges::end(__base_)); + } + + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr __iterator end() requires common_range<_View> { return __iterator(*this, ranges::end(__base_)); } - _LIBCPP_HIDE_FROM_ABI constexpr __sentinel end() const + + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr __sentinel end() const requires range && __regular_invocable_with_range_ref { return __sentinel(ranges::end(__base_)); } - _LIBCPP_HIDE_FROM_ABI constexpr __iterator end() const + + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr __iterator end() const requires common_range && __regular_invocable_with_range_ref { return __iterator(*this, ranges::end(__base_)); } - _LIBCPP_HIDE_FROM_ABI constexpr auto size() + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto size() requires sized_range<_View> { return ranges::size(__base_); } - _LIBCPP_HIDE_FROM_ABI constexpr auto size() const + + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto size() const requires sized_range { return ranges::size(__base_); @@ -209,11 +219,11 @@ public: requires _Const && convertible_to, iterator_t<_Base>> : __parent_(__i.__parent_), __current_(std::move(__i.__current_)) {} - _LIBCPP_HIDE_FROM_ABI constexpr const iterator_t<_Base>& base() const& noexcept { return __current_; } + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr const iterator_t<_Base>& base() const& noexcept { return __current_; } - _LIBCPP_HIDE_FROM_ABI constexpr iterator_t<_Base> base() && { return std::move(__current_); } + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr iterator_t<_Base> base() && { return std::move(__current_); } - _LIBCPP_HIDE_FROM_ABI constexpr decltype(auto) operator*() const + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr decltype(auto) operator*() const noexcept(noexcept(std::invoke(*__parent_->__func_, *__current_))) { return std::invoke(*__parent_->__func_, *__current_); } @@ -262,7 +272,7 @@ public: return *this; } - _LIBCPP_HIDE_FROM_ABI constexpr decltype(auto) operator[](difference_type __n) const + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr decltype(auto) operator[](difference_type __n) const noexcept(noexcept(std::invoke(*__parent_->__func_, __current_[__n]))) requires random_access_range<_Base> { @@ -305,25 +315,26 @@ public: return __x.__current_ <=> __y.__current_; } - _LIBCPP_HIDE_FROM_ABI friend constexpr __iterator operator+(__iterator __i, difference_type __n) + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI friend constexpr __iterator operator+(__iterator __i, difference_type __n) requires random_access_range<_Base> { return __iterator{*__i.__parent_, __i.__current_ + __n}; } - _LIBCPP_HIDE_FROM_ABI friend constexpr __iterator operator+(difference_type __n, __iterator __i) + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI friend constexpr __iterator operator+(difference_type __n, __iterator __i) requires random_access_range<_Base> { return __iterator{*__i.__parent_, __i.__current_ + __n}; } - _LIBCPP_HIDE_FROM_ABI friend constexpr __iterator operator-(__iterator __i, difference_type __n) + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI friend constexpr __iterator operator-(__iterator __i, difference_type __n) requires random_access_range<_Base> { return __iterator{*__i.__parent_, __i.__current_ - __n}; } - _LIBCPP_HIDE_FROM_ABI friend constexpr difference_type operator-(const __iterator& __x, const __iterator& __y) + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI friend constexpr difference_type + operator-(const __iterator& __x, const __iterator& __y) requires sized_sentinel_for, iterator_t<_Base>> { return __x.__current_ - __y.__current_; @@ -361,7 +372,7 @@ public: requires _Const && convertible_to, sentinel_t<_Base>> : __end_(std::move(__i.__end_)) {} - _LIBCPP_HIDE_FROM_ABI constexpr sentinel_t<_Base> base() const { return __end_; } + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr sentinel_t<_Base> base() const { return __end_; } template requires sentinel_for, iterator_t<__maybe_const<_OtherConst, _View>>> @@ -371,14 +382,14 @@ public: template requires sized_sentinel_for, iterator_t<__maybe_const<_OtherConst, _View>>> - _LIBCPP_HIDE_FROM_ABI friend constexpr range_difference_t<__maybe_const<_OtherConst, _View>> + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI friend constexpr range_difference_t<__maybe_const<_OtherConst, _View>> operator-(const __iterator<_OtherConst>& __x, const __sentinel& __y) { return __x.__current_ - __y.__end_; } template requires sized_sentinel_for, iterator_t<__maybe_const<_OtherConst, _View>>> - _LIBCPP_HIDE_FROM_ABI friend constexpr range_difference_t<__maybe_const<_OtherConst, _View>> + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI friend constexpr range_difference_t<__maybe_const<_OtherConst, _View>> operator-(const __sentinel& __x, const __iterator<_OtherConst>& __y) { return __x.__end_ - __y.__current_; } diff --git a/lib/libcxx/include/__ranges/view_interface.h b/lib/libcxx/include/__ranges/view_interface.h index 37b2c9e2c1a75651ba8ade957208f22eeecdcf25..96508c2be72777c01ec201b695244c20d241b314 100644 --- a/lib/libcxx/include/__ranges/view_interface.h +++ b/lib/libcxx/include/__ranges/view_interface.h @@ -30,10 +30,10 @@ # pragma GCC system_header #endif -_LIBCPP_BEGIN_NAMESPACE_STD - #if _LIBCPP_STD_VER >= 20 +_LIBCPP_BEGIN_NAMESPACE_STD + namespace ranges { template @@ -163,8 +163,8 @@ public: } // namespace ranges -#endif // _LIBCPP_STD_VER >= 20 - _LIBCPP_END_NAMESPACE_STD +#endif // _LIBCPP_STD_VER >= 20 + #endif // _LIBCPP___RANGES_VIEW_INTERFACE_H diff --git a/lib/libcxx/include/__ranges/views.h b/lib/libcxx/include/__ranges/views.h index a4de2a5e52a9de41744a652e13385603fbbfe125..e416b3f76d3f7acf53e8e5470fcec5f69d7774ef 100644 --- a/lib/libcxx/include/__ranges/views.h +++ b/lib/libcxx/include/__ranges/views.h @@ -22,7 +22,8 @@ _LIBCPP_BEGIN_NAMESPACE_STD namespace ranges { -namespace views {} +namespace views { // NOLINT(libcpp-avoid-empty-namespaces) // This is needed to declare the alias below. +} // namespace views } // namespace ranges diff --git a/lib/libcxx/include/__ranges/zip_transform_view.h b/lib/libcxx/include/__ranges/zip_transform_view.h index 07aa182f2858f8f4dadae2d44d7c864d8b75bec7..ffa3e9f9c6dd2959f95627e9751513d229fc9fdd 100644 --- a/lib/libcxx/include/__ranges/zip_transform_view.h +++ b/lib/libcxx/include/__ranges/zip_transform_view.h @@ -17,6 +17,7 @@ #include <__concepts/derived_from.h> #include <__concepts/equality_comparable.h> #include <__concepts/invocable.h> +#include <__concepts/referenceable.h> #include <__functional/invoke.h> #include <__iterator/concepts.h> #include <__iterator/incrementable_traits.h> @@ -33,7 +34,6 @@ #include <__type_traits/invoke.h> #include <__type_traits/is_object.h> #include <__type_traits/is_reference.h> -#include <__type_traits/is_referenceable.h> #include <__type_traits/maybe_const.h> #include <__type_traits/remove_cvref.h> #include <__utility/forward.h> @@ -79,15 +79,15 @@ public: _LIBCPP_HIDE_FROM_ABI constexpr explicit zip_transform_view(_Fn __fun, _Views... __views) : __zip_(std::move(__views)...), __fun_(in_place, std::move(__fun)) {} - _LIBCPP_HIDE_FROM_ABI constexpr auto begin() { return __iterator(*this, __zip_.begin()); } + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto begin() { return __iterator(*this, __zip_.begin()); } - _LIBCPP_HIDE_FROM_ABI constexpr auto begin() const + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto begin() const requires range && regular_invocable...> { return __iterator(*this, __zip_.begin()); } - _LIBCPP_HIDE_FROM_ABI constexpr auto end() { + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto end() { if constexpr (common_range<_InnerView>) { return __iterator(*this, __zip_.end()); } else { @@ -95,7 +95,7 @@ public: } } - _LIBCPP_HIDE_FROM_ABI constexpr auto end() const + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto end() const requires range && regular_invocable...> { if constexpr (common_range) { @@ -105,13 +105,13 @@ public: } } - _LIBCPP_HIDE_FROM_ABI constexpr auto size() + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto size() requires sized_range<_InnerView> { return __zip_.size(); } - _LIBCPP_HIDE_FROM_ABI constexpr auto size() const + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto size() const requires sized_range { return __zip_.size(); @@ -184,7 +184,7 @@ public: requires _Const && convertible_to<__ziperator, __ziperator<_Const>> : __parent_(__i.__parent_), __inner_(std::move(__i.__inner_)) {} - _LIBCPP_HIDE_FROM_ABI constexpr decltype(auto) operator*() const + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr decltype(auto) operator*() const noexcept(noexcept(std::apply(__get_deref_and_invoke(), __zip_view_iterator_access::__get_underlying(__inner_)))) { return std::apply(__get_deref_and_invoke(), __zip_view_iterator_access::__get_underlying(__inner_)); } @@ -233,7 +233,7 @@ public: return *this; } - _LIBCPP_HIDE_FROM_ABI constexpr decltype(auto) operator[](difference_type __n) const + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr decltype(auto) operator[](difference_type __n) const requires random_access_range<_Base> { return std::apply( @@ -255,25 +255,26 @@ public: return __x.__inner_ <=> __y.__inner_; } - _LIBCPP_HIDE_FROM_ABI friend constexpr __iterator operator+(const __iterator& __i, difference_type __n) + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI friend constexpr __iterator operator+(const __iterator& __i, difference_type __n) requires random_access_range<_Base> { return __iterator(*__i.__parent_, __i.__inner_ + __n); } - _LIBCPP_HIDE_FROM_ABI friend constexpr __iterator operator+(difference_type __n, const __iterator& __i) + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI friend constexpr __iterator operator+(difference_type __n, const __iterator& __i) requires random_access_range<_Base> { return __iterator(*__i.__parent_, __i.__inner_ + __n); } - _LIBCPP_HIDE_FROM_ABI friend constexpr __iterator operator-(const __iterator& __i, difference_type __n) + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI friend constexpr __iterator operator-(const __iterator& __i, difference_type __n) requires random_access_range<_Base> { return __iterator(*__i.__parent_, __i.__inner_ - __n); } - _LIBCPP_HIDE_FROM_ABI friend constexpr difference_type operator-(const __iterator& __x, const __iterator& __y) + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI friend constexpr difference_type + operator-(const __iterator& __x, const __iterator& __y) requires sized_sentinel_for<__ziperator<_Const>, __ziperator<_Const>> { return __x.__inner_ - __y.__inner_; @@ -307,14 +308,14 @@ public: template requires sized_sentinel_for<__zentinel<_Const>, __ziperator<_OtherConst>> - _LIBCPP_HIDE_FROM_ABI friend constexpr range_difference_t<__maybe_const<_OtherConst, _InnerView>> + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI friend constexpr range_difference_t<__maybe_const<_OtherConst, _InnerView>> operator-(const __iterator<_OtherConst>& __x, const __sentinel& __y) { return __x.__inner_ - __y.__inner_; } template requires sized_sentinel_for<__zentinel<_Const>, __ziperator<_OtherConst>> - _LIBCPP_HIDE_FROM_ABI friend constexpr range_difference_t<__maybe_const<_OtherConst, _InnerView>> + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI friend constexpr range_difference_t<__maybe_const<_OtherConst, _InnerView>> operator-(const __sentinel& __x, const __iterator<_OtherConst>& __y) { return __x.__inner_ - __y.__inner_; } @@ -327,14 +328,14 @@ struct __fn { template requires(move_constructible> && regular_invocable&> && is_object_v&>>) - _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Fn&&) const + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Fn&&) const noexcept(noexcept(auto(views::empty&>>>))) { return views::empty&>>>; } template requires(sizeof...(_Ranges) > 0) - _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Fn&& __fun, _Ranges&&... __rs) const + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Fn&& __fun, _Ranges&&... __rs) const noexcept(noexcept(zip_transform_view(std::forward<_Fn>(__fun), std::forward<_Ranges>(__rs)...))) -> decltype(zip_transform_view(std::forward<_Fn>(__fun), std::forward<_Ranges>(__rs)...)) { return zip_transform_view(std::forward<_Fn>(__fun), std::forward<_Ranges>(__rs)...); diff --git a/lib/libcxx/include/__ranges/zip_view.h b/lib/libcxx/include/__ranges/zip_view.h index bea64c4997a9e26aaaa1bcba07769142e4cb4623..aa13bed5f428d8c8d3ff5b445b9d2b4e8744b3f5 100644 --- a/lib/libcxx/include/__ranges/zip_view.h +++ b/lib/libcxx/include/__ranges/zip_view.h @@ -134,19 +134,19 @@ public: _LIBCPP_HIDE_FROM_ABI constexpr explicit zip_view(_Views... __views) : __views_(std::move(__views)...) {} - _LIBCPP_HIDE_FROM_ABI constexpr auto begin() + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto begin() requires(!(__simple_view<_Views> && ...)) { return __iterator(std::__tuple_transform(ranges::begin, __views_)); } - _LIBCPP_HIDE_FROM_ABI constexpr auto begin() const + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto begin() const requires(range && ...) { return __iterator(std::__tuple_transform(ranges::begin, __views_)); } - _LIBCPP_HIDE_FROM_ABI constexpr auto end() + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto end() requires(!(__simple_view<_Views> && ...)) { if constexpr (!__zip_is_common<_Views...>) { @@ -158,7 +158,7 @@ public: } } - _LIBCPP_HIDE_FROM_ABI constexpr auto end() const + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto end() const requires(range && ...) { if constexpr (!__zip_is_common) { @@ -170,7 +170,7 @@ public: } } - _LIBCPP_HIDE_FROM_ABI constexpr auto size() + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto size() requires(sized_range<_Views> && ...) { return std::apply( @@ -181,7 +181,7 @@ public: std::__tuple_transform(ranges::size, __views_)); } - _LIBCPP_HIDE_FROM_ABI constexpr auto size() const + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto size() const requires(sized_range && ...) { return std::apply( @@ -267,7 +267,7 @@ public: requires _Const && (convertible_to, iterator_t<__maybe_const<_Const, _Views>>> && ...) : __current_(std::move(__i.__current_)) {} - _LIBCPP_HIDE_FROM_ABI constexpr auto operator*() const { + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator*() const { return std::__tuple_transform([](auto& __i) -> decltype(auto) { return *__i; }, __current_); } @@ -315,7 +315,7 @@ public: return *this; } - _LIBCPP_HIDE_FROM_ABI constexpr auto operator[](difference_type __n) const + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator[](difference_type __n) const requires __zip_all_random_access<_Const, _Views...> { return std::__tuple_transform( @@ -338,7 +338,7 @@ public: return __x.__current_ <=> __y.__current_; } - _LIBCPP_HIDE_FROM_ABI friend constexpr __iterator operator+(const __iterator& __i, difference_type __n) + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI friend constexpr __iterator operator+(const __iterator& __i, difference_type __n) requires __zip_all_random_access<_Const, _Views...> { auto __r = __i; @@ -346,13 +346,13 @@ public: return __r; } - _LIBCPP_HIDE_FROM_ABI friend constexpr __iterator operator+(difference_type __n, const __iterator& __i) + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI friend constexpr __iterator operator+(difference_type __n, const __iterator& __i) requires __zip_all_random_access<_Const, _Views...> { return __i + __n; } - _LIBCPP_HIDE_FROM_ABI friend constexpr __iterator operator-(const __iterator& __i, difference_type __n) + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI friend constexpr __iterator operator-(const __iterator& __i, difference_type __n) requires __zip_all_random_access<_Const, _Views...> { auto __r = __i; @@ -360,7 +360,8 @@ public: return __r; } - _LIBCPP_HIDE_FROM_ABI friend constexpr difference_type operator-(const __iterator& __x, const __iterator& __y) + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI friend constexpr difference_type + operator-(const __iterator& __x, const __iterator& __y) requires(sized_sentinel_for>, iterator_t<__maybe_const<_Const, _Views>>> && ...) { @@ -374,7 +375,7 @@ public: __diffs); } - _LIBCPP_HIDE_FROM_ABI friend constexpr auto iter_move(const __iterator& __i) noexcept( + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI friend constexpr auto iter_move(const __iterator& __i) noexcept( (noexcept(ranges::iter_move(std::declval>&>())) && ...) && (is_nothrow_move_constructible_v>> && ...)) { return std::__tuple_transform(ranges::iter_move, __i.__current_); @@ -426,6 +427,7 @@ public: requires( sized_sentinel_for>, iterator_t<__maybe_const<_OtherConst, _Views>>> && ...) + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI friend constexpr common_type_t>...> operator-(const __iterator<_OtherConst>& __x, const __sentinel& __y) { const auto __diffs = ranges::__tuple_zip_transform(minus<>(), __iter_current(__x), __y.__end_); @@ -443,6 +445,7 @@ public: requires( sized_sentinel_for>, iterator_t<__maybe_const<_OtherConst, _Views>>> && ...) + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI friend constexpr common_type_t>...> operator-(const __sentinel& __y, const __iterator<_OtherConst>& __x) { return -(__x - __y); @@ -456,10 +459,10 @@ namespace views { namespace __zip { struct __fn { - _LIBCPP_HIDE_FROM_ABI static constexpr auto operator()() noexcept { return empty_view>{}; } + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static constexpr auto operator()() noexcept { return empty_view>{}; } template - _LIBCPP_HIDE_FROM_ABI static constexpr auto + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static constexpr auto operator()(_Ranges&&... __rs) noexcept(noexcept(zip_view...>(std::forward<_Ranges>(__rs)...))) -> decltype(zip_view...>(std::forward<_Ranges>(__rs)...)) { return zip_view...>(std::forward<_Ranges>(__rs)...); diff --git a/lib/libcxx/include/__split_buffer b/lib/libcxx/include/__split_buffer index d6176f8ca27499c650d61a96a76520b2c167ab38..1d50486947f08f0a97abdfe891f152dd48cec8b8 100644 --- a/lib/libcxx/include/__split_buffer +++ b/lib/libcxx/include/__split_buffer @@ -25,6 +25,7 @@ #include <__memory/compressed_pair.h> #include <__memory/pointer_traits.h> #include <__memory/swap_allocator.h> +#include <__memory/uninitialized_algorithms.h> #include <__type_traits/conditional.h> #include <__type_traits/enable_if.h> #include <__type_traits/integral_constant.h> @@ -156,10 +157,8 @@ public: _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const_reference back() const _NOEXCEPT { return *(__end_ - 1); } - _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __swap_without_allocator( - __split_buffer_pointer_layout<__split_buffer, - value_type, - allocator_type>& __other) _NOEXCEPT { + _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void + __swap_without_allocator(__split_buffer_pointer_layout& __other) _NOEXCEPT { std::swap(__front_cap_, __other.__front_cap_); std::swap(__begin_, __other.__begin_); std::swap(__back_cap_, __other.__back_cap_); @@ -190,6 +189,65 @@ public: __back_cap_ = __other.__back_cap_; } + _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void + __swap_layouts(pointer& __begin, pointer& __end, pointer& __back_capacity) { + using std::swap; + swap(__begin_, __begin); + swap(__end_, __end); + swap(__back_cap_, __back_capacity); + } + + /// Relocates the objects in the range `[__first, __last)` to the front of the buffer, then swaps + /// `__first`, `__last`, and `__capacity` with `__begin_`, `__end_`, and `__back_cap_`, + /// respectively. + /// + /// Precondition: `__front_spare() == __last - __first`. + /// Exceptions: This function has a strong exception guarantee. + _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void + __relocate(pointer& __first, pointer& __last, pointer& __capacity) { + auto __size = __last - __first; + auto __new_begin = __begin_ - __size; + std::__uninitialized_allocator_relocate( + __alloc_, std::__to_address(__first), std::__to_address(__last), std::__to_address(__new_begin)); + __begin_ = __new_begin; + __last = __first; + + __swap_layouts(__first, __last, __capacity); + __front_cap_ = __begin_; + } + + /// Relocates the objects in the range `[__first, __pivot)` to the front of the buffer, the + /// objects in `[__pivot, __last)` into the back of the buffer, then swaps `__first`, `__last`, + /// and `__capacity` with `__begin_`, `__end_`, and `__back_cap_`, respectively. + /// + /// Preconditions: + /// * `__front_spare() == __pivot - __first` + /// * `__back_spare() == __last - __pivot` + /// Exceptions: This function has a strong exception guarantee if `__first == __pivot` or + /// `__last == __pivot`. + _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI pointer + __relocate_with_pivot(pointer __pivot, pointer& __first, pointer& __last, pointer& __capacity) { + pointer __result = __begin_; + + // Relocate [__p, __last) first to avoid having a hole in [__first, __last) + // in case something in [__first, __p) throws. + std::__uninitialized_allocator_relocate( + __alloc_, std::__to_address(__pivot), std::__to_address(__last), std::__to_address(__end_)); + auto __relocated_so_far = __last - __pivot; + __end_ += __relocated_so_far; + __last = __pivot; // The objects in [__p, __last) have been destroyed by relocating them. + + auto __new_begin = __begin_ - (__pivot - __first); + std::__uninitialized_allocator_relocate( + __alloc_, std::__to_address(__first), std::__to_address(__pivot), std::__to_address(__new_begin)); + __begin_ = __new_begin; + + __last = __first; // All the objects have been destroyed by relocating them. + __swap_layouts(__first, __last, __capacity); + __front_cap_ = __begin_; + return __result; + } + private: pointer __front_cap_ = nullptr; pointer __begin_ = nullptr; @@ -263,25 +321,19 @@ public: _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __set_valid_range(pointer __new_begin, pointer __new_end) _NOEXCEPT { - // Size-based __split_buffers track their size directly: we need to explicitly update the size - // when the front is adjusted. - __size_ -= __new_begin - __begin_; __begin_ = __new_begin; __set_sentinel(__new_end); } _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __set_valid_range(pointer __new_begin, size_type __new_size) _NOEXCEPT { - // Size-based __split_buffers track their size directly: we need to explicitly update the size - // when the front is adjusted. - __size_ -= __new_begin - __begin_; __begin_ = __new_begin; __set_sentinel(__new_size); } _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __set_sentinel(pointer __new_end) _NOEXCEPT { _LIBCPP_ASSERT_INTERNAL(__front_cap_ <= __new_end, "__new_end cannot precede __front_cap_"); - __size_ += __new_end - end(); + __size_ = __new_end - __begin_; } _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __set_sentinel(size_type __new_size) _NOEXCEPT { @@ -312,10 +364,8 @@ public: return __begin_[__size_ - 1]; } - _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __swap_without_allocator( - __split_buffer_pointer_layout<__split_buffer, - value_type, - allocator_type>& __other) _NOEXCEPT { + _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void + __swap_without_allocator(__split_buffer_size_layout& __other) _NOEXCEPT { std::swap(__front_cap_, __other.__front_cap_); std::swap(__begin_, __other.__begin_); std::swap(__cap_, __other.__cap_); @@ -346,6 +396,68 @@ public: __size_ = __other.__size_; } + _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void + __swap_layouts(pointer& __begin, size_type& __size, size_type& __capacity) { + using std::swap; + swap(__begin_, __begin); + swap(__size_, __size); + swap(__cap_, __capacity); + } + + /// Relocates the objects in the range `[__first, __first + __n)` to the front of the buffer, then + /// swaps `__first`, `__n`, and `__capacity` with `__begin_`, `__size_`, and `__capacity_`, + /// respectively. + /// + /// Precondition: `__front_spare() == __n`. + /// Exceptions: This function has a strong exception guarantee. + _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void + __relocate(pointer& __first, size_type& __n, size_type& __capacity) { + auto __new_begin = __begin_ - __n; + auto __last = __first + __n; + std::__uninitialized_allocator_relocate( + __alloc_, std::__to_address(__first), std::__to_address(__last), std::__to_address(__new_begin)); + __set_valid_range(__new_begin, end()); + __n = 0; + + __swap_layouts(__first, __n, __capacity); + __front_cap_ = __begin_; + } + + /// Relocates the objects in the range `[__first, __pivot)` to the front of the buffer, the + /// objects in `[__pivot, __first + __n)` to the back of the buffer, then swaps `__first`, `__n`, + /// and `__capacity` with `__begin_`, `__size_`, and `__capacity_`, respectively. + /// + /// Preconditions: + /// * `__front_spare() == __pivot - __first` + /// * `__back_spare() == __last - __pivot` + /// Exceptions: This function has a strong exception guarantee if `__first == __pivot` or + /// `__first + __n == __pivot`. + _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI pointer + __relocate_with_pivot(pointer __pivot, pointer& __first, size_type& __n, size_type& __capacity) { + pointer __result = __begin_; + pointer __last = __first + __n; + + // We relocate elements in reverse order to ensure that a throwing relocation operation leaves the + // buffer in a valid state. + std::__uninitialized_allocator_relocate( + __alloc_, std::__to_address(__pivot), std::__to_address(__last), std::__to_address(end())); + + auto const __relocated_so_far = __last - __pivot; + __size_ += __relocated_so_far; + __n -= __relocated_so_far; // The objects in [__pivot, __last) have been destroyed by relocating them. + + auto __new_begin = __begin_ - __n; + std::__uninitialized_allocator_relocate( + __alloc_, std::__to_address(__first), std::__to_address(__pivot), std::__to_address(__new_begin)); + __begin_ = __new_begin; + __size_ += __n; + __n = 0; // All the objects have been destroyed by relocating them. + + __swap_layouts(__first, __n, __capacity); + __front_cap_ = __begin_; + return __result; + } + private: pointer __front_cap_ = nullptr; pointer __begin_ = nullptr; @@ -452,11 +564,14 @@ public: using __base_type::__get_allocator; using __base_type::__raw_capacity; using __base_type::__raw_sentinel; + using __base_type::__relocate; + using __base_type::__relocate_with_pivot; using __base_type::__reset; using __base_type::__set_capacity; using __base_type::__set_data; using __base_type::__set_sentinel; using __base_type::__set_valid_range; + using __base_type::__swap_layouts; using typename __base_type::__alloc_traits; using typename __base_type::allocator_type; @@ -585,7 +700,7 @@ public: _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __swap_without_allocator(__split_buffer& __other) _NOEXCEPT { - __base_type::__swap_without_allocator(__other); + __base_type::__swap_without_allocator(static_cast<__base_type&>(__other)); } private: diff --git a/lib/libcxx/include/__stop_token/atomic_unique_lock.h b/lib/libcxx/include/__stop_token/atomic_unique_lock.h index 4b0ae05ca86c8d42074a07b101c809ce0e9b3c29..99f94b8a789371b4f6806eb0e0049a5d86da7db6 100644 --- a/lib/libcxx/include/__stop_token/atomic_unique_lock.h +++ b/lib/libcxx/include/__stop_token/atomic_unique_lock.h @@ -10,25 +10,26 @@ #ifndef _LIBCPP___STOP_TOKEN_ATOMIC_UNIQUE_LOCK_H #define _LIBCPP___STOP_TOKEN_ATOMIC_UNIQUE_LOCK_H -#include <__bit/popcount.h> +#include <__atomic/atomic.h> +#include <__atomic/memory_order.h> +#include <__bit/has_single_bit.h> #include <__config> -#include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header #endif -_LIBCPP_BEGIN_NAMESPACE_STD - #if _LIBCPP_STD_VER >= 20 +_LIBCPP_BEGIN_NAMESPACE_STD + // This class implements an RAII unique_lock without a mutex. // It uses std::atomic, // where State contains a lock bit and might contain other data, // and LockedBit is the value of State when the lock bit is set, e.g 1 << 2 template class __atomic_unique_lock { - static_assert(std::__popcount(static_cast(_LockedBit)) == 1, + static_assert(std::has_single_bit(static_cast(_LockedBit)), "LockedBit must be an integer where only one bit is set"); std::atomic<_State>& __state_; @@ -133,8 +134,8 @@ private: _LIBCPP_HIDE_FROM_ABI static constexpr auto __set_locked_bit = [](_State __state) { return __state | _LockedBit; }; }; -#endif // _LIBCPP_STD_VER >= 20 && _LIBCPP_HAS_THREADS - _LIBCPP_END_NAMESPACE_STD +#endif // _LIBCPP_STD_VER >= 20 + #endif // _LIBCPP___STOP_TOKEN_ATOMIC_UNIQUE_LOCK_H diff --git a/lib/libcxx/include/__stop_token/intrusive_list_view.h b/lib/libcxx/include/__stop_token/intrusive_list_view.h index 11a3e267e7c6d643d122e182e3d09eea3c4ed3ee..0198b1756a525a4e25d75c17fab53b16b72a031e 100644 --- a/lib/libcxx/include/__stop_token/intrusive_list_view.h +++ b/lib/libcxx/include/__stop_token/intrusive_list_view.h @@ -17,10 +17,10 @@ # pragma GCC system_header #endif -_LIBCPP_BEGIN_NAMESPACE_STD - #if _LIBCPP_STD_VER >= 20 +_LIBCPP_BEGIN_NAMESPACE_STD + template struct __intrusive_node_base { _Derived* __next_ = nullptr; @@ -78,8 +78,8 @@ private: _Node* __head_ = nullptr; }; -#endif // _LIBCPP_STD_VER >= 20 - _LIBCPP_END_NAMESPACE_STD +#endif // _LIBCPP_STD_VER >= 20 + #endif // _LIBCPP___STOP_TOKEN_INTRUSIVE_LIST_VIEW_H diff --git a/lib/libcxx/include/__stop_token/intrusive_shared_ptr.h b/lib/libcxx/include/__stop_token/intrusive_shared_ptr.h index 0d5ffe06471661df446b7040c2622c033e2190c5..c37317f8c5c7b3b34fec558a9efed51ee5f96694 100644 --- a/lib/libcxx/include/__stop_token/intrusive_shared_ptr.h +++ b/lib/libcxx/include/__stop_token/intrusive_shared_ptr.h @@ -10,7 +10,6 @@ #ifndef _LIBCPP___STOP_TOKEN_INTRUSIVE_SHARED_PTR_H #define _LIBCPP___STOP_TOKEN_INTRUSIVE_SHARED_PTR_H -#include <__atomic/atomic.h> #include <__atomic/memory_order.h> #include <__config> #include <__cstddef/nullptr_t.h> @@ -26,10 +25,10 @@ _LIBCPP_PUSH_MACROS #include <__undef_macros> -_LIBCPP_BEGIN_NAMESPACE_STD - #if _LIBCPP_STD_VER >= 20 +_LIBCPP_BEGIN_NAMESPACE_STD + // For intrusive_shared_ptr to work with a type T, specialize __intrusive_shared_ptr_traits and implement // the following function: // @@ -126,10 +125,10 @@ private: } }; -#endif // _LIBCPP_STD_VER >= 20 - _LIBCPP_END_NAMESPACE_STD +#endif // _LIBCPP_STD_VER >= 20 + _LIBCPP_POP_MACROS #endif // _LIBCPP___STOP_TOKEN_INTRUSIVE_SHARED_PTR_H diff --git a/lib/libcxx/include/__stop_token/stop_callback.h b/lib/libcxx/include/__stop_token/stop_callback.h index 76d438e096c033614d1c1d403530f71b12c83fd3..f9d486b34746c084fb290d7196863aa433182f54 100644 --- a/lib/libcxx/include/__stop_token/stop_callback.h +++ b/lib/libcxx/include/__stop_token/stop_callback.h @@ -29,10 +29,10 @@ _LIBCPP_PUSH_MACROS #include <__undef_macros> -_LIBCPP_BEGIN_NAMESPACE_STD - #if _LIBCPP_STD_VER >= 20 && _LIBCPP_HAS_THREADS +_LIBCPP_BEGIN_NAMESPACE_STD + template class stop_callback : private __stop_callback_base { static_assert(invocable<_Callback>, @@ -93,10 +93,10 @@ private: template stop_callback(stop_token, _Callback) -> stop_callback<_Callback>; -#endif // _LIBCPP_STD_VER >= 20 && _LIBCPP_HAS_THREADS - _LIBCPP_END_NAMESPACE_STD +#endif // _LIBCPP_STD_VER >= 20 && _LIBCPP_HAS_THREADS + _LIBCPP_POP_MACROS #endif // _LIBCPP___STOP_TOKEN_STOP_CALLBACK_H diff --git a/lib/libcxx/include/__stop_token/stop_state.h b/lib/libcxx/include/__stop_token/stop_state.h index 74fafbdc637af4df12fecac817388822e5b575d3..762cf203b0af97cae137811e223e4e39c9da4cd3 100644 --- a/lib/libcxx/include/__stop_token/stop_state.h +++ b/lib/libcxx/include/__stop_token/stop_state.h @@ -11,21 +11,22 @@ #define _LIBCPP___STOP_TOKEN_STOP_STATE_H #include <__assert> +#include <__atomic/atomic.h> +#include <__atomic/memory_order.h> #include <__config> #include <__stop_token/atomic_unique_lock.h> #include <__stop_token/intrusive_list_view.h> #include <__thread/id.h> -#include #include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header #endif -_LIBCPP_BEGIN_NAMESPACE_STD - #if _LIBCPP_STD_VER >= 20 && _LIBCPP_HAS_THREADS +_LIBCPP_BEGIN_NAMESPACE_STD + struct __stop_callback_base : __intrusive_node_base<__stop_callback_base> { using __callback_fn_t _LIBCPP_NODEBUG = void(__stop_callback_base*) noexcept; _LIBCPP_HIDE_FROM_ABI explicit __stop_callback_base(__callback_fn_t* __callback_fn) : __callback_fn_(__callback_fn) {} @@ -229,8 +230,8 @@ struct __intrusive_shared_ptr_traits<__stop_state> { } }; -#endif // _LIBCPP_STD_VER >= 20 && _LIBCPP_HAS_THREADS - _LIBCPP_END_NAMESPACE_STD +#endif // _LIBCPP_STD_VER >= 20 && _LIBCPP_HAS_THREADS + #endif // _LIBCPP___STOP_TOKEN_STOP_STATE_H diff --git a/lib/libcxx/include/__stop_token/stop_token.h b/lib/libcxx/include/__stop_token/stop_token.h index 4a6ca27ac44d91492d191658e2d67bc56bb34241..c6658f86879d52de2f46e8a560a3cc8c7e7bb174 100644 --- a/lib/libcxx/include/__stop_token/stop_token.h +++ b/lib/libcxx/include/__stop_token/stop_token.h @@ -18,10 +18,10 @@ # pragma GCC system_header #endif -_LIBCPP_BEGIN_NAMESPACE_STD - #if _LIBCPP_STD_VER >= 20 && _LIBCPP_HAS_THREADS +_LIBCPP_BEGIN_NAMESPACE_STD + class stop_token { public: _LIBCPP_HIDE_FROM_ABI stop_token() noexcept = default; @@ -56,8 +56,8 @@ private: _LIBCPP_HIDE_FROM_ABI explicit stop_token(const __intrusive_shared_ptr<__stop_state>& __state) : __state_(__state) {} }; -#endif // _LIBCPP_STD_VER >= 20 && _LIBCPP_HAS_THREADS - _LIBCPP_END_NAMESPACE_STD +#endif // _LIBCPP_STD_VER >= 20 && _LIBCPP_HAS_THREADS + #endif // _LIBCPP___STOP_TOKEN_STOP_TOKEN_H diff --git a/lib/libcxx/include/__support/xlocale/__nop_locale_mgmt.h b/lib/libcxx/include/__support/xlocale/__nop_locale_mgmt.h deleted file mode 100644 index eabe169cc4bc8c9c10b7998f1806604f81747976..0000000000000000000000000000000000000000 --- a/lib/libcxx/include/__support/xlocale/__nop_locale_mgmt.h +++ /dev/null @@ -1,33 +0,0 @@ -// -*- C++ -*- -//===-----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___SUPPORT_XLOCALE_NOP_LOCALE_MGMT_H -#define _LIBCPP___SUPPORT_XLOCALE_NOP_LOCALE_MGMT_H - -#include <__config> - -// Patch over lack of extended locale support -typedef void* locale_t; - -inline _LIBCPP_HIDE_FROM_ABI locale_t duplocale(locale_t) { return nullptr; } - -inline _LIBCPP_HIDE_FROM_ABI void freelocale(locale_t) {} - -inline _LIBCPP_HIDE_FROM_ABI locale_t newlocale(int, const char*, locale_t) { return nullptr; } - -#define LC_COLLATE_MASK (1 << LC_COLLATE) -#define LC_CTYPE_MASK (1 << LC_CTYPE) -#define LC_MESSAGES_MASK (1 << LC_MESSAGES) -#define LC_MONETARY_MASK (1 << LC_MONETARY) -#define LC_NUMERIC_MASK (1 << LC_NUMERIC) -#define LC_TIME_MASK (1 << LC_TIME) -#define LC_ALL_MASK \ - (LC_COLLATE_MASK | LC_CTYPE_MASK | LC_MONETARY_MASK | LC_NUMERIC_MASK | LC_TIME_MASK | LC_MESSAGES_MASK) - -#endif // _LIBCPP___SUPPORT_XLOCALE_NOP_LOCALE_MGMT_H diff --git a/lib/libcxx/include/__support/xlocale/__strtonum_fallback.h b/lib/libcxx/include/__support/xlocale/__strtonum_fallback.h deleted file mode 100644 index 90bd59d36c248a824b9fffd9e74b6e50e499ccd3..0000000000000000000000000000000000000000 --- a/lib/libcxx/include/__support/xlocale/__strtonum_fallback.h +++ /dev/null @@ -1,37 +0,0 @@ -// -*- C++ -*- -//===-----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// -// These are reimplementations of some extended locale functions ( *_l ) that -// aren't part of POSIX. They are widely available though (GLIBC, BSD, maybe -// others). The unifying aspect in this case is that all of these functions -// convert strings to some numeric type. -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___SUPPORT_XLOCALE_STRTONUM_FALLBACK_H -#define _LIBCPP___SUPPORT_XLOCALE_STRTONUM_FALLBACK_H - -#include <__config> -#include - -#if _LIBCPP_HAS_WIDE_CHARACTERS -# include -#endif - -inline _LIBCPP_HIDE_FROM_ABI float strtof_l(const char* __nptr, char** __endptr, locale_t) { - return ::strtof(__nptr, __endptr); -} - -inline _LIBCPP_HIDE_FROM_ABI double strtod_l(const char* __nptr, char** __endptr, locale_t) { - return ::strtod(__nptr, __endptr); -} - -inline _LIBCPP_HIDE_FROM_ABI long double strtold_l(const char* __nptr, char** __endptr, locale_t) { - return ::strtold(__nptr, __endptr); -} - -#endif // _LIBCPP___SUPPORT_XLOCALE_STRTONUM_FALLBACK_H diff --git a/lib/libcxx/include/__system_error/error_category.h b/lib/libcxx/include/__system_error/error_category.h index 7f7c7355c7e7f622eb1f6e71a1b633816d441afa..f7b9233f6ef9b607850c193110163a692720ae43 100644 --- a/lib/libcxx/include/__system_error/error_category.h +++ b/lib/libcxx/include/__system_error/error_category.h @@ -19,6 +19,7 @@ #endif _LIBCPP_BEGIN_NAMESPACE_STD +_LIBCPP_BEGIN_EXPLICIT_ABI_ANNOTATIONS class error_condition; class _LIBCPP_EXPORTED_FROM_ABI error_code; @@ -70,6 +71,7 @@ public: [[__gnu__::__const__]] [[__nodiscard__]] _LIBCPP_EXPORTED_FROM_ABI const error_category& generic_category() _NOEXCEPT; [[__gnu__::__const__]] [[__nodiscard__]] _LIBCPP_EXPORTED_FROM_ABI const error_category& system_category() _NOEXCEPT; +_LIBCPP_END_EXPLICIT_ABI_ANNOTATIONS _LIBCPP_END_NAMESPACE_STD #endif // _LIBCPP___SYSTEM_ERROR_ERROR_CATEGORY_H diff --git a/lib/libcxx/include/__system_error/error_code.h b/lib/libcxx/include/__system_error/error_code.h index e90437693975383ce1df775e99c9031935277884..1b4fdd8eabb77f6303360edbd2d6ad09bb725064 100644 --- a/lib/libcxx/include/__system_error/error_code.h +++ b/lib/libcxx/include/__system_error/error_code.h @@ -24,6 +24,7 @@ #endif _LIBCPP_BEGIN_NAMESPACE_STD +_LIBCPP_BEGIN_EXPLICIT_ABI_ANNOTATIONS template struct is_error_code_enum : public false_type {}; @@ -137,6 +138,7 @@ struct hash : public __unary_function { } }; +_LIBCPP_END_EXPLICIT_ABI_ANNOTATIONS _LIBCPP_END_NAMESPACE_STD #endif // _LIBCPP___SYSTEM_ERROR_ERROR_CODE_H diff --git a/lib/libcxx/include/__system_error/error_condition.h b/lib/libcxx/include/__system_error/error_condition.h index be7deaba0444c8f79a025fb3b904ccecfcf928b6..47d87be8d76547869e57add4fc57467fc1ae6087 100644 --- a/lib/libcxx/include/__system_error/error_condition.h +++ b/lib/libcxx/include/__system_error/error_condition.h @@ -23,6 +23,7 @@ #endif _LIBCPP_BEGIN_NAMESPACE_STD +_LIBCPP_BEGIN_EXPLICIT_ABI_ANNOTATIONS template struct is_error_condition_enum : public false_type {}; @@ -124,6 +125,7 @@ struct hash : public __unary_function } }; +_LIBCPP_END_EXPLICIT_ABI_ANNOTATIONS _LIBCPP_END_NAMESPACE_STD #endif // _LIBCPP___SYSTEM_ERROR_ERROR_CONDITION_H diff --git a/lib/libcxx/include/__system_error/system_error.h b/lib/libcxx/include/__system_error/system_error.h index 74427d8f0bf9b00919b0bfcc6312f0f486308e7c..435b8f7f6aa13af6459f0e319641f5483827c9e4 100644 --- a/lib/libcxx/include/__system_error/system_error.h +++ b/lib/libcxx/include/__system_error/system_error.h @@ -22,6 +22,7 @@ #endif _LIBCPP_BEGIN_NAMESPACE_STD +_LIBCPP_BEGIN_EXPLICIT_ABI_ANNOTATIONS class _LIBCPP_EXPORTED_FROM_ABI system_error : public runtime_error { error_code __ec_; @@ -52,6 +53,7 @@ public: #endif } +_LIBCPP_END_EXPLICIT_ABI_ANNOTATIONS _LIBCPP_END_NAMESPACE_STD #endif // _LIBCPP___SYSTEM_ERROR_SYSTEM_ERROR_H diff --git a/lib/libcxx/include/__system_error/throw_system_error.h b/lib/libcxx/include/__system_error/throw_system_error.h index e4605b6f014dc57fd4903347ea8eb6edd6145b44..abcfaeb7fbed226ab2332d20eb347f05250f2e0a 100644 --- a/lib/libcxx/include/__system_error/throw_system_error.h +++ b/lib/libcxx/include/__system_error/throw_system_error.h @@ -17,9 +17,11 @@ #endif _LIBCPP_BEGIN_NAMESPACE_STD +_LIBCPP_BEGIN_EXPLICIT_ABI_ANNOTATIONS [[__noreturn__]] _LIBCPP_EXPORTED_FROM_ABI void __throw_system_error(int __ev, const char* __what_arg); +_LIBCPP_END_EXPLICIT_ABI_ANNOTATIONS _LIBCPP_END_NAMESPACE_STD #endif // _LIBCPP___SYSTEM_ERROR_THROW_SYSTEM_ERROR_H diff --git a/lib/libcxx/include/__thread/formatter.h b/lib/libcxx/include/__thread/formatter.h index 826607d47b46928518a21734b116a4b8c6003c63..9682798e1df413638bb1965857845768b994f4cd 100644 --- a/lib/libcxx/include/__thread/formatter.h +++ b/lib/libcxx/include/__thread/formatter.h @@ -51,20 +51,13 @@ public: // On Linux systems pthread_t is an unsigned long long. // On Apple systems pthread_t is a pointer type. // - // Note the output should match what the stream operator does. Since - // the ostream operator has been shipped years before this formatter - // was added to the Standard, this formatter does what the stream - // operator does. This may require platform specific changes. + // Note the output should match what the stream operator does. using _Tp = decltype(__get_underlying_id(__id)); using _Cp = conditional_t, _Tp, conditional_t, uintptr_t, void>>; static_assert(!is_same_v<_Cp, void>, "unsupported thread::id type, please file a bug report"); __format_spec::__parsed_specifications<_CharT> __specs = __parser_.__get_parsed_std_specifications(__ctx); - if constexpr (is_pointer_v<_Tp>) { - __specs.__std_.__alternate_form_ = true; - __specs.__std_.__type_ = __format_spec::__type::__hexadecimal_lower_case; - } return __formatter::__format_integer(reinterpret_cast<_Cp>(__get_underlying_id(__id)), __ctx, __specs); } diff --git a/lib/libcxx/include/__thread/id.h b/lib/libcxx/include/__thread/id.h index 14a51fc9ee8806bdd3e99c4cdcdd2aa7ff517f1a..5a602b070c3d2dc7f5929f1cd5dceadf1cb74ec9 100644 --- a/lib/libcxx/include/__thread/id.h +++ b/lib/libcxx/include/__thread/id.h @@ -20,9 +20,10 @@ # pragma GCC system_header #endif -_LIBCPP_BEGIN_NAMESPACE_STD - #if _LIBCPP_HAS_THREADS + +_LIBCPP_BEGIN_NAMESPACE_STD + class __thread_id; namespace this_thread { @@ -114,8 +115,8 @@ inline _LIBCPP_HIDE_FROM_ABI __thread_id get_id() _NOEXCEPT { return __libcpp_th } // namespace this_thread -#endif // _LIBCPP_HAS_THREADS - _LIBCPP_END_NAMESPACE_STD +#endif // _LIBCPP_HAS_THREADS + #endif // _LIBCPP___THREAD_ID_H diff --git a/lib/libcxx/include/__thread/support/pthread.h b/lib/libcxx/include/__thread/support/pthread.h index 4cf5c0342467bdbf4ba9bc7a1fe34bb6492d5c33..28b265ca5374865f4c51ee9304517ffb3d735e78 100644 --- a/lib/libcxx/include/__thread/support/pthread.h +++ b/lib/libcxx/include/__thread/support/pthread.h @@ -144,7 +144,9 @@ inline _LIBCPP_HIDE_FROM_ABI int __libcpp_execute_once(__libcpp_exec_once_flag* // // Thread id // -#if defined(__MVS__) +#if _LIBCPP_LIBC_LLVM_LIBC +typedef pthread_id_np_t __libcpp_thread_id; +#elif defined(__MVS__) typedef unsigned long long __libcpp_thread_id; #else typedef pthread_t __libcpp_thread_id; @@ -163,11 +165,18 @@ inline _LIBCPP_HIDE_FROM_ABI bool __libcpp_thread_id_less(__libcpp_thread_id __t // // Thread // -#define _LIBCPP_NULL_THREAD ((__libcpp_thread_t())) +#if defined(PTHREAD_NULL) +# define _LIBCPP_NULL_THREAD PTHREAD_NULL +#else +# define _LIBCPP_NULL_THREAD ((__libcpp_thread_t())) +#endif typedef pthread_t __libcpp_thread_t; inline _LIBCPP_HIDE_FROM_ABI __libcpp_thread_id __libcpp_thread_get_id(const __libcpp_thread_t* __t) { -#if defined(__MVS__) +#if _LIBCPP_LIBC_LLVM_LIBC + __libcpp_thread_id __id; + return pthread_getunique_np(__t, &__id) ? 0 : __id; +#elif defined(__MVS__) return __t->__; #else return *__t; @@ -183,8 +192,12 @@ inline _LIBCPP_HIDE_FROM_ABI int __libcpp_thread_create(__libcpp_thread_t* __t, } inline _LIBCPP_HIDE_FROM_ABI __libcpp_thread_id __libcpp_thread_get_current_id() { +#if _LIBCPP_LIBC_LLVM_LIBC + return pthread_getthreadid_np(); +#else const __libcpp_thread_t __current_thread = pthread_self(); return __libcpp_thread_get_id(&__current_thread); +#endif } inline _LIBCPP_HIDE_FROM_ABI int __libcpp_thread_join(__libcpp_thread_t* __t) { return pthread_join(*__t, nullptr); } diff --git a/lib/libcxx/include/__thread/support/windows.h b/lib/libcxx/include/__thread/support/windows.h index 558b5c81dc191ee6f42834ba052a75d24461cf24..558e8b5050e3e9339f80e0d6897c493dd91cd47a 100644 --- a/lib/libcxx/include/__thread/support/windows.h +++ b/lib/libcxx/include/__thread/support/windows.h @@ -19,6 +19,7 @@ #endif _LIBCPP_BEGIN_NAMESPACE_STD +_LIBCPP_BEGIN_EXPLICIT_ABI_ANNOTATIONS using __libcpp_timespec_t = ::timespec; @@ -126,6 +127,7 @@ _LIBCPP_EXPORTED_FROM_ABI void* __libcpp_tls_get(__libcpp_tls_key __key); _LIBCPP_EXPORTED_FROM_ABI int __libcpp_tls_set(__libcpp_tls_key __key, void* __p); +_LIBCPP_END_EXPLICIT_ABI_ANNOTATIONS _LIBCPP_END_NAMESPACE_STD #endif // _LIBCPP___THREAD_SUPPORT_WINDOWS_H diff --git a/lib/libcxx/include/__thread/this_thread.h b/lib/libcxx/include/__thread/this_thread.h index 4df137711a7fd772711c8f99943b1f42ab1857b1..5a93e4d605027e1e576feae67d010796e51b072f 100644 --- a/lib/libcxx/include/__thread/this_thread.h +++ b/lib/libcxx/include/__thread/this_thread.h @@ -32,7 +32,9 @@ namespace this_thread { #if _LIBCPP_HAS_THREADS +_LIBCPP_BEGIN_EXPLICIT_ABI_ANNOTATIONS _LIBCPP_EXPORTED_FROM_ABI void sleep_for(const chrono::nanoseconds& __ns); +_LIBCPP_END_EXPLICIT_ABI_ANNOTATIONS template _LIBCPP_HIDE_FROM_ABI void sleep_for(const chrono::duration<_Rep, _Period>& __d) { diff --git a/lib/libcxx/include/__thread/thread.h b/lib/libcxx/include/__thread/thread.h index b2f51aa816c10d61b370abf169202ba8fe679fef..4fd51c12a6dc2b06556653398534c0326b703ead 100644 --- a/lib/libcxx/include/__thread/thread.h +++ b/lib/libcxx/include/__thread/thread.h @@ -11,12 +11,13 @@ #define _LIBCPP___THREAD_THREAD_H #include <__assert> +#include <__charconv/to_chars_integral.h> #include <__condition_variable/condition_variable.h> #include <__config> #include <__exception/terminate.h> #include <__functional/hash.h> #include <__functional/unary_function.h> -#include <__locale> +#include <__fwd/ostream.h> #include <__memory/addressof.h> #include <__memory/unique_ptr.h> #include <__mutex/mutex.h> @@ -27,15 +28,16 @@ #include <__type_traits/enable_if.h> #include <__type_traits/invoke.h> #include <__type_traits/is_constructible.h> +#include <__type_traits/is_integral.h> +#include <__type_traits/is_pointer.h> #include <__type_traits/is_same.h> #include <__type_traits/remove_cvref.h> +#include <__utility/exchange.h> #include <__utility/forward.h> +#include +#include #include -#if _LIBCPP_HAS_LOCALIZATION -# include -#endif - #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header #endif @@ -44,6 +46,7 @@ _LIBCPP_PUSH_MACROS #include <__undef_macros> _LIBCPP_BEGIN_NAMESPACE_STD +_LIBCPP_BEGIN_EXPLICIT_ABI_ANNOTATIONS #if _LIBCPP_HAS_THREADS @@ -144,13 +147,19 @@ operator<<(basic_ostream<_CharT, _Traits>& __os, __thread_id __id) { // // Since various flags in the output stream can affect how the // thread id is represented (e.g. numpunct or showbase), we - // use a temporary stream instead and just output the thread - // id representation as a string. + // use `to_chars` directly and output the id as a string. - basic_ostringstream<_CharT, _Traits> __sstr; - __sstr.imbue(locale::classic()); - __sstr << __id.__id_; - return __os << __sstr.str(); + static_assert(is_pointer<__libcpp_thread_id>::value || is_integral<__libcpp_thread_id>::value); + + using __int_type = __conditional_t::value, uintptr_t, __libcpp_thread_id>; + + static const size_t __buffer_size = numeric_limits<__int_type>::digits10 + 2; + char __buffer[__buffer_size]; + auto __ret = + std::__to_chars_integral(__buffer, __buffer + __buffer_size - 1, reinterpret_cast<__int_type>(__id.__id_), 10); + _LIBCPP_ASSERT_INTERNAL(__ret.__ec == std::errc(), "to_chars failed!"); + *__ret.__ptr = '\0'; + return __os << __buffer; } # endif // _LIBCPP_HAS_LOCALIZATION @@ -236,13 +245,12 @@ public: # endif ~thread(); - _LIBCPP_HIDE_FROM_ABI thread(thread&& __t) _NOEXCEPT : __t_(__t.__t_) { __t.__t_ = _LIBCPP_NULL_THREAD; } + _LIBCPP_HIDE_FROM_ABI thread(thread&& __t) _NOEXCEPT : __t_(std::__exchange(__t.__t_, __libcpp_thread_t())) {} _LIBCPP_HIDE_FROM_ABI thread& operator=(thread&& __t) _NOEXCEPT { if (!__libcpp_thread_isnull(&__t_)) terminate(); - __t_ = __t.__t_; - __t.__t_ = _LIBCPP_NULL_THREAD; + __t_ = std::__exchange(__t.__t_, __libcpp_thread_t()); return *this; } @@ -261,6 +269,7 @@ inline _LIBCPP_HIDE_FROM_ABI void swap(thread& __x, thread& __y) _NOEXCEPT { __x #endif // _LIBCPP_HAS_THREADS +_LIBCPP_END_EXPLICIT_ABI_ANNOTATIONS _LIBCPP_END_NAMESPACE_STD _LIBCPP_POP_MACROS diff --git a/lib/libcxx/include/__tree b/lib/libcxx/include/__tree index ddeb82f91b8ad587c15fa7d2af8b3bd3784379f8..dafeff3e2e019805466c1f4a7bcdc8aa7f9bc87f 100644 --- a/lib/libcxx/include/__tree +++ b/lib/libcxx/include/__tree @@ -113,7 +113,7 @@ __root, have a non-null __parent_ field. // Returns: true if __x is a left child of its parent, else false // Precondition: __x != nullptr. template -inline _LIBCPP_HIDE_FROM_ABI bool __tree_is_left_child(_NodePtr __x) _NOEXCEPT { +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 bool __tree_is_left_child(_NodePtr __x) _NOEXCEPT { return __x == __x->__parent_->__left_; } @@ -121,7 +121,7 @@ inline _LIBCPP_HIDE_FROM_ABI bool __tree_is_left_child(_NodePtr __x) _NOEXCEPT { // __x is a proper subtree, returns the black height (null counts as 1). If // __x is an improper subtree, returns 0. template -unsigned __tree_sub_invariant(_NodePtr __x) { +_LIBCPP_CONSTEXPR_SINCE_CXX26 unsigned __tree_sub_invariant(_NodePtr __x) { if (__x == nullptr) return 1; // parent consistency checked by caller @@ -153,7 +153,7 @@ unsigned __tree_sub_invariant(_NodePtr __x) { // __root == nullptr is a proper tree. Returns true if __root is a proper // red black tree, else returns false. template -_LIBCPP_HIDE_FROM_ABI bool __tree_invariant(_NodePtr __root) { +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 bool __tree_invariant(_NodePtr __root) { if (__root == nullptr) return true; // check __x->__parent_ consistency @@ -170,7 +170,7 @@ _LIBCPP_HIDE_FROM_ABI bool __tree_invariant(_NodePtr __root) { // Returns: pointer to the left-most node under __x. template -inline _LIBCPP_HIDE_FROM_ABI _NodePtr __tree_min(_NodePtr __x) _NOEXCEPT { +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 _NodePtr __tree_min(_NodePtr __x) _NOEXCEPT { _LIBCPP_ASSERT_INTERNAL(__x != nullptr, "Root node shouldn't be null"); while (__x->__left_ != nullptr) __x = __x->__left_; @@ -179,7 +179,7 @@ inline _LIBCPP_HIDE_FROM_ABI _NodePtr __tree_min(_NodePtr __x) _NOEXCEPT { // Returns: pointer to the right-most node under __x. template -inline _LIBCPP_HIDE_FROM_ABI _NodePtr __tree_max(_NodePtr __x) _NOEXCEPT { +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 _NodePtr __tree_max(_NodePtr __x) _NOEXCEPT { _LIBCPP_ASSERT_INTERNAL(__x != nullptr, "Root node shouldn't be null"); while (__x->__right_ != nullptr) __x = __x->__right_; @@ -188,7 +188,7 @@ inline _LIBCPP_HIDE_FROM_ABI _NodePtr __tree_max(_NodePtr __x) _NOEXCEPT { // Returns: pointer to the next in-order node after __x. template -_LIBCPP_HIDE_FROM_ABI _NodePtr __tree_next(_NodePtr __x) _NOEXCEPT { +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 _NodePtr __tree_next(_NodePtr __x) _NOEXCEPT { _LIBCPP_ASSERT_INTERNAL(__x != nullptr, "node shouldn't be null"); if (__x->__right_ != nullptr) return std::__tree_min(__x->__right_); @@ -203,23 +203,23 @@ _LIBCPP_HIDE_FROM_ABI _NodePtr __tree_next(_NodePtr __x) _NOEXCEPT { // to the actual root of the tree through a __left_ pointer. Incrementing the end() pointer is UB, so we can assume that // never happens. template -inline _LIBCPP_HIDE_FROM_ABI _EndNodePtr __tree_next_iter(_NodePtr __x) _NOEXCEPT { +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 _EndNodePtr __tree_next_iter(_NodePtr __x) _NOEXCEPT { _LIBCPP_ASSERT_INTERNAL(__x != nullptr, "node shouldn't be null"); if (__x->__right_ != nullptr) - return static_cast<_EndNodePtr>(std::__tree_min(__x->__right_)); + return std::__static_fancy_pointer_cast<_EndNodePtr>(std::__tree_min(__x->__right_)); while (!std::__tree_is_left_child(__x)) __x = __x->__parent_unsafe(); - return static_cast<_EndNodePtr>(__x->__parent_); + return std::__static_fancy_pointer_cast<_EndNodePtr>(__x->__parent_); } // Returns: pointer to the previous in-order node before __x. // Note: __x may be the end node. template -inline _LIBCPP_HIDE_FROM_ABI _NodePtr __tree_prev_iter(_EndNodePtr __x) _NOEXCEPT { +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 _NodePtr __tree_prev_iter(_EndNodePtr __x) _NOEXCEPT { _LIBCPP_ASSERT_INTERNAL(__x != nullptr, "node shouldn't be null"); if (__x->__left_ != nullptr) return std::__tree_max(__x->__left_); - _NodePtr __xx = static_cast<_NodePtr>(__x); + _NodePtr __xx = std::__static_fancy_pointer_cast<_NodePtr>(__x); while (std::__tree_is_left_child(__xx)) __xx = __xx->__parent_unsafe(); return __xx->__parent_unsafe(); @@ -227,7 +227,7 @@ inline _LIBCPP_HIDE_FROM_ABI _NodePtr __tree_prev_iter(_EndNodePtr __x) _NOEXCEP // Returns: pointer to a node which has no children template -_LIBCPP_HIDE_FROM_ABI _NodePtr __tree_leaf(_NodePtr __x) _NOEXCEPT { +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 _NodePtr __tree_leaf(_NodePtr __x) _NOEXCEPT { _LIBCPP_ASSERT_INTERNAL(__x != nullptr, "node shouldn't be null"); while (true) { if (__x->__left_ != nullptr) { @@ -246,7 +246,7 @@ _LIBCPP_HIDE_FROM_ABI _NodePtr __tree_leaf(_NodePtr __x) _NOEXCEPT { // Effects: Makes __x->__right_ the subtree root with __x as its left child // while preserving in-order order. template -_LIBCPP_HIDE_FROM_ABI void __tree_left_rotate(_NodePtr __x) _NOEXCEPT { +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void __tree_left_rotate(_NodePtr __x) _NOEXCEPT { _LIBCPP_ASSERT_INTERNAL(__x != nullptr, "node shouldn't be null"); _LIBCPP_ASSERT_INTERNAL(__x->__right_ != nullptr, "node should have a right child"); _NodePtr __y = __x->__right_; @@ -265,7 +265,7 @@ _LIBCPP_HIDE_FROM_ABI void __tree_left_rotate(_NodePtr __x) _NOEXCEPT { // Effects: Makes __x->__left_ the subtree root with __x as its right child // while preserving in-order order. template -_LIBCPP_HIDE_FROM_ABI void __tree_right_rotate(_NodePtr __x) _NOEXCEPT { +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void __tree_right_rotate(_NodePtr __x) _NOEXCEPT { _LIBCPP_ASSERT_INTERNAL(__x != nullptr, "node shouldn't be null"); _LIBCPP_ASSERT_INTERNAL(__x->__left_ != nullptr, "node should have a left child"); _NodePtr __y = __x->__left_; @@ -289,7 +289,8 @@ _LIBCPP_HIDE_FROM_ABI void __tree_right_rotate(_NodePtr __x) _NOEXCEPT { // Postcondition: __tree_invariant(end_node->__left_) == true. end_node->__left_ // may be different than the value passed in as __root. template -_LIBCPP_HIDE_FROM_ABI void __tree_balance_after_insert(_NodePtr __root, _NodePtr __x) _NOEXCEPT { +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void +__tree_balance_after_insert(_NodePtr __root, _NodePtr __x) _NOEXCEPT { _LIBCPP_ASSERT_INTERNAL(__root != nullptr, "Root of the tree shouldn't be null"); _LIBCPP_ASSERT_INTERNAL(__x != nullptr, "Can't attach null node to a leaf"); __x->__is_black_ = __x == __root; @@ -345,7 +346,7 @@ _LIBCPP_HIDE_FROM_ABI void __tree_balance_after_insert(_NodePtr __root, _NodePtr // nor any of its children refer to __z. end_node->__left_ // may be different than the value passed in as __root. template -_LIBCPP_HIDE_FROM_ABI void __tree_remove(_NodePtr __root, _NodePtr __z) _NOEXCEPT { +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void __tree_remove(_NodePtr __root, _NodePtr __z) _NOEXCEPT { _LIBCPP_ASSERT_INTERNAL(__root != nullptr, "Root node should not be null"); _LIBCPP_ASSERT_INTERNAL(__z != nullptr, "The node to remove should not be null"); _LIBCPP_ASSERT_INTERNAL(std::__tree_invariant(__root), "The tree invariants should hold"); @@ -560,7 +561,7 @@ public: using pointer = _Pointer; pointer __left_; - _LIBCPP_HIDE_FROM_ABI __tree_end_node() _NOEXCEPT : __left_() {} + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __tree_end_node() _NOEXCEPT : __left_() {} }; template @@ -573,9 +574,13 @@ public: __end_node_pointer __parent_; bool __is_black_; - _LIBCPP_HIDE_FROM_ABI pointer __parent_unsafe() const { return static_cast(__parent_); } + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 pointer __parent_unsafe() const { + return std::__static_fancy_pointer_cast(__parent_); + } - _LIBCPP_HIDE_FROM_ABI void __set_parent(pointer __p) { __parent_ = static_cast<__end_node_pointer>(__p); } + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void __set_parent(pointer __p) { + __parent_ = std::__static_fancy_pointer_cast<__end_node_pointer>(__p); + } _LIBCPP_HIDE_FROM_ABI __tree_node_base() = default; __tree_node_base(__tree_node_base const&) = delete; @@ -598,7 +603,7 @@ private: }; public: - _LIBCPP_HIDE_FROM_ABI __node_value_type& __get_value() { return __value_; } + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __node_value_type& __get_value() { return __value_; } #else private: @@ -609,9 +614,10 @@ public: #endif template - _LIBCPP_HIDE_FROM_ABI explicit __tree_node(_Alloc& __na, _Args&&... __args) { + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 explicit __tree_node(_Alloc& __na, _Args&&... __args) { allocator_traits<_Alloc>::construct(__na, std::addressof(__get_value()), std::forward<_Args>(__args)...); } + ~__tree_node() = delete; __tree_node(__tree_node const&) = delete; __tree_node& operator=(__tree_node const&) = delete; @@ -631,14 +637,15 @@ private: public: bool __value_constructed; - _LIBCPP_HIDE_FROM_ABI __tree_node_destructor(const __tree_node_destructor&) = default; + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __tree_node_destructor(const __tree_node_destructor&) = default; __tree_node_destructor& operator=(const __tree_node_destructor&) = delete; - _LIBCPP_HIDE_FROM_ABI explicit __tree_node_destructor(allocator_type& __na, bool __val = false) _NOEXCEPT + _LIBCPP_HIDE_FROM_ABI + _LIBCPP_CONSTEXPR_SINCE_CXX26 explicit __tree_node_destructor(allocator_type& __na, bool __val = false) _NOEXCEPT : __na_(__na), __value_constructed(__val) {} - _LIBCPP_HIDE_FROM_ABI void operator()(pointer __p) _NOEXCEPT { + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void operator()(pointer __p) _NOEXCEPT { if (__value_constructed) __alloc_traits::destroy(__na_, std::addressof(__p->__get_value())); if (__p) @@ -663,7 +670,8 @@ template __left_) { if (std::__tree_iterate_from_root<_Reference>(__break, static_cast<_NodePtr>(__root->__left_), __func, __proj)) return true; @@ -678,7 +686,7 @@ bool __tree_iterate_from_root(_Break __break, _NodePtr __root, _Func& __func, _P // Do an in-order traversal of the tree from __first to __last. template -_LIBCPP_HIDE_FROM_ABI void +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void __tree_iterate_subrange(_NodeIter __first_it, _NodeIter __last_it, _Func& __func, _Proj& __proj) { using _NodePtr = typename _NodeIter::__node_pointer; using _Reference = typename _NodeIter::reference; @@ -722,51 +730,57 @@ public: using reference = value_type&; using pointer = __rebind_pointer_t<_NodePtr, value_type>; - _LIBCPP_HIDE_FROM_ABI __tree_iterator() _NOEXCEPT : __ptr_(nullptr) {} + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __tree_iterator() _NOEXCEPT : __ptr_(nullptr) {} - _LIBCPP_HIDE_FROM_ABI reference operator*() const { return __get_np()->__get_value(); } - _LIBCPP_HIDE_FROM_ABI pointer operator->() const { + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 reference operator*() const { return __get_np()->__get_value(); } + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 pointer operator->() const { return pointer_traits::pointer_to(__get_np()->__get_value()); } - _LIBCPP_HIDE_FROM_ABI __tree_iterator& operator++() { - __ptr_ = std::__tree_next_iter<__end_node_pointer>(static_cast<__node_base_pointer>(__ptr_)); + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __tree_iterator& operator++() { + __ptr_ = std::__tree_next_iter<__end_node_pointer>(std::__static_fancy_pointer_cast<__node_base_pointer>(__ptr_)); return *this; } - _LIBCPP_HIDE_FROM_ABI __tree_iterator operator++(int) { + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __tree_iterator operator++(int) { __tree_iterator __t(*this); ++(*this); return __t; } - _LIBCPP_HIDE_FROM_ABI __tree_iterator& operator--() { - __ptr_ = static_cast<__end_node_pointer>(std::__tree_prev_iter<__node_base_pointer>(__ptr_)); + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __tree_iterator& operator--() { + __ptr_ = std::__static_fancy_pointer_cast<__end_node_pointer>(std::__tree_prev_iter<__node_base_pointer>(__ptr_)); return *this; } - _LIBCPP_HIDE_FROM_ABI __tree_iterator operator--(int) { + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __tree_iterator operator--(int) { __tree_iterator __t(*this); --(*this); return __t; } - friend _LIBCPP_HIDE_FROM_ABI bool operator==(const __tree_iterator& __x, const __tree_iterator& __y) { + friend _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 bool + operator==(const __tree_iterator& __x, const __tree_iterator& __y) { return __x.__ptr_ == __y.__ptr_; } - friend _LIBCPP_HIDE_FROM_ABI bool operator!=(const __tree_iterator& __x, const __tree_iterator& __y) { + friend _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 bool + operator!=(const __tree_iterator& __x, const __tree_iterator& __y) { return !(__x == __y); } private: - _LIBCPP_HIDE_FROM_ABI explicit __tree_iterator(__node_pointer __p) _NOEXCEPT : __ptr_(__p) {} - _LIBCPP_HIDE_FROM_ABI explicit __tree_iterator(__end_node_pointer __p) _NOEXCEPT : __ptr_(__p) {} - _LIBCPP_HIDE_FROM_ABI __node_pointer __get_np() const { return static_cast<__node_pointer>(__ptr_); } + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 explicit __tree_iterator(__node_pointer __p) _NOEXCEPT + : __ptr_(std::__static_fancy_pointer_cast<__end_node_pointer>(__p)) {} + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 explicit __tree_iterator(__end_node_pointer __p) _NOEXCEPT + : __ptr_(__p) {} + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __node_pointer __get_np() const { + return std::__static_fancy_pointer_cast<__node_pointer>(__ptr_); + } template friend class __tree; template friend class __tree_const_iterator; template - friend void __tree_iterate_subrange(_NodeIter, _NodeIter, _Func&, _Proj&); + _LIBCPP_CONSTEXPR_SINCE_CXX26 friend void __tree_iterate_subrange(_NodeIter, _NodeIter, _Func&, _Proj&); }; #ifndef _LIBCPP_CXX03_LANG @@ -780,7 +794,8 @@ struct __specialized_algorithm< using __iterator _LIBCPP_NODEBUG = __tree_iterator<_Tp, _NodePtr, _DiffType>; template - _LIBCPP_HIDE_FROM_ABI static void operator()(__iterator __first, __iterator __last, _Func& __func, _Proj& __proj) { + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 static void + operator()(__iterator __first, __iterator __last, _Func& __func, _Proj& __proj) { std::__tree_iterate_subrange(__first, __last, __func, __proj); } }; @@ -804,54 +819,61 @@ public: using pointer = __rebind_pointer_t<_NodePtr, const value_type>; using __non_const_iterator _LIBCPP_NODEBUG = __tree_iterator<_Tp, __node_pointer, difference_type>; - _LIBCPP_HIDE_FROM_ABI __tree_const_iterator() _NOEXCEPT : __ptr_(nullptr) {} + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __tree_const_iterator() _NOEXCEPT : __ptr_(nullptr) {} - _LIBCPP_HIDE_FROM_ABI __tree_const_iterator(__non_const_iterator __p) _NOEXCEPT : __ptr_(__p.__ptr_) {} + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __tree_const_iterator(__non_const_iterator __p) _NOEXCEPT + : __ptr_(__p.__ptr_) {} - _LIBCPP_HIDE_FROM_ABI reference operator*() const { return __get_np()->__get_value(); } - _LIBCPP_HIDE_FROM_ABI pointer operator->() const { + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 reference operator*() const { return __get_np()->__get_value(); } + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 pointer operator->() const { return pointer_traits::pointer_to(__get_np()->__get_value()); } - _LIBCPP_HIDE_FROM_ABI __tree_const_iterator& operator++() { - __ptr_ = std::__tree_next_iter<__end_node_pointer>(static_cast<__node_base_pointer>(__ptr_)); + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __tree_const_iterator& operator++() { + __ptr_ = std::__tree_next_iter<__end_node_pointer>(std::__static_fancy_pointer_cast<__node_base_pointer>(__ptr_)); return *this; } - _LIBCPP_HIDE_FROM_ABI __tree_const_iterator operator++(int) { + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __tree_const_iterator operator++(int) { __tree_const_iterator __t(*this); ++(*this); return __t; } - _LIBCPP_HIDE_FROM_ABI __tree_const_iterator& operator--() { - __ptr_ = static_cast<__end_node_pointer>(std::__tree_prev_iter<__node_base_pointer>(__ptr_)); + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __tree_const_iterator& operator--() { + __ptr_ = std::__static_fancy_pointer_cast<__end_node_pointer>(std::__tree_prev_iter<__node_base_pointer>(__ptr_)); return *this; } - _LIBCPP_HIDE_FROM_ABI __tree_const_iterator operator--(int) { + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __tree_const_iterator operator--(int) { __tree_const_iterator __t(*this); --(*this); return __t; } - friend _LIBCPP_HIDE_FROM_ABI bool operator==(const __tree_const_iterator& __x, const __tree_const_iterator& __y) { + friend _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 bool + operator==(const __tree_const_iterator& __x, const __tree_const_iterator& __y) { return __x.__ptr_ == __y.__ptr_; } - friend _LIBCPP_HIDE_FROM_ABI bool operator!=(const __tree_const_iterator& __x, const __tree_const_iterator& __y) { + friend _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 bool + operator!=(const __tree_const_iterator& __x, const __tree_const_iterator& __y) { return !(__x == __y); } private: - _LIBCPP_HIDE_FROM_ABI explicit __tree_const_iterator(__node_pointer __p) _NOEXCEPT : __ptr_(__p) {} - _LIBCPP_HIDE_FROM_ABI explicit __tree_const_iterator(__end_node_pointer __p) _NOEXCEPT : __ptr_(__p) {} - _LIBCPP_HIDE_FROM_ABI __node_pointer __get_np() const { return static_cast<__node_pointer>(__ptr_); } + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 explicit __tree_const_iterator(__node_pointer __p) _NOEXCEPT + : __ptr_(std::__static_fancy_pointer_cast<__end_node_pointer>(__p)) {} + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 explicit __tree_const_iterator(__end_node_pointer __p) _NOEXCEPT + : __ptr_(std::__static_fancy_pointer_cast<__end_node_pointer>(__p)) {} + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __node_pointer __get_np() const { + return std::__static_fancy_pointer_cast<__node_pointer>(__ptr_); + } template friend class __tree; template - friend void __tree_iterate_subrange(_NodeIter, _NodeIter, _Func&, _Proj&); + _LIBCPP_CONSTEXPR_SINCE_CXX26 friend void __tree_iterate_subrange(_NodeIter, _NodeIter, _Func&, _Proj&); }; #ifndef _LIBCPP_CXX03_LANG @@ -865,7 +887,8 @@ struct __specialized_algorithm< using __iterator _LIBCPP_NODEBUG = __tree_const_iterator<_Tp, _NodePtr, _DiffType>; template - _LIBCPP_HIDE_FROM_ABI static void operator()(__iterator __first, __iterator __last, _Func& __func, _Proj& __proj) { + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 static void + operator()(__iterator __first, __iterator __last, _Func& __func, _Proj& __proj) { std::__tree_iterate_subrange(__first, __last, __func, __proj); } }; @@ -927,98 +950,114 @@ private: _LIBCPP_COMPRESSED_PAIR(size_type, __size_, value_compare, __value_comp_); public: - _LIBCPP_HIDE_FROM_ABI __end_node_pointer __end_node() _NOEXCEPT { + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __end_node_pointer __end_node() _NOEXCEPT { return pointer_traits<__end_node_pointer>::pointer_to(__end_node_); } - _LIBCPP_HIDE_FROM_ABI __end_node_pointer __end_node() const _NOEXCEPT { + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __end_node_pointer __end_node() const _NOEXCEPT { return pointer_traits<__end_node_pointer>::pointer_to(const_cast<__end_node_t&>(__end_node_)); } - _LIBCPP_HIDE_FROM_ABI __node_allocator& __node_alloc() _NOEXCEPT { return __node_alloc_; } + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __node_allocator& __node_alloc() _NOEXCEPT { + return __node_alloc_; + } private: - _LIBCPP_HIDE_FROM_ABI const __node_allocator& __node_alloc() const _NOEXCEPT { return __node_alloc_; } + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 const __node_allocator& __node_alloc() const _NOEXCEPT { + return __node_alloc_; + } public: - _LIBCPP_HIDE_FROM_ABI allocator_type __alloc() const _NOEXCEPT { return allocator_type(__node_alloc()); } + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 allocator_type __alloc() const _NOEXCEPT { + return allocator_type(__node_alloc()); + } - _LIBCPP_HIDE_FROM_ABI size_type size() const _NOEXCEPT { return __size_; } - _LIBCPP_HIDE_FROM_ABI value_compare& value_comp() _NOEXCEPT { return __value_comp_; } - _LIBCPP_HIDE_FROM_ABI const value_compare& value_comp() const _NOEXCEPT { return __value_comp_; } + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 size_type size() const _NOEXCEPT { return __size_; } + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 value_compare& value_comp() _NOEXCEPT { return __value_comp_; } + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 const value_compare& value_comp() const _NOEXCEPT { + return __value_comp_; + } public: - _LIBCPP_HIDE_FROM_ABI __node_pointer __root() const _NOEXCEPT { - return static_cast<__node_pointer>(__end_node()->__left_); + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __node_pointer __root() const _NOEXCEPT { + return std::__static_fancy_pointer_cast<__node_pointer>(__end_node()->__left_); } - _LIBCPP_HIDE_FROM_ABI __node_base_pointer* __root_ptr() const _NOEXCEPT { + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __node_base_pointer* __root_ptr() const _NOEXCEPT { return std::addressof(__end_node()->__left_); } using iterator = __tree_iterator<_Tp, __node_pointer, difference_type>; using const_iterator = __tree_const_iterator<_Tp, __node_pointer, difference_type>; - _LIBCPP_HIDE_FROM_ABI explicit __tree(const value_compare& __comp) _NOEXCEPT_( + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 explicit __tree(const value_compare& __comp) _NOEXCEPT_( is_nothrow_default_constructible<__node_allocator>::value&& is_nothrow_copy_constructible::value) : __size_(0), __value_comp_(__comp) { __begin_node_ = __end_node(); } - _LIBCPP_HIDE_FROM_ABI explicit __tree(const allocator_type& __a) + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 explicit __tree(const allocator_type& __a) : __begin_node_(), __node_alloc_(__node_allocator(__a)), __size_(0) { __begin_node_ = __end_node(); } - _LIBCPP_HIDE_FROM_ABI __tree(const value_compare& __comp, const allocator_type& __a) + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __tree(const value_compare& __comp, const allocator_type& __a) : __begin_node_(), __node_alloc_(__node_allocator(__a)), __size_(0), __value_comp_(__comp) { __begin_node_ = __end_node(); } - _LIBCPP_HIDE_FROM_ABI __tree(const __tree& __t); + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __tree(const __tree& __t); - _LIBCPP_HIDE_FROM_ABI __tree(const __tree& __other, const allocator_type& __alloc) + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __tree(const __tree& __other, const allocator_type& __alloc) : __begin_node_(__end_node()), __node_alloc_(__alloc), __size_(0), __value_comp_(__other.value_comp()) { if (__other.size() == 0) return; - *__root_ptr() = static_cast<__node_base_pointer>(__copy_construct_tree(__other.__root())); + *__root_ptr() = std::__static_fancy_pointer_cast<__node_base_pointer>(__copy_construct_tree(__other.__root())); __root()->__parent_ = __end_node(); - __begin_node_ = static_cast<__end_node_pointer>(std::__tree_min(__end_node()->__left_)); + __begin_node_ = std::__static_fancy_pointer_cast<__end_node_pointer>(std::__tree_min(__end_node()->__left_)); __size_ = __other.size(); } - _LIBCPP_HIDE_FROM_ABI __tree& operator=(const __tree& __t); + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __tree& operator=(const __tree& __t); template - _LIBCPP_HIDE_FROM_ABI void __assign_unique(_ForwardIterator __first, _ForwardIterator __last); - _LIBCPP_HIDE_FROM_ABI __tree(__tree&& __t) _NOEXCEPT_( + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void + __assign_unique(_ForwardIterator __first, _ForwardIterator __last); + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __tree(__tree&& __t) _NOEXCEPT_( is_nothrow_move_constructible<__node_allocator>::value&& is_nothrow_move_constructible::value); - _LIBCPP_HIDE_FROM_ABI __tree(__tree&& __t, const allocator_type& __a); + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __tree(__tree&& __t, const allocator_type& __a); - _LIBCPP_HIDE_FROM_ABI __tree& operator=(__tree&& __t) + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __tree& operator=(__tree&& __t) _NOEXCEPT_(is_nothrow_move_assignable::value && ((__node_traits::propagate_on_container_move_assignment::value && is_nothrow_move_assignable<__node_allocator>::value) || allocator_traits<__node_allocator>::is_always_equal::value)) { - __move_assign(__t, integral_constant()); + __move_assign(__t, + integral_constant()); return *this; } - _LIBCPP_HIDE_FROM_ABI ~__tree() { + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 ~__tree() { static_assert(is_copy_constructible::value, "Comparator must be copy-constructible."); destroy(__root()); } - _LIBCPP_HIDE_FROM_ABI iterator begin() _NOEXCEPT { return iterator(__begin_node_); } - _LIBCPP_HIDE_FROM_ABI const_iterator begin() const _NOEXCEPT { return const_iterator(__begin_node_); } - _LIBCPP_HIDE_FROM_ABI iterator end() _NOEXCEPT { return iterator(__end_node()); } - _LIBCPP_HIDE_FROM_ABI const_iterator end() const _NOEXCEPT { return const_iterator(__end_node()); } + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 iterator begin() _NOEXCEPT { return iterator(__begin_node_); } + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 const_iterator begin() const _NOEXCEPT { + return const_iterator(__begin_node_); + } + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 iterator end() _NOEXCEPT { return iterator(__end_node()); } + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 const_iterator end() const _NOEXCEPT { + return const_iterator(__end_node()); + } - _LIBCPP_HIDE_FROM_ABI size_type max_size() const _NOEXCEPT { + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 size_type max_size() const _NOEXCEPT { return std::min(__node_traits::max_size(__node_alloc()), numeric_limits::max()); } - _LIBCPP_HIDE_FROM_ABI void clear() _NOEXCEPT; + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void clear() _NOEXCEPT; - _LIBCPP_HIDE_FROM_ABI void swap(__tree& __t) + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void swap(__tree& __t) #if _LIBCPP_STD_VER <= 11 _NOEXCEPT_(__is_nothrow_swappable_v && (!__node_traits::propagate_on_container_swap::value || __is_nothrow_swappable_v<__node_allocator>)); @@ -1027,21 +1066,22 @@ public: #endif template - _LIBCPP_HIDE_FROM_ABI iterator __emplace_multi(_Args&&... __args); + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 iterator __emplace_multi(_Args&&... __args); template - _LIBCPP_HIDE_FROM_ABI iterator __emplace_hint_multi(const_iterator __p, _Args&&... __args); + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 iterator + __emplace_hint_multi(const_iterator __p, _Args&&... __args); template - _LIBCPP_HIDE_FROM_ABI pair __emplace_unique(_Args&&... __args) { + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 pair __emplace_unique(_Args&&... __args) { return std::__try_key_extraction( [this](const key_type& __key, _Args&&... __args2) { auto [__parent, __child] = __find_equal(__key); - __node_pointer __r = static_cast<__node_pointer>(__child); + __node_pointer __r = std::__static_fancy_pointer_cast<__node_pointer>(__child); bool __inserted = false; if (__child == nullptr) { __node_holder __h = __construct_node(std::forward<_Args>(__args2)...); - __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get())); + __insert_node_at(__parent, __child, std::__static_fancy_pointer_cast<__node_base_pointer>(__h.get())); __r = __h.release(); __inserted = true; } @@ -1050,10 +1090,10 @@ public: [this](_Args&&... __args2) { __node_holder __h = __construct_node(std::forward<_Args>(__args2)...); auto [__parent, __child] = __find_equal(__h->__get_value()); - __node_pointer __r = static_cast<__node_pointer>(__child); + __node_pointer __r = std::__static_fancy_pointer_cast<__node_pointer>(__child); bool __inserted = false; if (__child == nullptr) { - __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get())); + __insert_node_at(__parent, __child, std::__static_fancy_pointer_cast<__node_base_pointer>(__h.get())); __r = __h.release(); __inserted = true; } @@ -1063,16 +1103,17 @@ public: } template - _LIBCPP_HIDE_FROM_ABI pair __emplace_hint_unique(const_iterator __p, _Args&&... __args) { + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 pair + __emplace_hint_unique(const_iterator __p, _Args&&... __args) { return std::__try_key_extraction( [this, __p](const key_type& __key, _Args&&... __args2) { __node_base_pointer __dummy; auto [__parent, __child] = __find_equal(__p, __dummy, __key); - __node_pointer __r = static_cast<__node_pointer>(__child); + __node_pointer __r = std::__static_fancy_pointer_cast<__node_pointer>(__child); bool __inserted = false; if (__child == nullptr) { __node_holder __h = __construct_node(std::forward<_Args>(__args2)...); - __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get())); + __insert_node_at(__parent, __child, std::__static_fancy_pointer_cast<__node_base_pointer>(__h.get())); __r = __h.release(); __inserted = true; } @@ -1082,9 +1123,9 @@ public: __node_holder __h = __construct_node(std::forward<_Args>(__args2)...); __node_base_pointer __dummy; auto [__parent, __child] = __find_equal(__p, __dummy, __h->__get_value()); - __node_pointer __r = static_cast<__node_pointer>(__child); + __node_pointer __r = std::__static_fancy_pointer_cast<__node_pointer>(__child); if (__child == nullptr) { - __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get())); + __insert_node_at(__parent, __child, std::__static_fancy_pointer_cast<__node_base_pointer>(__h.get())); __r = __h.release(); } return pair(iterator(__r), __child == nullptr); @@ -1093,46 +1134,50 @@ public: } template - _LIBCPP_HIDE_FROM_ABI void __insert_range_multi(_InIter __first, _Sent __last) { + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void __insert_range_multi(_InIter __first, _Sent __last) { if (__first == __last) return; if (__root() == nullptr) { // Make sure we always have a root node - __insert_node_at( - __end_node(), __end_node()->__left_, static_cast<__node_base_pointer>(__construct_node(*__first).release())); + __insert_node_at(__end_node(), + __end_node()->__left_, + std::__static_fancy_pointer_cast<__node_base_pointer>(__construct_node(*__first).release())); ++__first; } - auto __max_node = static_cast<__node_pointer>(std::__tree_max(static_cast<__node_base_pointer>(__root()))); + auto __max_node = std::__static_fancy_pointer_cast<__node_pointer>( + std::__tree_max(std::__static_fancy_pointer_cast<__node_base_pointer>(__root()))); for (; __first != __last; ++__first) { __node_holder __nd = __construct_node(*__first); // Always check the max node first. This optimizes for sorted ranges inserted at the end. if (!value_comp()(__nd->__get_value(), __max_node->__get_value())) { // __node >= __max_val - __insert_node_at(static_cast<__end_node_pointer>(__max_node), + __insert_node_at(std::__static_fancy_pointer_cast<__end_node_pointer>(__max_node), __max_node->__right_, - static_cast<__node_base_pointer>(__nd.get())); + std::__static_fancy_pointer_cast<__node_base_pointer>(__nd.get())); __max_node = __nd.release(); } else { __end_node_pointer __parent; __node_base_pointer& __child = __find_leaf_high(__parent, __nd->__get_value()); - __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__nd.release())); + __insert_node_at(__parent, __child, std::__static_fancy_pointer_cast<__node_base_pointer>(__nd.release())); } } } template - _LIBCPP_HIDE_FROM_ABI void __insert_range_unique(_InIter __first, _Sent __last) { + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void __insert_range_unique(_InIter __first, _Sent __last) { if (__first == __last) return; if (__root() == nullptr) { - __insert_node_at( - __end_node(), __end_node()->__left_, static_cast<__node_base_pointer>(__construct_node(*__first).release())); + __insert_node_at(__end_node(), + __end_node()->__left_, + std::__static_fancy_pointer_cast<__node_base_pointer>(__construct_node(*__first).release())); ++__first; } - auto __max_node = static_cast<__node_pointer>(std::__tree_max(static_cast<__node_base_pointer>(__root()))); + auto __max_node = std::__static_fancy_pointer_cast<__node_pointer>( + std::__tree_max(std::__static_fancy_pointer_cast<__node_base_pointer>(__root()))); using __reference = decltype(*__first); @@ -1141,29 +1186,31 @@ public: [this, &__max_node](const key_type& __key, __reference&& __val) { if (value_comp()(__max_node->__get_value(), __key)) { // __key > __max_node __node_holder __nd = __construct_node(std::forward<__reference>(__val)); - __insert_node_at(static_cast<__end_node_pointer>(__max_node), + __insert_node_at(std::__static_fancy_pointer_cast<__end_node_pointer>(__max_node), __max_node->__right_, - static_cast<__node_base_pointer>(__nd.get())); + std::__static_fancy_pointer_cast<__node_base_pointer>(__nd.get())); __max_node = __nd.release(); } else { auto [__parent, __child] = __find_equal(__key); if (__child == nullptr) { __node_holder __nd = __construct_node(std::forward<__reference>(__val)); - __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__nd.release())); + __insert_node_at( + __parent, __child, std::__static_fancy_pointer_cast<__node_base_pointer>(__nd.release())); } } }, [this, &__max_node](__reference&& __val) { __node_holder __nd = __construct_node(std::forward<__reference>(__val)); if (value_comp()(__max_node->__get_value(), __nd->__get_value())) { // __node > __max_node - __insert_node_at(static_cast<__end_node_pointer>(__max_node), + __insert_node_at(std::__static_fancy_pointer_cast<__end_node_pointer>(__max_node), __max_node->__right_, - static_cast<__node_base_pointer>(__nd.get())); + std::__static_fancy_pointer_cast<__node_base_pointer>(__nd.get())); __max_node = __nd.release(); } else { auto [__parent, __child] = __find_equal(__nd->__get_value()); if (__child == nullptr) { - __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__nd.release())); + __insert_node_at( + __parent, __child, std::__static_fancy_pointer_cast<__node_base_pointer>(__nd.release())); } } }, @@ -1171,62 +1218,67 @@ public: } } - _LIBCPP_HIDE_FROM_ABI iterator __remove_node_pointer(__node_pointer) _NOEXCEPT; + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 iterator __remove_node_pointer(__node_pointer) _NOEXCEPT; #if _LIBCPP_STD_VER >= 17 template - _LIBCPP_HIDE_FROM_ABI _InsertReturnType __node_handle_insert_unique(_NodeHandle&&); + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 _InsertReturnType __node_handle_insert_unique(_NodeHandle&&); template - _LIBCPP_HIDE_FROM_ABI iterator __node_handle_insert_unique(const_iterator, _NodeHandle&&); + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 iterator + __node_handle_insert_unique(const_iterator, _NodeHandle&&); template - _LIBCPP_HIDE_FROM_ABI void __node_handle_merge_unique(__tree<_Tp, _Comp2, _Allocator>& __source); + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void + __node_handle_merge_unique(__tree<_Tp, _Comp2, _Allocator>& __source); template - _LIBCPP_HIDE_FROM_ABI iterator __node_handle_insert_multi(_NodeHandle&&); + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 iterator __node_handle_insert_multi(_NodeHandle&&); template - _LIBCPP_HIDE_FROM_ABI iterator __node_handle_insert_multi(const_iterator, _NodeHandle&&); + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 iterator + __node_handle_insert_multi(const_iterator, _NodeHandle&&); template - _LIBCPP_HIDE_FROM_ABI void __node_handle_merge_multi(__tree<_Tp, _Comp2, _Allocator>& __source); + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void + __node_handle_merge_multi(__tree<_Tp, _Comp2, _Allocator>& __source); template - _LIBCPP_HIDE_FROM_ABI _NodeHandle __node_handle_extract(key_type const&); + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 _NodeHandle __node_handle_extract(key_type const&); template - _LIBCPP_HIDE_FROM_ABI _NodeHandle __node_handle_extract(const_iterator); + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 _NodeHandle __node_handle_extract(const_iterator); #endif - _LIBCPP_HIDE_FROM_ABI iterator erase(const_iterator __p); - _LIBCPP_HIDE_FROM_ABI iterator erase(const_iterator __f, const_iterator __l); + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 iterator erase(const_iterator __p); + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 iterator erase(const_iterator __f, const_iterator __l); template - _LIBCPP_HIDE_FROM_ABI size_type __erase_unique(const _Key& __k); + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 size_type __erase_unique(const _Key& __k); template - _LIBCPP_HIDE_FROM_ABI size_type __erase_multi(const _Key& __k); + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 size_type __erase_multi(const _Key& __k); - _LIBCPP_HIDE_FROM_ABI void + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void __insert_node_at(__end_node_pointer __parent, __node_base_pointer& __child, __node_base_pointer __new_node) _NOEXCEPT; template - _LIBCPP_HIDE_FROM_ABI iterator find(const _Key& __key) { - auto [__, __match] = __find_equal(__key); + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 iterator find(const _Key& __key) { + auto [__dummy, __match] = __find_equal(__key); if (__match == nullptr) return end(); - return iterator(static_cast<__node_pointer>(__match)); + return iterator(std::__static_fancy_pointer_cast<__node_pointer>(__match)); } template - _LIBCPP_HIDE_FROM_ABI const_iterator find(const _Key& __key) const { - auto [__, __match] = __find_equal(__key); + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 const_iterator find(const _Key& __key) const { + auto [__dummy, __match] = __find_equal(__key); if (__match == nullptr) return end(); - return const_iterator(static_cast<__node_pointer>(__match)); + return const_iterator(std::__static_fancy_pointer_cast<__node_pointer>(__match)); } template - _LIBCPP_HIDE_FROM_ABI size_type __count_unique(const _Key& __k) const; + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 size_type __count_unique(const _Key& __k) const; template - _LIBCPP_HIDE_FROM_ABI size_type __count_multi(const _Key& __k) const; + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 size_type __count_multi(const _Key& __k) const; template - _LIBCPP_HIDE_FROM_ABI __end_node_pointer __lower_upper_bound_unique_impl(const _Key& __v) const { + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __end_node_pointer + __lower_upper_bound_unique_impl(const _Key& __v) const { auto __rt = __root(); auto __result = __end_node(); auto __comp = __lazy_synth_three_way_comparator<_Compare, _Key, value_type>(value_comp()); @@ -1234,14 +1286,15 @@ public: auto __comp_res = __comp(__v, __rt->__get_value()); if (__comp_res.__less()) { - __result = static_cast<__end_node_pointer>(__rt); - __rt = static_cast<__node_pointer>(__rt->__left_); + __result = std::__static_fancy_pointer_cast<__end_node_pointer>(__rt); + __rt = std::__static_fancy_pointer_cast<__node_pointer>(__rt->__left_); } else if (__comp_res.__greater()) { - __rt = static_cast<__node_pointer>(__rt->__right_); + __rt = std::__static_fancy_pointer_cast<__node_pointer>(__rt->__right_); } else if _LIBCPP_CONSTEXPR (_LowerBound) { - return static_cast<__end_node_pointer>(__rt); + return std::__static_fancy_pointer_cast<__end_node_pointer>(__rt); } else { - return __rt->__right_ ? static_cast<__end_node_pointer>(std::__tree_min(__rt->__right_)) : __result; + return __rt->__right_ ? std::__static_fancy_pointer_cast<__end_node_pointer>(std::__tree_min(__rt->__right_)) + : __result; } } return __result; @@ -1282,7 +1335,7 @@ public: #endif // _LIBCPP_ENABLE_LEGACY_TREE_LOWER_UPPER_BOUND template - _LIBCPP_HIDE_FROM_ABI iterator __lower_bound_unique(const _Key& __v) { + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 iterator __lower_bound_unique(const _Key& __v) { #if defined(_LIBCPP_ENABLE_LEGACY_TREE_LOWER_UPPER_BOUND) return iterator(__lower_bound_unique_compat_impl(__v)); #else @@ -1291,7 +1344,7 @@ public: } template - _LIBCPP_HIDE_FROM_ABI const_iterator __lower_bound_unique(const _Key& __v) const { + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 const_iterator __lower_bound_unique(const _Key& __v) const { #if defined(_LIBCPP_ENABLE_LEGACY_TREE_LOWER_UPPER_BOUND) return const_iterator(__lower_bound_unique_compat_impl(__v)); #else @@ -1300,7 +1353,7 @@ public: } template - _LIBCPP_HIDE_FROM_ABI iterator __upper_bound_unique(const _Key& __v) { + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 iterator __upper_bound_unique(const _Key& __v) { #if defined(_LIBCPP_ENABLE_LEGACY_TREE_LOWER_UPPER_BOUND) return iterator(__upper_bound_unique_compat_impl(__v)); #else @@ -1309,7 +1362,7 @@ public: } template - _LIBCPP_HIDE_FROM_ABI const_iterator __upper_bound_unique(const _Key& __v) const { + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 const_iterator __upper_bound_unique(const _Key& __v) const { #if defined(_LIBCPP_ENABLE_LEGACY_TREE_LOWER_UPPER_BOUND) return iterator(__upper_bound_unique_compat_impl(__v)); #else @@ -1319,117 +1372,138 @@ public: private: template - _LIBCPP_HIDE_FROM_ABI iterator + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 iterator __lower_bound_multi(const _Key& __v, __node_pointer __root, __end_node_pointer __result); template - _LIBCPP_HIDE_FROM_ABI const_iterator + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 const_iterator __lower_bound_multi(const _Key& __v, __node_pointer __root, __end_node_pointer __result) const; public: template - _LIBCPP_HIDE_FROM_ABI iterator __lower_bound_multi(const _Key& __v) { + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 iterator __lower_bound_multi(const _Key& __v) { return __lower_bound_multi(__v, __root(), __end_node()); } template - _LIBCPP_HIDE_FROM_ABI const_iterator __lower_bound_multi(const _Key& __v) const { + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 const_iterator __lower_bound_multi(const _Key& __v) const { return __lower_bound_multi(__v, __root(), __end_node()); } template - _LIBCPP_HIDE_FROM_ABI iterator __upper_bound_multi(const _Key& __v) { + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 iterator __upper_bound_multi(const _Key& __v) { return __upper_bound_multi(__v, __root(), __end_node()); } template - _LIBCPP_HIDE_FROM_ABI const_iterator __upper_bound_multi(const _Key& __v) const { + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 const_iterator __upper_bound_multi(const _Key& __v) const { return __upper_bound_multi(__v, __root(), __end_node()); } private: template - _LIBCPP_HIDE_FROM_ABI iterator + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 iterator __upper_bound_multi(const _Key& __v, __node_pointer __root, __end_node_pointer __result); template - _LIBCPP_HIDE_FROM_ABI const_iterator + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 const_iterator __upper_bound_multi(const _Key& __v, __node_pointer __root, __end_node_pointer __result) const; public: template - _LIBCPP_HIDE_FROM_ABI pair __equal_range_unique(const _Key& __k); + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 pair __equal_range_unique(const _Key& __k); template - _LIBCPP_HIDE_FROM_ABI pair __equal_range_unique(const _Key& __k) const; + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 pair + __equal_range_unique(const _Key& __k) const; template - _LIBCPP_HIDE_FROM_ABI pair __equal_range_multi(const _Key& __k); + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 pair __equal_range_multi(const _Key& __k); template - _LIBCPP_HIDE_FROM_ABI pair __equal_range_multi(const _Key& __k) const; + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 pair + __equal_range_multi(const _Key& __k) const; using _Dp _LIBCPP_NODEBUG = __tree_node_destructor<__node_allocator>; using __node_holder _LIBCPP_NODEBUG = unique_ptr<__node, _Dp>; - _LIBCPP_HIDE_FROM_ABI __node_holder remove(const_iterator __p) _NOEXCEPT; + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __node_holder remove(const_iterator __p) _NOEXCEPT; // FIXME: Make this function const qualified. Unfortunately doing so // breaks existing code which uses non-const callable comparators. template - _LIBCPP_HIDE_FROM_ABI pair<__end_node_pointer, __node_base_pointer&> __find_equal(const _Key& __v); + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 pair<__end_node_pointer, __node_base_pointer&> + __find_equal(const _Key& __v); template - _LIBCPP_HIDE_FROM_ABI pair<__end_node_pointer, __node_base_pointer&> __find_equal(const _Key& __v) const { + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 pair<__end_node_pointer, __node_base_pointer&> + __find_equal(const _Key& __v) const { return const_cast<__tree*>(this)->__find_equal(__v); } template - _LIBCPP_HIDE_FROM_ABI pair<__end_node_pointer, __node_base_pointer&> + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 pair<__end_node_pointer, __node_base_pointer&> __find_equal(const_iterator __hint, __node_base_pointer& __dummy, const _Key& __v); - _LIBCPP_HIDE_FROM_ABI void __copy_assign_alloc(const __tree& __t) { + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void __copy_assign_alloc(const __tree& __t) { __copy_assign_alloc(__t, integral_constant()); } - _LIBCPP_HIDE_FROM_ABI void __copy_assign_alloc(const __tree& __t, true_type) { + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void __copy_assign_alloc(const __tree& __t, true_type) { if (__node_alloc() != __t.__node_alloc()) clear(); __node_alloc() = __t.__node_alloc(); } - _LIBCPP_HIDE_FROM_ABI void __copy_assign_alloc(const __tree&, false_type) {} + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void __copy_assign_alloc(const __tree&, false_type) {} private: - _LIBCPP_HIDE_FROM_ABI __node_base_pointer& __find_leaf_low(__end_node_pointer& __parent, const value_type& __v); + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __node_base_pointer& + __find_leaf_low(__end_node_pointer& __parent, const value_type& __v); - _LIBCPP_HIDE_FROM_ABI __node_base_pointer& __find_leaf_high(__end_node_pointer& __parent, const value_type& __v); + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __node_base_pointer& + __find_leaf_high(__end_node_pointer& __parent, const value_type& __v); - _LIBCPP_HIDE_FROM_ABI __node_base_pointer& + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __node_base_pointer& __find_leaf(const_iterator __hint, __end_node_pointer& __parent, const value_type& __v); template - _LIBCPP_HIDE_FROM_ABI __node_holder __construct_node(_Args&&... __args); + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __node_holder __construct_node(_Args&&... __args); // TODO: Make this _LIBCPP_HIDE_FROM_ABI - _LIBCPP_HIDDEN void destroy(__node_pointer __nd) _NOEXCEPT { (__tree_deleter(__node_alloc_))(__nd); } + _LIBCPP_HIDDEN _LIBCPP_CONSTEXPR_SINCE_CXX26 void destroy(__node_pointer __nd) _NOEXCEPT { + (__tree_deleter(__node_alloc_))(__nd); + } - _LIBCPP_HIDE_FROM_ABI void __move_assign(__tree& __t, false_type); - _LIBCPP_HIDE_FROM_ABI void __move_assign(__tree& __t, true_type) _NOEXCEPT_( + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void __move_assign(__tree& __t, false_type); + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void __move_assign(__tree& __t, true_type) _NOEXCEPT_( is_nothrow_move_assignable::value&& is_nothrow_move_assignable<__node_allocator>::value); - _LIBCPP_HIDE_FROM_ABI void __move_assign_alloc(__tree& __t) + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void __move_assign_alloc(__tree& __t) _NOEXCEPT_(!__node_traits::propagate_on_container_move_assignment::value || is_nothrow_move_assignable<__node_allocator>::value) { __move_assign_alloc(__t, integral_constant()); } - _LIBCPP_HIDE_FROM_ABI void __move_assign_alloc(__tree& __t, true_type) + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void __move_assign_alloc(__tree& __t, true_type) _NOEXCEPT_(is_nothrow_move_assignable<__node_allocator>::value) { __node_alloc() = std::move(__t.__node_alloc()); } - _LIBCPP_HIDE_FROM_ABI void __move_assign_alloc(__tree&, false_type) _NOEXCEPT {} + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void __move_assign_alloc(__tree&, false_type) _NOEXCEPT {} template , int> = 0> - _LIBCPP_HIDE_FROM_ABI static void __assign_value(__get_node_value_type_t& __lhs, _From&& __rhs) { + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 static void + __assign_value(__get_node_value_type_t& __lhs, _From&& __rhs) { using __key_type = __remove_const_t; +#if _LIBCPP_STD_VER >= 26 + if constexpr (std::is_copy_constructible_v) { + // We need to replace the `const key_type` subobject by reconstruction during constant evaluation to avoid + // undefined behavior. Currently, there is no constexpr-friend way to replacing a move-only key subobject. + if consteval { + std::destroy_at(std::addressof(__lhs)); + std::construct_at(std::addressof(__lhs), __rhs.first, std::forward<_From>(__rhs).second); + return; + } + } +#endif + // This is technically UB, since the object was constructed as `const`. // Clang doesn't optimize on this currently though. const_cast<__key_type&>(__lhs.first) = const_cast<__copy_cvref_t<_From, __key_type>&&>(__rhs.first); @@ -1437,7 +1511,7 @@ private: } template , int> = 0> - _LIBCPP_HIDE_FROM_ABI static void __assign_value(_To& __lhs, _From&& __rhs) { + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 static void __assign_value(_To& __lhs, _From&& __rhs) { __lhs = std::forward<_From>(__rhs); } @@ -1447,24 +1521,23 @@ private: public: using pointer = __node_pointer; - _LIBCPP_HIDE_FROM_ABI __tree_deleter(__node_allocator& __alloc) : __alloc_(__alloc) {} + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __tree_deleter(__node_allocator& __alloc) : __alloc_(__alloc) {} #ifdef _LIBCPP_COMPILER_CLANG_BASED // FIXME: GCC complains about not being able to always_inline a recursive function _LIBCPP_HIDE_FROM_ABI #endif - void - operator()(__node_pointer __ptr) { + _LIBCPP_CONSTEXPR_SINCE_CXX26 void operator()(__node_pointer __ptr) { if (!__ptr) return; - (*this)(static_cast<__node_pointer>(__ptr->__left_)); + (*this)(std::__static_fancy_pointer_cast<__node_pointer>(__ptr->__left_)); auto __right = __ptr->__right_; __node_traits::destroy(__alloc_, std::addressof(__ptr->__get_value())); __node_traits::deallocate(__alloc_, __ptr, 1); - (*this)(static_cast<__node_pointer>(__right)); + (*this)(std::__static_fancy_pointer_cast<__node_pointer>(__right)); } }; @@ -1476,41 +1549,54 @@ private: #ifdef _LIBCPP_COMPILER_CLANG_BASED // FIXME: GCC complains about not being able to always_inline a recursive function _LIBCPP_HIDE_FROM_ABI #endif - __node_pointer __construct_from_tree(__node_pointer __src, _NodeConstructor __construct) { + _LIBCPP_CONSTEXPR_SINCE_CXX26 __node_pointer + __construct_from_tree(__node_pointer __src, _NodeConstructor __construct) { if (!__src) return nullptr; __node_holder __new_node = __construct(__src->__get_value()); unique_ptr<__node, __tree_deleter> __left( - __construct_from_tree(static_cast<__node_pointer>(__src->__left_), __construct), __node_alloc_); - __node_pointer __right = __construct_from_tree(static_cast<__node_pointer>(__src->__right_), __construct); + __construct_from_tree(std::__static_fancy_pointer_cast<__node_pointer>(__src->__left_), __construct), + __node_alloc_); + __node_pointer __right = + __construct_from_tree(std::__static_fancy_pointer_cast<__node_pointer>(__src->__right_), __construct); __node_pointer __new_node_ptr = __new_node.release(); __new_node_ptr->__is_black_ = __src->__is_black_; - __new_node_ptr->__left_ = static_cast<__node_base_pointer>(__left.release()); - __new_node_ptr->__right_ = static_cast<__node_base_pointer>(__right); + __new_node_ptr->__left_ = std::__static_fancy_pointer_cast<__node_base_pointer>(__left.release()); + __new_node_ptr->__right_ = std::__static_fancy_pointer_cast<__node_base_pointer>(__right); if (__new_node_ptr->__left_) - __new_node_ptr->__left_->__parent_ = static_cast<__end_node_pointer>(__new_node_ptr); + __new_node_ptr->__left_->__parent_ = std::__static_fancy_pointer_cast<__end_node_pointer>(__new_node_ptr); if (__new_node_ptr->__right_) - __new_node_ptr->__right_->__parent_ = static_cast<__end_node_pointer>(__new_node_ptr); + __new_node_ptr->__right_->__parent_ = std::__static_fancy_pointer_cast<__end_node_pointer>(__new_node_ptr); return __new_node_ptr; } - _LIBCPP_HIDE_FROM_ABI __node_pointer __copy_construct_tree(__node_pointer __src) { + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __node_pointer __copy_construct_tree(__node_pointer __src) { return __construct_from_tree(__src, [this](const value_type& __val) { return __construct_node(__val); }); } template , int> = 0> - _LIBCPP_HIDE_FROM_ABI __node_pointer __move_construct_tree(__node_pointer __src) { + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __node_pointer __move_construct_tree(__node_pointer __src) { return __construct_from_tree(__src, [this](value_type& __val) { + +#if _LIBCPP_STD_VER >= 26 + // We need to replace the `const key_type` subobject by reconstruction during constant evaluation to avoid + // undefined behavior. Currently, there is no constexpr-friend way to replacing a move-only key subobject. + if constexpr (std::is_copy_constructible_v) { + if consteval { + return __construct_node(__val.first, std::move(__val.second)); + } + } +#endif return __construct_node(const_cast(__val.first), std::move(__val.second)); }); } template , int> = 0> - _LIBCPP_HIDE_FROM_ABI __node_pointer __move_construct_tree(__node_pointer __src) { + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __node_pointer __move_construct_tree(__node_pointer __src) { return __construct_from_tree(__src, [this](value_type& __val) { return __construct_node(std::move(__val)); }); } @@ -1521,7 +1607,7 @@ private: #ifdef _LIBCPP_COMPILER_CLANG_BASED // FIXME: GCC complains about not being able to always_inline a recursive function _LIBCPP_HIDE_FROM_ABI #endif - __node_pointer __assign_from_tree( + _LIBCPP_CONSTEXPR_SINCE_CXX26 __node_pointer __assign_from_tree( __node_pointer __dest, __node_pointer __src, _Assignment __assign, _ConstructionAlg __construct_subtree) { if (!__src) { destroy(__dest); @@ -1533,36 +1619,37 @@ private: // If we already have a left node in the destination tree, reuse it and copy-assign recursively if (__dest->__left_) { - __dest->__left_ = static_cast<__node_base_pointer>(__assign_from_tree( - static_cast<__node_pointer>(__dest->__left_), - static_cast<__node_pointer>(__src->__left_), + __dest->__left_ = std::__static_fancy_pointer_cast<__node_base_pointer>(__assign_from_tree( + std::__static_fancy_pointer_cast<__node_pointer>(__dest->__left_), + std::__static_fancy_pointer_cast<__node_pointer>(__src->__left_), __assign, __construct_subtree)); // Otherwise, we must create new nodes; copy-construct from here on } else if (__src->__left_) { - auto __new_left = __construct_subtree(static_cast<__node_pointer>(__src->__left_)); - __dest->__left_ = static_cast<__node_base_pointer>(__new_left); - __new_left->__parent_ = static_cast<__end_node_pointer>(__dest); + auto __new_left = __construct_subtree(std::__static_fancy_pointer_cast<__node_pointer>(__src->__left_)); + __dest->__left_ = std::__static_fancy_pointer_cast<__node_base_pointer>(__new_left); + __new_left->__parent_ = std::__static_fancy_pointer_cast<__end_node_pointer>(__dest); } // Identical to the left case above, just for the right nodes if (__dest->__right_) { - __dest->__right_ = static_cast<__node_base_pointer>(__assign_from_tree( - static_cast<__node_pointer>(__dest->__right_), - static_cast<__node_pointer>(__src->__right_), + __dest->__right_ = std::__static_fancy_pointer_cast<__node_base_pointer>(__assign_from_tree( + std::__static_fancy_pointer_cast<__node_pointer>(__dest->__right_), + std::__static_fancy_pointer_cast<__node_pointer>(__src->__right_), __assign, __construct_subtree)); } else if (__src->__right_) { - auto __new_right = __construct_subtree(static_cast<__node_pointer>(__src->__right_)); - __dest->__right_ = static_cast<__node_base_pointer>(__new_right); - __new_right->__parent_ = static_cast<__end_node_pointer>(__dest); + auto __new_right = __construct_subtree(std::__static_fancy_pointer_cast<__node_pointer>(__src->__right_)); + __dest->__right_ = std::__static_fancy_pointer_cast<__node_base_pointer>(__new_right); + __new_right->__parent_ = std::__static_fancy_pointer_cast<__end_node_pointer>(__dest); } return __dest; } - _LIBCPP_HIDE_FROM_ABI __node_pointer __copy_assign_tree(__node_pointer __dest, __node_pointer __src) { + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __node_pointer + __copy_assign_tree(__node_pointer __dest, __node_pointer __src) { return __assign_from_tree( __dest, __src, @@ -1570,7 +1657,8 @@ private: [this](__node_pointer __nd) { return __copy_construct_tree(__nd); }); } - _LIBCPP_HIDE_FROM_ABI __node_pointer __move_assign_tree(__node_pointer __dest, __node_pointer __src) { + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __node_pointer + __move_assign_tree(__node_pointer __dest, __node_pointer __src) { return __assign_from_tree( __dest, __src, @@ -1589,7 +1677,8 @@ struct __specialized_algorithm<_Algorithm::__for_each, __single_range<__tree<_Tp using __node_pointer _LIBCPP_NODEBUG = typename __tree<_Tp, _Compare, _Allocator>::__node_pointer; template - _LIBCPP_HIDE_FROM_ABI static auto operator()(_Tree&& __range, _Func __func, _Proj __proj) { + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 static auto + operator()(_Tree&& __range, _Func __func, _Proj __proj) { if (__range.size() != 0) std::__tree_iterate_from_root<__copy_cvref_t<_Tree, typename __remove_cvref_t<_Tree>::value_type>>( [](__node_pointer) { return false; }, __range.__root(), __func, __proj); @@ -1599,7 +1688,8 @@ struct __specialized_algorithm<_Algorithm::__for_each, __single_range<__tree<_Tp #endif template -__tree<_Tp, _Compare, _Allocator>& __tree<_Tp, _Compare, _Allocator>::operator=(const __tree& __t) { +_LIBCPP_CONSTEXPR_SINCE_CXX26 __tree<_Tp, _Compare, _Allocator>& +__tree<_Tp, _Compare, _Allocator>::operator=(const __tree& __t) { if (this == std::addressof(__t)) return *this; @@ -1607,21 +1697,22 @@ __tree<_Tp, _Compare, _Allocator>& __tree<_Tp, _Compare, _Allocator>::operator=( __copy_assign_alloc(__t); if (__size_ != 0) { - *__root_ptr() = static_cast<__node_base_pointer>(__copy_assign_tree(__root(), __t.__root())); + *__root_ptr() = std::__static_fancy_pointer_cast<__node_base_pointer>(__copy_assign_tree(__root(), __t.__root())); } else { - *__root_ptr() = static_cast<__node_base_pointer>(__copy_construct_tree(__t.__root())); + *__root_ptr() = std::__static_fancy_pointer_cast<__node_base_pointer>(__copy_construct_tree(__t.__root())); if (__root()) __root()->__parent_ = __end_node(); } - __begin_node_ = - __end_node()->__left_ ? static_cast<__end_node_pointer>(std::__tree_min(__end_node()->__left_)) : __end_node(); + __begin_node_ = __end_node()->__left_ + ? std::__static_fancy_pointer_cast<__end_node_pointer>(std::__tree_min(__end_node()->__left_)) + : __end_node(); __size_ = __t.size(); return *this; } template -__tree<_Tp, _Compare, _Allocator>::__tree(const __tree& __t) +_LIBCPP_CONSTEXPR_SINCE_CXX26 __tree<_Tp, _Compare, _Allocator>::__tree(const __tree& __t) : __begin_node_(__end_node()), __node_alloc_(__node_traits::select_on_container_copy_construction(__t.__node_alloc())), __size_(0), @@ -1629,14 +1720,14 @@ __tree<_Tp, _Compare, _Allocator>::__tree(const __tree& __t) if (__t.size() == 0) return; - *__root_ptr() = static_cast<__node_base_pointer>(__copy_construct_tree(__t.__root())); + *__root_ptr() = std::__static_fancy_pointer_cast<__node_base_pointer>(__copy_construct_tree(__t.__root())); __root()->__parent_ = __end_node(); - __begin_node_ = static_cast<__end_node_pointer>(std::__tree_min(__end_node()->__left_)); + __begin_node_ = std::__static_fancy_pointer_cast<__end_node_pointer>(std::__tree_min(__end_node()->__left_)); __size_ = __t.size(); } template -__tree<_Tp, _Compare, _Allocator>::__tree(__tree&& __t) _NOEXCEPT_( +_LIBCPP_CONSTEXPR_SINCE_CXX26 __tree<_Tp, _Compare, _Allocator>::__tree(__tree&& __t) _NOEXCEPT_( is_nothrow_move_constructible<__node_allocator>::value&& is_nothrow_move_constructible::value) : __begin_node_(std::move(__t.__begin_node_)), __end_node_(std::move(__t.__end_node_)), @@ -1646,7 +1737,7 @@ __tree<_Tp, _Compare, _Allocator>::__tree(__tree&& __t) _NOEXCEPT_( if (__size_ == 0) __begin_node_ = __end_node(); else { - __end_node()->__left_->__parent_ = static_cast<__end_node_pointer>(__end_node()); + __end_node()->__left_->__parent_ = std::__static_fancy_pointer_cast<__end_node_pointer>(__end_node()); __t.__begin_node_ = __t.__end_node(); __t.__end_node()->__left_ = nullptr; __t.__size_ = 0; @@ -1654,7 +1745,7 @@ __tree<_Tp, _Compare, _Allocator>::__tree(__tree&& __t) _NOEXCEPT_( } template -__tree<_Tp, _Compare, _Allocator>::__tree(__tree&& __t, const allocator_type& __a) +_LIBCPP_CONSTEXPR_SINCE_CXX26 __tree<_Tp, _Compare, _Allocator>::__tree(__tree&& __t, const allocator_type& __a) : __begin_node_(__end_node()), __node_alloc_(__node_allocator(__a)), __size_(0), @@ -1664,24 +1755,24 @@ __tree<_Tp, _Compare, _Allocator>::__tree(__tree&& __t, const allocator_type& __ if (__a == __t.__alloc()) { __begin_node_ = __t.__begin_node_; __end_node()->__left_ = __t.__end_node()->__left_; - __end_node()->__left_->__parent_ = static_cast<__end_node_pointer>(__end_node()); + __end_node()->__left_->__parent_ = std::__static_fancy_pointer_cast<__end_node_pointer>(__end_node()); __size_ = __t.__size_; __t.__begin_node_ = __t.__end_node(); __t.__end_node()->__left_ = nullptr; __t.__size_ = 0; } else { - *__root_ptr() = static_cast<__node_base_pointer>(__move_construct_tree(__t.__root())); + *__root_ptr() = std::__static_fancy_pointer_cast<__node_base_pointer>(__move_construct_tree(__t.__root())); __root()->__parent_ = __end_node(); - __begin_node_ = static_cast<__end_node_pointer>(std::__tree_min(__end_node()->__left_)); + __begin_node_ = std::__static_fancy_pointer_cast<__end_node_pointer>(std::__tree_min(__end_node()->__left_)); __size_ = __t.size(); __t.clear(); // Ensure that __t is in a valid state after moving out the keys } } template -void __tree<_Tp, _Compare, _Allocator>::__move_assign(__tree& __t, true_type) +_LIBCPP_CONSTEXPR_SINCE_CXX26 void __tree<_Tp, _Compare, _Allocator>::__move_assign(__tree& __t, true_type) _NOEXCEPT_(is_nothrow_move_assignable::value&& is_nothrow_move_assignable<__node_allocator>::value) { - destroy(static_cast<__node_pointer>(__end_node()->__left_)); + destroy(std::__static_fancy_pointer_cast<__node_pointer>(__end_node()->__left_)); __begin_node_ = __t.__begin_node_; __end_node_ = __t.__end_node_; __move_assign_alloc(__t); @@ -1690,7 +1781,7 @@ void __tree<_Tp, _Compare, _Allocator>::__move_assign(__tree& __t, true_type) if (__size_ == 0) __begin_node_ = __end_node(); else { - __end_node()->__left_->__parent_ = static_cast<__end_node_pointer>(__end_node()); + __end_node()->__left_->__parent_ = std::__static_fancy_pointer_cast<__end_node_pointer>(__end_node()); __t.__begin_node_ = __t.__end_node(); __t.__end_node()->__left_ = nullptr; __t.__size_ = 0; @@ -1698,27 +1789,28 @@ void __tree<_Tp, _Compare, _Allocator>::__move_assign(__tree& __t, true_type) } template -void __tree<_Tp, _Compare, _Allocator>::__move_assign(__tree& __t, false_type) { +_LIBCPP_CONSTEXPR_SINCE_CXX26 void __tree<_Tp, _Compare, _Allocator>::__move_assign(__tree& __t, false_type) { if (__node_alloc() == __t.__node_alloc()) { __move_assign(__t, true_type()); } else { value_comp() = std::move(__t.value_comp()); if (__size_ != 0) { - *__root_ptr() = static_cast<__node_base_pointer>(__move_assign_tree(__root(), __t.__root())); + *__root_ptr() = std::__static_fancy_pointer_cast<__node_base_pointer>(__move_assign_tree(__root(), __t.__root())); } else { - *__root_ptr() = static_cast<__node_base_pointer>(__move_construct_tree(__t.__root())); + *__root_ptr() = std::__static_fancy_pointer_cast<__node_base_pointer>(__move_construct_tree(__t.__root())); if (__root()) __root()->__parent_ = __end_node(); } - __begin_node_ = - __end_node()->__left_ ? static_cast<__end_node_pointer>(std::__tree_min(__end_node()->__left_)) : __end_node(); + __begin_node_ = __end_node()->__left_ + ? std::__static_fancy_pointer_cast<__end_node_pointer>(std::__tree_min(__end_node()->__left_)) + : __end_node(); __size_ = __t.size(); __t.clear(); // Ensure that __t is in a valid state after moving out the keys } } template -void __tree<_Tp, _Compare, _Allocator>::swap(__tree& __t) +_LIBCPP_CONSTEXPR_SINCE_CXX26 void __tree<_Tp, _Compare, _Allocator>::swap(__tree& __t) #if _LIBCPP_STD_VER <= 11 _NOEXCEPT_(__is_nothrow_swappable_v && (!__node_traits::propagate_on_container_swap::value || __is_nothrow_swappable_v<__node_allocator>)) @@ -1743,7 +1835,7 @@ void __tree<_Tp, _Compare, _Allocator>::swap(__tree& __t) } template -void __tree<_Tp, _Compare, _Allocator>::clear() _NOEXCEPT { +_LIBCPP_CONSTEXPR_SINCE_CXX26 void __tree<_Tp, _Compare, _Allocator>::clear() _NOEXCEPT { destroy(__root()); __size_ = 0; __begin_node_ = __end_node(); @@ -1754,23 +1846,23 @@ void __tree<_Tp, _Compare, _Allocator>::clear() _NOEXCEPT { // Set __parent to parent of null leaf // Return reference to null leaf template -typename __tree<_Tp, _Compare, _Allocator>::__node_base_pointer& +_LIBCPP_CONSTEXPR_SINCE_CXX26 typename __tree<_Tp, _Compare, _Allocator>::__node_base_pointer& __tree<_Tp, _Compare, _Allocator>::__find_leaf_low(__end_node_pointer& __parent, const value_type& __v) { __node_pointer __nd = __root(); if (__nd != nullptr) { while (true) { if (value_comp()(__nd->__get_value(), __v)) { if (__nd->__right_ != nullptr) - __nd = static_cast<__node_pointer>(__nd->__right_); + __nd = std::__static_fancy_pointer_cast<__node_pointer>(__nd->__right_); else { - __parent = static_cast<__end_node_pointer>(__nd); + __parent = std::__static_fancy_pointer_cast<__end_node_pointer>(__nd); return __nd->__right_; } } else { if (__nd->__left_ != nullptr) - __nd = static_cast<__node_pointer>(__nd->__left_); + __nd = std::__static_fancy_pointer_cast<__node_pointer>(__nd->__left_); else { - __parent = static_cast<__end_node_pointer>(__nd); + __parent = std::__static_fancy_pointer_cast<__end_node_pointer>(__nd); return __parent->__left_; } } @@ -1784,23 +1876,23 @@ __tree<_Tp, _Compare, _Allocator>::__find_leaf_low(__end_node_pointer& __parent, // Set __parent to parent of null leaf // Return reference to null leaf template -typename __tree<_Tp, _Compare, _Allocator>::__node_base_pointer& +_LIBCPP_CONSTEXPR_SINCE_CXX26 typename __tree<_Tp, _Compare, _Allocator>::__node_base_pointer& __tree<_Tp, _Compare, _Allocator>::__find_leaf_high(__end_node_pointer& __parent, const value_type& __v) { __node_pointer __nd = __root(); if (__nd != nullptr) { while (true) { if (value_comp()(__v, __nd->__get_value())) { if (__nd->__left_ != nullptr) - __nd = static_cast<__node_pointer>(__nd->__left_); + __nd = std::__static_fancy_pointer_cast<__node_pointer>(__nd->__left_); else { - __parent = static_cast<__end_node_pointer>(__nd); + __parent = std::__static_fancy_pointer_cast<__end_node_pointer>(__nd); return __parent->__left_; } } else { if (__nd->__right_ != nullptr) - __nd = static_cast<__node_pointer>(__nd->__right_); + __nd = std::__static_fancy_pointer_cast<__node_pointer>(__nd->__right_); else { - __parent = static_cast<__end_node_pointer>(__nd); + __parent = std::__static_fancy_pointer_cast<__end_node_pointer>(__nd); return __nd->__right_; } } @@ -1817,7 +1909,8 @@ __tree<_Tp, _Compare, _Allocator>::__find_leaf_high(__end_node_pointer& __parent // Set __parent to parent of null leaf // Return reference to null leaf template -typename __tree<_Tp, _Compare, _Allocator>::__node_base_pointer& __tree<_Tp, _Compare, _Allocator>::__find_leaf( +_LIBCPP_CONSTEXPR_SINCE_CXX26 typename __tree<_Tp, _Compare, _Allocator>::__node_base_pointer& +__tree<_Tp, _Compare, _Allocator>::__find_leaf( const_iterator __hint, __end_node_pointer& __parent, const value_type& __v) { if (__hint == end() || !value_comp()(*__hint, __v)) // check before { @@ -1826,11 +1919,11 @@ typename __tree<_Tp, _Compare, _Allocator>::__node_base_pointer& __tree<_Tp, _Co if (__prior == begin() || !value_comp()(__v, *--__prior)) { // *prev(__hint) <= __v <= *__hint if (__hint.__ptr_->__left_ == nullptr) { - __parent = static_cast<__end_node_pointer>(__hint.__ptr_); + __parent = std::__static_fancy_pointer_cast<__end_node_pointer>(__hint.__ptr_); return __parent->__left_; } else { - __parent = static_cast<__end_node_pointer>(__prior.__ptr_); - return static_cast<__node_base_pointer>(__prior.__ptr_)->__right_; + __parent = std::__static_fancy_pointer_cast<__end_node_pointer>(__prior.__ptr_); + return std::__static_fancy_pointer_cast<__node_base_pointer>(__prior.__ptr_)->__right_; } } // __v < *prev(__hint) @@ -1845,8 +1938,9 @@ typename __tree<_Tp, _Compare, _Allocator>::__node_base_pointer& __tree<_Tp, _Co // If __v doesn't exist, return the parent of the null leaf and a reference to the pointer to the null leaf. template template -_LIBCPP_HIDE_FROM_ABI pair::__end_node_pointer, - typename __tree<_Tp, _Compare, _Allocator>::__node_base_pointer&> +_LIBCPP_HIDE_FROM_ABI +_LIBCPP_CONSTEXPR_SINCE_CXX26 pair::__end_node_pointer, + typename __tree<_Tp, _Compare, _Allocator>::__node_base_pointer&> __tree<_Tp, _Compare, _Allocator>::__find_equal(const _Key& __v) { using _Pair = pair<__end_node_pointer, __node_base_pointer&>; @@ -1858,27 +1952,27 @@ __tree<_Tp, _Compare, _Allocator>::__find_equal(const _Key& __v) { } __node_base_pointer* __node_ptr = __root_ptr(); - auto&& __transparent = std::__as_transparent<_Key>(value_comp()); + auto&& __transparent = std::__as_transparent(value_comp()); auto __comp = - __lazy_synth_three_way_comparator<__make_transparent_t<_Key, _Compare>, _Key, value_type>(__transparent); + __lazy_synth_three_way_comparator<__make_transparent_t, _Key, value_type>(__transparent); while (true) { auto __comp_res = __comp(__v, __nd->__get_value()); if (__comp_res.__less()) { if (__nd->__left_ == nullptr) - return _Pair(static_cast<__end_node_pointer>(__nd), __nd->__left_); + return _Pair(std::__static_fancy_pointer_cast<__end_node_pointer>(__nd), __nd->__left_); __node_ptr = std::addressof(__nd->__left_); - __nd = static_cast<__node_pointer>(__nd->__left_); + __nd = std::__static_fancy_pointer_cast<__node_pointer>(__nd->__left_); } else if (__comp_res.__greater()) { if (__nd->__right_ == nullptr) - return _Pair(static_cast<__end_node_pointer>(__nd), __nd->__right_); + return _Pair(std::__static_fancy_pointer_cast<__end_node_pointer>(__nd), __nd->__right_); __node_ptr = std::addressof(__nd->__right_); - __nd = static_cast<__node_pointer>(__nd->__right_); + __nd = std::__static_fancy_pointer_cast<__node_pointer>(__nd->__right_); } else { - return _Pair(static_cast<__end_node_pointer>(__nd), *__node_ptr); + return _Pair(std::__static_fancy_pointer_cast<__end_node_pointer>(__nd), *__node_ptr); } } } @@ -1891,8 +1985,9 @@ __tree<_Tp, _Compare, _Allocator>::__find_equal(const _Key& __v) { // If __v doesn't exist, return the parent of the null leaf and a reference to the pointer to the null leaf. template template -_LIBCPP_HIDE_FROM_ABI pair::__end_node_pointer, - typename __tree<_Tp, _Compare, _Allocator>::__node_base_pointer&> +_LIBCPP_HIDE_FROM_ABI +_LIBCPP_CONSTEXPR_SINCE_CXX26 pair::__end_node_pointer, + typename __tree<_Tp, _Compare, _Allocator>::__node_base_pointer&> __tree<_Tp, _Compare, _Allocator>::__find_equal(const_iterator __hint, __node_base_pointer& __dummy, const _Key& __v) { using _Pair = pair<__end_node_pointer, __node_base_pointer&>; @@ -1903,7 +1998,7 @@ __tree<_Tp, _Compare, _Allocator>::__find_equal(const_iterator __hint, __node_ba // *prev(__hint) < __v < *__hint if (__hint.__ptr_->__left_ == nullptr) return _Pair(__hint.__ptr_, __hint.__ptr_->__left_); - return _Pair(__prior.__ptr_, static_cast<__node_pointer>(__prior.__ptr_)->__right_); + return _Pair(__prior.__ptr_, std::__static_fancy_pointer_cast<__node_pointer>(__prior.__ptr_)->__right_); } // __v <= *prev(__hint) return __find_equal(__v); @@ -1915,7 +2010,7 @@ __tree<_Tp, _Compare, _Allocator>::__find_equal(const_iterator __hint, __node_ba if (__next == end() || value_comp()(__v, *__next)) { // *__hint < __v < *std::next(__hint) if (__hint.__get_np()->__right_ == nullptr) - return _Pair(__hint.__ptr_, static_cast<__node_pointer>(__hint.__ptr_)->__right_); + return _Pair(__hint.__ptr_, std::__static_fancy_pointer_cast<__node_pointer>(__hint.__ptr_)->__right_); return _Pair(__next.__ptr_, __next.__ptr_->__left_); } // *next(__hint) <= __v @@ -1923,12 +2018,12 @@ __tree<_Tp, _Compare, _Allocator>::__find_equal(const_iterator __hint, __node_ba } // else __v == *__hint - __dummy = static_cast<__node_base_pointer>(__hint.__ptr_); + __dummy = std::__static_fancy_pointer_cast<__node_base_pointer>(__hint.__ptr_); return _Pair(__hint.__ptr_, __dummy); } template -void __tree<_Tp, _Compare, _Allocator>::__insert_node_at( +_LIBCPP_CONSTEXPR_SINCE_CXX26 void __tree<_Tp, _Compare, _Allocator>::__insert_node_at( __end_node_pointer __parent, __node_base_pointer& __child, __node_base_pointer __new_node) _NOEXCEPT { __new_node->__left_ = nullptr; __new_node->__right_ = nullptr; @@ -1936,14 +2031,14 @@ void __tree<_Tp, _Compare, _Allocator>::__insert_node_at( // __new_node->__is_black_ is initialized in __tree_balance_after_insert __child = __new_node; if (__begin_node_->__left_ != nullptr) - __begin_node_ = static_cast<__end_node_pointer>(__begin_node_->__left_); + __begin_node_ = std::__static_fancy_pointer_cast<__end_node_pointer>(__begin_node_->__left_); std::__tree_balance_after_insert(__end_node()->__left_, __child); ++__size_; } template template -typename __tree<_Tp, _Compare, _Allocator>::__node_holder +_LIBCPP_CONSTEXPR_SINCE_CXX26 typename __tree<_Tp, _Compare, _Allocator>::__node_holder __tree<_Tp, _Compare, _Allocator>::__construct_node(_Args&&... __args) { __node_allocator& __na = __node_alloc(); __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na)); @@ -1954,42 +2049,42 @@ __tree<_Tp, _Compare, _Allocator>::__construct_node(_Args&&... __args) { template template -typename __tree<_Tp, _Compare, _Allocator>::iterator +typename __tree<_Tp, _Compare, _Allocator>::iterator _LIBCPP_CONSTEXPR_SINCE_CXX26 __tree<_Tp, _Compare, _Allocator>::__emplace_multi(_Args&&... __args) { __node_holder __h = __construct_node(std::forward<_Args>(__args)...); __end_node_pointer __parent; __node_base_pointer& __child = __find_leaf_high(__parent, __h->__get_value()); - __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get())); - return iterator(static_cast<__node_pointer>(__h.release())); + __insert_node_at(__parent, __child, std::__static_fancy_pointer_cast<__node_base_pointer>(__h.get())); + return iterator(std::__static_fancy_pointer_cast<__node_pointer>(__h.release())); } template template -typename __tree<_Tp, _Compare, _Allocator>::iterator +typename __tree<_Tp, _Compare, _Allocator>::iterator _LIBCPP_CONSTEXPR_SINCE_CXX26 __tree<_Tp, _Compare, _Allocator>::__emplace_hint_multi(const_iterator __p, _Args&&... __args) { __node_holder __h = __construct_node(std::forward<_Args>(__args)...); __end_node_pointer __parent; __node_base_pointer& __child = __find_leaf(__p, __parent, __h->__get_value()); - __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get())); - return iterator(static_cast<__node_pointer>(__h.release())); + __insert_node_at(__parent, __child, std::__static_fancy_pointer_cast<__node_base_pointer>(__h.get())); + return iterator(std::__static_fancy_pointer_cast<__node_pointer>(__h.release())); } template -typename __tree<_Tp, _Compare, _Allocator>::iterator +typename __tree<_Tp, _Compare, _Allocator>::iterator _LIBCPP_CONSTEXPR_SINCE_CXX26 __tree<_Tp, _Compare, _Allocator>::__remove_node_pointer(__node_pointer __ptr) _NOEXCEPT { iterator __r(__ptr); ++__r; if (__begin_node_ == __ptr) __begin_node_ = __r.__ptr_; --__size_; - std::__tree_remove(__end_node()->__left_, static_cast<__node_base_pointer>(__ptr)); + std::__tree_remove(__end_node()->__left_, std::__static_fancy_pointer_cast<__node_base_pointer>(__ptr)); return __r; } #if _LIBCPP_STD_VER >= 17 template template -_LIBCPP_HIDE_FROM_ABI _InsertReturnType +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 _InsertReturnType __tree<_Tp, _Compare, _Allocator>::__node_handle_insert_unique(_NodeHandle&& __nh) { if (__nh.empty()) return _InsertReturnType{end(), false, _NodeHandle()}; @@ -1997,16 +2092,17 @@ __tree<_Tp, _Compare, _Allocator>::__node_handle_insert_unique(_NodeHandle&& __n __node_pointer __ptr = __nh.__ptr_; auto [__parent, __child] = __find_equal(__ptr->__get_value()); if (__child != nullptr) - return _InsertReturnType{iterator(static_cast<__node_pointer>(__child)), false, std::move(__nh)}; + return _InsertReturnType{ + iterator(std::__static_fancy_pointer_cast<__node_pointer>(__child)), false, std::move(__nh)}; - __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__ptr)); + __insert_node_at(__parent, __child, std::__static_fancy_pointer_cast<__node_base_pointer>(__ptr)); __nh.__release_ptr(); return _InsertReturnType{iterator(__ptr), true, _NodeHandle()}; } template template -_LIBCPP_HIDE_FROM_ABI typename __tree<_Tp, _Compare, _Allocator>::iterator +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 typename __tree<_Tp, _Compare, _Allocator>::iterator __tree<_Tp, _Compare, _Allocator>::__node_handle_insert_unique(const_iterator __hint, _NodeHandle&& __nh) { if (__nh.empty()) return end(); @@ -2014,9 +2110,9 @@ __tree<_Tp, _Compare, _Allocator>::__node_handle_insert_unique(const_iterator __ __node_pointer __ptr = __nh.__ptr_; __node_base_pointer __dummy; auto [__parent, __child] = __find_equal(__hint, __dummy, __ptr->__get_value()); - __node_pointer __r = static_cast<__node_pointer>(__child); + __node_pointer __r = std::__static_fancy_pointer_cast<__node_pointer>(__child); if (__child == nullptr) { - __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__ptr)); + __insert_node_at(__parent, __child, std::__static_fancy_pointer_cast<__node_base_pointer>(__ptr)); __r = __ptr; __nh.__release_ptr(); } @@ -2025,7 +2121,8 @@ __tree<_Tp, _Compare, _Allocator>::__node_handle_insert_unique(const_iterator __ template template -_LIBCPP_HIDE_FROM_ABI _NodeHandle __tree<_Tp, _Compare, _Allocator>::__node_handle_extract(key_type const& __key) { +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 _NodeHandle +__tree<_Tp, _Compare, _Allocator>::__node_handle_extract(key_type const& __key) { iterator __it = __lower_bound_multi(__key); if (__it == end() || __value_comp_(__key, *__it)) return _NodeHandle(); @@ -2034,7 +2131,8 @@ _LIBCPP_HIDE_FROM_ABI _NodeHandle __tree<_Tp, _Compare, _Allocator>::__node_hand template template -_LIBCPP_HIDE_FROM_ABI _NodeHandle __tree<_Tp, _Compare, _Allocator>::__node_handle_extract(const_iterator __p) { +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 _NodeHandle +__tree<_Tp, _Compare, _Allocator>::__node_handle_extract(const_iterator __p) { __node_pointer __np = __p.__get_np(); __remove_node_pointer(__np); return _NodeHandle(__np, __alloc()); @@ -2042,7 +2140,7 @@ _LIBCPP_HIDE_FROM_ABI _NodeHandle __tree<_Tp, _Compare, _Allocator>::__node_hand template template -_LIBCPP_HIDE_FROM_ABI void +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void __tree<_Tp, _Compare, _Allocator>::__node_handle_merge_unique(__tree<_Tp, _Comp2, _Allocator>& __source) { for (iterator __i = __source.begin(); __i != __source.end();) { __node_pointer __src_ptr = __i.__get_np(); @@ -2051,27 +2149,27 @@ __tree<_Tp, _Compare, _Allocator>::__node_handle_merge_unique(__tree<_Tp, _Comp2 if (__child != nullptr) continue; __source.__remove_node_pointer(__src_ptr); - __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__src_ptr)); + __insert_node_at(__parent, __child, std::__static_fancy_pointer_cast<__node_base_pointer>(__src_ptr)); } } template template -_LIBCPP_HIDE_FROM_ABI typename __tree<_Tp, _Compare, _Allocator>::iterator +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 typename __tree<_Tp, _Compare, _Allocator>::iterator __tree<_Tp, _Compare, _Allocator>::__node_handle_insert_multi(_NodeHandle&& __nh) { if (__nh.empty()) return end(); __node_pointer __ptr = __nh.__ptr_; __end_node_pointer __parent; __node_base_pointer& __child = __find_leaf_high(__parent, __ptr->__get_value()); - __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__ptr)); + __insert_node_at(__parent, __child, std::__static_fancy_pointer_cast<__node_base_pointer>(__ptr)); __nh.__release_ptr(); return iterator(__ptr); } template template -_LIBCPP_HIDE_FROM_ABI typename __tree<_Tp, _Compare, _Allocator>::iterator +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 typename __tree<_Tp, _Compare, _Allocator>::iterator __tree<_Tp, _Compare, _Allocator>::__node_handle_insert_multi(const_iterator __hint, _NodeHandle&& __nh) { if (__nh.empty()) return end(); @@ -2079,14 +2177,14 @@ __tree<_Tp, _Compare, _Allocator>::__node_handle_insert_multi(const_iterator __h __node_pointer __ptr = __nh.__ptr_; __end_node_pointer __parent; __node_base_pointer& __child = __find_leaf(__hint, __parent, __ptr->__get_value()); - __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__ptr)); + __insert_node_at(__parent, __child, std::__static_fancy_pointer_cast<__node_base_pointer>(__ptr)); __nh.__release_ptr(); return iterator(__ptr); } template template -_LIBCPP_HIDE_FROM_ABI void +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void __tree<_Tp, _Compare, _Allocator>::__node_handle_merge_multi(__tree<_Tp, _Comp2, _Allocator>& __source) { for (iterator __i = __source.begin(); __i != __source.end();) { __node_pointer __src_ptr = __i.__get_np(); @@ -2094,14 +2192,14 @@ __tree<_Tp, _Compare, _Allocator>::__node_handle_merge_multi(__tree<_Tp, _Comp2, __node_base_pointer& __child = __find_leaf_high(__parent, __src_ptr->__get_value()); ++__i; __source.__remove_node_pointer(__src_ptr); - __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__src_ptr)); + __insert_node_at(__parent, __child, std::__static_fancy_pointer_cast<__node_base_pointer>(__src_ptr)); } } - #endif // _LIBCPP_STD_VER >= 17 template -typename __tree<_Tp, _Compare, _Allocator>::iterator __tree<_Tp, _Compare, _Allocator>::erase(const_iterator __p) { +_LIBCPP_CONSTEXPR_SINCE_CXX26 + typename __tree<_Tp, _Compare, _Allocator>::iterator __tree<_Tp, _Compare, _Allocator>::erase(const_iterator __p) { __node_pointer __np = __p.__get_np(); iterator __r = __remove_node_pointer(__np); __node_allocator& __na = __node_alloc(); @@ -2111,7 +2209,7 @@ typename __tree<_Tp, _Compare, _Allocator>::iterator __tree<_Tp, _Compare, _Allo } template -typename __tree<_Tp, _Compare, _Allocator>::iterator +_LIBCPP_CONSTEXPR_SINCE_CXX26 typename __tree<_Tp, _Compare, _Allocator>::iterator __tree<_Tp, _Compare, _Allocator>::erase(const_iterator __f, const_iterator __l) { while (__f != __l) __f = erase(__f); @@ -2120,7 +2218,7 @@ __tree<_Tp, _Compare, _Allocator>::erase(const_iterator __f, const_iterator __l) template template -typename __tree<_Tp, _Compare, _Allocator>::size_type +_LIBCPP_CONSTEXPR_SINCE_CXX26 typename __tree<_Tp, _Compare, _Allocator>::size_type __tree<_Tp, _Compare, _Allocator>::__erase_unique(const _Key& __k) { iterator __i = find(__k); if (__i == end()) @@ -2131,7 +2229,7 @@ __tree<_Tp, _Compare, _Allocator>::__erase_unique(const _Key& __k) { template template -typename __tree<_Tp, _Compare, _Allocator>::size_type +_LIBCPP_CONSTEXPR_SINCE_CXX26 typename __tree<_Tp, _Compare, _Allocator>::size_type __tree<_Tp, _Compare, _Allocator>::__erase_multi(const _Key& __k) { pair __p = __equal_range_multi(__k); size_type __r = 0; @@ -2142,16 +2240,16 @@ __tree<_Tp, _Compare, _Allocator>::__erase_multi(const _Key& __k) { template template -typename __tree<_Tp, _Compare, _Allocator>::size_type +_LIBCPP_CONSTEXPR_SINCE_CXX26 typename __tree<_Tp, _Compare, _Allocator>::size_type __tree<_Tp, _Compare, _Allocator>::__count_unique(const _Key& __k) const { __node_pointer __rt = __root(); auto __comp = __lazy_synth_three_way_comparator(value_comp()); while (__rt != nullptr) { auto __comp_res = __comp(__k, __rt->__get_value()); if (__comp_res.__less()) { - __rt = static_cast<__node_pointer>(__rt->__left_); + __rt = std::__static_fancy_pointer_cast<__node_pointer>(__rt->__left_); } else if (__comp_res.__greater()) - __rt = static_cast<__node_pointer>(__rt->__right_); + __rt = std::__static_fancy_pointer_cast<__node_pointer>(__rt->__right_); else return 1; } @@ -2160,7 +2258,7 @@ __tree<_Tp, _Compare, _Allocator>::__count_unique(const _Key& __k) const { template template -typename __tree<_Tp, _Compare, _Allocator>::size_type +_LIBCPP_CONSTEXPR_SINCE_CXX26 typename __tree<_Tp, _Compare, _Allocator>::size_type __tree<_Tp, _Compare, _Allocator>::__count_multi(const _Key& __k) const { __end_node_pointer __result = __end_node(); __node_pointer __rt = __root(); @@ -2168,78 +2266,85 @@ __tree<_Tp, _Compare, _Allocator>::__count_multi(const _Key& __k) const { while (__rt != nullptr) { auto __comp_res = __comp(__k, __rt->__get_value()); if (__comp_res.__less()) { - __result = static_cast<__end_node_pointer>(__rt); - __rt = static_cast<__node_pointer>(__rt->__left_); + __result = std::__static_fancy_pointer_cast<__end_node_pointer>(__rt); + __rt = std::__static_fancy_pointer_cast<__node_pointer>(__rt->__left_); } else if (__comp_res.__greater()) - __rt = static_cast<__node_pointer>(__rt->__right_); + __rt = std::__static_fancy_pointer_cast<__node_pointer>(__rt->__right_); else return std::distance( - __lower_bound_multi(__k, static_cast<__node_pointer>(__rt->__left_), static_cast<__end_node_pointer>(__rt)), - __upper_bound_multi(__k, static_cast<__node_pointer>(__rt->__right_), __result)); + __lower_bound_multi(__k, + std::__static_fancy_pointer_cast<__node_pointer>(__rt->__left_), + std::__static_fancy_pointer_cast<__end_node_pointer>(__rt)), + __upper_bound_multi(__k, std::__static_fancy_pointer_cast<__node_pointer>(__rt->__right_), __result)); } return 0; } template template -typename __tree<_Tp, _Compare, _Allocator>::iterator __tree<_Tp, _Compare, _Allocator>::__lower_bound_multi( +_LIBCPP_CONSTEXPR_SINCE_CXX26 typename __tree<_Tp, _Compare, _Allocator>::iterator +__tree<_Tp, _Compare, _Allocator>::__lower_bound_multi( const _Key& __v, __node_pointer __root, __end_node_pointer __result) { while (__root != nullptr) { if (!value_comp()(__root->__get_value(), __v)) { - __result = static_cast<__end_node_pointer>(__root); - __root = static_cast<__node_pointer>(__root->__left_); + __result = std::__static_fancy_pointer_cast<__end_node_pointer>(__root); + __root = std::__static_fancy_pointer_cast<__node_pointer>(__root->__left_); } else - __root = static_cast<__node_pointer>(__root->__right_); + __root = std::__static_fancy_pointer_cast<__node_pointer>(__root->__right_); } return iterator(__result); } template template -typename __tree<_Tp, _Compare, _Allocator>::const_iterator __tree<_Tp, _Compare, _Allocator>::__lower_bound_multi( +_LIBCPP_CONSTEXPR_SINCE_CXX26 typename __tree<_Tp, _Compare, _Allocator>::const_iterator +__tree<_Tp, _Compare, _Allocator>::__lower_bound_multi( const _Key& __v, __node_pointer __root, __end_node_pointer __result) const { while (__root != nullptr) { if (!value_comp()(__root->__get_value(), __v)) { - __result = static_cast<__end_node_pointer>(__root); - __root = static_cast<__node_pointer>(__root->__left_); + __result = std::__static_fancy_pointer_cast<__end_node_pointer>(__root); + __root = std::__static_fancy_pointer_cast<__node_pointer>(__root->__left_); } else - __root = static_cast<__node_pointer>(__root->__right_); + __root = std::__static_fancy_pointer_cast<__node_pointer>(__root->__right_); } return const_iterator(__result); } template template -typename __tree<_Tp, _Compare, _Allocator>::iterator __tree<_Tp, _Compare, _Allocator>::__upper_bound_multi( +_LIBCPP_CONSTEXPR_SINCE_CXX26 typename __tree<_Tp, _Compare, _Allocator>::iterator +__tree<_Tp, _Compare, _Allocator>::__upper_bound_multi( const _Key& __v, __node_pointer __root, __end_node_pointer __result) { while (__root != nullptr) { if (value_comp()(__v, __root->__get_value())) { - __result = static_cast<__end_node_pointer>(__root); - __root = static_cast<__node_pointer>(__root->__left_); + __result = std::__static_fancy_pointer_cast<__end_node_pointer>(__root); + __root = std::__static_fancy_pointer_cast<__node_pointer>(__root->__left_); } else - __root = static_cast<__node_pointer>(__root->__right_); + __root = std::__static_fancy_pointer_cast<__node_pointer>(__root->__right_); } return iterator(__result); } template template -typename __tree<_Tp, _Compare, _Allocator>::const_iterator __tree<_Tp, _Compare, _Allocator>::__upper_bound_multi( +_LIBCPP_CONSTEXPR_SINCE_CXX26 typename __tree<_Tp, _Compare, _Allocator>::const_iterator +__tree<_Tp, _Compare, _Allocator>::__upper_bound_multi( const _Key& __v, __node_pointer __root, __end_node_pointer __result) const { while (__root != nullptr) { if (value_comp()(__v, __root->__get_value())) { - __result = static_cast<__end_node_pointer>(__root); - __root = static_cast<__node_pointer>(__root->__left_); + __result = std::__static_fancy_pointer_cast<__end_node_pointer>(__root); + __root = std::__static_fancy_pointer_cast<__node_pointer>(__root->__left_); } else - __root = static_cast<__node_pointer>(__root->__right_); + __root = std::__static_fancy_pointer_cast<__node_pointer>(__root->__right_); } return const_iterator(__result); } template template -pair::iterator, typename __tree<_Tp, _Compare, _Allocator>::iterator> -__tree<_Tp, _Compare, _Allocator>::__equal_range_unique(const _Key& __k) { +_LIBCPP_CONSTEXPR_SINCE_CXX26 + pair::iterator, typename __tree<_Tp, _Compare, _Allocator>::iterator> + __tree<_Tp, _Compare, _Allocator>::__equal_range_unique(const _Key& __k) { using _Pp = pair; __end_node_pointer __result = __end_node(); __node_pointer __rt = __root(); @@ -2247,22 +2352,23 @@ __tree<_Tp, _Compare, _Allocator>::__equal_range_unique(const _Key& __k) { while (__rt != nullptr) { auto __comp_res = __comp(__k, __rt->__get_value()); if (__comp_res.__less()) { - __result = static_cast<__end_node_pointer>(__rt); - __rt = static_cast<__node_pointer>(__rt->__left_); + __result = std::__static_fancy_pointer_cast<__end_node_pointer>(__rt); + __rt = std::__static_fancy_pointer_cast<__node_pointer>(__rt->__left_); } else if (__comp_res.__greater()) - __rt = static_cast<__node_pointer>(__rt->__right_); + __rt = std::__static_fancy_pointer_cast<__node_pointer>(__rt->__right_); else return _Pp(iterator(__rt), - iterator(__rt->__right_ != nullptr ? static_cast<__end_node_pointer>(std::__tree_min(__rt->__right_)) - : __result)); + iterator(__rt->__right_ != nullptr + ? std::__static_fancy_pointer_cast<__end_node_pointer>(std::__tree_min(__rt->__right_)) + : __result)); } return _Pp(iterator(__result), iterator(__result)); } template template -pair::const_iterator, - typename __tree<_Tp, _Compare, _Allocator>::const_iterator> +_LIBCPP_CONSTEXPR_SINCE_CXX26 pair::const_iterator, + typename __tree<_Tp, _Compare, _Allocator>::const_iterator> __tree<_Tp, _Compare, _Allocator>::__equal_range_unique(const _Key& __k) const { using _Pp = pair; __end_node_pointer __result = __end_node(); @@ -2271,23 +2377,25 @@ __tree<_Tp, _Compare, _Allocator>::__equal_range_unique(const _Key& __k) const { while (__rt != nullptr) { auto __comp_res = __comp(__k, __rt->__get_value()); if (__comp_res.__less()) { - __result = static_cast<__end_node_pointer>(__rt); - __rt = static_cast<__node_pointer>(__rt->__left_); + __result = std::__static_fancy_pointer_cast<__end_node_pointer>(__rt); + __rt = std::__static_fancy_pointer_cast<__node_pointer>(__rt->__left_); } else if (__comp_res.__greater()) - __rt = static_cast<__node_pointer>(__rt->__right_); + __rt = std::__static_fancy_pointer_cast<__node_pointer>(__rt->__right_); else return _Pp( const_iterator(__rt), - const_iterator( - __rt->__right_ != nullptr ? static_cast<__end_node_pointer>(std::__tree_min(__rt->__right_)) : __result)); + const_iterator(__rt->__right_ != nullptr + ? std::__static_fancy_pointer_cast<__end_node_pointer>(std::__tree_min(__rt->__right_)) + : __result)); } return _Pp(const_iterator(__result), const_iterator(__result)); } template template -pair::iterator, typename __tree<_Tp, _Compare, _Allocator>::iterator> -__tree<_Tp, _Compare, _Allocator>::__equal_range_multi(const _Key& __k) { +_LIBCPP_CONSTEXPR_SINCE_CXX26 + pair::iterator, typename __tree<_Tp, _Compare, _Allocator>::iterator> + __tree<_Tp, _Compare, _Allocator>::__equal_range_multi(const _Key& __k) { using _Pp = pair; __end_node_pointer __result = __end_node(); __node_pointer __rt = __root(); @@ -2295,22 +2403,23 @@ __tree<_Tp, _Compare, _Allocator>::__equal_range_multi(const _Key& __k) { while (__rt != nullptr) { auto __comp_res = __comp(__k, __rt->__get_value()); if (__comp_res.__less()) { - __result = static_cast<__end_node_pointer>(__rt); - __rt = static_cast<__node_pointer>(__rt->__left_); + __result = std::__static_fancy_pointer_cast<__end_node_pointer>(__rt); + __rt = std::__static_fancy_pointer_cast<__node_pointer>(__rt->__left_); } else if (__comp_res.__greater()) - __rt = static_cast<__node_pointer>(__rt->__right_); + __rt = std::__static_fancy_pointer_cast<__node_pointer>(__rt->__right_); else - return _Pp( - __lower_bound_multi(__k, static_cast<__node_pointer>(__rt->__left_), static_cast<__end_node_pointer>(__rt)), - __upper_bound_multi(__k, static_cast<__node_pointer>(__rt->__right_), __result)); + return _Pp(__lower_bound_multi(__k, + std::__static_fancy_pointer_cast<__node_pointer>(__rt->__left_), + std::__static_fancy_pointer_cast<__end_node_pointer>(__rt)), + __upper_bound_multi(__k, std::__static_fancy_pointer_cast<__node_pointer>(__rt->__right_), __result)); } return _Pp(iterator(__result), iterator(__result)); } template template -pair::const_iterator, - typename __tree<_Tp, _Compare, _Allocator>::const_iterator> +_LIBCPP_CONSTEXPR_SINCE_CXX26 pair::const_iterator, + typename __tree<_Tp, _Compare, _Allocator>::const_iterator> __tree<_Tp, _Compare, _Allocator>::__equal_range_multi(const _Key& __k) const { using _Pp = pair; __end_node_pointer __result = __end_node(); @@ -2319,35 +2428,37 @@ __tree<_Tp, _Compare, _Allocator>::__equal_range_multi(const _Key& __k) const { while (__rt != nullptr) { auto __comp_res = __comp(__k, __rt->__get_value()); if (__comp_res.__less()) { - __result = static_cast<__end_node_pointer>(__rt); - __rt = static_cast<__node_pointer>(__rt->__left_); + __result = std::__static_fancy_pointer_cast<__end_node_pointer>(__rt); + __rt = std::__static_fancy_pointer_cast<__node_pointer>(__rt->__left_); } else if (__comp_res.__greater()) - __rt = static_cast<__node_pointer>(__rt->__right_); + __rt = std::__static_fancy_pointer_cast<__node_pointer>(__rt->__right_); else - return _Pp( - __lower_bound_multi(__k, static_cast<__node_pointer>(__rt->__left_), static_cast<__end_node_pointer>(__rt)), - __upper_bound_multi(__k, static_cast<__node_pointer>(__rt->__right_), __result)); + return _Pp(__lower_bound_multi(__k, + std::__static_fancy_pointer_cast<__node_pointer>(__rt->__left_), + std::__static_fancy_pointer_cast<__end_node_pointer>(__rt)), + __upper_bound_multi(__k, std::__static_fancy_pointer_cast<__node_pointer>(__rt->__right_), __result)); } return _Pp(const_iterator(__result), const_iterator(__result)); } template -typename __tree<_Tp, _Compare, _Allocator>::__node_holder +_LIBCPP_CONSTEXPR_SINCE_CXX26 typename __tree<_Tp, _Compare, _Allocator>::__node_holder __tree<_Tp, _Compare, _Allocator>::remove(const_iterator __p) _NOEXCEPT { __node_pointer __np = __p.__get_np(); if (__begin_node_ == __p.__ptr_) { if (__np->__right_ != nullptr) - __begin_node_ = static_cast<__end_node_pointer>(__np->__right_); + __begin_node_ = std::__static_fancy_pointer_cast<__end_node_pointer>(__np->__right_); else - __begin_node_ = static_cast<__end_node_pointer>(__np->__parent_); + __begin_node_ = std::__static_fancy_pointer_cast<__end_node_pointer>(__np->__parent_); } --__size_; - std::__tree_remove(__end_node()->__left_, static_cast<__node_base_pointer>(__np)); + std::__tree_remove(__end_node()->__left_, std::__static_fancy_pointer_cast<__node_base_pointer>(__np)); return __node_holder(__np, _Dp(__node_alloc(), true)); } template -inline _LIBCPP_HIDE_FROM_ABI void swap(__tree<_Tp, _Compare, _Allocator>& __x, __tree<_Tp, _Compare, _Allocator>& __y) +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void +swap(__tree<_Tp, _Compare, _Allocator>& __x, __tree<_Tp, _Compare, _Allocator>& __y) _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) { __x.swap(__y); } diff --git a/lib/libcxx/include/__tuple/make_tuple_types.h b/lib/libcxx/include/__tuple/make_tuple_types.h deleted file mode 100644 index a5c9bcf23a6eb973b0ea15f11c068ca7f545b962..0000000000000000000000000000000000000000 --- a/lib/libcxx/include/__tuple/make_tuple_types.h +++ /dev/null @@ -1,80 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___TUPLE_MAKE_TUPLE_TYPES_H -#define _LIBCPP___TUPLE_MAKE_TUPLE_TYPES_H - -#include <__config> -#include <__cstddef/size_t.h> -#include <__fwd/array.h> -#include <__fwd/tuple.h> -#include <__tuple/tuple_element.h> -#include <__tuple/tuple_indices.h> -#include <__tuple/tuple_size.h> -#include <__tuple/tuple_types.h> -#include <__type_traits/copy_cvref.h> -#include <__type_traits/remove_cvref.h> -#include <__type_traits/remove_reference.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -#ifndef _LIBCPP_CXX03_LANG - -_LIBCPP_BEGIN_NAMESPACE_STD - -// __make_tuple_types<_Tuple<_Types...>, _Ep, _Sp>::type is a -// __tuple_types<_Types...> using only those _Types in the range [_Sp, _Ep). -// _Sp defaults to 0 and _Ep defaults to tuple_size<_Tuple>. If _Tuple is a -// lvalue_reference type, then __tuple_types<_Types&...> is the result. - -template -struct __make_tuple_types_flat; - -template