From 1eaf180dd04efcf65ef981b1e1064658b5ec09c3 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Thu, 26 Jan 2023 13:23:03 -0700 Subject: [PATCH] update libcxx to llvm 16 --- .../include/__algorithm/adjacent_find.h | 9 +- lib/libcxx/include/__algorithm/all_of.h | 2 +- lib/libcxx/include/__algorithm/any_of.h | 2 +- .../include/__algorithm/binary_search.h | 7 +- lib/libcxx/include/__algorithm/comp.h | 50 +- .../include/__algorithm/comp_ref_type.h | 27 +- lib/libcxx/include/__algorithm/copy.h | 162 +- .../include/__algorithm/copy_backward.h | 142 +- lib/libcxx/include/__algorithm/copy_if.h | 2 +- .../include/__algorithm/copy_move_common.h | 163 ++ lib/libcxx/include/__algorithm/copy_n.h | 5 +- lib/libcxx/include/__algorithm/count.h | 2 +- lib/libcxx/include/__algorithm/count_if.h | 2 +- lib/libcxx/include/__algorithm/equal.h | 29 +- lib/libcxx/include/__algorithm/equal_range.h | 13 +- lib/libcxx/include/__algorithm/fill.h | 6 +- lib/libcxx/include/__algorithm/fill_n.h | 5 +- lib/libcxx/include/__algorithm/find.h | 2 +- lib/libcxx/include/__algorithm/find_end.h | 16 +- .../include/__algorithm/find_first_of.h | 11 +- lib/libcxx/include/__algorithm/find_if.h | 2 +- lib/libcxx/include/__algorithm/find_if_not.h | 2 +- lib/libcxx/include/__algorithm/for_each.h | 2 +- lib/libcxx/include/__algorithm/for_each_n.h | 3 +- lib/libcxx/include/__algorithm/generate.h | 2 +- lib/libcxx/include/__algorithm/generate_n.h | 3 +- .../include/__algorithm/half_positive.h | 2 +- .../include/__algorithm/in_found_result.h | 4 +- .../include/__algorithm/in_fun_result.h | 4 +- .../include/__algorithm/in_in_out_result.h | 4 +- lib/libcxx/include/__algorithm/in_in_result.h | 4 +- .../include/__algorithm/in_out_out_result.h | 4 +- .../include/__algorithm/in_out_result.h | 4 +- lib/libcxx/include/__algorithm/includes.h | 16 +- .../include/__algorithm/inplace_merge.h | 11 +- lib/libcxx/include/__algorithm/is_heap.h | 7 +- .../include/__algorithm/is_heap_until.h | 9 +- .../include/__algorithm/is_partitioned.h | 2 +- .../include/__algorithm/is_permutation.h | 37 +- lib/libcxx/include/__algorithm/is_sorted.h | 7 +- .../include/__algorithm/is_sorted_until.h | 9 +- lib/libcxx/include/__algorithm/iter_swap.h | 4 +- .../include/__algorithm/iterator_operations.h | 37 +- .../__algorithm/lexicographical_compare.h | 9 +- lib/libcxx/include/__algorithm/lower_bound.h | 6 +- lib/libcxx/include/__algorithm/make_heap.h | 9 +- .../include/__algorithm/make_projected.h | 4 +- lib/libcxx/include/__algorithm/max.h | 11 +- lib/libcxx/include/__algorithm/max_element.h | 9 +- lib/libcxx/include/__algorithm/merge.h | 9 +- lib/libcxx/include/__algorithm/min.h | 11 +- lib/libcxx/include/__algorithm/min_element.h | 11 +- .../include/__algorithm/min_max_result.h | 4 +- lib/libcxx/include/__algorithm/minmax.h | 8 +- .../include/__algorithm/minmax_element.h | 8 +- lib/libcxx/include/__algorithm/mismatch.h | 16 +- lib/libcxx/include/__algorithm/move.h | 169 +- .../include/__algorithm/move_backward.h | 160 +- .../include/__algorithm/next_permutation.h | 10 +- lib/libcxx/include/__algorithm/none_of.h | 2 +- lib/libcxx/include/__algorithm/nth_element.h | 13 +- lib/libcxx/include/__algorithm/partial_sort.h | 13 +- .../include/__algorithm/partial_sort_copy.h | 9 +- lib/libcxx/include/__algorithm/partition.h | 10 +- .../include/__algorithm/partition_copy.h | 2 +- .../include/__algorithm/partition_point.h | 2 +- lib/libcxx/include/__algorithm/pop_heap.h | 9 +- .../include/__algorithm/prev_permutation.h | 9 +- lib/libcxx/include/__algorithm/push_heap.h | 11 +- .../__algorithm/ranges_adjacent_find.h | 8 +- .../include/__algorithm/ranges_all_of.h | 8 +- .../include/__algorithm/ranges_any_of.h | 8 +- .../__algorithm/ranges_binary_search.h | 8 +- lib/libcxx/include/__algorithm/ranges_clamp.h | 6 +- lib/libcxx/include/__algorithm/ranges_copy.h | 10 +- .../__algorithm/ranges_copy_backward.h | 5 +- .../include/__algorithm/ranges_copy_if.h | 4 +- .../include/__algorithm/ranges_copy_n.h | 7 +- lib/libcxx/include/__algorithm/ranges_count.h | 8 +- .../include/__algorithm/ranges_count_if.h | 8 +- lib/libcxx/include/__algorithm/ranges_equal.h | 8 +- .../include/__algorithm/ranges_equal_range.h | 9 +- lib/libcxx/include/__algorithm/ranges_fill.h | 4 +- .../include/__algorithm/ranges_fill_n.h | 4 +- lib/libcxx/include/__algorithm/ranges_find.h | 8 +- .../include/__algorithm/ranges_find_end.h | 9 +- .../__algorithm/ranges_find_first_of.h | 8 +- .../include/__algorithm/ranges_find_if.h | 8 +- .../include/__algorithm/ranges_find_if_not.h | 8 +- .../include/__algorithm/ranges_for_each.h | 4 +- .../include/__algorithm/ranges_for_each_n.h | 4 +- .../include/__algorithm/ranges_generate.h | 4 +- .../include/__algorithm/ranges_generate_n.h | 4 +- .../include/__algorithm/ranges_includes.h | 8 +- .../__algorithm/ranges_inplace_merge.h | 4 +- .../include/__algorithm/ranges_is_heap.h | 8 +- .../__algorithm/ranges_is_heap_until.h | 8 +- .../__algorithm/ranges_is_partitioned.h | 8 +- .../__algorithm/ranges_is_permutation.h | 8 +- .../include/__algorithm/ranges_is_sorted.h | 8 +- .../__algorithm/ranges_is_sorted_until.h | 8 +- .../__algorithm/ranges_iterator_concept.h | 8 +- .../ranges_lexicographical_compare.h | 8 +- .../include/__algorithm/ranges_lower_bound.h | 8 +- .../include/__algorithm/ranges_make_heap.h | 4 +- lib/libcxx/include/__algorithm/ranges_max.h | 10 +- .../include/__algorithm/ranges_max_element.h | 8 +- lib/libcxx/include/__algorithm/ranges_merge.h | 8 +- lib/libcxx/include/__algorithm/ranges_min.h | 10 +- .../include/__algorithm/ranges_min_element.h | 8 +- .../include/__algorithm/ranges_minmax.h | 11 +- .../__algorithm/ranges_minmax_element.h | 8 +- .../include/__algorithm/ranges_mismatch.h | 8 +- lib/libcxx/include/__algorithm/ranges_move.h | 5 +- .../__algorithm/ranges_move_backward.h | 15 +- .../__algorithm/ranges_next_permutation.h | 5 +- .../include/__algorithm/ranges_none_of.h | 8 +- .../include/__algorithm/ranges_nth_element.h | 4 +- .../include/__algorithm/ranges_partial_sort.h | 5 +- .../__algorithm/ranges_partial_sort_copy.h | 5 +- .../include/__algorithm/ranges_partition.h | 7 +- .../__algorithm/ranges_partition_copy.h | 6 +- .../__algorithm/ranges_partition_point.h | 4 +- .../include/__algorithm/ranges_pop_heap.h | 4 +- .../__algorithm/ranges_prev_permutation.h | 5 +- .../include/__algorithm/ranges_push_heap.h | 4 +- .../include/__algorithm/ranges_remove.h | 8 +- .../include/__algorithm/ranges_remove_copy.h | 4 +- .../__algorithm/ranges_remove_copy_if.h | 4 +- .../include/__algorithm/ranges_remove_if.h | 8 +- .../include/__algorithm/ranges_replace.h | 4 +- .../include/__algorithm/ranges_replace_copy.h | 4 +- .../__algorithm/ranges_replace_copy_if.h | 4 +- .../include/__algorithm/ranges_replace_if.h | 4 +- .../include/__algorithm/ranges_reverse.h | 4 +- .../include/__algorithm/ranges_reverse_copy.h | 4 +- .../include/__algorithm/ranges_rotate.h | 4 +- .../include/__algorithm/ranges_rotate_copy.h | 4 +- .../include/__algorithm/ranges_sample.h | 4 +- .../include/__algorithm/ranges_search.h | 9 +- .../include/__algorithm/ranges_search_n.h | 17 +- .../__algorithm/ranges_set_difference.h | 12 +- .../__algorithm/ranges_set_intersection.h | 6 +- .../ranges_set_symmetric_difference.h | 11 +- .../include/__algorithm/ranges_set_union.h | 11 +- .../include/__algorithm/ranges_shuffle.h | 4 +- lib/libcxx/include/__algorithm/ranges_sort.h | 4 +- .../include/__algorithm/ranges_sort_heap.h | 4 +- .../__algorithm/ranges_stable_partition.h | 6 +- .../include/__algorithm/ranges_stable_sort.h | 4 +- .../include/__algorithm/ranges_swap_ranges.h | 4 +- .../include/__algorithm/ranges_transform.h | 4 +- .../include/__algorithm/ranges_unique.h | 9 +- .../include/__algorithm/ranges_unique_copy.h | 5 +- .../include/__algorithm/ranges_upper_bound.h | 8 +- lib/libcxx/include/__algorithm/remove.h | 2 +- lib/libcxx/include/__algorithm/remove_copy.h | 2 +- .../include/__algorithm/remove_copy_if.h | 2 +- lib/libcxx/include/__algorithm/remove_if.h | 2 +- lib/libcxx/include/__algorithm/replace.h | 2 +- lib/libcxx/include/__algorithm/replace_copy.h | 2 +- .../include/__algorithm/replace_copy_if.h | 2 +- lib/libcxx/include/__algorithm/replace_if.h | 2 +- lib/libcxx/include/__algorithm/reverse.h | 8 +- lib/libcxx/include/__algorithm/reverse_copy.h | 2 +- lib/libcxx/include/__algorithm/rotate.h | 22 +- lib/libcxx/include/__algorithm/rotate_copy.h | 2 +- lib/libcxx/include/__algorithm/search.h | 18 +- lib/libcxx/include/__algorithm/search_n.h | 16 +- .../include/__algorithm/set_difference.h | 18 +- .../include/__algorithm/set_intersection.h | 11 +- .../__algorithm/set_symmetric_difference.h | 19 +- lib/libcxx/include/__algorithm/set_union.h | 19 +- lib/libcxx/include/__algorithm/shuffle.h | 25 +- lib/libcxx/include/__algorithm/sift_down.h | 4 +- lib/libcxx/include/__algorithm/sort.h | 644 +++-- lib/libcxx/include/__algorithm/sort_heap.h | 9 +- .../include/__algorithm/stable_partition.h | 15 +- lib/libcxx/include/__algorithm/stable_sort.h | 13 +- lib/libcxx/include/__algorithm/swap_ranges.h | 6 +- lib/libcxx/include/__algorithm/transform.h | 4 +- .../uniform_random_bit_generator_adaptor.h | 10 +- lib/libcxx/include/__algorithm/unique.h | 9 +- lib/libcxx/include/__algorithm/unique_copy.h | 19 +- lib/libcxx/include/__algorithm/unwrap_iter.h | 6 +- lib/libcxx/include/__algorithm/unwrap_range.h | 2 +- lib/libcxx/include/__algorithm/upper_bound.h | 6 +- lib/libcxx/include/__assert | 10 +- lib/libcxx/include/__availability | 17 +- lib/libcxx/include/__bit/bit_cast.h | 2 +- lib/libcxx/include/__bit/bit_ceil.h | 46 + lib/libcxx/include/__bit/bit_floor.h | 34 + lib/libcxx/include/__bit/bit_log2.h | 34 + lib/libcxx/include/__bit/bit_width.h | 33 + lib/libcxx/include/__bit/blsr.h | 34 + lib/libcxx/include/__bit/countl.h | 104 + lib/libcxx/include/__bit/countr.h | 70 + lib/libcxx/include/__bit/endian.h | 38 + lib/libcxx/include/__bit/has_single_bit.h | 37 + lib/libcxx/include/__bit/popcount.h | 61 + lib/libcxx/include/__bit/rotate.h | 53 + lib/libcxx/include/__bit_reference | 174 +- lib/libcxx/include/__bits | 162 -- lib/libcxx/include/__bsd_locale_fallbacks.h | 1 - lib/libcxx/include/__charconv/chars_format.h | 10 +- .../include/__charconv/from_chars_result.h | 4 +- lib/libcxx/include/__charconv/tables.h | 46 +- .../include/__charconv/to_chars_base_10.h | 38 +- .../include/__charconv/to_chars_result.h | 4 +- .../include/__chrono/convert_to_timespec.h | 1 + lib/libcxx/include/__chrono/convert_to_tm.h | 127 + lib/libcxx/include/__chrono/day.h | 12 +- lib/libcxx/include/__chrono/duration.h | 59 +- lib/libcxx/include/__chrono/file_clock.h | 2 +- lib/libcxx/include/__chrono/formatter.h | 716 ++++++ lib/libcxx/include/__chrono/hh_mm_ss.h | 34 +- lib/libcxx/include/__chrono/month.h | 35 +- lib/libcxx/include/__chrono/month_weekday.h | 24 +- lib/libcxx/include/__chrono/monthday.h | 75 +- lib/libcxx/include/__chrono/ostream.h | 238 ++ .../include/__chrono/parser_std_format_spec.h | 410 ++++ .../include/__chrono/statically_widen.h | 52 + lib/libcxx/include/__chrono/steady_clock.h | 2 +- lib/libcxx/include/__chrono/system_clock.h | 2 +- lib/libcxx/include/__chrono/time_point.h | 44 +- lib/libcxx/include/__chrono/weekday.h | 38 +- lib/libcxx/include/__chrono/year.h | 41 +- lib/libcxx/include/__chrono/year_month.h | 45 +- lib/libcxx/include/__chrono/year_month_day.h | 74 +- .../include/__chrono/year_month_weekday.h | 56 +- .../__compare/common_comparison_category.h | 5 +- .../compare_partial_order_fallback.h | 3 +- .../__compare/compare_strong_order_fallback.h | 3 +- .../__compare/compare_three_way_result.h | 7 +- .../__compare/compare_weak_order_fallback.h | 3 +- lib/libcxx/include/__compare/ordering.h | 9 +- lib/libcxx/include/__compare/partial_order.h | 5 +- lib/libcxx/include/__compare/strong_order.h | 5 +- .../include/__compare/synth_three_way.h | 2 +- .../include/__compare/three_way_comparable.h | 3 +- lib/libcxx/include/__compare/weak_order.h | 4 +- lib/libcxx/include/__concepts/arithmetic.h | 4 +- lib/libcxx/include/__concepts/assignable.h | 3 +- lib/libcxx/include/__concepts/class_or_enum.h | 7 +- .../__concepts/common_reference_with.h | 2 +- lib/libcxx/include/__concepts/common_with.h | 9 +- lib/libcxx/include/__concepts/constructible.h | 2 +- .../include/__concepts/convertible_to.h | 4 +- lib/libcxx/include/__concepts/derived_from.h | 3 +- lib/libcxx/include/__concepts/destructible.h | 2 +- .../include/__concepts/different_from.h | 2 +- .../include/__concepts/equality_comparable.h | 3 +- lib/libcxx/include/__concepts/invocable.h | 1 - lib/libcxx/include/__concepts/movable.h | 2 +- lib/libcxx/include/__concepts/predicate.h | 2 +- lib/libcxx/include/__concepts/same_as.h | 2 +- lib/libcxx/include/__concepts/swappable.h | 7 +- .../include/__concepts/totally_ordered.h | 3 +- lib/libcxx/include/__config | 207 +- .../include/__coroutine/coroutine_handle.h | 9 +- .../include/__coroutine/coroutine_traits.h | 8 +- .../__coroutine/noop_coroutine_handle.h | 4 +- .../include/__coroutine/trivial_awaitables.h | 4 +- lib/libcxx/include/__debug | 29 +- .../include/__debug_utils/randomize_range.h | 2 +- .../include/__expected/bad_expected_access.h | 64 + lib/libcxx/include/__expected/expected.h | 973 ++++++++ lib/libcxx/include/__expected/unexpect.h | 32 + lib/libcxx/include/__expected/unexpected.h | 122 + .../include/__filesystem/directory_entry.h | 19 +- .../include/__filesystem/filesystem_error.h | 3 +- lib/libcxx/include/__filesystem/path.h | 67 +- lib/libcxx/include/__filesystem/space_info.h | 4 + lib/libcxx/include/__format/buffer.h | 362 ++- lib/libcxx/include/__format/concepts.h | 49 +- .../include/__format/container_adaptor.h | 70 + .../include/__format/escaped_output_table.h | 1038 ++++++++ .../extended_grapheme_cluster_table.h | 1673 +++++++++++-- lib/libcxx/include/__format/format_arg.h | 40 +- .../include/__format/format_arg_store.h | 5 +- lib/libcxx/include/__format/format_args.h | 1 + lib/libcxx/include/__format/format_context.h | 88 +- lib/libcxx/include/__format/format_error.h | 14 +- .../include/__format/format_functions.h | 661 +++++ .../include/__format/format_parse_context.h | 9 +- lib/libcxx/include/__format/format_string.h | 10 +- .../include/__format/format_to_n_result.h | 1 + lib/libcxx/include/__format/formatter.h | 16 +- lib/libcxx/include/__format/formatter_bool.h | 4 +- lib/libcxx/include/__format/formatter_char.h | 13 +- .../__format/formatter_floating_point.h | 106 +- .../include/__format/formatter_integer.h | 28 +- .../include/__format/formatter_integral.h | 13 +- .../include/__format/formatter_output.h | 354 ++- .../include/__format/formatter_pointer.h | 10 +- .../include/__format/formatter_string.h | 34 +- lib/libcxx/include/__format/formatter_tuple.h | 178 ++ .../include/__format/parser_std_format_spec.h | 132 +- .../__format/range_default_formatter.h | 201 ++ lib/libcxx/include/__format/range_formatter.h | 255 ++ lib/libcxx/include/__format/unicode.h | 172 +- .../include/__functional/binary_negate.h | 6 +- lib/libcxx/include/__functional/bind.h | 28 +- .../__functional/boyer_moore_searcher.h | 2 + .../include/__functional/default_searcher.h | 5 +- lib/libcxx/include/__functional/function.h | 1665 +------------ lib/libcxx/include/__functional/hash.h | 76 +- lib/libcxx/include/__functional/invoke.h | 24 +- .../include/__functional/is_transparent.h | 3 +- lib/libcxx/include/__functional/mem_fn.h | 6 +- lib/libcxx/include/__functional/not_fn.h | 4 +- lib/libcxx/include/__functional/operations.h | 95 +- .../include/__functional/ranges_operations.h | 3 +- .../include/__functional/reference_wrapper.h | 25 +- .../include/__functional/unary_negate.h | 6 +- lib/libcxx/include/__functional/unwrap_ref.h | 1 + .../include/__functional/weak_result_type.h | 7 +- lib/libcxx/include/__fwd/array.h | 26 + lib/libcxx/include/__fwd/get.h | 115 + lib/libcxx/include/__fwd/hash.h | 25 + lib/libcxx/include/__fwd/memory_resource.h | 27 + lib/libcxx/include/__fwd/pair.h | 25 + lib/libcxx/include/__fwd/span.h | 6 +- lib/libcxx/include/__fwd/string.h | 110 + lib/libcxx/include/__fwd/string_view.h | 19 +- lib/libcxx/include/__fwd/subrange.h | 38 + lib/libcxx/include/__fwd/tuple.h | 29 + lib/libcxx/include/__hash_table | 147 +- lib/libcxx/include/__iterator/access.h | 16 +- lib/libcxx/include/__iterator/advance.h | 22 +- .../include/__iterator/back_insert_iterator.h | 17 +- lib/libcxx/include/__iterator/bounded_iter.h | 32 +- .../include/__iterator/common_iterator.h | 39 +- lib/libcxx/include/__iterator/concepts.h | 24 +- .../include/__iterator/counted_iterator.h | 13 +- lib/libcxx/include/__iterator/distance.h | 15 +- .../__iterator/front_insert_iterator.h | 15 +- .../include/__iterator/incrementable_traits.h | 10 +- .../include/__iterator/insert_iterator.h | 16 +- lib/libcxx/include/__iterator/iter_move.h | 9 +- lib/libcxx/include/__iterator/iter_swap.h | 13 +- .../include/__iterator/iterator_traits.h | 42 +- .../include/__iterator/iterator_with_data.h | 100 + lib/libcxx/include/__iterator/move_iterator.h | 65 +- lib/libcxx/include/__iterator/move_sentinel.h | 2 + lib/libcxx/include/__iterator/next.h | 8 +- .../include/__iterator/ostreambuf_iterator.h | 2 +- lib/libcxx/include/__iterator/prev.h | 8 +- lib/libcxx/include/__iterator/projected.h | 3 +- .../include/__iterator/readable_traits.h | 10 +- .../include/__iterator/reverse_access.h | 20 +- .../include/__iterator/reverse_iterator.h | 95 +- .../include/__iterator/segmented_iterator.h | 79 + lib/libcxx/include/__iterator/size.h | 3 +- lib/libcxx/include/__iterator/wrap_iter.h | 71 +- lib/libcxx/include/__locale | 148 +- lib/libcxx/include/__memory/addressof.h | 2 +- lib/libcxx/include/__memory/align.h | 25 + .../include/__memory/allocate_at_least.h | 1 + lib/libcxx/include/__memory/allocator.h | 25 +- lib/libcxx/include/__memory/allocator_arg_t.h | 6 +- .../include/__memory/allocator_destructor.h | 42 + .../include/__memory/allocator_traits.h | 63 +- lib/libcxx/include/__memory/assume_aligned.h | 2 +- .../include/__memory/builtin_new_allocator.h | 70 + lib/libcxx/include/__memory/compressed_pair.h | 33 +- lib/libcxx/include/__memory/concepts.h | 9 +- lib/libcxx/include/__memory/construct_at.h | 25 +- lib/libcxx/include/__memory/destruct_n.h | 64 + lib/libcxx/include/__memory/pointer_traits.h | 46 +- .../include/__memory/ranges_construct_at.h | 7 +- .../ranges_uninitialized_algorithms.h | 13 +- .../include/__memory/raw_storage_iterator.h | 1 + lib/libcxx/include/__memory/shared_ptr.h | 224 +- lib/libcxx/include/__memory/swap_allocator.h | 7 +- lib/libcxx/include/__memory/temp_value.h | 56 + .../include/__memory/temporary_buffer.h | 2 +- .../__memory/uninitialized_algorithms.h | 70 +- lib/libcxx/include/__memory/unique_ptr.h | 405 ++- lib/libcxx/include/__memory/uses_allocator.h | 2 +- .../__memory/uses_allocator_construction.h | 221 ++ lib/libcxx/include/__memory/voidify.h | 2 +- .../__memory_resource/memory_resource.h | 75 + .../monotonic_buffer_resource.h | 120 + .../__memory_resource/polymorphic_allocator.h | 224 ++ .../include/__memory_resource/pool_options.h | 38 + .../synchronized_pool_resource.h | 94 + .../unsynchronized_pool_resource.h | 106 + lib/libcxx/include/__mutex_base | 2 + lib/libcxx/include/__node_handle | 7 +- lib/libcxx/include/__numeric/accumulate.h | 4 +- .../include/__numeric/adjacent_difference.h | 4 +- lib/libcxx/include/__numeric/exclusive_scan.h | 4 +- lib/libcxx/include/__numeric/gcd_lcm.h | 14 +- lib/libcxx/include/__numeric/inclusive_scan.h | 6 +- lib/libcxx/include/__numeric/inner_product.h | 4 +- lib/libcxx/include/__numeric/iota.h | 2 +- lib/libcxx/include/__numeric/midpoint.h | 22 +- lib/libcxx/include/__numeric/partial_sum.h | 4 +- lib/libcxx/include/__numeric/reduce.h | 6 +- .../__numeric/transform_exclusive_scan.h | 2 +- .../__numeric/transform_inclusive_scan.h | 4 +- .../include/__numeric/transform_reduce.h | 6 +- .../include/__random/bernoulli_distribution.h | 4 +- .../include/__random/binomial_distribution.h | 10 +- .../include/__random/cauchy_distribution.h | 4 +- .../__random/chi_squared_distribution.h | 4 +- .../include/__random/discard_block_engine.h | 10 +- .../include/__random/discrete_distribution.h | 4 +- .../__random/exponential_distribution.h | 4 +- .../__random/extreme_value_distribution.h | 4 +- .../include/__random/fisher_f_distribution.h | 4 +- .../include/__random/gamma_distribution.h | 4 +- .../include/__random/generate_canonical.h | 2 +- .../include/__random/geometric_distribution.h | 4 +- .../__random/independent_bits_engine.h | 12 +- .../include/__random/is_seed_sequence.h | 2 +- lib/libcxx/include/__random/is_valid.h | 2 +- .../__random/linear_congruential_engine.h | 4 +- lib/libcxx/include/__random/log2.h | 9 +- .../__random/mersenne_twister_engine.h | 12 +- .../__random/negative_binomial_distribution.h | 4 +- .../include/__random/normal_distribution.h | 40 +- .../piecewise_constant_distribution.h | 4 +- .../__random/piecewise_linear_distribution.h | 4 +- .../include/__random/poisson_distribution.h | 4 +- .../include/__random/shuffle_order_engine.h | 42 +- .../include/__random/student_t_distribution.h | 4 +- .../__random/subtract_with_carry_engine.h | 12 +- .../__random/uniform_int_distribution.h | 23 +- .../__random/uniform_real_distribution.h | 4 +- .../include/__random/weibull_distribution.h | 4 +- lib/libcxx/include/__ranges/access.h | 10 +- lib/libcxx/include/__ranges/all.h | 7 +- lib/libcxx/include/__ranges/as_rvalue_view.h | 137 ++ lib/libcxx/include/__ranges/common_view.h | 8 +- lib/libcxx/include/__ranges/concepts.h | 11 +- lib/libcxx/include/__ranges/copyable_box.h | 8 +- lib/libcxx/include/__ranges/counted.h | 5 +- lib/libcxx/include/__ranges/dangling.h | 2 +- lib/libcxx/include/__ranges/data.h | 8 +- lib/libcxx/include/__ranges/drop_view.h | 8 +- lib/libcxx/include/__ranges/drop_while_view.h | 129 + lib/libcxx/include/__ranges/elements_view.h | 423 ++++ lib/libcxx/include/__ranges/empty.h | 6 +- lib/libcxx/include/__ranges/empty_view.h | 5 +- lib/libcxx/include/__ranges/enable_view.h | 7 +- lib/libcxx/include/__ranges/filter_view.h | 63 +- lib/libcxx/include/__ranges/iota_view.h | 436 ++-- lib/libcxx/include/__ranges/istream_view.h | 149 ++ lib/libcxx/include/__ranges/join_view.h | 138 +- lib/libcxx/include/__ranges/lazy_split_view.h | 6 +- .../include/__ranges/non_propagating_cache.h | 6 +- lib/libcxx/include/__ranges/owning_view.h | 6 +- lib/libcxx/include/__ranges/range_adaptor.h | 10 +- lib/libcxx/include/__ranges/rbegin.h | 5 +- lib/libcxx/include/__ranges/ref_view.h | 10 +- lib/libcxx/include/__ranges/rend.h | 5 +- lib/libcxx/include/__ranges/reverse_view.h | 5 +- lib/libcxx/include/__ranges/single_view.h | 7 +- lib/libcxx/include/__ranges/size.h | 11 +- lib/libcxx/include/__ranges/split_view.h | 232 ++ lib/libcxx/include/__ranges/subrange.h | 33 +- lib/libcxx/include/__ranges/take_view.h | 18 +- lib/libcxx/include/__ranges/take_while_view.h | 183 ++ lib/libcxx/include/__ranges/transform_view.h | 133 +- lib/libcxx/include/__ranges/view_interface.h | 13 +- lib/libcxx/include/__ranges/views.h | 4 +- lib/libcxx/include/__ranges/zip_view.h | 11 +- lib/libcxx/include/__split_buffer | 187 +- lib/libcxx/include/__string/char_traits.h | 549 ++--- .../include/__support/android/locale_bionic.h | 6 +- .../include/__support/fuchsia/xlocale.h | 6 +- lib/libcxx/include/__support/ibm/gettod_zos.h | 6 +- .../include/__support/ibm/locale_mgmt_zos.h | 6 +- lib/libcxx/include/__support/ibm/nanosleep.h | 6 +- lib/libcxx/include/__support/ibm/xlocale.h | 6 +- lib/libcxx/include/__support/musl/xlocale.h | 8 +- lib/libcxx/include/__support/newlib/xlocale.h | 8 +- .../include/__support/openbsd/xlocale.h | 4 +- .../include/__support/solaris/xlocale.h | 2 +- .../__support/win32/limits_msvc_win32.h | 71 - .../include/__support/win32/locale_win32.h | 119 +- .../__support/xlocale/__nop_locale_mgmt.h | 8 +- .../__support/xlocale/__posix_l_fallback.h | 34 +- .../__support/xlocale/__strtonum_fallback.h | 15 +- .../include/__thread/poll_with_backoff.h | 4 +- .../include/__thread/timed_backoff_policy.h | 1 + lib/libcxx/include/__threading_support | 79 +- lib/libcxx/include/__tree | 73 +- lib/libcxx/include/__tuple | 550 ----- lib/libcxx/include/__tuple_dir/apply_cv.h | 70 + .../include/__tuple_dir/make_tuple_types.h | 84 + lib/libcxx/include/__tuple_dir/pair_like.h | 32 + .../include/__tuple_dir/sfinae_helpers.h | 196 ++ .../include/__tuple_dir/tuple_element.h | 93 + .../include/__tuple_dir/tuple_indices.h | 37 + lib/libcxx/include/__tuple_dir/tuple_like.h | 51 + .../include/__tuple_dir/tuple_like_ext.h | 44 + lib/libcxx/include/__tuple_dir/tuple_size.h | 75 + lib/libcxx/include/__tuple_dir/tuple_types.h | 24 + .../__type_traits/add_lvalue_reference.h | 30 +- .../include/__type_traits/add_pointer.h | 28 +- .../__type_traits/add_rvalue_reference.h | 31 +- .../include/__type_traits/aligned_storage.h | 22 +- .../include/__type_traits/aligned_union.h | 5 +- .../include/__type_traits/alignment_of.h | 2 +- lib/libcxx/include/__type_traits/apply_cv.h | 5 +- .../include/__type_traits/can_extract_key.h | 56 + .../include/__type_traits/common_reference.h | 2 +- .../include/__type_traits/common_type.h | 14 +- .../include/__type_traits/conditional.h | 13 +- .../include/__type_traits/conjunction.h | 43 +- lib/libcxx/include/__type_traits/copy_cvref.h | 4 +- lib/libcxx/include/__type_traits/decay.h | 18 +- .../include/__type_traits/dependent_type.h | 25 + .../include/__type_traits/disjunction.h | 7 +- .../__type_traits/has_virtual_destructor.h | 11 +- .../include/__type_traits/is_allocator.h | 36 + .../__type_traits/is_always_bitcastable.h | 82 + .../include/__type_traits/is_assignable.h | 35 - .../include/__type_traits/is_callable.h | 2 +- .../include/__type_traits/is_char_like_type.h | 28 + lib/libcxx/include/__type_traits/is_class.h | 2 - .../__type_traits/is_constant_evaluated.h | 2 +- .../include/__type_traits/is_constructible.h | 2 +- .../include/__type_traits/is_convertible.h | 4 +- .../__type_traits/is_copy_assignable.h | 10 +- .../__type_traits/is_copy_constructible.h | 6 +- .../__type_traits/is_default_constructible.h | 5 +- .../include/__type_traits/is_destructible.h | 4 +- lib/libcxx/include/__type_traits/is_enum.h | 1 - .../include/__type_traits/is_floating_point.h | 2 +- .../is_implicitly_default_constructible.h | 48 + .../include/__type_traits/is_integral.h | 2 +- .../include/__type_traits/is_literal_type.h | 2 +- .../is_member_function_pointer.h | 2 +- .../__type_traits/is_member_object_pointer.h | 2 +- .../include/__type_traits/is_member_pointer.h | 3 +- .../__type_traits/is_move_assignable.h | 10 +- .../__type_traits/is_move_constructible.h | 3 +- .../__type_traits/is_nothrow_assignable.h | 29 +- .../__type_traits/is_nothrow_constructible.h | 11 +- .../__type_traits/is_nothrow_convertible.h | 2 +- .../is_nothrow_copy_assignable.h | 11 +- .../is_nothrow_copy_constructible.h | 15 +- .../is_nothrow_default_constructible.h | 5 +- .../__type_traits/is_nothrow_destructible.h | 5 +- .../is_nothrow_move_assignable.h | 11 +- .../is_nothrow_move_constructible.h | 13 +- .../include/__type_traits/is_null_pointer.h | 4 +- lib/libcxx/include/__type_traits/is_pod.h | 14 +- lib/libcxx/include/__type_traits/is_pointer.h | 2 +- .../__type_traits/is_reference_wrapper.h | 2 +- .../include/__type_traits/is_referenceable.h | 18 +- lib/libcxx/include/__type_traits/is_scalar.h | 1 + lib/libcxx/include/__type_traits/is_signed.h | 2 + .../include/__type_traits/is_specialization.h | 45 + .../__type_traits/is_standard_layout.h | 6 +- .../include/__type_traits/is_swappable.h | 165 ++ lib/libcxx/include/__type_traits/is_trivial.h | 7 +- .../__type_traits/is_trivially_assignable.h | 2 +- .../is_trivially_constructible.h | 2 +- .../is_trivially_copy_assignable.h | 11 +- .../is_trivially_copy_constructible.h | 3 +- .../__type_traits/is_trivially_copyable.h | 2 +- .../is_trivially_default_constructible.h | 5 +- .../__type_traits/is_trivially_destructible.h | 11 +- .../is_trivially_move_assignable.h | 10 +- .../is_trivially_move_constructible.h | 7 +- lib/libcxx/include/__type_traits/is_union.h | 1 - .../include/__type_traits/is_unsigned.h | 3 +- .../__type_traits/is_valid_expansion.h | 2 +- lib/libcxx/include/__type_traits/is_void.h | 4 +- .../__type_traits/make_const_lvalue_ref.h | 26 + .../include/__type_traits/make_signed.h | 30 +- .../include/__type_traits/make_unsigned.h | 36 +- .../include/__type_traits/maybe_const.h | 26 + lib/libcxx/include/__type_traits/negation.h | 2 +- .../noexcept_move_assign_container.h | 35 + lib/libcxx/include/__type_traits/promote.h | 6 +- lib/libcxx/include/__type_traits/rank.h | 10 + .../__type_traits/remove_all_extents.h | 15 +- .../include/__type_traits/remove_const.h | 16 +- .../include/__type_traits/remove_const_ref.h | 27 + lib/libcxx/include/__type_traits/remove_cv.h | 18 +- .../include/__type_traits/remove_cvref.h | 14 +- .../include/__type_traits/remove_extent.h | 15 +- .../include/__type_traits/remove_pointer.h | 15 +- .../include/__type_traits/remove_reference.h | 15 +- .../include/__type_traits/remove_volatile.h | 16 +- lib/libcxx/include/__type_traits/result_of.h | 39 + .../include/__type_traits/strip_signature.h | 79 + lib/libcxx/include/__type_traits/void_t.h | 4 +- lib/libcxx/include/__utility/as_const.h | 4 +- lib/libcxx/include/__utility/auto_cast.h | 2 +- lib/libcxx/include/__utility/cmp.h | 6 +- .../include/__utility/convert_to_integral.h | 72 + lib/libcxx/include/__utility/declval.h | 2 +- .../include/__utility/exception_guard.h | 128 + lib/libcxx/include/__utility/exchange.h | 5 +- lib/libcxx/include/__utility/forward.h | 8 +- lib/libcxx/include/__utility/forward_like.h | 46 + lib/libcxx/include/__utility/in_place.h | 7 +- .../include/__utility/integer_sequence.h | 77 +- lib/libcxx/include/__utility/move.h | 20 +- lib/libcxx/include/__utility/pair.h | 250 +- lib/libcxx/include/__utility/rel_ops.h | 3 - lib/libcxx/include/__utility/swap.h | 10 +- lib/libcxx/include/__utility/to_underlying.h | 2 +- lib/libcxx/include/__utility/transaction.h | 96 - lib/libcxx/include/__utility/unreachable.h | 16 +- lib/libcxx/include/__variant/monostate.h | 32 +- lib/libcxx/include/__verbose_abort | 54 +- lib/libcxx/include/algorithm | 27 +- lib/libcxx/include/any | 100 +- lib/libcxx/include/array | 140 +- lib/libcxx/include/atomic | 174 +- lib/libcxx/include/barrier | 25 +- lib/libcxx/include/bit | 200 +- lib/libcxx/include/bitset | 281 ++- lib/libcxx/include/cassert | 9 +- lib/libcxx/include/cctype | 8 + lib/libcxx/include/cerrno | 9 + lib/libcxx/include/cfenv | 9 + lib/libcxx/include/cfloat | 9 + lib/libcxx/include/charconv | 230 +- lib/libcxx/include/chrono | 149 +- lib/libcxx/include/cinttypes | 13 + lib/libcxx/include/climits | 9 + lib/libcxx/include/clocale | 9 + lib/libcxx/include/cmath | 207 +- lib/libcxx/include/codecvt | 448 ++-- lib/libcxx/include/compare | 4 + lib/libcxx/include/complex | 757 +++--- lib/libcxx/include/complex.h | 12 +- lib/libcxx/include/concepts | 4 + lib/libcxx/include/condition_variable | 8 +- lib/libcxx/include/coroutine | 11 +- lib/libcxx/include/csetjmp | 9 + lib/libcxx/include/csignal | 6 +- lib/libcxx/include/cstdarg | 9 +- lib/libcxx/include/cstddef | 35 +- lib/libcxx/include/cstdint | 9 + lib/libcxx/include/cstdio | 9 + lib/libcxx/include/cstdlib | 9 + lib/libcxx/include/cstring | 57 + lib/libcxx/include/ctime | 9 +- lib/libcxx/include/ctype.h | 4 +- lib/libcxx/include/cuchar | 15 + lib/libcxx/include/cwchar | 59 + lib/libcxx/include/cwctype | 9 + lib/libcxx/include/deque | 2169 ++++++----------- lib/libcxx/include/errno.h | 4 +- lib/libcxx/include/exception | 88 +- lib/libcxx/include/expected | 54 + lib/libcxx/include/experimental/__memory | 4 +- lib/libcxx/include/experimental/coroutine | 31 +- lib/libcxx/include/experimental/deque | 4 + lib/libcxx/include/experimental/forward_list | 4 + lib/libcxx/include/experimental/functional | 50 +- lib/libcxx/include/experimental/iterator | 25 +- lib/libcxx/include/experimental/list | 4 + lib/libcxx/include/experimental/map | 4 + .../include/experimental/memory_resource | 50 +- .../include/experimental/propagate_const | 7 +- lib/libcxx/include/experimental/regex | 12 +- lib/libcxx/include/experimental/set | 4 + lib/libcxx/include/experimental/simd | 49 +- lib/libcxx/include/experimental/string | 16 +- lib/libcxx/include/experimental/unordered_map | 20 +- lib/libcxx/include/experimental/unordered_set | 4 + lib/libcxx/include/experimental/vector | 4 + lib/libcxx/include/ext/__hash | 1 + lib/libcxx/include/ext/hash_map | 22 +- lib/libcxx/include/ext/hash_set | 13 +- lib/libcxx/include/fenv.h | 4 +- lib/libcxx/include/filesystem | 236 +- lib/libcxx/include/float.h | 4 +- lib/libcxx/include/format | 675 +---- lib/libcxx/include/forward_list | 89 +- lib/libcxx/include/fstream | 63 +- lib/libcxx/include/functional | 14 +- lib/libcxx/include/future | 70 +- lib/libcxx/include/initializer_list | 14 +- lib/libcxx/include/inttypes.h | 4 +- lib/libcxx/include/iomanip | 24 +- lib/libcxx/include/ios | 71 +- lib/libcxx/include/iosfwd | 26 +- lib/libcxx/include/iostream | 2 + lib/libcxx/include/istream | 41 +- lib/libcxx/include/iterator | 22 +- lib/libcxx/include/latch | 12 +- lib/libcxx/include/limits | 18 +- lib/libcxx/include/limits.h | 19 +- lib/libcxx/include/list | 67 +- lib/libcxx/include/locale | 274 +-- lib/libcxx/include/locale.h | 4 +- lib/libcxx/include/map | 81 +- lib/libcxx/include/math.h | 1568 ++++++------ lib/libcxx/include/memory | 361 +-- lib/libcxx/include/memory_resource | 65 + lib/libcxx/include/mutex | 35 +- lib/libcxx/include/new | 72 +- lib/libcxx/include/numbers | 8 +- lib/libcxx/include/numeric | 12 +- lib/libcxx/include/optional | 191 +- lib/libcxx/include/ostream | 129 +- lib/libcxx/include/queue | 15 +- lib/libcxx/include/random | 31 +- lib/libcxx/include/ranges | 92 +- lib/libcxx/include/ratio | 6 +- lib/libcxx/include/regex | 103 +- lib/libcxx/include/scoped_allocator | 50 +- lib/libcxx/include/semaphore | 34 +- lib/libcxx/include/set | 34 +- lib/libcxx/include/setjmp.h | 4 +- lib/libcxx/include/shared_mutex | 55 +- lib/libcxx/include/source_location | 85 + lib/libcxx/include/span | 137 +- lib/libcxx/include/sstream | 87 +- lib/libcxx/include/stack | 13 +- lib/libcxx/include/stdbool.h | 5 +- lib/libcxx/include/stddef.h | 4 +- lib/libcxx/include/stdexcept | 22 +- lib/libcxx/include/stdint.h | 4 +- lib/libcxx/include/stdio.h | 4 +- lib/libcxx/include/stdlib.h | 14 +- lib/libcxx/include/streambuf | 6 +- lib/libcxx/include/string | 1659 ++++++------- lib/libcxx/include/string.h | 72 +- lib/libcxx/include/string_view | 399 +-- lib/libcxx/include/strstream | 22 +- lib/libcxx/include/system_error | 125 +- lib/libcxx/include/tgmath.h | 14 +- lib/libcxx/include/thread | 38 +- lib/libcxx/include/tuple | 288 ++- lib/libcxx/include/type_traits | 291 +-- lib/libcxx/include/typeindex | 27 +- lib/libcxx/include/typeinfo | 47 +- lib/libcxx/include/uchar.h | 2 + lib/libcxx/include/unordered_map | 71 +- lib/libcxx/include/unordered_set | 40 +- lib/libcxx/include/utility | 38 +- lib/libcxx/include/valarray | 59 +- lib/libcxx/include/variant | 405 +-- lib/libcxx/include/vector | 1333 +++++----- lib/libcxx/include/version | 33 +- lib/libcxx/include/wchar.h | 4 +- lib/libcxx/src/atomic.cpp | 27 +- lib/libcxx/src/charconv.cpp | 4 +- .../src/experimental/memory_resource.cpp | 4 +- lib/libcxx/src/filesystem/filesystem_common.h | 20 +- lib/libcxx/src/filesystem/operations.cpp | 3 +- lib/libcxx/src/format.cpp | 2 + lib/libcxx/src/include/apple_availability.h | 1 + lib/libcxx/src/include/ryu/digit_table.h | 2 +- lib/libcxx/src/ios.cpp | 10 +- lib/libcxx/src/ios.instantiations.cpp | 3 + lib/libcxx/src/iostream.cpp | 4 +- lib/libcxx/src/locale.cpp | 327 ++- lib/libcxx/src/memory.cpp | 8 +- lib/libcxx/src/memory_resource.cpp | 496 ++++ lib/libcxx/src/memory_resource_init_helper.h | 2 + lib/libcxx/src/optional.cpp | 10 +- lib/libcxx/src/shared_mutex.cpp | 14 +- lib/libcxx/src/string.cpp | 4 +- lib/libcxx/src/support/ibm/wcsnrtombs.cpp | 2 +- .../support/runtime/stdexcept_vcruntime.ipp | 2 +- lib/libcxx/src/thread.cpp | 2 +- 770 files changed, 27347 insertions(+), 15411 deletions(-) create mode 100644 lib/libcxx/include/__algorithm/copy_move_common.h create mode 100644 lib/libcxx/include/__bit/bit_ceil.h create mode 100644 lib/libcxx/include/__bit/bit_floor.h create mode 100644 lib/libcxx/include/__bit/bit_log2.h create mode 100644 lib/libcxx/include/__bit/bit_width.h create mode 100644 lib/libcxx/include/__bit/blsr.h create mode 100644 lib/libcxx/include/__bit/countl.h create mode 100644 lib/libcxx/include/__bit/countr.h create mode 100644 lib/libcxx/include/__bit/endian.h create mode 100644 lib/libcxx/include/__bit/has_single_bit.h create mode 100644 lib/libcxx/include/__bit/popcount.h create mode 100644 lib/libcxx/include/__bit/rotate.h delete mode 100644 lib/libcxx/include/__bits create mode 100644 lib/libcxx/include/__chrono/convert_to_tm.h create mode 100644 lib/libcxx/include/__chrono/formatter.h create mode 100644 lib/libcxx/include/__chrono/ostream.h create mode 100644 lib/libcxx/include/__chrono/parser_std_format_spec.h create mode 100644 lib/libcxx/include/__chrono/statically_widen.h create mode 100644 lib/libcxx/include/__expected/bad_expected_access.h create mode 100644 lib/libcxx/include/__expected/expected.h create mode 100644 lib/libcxx/include/__expected/unexpect.h create mode 100644 lib/libcxx/include/__expected/unexpected.h create mode 100644 lib/libcxx/include/__format/container_adaptor.h create mode 100644 lib/libcxx/include/__format/escaped_output_table.h create mode 100644 lib/libcxx/include/__format/format_functions.h create mode 100644 lib/libcxx/include/__format/formatter_tuple.h create mode 100644 lib/libcxx/include/__format/range_default_formatter.h create mode 100644 lib/libcxx/include/__format/range_formatter.h create mode 100644 lib/libcxx/include/__fwd/array.h create mode 100644 lib/libcxx/include/__fwd/get.h create mode 100644 lib/libcxx/include/__fwd/hash.h create mode 100644 lib/libcxx/include/__fwd/memory_resource.h create mode 100644 lib/libcxx/include/__fwd/pair.h create mode 100644 lib/libcxx/include/__fwd/string.h create mode 100644 lib/libcxx/include/__fwd/subrange.h create mode 100644 lib/libcxx/include/__fwd/tuple.h create mode 100644 lib/libcxx/include/__iterator/iterator_with_data.h create mode 100644 lib/libcxx/include/__iterator/segmented_iterator.h create mode 100644 lib/libcxx/include/__memory/align.h create mode 100644 lib/libcxx/include/__memory/allocator_destructor.h create mode 100644 lib/libcxx/include/__memory/builtin_new_allocator.h create mode 100644 lib/libcxx/include/__memory/destruct_n.h create mode 100644 lib/libcxx/include/__memory/temp_value.h create mode 100644 lib/libcxx/include/__memory/uses_allocator_construction.h create mode 100644 lib/libcxx/include/__memory_resource/memory_resource.h create mode 100644 lib/libcxx/include/__memory_resource/monotonic_buffer_resource.h create mode 100644 lib/libcxx/include/__memory_resource/polymorphic_allocator.h create mode 100644 lib/libcxx/include/__memory_resource/pool_options.h create mode 100644 lib/libcxx/include/__memory_resource/synchronized_pool_resource.h create mode 100644 lib/libcxx/include/__memory_resource/unsynchronized_pool_resource.h create mode 100644 lib/libcxx/include/__ranges/as_rvalue_view.h create mode 100644 lib/libcxx/include/__ranges/drop_while_view.h create mode 100644 lib/libcxx/include/__ranges/elements_view.h create mode 100644 lib/libcxx/include/__ranges/istream_view.h create mode 100644 lib/libcxx/include/__ranges/split_view.h create mode 100644 lib/libcxx/include/__ranges/take_while_view.h delete mode 100644 lib/libcxx/include/__support/win32/limits_msvc_win32.h delete mode 100644 lib/libcxx/include/__tuple create mode 100644 lib/libcxx/include/__tuple_dir/apply_cv.h create mode 100644 lib/libcxx/include/__tuple_dir/make_tuple_types.h create mode 100644 lib/libcxx/include/__tuple_dir/pair_like.h create mode 100644 lib/libcxx/include/__tuple_dir/sfinae_helpers.h create mode 100644 lib/libcxx/include/__tuple_dir/tuple_element.h create mode 100644 lib/libcxx/include/__tuple_dir/tuple_indices.h create mode 100644 lib/libcxx/include/__tuple_dir/tuple_like.h create mode 100644 lib/libcxx/include/__tuple_dir/tuple_like_ext.h create mode 100644 lib/libcxx/include/__tuple_dir/tuple_size.h create mode 100644 lib/libcxx/include/__tuple_dir/tuple_types.h create mode 100644 lib/libcxx/include/__type_traits/can_extract_key.h create mode 100644 lib/libcxx/include/__type_traits/dependent_type.h create mode 100644 lib/libcxx/include/__type_traits/is_allocator.h create mode 100644 lib/libcxx/include/__type_traits/is_always_bitcastable.h create mode 100644 lib/libcxx/include/__type_traits/is_char_like_type.h create mode 100644 lib/libcxx/include/__type_traits/is_implicitly_default_constructible.h create mode 100644 lib/libcxx/include/__type_traits/is_specialization.h create mode 100644 lib/libcxx/include/__type_traits/is_swappable.h create mode 100644 lib/libcxx/include/__type_traits/make_const_lvalue_ref.h create mode 100644 lib/libcxx/include/__type_traits/maybe_const.h create mode 100644 lib/libcxx/include/__type_traits/noexcept_move_assign_container.h create mode 100644 lib/libcxx/include/__type_traits/remove_const_ref.h create mode 100644 lib/libcxx/include/__type_traits/result_of.h create mode 100644 lib/libcxx/include/__type_traits/strip_signature.h create mode 100644 lib/libcxx/include/__utility/convert_to_integral.h create mode 100644 lib/libcxx/include/__utility/exception_guard.h create mode 100644 lib/libcxx/include/__utility/forward_like.h delete mode 100644 lib/libcxx/include/__utility/transaction.h create mode 100644 lib/libcxx/include/expected create mode 100644 lib/libcxx/include/memory_resource create mode 100644 lib/libcxx/include/source_location create mode 100644 lib/libcxx/src/memory_resource.cpp create mode 100644 lib/libcxx/src/memory_resource_init_helper.h diff --git a/lib/libcxx/include/__algorithm/adjacent_find.h b/lib/libcxx/include/__algorithm/adjacent_find.h index 1089bb20d5..30df4a976f 100644 --- a/lib/libcxx/include/__algorithm/adjacent_find.h +++ b/lib/libcxx/include/__algorithm/adjacent_find.h @@ -23,7 +23,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD template -_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 _Iter +_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Iter __adjacent_find(_Iter __first, _Sent __last, _BinaryPredicate&& __pred) { if (__first == __last) return __first; @@ -37,16 +37,15 @@ __adjacent_find(_Iter __first, _Sent __last, _BinaryPredicate&& __pred) { } template -_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator +_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator adjacent_find(_ForwardIterator __first, _ForwardIterator __last, _BinaryPredicate __pred) { return std::__adjacent_find(std::move(__first), std::move(__last), __pred); } template -_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator +_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator adjacent_find(_ForwardIterator __first, _ForwardIterator __last) { - typedef typename iterator_traits<_ForwardIterator>::value_type __v; - return std::adjacent_find(std::move(__first), std::move(__last), __equal_to<__v>()); + return std::adjacent_find(std::move(__first), std::move(__last), __equal_to()); } _LIBCPP_END_NAMESPACE_STD diff --git a/lib/libcxx/include/__algorithm/all_of.h b/lib/libcxx/include/__algorithm/all_of.h index 3af32a5775..284c34ffcd 100644 --- a/lib/libcxx/include/__algorithm/all_of.h +++ b/lib/libcxx/include/__algorithm/all_of.h @@ -19,7 +19,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD template -_LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 bool +_LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 bool all_of(_InputIterator __first, _InputIterator __last, _Predicate __pred) { for (; __first != __last; ++__first) if (!__pred(*__first)) diff --git a/lib/libcxx/include/__algorithm/any_of.h b/lib/libcxx/include/__algorithm/any_of.h index 6fe6a0b6b3..fe0882816b 100644 --- a/lib/libcxx/include/__algorithm/any_of.h +++ b/lib/libcxx/include/__algorithm/any_of.h @@ -19,7 +19,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD template -_LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 bool +_LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 bool any_of(_InputIterator __first, _InputIterator __last, _Predicate __pred) { for (; __first != __last; ++__first) if (__pred(*__first)) diff --git a/lib/libcxx/include/__algorithm/binary_search.h b/lib/libcxx/include/__algorithm/binary_search.h index a440072378..8f958c2c1a 100644 --- a/lib/libcxx/include/__algorithm/binary_search.h +++ b/lib/libcxx/include/__algorithm/binary_search.h @@ -23,18 +23,17 @@ _LIBCPP_BEGIN_NAMESPACE_STD template _LIBCPP_NODISCARD_EXT inline -_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 bool binary_search(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value, _Compare __comp) { - using _Comp_ref = typename __comp_ref_type<_Compare>::type; - __first = std::lower_bound<_ForwardIterator, _Tp, _Comp_ref>(__first, __last, __value, __comp); + __first = std::lower_bound<_ForwardIterator, _Tp, __comp_ref_type<_Compare> >(__first, __last, __value, __comp); return __first != __last && !__comp(__value, *__first); } template _LIBCPP_NODISCARD_EXT inline -_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 bool binary_search(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value) { diff --git a/lib/libcxx/include/__algorithm/comp.h b/lib/libcxx/include/__algorithm/comp.h index 62c06ae57f..af8eb7b5d7 100644 --- a/lib/libcxx/include/__algorithm/comp.h +++ b/lib/libcxx/include/__algorithm/comp.h @@ -17,73 +17,47 @@ _LIBCPP_BEGIN_NAMESPACE_STD -// I'd like to replace these with _VSTD::equal_to, but can't because: -// * That only works with C++14 and later, and -// * We haven't included here. -template -struct __equal_to -{ - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 bool operator()(const _T1& __x, const _T1& __y) const {return __x == __y;} - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 bool operator()(const _T1& __x, const _T2& __y) const {return __x == __y;} - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 bool operator()(const _T2& __x, const _T1& __y) const {return __x == __y;} - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 bool operator()(const _T2& __x, const _T2& __y) const {return __x == __y;} -}; - -template -struct __equal_to<_T1, _T1> -{ - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 - bool operator()(const _T1& __x, const _T1& __y) const {return __x == __y;} -}; - -template -struct __equal_to -{ - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 - bool operator()(const _T1& __x, const _T1& __y) const {return __x == __y;} -}; - -template -struct __equal_to<_T1, const _T1> -{ - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 - bool operator()(const _T1& __x, const _T1& __y) const {return __x == __y;} +struct __equal_to { + template + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool operator()(const _T1& __x, const _T2& __y) const { + return __x == __y; + } }; template struct __less { - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14 bool operator()(const _T1& __x, const _T1& __y) const {return __x < __y;} - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14 bool operator()(const _T1& __x, const _T2& __y) const {return __x < __y;} - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14 bool operator()(const _T2& __x, const _T1& __y) const {return __x < __y;} - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14 bool operator()(const _T2& __x, const _T2& __y) const {return __x < __y;} }; template struct __less<_T1, _T1> { - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14 bool operator()(const _T1& __x, const _T1& __y) const {return __x < __y;} }; template struct __less { - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14 bool operator()(const _T1& __x, const _T1& __y) const {return __x < __y;} }; template struct __less<_T1, const _T1> { - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14 bool operator()(const _T1& __x, const _T1& __y) const {return __x < __y;} }; diff --git a/lib/libcxx/include/__algorithm/comp_ref_type.h b/lib/libcxx/include/__algorithm/comp_ref_type.h index 4719871461..f2338e1446 100644 --- a/lib/libcxx/include/__algorithm/comp_ref_type.h +++ b/lib/libcxx/include/__algorithm/comp_ref_type.h @@ -23,11 +23,11 @@ template struct __debug_less { _Compare &__comp_; - _LIBCPP_CONSTEXPR_AFTER_CXX11 + _LIBCPP_CONSTEXPR_SINCE_CXX14 __debug_less(_Compare& __c) : __comp_(__c) {} template - _LIBCPP_CONSTEXPR_AFTER_CXX11 + _LIBCPP_CONSTEXPR_SINCE_CXX14 bool operator()(const _Tp& __x, const _Up& __y) { bool __r = __comp_(__x, __y); @@ -37,7 +37,7 @@ struct __debug_less } template - _LIBCPP_CONSTEXPR_AFTER_CXX11 + _LIBCPP_CONSTEXPR_SINCE_CXX14 bool operator()(_Tp& __x, _Up& __y) { bool __r = __comp_(__x, __y); @@ -47,10 +47,10 @@ struct __debug_less } template - _LIBCPP_CONSTEXPR_AFTER_CXX11 + _LIBCPP_CONSTEXPR_SINCE_CXX14 inline _LIBCPP_INLINE_VISIBILITY - decltype((void)declval<_Compare&>()( - declval<_LHS &>(), declval<_RHS &>())) + decltype((void)std::declval<_Compare&>()( + std::declval<_LHS &>(), std::declval<_RHS &>())) __do_compare_assert(int, _LHS & __l, _RHS & __r) { _LIBCPP_DEBUG_ASSERT(!__comp_(__l, __r), "Comparator does not induce a strict weak ordering"); @@ -59,21 +59,20 @@ struct __debug_less } template - _LIBCPP_CONSTEXPR_AFTER_CXX11 + _LIBCPP_CONSTEXPR_SINCE_CXX14 inline _LIBCPP_INLINE_VISIBILITY void __do_compare_assert(long, _LHS &, _RHS &) {} }; -template -struct __comp_ref_type { - // Pass the comparator by lvalue reference. Or in debug mode, using a - // debugging wrapper that stores a reference. +// Pass the comparator by lvalue reference. Or in debug mode, using a +// debugging wrapper that stores a reference. #ifdef _LIBCPP_ENABLE_DEBUG_MODE - typedef __debug_less<_Comp> type; +template +using __comp_ref_type = __debug_less<_Comp>; #else - typedef _Comp& type; +template +using __comp_ref_type = _Comp&; #endif -}; _LIBCPP_END_NAMESPACE_STD diff --git a/lib/libcxx/include/__algorithm/copy.h b/lib/libcxx/include/__algorithm/copy.h index f7535a8154..193a6df316 100644 --- a/lib/libcxx/include/__algorithm/copy.h +++ b/lib/libcxx/include/__algorithm/copy.h @@ -9,100 +9,118 @@ #ifndef _LIBCPP___ALGORITHM_COPY_H #define _LIBCPP___ALGORITHM_COPY_H -#include <__algorithm/unwrap_iter.h> -#include <__algorithm/unwrap_range.h> +#include <__algorithm/copy_move_common.h> +#include <__algorithm/iterator_operations.h> +#include <__algorithm/min.h> #include <__config> -#include <__iterator/iterator_traits.h> -#include <__iterator/reverse_iterator.h> +#include <__iterator/segmented_iterator.h> +#include <__type_traits/common_type.h> #include <__utility/move.h> #include <__utility/pair.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 -// copy +template +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_InIter, _OutIter> __copy(_InIter, _Sent, _OutIter); -template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 -pair<_InIter, _OutIter> __copy_impl(_InIter __first, _Sent __last, _OutIter __result) { - while (__first != __last) { - *__result = *__first; - ++__first; - ++__result; +template +struct __copy_loop { + template + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_InIter, _OutIter> + operator()(_InIter __first, _Sent __last, _OutIter __result) const { + while (__first != __last) { + *__result = *__first; + ++__first; + ++__result; + } + + return std::make_pair(std::move(__first), std::move(__result)); } - return pair<_InIter, _OutIter>(std::move(__first), std::move(__result)); -} -template ::type, _OutValueT>::value - && is_trivially_copy_assignable<_OutValueT>::value> > -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 -pair<_InValueT*, _OutValueT*> __copy_impl(_InValueT* __first, _InValueT* __last, _OutValueT* __result) { - if (__libcpp_is_constant_evaluated() -// TODO: Remove this once GCC supports __builtin_memmove during constant evaluation -#ifndef _LIBCPP_COMPILER_GCC - && !is_trivially_copyable<_InValueT>::value -#endif - ) - return std::__copy_impl<_InValueT*, _InValueT*, _OutValueT*>(__first, __last, __result); - const size_t __n = static_cast(__last - __first); - if (__n > 0) - ::__builtin_memmove(__result, __first, __n * sizeof(_OutValueT)); - return std::make_pair(__first + __n, __result + __n); -} + template ::value, int> = 0> + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_InIter, _OutIter> + operator()(_InIter __first, _InIter __last, _OutIter __result) const { + using _Traits = __segmented_iterator_traits<_InIter>; + auto __sfirst = _Traits::__segment(__first); + auto __slast = _Traits::__segment(__last); + if (__sfirst == __slast) { + auto __iters = std::__copy<_AlgPolicy>(_Traits::__local(__first), _Traits::__local(__last), std::move(__result)); + return std::make_pair(__last, std::move(__iters.second)); + } -template >::type, __iter_value_type<_OutIter> >::value - && __is_cpp17_contiguous_iterator::value - && __is_cpp17_contiguous_iterator::value - && is_trivially_copy_assignable<__iter_value_type<_OutIter> >::value - && __is_reverse_iterator<_InIter>::value - && __is_reverse_iterator<_OutIter>::value, int> = 0> -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 -pair<_InIter, _OutIter> -__copy_impl(_InIter __first, _InIter __last, _OutIter __result) { - auto __first_base = std::__unwrap_iter(__first.base()); - auto __last_base = std::__unwrap_iter(__last.base()); - auto __result_base = std::__unwrap_iter(__result.base()); - auto __result_first = __result_base - (__first_base - __last_base); - std::__copy_impl(__last_base, __first_base, __result_first); - return std::make_pair(__last, _OutIter(std::__rewrap_iter(__result.base(), __result_first))); -} + __result = std::__copy<_AlgPolicy>(_Traits::__local(__first), _Traits::__end(__sfirst), std::move(__result)).second; + ++__sfirst; + while (__sfirst != __slast) { + __result = + std::__copy<_AlgPolicy>(_Traits::__begin(__sfirst), _Traits::__end(__sfirst), std::move(__result)).second; + ++__sfirst; + } + __result = + std::__copy<_AlgPolicy>(_Traits::__begin(__sfirst), _Traits::__local(__last), std::move(__result)).second; + return std::make_pair(__last, std::move(__result)); + } -template ::value - && is_copy_constructible<_Sent>::value - && is_copy_constructible<_OutIter>::value), int> = 0 > -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 -pair<_InIter, _OutIter> __copy(_InIter __first, _Sent __last, _OutIter __result) { - return std::__copy_impl(std::move(__first), std::move(__last), std::move(__result)); -} + template ::value && + !__is_segmented_iterator<_InIter>::value && __is_segmented_iterator<_OutIter>::value, + int> = 0> + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_InIter, _OutIter> + operator()(_InIter __first, _InIter __last, _OutIter __result) { + using _Traits = __segmented_iterator_traits<_OutIter>; + using _DiffT = typename common_type<__iter_diff_t<_InIter>, __iter_diff_t<_OutIter> >::type; -template ::value - && is_copy_constructible<_Sent>::value - && is_copy_constructible<_OutIter>::value, int> = 0> -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 -pair<_InIter, _OutIter> __copy(_InIter __first, _Sent __last, _OutIter __result) { - auto __range = std::__unwrap_range(__first, __last); - auto __ret = std::__copy_impl(std::move(__range.first), std::move(__range.second), std::__unwrap_iter(__result)); - return std::make_pair( - std::__rewrap_range<_Sent>(__first, __ret.first), std::__rewrap_iter(__result, __ret.second)); + if (__first == __last) + return std::make_pair(std::move(__first), std::move(__result)); + + auto __local_first = _Traits::__local(__result); + auto __segment_iterator = _Traits::__segment(__result); + while (true) { + auto __local_last = _Traits::__end(__segment_iterator); + auto __size = std::min<_DiffT>(__local_last - __local_first, __last - __first); + auto __iters = std::__copy<_AlgPolicy>(__first, __first + __size, __local_first); + __first = std::move(__iters.first); + + if (__first == __last) + return std::make_pair(std::move(__first), _Traits::__compose(__segment_iterator, std::move(__iters.second))); + + __local_first = _Traits::__begin(++__segment_iterator); + } + } +}; + +struct __copy_trivial { + // 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*> + 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 +__copy(_InIter __first, _Sent __last, _OutIter __result) { + return std::__dispatch_copy_or_move<_AlgPolicy, __copy_loop<_AlgPolicy>, __copy_trivial>( + std::move(__first), std::move(__last), std::move(__result)); } template -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 -_OutputIterator +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator copy(_InputIterator __first, _InputIterator __last, _OutputIterator __result) { - return std::__copy(__first, __last, __result).second; + return std::__copy<_ClassicAlgPolicy>(__first, __last, __result).second; } _LIBCPP_END_NAMESPACE_STD +_LIBCPP_POP_MACROS + #endif // _LIBCPP___ALGORITHM_COPY_H diff --git a/lib/libcxx/include/__algorithm/copy_backward.h b/lib/libcxx/include/__algorithm/copy_backward.h index c5fa64bc8d..bb2a432878 100644 --- a/lib/libcxx/include/__algorithm/copy_backward.h +++ b/lib/libcxx/include/__algorithm/copy_backward.h @@ -9,53 +9,135 @@ #ifndef _LIBCPP___ALGORITHM_COPY_BACKWARD_H #define _LIBCPP___ALGORITHM_COPY_BACKWARD_H -#include <__algorithm/copy.h> +#include <__algorithm/copy_move_common.h> #include <__algorithm/iterator_operations.h> -#include <__algorithm/ranges_copy.h> -#include <__algorithm/unwrap_iter.h> -#include <__concepts/same_as.h> +#include <__algorithm/min.h> #include <__config> -#include <__iterator/iterator_traits.h> -#include <__iterator/reverse_iterator.h> -#include <__ranges/subrange.h> +#include <__iterator/segmented_iterator.h> +#include <__type_traits/common_type.h> +#include <__type_traits/is_copy_constructible.h> #include <__utility/move.h> #include <__utility/pair.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 -template ::value, int> = 0> -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 pair<_InputIterator, _OutputIterator> -__copy_backward(_InputIterator __first, _InputIterator __last, _OutputIterator __result) { - auto __ret = std::__copy( - __unconstrained_reverse_iterator<_InputIterator>(__last), - __unconstrained_reverse_iterator<_InputIterator>(__first), - __unconstrained_reverse_iterator<_OutputIterator>(__result)); - return pair<_InputIterator, _OutputIterator>(__ret.first.base(), __ret.second.base()); -} +template +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_InIter, _OutIter> +__copy_backward(_InIter __first, _Sent __last, _OutIter __result); -#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) -template ::value, int> = 0> -_LIBCPP_HIDE_FROM_ABI constexpr pair<_Iter1, _Iter2> __copy_backward(_Iter1 __first, _Sent1 __last, _Iter2 __result) { - auto __last_iter = _IterOps<_AlgPolicy>::next(__first, std::move(__last)); - auto __reverse_range = std::__reverse_range(std::ranges::subrange(std::move(__first), __last_iter)); - auto __ret = ranges::copy(std::move(__reverse_range), std::make_reverse_iterator(__result)); - return std::make_pair(__last_iter, __ret.out.base()); +template +struct __copy_backward_loop { + template + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_InIter, _OutIter> + operator()(_InIter __first, _Sent __last, _OutIter __result) const { + auto __last_iter = _IterOps<_AlgPolicy>::next(__first, __last); + auto __original_last_iter = __last_iter; + + while (__first != __last_iter) { + *--__result = *--__last_iter; + } + + return std::make_pair(std::move(__original_last_iter), std::move(__result)); + } + + template ::value, int> = 0> + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_InIter, _OutIter> + operator()(_InIter __first, _InIter __last, _OutIter __result) const { + using _Traits = __segmented_iterator_traits<_InIter>; + auto __sfirst = _Traits::__segment(__first); + auto __slast = _Traits::__segment(__last); + if (__sfirst == __slast) { + auto __iters = + std::__copy_backward<_AlgPolicy>(_Traits::__local(__first), _Traits::__local(__last), std::move(__result)); + return std::make_pair(__last, __iters.second); + } + + __result = + std::__copy_backward<_AlgPolicy>(_Traits::__begin(__slast), _Traits::__local(__last), std::move(__result)) + .second; + --__slast; + while (__sfirst != __slast) { + __result = + std::__copy_backward<_AlgPolicy>(_Traits::__begin(__slast), _Traits::__end(__slast), std::move(__result)) + .second; + --__slast; + } + __result = std::__copy_backward<_AlgPolicy>(_Traits::__local(__first), _Traits::__end(__slast), std::move(__result)) + .second; + return std::make_pair(__last, std::move(__result)); + } + + template ::value && + !__is_segmented_iterator<_InIter>::value && __is_segmented_iterator<_OutIter>::value, + int> = 0> + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_InIter, _OutIter> + operator()(_InIter __first, _InIter __last, _OutIter __result) { + using _Traits = __segmented_iterator_traits<_OutIter>; + auto __orig_last = __last; + auto __segment_iterator = _Traits::__segment(__result); + + // When the range contains no elements, __result might not be a valid iterator + if (__first == __last) + return std::make_pair(__first, __result); + + auto __local_last = _Traits::__local(__result); + while (true) { + using _DiffT = typename common_type<__iter_diff_t<_InIter>, __iter_diff_t<_OutIter> >::type; + + 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; + __last -= __size; + + if (__first == __last) + return std::make_pair(std::move(__orig_last), _Traits::__compose(__segment_iterator, std::move(__iter))); + --__segment_iterator; + __local_last = _Traits::__end(__segment_iterator); + } + } +}; + +struct __copy_backward_trivial { + // 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*> + 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> +__copy_backward(_BidirectionalIterator1 __first, _Sentinel __last, _BidirectionalIterator2 __result) { + return std::__dispatch_copy_or_move<_AlgPolicy, __copy_backward_loop<_AlgPolicy>, __copy_backward_trivial>( + std::move(__first), std::move(__last), std::move(__result)); } -#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 _BidirectionalIterator2 -copy_backward(_BidirectionalIterator1 __first, _BidirectionalIterator1 __last, _BidirectionalIterator2 __result) { - return std::__copy_backward<_ClassicAlgPolicy>(__first, __last, __result).second; +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 +_BidirectionalIterator2 +copy_backward(_BidirectionalIterator1 __first, _BidirectionalIterator1 __last, + _BidirectionalIterator2 __result) +{ + static_assert(std::is_copy_constructible<_BidirectionalIterator1>::value && + 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; } _LIBCPP_END_NAMESPACE_STD +_LIBCPP_POP_MACROS + #endif // _LIBCPP___ALGORITHM_COPY_BACKWARD_H diff --git a/lib/libcxx/include/__algorithm/copy_if.h b/lib/libcxx/include/__algorithm/copy_if.h index 9c3cd29e24..a5938b8719 100644 --- a/lib/libcxx/include/__algorithm/copy_if.h +++ b/lib/libcxx/include/__algorithm/copy_if.h @@ -18,7 +18,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD template -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator copy_if(_InputIterator __first, _InputIterator __last, _OutputIterator __result, _Predicate __pred) diff --git a/lib/libcxx/include/__algorithm/copy_move_common.h b/lib/libcxx/include/__algorithm/copy_move_common.h new file mode 100644 index 0000000000..b88c14911b --- /dev/null +++ b/lib/libcxx/include/__algorithm/copy_move_common.h @@ -0,0 +1,163 @@ +//===----------------------------------------------------------------------===// +// +// 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_COPY_MOVE_COMMON_H +#define _LIBCPP___ALGORITHM_COPY_MOVE_COMMON_H + +#include <__algorithm/iterator_operations.h> +#include <__algorithm/unwrap_iter.h> +#include <__algorithm/unwrap_range.h> +#include <__config> +#include <__iterator/iterator_traits.h> +#include <__memory/pointer_traits.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_copy_constructible.h> +#include <__type_traits/is_trivially_assignable.h> +#include <__type_traits/is_trivially_copyable.h> +#include <__type_traits/is_volatile.h> +#include <__utility/move.h> +#include <__utility/pair.h> +#include + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +// Type traits. + +template +struct __can_lower_copy_assignment_to_memmove { + static const bool value = + // If the types are always bitcastable, it's valid to do a bitwise copy between them. + __is_always_bitcastable<_From, _To>::value && + // Reject conversions that wouldn't be performed by the regular built-in assignment (e.g. between arrays). + is_trivially_assignable<_To&, const _From&>::value && + // `memmove` doesn't accept `volatile` pointers, make sure the optimization SFINAEs away in that case. + !is_volatile<_From>::value && + !is_volatile<_To>::value; +}; + +template +struct __can_lower_move_assignment_to_memmove { + static const bool value = + __is_always_bitcastable<_From, _To>::value && + is_trivially_assignable<_To&, _From&&>::value && + !is_volatile<_From>::value && + !is_volatile<_To>::value; +}; + +// `memmove` algorithms implementation. + +template +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_In*, _Out*> +__copy_trivial_impl(_In* __first, _In* __last, _Out* __result) { + const size_t __n = static_cast(__last - __first); + ::__builtin_memmove(__result, __first, __n * sizeof(_Out)); + + return std::make_pair(__last, __result + __n); +} + +template +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_In*, _Out*> +__copy_backward_trivial_impl(_In* __first, _In* __last, _Out* __result) { + const size_t __n = static_cast(__last - __first); + __result -= __n; + + ::__builtin_memmove(__result, __first, __n * sizeof(_Out)); + + return std::make_pair(__last, __result); +} + +// Iterator unwrapping and dispatching to the correct overload. + +template +struct __overload : _F1, _F2 { + using _F1::operator(); + using _F2::operator(); +}; + +template +struct __can_rewrap : false_type {}; + +template +struct __can_rewrap<_InIter, + _Sent, + _OutIter, + // Note that sentinels are always copy-constructible. + __enable_if_t< is_copy_constructible<_InIter>::value && + is_copy_constructible<_OutIter>::value > > : true_type {}; + +template ::value, int> = 0> +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 pair<_InIter, _OutIter> +__unwrap_and_dispatch(_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))); +} + +template ::value, int> = 0> +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 pair<_InIter, _OutIter> +__unwrap_and_dispatch(_InIter __first, _Sent __last, _OutIter __out_first) { + return _Algorithm()(std::move(__first), std::move(__last), std::move(__out_first)); +} + +template +struct __can_copy_without_conversion : false_type {}; + +template +struct __can_copy_without_conversion< + _IterOps, + _InValue, + _OutIter, + __enable_if_t >::value> > : true_type {}; + +template +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 pair<_InIter, _OutIter> +__dispatch_copy_or_move(_InIter __first, _Sent __last, _OutIter __out_first) { +#ifdef _LIBCPP_COMPILER_GCC + // GCC doesn't support `__builtin_memmove` during constant evaluation. + if (__libcpp_is_constant_evaluated()) { + return std::__unwrap_and_dispatch<_NaiveAlgorithm>(std::move(__first), std::move(__last), std::move(__out_first)); + } +#else + // In Clang, `__builtin_memmove` only supports fully trivially copyable types (just having trivial copy assignment is + // insufficient). Also, conversions are not supported. + if (__libcpp_is_constant_evaluated()) { + using _InValue = typename _IterOps<_AlgPolicy>::template __value_type<_InIter>; + if (!is_trivially_copyable<_InValue>::value || + !__can_copy_without_conversion<_IterOps<_AlgPolicy>, _InValue, _OutIter>::value) { + return std::__unwrap_and_dispatch<_NaiveAlgorithm>(std::move(__first), std::move(__last), std::move(__out_first)); + } + } +#endif // _LIBCPP_COMPILER_GCC + + using _Algorithm = __overload<_NaiveAlgorithm, _OptimizedAlgorithm>; + return std::__unwrap_and_dispatch<_Algorithm>(std::move(__first), std::move(__last), std::move(__out_first)); +} + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___ALGORITHM_COPY_MOVE_COMMON_H diff --git a/lib/libcxx/include/__algorithm/copy_n.h b/lib/libcxx/include/__algorithm/copy_n.h index 8b915af63c..b08bbdfb9b 100644 --- a/lib/libcxx/include/__algorithm/copy_n.h +++ b/lib/libcxx/include/__algorithm/copy_n.h @@ -12,6 +12,7 @@ #include <__algorithm/copy.h> #include <__config> #include <__iterator/iterator_traits.h> +#include <__utility/convert_to_integral.h> #include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) @@ -21,7 +22,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD template -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 typename enable_if < __is_cpp17_input_iterator<_InputIterator>::value && @@ -47,7 +48,7 @@ copy_n(_InputIterator __first, _Size __orig_n, _OutputIterator __result) } template -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 typename enable_if < __is_cpp17_random_access_iterator<_InputIterator>::value, diff --git a/lib/libcxx/include/__algorithm/count.h b/lib/libcxx/include/__algorithm/count.h index 5b54693403..6c8c7fda35 100644 --- a/lib/libcxx/include/__algorithm/count.h +++ b/lib/libcxx/include/__algorithm/count.h @@ -20,7 +20,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD template -_LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +_LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 typename iterator_traits<_InputIterator>::difference_type count(_InputIterator __first, _InputIterator __last, const _Tp& __value) { typename iterator_traits<_InputIterator>::difference_type __r(0); diff --git a/lib/libcxx/include/__algorithm/count_if.h b/lib/libcxx/include/__algorithm/count_if.h index 1ec2d83394..b96521fe0a 100644 --- a/lib/libcxx/include/__algorithm/count_if.h +++ b/lib/libcxx/include/__algorithm/count_if.h @@ -20,7 +20,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD template -_LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +_LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 typename iterator_traits<_InputIterator>::difference_type count_if(_InputIterator __first, _InputIterator __last, _Predicate __pred) { typename iterator_traits<_InputIterator>::difference_type __r(0); diff --git a/lib/libcxx/include/__algorithm/equal.h b/lib/libcxx/include/__algorithm/equal.h index ca1bc6bc56..cf37f46aaf 100644 --- a/lib/libcxx/include/__algorithm/equal.h +++ b/lib/libcxx/include/__algorithm/equal.h @@ -22,7 +22,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD template -_LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 bool +_LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 bool equal(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _BinaryPredicate __pred) { for (; __first1 != __last1; ++__first1, (void)++__first2) if (!__pred(*__first1, *__first2)) @@ -31,16 +31,14 @@ equal(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first } template -_LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 bool +_LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 bool equal(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2) { - typedef typename iterator_traits<_InputIterator1>::value_type __v1; - typedef typename iterator_traits<_InputIterator2>::value_type __v2; - return _VSTD::equal(__first1, __last1, __first2, __equal_to<__v1, __v2>()); + return std::equal(__first1, __last1, __first2, __equal_to()); } #if _LIBCPP_STD_VER > 11 template -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 bool +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 bool __equal(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2, _BinaryPredicate __pred, input_iterator_tag, input_iterator_tag) { for (; __first1 != __last1 && __first2 != __last2; ++__first1, (void)++__first2) @@ -50,7 +48,7 @@ __equal(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __fir } template -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 bool +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 bool __equal(_RandomAccessIterator1 __first1, _RandomAccessIterator1 __last1, _RandomAccessIterator2 __first2, _RandomAccessIterator2 __last2, _BinaryPredicate __pred, random_access_iterator_tag, random_access_iterator_tag) { @@ -61,7 +59,7 @@ __equal(_RandomAccessIterator1 __first1, _RandomAccessIterator1 __last1, _Random } template -_LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 bool +_LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 bool equal(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2, _BinaryPredicate __pred) { return _VSTD::__equal<_BinaryPredicate&>( @@ -70,13 +68,16 @@ equal(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first } template -_LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 bool +_LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 bool equal(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2) { - typedef typename iterator_traits<_InputIterator1>::value_type __v1; - typedef typename iterator_traits<_InputIterator2>::value_type __v2; - return _VSTD::__equal(__first1, __last1, __first2, __last2, __equal_to<__v1, __v2>(), - typename iterator_traits<_InputIterator1>::iterator_category(), - typename iterator_traits<_InputIterator2>::iterator_category()); + return std::__equal( + __first1, + __last1, + __first2, + __last2, + __equal_to(), + typename iterator_traits<_InputIterator1>::iterator_category(), + typename iterator_traits<_InputIterator2>::iterator_category()); } #endif diff --git a/lib/libcxx/include/__algorithm/equal_range.h b/lib/libcxx/include/__algorithm/equal_range.h index b11165baf3..2075b03412 100644 --- a/lib/libcxx/include/__algorithm/equal_range.h +++ b/lib/libcxx/include/__algorithm/equal_range.h @@ -34,7 +34,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 pair<_Iter, _Iter> +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_Iter, _Iter> __equal_range(_Iter __first, _Sent __last, const _Tp& __value, _Compare&& __comp, _Proj&& __proj) { auto __len = _IterOps<_AlgPolicy>::distance(__first, __last); _Iter __end = _IterOps<_AlgPolicy>::next(__first, __last); @@ -58,19 +58,22 @@ __equal_range(_Iter __first, _Sent __last, const _Tp& __value, _Compare&& __comp } template -_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 pair<_ForwardIterator, _ForwardIterator> +_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_ForwardIterator, _ForwardIterator> equal_range(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value, _Compare __comp) { static_assert(__is_callable<_Compare, decltype(*__first), const _Tp&>::value, "The comparator has to be callable"); static_assert(is_copy_constructible<_ForwardIterator>::value, "Iterator has to be copy constructible"); - typedef typename __comp_ref_type<_Compare>::type _Comp_ref; return std::__equal_range<_ClassicAlgPolicy>( - std::move(__first), std::move(__last), __value, static_cast<_Comp_ref>(__comp), std::__identity()); + std::move(__first), + std::move(__last), + __value, + static_cast<__comp_ref_type<_Compare> >(__comp), + std::__identity()); } template -_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 pair<_ForwardIterator, _ForwardIterator> +_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_ForwardIterator, _ForwardIterator> equal_range(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value) { return std::equal_range( std::move(__first), diff --git a/lib/libcxx/include/__algorithm/fill.h b/lib/libcxx/include/__algorithm/fill.h index 901ba4e686..76cf4a1477 100644 --- a/lib/libcxx/include/__algorithm/fill.h +++ b/lib/libcxx/include/__algorithm/fill.h @@ -23,7 +23,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD // fill isn't specialized for std::memset, because the compiler already optimizes the loop to a call to std::memset. template -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 void __fill(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value, forward_iterator_tag) { @@ -32,7 +32,7 @@ __fill(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value, fo } template -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 void __fill(_RandomAccessIterator __first, _RandomAccessIterator __last, const _Tp& __value, random_access_iterator_tag) { @@ -40,7 +40,7 @@ __fill(_RandomAccessIterator __first, _RandomAccessIterator __last, const _Tp& _ } template -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 void fill(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value) { diff --git a/lib/libcxx/include/__algorithm/fill_n.h b/lib/libcxx/include/__algorithm/fill_n.h index 6c5e44efde..fe58c8d641 100644 --- a/lib/libcxx/include/__algorithm/fill_n.h +++ b/lib/libcxx/include/__algorithm/fill_n.h @@ -11,6 +11,7 @@ #include <__config> #include <__iterator/iterator_traits.h> +#include <__utility/convert_to_integral.h> #include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) @@ -22,7 +23,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD // fill_n isn't specialized for std::memset, because the compiler already optimizes the loop to a call to std::memset. template -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator __fill_n(_OutputIterator __first, _Size __n, const _Tp& __value) { @@ -32,7 +33,7 @@ __fill_n(_OutputIterator __first, _Size __n, const _Tp& __value) } template -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator fill_n(_OutputIterator __first, _Size __n, const _Tp& __value) { diff --git a/lib/libcxx/include/__algorithm/find.h b/lib/libcxx/include/__algorithm/find.h index ab37d81262..e51dc9bb16 100644 --- a/lib/libcxx/include/__algorithm/find.h +++ b/lib/libcxx/include/__algorithm/find.h @@ -19,7 +19,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD template -_LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _InputIterator +_LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 _InputIterator find(_InputIterator __first, _InputIterator __last, const _Tp& __value) { for (; __first != __last; ++__first) if (*__first == __value) diff --git a/lib/libcxx/include/__algorithm/find_end.h b/lib/libcxx/include/__algorithm/find_end.h index 65e9f29b1c..e2fee6b3c4 100644 --- a/lib/libcxx/include/__algorithm/find_end.h +++ b/lib/libcxx/include/__algorithm/find_end.h @@ -37,7 +37,7 @@ template < class _Pred, class _Proj1, class _Proj2> -_LIBCPP_HIDE_FROM_ABI inline _LIBCPP_CONSTEXPR_AFTER_CXX11 pair<_Iter1, _Iter1> __find_end_impl( +_LIBCPP_HIDE_FROM_ABI inline _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_Iter1, _Iter1> __find_end_impl( _Iter1 __first1, _Sent1 __last1, _Iter2 __first2, @@ -91,7 +91,7 @@ template < class _Sent2, class _Proj1, class _Proj2> -_LIBCPP_CONSTEXPR_AFTER_CXX17 _Iter1 __find_end( +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Iter1 __find_end( _Iter1 __first1, _Sent1 __sent1, _Iter2 __first2, @@ -144,7 +144,7 @@ template < class _Sent2, class _Proj1, class _Proj2> -_LIBCPP_CONSTEXPR_AFTER_CXX11 _Iter1 __find_end( +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Iter1 __find_end( _Iter1 __first1, _Sent1 __sent1, _Iter2 __first2, @@ -189,7 +189,7 @@ _LIBCPP_CONSTEXPR_AFTER_CXX11 _Iter1 __find_end( } template -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 +_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _ForwardIterator1 __find_end_classic(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2, _ForwardIterator2 __last2, _BinaryPredicate& __pred) { @@ -208,7 +208,7 @@ _ForwardIterator1 __find_end_classic(_ForwardIterator1 __first1, _ForwardIterato } template -_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 +_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator1 find_end(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2, _ForwardIterator2 __last2, _BinaryPredicate __pred) { @@ -216,12 +216,10 @@ _ForwardIterator1 find_end(_ForwardIterator1 __first1, _ForwardIterator1 __last1 } template -_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 +_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator1 find_end(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2, _ForwardIterator2 __last2) { - using __v1 = typename iterator_traits<_ForwardIterator1>::value_type; - using __v2 = typename iterator_traits<_ForwardIterator2>::value_type; - return std::find_end(__first1, __last1, __first2, __last2, __equal_to<__v1, __v2>()); + return std::find_end(__first1, __last1, __first2, __last2, __equal_to()); } _LIBCPP_END_NAMESPACE_STD diff --git a/lib/libcxx/include/__algorithm/find_first_of.h b/lib/libcxx/include/__algorithm/find_first_of.h index 2096b0f0c9..12f0109a61 100644 --- a/lib/libcxx/include/__algorithm/find_first_of.h +++ b/lib/libcxx/include/__algorithm/find_first_of.h @@ -21,7 +21,8 @@ _LIBCPP_BEGIN_NAMESPACE_STD template -_LIBCPP_CONSTEXPR_AFTER_CXX11 _ForwardIterator1 __find_first_of_ce(_ForwardIterator1 __first1, +_LIBCPP_HIDE_FROM_ABI +_LIBCPP_CONSTEXPR_SINCE_CXX14 _ForwardIterator1 __find_first_of_ce(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2, _ForwardIterator2 __last2, @@ -34,18 +35,16 @@ _LIBCPP_CONSTEXPR_AFTER_CXX11 _ForwardIterator1 __find_first_of_ce(_ForwardItera } template -_LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator1 +_LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator1 find_first_of(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2, _ForwardIterator2 __last2, _BinaryPredicate __pred) { return _VSTD::__find_first_of_ce(__first1, __last1, __first2, __last2, __pred); } template -_LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator1 find_first_of( +_LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator1 find_first_of( _ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2, _ForwardIterator2 __last2) { - typedef typename iterator_traits<_ForwardIterator1>::value_type __v1; - typedef typename iterator_traits<_ForwardIterator2>::value_type __v2; - return _VSTD::__find_first_of_ce(__first1, __last1, __first2, __last2, __equal_to<__v1, __v2>()); + return std::__find_first_of_ce(__first1, __last1, __first2, __last2, __equal_to()); } _LIBCPP_END_NAMESPACE_STD diff --git a/lib/libcxx/include/__algorithm/find_if.h b/lib/libcxx/include/__algorithm/find_if.h index aa98171a1f..f4ef3ac31c 100644 --- a/lib/libcxx/include/__algorithm/find_if.h +++ b/lib/libcxx/include/__algorithm/find_if.h @@ -19,7 +19,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD template -_LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _InputIterator +_LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 _InputIterator find_if(_InputIterator __first, _InputIterator __last, _Predicate __pred) { for (; __first != __last; ++__first) if (__pred(*__first)) diff --git a/lib/libcxx/include/__algorithm/find_if_not.h b/lib/libcxx/include/__algorithm/find_if_not.h index 61ddab0b98..96c159cf5e 100644 --- a/lib/libcxx/include/__algorithm/find_if_not.h +++ b/lib/libcxx/include/__algorithm/find_if_not.h @@ -19,7 +19,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD template -_LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _InputIterator +_LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 _InputIterator find_if_not(_InputIterator __first, _InputIterator __last, _Predicate __pred) { for (; __first != __last; ++__first) if (!__pred(*__first)) diff --git a/lib/libcxx/include/__algorithm/for_each.h b/lib/libcxx/include/__algorithm/for_each.h index bfbd37c3a3..6564f31cd0 100644 --- a/lib/libcxx/include/__algorithm/for_each.h +++ b/lib/libcxx/include/__algorithm/for_each.h @@ -19,7 +19,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD template -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _Function for_each(_InputIterator __first, +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 _Function for_each(_InputIterator __first, _InputIterator __last, _Function __f) { for (; __first != __last; ++__first) diff --git a/lib/libcxx/include/__algorithm/for_each_n.h b/lib/libcxx/include/__algorithm/for_each_n.h index 2552b40c27..38d204a118 100644 --- a/lib/libcxx/include/__algorithm/for_each_n.h +++ b/lib/libcxx/include/__algorithm/for_each_n.h @@ -11,6 +11,7 @@ #define _LIBCPP___ALGORITHM_FOR_EACH_N_H #include <__config> +#include <__utility/convert_to_integral.h> #include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) @@ -22,7 +23,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD #if _LIBCPP_STD_VER > 14 template -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _InputIterator for_each_n(_InputIterator __first, +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 _InputIterator for_each_n(_InputIterator __first, _Size __orig_n, _Function __f) { typedef decltype(_VSTD::__convert_to_integral(__orig_n)) _IntegralSize; diff --git a/lib/libcxx/include/__algorithm/generate.h b/lib/libcxx/include/__algorithm/generate.h index dacbd8c681..48e21b51e6 100644 --- a/lib/libcxx/include/__algorithm/generate.h +++ b/lib/libcxx/include/__algorithm/generate.h @@ -18,7 +18,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD template -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 void generate(_ForwardIterator __first, _ForwardIterator __last, _Generator __gen) { diff --git a/lib/libcxx/include/__algorithm/generate_n.h b/lib/libcxx/include/__algorithm/generate_n.h index 2650e9e5d8..45259989bf 100644 --- a/lib/libcxx/include/__algorithm/generate_n.h +++ b/lib/libcxx/include/__algorithm/generate_n.h @@ -10,6 +10,7 @@ #define _LIBCPP___ALGORITHM_GENERATE_N_H #include <__config> +#include <__utility/convert_to_integral.h> #include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) @@ -19,7 +20,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD template -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator generate_n(_OutputIterator __first, _Size __orig_n, _Generator __gen) { diff --git a/lib/libcxx/include/__algorithm/half_positive.h b/lib/libcxx/include/__algorithm/half_positive.h index 7666ef1449..74aede2b56 100644 --- a/lib/libcxx/include/__algorithm/half_positive.h +++ b/lib/libcxx/include/__algorithm/half_positive.h @@ -29,7 +29,7 @@ typename enable_if >::type __half_positive(_Integral __value) { - return static_cast<_Integral>(static_cast::type>(__value) / 2); + return static_cast<_Integral>(static_cast<__make_unsigned_t<_Integral> >(__value) / 2); } template diff --git a/lib/libcxx/include/__algorithm/in_found_result.h b/lib/libcxx/include/__algorithm/in_found_result.h index d43f45cd80..3134d6e0df 100644 --- a/lib/libcxx/include/__algorithm/in_found_result.h +++ b/lib/libcxx/include/__algorithm/in_found_result.h @@ -18,7 +18,7 @@ # pragma GCC system_header #endif -#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#if _LIBCPP_STD_VER > 17 _LIBCPP_BEGIN_NAMESPACE_STD @@ -44,6 +44,6 @@ struct in_found_result { _LIBCPP_END_NAMESPACE_STD -#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#endif // _LIBCPP_STD_VER > 17 #endif // _LIBCPP___ALGORITHM_IN_FOUND_RESULT_H diff --git a/lib/libcxx/include/__algorithm/in_fun_result.h b/lib/libcxx/include/__algorithm/in_fun_result.h index 21efa65506..3cbb9e12d3 100644 --- a/lib/libcxx/include/__algorithm/in_fun_result.h +++ b/lib/libcxx/include/__algorithm/in_fun_result.h @@ -20,7 +20,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD -#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#if _LIBCPP_STD_VER > 17 namespace ranges { template @@ -42,7 +42,7 @@ struct in_fun_result { }; } // namespace ranges -#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#endif // _LIBCPP_STD_VER > 17 _LIBCPP_END_NAMESPACE_STD diff --git a/lib/libcxx/include/__algorithm/in_in_out_result.h b/lib/libcxx/include/__algorithm/in_in_out_result.h index e45fef187e..3e747be44d 100644 --- a/lib/libcxx/include/__algorithm/in_in_out_result.h +++ b/lib/libcxx/include/__algorithm/in_in_out_result.h @@ -20,7 +20,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD -#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#if _LIBCPP_STD_VER > 17 namespace ranges { @@ -49,7 +49,7 @@ struct in_in_out_result { } // namespace ranges -#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#endif // _LIBCPP_STD_VER > 17 _LIBCPP_END_NAMESPACE_STD diff --git a/lib/libcxx/include/__algorithm/in_in_result.h b/lib/libcxx/include/__algorithm/in_in_result.h index 39e64ced33..2098c188cc 100644 --- a/lib/libcxx/include/__algorithm/in_in_result.h +++ b/lib/libcxx/include/__algorithm/in_in_result.h @@ -20,7 +20,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD -#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#if _LIBCPP_STD_VER > 17 namespace ranges { @@ -46,7 +46,7 @@ struct in_in_result { } // namespace ranges -#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#endif // _LIBCPP_STD_VER > 17 _LIBCPP_END_NAMESPACE_STD diff --git a/lib/libcxx/include/__algorithm/in_out_out_result.h b/lib/libcxx/include/__algorithm/in_out_out_result.h index 52a883b176..4046eee57d 100644 --- a/lib/libcxx/include/__algorithm/in_out_out_result.h +++ b/lib/libcxx/include/__algorithm/in_out_out_result.h @@ -20,7 +20,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD -#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#if _LIBCPP_STD_VER > 17 namespace ranges { template @@ -47,7 +47,7 @@ struct in_out_out_result { }; } // namespace ranges -#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#endif // _LIBCPP_STD_VER > 17 _LIBCPP_END_NAMESPACE_STD diff --git a/lib/libcxx/include/__algorithm/in_out_result.h b/lib/libcxx/include/__algorithm/in_out_result.h index 47e6f39079..7f5a0271b4 100644 --- a/lib/libcxx/include/__algorithm/in_out_result.h +++ b/lib/libcxx/include/__algorithm/in_out_result.h @@ -20,7 +20,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD -#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#if _LIBCPP_STD_VER > 17 namespace ranges { @@ -46,7 +46,7 @@ struct in_out_result { } // namespace ranges -#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#endif // _LIBCPP_STD_VER > 17 _LIBCPP_END_NAMESPACE_STD diff --git a/lib/libcxx/include/__algorithm/includes.h b/lib/libcxx/include/__algorithm/includes.h index c64194a2c8..cc39f275bf 100644 --- a/lib/libcxx/include/__algorithm/includes.h +++ b/lib/libcxx/include/__algorithm/includes.h @@ -25,7 +25,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 bool +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool __includes(_Iter1 __first1, _Sent1 __last1, _Iter2 __first2, _Sent2 __last2, _Comp&& __comp, _Proj1&& __proj1, _Proj2&& __proj2) { for (; __first2 != __last2; ++__first1) { @@ -39,7 +39,7 @@ __includes(_Iter1 __first1, _Sent1 __last1, _Iter2 __first2, _Sent2 __last2, } template -_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 bool includes( +_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool includes( _InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, @@ -48,14 +48,18 @@ _LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 static_assert(__is_callable<_Compare, decltype(*__first1), decltype(*__first2)>::value, "Comparator has to be callable"); - typedef typename __comp_ref_type<_Compare>::type _Comp_ref; return std::__includes( - std::move(__first1), std::move(__last1), std::move(__first2), std::move(__last2), - static_cast<_Comp_ref>(__comp), __identity(), __identity()); + std::move(__first1), + std::move(__last1), + std::move(__first2), + std::move(__last2), + static_cast<__comp_ref_type<_Compare> >(__comp), + __identity(), + __identity()); } template -_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 bool +_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool includes(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2) { return std::includes( std::move(__first1), diff --git a/lib/libcxx/include/__algorithm/inplace_merge.h b/lib/libcxx/include/__algorithm/inplace_merge.h index 0890639f49..5bbefc94bd 100644 --- a/lib/libcxx/include/__algorithm/inplace_merge.h +++ b/lib/libcxx/include/__algorithm/inplace_merge.h @@ -23,7 +23,11 @@ #include <__iterator/distance.h> #include <__iterator/iterator_traits.h> #include <__iterator/reverse_iterator.h> -#include +#include <__memory/destruct_n.h> +#include <__memory/temporary_buffer.h> +#include <__memory/unique_ptr.h> +#include <__utility/pair.h> +#include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header @@ -56,6 +60,7 @@ public: template +_LIBCPP_HIDE_FROM_ABI void __half_inplace_merge(_InputIterator1 __first1, _Sent1 __last1, _InputIterator2 __first2, _Sent2 __last2, _OutputIterator __result, _Compare&& __comp) @@ -83,6 +88,7 @@ void __half_inplace_merge(_InputIterator1 __first1, _Sent1 __last1, } template +_LIBCPP_HIDE_FROM_ABI void __buffered_inplace_merge( _BidirectionalIterator __first, _BidirectionalIterator __middle, @@ -231,9 +237,8 @@ _LIBCPP_SUPPRESS_DEPRECATED_POP template inline _LIBCPP_HIDE_FROM_ABI void inplace_merge( _BidirectionalIterator __first, _BidirectionalIterator __middle, _BidirectionalIterator __last, _Compare __comp) { - typedef typename __comp_ref_type<_Compare>::type _Comp_ref; std::__inplace_merge<_ClassicAlgPolicy>( - std::move(__first), std::move(__middle), std::move(__last), static_cast<_Comp_ref>(__comp)); + std::move(__first), std::move(__middle), std::move(__last), static_cast<__comp_ref_type<_Compare> >(__comp)); } template diff --git a/lib/libcxx/include/__algorithm/is_heap.h b/lib/libcxx/include/__algorithm/is_heap.h index 0d399a09b8..2dcb4a28e8 100644 --- a/lib/libcxx/include/__algorithm/is_heap.h +++ b/lib/libcxx/include/__algorithm/is_heap.h @@ -23,17 +23,16 @@ _LIBCPP_BEGIN_NAMESPACE_STD template _LIBCPP_NODISCARD_EXT inline -_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 bool is_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) { - typedef typename __comp_ref_type<_Compare>::type _Comp_ref; - return std::__is_heap_until(__first, __last, static_cast<_Comp_ref>(__comp)) == __last; + return std::__is_heap_until(__first, __last, static_cast<__comp_ref_type<_Compare> >(__comp)) == __last; } template _LIBCPP_NODISCARD_EXT inline -_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 bool is_heap(_RandomAccessIterator __first, _RandomAccessIterator __last) { diff --git a/lib/libcxx/include/__algorithm/is_heap_until.h b/lib/libcxx/include/__algorithm/is_heap_until.h index adb35af887..6ed4cb29c4 100644 --- a/lib/libcxx/include/__algorithm/is_heap_until.h +++ b/lib/libcxx/include/__algorithm/is_heap_until.h @@ -21,7 +21,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 _RandomAccessIterator +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _RandomAccessIterator __is_heap_until(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare&& __comp) { typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type; @@ -48,15 +48,14 @@ __is_heap_until(_RandomAccessIterator __first, _RandomAccessIterator __last, _Co } template -_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 _RandomAccessIterator +_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _RandomAccessIterator is_heap_until(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) { - typedef typename __comp_ref_type<_Compare>::type _Comp_ref; - return std::__is_heap_until(__first, __last, static_cast<_Comp_ref>(__comp)); + return std::__is_heap_until(__first, __last, static_cast<__comp_ref_type<_Compare> >(__comp)); } template -_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 _RandomAccessIterator +_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _RandomAccessIterator is_heap_until(_RandomAccessIterator __first, _RandomAccessIterator __last) { return _VSTD::__is_heap_until(__first, __last, __less::value_type>()); diff --git a/lib/libcxx/include/__algorithm/is_partitioned.h b/lib/libcxx/include/__algorithm/is_partitioned.h index b4f421cfc0..ab59d3cce5 100644 --- a/lib/libcxx/include/__algorithm/is_partitioned.h +++ b/lib/libcxx/include/__algorithm/is_partitioned.h @@ -18,7 +18,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD template -_LIBCPP_NODISCARD_EXT _LIBCPP_CONSTEXPR_AFTER_CXX17 bool +_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool is_partitioned(_InputIterator __first, _InputIterator __last, _Predicate __pred) { for (; __first != __last; ++__first) diff --git a/lib/libcxx/include/__algorithm/is_permutation.h b/lib/libcxx/include/__algorithm/is_permutation.h index 06a4949e21..005445652e 100644 --- a/lib/libcxx/include/__algorithm/is_permutation.h +++ b/lib/libcxx/include/__algorithm/is_permutation.h @@ -55,7 +55,7 @@ struct _ConstTimeDistance<_Iter1, _Iter1, _Iter2, _Iter2, __enable_if_t< template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 bool +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool __is_permutation_impl(_Iter1 __first1, _Sent1 __last1, _Iter2 __first2, _Sent2 __last2, _Pred&& __pred, _Proj1&& __proj1, _Proj2&& __proj2) { using _D1 = __iter_diff_t<_Iter1>; @@ -94,7 +94,7 @@ __is_permutation_impl(_Iter1 __first1, _Sent1 __last1, _Iter2 __first2, _Sent2 _ // 2+1 iterators, predicate. Not used by range algorithms. template -_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 bool +_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool __is_permutation(_ForwardIterator1 __first1, _Sentinel1 __last1, _ForwardIterator2 __first2, _BinaryPredicate&& __pred) { // Shorten sequences as much as possible by lopping of any equal prefix. @@ -122,7 +122,7 @@ __is_permutation(_ForwardIterator1 __first1, _Sentinel1 __last1, _ForwardIterato template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 bool +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool __is_permutation(_Iter1 __first1, _Sent1 __last1, _Iter2 __first2, _Sent2 __last2, _Pred&& __pred, _Proj1&& __proj1, _Proj2&& __proj2, /*_ConstTimeDistance=*/false_type) { @@ -156,7 +156,7 @@ __is_permutation(_Iter1 __first1, _Sent1 __last1, _Iter2 __first2, _Sent2 __last template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 bool +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool __is_permutation(_Iter1 __first1, _Sent1 __last1, _Iter2 __first2, _Sent2 __last2, _Pred&& __pred, _Proj1&& __proj1, _Proj2&& __proj2, /*_ConstTimeDistance=*/true_type) { @@ -172,7 +172,7 @@ __is_permutation(_Iter1 __first1, _Sent1 __last1, _Iter2 __first2, _Sent2 __last template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 bool +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool __is_permutation(_Iter1 __first1, _Sent1 __last1, _Iter2 __first2, _Sent2 __last2, _Pred&& __pred, _Proj1&& __proj1, _Proj2&& __proj2) { return std::__is_permutation<_AlgPolicy>( @@ -185,7 +185,7 @@ __is_permutation(_Iter1 __first1, _Sent1 __last1, _Iter2 __first2, _Sent2 __last // 2+1 iterators, predicate template -_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 bool +_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2, _BinaryPredicate __pred) { static_assert(__is_callable<_BinaryPredicate, decltype(*__first1), decltype(*__first2)>::value, @@ -197,31 +197,30 @@ is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIt // 2+1 iterators template -_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 bool +_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2) { - using __v1 = __iter_value_type<_ForwardIterator1>; - using __v2 = __iter_value_type<_ForwardIterator2>; - return std::is_permutation(__first1, __last1, __first2, __equal_to<__v1, __v2>()); + return std::is_permutation(__first1, __last1, __first2, __equal_to()); } #if _LIBCPP_STD_VER > 11 // 2+2 iterators template -_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 bool -is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2, - _ForwardIterator2 __last2) { - using __v1 = __iter_value_type<_ForwardIterator1>; - using __v2 = __iter_value_type<_ForwardIterator2>; - +_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool is_permutation( + _ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2, _ForwardIterator2 __last2) { return std::__is_permutation<_ClassicAlgPolicy>( - std::move(__first1), std::move(__last1), std::move(__first2), std::move(__last2), - __equal_to<__v1, __v2>(), __identity(), __identity()); + std::move(__first1), + std::move(__last1), + std::move(__first2), + std::move(__last2), + __equal_to(), + __identity(), + __identity()); } // 2+2 iterators, predicate template -_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 bool +_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2, _ForwardIterator2 __last2, _BinaryPredicate __pred) { static_assert(__is_callable<_BinaryPredicate, decltype(*__first1), decltype(*__first2)>::value, diff --git a/lib/libcxx/include/__algorithm/is_sorted.h b/lib/libcxx/include/__algorithm/is_sorted.h index 56de95bb31..bf44f45764 100644 --- a/lib/libcxx/include/__algorithm/is_sorted.h +++ b/lib/libcxx/include/__algorithm/is_sorted.h @@ -23,17 +23,16 @@ _LIBCPP_BEGIN_NAMESPACE_STD template _LIBCPP_NODISCARD_EXT inline -_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 bool is_sorted(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp) { - typedef typename __comp_ref_type<_Compare>::type _Comp_ref; - return _VSTD::__is_sorted_until<_Comp_ref>(__first, __last, __comp) == __last; + return _VSTD::__is_sorted_until<__comp_ref_type<_Compare> >(__first, __last, __comp) == __last; } template _LIBCPP_NODISCARD_EXT inline -_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 bool is_sorted(_ForwardIterator __first, _ForwardIterator __last) { diff --git a/lib/libcxx/include/__algorithm/is_sorted_until.h b/lib/libcxx/include/__algorithm/is_sorted_until.h index 338d28508c..b6683000a0 100644 --- a/lib/libcxx/include/__algorithm/is_sorted_until.h +++ b/lib/libcxx/include/__algorithm/is_sorted_until.h @@ -21,7 +21,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator __is_sorted_until(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp) { if (__first != __last) @@ -38,15 +38,14 @@ __is_sorted_until(_ForwardIterator __first, _ForwardIterator __last, _Compare __ } template -_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator +_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator is_sorted_until(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp) { - typedef typename __comp_ref_type<_Compare>::type _Comp_ref; - return _VSTD::__is_sorted_until<_Comp_ref>(__first, __last, __comp); + return _VSTD::__is_sorted_until<__comp_ref_type<_Compare> >(__first, __last, __comp); } template -_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator +_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator is_sorted_until(_ForwardIterator __first, _ForwardIterator __last) { return _VSTD::is_sorted_until(__first, __last, __less::value_type>()); diff --git a/lib/libcxx/include/__algorithm/iter_swap.h b/lib/libcxx/include/__algorithm/iter_swap.h index 038859e136..44422b5de0 100644 --- a/lib/libcxx/include/__algorithm/iter_swap.h +++ b/lib/libcxx/include/__algorithm/iter_swap.h @@ -20,10 +20,10 @@ _LIBCPP_BEGIN_NAMESPACE_STD template -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 void iter_swap(_ForwardIterator1 __a, +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 void iter_swap(_ForwardIterator1 __a, _ForwardIterator2 __b) // _NOEXCEPT_(_NOEXCEPT_(swap(*__a, *__b))) - _NOEXCEPT_(_NOEXCEPT_(swap(*declval<_ForwardIterator1>(), *declval<_ForwardIterator2>()))) { + _NOEXCEPT_(_NOEXCEPT_(swap(*std::declval<_ForwardIterator1>(), *std::declval<_ForwardIterator2>()))) { swap(*__a, *__b); } diff --git a/lib/libcxx/include/__algorithm/iterator_operations.h b/lib/libcxx/include/__algorithm/iterator_operations.h index af46187873..bd3e6f1d38 100644 --- a/lib/libcxx/include/__algorithm/iterator_operations.h +++ b/lib/libcxx/include/__algorithm/iterator_operations.h @@ -21,10 +21,13 @@ #include <__iterator/next.h> #include <__iterator/prev.h> #include <__iterator/readable_traits.h> +#include <__type_traits/enable_if.h> +#include <__type_traits/is_reference.h> +#include <__type_traits/is_same.h> +#include <__type_traits/remove_cvref.h> #include <__utility/declval.h> #include <__utility/forward.h> #include <__utility/move.h> -#include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header @@ -34,7 +37,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD template struct _IterOps; -#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#if _LIBCPP_STD_VER > 17 struct _RangeAlgPolicy {}; template <> @@ -76,14 +79,14 @@ struct _IterOps<_ClassicAlgPolicy> { // advance template - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 static void advance(_Iter& __iter, _Distance __count) { std::advance(__iter, __count); } // distance template - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 static typename iterator_traits<_Iter>::difference_type distance(_Iter __first, _Iter __last) { return std::distance(__first, __last); } @@ -95,9 +98,9 @@ struct _IterOps<_ClassicAlgPolicy> { using __move_t = decltype(std::move(*std::declval<_Iter&>())); template - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 static void __validate_iter_reference() { - static_assert(is_same<__deref_t<_Iter>, typename iterator_traits<__uncvref_t<_Iter> >::reference>::value, + static_assert(is_same<__deref_t<_Iter>, typename iterator_traits<__remove_cvref_t<_Iter> >::reference>::value, "It looks like your iterator's `iterator_traits::reference` does not match the return type of " "dereferencing the iterator, i.e., calling `*it`. This is undefined behavior according to [input.iterators] " "and can lead to dangling reference issues at runtime, so we are flagging this."); @@ -105,7 +108,7 @@ struct _IterOps<_ClassicAlgPolicy> { // iter_move template - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 static + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 static // If the result of dereferencing `_Iter` is a reference type, deduce the result of calling `std::move` on it. Note // that the C++03 mode doesn't support `decltype(auto)` as the return type. __enable_if_t< @@ -118,7 +121,7 @@ struct _IterOps<_ClassicAlgPolicy> { } template - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 static + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 static // If the result of dereferencing `_Iter` is a value type, deduce the return value of this function to also be a // value -- otherwise, after `operator*` returns a temporary, this function would return a dangling reference to that // temporary. Note that the C++03 mode doesn't support `auto` as the return type. @@ -133,35 +136,35 @@ struct _IterOps<_ClassicAlgPolicy> { // iter_swap template - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 static void iter_swap(_Iter1&& __a, _Iter2&& __b) { std::iter_swap(std::forward<_Iter1>(__a), std::forward<_Iter2>(__b)); } // next template - _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR_AFTER_CXX11 + _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR_SINCE_CXX14 _Iterator next(_Iterator, _Iterator __last) { return __last; } template - _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR_AFTER_CXX11 - __uncvref_t<_Iter> next(_Iter&& __it, - typename iterator_traits<__uncvref_t<_Iter> >::difference_type __n = 1) { + _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR_SINCE_CXX14 + __remove_cvref_t<_Iter> next(_Iter&& __it, + typename iterator_traits<__remove_cvref_t<_Iter> >::difference_type __n = 1) { return std::next(std::forward<_Iter>(__it), __n); } // prev template - _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR_AFTER_CXX11 - __uncvref_t<_Iter> prev(_Iter&& __iter, - typename iterator_traits<__uncvref_t<_Iter> >::difference_type __n = 1) { + _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR_SINCE_CXX14 + __remove_cvref_t<_Iter> prev(_Iter&& __iter, + typename iterator_traits<__remove_cvref_t<_Iter> >::difference_type __n = 1) { return std::prev(std::forward<_Iter>(__iter), __n); } template - _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR_AFTER_CXX11 + _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR_SINCE_CXX14 void __advance_to(_Iter& __first, _Iter __last) { __first = __last; } diff --git a/lib/libcxx/include/__algorithm/lexicographical_compare.h b/lib/libcxx/include/__algorithm/lexicographical_compare.h index 30ddf24081..0a13c5dd31 100644 --- a/lib/libcxx/include/__algorithm/lexicographical_compare.h +++ b/lib/libcxx/include/__algorithm/lexicographical_compare.h @@ -21,7 +21,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD template -_LIBCPP_CONSTEXPR_AFTER_CXX17 bool +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool __lexicographical_compare(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2, _Compare __comp) { @@ -37,18 +37,17 @@ __lexicographical_compare(_InputIterator1 __first1, _InputIterator1 __last1, template _LIBCPP_NODISCARD_EXT inline -_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 bool lexicographical_compare(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2, _Compare __comp) { - typedef typename __comp_ref_type<_Compare>::type _Comp_ref; - return _VSTD::__lexicographical_compare<_Comp_ref>(__first1, __last1, __first2, __last2, __comp); + return _VSTD::__lexicographical_compare<__comp_ref_type<_Compare> >(__first1, __last1, __first2, __last2, __comp); } template _LIBCPP_NODISCARD_EXT inline -_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 bool lexicographical_compare(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2) diff --git a/lib/libcxx/include/__algorithm/lower_bound.h b/lib/libcxx/include/__algorithm/lower_bound.h index 2c92f71526..2648982ea5 100644 --- a/lib/libcxx/include/__algorithm/lower_bound.h +++ b/lib/libcxx/include/__algorithm/lower_bound.h @@ -29,7 +29,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Iter __lower_bound_impl(_Iter __first, _Sent __last, const _Type& __value, _Comp& __comp, _Proj& __proj) { auto __len = _IterOps<_AlgPolicy>::distance(__first, __last); @@ -48,7 +48,7 @@ _Iter __lower_bound_impl(_Iter __first, _Sent __last, const _Type& __value, _Com } template -_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 +_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator lower_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value, _Compare __comp) { static_assert(__is_callable<_Compare, decltype(*__first), const _Tp&>::value, "The comparator has to be callable"); @@ -57,7 +57,7 @@ _ForwardIterator lower_bound(_ForwardIterator __first, _ForwardIterator __last, } template -_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 +_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator lower_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value) { return std::lower_bound(__first, __last, __value, __less::value_type, _Tp>()); diff --git a/lib/libcxx/include/__algorithm/make_heap.h b/lib/libcxx/include/__algorithm/make_heap.h index 0aa67d18ed..d66cfe2e5f 100644 --- a/lib/libcxx/include/__algorithm/make_heap.h +++ b/lib/libcxx/include/__algorithm/make_heap.h @@ -24,10 +24,9 @@ _LIBCPP_BEGIN_NAMESPACE_STD template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void __make_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare&& __comp) { - using _CompRef = typename __comp_ref_type<_Compare>::type; - _CompRef __comp_ref = __comp; + __comp_ref_type<_Compare> __comp_ref = __comp; using difference_type = typename iterator_traits<_RandomAccessIterator>::difference_type; difference_type __n = __last - __first; @@ -40,13 +39,13 @@ void __make_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _C } template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void make_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) { std::__make_heap<_ClassicAlgPolicy>(std::move(__first), std::move(__last), __comp); } template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void make_heap(_RandomAccessIterator __first, _RandomAccessIterator __last) { std::make_heap(std::move(__first), std::move(__last), __less::value_type>()); diff --git a/lib/libcxx/include/__algorithm/make_projected.h b/lib/libcxx/include/__algorithm/make_projected.h index 6c1d156776..87d4d59042 100644 --- a/lib/libcxx/include/__algorithm/make_projected.h +++ b/lib/libcxx/include/__algorithm/make_projected.h @@ -93,7 +93,7 @@ __make_projected(_Pred& __pred, _Proj&) { _LIBCPP_END_NAMESPACE_STD -#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#if _LIBCPP_STD_VER > 17 _LIBCPP_BEGIN_NAMESPACE_STD @@ -121,6 +121,6 @@ decltype(auto) __make_projected_comp(_Comp& __comp, _Proj1& __proj1, _Proj2& __p _LIBCPP_END_NAMESPACE_STD -#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#endif // _LIBCPP_STD_VER > 17 #endif // _LIBCPP___ALGORITHM_MAKE_PROJECTED_H diff --git a/lib/libcxx/include/__algorithm/max.h b/lib/libcxx/include/__algorithm/max.h index 345b235a21..a08a3fc59b 100644 --- a/lib/libcxx/include/__algorithm/max.h +++ b/lib/libcxx/include/__algorithm/max.h @@ -26,7 +26,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD template _LIBCPP_NODISCARD_EXT inline -_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14 const _Tp& max(const _Tp& __a, const _Tp& __b, _Compare __comp) { @@ -35,7 +35,7 @@ max(const _Tp& __a, const _Tp& __b, _Compare __comp) template _LIBCPP_NODISCARD_EXT inline -_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14 const _Tp& max(const _Tp& __a, const _Tp& __b) { @@ -46,17 +46,16 @@ max(const _Tp& __a, const _Tp& __b) template _LIBCPP_NODISCARD_EXT inline -_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14 _Tp max(initializer_list<_Tp> __t, _Compare __comp) { - typedef typename __comp_ref_type<_Compare>::type _Comp_ref; - return *_VSTD::__max_element<_Comp_ref>(__t.begin(), __t.end(), __comp); + return *_VSTD::__max_element<__comp_ref_type<_Compare> >(__t.begin(), __t.end(), __comp); } template _LIBCPP_NODISCARD_EXT inline -_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14 _Tp max(initializer_list<_Tp> __t) { diff --git a/lib/libcxx/include/__algorithm/max_element.h b/lib/libcxx/include/__algorithm/max_element.h index 795ec8e1dd..6ac310619b 100644 --- a/lib/libcxx/include/__algorithm/max_element.h +++ b/lib/libcxx/include/__algorithm/max_element.h @@ -21,7 +21,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 _ForwardIterator +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _ForwardIterator __max_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp) { static_assert(__is_cpp17_forward_iterator<_ForwardIterator>::value, @@ -37,16 +37,15 @@ __max_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp } template -_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 _ForwardIterator +_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _ForwardIterator max_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp) { - typedef typename __comp_ref_type<_Compare>::type _Comp_ref; - return _VSTD::__max_element<_Comp_ref>(__first, __last, __comp); + return _VSTD::__max_element<__comp_ref_type<_Compare> >(__first, __last, __comp); } template -_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 _ForwardIterator +_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _ForwardIterator max_element(_ForwardIterator __first, _ForwardIterator __last) { return _VSTD::max_element(__first, __last, diff --git a/lib/libcxx/include/__algorithm/merge.h b/lib/libcxx/include/__algorithm/merge.h index 48360ed5b4..e54e430bcb 100644 --- a/lib/libcxx/include/__algorithm/merge.h +++ b/lib/libcxx/include/__algorithm/merge.h @@ -22,7 +22,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD template -_LIBCPP_CONSTEXPR_AFTER_CXX17 +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator __merge(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result, _Compare __comp) @@ -46,17 +46,16 @@ __merge(_InputIterator1 __first1, _InputIterator1 __last1, } template -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator merge(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result, _Compare __comp) { - typedef typename __comp_ref_type<_Compare>::type _Comp_ref; - return _VSTD::__merge<_Comp_ref>(__first1, __last1, __first2, __last2, __result, __comp); + return _VSTD::__merge<__comp_ref_type<_Compare> >(__first1, __last1, __first2, __last2, __result, __comp); } template -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator merge(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result) diff --git a/lib/libcxx/include/__algorithm/min.h b/lib/libcxx/include/__algorithm/min.h index 3d8c73d78f..2882485ad7 100644 --- a/lib/libcxx/include/__algorithm/min.h +++ b/lib/libcxx/include/__algorithm/min.h @@ -26,7 +26,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD template _LIBCPP_NODISCARD_EXT inline -_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14 const _Tp& min(const _Tp& __a, const _Tp& __b, _Compare __comp) { @@ -35,7 +35,7 @@ min(const _Tp& __a, const _Tp& __b, _Compare __comp) template _LIBCPP_NODISCARD_EXT inline -_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14 const _Tp& min(const _Tp& __a, const _Tp& __b) { @@ -46,17 +46,16 @@ min(const _Tp& __a, const _Tp& __b) template _LIBCPP_NODISCARD_EXT inline -_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14 _Tp min(initializer_list<_Tp> __t, _Compare __comp) { - typedef typename __comp_ref_type<_Compare>::type _Comp_ref; - return *_VSTD::__min_element<_Comp_ref>(__t.begin(), __t.end(), __comp); + return *_VSTD::__min_element<__comp_ref_type<_Compare> >(__t.begin(), __t.end(), __comp); } template _LIBCPP_NODISCARD_EXT inline -_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14 _Tp min(initializer_list<_Tp> __t) { diff --git a/lib/libcxx/include/__algorithm/min_element.h b/lib/libcxx/include/__algorithm/min_element.h index 17b242c341..c0706fe9e4 100644 --- a/lib/libcxx/include/__algorithm/min_element.h +++ b/lib/libcxx/include/__algorithm/min_element.h @@ -25,7 +25,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Iter __min_element(_Iter __first, _Sent __last, _Comp __comp, _Proj& __proj) { if (__first == __last) return __first; @@ -39,14 +39,14 @@ _Iter __min_element(_Iter __first, _Sent __last, _Comp __comp, _Proj& __proj) { } template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Iter __min_element(_Iter __first, _Sent __last, _Comp __comp) { auto __proj = __identity(); return std::__min_element<_Comp>(std::move(__first), std::move(__last), __comp, __proj); } template -_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 _ForwardIterator +_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _ForwardIterator min_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp) { static_assert(__is_cpp17_forward_iterator<_ForwardIterator>::value, @@ -54,12 +54,11 @@ min_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp) static_assert(__is_callable<_Compare, decltype(*__first), decltype(*__first)>::value, "The comparator has to be callable"); - typedef typename __comp_ref_type<_Compare>::type _Comp_ref; - return std::__min_element<_Comp_ref>(std::move(__first), std::move(__last), __comp); + return std::__min_element<__comp_ref_type<_Compare> >(std::move(__first), std::move(__last), __comp); } template -_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 _ForwardIterator +_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _ForwardIterator min_element(_ForwardIterator __first, _ForwardIterator __last) { return _VSTD::min_element(__first, __last, diff --git a/lib/libcxx/include/__algorithm/min_max_result.h b/lib/libcxx/include/__algorithm/min_max_result.h index ca77dcc572..4be39992b4 100644 --- a/lib/libcxx/include/__algorithm/min_max_result.h +++ b/lib/libcxx/include/__algorithm/min_max_result.h @@ -23,7 +23,7 @@ _LIBCPP_PUSH_MACROS _LIBCPP_BEGIN_NAMESPACE_STD -#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#if _LIBCPP_STD_VER > 17 namespace ranges { @@ -47,7 +47,7 @@ struct min_max_result { } // namespace ranges -#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#endif // _LIBCPP_STD_VER > 17 _LIBCPP_END_NAMESPACE_STD diff --git a/lib/libcxx/include/__algorithm/minmax.h b/lib/libcxx/include/__algorithm/minmax.h index 7e10b8b835..6ef0a77708 100644 --- a/lib/libcxx/include/__algorithm/minmax.h +++ b/lib/libcxx/include/__algorithm/minmax.h @@ -25,7 +25,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD template _LIBCPP_NODISCARD_EXT inline -_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14 pair minmax(const _Tp& __a, const _Tp& __b, _Compare __comp) { @@ -35,7 +35,7 @@ minmax(const _Tp& __a, const _Tp& __b, _Compare __comp) template _LIBCPP_NODISCARD_EXT inline -_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14 pair minmax(const _Tp& __a, const _Tp& __b) { @@ -45,7 +45,7 @@ minmax(const _Tp& __a, const _Tp& __b) #ifndef _LIBCPP_CXX03_LANG template -_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 +_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_Tp, _Tp> minmax(initializer_list<_Tp> __t, _Compare __comp) { static_assert(__is_callable<_Compare, _Tp, _Tp>::value, "The comparator has to be callable"); __identity __proj; @@ -55,7 +55,7 @@ pair<_Tp, _Tp> minmax(initializer_list<_Tp> __t, _Compare __comp) { template _LIBCPP_NODISCARD_EXT inline -_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_Tp, _Tp> minmax(initializer_list<_Tp> __t) { diff --git a/lib/libcxx/include/__algorithm/minmax_element.h b/lib/libcxx/include/__algorithm/minmax_element.h index cf67184e0b..caa963e112 100644 --- a/lib/libcxx/include/__algorithm/minmax_element.h +++ b/lib/libcxx/include/__algorithm/minmax_element.h @@ -32,14 +32,14 @@ public: _MinmaxElementLessFunc(_Comp& __comp, _Proj& __proj) : __comp_(__comp), __proj_(__proj) {} template - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool operator()(_Iter& __it1, _Iter& __it2) { return std::__invoke(__comp_, std::__invoke(__proj_, *__it1), std::__invoke(__proj_, *__it2)); } }; template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_Iter, _Iter> __minmax_element_impl(_Iter __first, _Sent __last, _Comp& __comp, _Proj& __proj) { auto __less = _MinmaxElementLessFunc<_Comp, _Proj>(__comp, __proj); @@ -79,7 +79,7 @@ pair<_Iter, _Iter> __minmax_element_impl(_Iter __first, _Sent __last, _Comp& __c } template -_LIBCPP_NODISCARD_EXT _LIBCPP_CONSTEXPR_AFTER_CXX11 +_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_ForwardIterator, _ForwardIterator> minmax_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp) { static_assert(__is_cpp17_forward_iterator<_ForwardIterator>::value, @@ -91,7 +91,7 @@ minmax_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __com } template -_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 +_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_ForwardIterator, _ForwardIterator> minmax_element(_ForwardIterator __first, _ForwardIterator __last) { return std::minmax_element(__first, __last, __less::value_type>()); } diff --git a/lib/libcxx/include/__algorithm/mismatch.h b/lib/libcxx/include/__algorithm/mismatch.h index f2011faf2f..600e2cdd3d 100644 --- a/lib/libcxx/include/__algorithm/mismatch.h +++ b/lib/libcxx/include/__algorithm/mismatch.h @@ -23,7 +23,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD template _LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY - _LIBCPP_CONSTEXPR_AFTER_CXX17 pair<_InputIterator1, _InputIterator2> + _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_InputIterator1, _InputIterator2> mismatch(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _BinaryPredicate __pred) { for (; __first1 != __last1; ++__first1, (void)++__first2) if (!__pred(*__first1, *__first2)) @@ -33,17 +33,15 @@ _LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY template _LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY - _LIBCPP_CONSTEXPR_AFTER_CXX17 pair<_InputIterator1, _InputIterator2> + _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_InputIterator1, _InputIterator2> mismatch(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2) { - typedef typename iterator_traits<_InputIterator1>::value_type __v1; - typedef typename iterator_traits<_InputIterator2>::value_type __v2; - return _VSTD::mismatch(__first1, __last1, __first2, __equal_to<__v1, __v2>()); + return std::mismatch(__first1, __last1, __first2, __equal_to()); } #if _LIBCPP_STD_VER > 11 template _LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY - _LIBCPP_CONSTEXPR_AFTER_CXX17 pair<_InputIterator1, _InputIterator2> + _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_InputIterator1, _InputIterator2> mismatch(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2, _BinaryPredicate __pred) { for (; __first1 != __last1 && __first2 != __last2; ++__first1, (void)++__first2) @@ -54,11 +52,9 @@ _LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY template _LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY - _LIBCPP_CONSTEXPR_AFTER_CXX17 pair<_InputIterator1, _InputIterator2> + _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_InputIterator1, _InputIterator2> mismatch(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2) { - typedef typename iterator_traits<_InputIterator1>::value_type __v1; - typedef typename iterator_traits<_InputIterator2>::value_type __v2; - return _VSTD::mismatch(__first1, __last1, __first2, __last2, __equal_to<__v1, __v2>()); + return std::mismatch(__first1, __last1, __first2, __last2, __equal_to()); } #endif diff --git a/lib/libcxx/include/__algorithm/move.h b/lib/libcxx/include/__algorithm/move.h index c090faf6b6..ac95bda7b6 100644 --- a/lib/libcxx/include/__algorithm/move.h +++ b/lib/libcxx/include/__algorithm/move.h @@ -9,111 +9,122 @@ #ifndef _LIBCPP___ALGORITHM_MOVE_H #define _LIBCPP___ALGORITHM_MOVE_H +#include <__algorithm/copy_move_common.h> #include <__algorithm/iterator_operations.h> -#include <__algorithm/unwrap_iter.h> +#include <__algorithm/min.h> #include <__config> -#include <__iterator/iterator_traits.h> -#include <__iterator/reverse_iterator.h> +#include <__iterator/segmented_iterator.h> +#include <__type_traits/common_type.h> +#include <__type_traits/is_copy_constructible.h> #include <__utility/move.h> #include <__utility/pair.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 -// move - template -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 -pair<_InIter, _OutIter> __move_impl(_InIter __first, _Sent __last, _OutIter __result) { - while (__first != __last) { - *__result = _IterOps<_AlgPolicy>::__iter_move(__first); - ++__first; - ++__result; +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_InIter, _OutIter> +__move(_InIter __first, _Sent __last, _OutIter __result); + +template +struct __move_loop { + template + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_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::make_pair(std::move(__first), std::move(__result)); -} -template ::type, _OutType>::value - && is_trivially_move_assignable<_OutType>::value> > -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 -pair<_InType*, _OutType*> __move_impl(_InType* __first, _InType* __last, _OutType* __result) { - if (__libcpp_is_constant_evaluated() -// TODO: Remove this once GCC supports __builtin_memmove during constant evaluation -#ifndef _LIBCPP_COMPILER_GCC - && !is_trivially_copyable<_InType>::value -#endif - ) - return std::__move_impl<_AlgPolicy, _InType*, _InType*, _OutType*>(__first, __last, __result); - const size_t __n = static_cast(__last - __first); - ::__builtin_memmove(__result, __first, __n * sizeof(_OutType)); - return std::make_pair(__first + __n, __result + __n); -} + template ::value, int> = 0> + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_InIter, _OutIter> + operator()(_InIter __first, _InIter __last, _OutIter __result) const { + using _Traits = __segmented_iterator_traits<_InIter>; + auto __sfirst = _Traits::__segment(__first); + auto __slast = _Traits::__segment(__last); + if (__sfirst == __slast) { + auto __iters = std::__move<_AlgPolicy>(_Traits::__local(__first), _Traits::__local(__last), std::move(__result)); + return std::make_pair(__last, std::move(__iters.second)); + } -template -struct __is_trivially_move_assignable_unwrapped_impl : false_type {}; + __result = std::__move<_AlgPolicy>(_Traits::__local(__first), _Traits::__end(__sfirst), std::move(__result)).second; + ++__sfirst; + while (__sfirst != __slast) { + __result = + std::__move<_AlgPolicy>(_Traits::__begin(__sfirst), _Traits::__end(__sfirst), std::move(__result)).second; + ++__sfirst; + } + __result = + std::__move<_AlgPolicy>(_Traits::__begin(__sfirst), _Traits::__local(__last), std::move(__result)).second; + return std::make_pair(__last, std::move(__result)); + } -template -struct __is_trivially_move_assignable_unwrapped_impl<_Type*> : is_trivially_move_assignable<_Type> {}; + template ::value && + !__is_segmented_iterator<_InIter>::value && __is_segmented_iterator<_OutIter>::value, + int> = 0> + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_InIter, _OutIter> + operator()(_InIter __first, _InIter __last, _OutIter __result) { + using _Traits = __segmented_iterator_traits<_OutIter>; + using _DiffT = typename common_type<__iter_diff_t<_InIter>, __iter_diff_t<_OutIter> >::type; -template -struct __is_trivially_move_assignable_unwrapped - : __is_trivially_move_assignable_unwrapped_impl(std::declval<_Iter>()))> {}; + if (__first == __last) + return std::make_pair(std::move(__first), std::move(__result)); -template ::value_type>::type, - typename iterator_traits<_OutIter>::value_type>::value - && __is_cpp17_contiguous_iterator<_InIter>::value - && __is_cpp17_contiguous_iterator<_OutIter>::value - && is_trivially_move_assignable<__iter_value_type<_OutIter> >::value, int> = 0> -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX14 -pair, reverse_iterator<_OutIter> > -__move_impl(reverse_iterator<_InIter> __first, - reverse_iterator<_InIter> __last, - reverse_iterator<_OutIter> __result) { - auto __first_base = std::__unwrap_iter(__first.base()); - auto __last_base = std::__unwrap_iter(__last.base()); - auto __result_base = std::__unwrap_iter(__result.base()); - auto __result_first = __result_base - (__first_base - __last_base); - std::__move_impl<_AlgPolicy>(__last_base, __first_base, __result_first); - return std::make_pair(__last, reverse_iterator<_OutIter>(std::__rewrap_iter(__result.base(), __result_first))); -} + auto __local_first = _Traits::__local(__result); + auto __segment_iterator = _Traits::__segment(__result); + while (true) { + 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); + + if (__first == __last) + return std::make_pair(std::move(__first), _Traits::__compose(__segment_iterator, std::move(__iters.second))); + + __local_first = _Traits::__begin(++__segment_iterator); + } + } +}; + +struct __move_trivial { + // 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*> + operator()(_In* __first, _In* __last, _Out* __result) const { + return std::__copy_trivial_impl(__first, __last, __result); + } +}; template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 -__enable_if_t::value - && is_copy_constructible<_Sent>::value - && is_copy_constructible<_OutIter>::value, pair<_InIter, _OutIter> > +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_InIter, _OutIter> __move(_InIter __first, _Sent __last, _OutIter __result) { - auto __ret = std::__move_impl<_AlgPolicy>( - std::__unwrap_iter(__first), std::__unwrap_iter(__last), std::__unwrap_iter(__result)); - return std::make_pair(std::__rewrap_iter(__first, __ret.first), std::__rewrap_iter(__result, __ret.second)); -} - -template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 -__enable_if_t::value - || !is_copy_constructible<_Sent>::value - || !is_copy_constructible<_OutIter>::value, pair<_InIter, _OutIter> > -__move(_InIter __first, _Sent __last, _OutIter __result) { - return std::__move_impl<_AlgPolicy>(std::move(__first), std::move(__last), std::move(__result)); + return std::__dispatch_copy_or_move<_AlgPolicy, __move_loop<_AlgPolicy>, __move_trivial>( + std::move(__first), std::move(__last), std::move(__result)); } template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 -_OutputIterator move(_InputIterator __first, _InputIterator __last, _OutputIterator __result) { - return std::__move<_ClassicAlgPolicy>(__first, __last, __result).second; +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator +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; } _LIBCPP_END_NAMESPACE_STD +_LIBCPP_POP_MACROS + #endif // _LIBCPP___ALGORITHM_MOVE_H diff --git a/lib/libcxx/include/__algorithm/move_backward.h b/lib/libcxx/include/__algorithm/move_backward.h index 626e250b6d..d4f013be68 100644 --- a/lib/libcxx/include/__algorithm/move_backward.h +++ b/lib/libcxx/include/__algorithm/move_backward.h @@ -9,81 +9,131 @@ #ifndef _LIBCPP___ALGORITHM_MOVE_BACKWARD_H #define _LIBCPP___ALGORITHM_MOVE_BACKWARD_H +#include <__algorithm/copy_move_common.h> #include <__algorithm/iterator_operations.h> -#include <__algorithm/unwrap_iter.h> +#include <__algorithm/min.h> #include <__config> +#include <__iterator/segmented_iterator.h> +#include <__type_traits/common_type.h> +#include <__type_traits/is_copy_constructible.h> #include <__utility/move.h> -#include -#include +#include <__utility/pair.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 -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 -_OutputIterator -__move_backward_constexpr(_InputIterator __first, _InputIterator __last, _OutputIterator __result) -{ - while (__first != __last) - *--__result = _IterOps<_AlgPolicy>::__iter_move(--__last); - return __result; -} +template +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_BidirectionalIterator1, _BidirectionalIterator2> +__move_backward(_BidirectionalIterator1 __first, _Sentinel __last, _BidirectionalIterator2 __result); -template -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 -_OutputIterator -__move_backward_impl(_InputIterator __first, _InputIterator __last, _OutputIterator __result) -{ - return _VSTD::__move_backward_constexpr<_AlgPolicy>(__first, __last, __result); -} +template +struct __move_backward_loop { + template + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_InIter, _OutIter> + operator()(_InIter __first, _Sent __last, _OutIter __result) const { + auto __last_iter = _IterOps<_AlgPolicy>::next(__first, __last); + auto __original_last_iter = __last_iter; -template -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 -typename enable_if -< - is_same::type, _Up>::value && - is_trivially_move_assignable<_Up>::value, - _Up* ->::type -__move_backward_impl(_Tp* __first, _Tp* __last, _Up* __result) -{ - const size_t __n = static_cast(__last - __first); - if (__n > 0) - { - __result -= __n; - _VSTD::memmove(__result, __first, __n * sizeof(_Up)); + while (__first != __last_iter) { + *--__result = _IterOps<_AlgPolicy>::__iter_move(--__last_iter); } - return __result; -} -template -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 -_BidirectionalIterator2 -__move_backward(_BidirectionalIterator1 __first, _BidirectionalIterator1 __last, - _BidirectionalIterator2 __result) -{ - if (__libcpp_is_constant_evaluated()) { - return _VSTD::__move_backward_constexpr<_AlgPolicy>(__first, __last, __result); - } else { - return _VSTD::__rewrap_iter(__result, - _VSTD::__move_backward_impl<_AlgPolicy>(_VSTD::__unwrap_iter(__first), - _VSTD::__unwrap_iter(__last), - _VSTD::__unwrap_iter(__result))); + return std::make_pair(std::move(__original_last_iter), std::move(__result)); + } + + template ::value, int> = 0> + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_InIter, _OutIter> + operator()(_InIter __first, _InIter __last, _OutIter __result) const { + using _Traits = __segmented_iterator_traits<_InIter>; + auto __sfirst = _Traits::__segment(__first); + auto __slast = _Traits::__segment(__last); + if (__sfirst == __slast) { + auto __iters = + std::__move_backward<_AlgPolicy>(_Traits::__local(__first), _Traits::__local(__last), std::move(__result)); + return std::make_pair(__last, __iters.second); } + + __result = + std::__move_backward<_AlgPolicy>(_Traits::__begin(__slast), _Traits::__local(__last), std::move(__result)) + .second; + --__slast; + while (__sfirst != __slast) { + __result = + std::__move_backward<_AlgPolicy>(_Traits::__begin(__slast), _Traits::__end(__slast), std::move(__result)) + .second; + --__slast; + } + __result = std::__move_backward<_AlgPolicy>(_Traits::__local(__first), _Traits::__end(__slast), std::move(__result)) + .second; + return std::make_pair(__last, std::move(__result)); + } + + template ::value && + !__is_segmented_iterator<_InIter>::value && __is_segmented_iterator<_OutIter>::value, + int> = 0> + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_InIter, _OutIter> + operator()(_InIter __first, _InIter __last, _OutIter __result) { + using _Traits = __segmented_iterator_traits<_OutIter>; + using _DiffT = typename common_type<__iter_diff_t<_InIter>, __iter_diff_t<_OutIter> >::type; + + // When the range contains no elements, __result might not be a valid iterator + if (__first == __last) + return std::make_pair(__first, __result); + + auto __orig_last = __last; + + auto __local_last = _Traits::__local(__result); + auto __segment_iterator = _Traits::__segment(__result); + 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; + __last -= __size; + + if (__first == __last) + return std::make_pair(std::move(__orig_last), _Traits::__compose(__segment_iterator, std::move(__iter))); + + __local_last = _Traits::__end(--__segment_iterator); + } + } +}; + +struct __move_backward_trivial { + // 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*> + 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> +__move_backward(_BidirectionalIterator1 __first, _Sentinel __last, _BidirectionalIterator2 __result) { + static_assert(std::is_copy_constructible<_BidirectionalIterator1>::value && + std::is_copy_constructible<_BidirectionalIterator1>::value, "Iterators must be copy constructible."); + + return std::__dispatch_copy_or_move<_AlgPolicy, __move_backward_loop<_AlgPolicy>, __move_backward_trivial>( + std::move(__first), std::move(__last), std::move(__result)); } template -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 -_BidirectionalIterator2 -move_backward(_BidirectionalIterator1 __first, _BidirectionalIterator1 __last, - _BidirectionalIterator2 __result) -{ - return std::__move_backward<_ClassicAlgPolicy>(std::move(__first), std::move(__last), std::move(__result)); +inline _LIBCPP_INLINE_VISIBILITY _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; } _LIBCPP_END_NAMESPACE_STD +_LIBCPP_POP_MACROS + #endif // _LIBCPP___ALGORITHM_MOVE_BACKWARD_H diff --git a/lib/libcxx/include/__algorithm/next_permutation.h b/lib/libcxx/include/__algorithm/next_permutation.h index b58dcf4e1a..73e8b99ab9 100644 --- a/lib/libcxx/include/__algorithm/next_permutation.h +++ b/lib/libcxx/include/__algorithm/next_permutation.h @@ -25,8 +25,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD template -_LIBCPP_CONSTEXPR_AFTER_CXX17 -pair<_BidirectionalIterator, bool> +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_BidirectionalIterator, bool> __next_permutation(_BidirectionalIterator __first, _Sentinel __last, _Compare&& __comp) { using _Result = pair<_BidirectionalIterator, bool>; @@ -57,17 +56,16 @@ __next_permutation(_BidirectionalIterator __first, _Sentinel __last, _Compare&& } template -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 bool next_permutation(_BidirectionalIterator __first, _BidirectionalIterator __last, _Compare __comp) { - using _Comp_ref = typename __comp_ref_type<_Compare>::type; return std::__next_permutation<_ClassicAlgPolicy>( - std::move(__first), std::move(__last), static_cast<_Comp_ref>(__comp)).second; + std::move(__first), std::move(__last), static_cast<__comp_ref_type<_Compare> >(__comp)).second; } template -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 bool next_permutation(_BidirectionalIterator __first, _BidirectionalIterator __last) { diff --git a/lib/libcxx/include/__algorithm/none_of.h b/lib/libcxx/include/__algorithm/none_of.h index b34b1e00dd..19357eb236 100644 --- a/lib/libcxx/include/__algorithm/none_of.h +++ b/lib/libcxx/include/__algorithm/none_of.h @@ -19,7 +19,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD template -_LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 bool +_LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 bool none_of(_InputIterator __first, _InputIterator __last, _Predicate __pred) { for (; __first != __last; ++__first) if (__pred(*__first)) diff --git a/lib/libcxx/include/__algorithm/nth_element.h b/lib/libcxx/include/__algorithm/nth_element.h index 688398dee8..9fdfb2cae6 100644 --- a/lib/libcxx/include/__algorithm/nth_element.h +++ b/lib/libcxx/include/__algorithm/nth_element.h @@ -26,7 +26,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD template -_LIBCPP_CONSTEXPR_AFTER_CXX11 bool +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool __nth_element_find_guard(_RandomAccessIterator& __i, _RandomAccessIterator& __j, _RandomAccessIterator __m, _Compare __comp) { @@ -42,7 +42,7 @@ __nth_element_find_guard(_RandomAccessIterator& __i, _RandomAccessIterator& __j, } template -_LIBCPP_CONSTEXPR_AFTER_CXX11 void +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void __nth_element(_RandomAccessIterator __first, _RandomAccessIterator __nth, _RandomAccessIterator __last, _Compare __comp) { using _Ops = _IterOps<_AlgPolicy>; @@ -223,7 +223,7 @@ __nth_element(_RandomAccessIterator __first, _RandomAccessIterator __nth, _Rando } template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __nth_element_impl(_RandomAccessIterator __first, _RandomAccessIterator __nth, _RandomAccessIterator __last, _Compare& __comp) { if (__nth == __last) @@ -231,8 +231,7 @@ void __nth_element_impl(_RandomAccessIterator __first, _RandomAccessIterator __n std::__debug_randomize_range<_AlgPolicy>(__first, __last); - using _Comp_ref = typename __comp_ref_type<_Compare>::type; - std::__nth_element<_AlgPolicy, _Comp_ref>(__first, __nth, __last, __comp); + std::__nth_element<_AlgPolicy, __comp_ref_type<_Compare> >(__first, __nth, __last, __comp); std::__debug_randomize_range<_AlgPolicy>(__first, __nth); if (__nth != __last) { @@ -241,14 +240,14 @@ void __nth_element_impl(_RandomAccessIterator __first, _RandomAccessIterator __n } template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void nth_element(_RandomAccessIterator __first, _RandomAccessIterator __nth, _RandomAccessIterator __last, _Compare __comp) { std::__nth_element_impl<_ClassicAlgPolicy>(std::move(__first), std::move(__nth), std::move(__last), __comp); } template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void nth_element(_RandomAccessIterator __first, _RandomAccessIterator __nth, _RandomAccessIterator __last) { std::nth_element(std::move(__first), std::move(__nth), std::move(__last), __less::value_type>()); diff --git a/lib/libcxx/include/__algorithm/partial_sort.h b/lib/libcxx/include/__algorithm/partial_sort.h index dff0cd01f3..e0812affe6 100644 --- a/lib/libcxx/include/__algorithm/partial_sort.h +++ b/lib/libcxx/include/__algorithm/partial_sort.h @@ -29,7 +29,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD template -_LIBCPP_CONSTEXPR_AFTER_CXX17 +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _RandomAccessIterator __partial_sort_impl( _RandomAccessIterator __first, _RandomAccessIterator __middle, _Sentinel __last, _Compare&& __comp) { if (__first == __middle) { @@ -47,7 +47,6 @@ _RandomAccessIterator __partial_sort_impl( _IterOps<_AlgPolicy>::iter_swap(__i, __first); std::__sift_down<_AlgPolicy>(__first, __comp, __len, __first); } - } std::__sort_heap<_AlgPolicy>(std::move(__first), std::move(__middle), __comp); @@ -55,7 +54,7 @@ _RandomAccessIterator __partial_sort_impl( } template -_LIBCPP_CONSTEXPR_AFTER_CXX17 +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _RandomAccessIterator __partial_sort(_RandomAccessIterator __first, _RandomAccessIterator __middle, _Sentinel __last, _Compare& __comp) { if (__first == __middle) @@ -63,8 +62,8 @@ _RandomAccessIterator __partial_sort(_RandomAccessIterator __first, _RandomAcces std::__debug_randomize_range<_AlgPolicy>(__first, __last); - using _Comp_ref = typename __comp_ref_type<_Compare>::type; - auto __last_iter = std::__partial_sort_impl<_AlgPolicy>(__first, __middle, __last, static_cast<_Comp_ref>(__comp)); + auto __last_iter = + std::__partial_sort_impl<_AlgPolicy>(__first, __middle, __last, static_cast<__comp_ref_type<_Compare> >(__comp)); std::__debug_randomize_range<_AlgPolicy>(__middle, __last); @@ -72,7 +71,7 @@ _RandomAccessIterator __partial_sort(_RandomAccessIterator __first, _RandomAcces } template -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 void partial_sort(_RandomAccessIterator __first, _RandomAccessIterator __middle, _RandomAccessIterator __last, _Compare __comp) @@ -84,7 +83,7 @@ partial_sort(_RandomAccessIterator __first, _RandomAccessIterator __middle, _Ran } template -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 void partial_sort(_RandomAccessIterator __first, _RandomAccessIterator __middle, _RandomAccessIterator __last) { diff --git a/lib/libcxx/include/__algorithm/partial_sort_copy.h b/lib/libcxx/include/__algorithm/partial_sort_copy.h index 55edf31b0f..1aba07105d 100644 --- a/lib/libcxx/include/__algorithm/partial_sort_copy.h +++ b/lib/libcxx/include/__algorithm/partial_sort_copy.h @@ -33,7 +33,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD template -_LIBCPP_CONSTEXPR_AFTER_CXX17 pair<_InputIterator, _RandomAccessIterator> +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_InputIterator, _RandomAccessIterator> __partial_sort_copy(_InputIterator __first, _Sentinel1 __last, _RandomAccessIterator __result_first, _Sentinel2 __result_last, _Compare&& __comp, _Proj1&& __proj1, _Proj2&& __proj2) @@ -60,7 +60,7 @@ __partial_sort_copy(_InputIterator __first, _Sentinel1 __last, } template -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 _RandomAccessIterator partial_sort_copy(_InputIterator __first, _InputIterator __last, _RandomAccessIterator __result_first, _RandomAccessIterator __result_last, _Compare __comp) @@ -68,14 +68,13 @@ partial_sort_copy(_InputIterator __first, _InputIterator __last, static_assert(__is_callable<_Compare, decltype(*__first), decltype(*__result_first)>::value, "Comparator has to be callable"); - using _Comp_ref = typename __comp_ref_type<_Compare>::type; auto __result = std::__partial_sort_copy<_ClassicAlgPolicy>(__first, __last, __result_first, __result_last, - static_cast<_Comp_ref>(__comp), __identity(), __identity()); + static_cast<__comp_ref_type<_Compare> >(__comp), __identity(), __identity()); return __result.second; } template -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 _RandomAccessIterator partial_sort_copy(_InputIterator __first, _InputIterator __last, _RandomAccessIterator __result_first, _RandomAccessIterator __result_last) diff --git a/lib/libcxx/include/__algorithm/partition.h b/lib/libcxx/include/__algorithm/partition.h index 60b4e290eb..0e094bf8dd 100644 --- a/lib/libcxx/include/__algorithm/partition.h +++ b/lib/libcxx/include/__algorithm/partition.h @@ -23,7 +23,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD template -_LIBCPP_CONSTEXPR_AFTER_CXX17 pair<_ForwardIterator, _ForwardIterator> +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_ForwardIterator, _ForwardIterator> __partition_impl(_ForwardIterator __first, _Sentinel __last, _Predicate __pred, forward_iterator_tag) { while (true) @@ -48,7 +48,7 @@ __partition_impl(_ForwardIterator __first, _Sentinel __last, _Predicate __pred, } template -_LIBCPP_CONSTEXPR_AFTER_CXX17 pair<_BidirectionalIterator, _BidirectionalIterator> +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_BidirectionalIterator, _BidirectionalIterator> __partition_impl(_BidirectionalIterator __first, _Sentinel __sentinel, _Predicate __pred, bidirectional_iterator_tag) { @@ -76,15 +76,15 @@ __partition_impl(_BidirectionalIterator __first, _Sentinel __sentinel, _Predicat } template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_ForwardIterator, _ForwardIterator> __partition( _ForwardIterator __first, _Sentinel __last, _Predicate&& __pred, _IterCategory __iter_category) { - return std::__partition_impl<__uncvref_t<_Predicate>&, _AlgPolicy>( + return std::__partition_impl<__remove_cvref_t<_Predicate>&, _AlgPolicy>( std::move(__first), std::move(__last), __pred, __iter_category); } template -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator partition(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred) { diff --git a/lib/libcxx/include/__algorithm/partition_copy.h b/lib/libcxx/include/__algorithm/partition_copy.h index cacde0bfd4..ff8826a937 100644 --- a/lib/libcxx/include/__algorithm/partition_copy.h +++ b/lib/libcxx/include/__algorithm/partition_copy.h @@ -21,7 +21,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD template -_LIBCPP_CONSTEXPR_AFTER_CXX17 pair<_OutputIterator1, _OutputIterator2> +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_OutputIterator1, _OutputIterator2> partition_copy(_InputIterator __first, _InputIterator __last, _OutputIterator1 __out_true, _OutputIterator2 __out_false, _Predicate __pred) diff --git a/lib/libcxx/include/__algorithm/partition_point.h b/lib/libcxx/include/__algorithm/partition_point.h index 1675534e60..6ede71a264 100644 --- a/lib/libcxx/include/__algorithm/partition_point.h +++ b/lib/libcxx/include/__algorithm/partition_point.h @@ -22,7 +22,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD template -_LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator partition_point(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred) { typedef typename iterator_traits<_ForwardIterator>::difference_type difference_type; diff --git a/lib/libcxx/include/__algorithm/pop_heap.h b/lib/libcxx/include/__algorithm/pop_heap.h index 44d5d39726..94d32a4239 100644 --- a/lib/libcxx/include/__algorithm/pop_heap.h +++ b/lib/libcxx/include/__algorithm/pop_heap.h @@ -27,13 +27,12 @@ _LIBCPP_BEGIN_NAMESPACE_STD template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void __pop_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare& __comp, typename iterator_traits<_RandomAccessIterator>::difference_type __len) { _LIBCPP_ASSERT(__len > 0, "The heap given to pop_heap must be non-empty"); - using _CompRef = typename __comp_ref_type<_Compare>::type; - _CompRef __comp_ref = __comp; + __comp_ref_type<_Compare> __comp_ref = __comp; using value_type = typename iterator_traits<_RandomAccessIterator>::value_type; if (__len > 1) { @@ -53,7 +52,7 @@ void __pop_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Co } template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void pop_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) { static_assert(std::is_copy_constructible<_RandomAccessIterator>::value, "Iterators must be copy constructible."); static_assert(std::is_copy_assignable<_RandomAccessIterator>::value, "Iterators must be copy assignable."); @@ -63,7 +62,7 @@ void pop_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Comp } template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void pop_heap(_RandomAccessIterator __first, _RandomAccessIterator __last) { std::pop_heap(std::move(__first), std::move(__last), __less::value_type>()); diff --git a/lib/libcxx/include/__algorithm/prev_permutation.h b/lib/libcxx/include/__algorithm/prev_permutation.h index 698506372b..0b86ab74ee 100644 --- a/lib/libcxx/include/__algorithm/prev_permutation.h +++ b/lib/libcxx/include/__algorithm/prev_permutation.h @@ -25,7 +25,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD template -_LIBCPP_CONSTEXPR_AFTER_CXX17 +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_BidirectionalIterator, bool> __prev_permutation(_BidirectionalIterator __first, _Sentinel __last, _Compare&& __comp) { @@ -57,17 +57,16 @@ __prev_permutation(_BidirectionalIterator __first, _Sentinel __last, _Compare&& } template -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 bool prev_permutation(_BidirectionalIterator __first, _BidirectionalIterator __last, _Compare __comp) { - using _Comp_ref = typename __comp_ref_type<_Compare>::type; return std::__prev_permutation<_ClassicAlgPolicy>( - std::move(__first), std::move(__last), static_cast<_Comp_ref>(__comp)).second; + std::move(__first), std::move(__last), static_cast<__comp_ref_type<_Compare> >(__comp)).second; } template -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 bool prev_permutation(_BidirectionalIterator __first, _BidirectionalIterator __last) { diff --git a/lib/libcxx/include/__algorithm/push_heap.h b/lib/libcxx/include/__algorithm/push_heap.h index 72ad51e1a8..9068495774 100644 --- a/lib/libcxx/include/__algorithm/push_heap.h +++ b/lib/libcxx/include/__algorithm/push_heap.h @@ -24,7 +24,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void __sift_up(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare&& __comp, typename iterator_traits<_RandomAccessIterator>::difference_type __len) { using value_type = typename iterator_traits<_RandomAccessIterator>::value_type; @@ -50,15 +50,14 @@ void __sift_up(_RandomAccessIterator __first, _RandomAccessIterator __last, _Com } template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void __push_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare& __comp) { - using _CompRef = typename __comp_ref_type<_Compare>::type; typename iterator_traits<_RandomAccessIterator>::difference_type __len = __last - __first; - std::__sift_up<_AlgPolicy, _CompRef>(std::move(__first), std::move(__last), __comp, __len); + std::__sift_up<_AlgPolicy, __comp_ref_type<_Compare> >(std::move(__first), std::move(__last), __comp, __len); } template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void push_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) { static_assert(std::is_copy_constructible<_RandomAccessIterator>::value, "Iterators must be copy constructible."); static_assert(std::is_copy_assignable<_RandomAccessIterator>::value, "Iterators must be copy assignable."); @@ -67,7 +66,7 @@ void push_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Com } template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void push_heap(_RandomAccessIterator __first, _RandomAccessIterator __last) { std::push_heap(std::move(__first), std::move(__last), __less::value_type>()); diff --git a/lib/libcxx/include/__algorithm/ranges_adjacent_find.h b/lib/libcxx/include/__algorithm/ranges_adjacent_find.h index e798d56829..d338d13e6e 100644 --- a/lib/libcxx/include/__algorithm/ranges_adjacent_find.h +++ b/lib/libcxx/include/__algorithm/ranges_adjacent_find.h @@ -24,7 +24,7 @@ # pragma GCC system_header #endif -#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#if _LIBCPP_STD_VER > 17 _LIBCPP_BEGIN_NAMESPACE_STD @@ -50,7 +50,7 @@ struct __fn { template _Sent, class _Proj = identity, indirect_binary_predicate, projected<_Iter, _Proj>> _Pred = ranges::equal_to> - _LIBCPP_HIDE_FROM_ABI constexpr + _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr _Iter operator()(_Iter __first, _Sent __last, _Pred __pred = {}, _Proj __proj = {}) const { return __adjacent_find_impl(std::move(__first), std::move(__last), __pred, __proj); } @@ -59,7 +59,7 @@ struct __fn { class _Proj = identity, indirect_binary_predicate, _Proj>, projected, _Proj>> _Pred = ranges::equal_to> - _LIBCPP_HIDE_FROM_ABI constexpr + _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr borrowed_iterator_t<_Range> operator()(_Range&& __range, _Pred __pred = {}, _Proj __proj = {}) const { return __adjacent_find_impl(ranges::begin(__range), ranges::end(__range), __pred, __proj); } @@ -73,6 +73,6 @@ inline namespace __cpo { _LIBCPP_END_NAMESPACE_STD -#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#endif // _LIBCPP_STD_VER > 17 #endif // _LIBCPP___ALGORITHM_RANGES_ADJACENT_FIND_H diff --git a/lib/libcxx/include/__algorithm/ranges_all_of.h b/lib/libcxx/include/__algorithm/ranges_all_of.h index a146865652..e45c4e5843 100644 --- a/lib/libcxx/include/__algorithm/ranges_all_of.h +++ b/lib/libcxx/include/__algorithm/ranges_all_of.h @@ -22,7 +22,7 @@ # pragma GCC system_header #endif -#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#if _LIBCPP_STD_VER > 17 _LIBCPP_BEGIN_NAMESPACE_STD @@ -42,14 +42,14 @@ struct __fn { template _Sent, class _Proj = identity, indirect_unary_predicate> _Pred> - _LIBCPP_HIDE_FROM_ABI constexpr + _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr bool operator()(_Iter __first, _Sent __last, _Pred __pred, _Proj __proj = {}) const { return __all_of_impl(std::move(__first), std::move(__last), __pred, __proj); } template , _Proj>> _Pred> - _LIBCPP_HIDE_FROM_ABI constexpr + _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr bool operator()(_Range&& __range, _Pred __pred, _Proj __proj = {}) const { return __all_of_impl(ranges::begin(__range), ranges::end(__range), __pred, __proj); } @@ -63,6 +63,6 @@ inline namespace __cpo { _LIBCPP_END_NAMESPACE_STD -#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#endif // _LIBCPP_STD_VER > 17 #endif // _LIBCPP___ALGORITHM_RANGES_ALL_OF_H diff --git a/lib/libcxx/include/__algorithm/ranges_any_of.h b/lib/libcxx/include/__algorithm/ranges_any_of.h index 11c52cbe21..e7d1e723a7 100644 --- a/lib/libcxx/include/__algorithm/ranges_any_of.h +++ b/lib/libcxx/include/__algorithm/ranges_any_of.h @@ -22,7 +22,7 @@ # pragma GCC system_header #endif -#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#if _LIBCPP_STD_VER > 17 _LIBCPP_BEGIN_NAMESPACE_STD @@ -42,14 +42,14 @@ struct __fn { template _Sent, class _Proj = identity, indirect_unary_predicate> _Pred> - _LIBCPP_HIDE_FROM_ABI constexpr + _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr bool operator()(_Iter __first, _Sent __last, _Pred __pred = {}, _Proj __proj = {}) const { return __any_of_impl(std::move(__first), std::move(__last), __pred, __proj); } template , _Proj>> _Pred> - _LIBCPP_HIDE_FROM_ABI constexpr + _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr bool operator()(_Range&& __range, _Pred __pred, _Proj __proj = {}) const { return __any_of_impl(ranges::begin(__range), ranges::end(__range), __pred, __proj); } @@ -63,6 +63,6 @@ inline namespace __cpo { _LIBCPP_END_NAMESPACE_STD -#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#endif // _LIBCPP_STD_VER > 17 #endif // _LIBCPP___ALGORITHM_RANGES_ANY_OF_H diff --git a/lib/libcxx/include/__algorithm/ranges_binary_search.h b/lib/libcxx/include/__algorithm/ranges_binary_search.h index 6da68834aa..b2a8977652 100644 --- a/lib/libcxx/include/__algorithm/ranges_binary_search.h +++ b/lib/libcxx/include/__algorithm/ranges_binary_search.h @@ -24,7 +24,7 @@ # pragma GCC system_header #endif -#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#if _LIBCPP_STD_VER > 17 _LIBCPP_BEGIN_NAMESPACE_STD @@ -33,7 +33,7 @@ namespace __binary_search { struct __fn { template _Sent, class _Type, class _Proj = identity, indirect_strict_weak_order> _Comp = ranges::less> - _LIBCPP_HIDE_FROM_ABI constexpr + _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr bool operator()(_Iter __first, _Sent __last, const _Type& __value, _Comp __comp = {}, _Proj __proj = {}) const { auto __ret = std::__lower_bound_impl<_RangeAlgPolicy>(__first, __last, __value, __comp, __proj); return __ret != __last && !std::invoke(__comp, __value, std::invoke(__proj, *__first)); @@ -41,7 +41,7 @@ struct __fn { template , _Proj>> _Comp = ranges::less> - _LIBCPP_HIDE_FROM_ABI constexpr + _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr bool operator()(_Range&& __r, const _Type& __value, _Comp __comp = {}, _Proj __proj = {}) const { auto __first = ranges::begin(__r); auto __last = ranges::end(__r); @@ -58,6 +58,6 @@ inline namespace __cpo { _LIBCPP_END_NAMESPACE_STD -#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#endif // _LIBCPP_STD_VER > 17 #endif // _LIBCPP___ALGORITHM_RANGES_BINARY_SEARCH_H diff --git a/lib/libcxx/include/__algorithm/ranges_clamp.h b/lib/libcxx/include/__algorithm/ranges_clamp.h index bdde97e178..09a97fc790 100644 --- a/lib/libcxx/include/__algorithm/ranges_clamp.h +++ b/lib/libcxx/include/__algorithm/ranges_clamp.h @@ -22,7 +22,7 @@ # pragma GCC system_header #endif -#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#if _LIBCPP_STD_VER > 17 _LIBCPP_BEGIN_NAMESPACE_STD @@ -33,7 +33,7 @@ struct __fn { template > _Comp = ranges::less> - _LIBCPP_HIDE_FROM_ABI constexpr + _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr const _Type& operator()(const _Type& __value, const _Type& __low, const _Type& __high, @@ -60,6 +60,6 @@ inline namespace __cpo { _LIBCPP_END_NAMESPACE_STD -#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#endif // _LIBCPP_STD_VER > 17 #endif // _LIBCPP___ALGORITHM_RANGES_CLAMP_H diff --git a/lib/libcxx/include/__algorithm/ranges_copy.h b/lib/libcxx/include/__algorithm/ranges_copy.h index f5d6d5cd13..bb02c84efb 100644 --- a/lib/libcxx/include/__algorithm/ranges_copy.h +++ b/lib/libcxx/include/__algorithm/ranges_copy.h @@ -11,6 +11,7 @@ #include <__algorithm/copy.h> #include <__algorithm/in_out_result.h> +#include <__algorithm/iterator_operations.h> #include <__config> #include <__functional/identity.h> #include <__iterator/concepts.h> @@ -18,12 +19,13 @@ #include <__ranges/concepts.h> #include <__ranges/dangling.h> #include <__utility/move.h> +#include <__utility/pair.h> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header #endif -#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#if _LIBCPP_STD_VER > 17 _LIBCPP_BEGIN_NAMESPACE_STD @@ -39,7 +41,7 @@ struct __fn { 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)); + auto __ret = std::__copy<_RangeAlgPolicy>(std::move(__first), std::move(__last), std::move(__result)); return {std::move(__ret.first), std::move(__ret.second)}; } @@ -47,7 +49,7 @@ struct __fn { 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)); + auto __ret = std::__copy<_RangeAlgPolicy>(ranges::begin(__r), ranges::end(__r), std::move(__result)); return {std::move(__ret.first), std::move(__ret.second)}; } }; @@ -60,6 +62,6 @@ inline namespace __cpo { _LIBCPP_END_NAMESPACE_STD -#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#endif // _LIBCPP_STD_VER > 17 #endif // _LIBCPP___ALGORITHM_RANGES_COPY_H diff --git a/lib/libcxx/include/__algorithm/ranges_copy_backward.h b/lib/libcxx/include/__algorithm/ranges_copy_backward.h index 673df8025f..f41af66f39 100644 --- a/lib/libcxx/include/__algorithm/ranges_copy_backward.h +++ b/lib/libcxx/include/__algorithm/ranges_copy_backward.h @@ -14,7 +14,6 @@ #include <__algorithm/iterator_operations.h> #include <__config> #include <__iterator/concepts.h> -#include <__iterator/reverse_iterator.h> #include <__ranges/access.h> #include <__ranges/concepts.h> #include <__ranges/dangling.h> @@ -24,7 +23,7 @@ # pragma GCC system_header #endif -#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#if _LIBCPP_STD_VER > 17 _LIBCPP_BEGIN_NAMESPACE_STD @@ -61,6 +60,6 @@ inline namespace __cpo { _LIBCPP_END_NAMESPACE_STD -#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#endif // _LIBCPP_STD_VER > 17 #endif // _LIBCPP___ALGORITHM_RANGES_COPY_BACKWARD_H diff --git a/lib/libcxx/include/__algorithm/ranges_copy_if.h b/lib/libcxx/include/__algorithm/ranges_copy_if.h index 492104fbbf..dba41c3b3a 100644 --- a/lib/libcxx/include/__algorithm/ranges_copy_if.h +++ b/lib/libcxx/include/__algorithm/ranges_copy_if.h @@ -24,7 +24,7 @@ # pragma GCC system_header #endif -#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#if _LIBCPP_STD_VER > 17 _LIBCPP_BEGIN_NAMESPACE_STD @@ -76,6 +76,6 @@ inline namespace __cpo { _LIBCPP_END_NAMESPACE_STD -#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#endif // _LIBCPP_STD_VER > 17 #endif // _LIBCPP___ALGORITHM_RANGES_COPY_IF_H diff --git a/lib/libcxx/include/__algorithm/ranges_copy_n.h b/lib/libcxx/include/__algorithm/ranges_copy_n.h index eaa05c9546..04bb80b3ba 100644 --- a/lib/libcxx/include/__algorithm/ranges_copy_n.h +++ b/lib/libcxx/include/__algorithm/ranges_copy_n.h @@ -11,6 +11,7 @@ #include <__algorithm/copy.h> #include <__algorithm/in_out_result.h> +#include <__algorithm/iterator_operations.h> #include <__algorithm/ranges_copy.h> #include <__config> #include <__functional/identity.h> @@ -26,7 +27,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD -#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#if _LIBCPP_STD_VER > 17 namespace ranges { @@ -51,7 +52,7 @@ struct __fn { template _LIBCPP_HIDE_FROM_ABI constexpr static copy_n_result<_InIter, _OutIter> __go(_InIter __first, _DiffType __n, _OutIter __result) { - auto __ret = std::__copy(__first, __first + __n, __result); + auto __ret = std::__copy<_RangeAlgPolicy>(__first, __first + __n, __result); return {__ret.first, __ret.second}; } @@ -69,7 +70,7 @@ inline namespace __cpo { } // namespace __cpo } // namespace ranges -#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#endif // _LIBCPP_STD_VER > 17 _LIBCPP_END_NAMESPACE_STD diff --git a/lib/libcxx/include/__algorithm/ranges_count.h b/lib/libcxx/include/__algorithm/ranges_count.h index 670df26911..527dd06200 100644 --- a/lib/libcxx/include/__algorithm/ranges_count.h +++ b/lib/libcxx/include/__algorithm/ranges_count.h @@ -25,7 +25,7 @@ # pragma GCC system_header #endif -#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#if _LIBCPP_STD_VER > 17 _LIBCPP_BEGIN_NAMESPACE_STD @@ -34,7 +34,7 @@ namespace __count { struct __fn { template _Sent, class _Type, class _Proj = identity> requires indirect_binary_predicate, const _Type*> - _LIBCPP_HIDE_FROM_ABI constexpr + _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr iter_difference_t<_Iter> operator()(_Iter __first, _Sent __last, const _Type& __value, _Proj __proj = {}) const { auto __pred = [&](auto&& __e) { return __e == __value; }; return ranges::__count_if_impl(std::move(__first), std::move(__last), __pred, __proj); @@ -42,7 +42,7 @@ struct __fn { template requires indirect_binary_predicate, _Proj>, const _Type*> - _LIBCPP_HIDE_FROM_ABI constexpr + _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr range_difference_t<_Range> operator()(_Range&& __r, const _Type& __value, _Proj __proj = {}) const { auto __pred = [&](auto&& __e) { return __e == __value; }; return ranges::__count_if_impl(ranges::begin(__r), ranges::end(__r), __pred, __proj); @@ -57,6 +57,6 @@ inline namespace __cpo { _LIBCPP_END_NAMESPACE_STD -#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#endif // _LIBCPP_STD_VER > 17 #endif // _LIBCPP___ALGORITHM_RANGES_COUNT_H diff --git a/lib/libcxx/include/__algorithm/ranges_count_if.h b/lib/libcxx/include/__algorithm/ranges_count_if.h index 0f34ee9f2b..931618b7b5 100644 --- a/lib/libcxx/include/__algorithm/ranges_count_if.h +++ b/lib/libcxx/include/__algorithm/ranges_count_if.h @@ -25,7 +25,7 @@ # pragma GCC system_header #endif -#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#if _LIBCPP_STD_VER > 17 _LIBCPP_BEGIN_NAMESPACE_STD @@ -46,14 +46,14 @@ namespace __count_if { struct __fn { template _Sent, class _Proj = identity, indirect_unary_predicate> _Predicate> - _LIBCPP_HIDE_FROM_ABI constexpr + _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr iter_difference_t<_Iter> operator()(_Iter __first, _Sent __last, _Predicate __pred, _Proj __proj = {}) const { return ranges::__count_if_impl(std::move(__first), std::move(__last), __pred, __proj); } template , _Proj>> _Predicate> - _LIBCPP_HIDE_FROM_ABI constexpr + _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr range_difference_t<_Range> operator()(_Range&& __r, _Predicate __pred, _Proj __proj = {}) const { return ranges::__count_if_impl(ranges::begin(__r), ranges::end(__r), __pred, __proj); } @@ -67,6 +67,6 @@ inline namespace __cpo { _LIBCPP_END_NAMESPACE_STD -#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#endif // _LIBCPP_STD_VER > 17 #endif // _LIBCPP___ALGORITHM_RANGES_COUNT_IF_H diff --git a/lib/libcxx/include/__algorithm/ranges_equal.h b/lib/libcxx/include/__algorithm/ranges_equal.h index c5f2d23322..3c417f09de 100644 --- a/lib/libcxx/include/__algorithm/ranges_equal.h +++ b/lib/libcxx/include/__algorithm/ranges_equal.h @@ -24,7 +24,7 @@ # pragma GCC system_header #endif -#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#if _LIBCPP_STD_VER > 17 _LIBCPP_BEGIN_NAMESPACE_STD @@ -60,7 +60,7 @@ public: class _Proj1 = identity, class _Proj2 = identity> requires indirectly_comparable<_Iter1, _Iter2, _Pred, _Proj1, _Proj2> - _LIBCPP_HIDE_FROM_ABI constexpr + _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr bool operator()(_Iter1 __first1, _Sent1 __last1, _Iter2 __first2, _Sent2 __last2, _Pred __pred = {}, @@ -83,7 +83,7 @@ public: class _Proj1 = identity, class _Proj2 = identity> requires indirectly_comparable, iterator_t<_Range2>, _Pred, _Proj1, _Proj2> - _LIBCPP_HIDE_FROM_ABI constexpr + _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr bool operator()(_Range1&& __range1, _Range2&& __range2, _Pred __pred = {}, @@ -110,6 +110,6 @@ inline namespace __cpo { _LIBCPP_END_NAMESPACE_STD -#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#endif // _LIBCPP_STD_VER > 17 #endif // _LIBCPP___ALGORITHM_RANGES_EQUAL_H diff --git a/lib/libcxx/include/__algorithm/ranges_equal_range.h b/lib/libcxx/include/__algorithm/ranges_equal_range.h index dd4b377df1..94dc058e7b 100644 --- a/lib/libcxx/include/__algorithm/ranges_equal_range.h +++ b/lib/libcxx/include/__algorithm/ranges_equal_range.h @@ -24,12 +24,13 @@ #include <__ranges/subrange.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 #endif -#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#if _LIBCPP_STD_VER > 17 _LIBCPP_BEGIN_NAMESPACE_STD @@ -43,7 +44,7 @@ struct __fn { class _Tp, class _Proj = identity, indirect_strict_weak_order> _Comp = ranges::less> - _LIBCPP_HIDE_FROM_ABI constexpr subrange<_Iter> + _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr subrange<_Iter> operator()(_Iter __first, _Sent __last, const _Tp& __value, _Comp __comp = {}, _Proj __proj = {}) const { auto __ret = std::__equal_range<_RangeAlgPolicy>( std::move(__first), std::move(__last), __value, __comp, __proj); @@ -55,7 +56,7 @@ struct __fn { class _Tp, class _Proj = identity, indirect_strict_weak_order, _Proj>> _Comp = ranges::less> - _LIBCPP_HIDE_FROM_ABI constexpr borrowed_subrange_t<_Range> + _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr borrowed_subrange_t<_Range> operator()(_Range&& __range, const _Tp& __value, _Comp __comp = {}, _Proj __proj = {}) const { auto __ret = std::__equal_range<_RangeAlgPolicy>( ranges::begin(__range), ranges::end(__range), __value, __comp, __proj); @@ -72,6 +73,6 @@ inline namespace __cpo { _LIBCPP_END_NAMESPACE_STD -#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#endif // _LIBCPP_STD_VER > 17 #endif // _LIBCPP___ALGORITHM_RANGES_EQUAL_RANGE_H diff --git a/lib/libcxx/include/__algorithm/ranges_fill.h b/lib/libcxx/include/__algorithm/ranges_fill.h index 7ce4a76ba9..6ebc2bd67d 100644 --- a/lib/libcxx/include/__algorithm/ranges_fill.h +++ b/lib/libcxx/include/__algorithm/ranges_fill.h @@ -20,7 +20,7 @@ # pragma GCC system_header #endif -#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#if _LIBCPP_STD_VER > 17 _LIBCPP_BEGIN_NAMESPACE_STD @@ -54,6 +54,6 @@ inline namespace __cpo { _LIBCPP_END_NAMESPACE_STD -#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#endif // _LIBCPP_STD_VER > 17 #endif // _LIBCPP___ALGORITHM_RANGES_FILL_H diff --git a/lib/libcxx/include/__algorithm/ranges_fill_n.h b/lib/libcxx/include/__algorithm/ranges_fill_n.h index d93c573406..a2660e8b59 100644 --- a/lib/libcxx/include/__algorithm/ranges_fill_n.h +++ b/lib/libcxx/include/__algorithm/ranges_fill_n.h @@ -17,7 +17,7 @@ # pragma GCC system_header #endif -#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#if _LIBCPP_STD_VER > 17 _LIBCPP_BEGIN_NAMESPACE_STD @@ -43,6 +43,6 @@ inline namespace __cpo { _LIBCPP_END_NAMESPACE_STD -#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#endif // _LIBCPP_STD_VER > 17 #endif // _LIBCPP___ALGORITHM_RANGES_FILL_N_H diff --git a/lib/libcxx/include/__algorithm/ranges_find.h b/lib/libcxx/include/__algorithm/ranges_find.h index ca6d2f4382..580c2a14c9 100644 --- a/lib/libcxx/include/__algorithm/ranges_find.h +++ b/lib/libcxx/include/__algorithm/ranges_find.h @@ -26,7 +26,7 @@ # pragma GCC system_header #endif -#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#if _LIBCPP_STD_VER > 17 _LIBCPP_BEGIN_NAMESPACE_STD @@ -35,7 +35,7 @@ namespace __find { struct __fn { template _Sp, class _Tp, class _Proj = identity> requires indirect_binary_predicate, const _Tp*> - _LIBCPP_HIDE_FROM_ABI constexpr + _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr _Ip operator()(_Ip __first, _Sp __last, const _Tp& __value, _Proj __proj = {}) const { auto __pred = [&](auto&& __e) { return std::forward(__e) == __value; }; return ranges::__find_if_impl(std::move(__first), std::move(__last), __pred, __proj); @@ -43,7 +43,7 @@ struct __fn { template requires indirect_binary_predicate, _Proj>, const _Tp*> - _LIBCPP_HIDE_FROM_ABI constexpr + _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr borrowed_iterator_t<_Rp> operator()(_Rp&& __r, const _Tp& __value, _Proj __proj = {}) const { auto __pred = [&](auto&& __e) { return std::forward(__e) == __value; }; return ranges::__find_if_impl(ranges::begin(__r), ranges::end(__r), __pred, __proj); @@ -58,6 +58,6 @@ inline namespace __cpo { _LIBCPP_END_NAMESPACE_STD -#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#endif // _LIBCPP_STD_VER > 17 #endif // _LIBCPP___ALGORITHM_RANGES_FIND_H diff --git a/lib/libcxx/include/__algorithm/ranges_find_end.h b/lib/libcxx/include/__algorithm/ranges_find_end.h index 270b006498..ea36f4d4e6 100644 --- a/lib/libcxx/include/__algorithm/ranges_find_end.h +++ b/lib/libcxx/include/__algorithm/ranges_find_end.h @@ -21,12 +21,13 @@ #include <__ranges/access.h> #include <__ranges/concepts.h> #include <__ranges/subrange.h> +#include <__utility/pair.h> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header #endif -#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#if _LIBCPP_STD_VER > 17 _LIBCPP_BEGIN_NAMESPACE_STD @@ -39,7 +40,7 @@ struct __fn { class _Proj1 = identity, class _Proj2 = identity> requires indirectly_comparable<_Iter1, _Iter2, _Pred, _Proj1, _Proj2> - _LIBCPP_HIDE_FROM_ABI constexpr + _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr subrange<_Iter1> operator()(_Iter1 __first1, _Sent1 __last1, _Iter2 __first2, _Sent2 __last2, _Pred __pred = {}, @@ -64,7 +65,7 @@ struct __fn { class _Proj1 = identity, class _Proj2 = identity> requires indirectly_comparable, iterator_t<_Range2>, _Pred, _Proj1, _Proj2> - _LIBCPP_HIDE_FROM_ABI constexpr + _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr borrowed_subrange_t<_Range1> operator()(_Range1&& __range1, _Range2&& __range2, _Pred __pred = {}, @@ -92,6 +93,6 @@ inline namespace __cpo { _LIBCPP_END_NAMESPACE_STD -#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#endif // _LIBCPP_STD_VER > 17 #endif // _LIBCPP___ALGORITHM_RANGES_FIND_END_H diff --git a/lib/libcxx/include/__algorithm/ranges_find_first_of.h b/lib/libcxx/include/__algorithm/ranges_find_first_of.h index ae31d38e6a..9d66e7511c 100644 --- a/lib/libcxx/include/__algorithm/ranges_find_first_of.h +++ b/lib/libcxx/include/__algorithm/ranges_find_first_of.h @@ -24,7 +24,7 @@ # pragma GCC system_header #endif -#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#if _LIBCPP_STD_VER > 17 _LIBCPP_BEGIN_NAMESPACE_STD @@ -54,7 +54,7 @@ struct __fn { class _Proj1 = identity, class _Proj2 = identity> requires indirectly_comparable<_Iter1, _Iter2, _Pred, _Proj1, _Proj2> - _LIBCPP_HIDE_FROM_ABI constexpr + _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr _Iter1 operator()(_Iter1 __first1, _Sent1 __last1, _Iter2 __first2, _Sent2 __last2, _Pred __pred = {}, @@ -73,7 +73,7 @@ struct __fn { class _Proj1 = identity, class _Proj2 = identity> requires indirectly_comparable, iterator_t<_Range2>, _Pred, _Proj1, _Proj2> - _LIBCPP_HIDE_FROM_ABI constexpr + _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr borrowed_iterator_t<_Range1> operator()(_Range1&& __range1, _Range2&& __range2, _Pred __pred = {}, @@ -96,6 +96,6 @@ inline namespace __cpo { _LIBCPP_END_NAMESPACE_STD -#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#endif // _LIBCPP_STD_VER > 17 #endif // _LIBCPP___ALGORITHM_RANGES_FIND_FIRST_OF_H diff --git a/lib/libcxx/include/__algorithm/ranges_find_if.h b/lib/libcxx/include/__algorithm/ranges_find_if.h index 65ac122f66..45ce6e460d 100644 --- a/lib/libcxx/include/__algorithm/ranges_find_if.h +++ b/lib/libcxx/include/__algorithm/ranges_find_if.h @@ -24,7 +24,7 @@ # pragma GCC system_header #endif -#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#if _LIBCPP_STD_VER > 17 _LIBCPP_BEGIN_NAMESPACE_STD @@ -45,14 +45,14 @@ struct __fn { template _Sp, class _Proj = identity, indirect_unary_predicate> _Pred> - _LIBCPP_HIDE_FROM_ABI constexpr + _LIBCPP_NODISCARD_EXT _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); } template , _Proj>> _Pred> - _LIBCPP_HIDE_FROM_ABI constexpr + _LIBCPP_NODISCARD_EXT _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); } @@ -66,6 +66,6 @@ inline namespace __cpo { _LIBCPP_END_NAMESPACE_STD -#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#endif // _LIBCPP_STD_VER > 17 #endif // _LIBCPP___ALGORITHM_RANGES_FIND_IF_H diff --git a/lib/libcxx/include/__algorithm/ranges_find_if_not.h b/lib/libcxx/include/__algorithm/ranges_find_if_not.h index 9a1adf71fc..3dd1213275 100644 --- a/lib/libcxx/include/__algorithm/ranges_find_if_not.h +++ b/lib/libcxx/include/__algorithm/ranges_find_if_not.h @@ -26,7 +26,7 @@ # pragma GCC system_header #endif -#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#if _LIBCPP_STD_VER > 17 _LIBCPP_BEGIN_NAMESPACE_STD @@ -35,7 +35,7 @@ namespace __find_if_not { struct __fn { template _Sp, class _Proj = identity, indirect_unary_predicate> _Pred> - _LIBCPP_HIDE_FROM_ABI constexpr + _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr _Ip operator()(_Ip __first, _Sp __last, _Pred __pred, _Proj __proj = {}) const { auto __pred2 = [&](auto&& __e) { return !std::invoke(__pred, std::forward(__e)); }; return ranges::__find_if_impl(std::move(__first), std::move(__last), __pred2, __proj); @@ -43,7 +43,7 @@ struct __fn { template , _Proj>> _Pred> - _LIBCPP_HIDE_FROM_ABI constexpr + _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr borrowed_iterator_t<_Rp> operator()(_Rp&& __r, _Pred __pred, _Proj __proj = {}) const { auto __pred2 = [&](auto&& __e) { return !std::invoke(__pred, std::forward(__e)); }; return ranges::__find_if_impl(ranges::begin(__r), ranges::end(__r), __pred2, __proj); @@ -58,6 +58,6 @@ inline namespace __cpo { _LIBCPP_END_NAMESPACE_STD -#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#endif // _LIBCPP_STD_VER > 17 #endif // _LIBCPP___ALGORITHM_RANGES_FIND_IF_NOT_H diff --git a/lib/libcxx/include/__algorithm/ranges_for_each.h b/lib/libcxx/include/__algorithm/ranges_for_each.h index f284c0ee3a..0c70c05981 100644 --- a/lib/libcxx/include/__algorithm/ranges_for_each.h +++ b/lib/libcxx/include/__algorithm/ranges_for_each.h @@ -24,7 +24,7 @@ # pragma GCC system_header #endif -#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#if _LIBCPP_STD_VER > 17 _LIBCPP_BEGIN_NAMESPACE_STD @@ -73,6 +73,6 @@ inline namespace __cpo { _LIBCPP_END_NAMESPACE_STD -#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#endif // _LIBCPP_STD_VER > 17 #endif // _LIBCPP___ALGORITHM_RANGES_FOR_EACH_H diff --git a/lib/libcxx/include/__algorithm/ranges_for_each_n.h b/lib/libcxx/include/__algorithm/ranges_for_each_n.h index 013afbd193..261816aba4 100644 --- a/lib/libcxx/include/__algorithm/ranges_for_each_n.h +++ b/lib/libcxx/include/__algorithm/ranges_for_each_n.h @@ -24,7 +24,7 @@ # pragma GCC system_header #endif -#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#if _LIBCPP_STD_VER > 17 _LIBCPP_BEGIN_NAMESPACE_STD @@ -61,6 +61,6 @@ inline namespace __cpo { _LIBCPP_END_NAMESPACE_STD -#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#endif // _LIBCPP_STD_VER > 17 #endif // _LIBCPP___ALGORITHM_RANGES_FOR_EACH_N_H diff --git a/lib/libcxx/include/__algorithm/ranges_generate.h b/lib/libcxx/include/__algorithm/ranges_generate.h index 149296574d..ae486ae653 100644 --- a/lib/libcxx/include/__algorithm/ranges_generate.h +++ b/lib/libcxx/include/__algorithm/ranges_generate.h @@ -24,7 +24,7 @@ # pragma GCC system_header #endif -#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#if _LIBCPP_STD_VER > 17 _LIBCPP_BEGIN_NAMESPACE_STD @@ -68,6 +68,6 @@ inline namespace __cpo { _LIBCPP_END_NAMESPACE_STD -#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#endif // _LIBCPP_STD_VER > 17 #endif // _LIBCPP___ALGORITHM_RANGES_GENERATE_H diff --git a/lib/libcxx/include/__algorithm/ranges_generate_n.h b/lib/libcxx/include/__algorithm/ranges_generate_n.h index 63f466cecd..e625e3a974 100644 --- a/lib/libcxx/include/__algorithm/ranges_generate_n.h +++ b/lib/libcxx/include/__algorithm/ranges_generate_n.h @@ -25,7 +25,7 @@ # pragma GCC system_header #endif -#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#if _LIBCPP_STD_VER > 17 _LIBCPP_BEGIN_NAMESPACE_STD @@ -57,6 +57,6 @@ inline namespace __cpo { _LIBCPP_END_NAMESPACE_STD -#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#endif // _LIBCPP_STD_VER > 17 #endif // _LIBCPP___ALGORITHM_RANGES_GENERATE_N_H diff --git a/lib/libcxx/include/__algorithm/ranges_includes.h b/lib/libcxx/include/__algorithm/ranges_includes.h index 2c7581af68..8438117cfa 100644 --- a/lib/libcxx/include/__algorithm/ranges_includes.h +++ b/lib/libcxx/include/__algorithm/ranges_includes.h @@ -27,7 +27,7 @@ # pragma GCC system_header #endif -#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#if _LIBCPP_STD_VER > 17 _LIBCPP_BEGIN_NAMESPACE_STD @@ -43,7 +43,7 @@ struct __fn { class _Proj1 = identity, class _Proj2 = identity, indirect_strict_weak_order, projected<_Iter2, _Proj2>> _Comp = ranges::less> - _LIBCPP_HIDE_FROM_ABI constexpr bool operator()( + _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr bool operator()( _Iter1 __first1, _Sent1 __last1, _Iter2 __first2, @@ -68,7 +68,7 @@ struct __fn { class _Proj2 = identity, indirect_strict_weak_order, _Proj1>, projected, _Proj2>> _Comp = ranges::less> - _LIBCPP_HIDE_FROM_ABI constexpr bool operator()( + _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr bool operator()( _Range1&& __range1, _Range2&& __range2, _Comp __comp = {}, _Proj1 __proj1 = {}, _Proj2 __proj2 = {}) const { return std::__includes( ranges::begin(__range1), @@ -90,6 +90,6 @@ inline namespace __cpo { _LIBCPP_END_NAMESPACE_STD -#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#endif // _LIBCPP_STD_VER > 17 #endif // _LIBCPP___ALGORITHM_RANGES_INCLUDES_H diff --git a/lib/libcxx/include/__algorithm/ranges_inplace_merge.h b/lib/libcxx/include/__algorithm/ranges_inplace_merge.h index 12c90908c2..88171a65c8 100644 --- a/lib/libcxx/include/__algorithm/ranges_inplace_merge.h +++ b/lib/libcxx/include/__algorithm/ranges_inplace_merge.h @@ -31,7 +31,7 @@ # pragma GCC system_header #endif -#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#if _LIBCPP_STD_VER > 17 _LIBCPP_BEGIN_NAMESPACE_STD @@ -80,6 +80,6 @@ inline namespace __cpo { _LIBCPP_END_NAMESPACE_STD -#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#endif // _LIBCPP_STD_VER > 17 #endif // _LIBCPP___ALGORITHM_RANGES_INPLACE_MERGE_H diff --git a/lib/libcxx/include/__algorithm/ranges_is_heap.h b/lib/libcxx/include/__algorithm/ranges_is_heap.h index 0bb1dcda0e..a16c075b07 100644 --- a/lib/libcxx/include/__algorithm/ranges_is_heap.h +++ b/lib/libcxx/include/__algorithm/ranges_is_heap.h @@ -26,7 +26,7 @@ # pragma GCC system_header #endif -#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#if _LIBCPP_STD_VER > 17 _LIBCPP_BEGIN_NAMESPACE_STD @@ -47,14 +47,14 @@ struct __fn { template _Sent, class _Proj = identity, indirect_strict_weak_order> _Comp = ranges::less> - _LIBCPP_HIDE_FROM_ABI constexpr + _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr bool operator()(_Iter __first, _Sent __last, _Comp __comp = {}, _Proj __proj = {}) const { return __is_heap_fn_impl(std::move(__first), std::move(__last), __comp, __proj); } template , _Proj>> _Comp = ranges::less> - _LIBCPP_HIDE_FROM_ABI constexpr + _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr bool operator()(_Range&& __range, _Comp __comp = {}, _Proj __proj = {}) const { return __is_heap_fn_impl(ranges::begin(__range), ranges::end(__range), __comp, __proj); } @@ -69,6 +69,6 @@ inline namespace __cpo { _LIBCPP_END_NAMESPACE_STD -#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#endif // _LIBCPP_STD_VER > 17 #endif // _LIBCPP___ALGORITHM_RANGES_IS_HEAP_H diff --git a/lib/libcxx/include/__algorithm/ranges_is_heap_until.h b/lib/libcxx/include/__algorithm/ranges_is_heap_until.h index 8a751fcc51..8c8dac5bc9 100644 --- a/lib/libcxx/include/__algorithm/ranges_is_heap_until.h +++ b/lib/libcxx/include/__algorithm/ranges_is_heap_until.h @@ -27,7 +27,7 @@ # pragma GCC system_header #endif -#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#if _LIBCPP_STD_VER > 17 _LIBCPP_BEGIN_NAMESPACE_STD @@ -47,14 +47,14 @@ struct __fn { template _Sent, class _Proj = identity, indirect_strict_weak_order> _Comp = ranges::less> - _LIBCPP_HIDE_FROM_ABI constexpr + _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr _Iter operator()(_Iter __first, _Sent __last, _Comp __comp = {}, _Proj __proj = {}) const { return __is_heap_until_fn_impl(std::move(__first), std::move(__last), __comp, __proj); } template , _Proj>> _Comp = ranges::less> - _LIBCPP_HIDE_FROM_ABI constexpr + _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr borrowed_iterator_t<_Range> operator()(_Range&& __range, _Comp __comp = {}, _Proj __proj = {}) const { return __is_heap_until_fn_impl(ranges::begin(__range), ranges::end(__range), __comp, __proj); } @@ -70,6 +70,6 @@ inline namespace __cpo { _LIBCPP_END_NAMESPACE_STD -#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#endif // _LIBCPP_STD_VER > 17 #endif // _LIBCPP___ALGORITHM_RANGES_IS_HEAP_UNTIL_H diff --git a/lib/libcxx/include/__algorithm/ranges_is_partitioned.h b/lib/libcxx/include/__algorithm/ranges_is_partitioned.h index 3d572895eb..b903953d61 100644 --- a/lib/libcxx/include/__algorithm/ranges_is_partitioned.h +++ b/lib/libcxx/include/__algorithm/ranges_is_partitioned.h @@ -23,7 +23,7 @@ # pragma GCC system_header #endif -#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#if _LIBCPP_STD_VER > 17 _LIBCPP_BEGIN_NAMESPACE_STD @@ -54,7 +54,7 @@ struct __fn { template _Sent, class _Proj = identity, indirect_unary_predicate> _Pred> - _LIBCPP_HIDE_FROM_ABI constexpr + _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr bool operator()(_Iter __first, _Sent __last, _Pred __pred, _Proj __proj = {}) const { return __is_parititioned_impl(std::move(__first), std::move(__last), __pred, __proj); } @@ -62,7 +62,7 @@ struct __fn { template , _Proj>> _Pred> - _LIBCPP_HIDE_FROM_ABI constexpr + _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr bool operator()(_Range&& __range, _Pred __pred, _Proj __proj = {}) const { return __is_parititioned_impl(ranges::begin(__range), ranges::end(__range), __pred, __proj); } @@ -76,6 +76,6 @@ inline namespace __cpo { _LIBCPP_END_NAMESPACE_STD -#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#endif // _LIBCPP_STD_VER > 17 #endif // _LIBCPP___ALGORITHM_RANGES_IS_PARTITIONED_H diff --git a/lib/libcxx/include/__algorithm/ranges_is_permutation.h b/lib/libcxx/include/__algorithm/ranges_is_permutation.h index 41e302fe99..b617500ea0 100644 --- a/lib/libcxx/include/__algorithm/ranges_is_permutation.h +++ b/lib/libcxx/include/__algorithm/ranges_is_permutation.h @@ -25,7 +25,7 @@ # pragma GCC system_header #endif -#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#if _LIBCPP_STD_VER > 17 _LIBCPP_BEGIN_NAMESPACE_STD @@ -49,7 +49,7 @@ struct __fn { class _Proj2 = identity, indirect_equivalence_relation, projected<_Iter2, _Proj2>> _Pred = ranges::equal_to> - _LIBCPP_HIDE_FROM_ABI constexpr + _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr bool operator()(_Iter1 __first1, _Sent1 __last1, _Iter2 __first2, _Sent2 __last2, _Pred __pred = {}, _Proj1 __proj1 = {}, _Proj2 __proj2 = {}) const { return __is_permutation_func_impl( @@ -62,7 +62,7 @@ struct __fn { class _Proj1 = identity, class _Proj2 = identity, indirect_equivalence_relation, _Proj1>, projected, _Proj2>> _Pred = ranges::equal_to> - _LIBCPP_HIDE_FROM_ABI constexpr + _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr bool operator()(_Range1&& __range1, _Range2&& __range2, _Pred __pred = {}, _Proj1 __proj1 = {}, _Proj2 __proj2 = {}) const { if constexpr (sized_range<_Range1> && sized_range<_Range2>) { @@ -84,6 +84,6 @@ inline namespace __cpo { _LIBCPP_END_NAMESPACE_STD -#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#endif // _LIBCPP_STD_VER > 17 #endif // _LIBCPP___ALGORITHM_RANGES_IS_PERMUTATION_H diff --git a/lib/libcxx/include/__algorithm/ranges_is_sorted.h b/lib/libcxx/include/__algorithm/ranges_is_sorted.h index 938e69afba..ce3032ff22 100644 --- a/lib/libcxx/include/__algorithm/ranges_is_sorted.h +++ b/lib/libcxx/include/__algorithm/ranges_is_sorted.h @@ -23,7 +23,7 @@ # pragma GCC system_header #endif -#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#if _LIBCPP_STD_VER > 17 _LIBCPP_BEGIN_NAMESPACE_STD @@ -33,7 +33,7 @@ struct __fn { template _Sent, class _Proj = identity, indirect_strict_weak_order> _Comp = ranges::less> - _LIBCPP_HIDE_FROM_ABI constexpr + _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr bool operator()(_Iter __first, _Sent __last, _Comp __comp = {}, _Proj __proj = {}) const { return ranges::__is_sorted_until_impl(std::move(__first), __last, __comp, __proj) == __last; } @@ -41,7 +41,7 @@ struct __fn { template , _Proj>> _Comp = ranges::less> - _LIBCPP_HIDE_FROM_ABI constexpr + _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr bool operator()(_Range&& __range, _Comp __comp = {}, _Proj __proj = {}) const { auto __last = ranges::end(__range); return ranges::__is_sorted_until_impl(ranges::begin(__range), __last, __comp, __proj) == __last; @@ -56,6 +56,6 @@ inline namespace __cpo { _LIBCPP_END_NAMESPACE_STD -#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#endif // _LIBCPP_STD_VER > 17 #endif // _LIBCPP__ALGORITHM_RANGES_IS_SORTED_H diff --git a/lib/libcxx/include/__algorithm/ranges_is_sorted_until.h b/lib/libcxx/include/__algorithm/ranges_is_sorted_until.h index c8f0608e12..17fc42e97f 100644 --- a/lib/libcxx/include/__algorithm/ranges_is_sorted_until.h +++ b/lib/libcxx/include/__algorithm/ranges_is_sorted_until.h @@ -24,7 +24,7 @@ # pragma GCC system_header #endif -#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#if _LIBCPP_STD_VER > 17 _LIBCPP_BEGIN_NAMESPACE_STD @@ -49,7 +49,7 @@ struct __fn { template _Sent, class _Proj = identity, indirect_strict_weak_order> _Comp = ranges::less> - _LIBCPP_HIDE_FROM_ABI constexpr + _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr _Iter operator()(_Iter __first, _Sent __last, _Comp __comp = {}, _Proj __proj = {}) const { return ranges::__is_sorted_until_impl(std::move(__first), std::move(__last), __comp, __proj); } @@ -57,7 +57,7 @@ struct __fn { template , _Proj>> _Comp = ranges::less> - _LIBCPP_HIDE_FROM_ABI constexpr + _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr borrowed_iterator_t<_Range> operator()(_Range&& __range, _Comp __comp = {}, _Proj __proj = {}) const { return ranges::__is_sorted_until_impl(ranges::begin(__range), ranges::end(__range), __comp, __proj); } @@ -71,6 +71,6 @@ inline namespace __cpo { _LIBCPP_END_NAMESPACE_STD -#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#endif // _LIBCPP_STD_VER > 17 #endif // _LIBCPP__ALGORITHM_RANGES_IS_SORTED_UNTIL_H diff --git a/lib/libcxx/include/__algorithm/ranges_iterator_concept.h b/lib/libcxx/include/__algorithm/ranges_iterator_concept.h index 3323119317..3ac6b31703 100644 --- a/lib/libcxx/include/__algorithm/ranges_iterator_concept.h +++ b/lib/libcxx/include/__algorithm/ranges_iterator_concept.h @@ -12,13 +12,13 @@ #include <__config> #include <__iterator/concepts.h> #include <__iterator/iterator_traits.h> -#include +#include <__type_traits/remove_cvref.h> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header #endif -#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#if _LIBCPP_STD_VER > 17 _LIBCPP_BEGIN_NAMESPACE_STD @@ -26,7 +26,7 @@ namespace ranges { template consteval auto __get_iterator_concept() { - using _Iter = __uncvref_t<_IterMaybeQualified>; + using _Iter = __remove_cvref_t<_IterMaybeQualified>; if constexpr (contiguous_iterator<_Iter>) return contiguous_iterator_tag(); @@ -46,6 +46,6 @@ using __iterator_concept = decltype(__get_iterator_concept<_Iter>()); } // namespace ranges _LIBCPP_END_NAMESPACE_STD -#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#endif // _LIBCPP_STD_VER > 17 #endif // _LIBCPP___ALGORITHM_RANGES_ITERATOR_CONCEPT_H diff --git a/lib/libcxx/include/__algorithm/ranges_lexicographical_compare.h b/lib/libcxx/include/__algorithm/ranges_lexicographical_compare.h index fe709f7a7f..2972e32716 100644 --- a/lib/libcxx/include/__algorithm/ranges_lexicographical_compare.h +++ b/lib/libcxx/include/__algorithm/ranges_lexicographical_compare.h @@ -23,7 +23,7 @@ # pragma GCC system_header #endif -#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#if _LIBCPP_STD_VER > 17 _LIBCPP_BEGIN_NAMESPACE_STD @@ -55,7 +55,7 @@ struct __fn { class _Proj1 = identity, class _Proj2 = identity, indirect_strict_weak_order, projected<_Iter2, _Proj2>> _Comp = ranges::less> - _LIBCPP_HIDE_FROM_ABI constexpr + _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr bool operator()(_Iter1 __first1, _Sent1 __last1, _Iter2 __first2, _Sent2 __last2, _Comp __comp = {}, @@ -74,7 +74,7 @@ struct __fn { class _Proj2 = identity, indirect_strict_weak_order, _Proj1>, projected, _Proj2>> _Comp = ranges::less> - _LIBCPP_HIDE_FROM_ABI constexpr + _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr bool operator()(_Range1&& __range1, _Range2&& __range2, _Comp __comp = {}, _Proj1 __proj1 = {}, _Proj2 __proj2 = {}) const { return __lexicographical_compare_impl(ranges::begin(__range1), ranges::end(__range1), ranges::begin(__range2), ranges::end(__range2), @@ -93,6 +93,6 @@ inline namespace __cpo { _LIBCPP_END_NAMESPACE_STD -#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#endif // _LIBCPP_STD_VER > 17 #endif // _LIBCPP___ALGORITHM_RANGES_LEXICOGRAPHICAL_COMPARE_H diff --git a/lib/libcxx/include/__algorithm/ranges_lower_bound.h b/lib/libcxx/include/__algorithm/ranges_lower_bound.h index 1a9ae204a1..78cbb6d4fb 100644 --- a/lib/libcxx/include/__algorithm/ranges_lower_bound.h +++ b/lib/libcxx/include/__algorithm/ranges_lower_bound.h @@ -27,7 +27,7 @@ # pragma GCC system_header #endif -#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#if _LIBCPP_STD_VER > 17 _LIBCPP_BEGIN_NAMESPACE_STD @@ -37,14 +37,14 @@ namespace __lower_bound { struct __fn { template _Sent, class _Type, class _Proj = identity, indirect_strict_weak_order> _Comp = ranges::less> - _LIBCPP_HIDE_FROM_ABI constexpr + _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr _Iter operator()(_Iter __first, _Sent __last, const _Type& __value, _Comp __comp = {}, _Proj __proj = {}) const { return std::__lower_bound_impl<_RangeAlgPolicy>(__first, __last, __value, __comp, __proj); } template , _Proj>> _Comp = ranges::less> - _LIBCPP_HIDE_FROM_ABI constexpr + _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr borrowed_iterator_t<_Range> operator()(_Range&& __r, const _Type& __value, _Comp __comp = {}, @@ -61,6 +61,6 @@ inline namespace __cpo { _LIBCPP_END_NAMESPACE_STD -#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#endif // _LIBCPP_STD_VER > 17 #endif // _LIBCPP___ALGORITHM_RANGES_LOWER_BOUND_H diff --git a/lib/libcxx/include/__algorithm/ranges_make_heap.h b/lib/libcxx/include/__algorithm/ranges_make_heap.h index b114286a85..f25c7ab588 100644 --- a/lib/libcxx/include/__algorithm/ranges_make_heap.h +++ b/lib/libcxx/include/__algorithm/ranges_make_heap.h @@ -32,7 +32,7 @@ # pragma GCC system_header #endif -#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#if _LIBCPP_STD_VER > 17 _LIBCPP_BEGIN_NAMESPACE_STD @@ -75,6 +75,6 @@ inline namespace __cpo { _LIBCPP_END_NAMESPACE_STD -#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#endif // _LIBCPP_STD_VER > 17 #endif // _LIBCPP___ALGORITHM_RANGES_MAKE_HEAP_H diff --git a/lib/libcxx/include/__algorithm/ranges_max.h b/lib/libcxx/include/__algorithm/ranges_max.h index f48bc3ecec..55aef99769 100644 --- a/lib/libcxx/include/__algorithm/ranges_max.h +++ b/lib/libcxx/include/__algorithm/ranges_max.h @@ -27,7 +27,7 @@ # pragma GCC system_header #endif -#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#if _LIBCPP_STD_VER > 17 _LIBCPP_PUSH_MACROS #include <__undef_macros> @@ -39,14 +39,14 @@ namespace __max { struct __fn { template > _Comp = ranges::less> - _LIBCPP_HIDE_FROM_ABI constexpr + _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr const _Tp& operator()(const _Tp& __a, const _Tp& __b, _Comp __comp = {}, _Proj __proj = {}) const { return std::invoke(__comp, std::invoke(__proj, __a), std::invoke(__proj, __b)) ? __b : __a; } template > _Comp = ranges::less> - _LIBCPP_HIDE_FROM_ABI constexpr + _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr _Tp operator()(initializer_list<_Tp> __il, _Comp __comp = {}, _Proj __proj = {}) const { _LIBCPP_ASSERT(__il.begin() != __il.end(), "initializer_list must contain at least one element"); @@ -57,7 +57,7 @@ struct __fn { template , _Proj>> _Comp = ranges::less> requires indirectly_copyable_storable, range_value_t<_Rp>*> - _LIBCPP_HIDE_FROM_ABI constexpr + _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr range_value_t<_Rp> operator()(_Rp&& __r, _Comp __comp = {}, _Proj __proj = {}) const { auto __first = ranges::begin(__r); auto __last = ranges::end(__r); @@ -88,6 +88,6 @@ _LIBCPP_END_NAMESPACE_STD _LIBCPP_POP_MACROS -#endif // _LIBCPP_STD_VER > 17 && && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#endif // _LIBCPP_STD_VER > 17 && #endif // _LIBCPP___ALGORITHM_RANGES_MAX_H diff --git a/lib/libcxx/include/__algorithm/ranges_max_element.h b/lib/libcxx/include/__algorithm/ranges_max_element.h index d8d7242e17..490f32075a 100644 --- a/lib/libcxx/include/__algorithm/ranges_max_element.h +++ b/lib/libcxx/include/__algorithm/ranges_max_element.h @@ -24,7 +24,7 @@ # pragma GCC system_header #endif -#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#if _LIBCPP_STD_VER > 17 _LIBCPP_BEGIN_NAMESPACE_STD @@ -33,7 +33,7 @@ namespace __max_element { struct __fn { template _Sp, class _Proj = identity, indirect_strict_weak_order> _Comp = ranges::less> - _LIBCPP_HIDE_FROM_ABI constexpr + _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr _Ip operator()(_Ip __first, _Sp __last, _Comp __comp = {}, _Proj __proj = {}) const { auto __comp_lhs_rhs_swapped = [&](auto&& __lhs, auto&& __rhs) { return std::invoke(__comp, __rhs, __lhs); }; return ranges::__min_element_impl(__first, __last, __comp_lhs_rhs_swapped, __proj); @@ -41,7 +41,7 @@ struct __fn { template , _Proj>> _Comp = ranges::less> - _LIBCPP_HIDE_FROM_ABI constexpr + _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr borrowed_iterator_t<_Rp> operator()(_Rp&& __r, _Comp __comp = {}, _Proj __proj = {}) const { auto __comp_lhs_rhs_swapped = [&](auto&& __lhs, auto&& __rhs) { return std::invoke(__comp, __rhs, __lhs); }; return ranges::__min_element_impl(ranges::begin(__r), ranges::end(__r), __comp_lhs_rhs_swapped, __proj); @@ -56,6 +56,6 @@ inline namespace __cpo { _LIBCPP_END_NAMESPACE_STD -#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#endif // _LIBCPP_STD_VER > 17 #endif // _LIBCPP___ALGORITHM_RANGES_MAX_ELEMENT_H diff --git a/lib/libcxx/include/__algorithm/ranges_merge.h b/lib/libcxx/include/__algorithm/ranges_merge.h index c73e09e94c..b36a05abc4 100644 --- a/lib/libcxx/include/__algorithm/ranges_merge.h +++ b/lib/libcxx/include/__algorithm/ranges_merge.h @@ -27,7 +27,7 @@ # pragma GCC system_header #endif -#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#if _LIBCPP_STD_VER > 17 _LIBCPP_BEGIN_NAMESPACE_STD @@ -47,7 +47,7 @@ template < class _Comp, class _Proj1, class _Proj2> -_LIBCPP_HIDE_FROM_ABI constexpr merge_result<__uncvref_t<_InIter1>, __uncvref_t<_InIter2>, __uncvref_t<_OutIter>> +_LIBCPP_HIDE_FROM_ABI constexpr merge_result<__remove_cvref_t<_InIter1>, __remove_cvref_t<_InIter2>, __remove_cvref_t<_OutIter>> __merge_impl( _InIter1&& __first1, _Sent1&& __last1, @@ -107,7 +107,7 @@ struct __fn { _OutIter, _Comp, _Proj1, - _Proj2> + _Proj2> _LIBCPP_HIDE_FROM_ABI constexpr merge_result, borrowed_iterator_t<_Range2>, _OutIter> operator()( _Range1&& __range1, @@ -137,6 +137,6 @@ inline namespace __cpo { _LIBCPP_END_NAMESPACE_STD -#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#endif // _LIBCPP_STD_VER > 17 #endif // _LIBCPP___ALGORITHM_RANGES_MERGE_H diff --git a/lib/libcxx/include/__algorithm/ranges_min.h b/lib/libcxx/include/__algorithm/ranges_min.h index 0bb1e72ac5..0e31f57fb8 100644 --- a/lib/libcxx/include/__algorithm/ranges_min.h +++ b/lib/libcxx/include/__algorithm/ranges_min.h @@ -26,7 +26,7 @@ # pragma GCC system_header #endif -#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#if _LIBCPP_STD_VER > 17 _LIBCPP_PUSH_MACROS #include <__undef_macros> @@ -38,14 +38,14 @@ namespace __min { struct __fn { template > _Comp = ranges::less> - _LIBCPP_HIDE_FROM_ABI constexpr + _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr const _Tp& operator()(const _Tp& __a, const _Tp& __b, _Comp __comp = {}, _Proj __proj = {}) const { return std::invoke(__comp, std::invoke(__proj, __b), std::invoke(__proj, __a)) ? __b : __a; } template > _Comp = ranges::less> - _LIBCPP_HIDE_FROM_ABI constexpr + _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr _Tp operator()(initializer_list<_Tp> __il, _Comp __comp = {}, _Proj __proj = {}) const { _LIBCPP_ASSERT(__il.begin() != __il.end(), "initializer_list must contain at least one element"); return *ranges::__min_element_impl(__il.begin(), __il.end(), __comp, __proj); @@ -54,7 +54,7 @@ struct __fn { template , _Proj>> _Comp = ranges::less> requires indirectly_copyable_storable, range_value_t<_Rp>*> - _LIBCPP_HIDE_FROM_ABI constexpr + _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr range_value_t<_Rp> operator()(_Rp&& __r, _Comp __comp = {}, _Proj __proj = {}) const { auto __first = ranges::begin(__r); auto __last = ranges::end(__r); @@ -84,6 +84,6 @@ _LIBCPP_END_NAMESPACE_STD _LIBCPP_POP_MACROS -#endif // _LIBCPP_STD_VER > 17 && && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#endif // _LIBCPP_STD_VER > 17 && #endif // _LIBCPP___ALGORITHM_RANGES_MIN_H diff --git a/lib/libcxx/include/__algorithm/ranges_min_element.h b/lib/libcxx/include/__algorithm/ranges_min_element.h index 26f95fe3a6..1751874d03 100644 --- a/lib/libcxx/include/__algorithm/ranges_min_element.h +++ b/lib/libcxx/include/__algorithm/ranges_min_element.h @@ -24,7 +24,7 @@ # pragma GCC system_header #endif -#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#if _LIBCPP_STD_VER > 17 _LIBCPP_BEGIN_NAMESPACE_STD @@ -48,14 +48,14 @@ namespace __min_element { struct __fn { template _Sp, class _Proj = identity, indirect_strict_weak_order> _Comp = ranges::less> - _LIBCPP_HIDE_FROM_ABI constexpr + _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr _Ip operator()(_Ip __first, _Sp __last, _Comp __comp = {}, _Proj __proj = {}) const { return ranges::__min_element_impl(__first, __last, __comp, __proj); } template , _Proj>> _Comp = ranges::less> - _LIBCPP_HIDE_FROM_ABI constexpr + _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr borrowed_iterator_t<_Rp> operator()(_Rp&& __r, _Comp __comp = {}, _Proj __proj = {}) const { return ranges::__min_element_impl(ranges::begin(__r), ranges::end(__r), __comp, __proj); } @@ -69,6 +69,6 @@ inline namespace __cpo { _LIBCPP_END_NAMESPACE_STD -#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#endif // _LIBCPP_STD_VER > 17 #endif // _LIBCPP___ALGORITHM_RANGES_MIN_ELEMENT_H diff --git a/lib/libcxx/include/__algorithm/ranges_minmax.h b/lib/libcxx/include/__algorithm/ranges_minmax.h index 2f4bba0e7c..f82e00551e 100644 --- a/lib/libcxx/include/__algorithm/ranges_minmax.h +++ b/lib/libcxx/include/__algorithm/ranges_minmax.h @@ -23,13 +23,14 @@ #include <__ranges/concepts.h> #include <__utility/forward.h> #include <__utility/move.h> +#include <__utility/pair.h> #include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header #endif -#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#if _LIBCPP_STD_VER > 17 _LIBCPP_PUSH_MACROS #include <__undef_macros> @@ -44,7 +45,7 @@ namespace __minmax { struct __fn { template > _Comp = ranges::less> - _LIBCPP_HIDE_FROM_ABI constexpr ranges::minmax_result + _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr ranges::minmax_result operator()(const _Type& __a, const _Type& __b, _Comp __comp = {}, _Proj __proj = {}) const { if (std::invoke(__comp, std::invoke(__proj, __b), std::invoke(__proj, __a))) return {__b, __a}; @@ -53,7 +54,7 @@ struct __fn { template > _Comp = ranges::less> - _LIBCPP_HIDE_FROM_ABI constexpr + _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr ranges::minmax_result<_Type> operator()(initializer_list<_Type> __il, _Comp __comp = {}, _Proj __proj = {}) const { _LIBCPP_ASSERT(__il.begin() != __il.end(), "initializer_list has to contain at least one element"); auto __iters = std::__minmax_element_impl(__il.begin(), __il.end(), __comp, __proj); @@ -63,7 +64,7 @@ struct __fn { template , _Proj>> _Comp = ranges::less> requires indirectly_copyable_storable, range_value_t<_Range>*> - _LIBCPP_HIDE_FROM_ABI constexpr + _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr ranges::minmax_result> operator()(_Range&& __r, _Comp __comp = {}, _Proj __proj = {}) const { auto __first = ranges::begin(__r); auto __last = ranges::end(__r); @@ -128,6 +129,6 @@ _LIBCPP_END_NAMESPACE_STD _LIBCPP_POP_MACROS -#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#endif // _LIBCPP_STD_VER > 17 #endif // _LIBCPP___ALGORITHM_RANGES_MINMAX_H diff --git a/lib/libcxx/include/__algorithm/ranges_minmax_element.h b/lib/libcxx/include/__algorithm/ranges_minmax_element.h index b7bb26cefe..6699f9626e 100644 --- a/lib/libcxx/include/__algorithm/ranges_minmax_element.h +++ b/lib/libcxx/include/__algorithm/ranges_minmax_element.h @@ -29,7 +29,7 @@ # pragma GCC system_header #endif -#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#if _LIBCPP_STD_VER > 17 _LIBCPP_BEGIN_NAMESPACE_STD @@ -42,7 +42,7 @@ namespace __minmax_element { struct __fn { template _Sp, class _Proj = identity, indirect_strict_weak_order> _Comp = ranges::less> - _LIBCPP_HIDE_FROM_ABI constexpr + _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr ranges::minmax_element_result<_Ip> operator()(_Ip __first, _Sp __last, _Comp __comp = {}, _Proj __proj = {}) const { auto __ret = std::__minmax_element_impl(std::move(__first), std::move(__last), __comp, __proj); return {__ret.first, __ret.second}; @@ -50,7 +50,7 @@ struct __fn { template , _Proj>> _Comp = ranges::less> - _LIBCPP_HIDE_FROM_ABI constexpr + _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr ranges::minmax_element_result> operator()(_Rp&& __r, _Comp __comp = {}, _Proj __proj = {}) const { auto __ret = std::__minmax_element_impl(ranges::begin(__r), ranges::end(__r), __comp, __proj); @@ -67,6 +67,6 @@ inline namespace __cpo { _LIBCPP_END_NAMESPACE_STD -#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#endif // _LIBCPP_STD_VER > 17 #endif // _LIBCPP___ALGORITHM_RANGES_MINMAX_H diff --git a/lib/libcxx/include/__algorithm/ranges_mismatch.h b/lib/libcxx/include/__algorithm/ranges_mismatch.h index 4c1440b5da..4fd0517928 100644 --- a/lib/libcxx/include/__algorithm/ranges_mismatch.h +++ b/lib/libcxx/include/__algorithm/ranges_mismatch.h @@ -27,7 +27,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD -#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#if _LIBCPP_STD_VER > 17 namespace ranges { @@ -55,7 +55,7 @@ struct __fn { input_iterator _I2, sentinel_for<_I2> _S2, class _Pred = ranges::equal_to, class _Proj1 = identity, class _Proj2 = identity> requires indirectly_comparable<_I1, _I2, _Pred, _Proj1, _Proj2> - _LIBCPP_HIDE_FROM_ABI constexpr + _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr mismatch_result<_I1, _I2> operator()(_I1 __first1, _S1 __last1, _I2 __first2, _S2 __last2, _Pred __pred = {}, _Proj1 __proj1 = {}, _Proj2 __proj2 = {}) const { return __go(std::move(__first1), __last1, std::move(__first2), __last2, __pred, __proj1, __proj2); @@ -64,7 +64,7 @@ struct __fn { template requires indirectly_comparable, iterator_t<_R2>, _Pred, _Proj1, _Proj2> - _LIBCPP_HIDE_FROM_ABI constexpr + _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr mismatch_result, borrowed_iterator_t<_R2>> operator()(_R1&& __r1, _R2&& __r2, _Pred __pred = {}, _Proj1 __proj1 = {}, _Proj2 __proj2 = {}) const { return __go(ranges::begin(__r1), ranges::end(__r1), ranges::begin(__r2), ranges::end(__r2), @@ -78,7 +78,7 @@ inline namespace __cpo { } // namespace __cpo } // namespace ranges -#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#endif // _LIBCPP_STD_VER > 17 _LIBCPP_END_NAMESPACE_STD diff --git a/lib/libcxx/include/__algorithm/ranges_move.h b/lib/libcxx/include/__algorithm/ranges_move.h index 9e1d4c72fb..46a0970f83 100644 --- a/lib/libcxx/include/__algorithm/ranges_move.h +++ b/lib/libcxx/include/__algorithm/ranges_move.h @@ -14,7 +14,6 @@ #include <__algorithm/move.h> #include <__config> #include <__iterator/concepts.h> -#include <__iterator/iter_move.h> #include <__ranges/access.h> #include <__ranges/concepts.h> #include <__ranges/dangling.h> @@ -24,7 +23,7 @@ # pragma GCC system_header #endif -#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#if _LIBCPP_STD_VER > 17 _LIBCPP_BEGIN_NAMESPACE_STD @@ -67,6 +66,6 @@ inline namespace __cpo { _LIBCPP_END_NAMESPACE_STD -#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#endif // _LIBCPP_STD_VER > 17 #endif // _LIBCPP___ALGORITHM_RANGES_MOVE_H diff --git a/lib/libcxx/include/__algorithm/ranges_move_backward.h b/lib/libcxx/include/__algorithm/ranges_move_backward.h index 583a6bf29d..d4e8eb1a50 100644 --- a/lib/libcxx/include/__algorithm/ranges_move_backward.h +++ b/lib/libcxx/include/__algorithm/ranges_move_backward.h @@ -10,12 +10,12 @@ #define _LIBCPP___ALGORITHM_RANGES_MOVE_BACKWARD_H #include <__algorithm/in_out_result.h> -#include <__algorithm/ranges_move.h> +#include <__algorithm/iterator_operations.h> +#include <__algorithm/move_backward.h> #include <__config> #include <__iterator/concepts.h> #include <__iterator/iter_move.h> #include <__iterator/next.h> -#include <__iterator/reverse_iterator.h> #include <__ranges/access.h> #include <__ranges/concepts.h> #include <__ranges/dangling.h> @@ -25,7 +25,7 @@ # pragma GCC system_header #endif -#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#if _LIBCPP_STD_VER > 17 _LIBCPP_BEGIN_NAMESPACE_STD @@ -40,11 +40,8 @@ struct __fn { template _LIBCPP_HIDE_FROM_ABI constexpr static move_backward_result<_InIter, _OutIter> __move_backward_impl(_InIter __first, _Sent __last, _OutIter __result) { - auto __last_iter = ranges::next(__first, std::move(__last)); - auto __ret = ranges::move(std::make_reverse_iterator(__last_iter), - std::make_reverse_iterator(__first), - std::make_reverse_iterator(__result)); - return {std::move(__last_iter), std::move(__ret.out.base())}; + 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> @@ -71,6 +68,6 @@ inline namespace __cpo { _LIBCPP_END_NAMESPACE_STD -#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#endif // _LIBCPP_STD_VER > 17 #endif // _LIBCPP___ALGORITHM_RANGES_MOVE_BACKWARD_H diff --git a/lib/libcxx/include/__algorithm/ranges_next_permutation.h b/lib/libcxx/include/__algorithm/ranges_next_permutation.h index 34c5fee040..6c8e8e1529 100644 --- a/lib/libcxx/include/__algorithm/ranges_next_permutation.h +++ b/lib/libcxx/include/__algorithm/ranges_next_permutation.h @@ -22,12 +22,13 @@ #include <__ranges/concepts.h> #include <__ranges/dangling.h> #include <__utility/move.h> +#include <__utility/pair.h> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header #endif -#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#if _LIBCPP_STD_VER > 17 _LIBCPP_BEGIN_NAMESPACE_STD @@ -67,6 +68,6 @@ constexpr inline auto next_permutation = __next_permutation::__fn{}; _LIBCPP_END_NAMESPACE_STD -#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#endif // _LIBCPP_STD_VER > 17 #endif // _LIBCPP___ALGORITHM_RANGES_NEXT_PERMUTATION_H diff --git a/lib/libcxx/include/__algorithm/ranges_none_of.h b/lib/libcxx/include/__algorithm/ranges_none_of.h index 706ff5cd74..b39e570fd3 100644 --- a/lib/libcxx/include/__algorithm/ranges_none_of.h +++ b/lib/libcxx/include/__algorithm/ranges_none_of.h @@ -22,7 +22,7 @@ # pragma GCC system_header #endif -#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#if _LIBCPP_STD_VER > 17 _LIBCPP_BEGIN_NAMESPACE_STD @@ -42,14 +42,14 @@ struct __fn { template _Sent, class _Proj = identity, indirect_unary_predicate> _Pred> - _LIBCPP_HIDE_FROM_ABI constexpr + _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr bool operator()(_Iter __first, _Sent __last, _Pred __pred = {}, _Proj __proj = {}) const { return __none_of_impl(std::move(__first), std::move(__last), __pred, __proj); } template , _Proj>> _Pred> - _LIBCPP_HIDE_FROM_ABI constexpr + _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr bool operator()(_Range&& __range, _Pred __pred, _Proj __proj = {}) const { return __none_of_impl(ranges::begin(__range), ranges::end(__range), __pred, __proj); } @@ -63,6 +63,6 @@ inline namespace __cpo { _LIBCPP_END_NAMESPACE_STD -#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#endif // _LIBCPP_STD_VER > 17 #endif // _LIBCPP___ALGORITHM_RANGES_NONE_OF_H diff --git a/lib/libcxx/include/__algorithm/ranges_nth_element.h b/lib/libcxx/include/__algorithm/ranges_nth_element.h index ad63bd20fb..d9ec4f1382 100644 --- a/lib/libcxx/include/__algorithm/ranges_nth_element.h +++ b/lib/libcxx/include/__algorithm/ranges_nth_element.h @@ -31,7 +31,7 @@ # pragma GCC system_header #endif -#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#if _LIBCPP_STD_VER > 17 _LIBCPP_BEGIN_NAMESPACE_STD @@ -75,6 +75,6 @@ inline namespace __cpo { _LIBCPP_END_NAMESPACE_STD -#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#endif // _LIBCPP_STD_VER > 17 #endif // _LIBCPP___ALGORITHM_RANGES_NTH_ELEMENT_H diff --git a/lib/libcxx/include/__algorithm/ranges_partial_sort.h b/lib/libcxx/include/__algorithm/ranges_partial_sort.h index 020e34925d..3ea0a7fb44 100644 --- a/lib/libcxx/include/__algorithm/ranges_partial_sort.h +++ b/lib/libcxx/include/__algorithm/ranges_partial_sort.h @@ -27,12 +27,13 @@ #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 #endif -#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#if _LIBCPP_STD_VER > 17 _LIBCPP_BEGIN_NAMESPACE_STD @@ -72,6 +73,6 @@ inline namespace __cpo { _LIBCPP_END_NAMESPACE_STD -#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#endif // _LIBCPP_STD_VER > 17 #endif // _LIBCPP___ALGORITHM_RANGES_PARTIAL_SORT_H diff --git a/lib/libcxx/include/__algorithm/ranges_partial_sort_copy.h b/lib/libcxx/include/__algorithm/ranges_partial_sort_copy.h index 271c347b7a..212db555a8 100644 --- a/lib/libcxx/include/__algorithm/ranges_partial_sort_copy.h +++ b/lib/libcxx/include/__algorithm/ranges_partial_sort_copy.h @@ -24,12 +24,13 @@ #include <__ranges/concepts.h> #include <__ranges/dangling.h> #include <__utility/move.h> +#include <__utility/pair.h> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header #endif -#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#if _LIBCPP_STD_VER > 17 _LIBCPP_BEGIN_NAMESPACE_STD @@ -86,6 +87,6 @@ inline namespace __cpo { _LIBCPP_END_NAMESPACE_STD -#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#endif // _LIBCPP_STD_VER > 17 #endif // _LIBCPP___ALGORITHM_RANGES_PARTIAL_SORT_COPY_H diff --git a/lib/libcxx/include/__algorithm/ranges_partition.h b/lib/libcxx/include/__algorithm/ranges_partition.h index 6a53933f37..8b3aae5c25 100644 --- a/lib/libcxx/include/__algorithm/ranges_partition.h +++ b/lib/libcxx/include/__algorithm/ranges_partition.h @@ -26,13 +26,14 @@ #include <__ranges/subrange.h> #include <__utility/forward.h> #include <__utility/move.h> +#include <__utility/pair.h> #include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header #endif -#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#if _LIBCPP_STD_VER > 17 _LIBCPP_BEGIN_NAMESPACE_STD @@ -43,7 +44,7 @@ struct __fn { template _LIBCPP_HIDE_FROM_ABI static constexpr - subrange<__uncvref_t<_Iter>> __partition_fn_impl(_Iter&& __first, _Sent&& __last, _Pred&& __pred, _Proj&& __proj) { + subrange<__remove_cvref_t<_Iter>> __partition_fn_impl(_Iter&& __first, _Sent&& __last, _Pred&& __pred, _Proj&& __proj) { auto&& __projected_pred = std::__make_projected(__pred, __proj); auto __result = std::__partition<_RangeAlgPolicy>( std::move(__first), std::move(__last), __projected_pred, __iterator_concept<_Iter>()); @@ -77,6 +78,6 @@ inline namespace __cpo { _LIBCPP_END_NAMESPACE_STD -#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#endif // _LIBCPP_STD_VER > 17 #endif // _LIBCPP___ALGORITHM_RANGES_PARTITION_H diff --git a/lib/libcxx/include/__algorithm/ranges_partition_copy.h b/lib/libcxx/include/__algorithm/ranges_partition_copy.h index 7201a8cbfe..e7a9a347df 100644 --- a/lib/libcxx/include/__algorithm/ranges_partition_copy.h +++ b/lib/libcxx/include/__algorithm/ranges_partition_copy.h @@ -26,7 +26,7 @@ # pragma GCC system_header #endif -#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#if _LIBCPP_STD_VER > 17 _LIBCPP_BEGIN_NAMESPACE_STD @@ -43,7 +43,7 @@ struct __fn { template _LIBCPP_HIDE_FROM_ABI constexpr static partition_copy_result< - __uncvref_t<_InIter>, __uncvref_t<_OutIter1>, __uncvref_t<_OutIter2> + __remove_cvref_t<_InIter>, __remove_cvref_t<_OutIter1>, __remove_cvref_t<_OutIter2> > __partition_copy_fn_impl( _InIter&& __first, _Sent&& __last, _OutIter1&& __out_true, _OutIter2&& __out_false, _Pred& __pred, _Proj& __proj) { for (; __first != __last; ++__first) { @@ -93,6 +93,6 @@ inline namespace __cpo { _LIBCPP_END_NAMESPACE_STD -#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#endif // _LIBCPP_STD_VER > 17 #endif // _LIBCPP___ALGORITHM_RANGES_PARTITION_COPY_H diff --git a/lib/libcxx/include/__algorithm/ranges_partition_point.h b/lib/libcxx/include/__algorithm/ranges_partition_point.h index 6614a0bb50..2bd118d4de 100644 --- a/lib/libcxx/include/__algorithm/ranges_partition_point.h +++ b/lib/libcxx/include/__algorithm/ranges_partition_point.h @@ -27,7 +27,7 @@ # pragma GCC system_header #endif -#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#if _LIBCPP_STD_VER > 17 _LIBCPP_BEGIN_NAMESPACE_STD @@ -83,6 +83,6 @@ inline namespace __cpo { _LIBCPP_END_NAMESPACE_STD -#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#endif // _LIBCPP_STD_VER > 17 #endif // _LIBCPP___ALGORITHM_RANGES_PARTITION_POINT_H diff --git a/lib/libcxx/include/__algorithm/ranges_pop_heap.h b/lib/libcxx/include/__algorithm/ranges_pop_heap.h index fc7554fb07..65beec8864 100644 --- a/lib/libcxx/include/__algorithm/ranges_pop_heap.h +++ b/lib/libcxx/include/__algorithm/ranges_pop_heap.h @@ -32,7 +32,7 @@ # pragma GCC system_header #endif -#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#if _LIBCPP_STD_VER > 17 _LIBCPP_BEGIN_NAMESPACE_STD @@ -76,6 +76,6 @@ inline namespace __cpo { _LIBCPP_END_NAMESPACE_STD -#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#endif // _LIBCPP_STD_VER > 17 #endif // _LIBCPP___ALGORITHM_RANGES_POP_HEAP_H diff --git a/lib/libcxx/include/__algorithm/ranges_prev_permutation.h b/lib/libcxx/include/__algorithm/ranges_prev_permutation.h index 58da606d07..6866d90cf4 100644 --- a/lib/libcxx/include/__algorithm/ranges_prev_permutation.h +++ b/lib/libcxx/include/__algorithm/ranges_prev_permutation.h @@ -22,12 +22,13 @@ #include <__ranges/concepts.h> #include <__ranges/dangling.h> #include <__utility/move.h> +#include <__utility/pair.h> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header #endif -#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#if _LIBCPP_STD_VER > 17 _LIBCPP_BEGIN_NAMESPACE_STD @@ -71,6 +72,6 @@ constexpr inline auto prev_permutation = __prev_permutation::__fn{}; _LIBCPP_END_NAMESPACE_STD -#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#endif // _LIBCPP_STD_VER > 17 #endif // _LIBCPP___ALGORITHM_RANGES_PREV_PERMUTATION_H diff --git a/lib/libcxx/include/__algorithm/ranges_push_heap.h b/lib/libcxx/include/__algorithm/ranges_push_heap.h index 3436b39e12..a1f4347417 100644 --- a/lib/libcxx/include/__algorithm/ranges_push_heap.h +++ b/lib/libcxx/include/__algorithm/ranges_push_heap.h @@ -32,7 +32,7 @@ # pragma GCC system_header #endif -#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#if _LIBCPP_STD_VER > 17 _LIBCPP_BEGIN_NAMESPACE_STD @@ -75,6 +75,6 @@ inline namespace __cpo { _LIBCPP_END_NAMESPACE_STD -#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#endif // _LIBCPP_STD_VER > 17 #endif // _LIBCPP___ALGORITHM_RANGES_PUSH_HEAP_H diff --git a/lib/libcxx/include/__algorithm/ranges_remove.h b/lib/libcxx/include/__algorithm/ranges_remove.h index a6a1200763..dd5c5fb453 100644 --- a/lib/libcxx/include/__algorithm/ranges_remove.h +++ b/lib/libcxx/include/__algorithm/ranges_remove.h @@ -25,7 +25,7 @@ # pragma GCC system_header #endif -#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#if _LIBCPP_STD_VER > 17 _LIBCPP_BEGIN_NAMESPACE_STD @@ -35,7 +35,7 @@ struct __fn { template _Sent, class _Type, class _Proj = identity> requires indirect_binary_predicate, const _Type*> - _LIBCPP_HIDE_FROM_ABI constexpr + _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr subrange<_Iter> operator()(_Iter __first, _Sent __last, const _Type& __value, _Proj __proj = {}) const { auto __pred = [&](auto&& __other) { return __value == __other; }; return ranges::__remove_if_impl(std::move(__first), std::move(__last), __pred, __proj); @@ -44,7 +44,7 @@ struct __fn { template requires permutable> && indirect_binary_predicate, _Proj>, const _Type*> - _LIBCPP_HIDE_FROM_ABI constexpr + _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr borrowed_subrange_t<_Range> operator()(_Range&& __range, const _Type& __value, _Proj __proj = {}) const { auto __pred = [&](auto&& __other) { return __value == __other; }; return ranges::__remove_if_impl(ranges::begin(__range), ranges::end(__range), __pred, __proj); @@ -59,6 +59,6 @@ inline namespace __cpo { _LIBCPP_END_NAMESPACE_STD -#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#endif // _LIBCPP_STD_VER > 17 #endif // _LIBCPP___ALGORITHM_RANGES_REMOVE_H diff --git a/lib/libcxx/include/__algorithm/ranges_remove_copy.h b/lib/libcxx/include/__algorithm/ranges_remove_copy.h index a8144ce0ec..2102228667 100644 --- a/lib/libcxx/include/__algorithm/ranges_remove_copy.h +++ b/lib/libcxx/include/__algorithm/ranges_remove_copy.h @@ -26,7 +26,7 @@ # pragma GCC system_header #endif -#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#if _LIBCPP_STD_VER > 17 _LIBCPP_BEGIN_NAMESPACE_STD @@ -71,6 +71,6 @@ inline namespace __cpo { _LIBCPP_END_NAMESPACE_STD -#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#endif // _LIBCPP_STD_VER > 17 #endif // _LIBCPP___ALGORITHM_RANGES_REMOVE_COPY_H diff --git a/lib/libcxx/include/__algorithm/ranges_remove_copy_if.h b/lib/libcxx/include/__algorithm/ranges_remove_copy_if.h index 3f56693fa1..4fc67454b9 100644 --- a/lib/libcxx/include/__algorithm/ranges_remove_copy_if.h +++ b/lib/libcxx/include/__algorithm/ranges_remove_copy_if.h @@ -29,7 +29,7 @@ # pragma GCC system_header #endif -#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#if _LIBCPP_STD_VER > 17 _LIBCPP_BEGIN_NAMESPACE_STD @@ -85,6 +85,6 @@ inline namespace __cpo { _LIBCPP_END_NAMESPACE_STD -#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#endif // _LIBCPP_STD_VER > 17 #endif // _LIBCPP___ALGORITHM_RANGES_REMOVE_COPY_IF_H diff --git a/lib/libcxx/include/__algorithm/ranges_remove_if.h b/lib/libcxx/include/__algorithm/ranges_remove_if.h index d4e382e551..1f17467fc4 100644 --- a/lib/libcxx/include/__algorithm/ranges_remove_if.h +++ b/lib/libcxx/include/__algorithm/ranges_remove_if.h @@ -27,7 +27,7 @@ # pragma GCC system_header #endif -#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#if _LIBCPP_STD_VER > 17 _LIBCPP_BEGIN_NAMESPACE_STD @@ -56,7 +56,7 @@ struct __fn { template _Sent, class _Proj = identity, indirect_unary_predicate> _Pred> - _LIBCPP_HIDE_FROM_ABI constexpr + _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr subrange<_Iter> operator()(_Iter __first, _Sent __last, _Pred __pred, _Proj __proj = {}) const { return ranges::__remove_if_impl(std::move(__first), std::move(__last), __pred, __proj); } @@ -65,7 +65,7 @@ struct __fn { class _Proj = identity, indirect_unary_predicate, _Proj>> _Pred> requires permutable> - _LIBCPP_HIDE_FROM_ABI constexpr + _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr borrowed_subrange_t<_Range> operator()(_Range&& __range, _Pred __pred, _Proj __proj = {}) const { return ranges::__remove_if_impl(ranges::begin(__range), ranges::end(__range), __pred, __proj); } @@ -80,6 +80,6 @@ inline namespace __cpo { _LIBCPP_END_NAMESPACE_STD -#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#endif // _LIBCPP_STD_VER > 17 #endif // _LIBCPP___ALGORITHM_RANGES_REMOVE_IF_H diff --git a/lib/libcxx/include/__algorithm/ranges_replace.h b/lib/libcxx/include/__algorithm/ranges_replace.h index 5e74c3ff80..8b12beacb7 100644 --- a/lib/libcxx/include/__algorithm/ranges_replace.h +++ b/lib/libcxx/include/__algorithm/ranges_replace.h @@ -24,7 +24,7 @@ # pragma GCC system_header #endif -#if _LIBCPP_STD_VER > 17 && !defined (_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#if _LIBCPP_STD_VER > 17 _LIBCPP_BEGIN_NAMESPACE_STD @@ -69,6 +69,6 @@ inline namespace __cpo { _LIBCPP_END_NAMESPACE_STD -#endif // _LIBCPP_STD_VER > 17 && !defined (_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#endif // _LIBCPP_STD_VER > 17 #endif // _LIBCPP___ALGORITHM_RANGES_REPLACE_H diff --git a/lib/libcxx/include/__algorithm/ranges_replace_copy.h b/lib/libcxx/include/__algorithm/ranges_replace_copy.h index 7d59dbe7db..f87a236fbd 100644 --- a/lib/libcxx/include/__algorithm/ranges_replace_copy.h +++ b/lib/libcxx/include/__algorithm/ranges_replace_copy.h @@ -26,7 +26,7 @@ # pragma GCC system_header #endif -#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#if _LIBCPP_STD_VER > 17 _LIBCPP_BEGIN_NAMESPACE_STD @@ -86,6 +86,6 @@ inline namespace __cpo { _LIBCPP_END_NAMESPACE_STD -#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#endif // _LIBCPP_STD_VER > 17 #endif // _LIBCPP___ALGORITHM_RANGES_REPLACE_COPY_H diff --git a/lib/libcxx/include/__algorithm/ranges_replace_copy_if.h b/lib/libcxx/include/__algorithm/ranges_replace_copy_if.h index 7602e8a144..b8741ec7be 100644 --- a/lib/libcxx/include/__algorithm/ranges_replace_copy_if.h +++ b/lib/libcxx/include/__algorithm/ranges_replace_copy_if.h @@ -24,7 +24,7 @@ # pragma GCC system_header #endif -#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#if _LIBCPP_STD_VER > 17 _LIBCPP_BEGIN_NAMESPACE_STD @@ -88,6 +88,6 @@ inline namespace __cpo { _LIBCPP_END_NAMESPACE_STD -#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#endif // _LIBCPP_STD_VER > 17 #endif // _LIBCPP___ALGORITHM_RANGES_REPLACE_COPY_IF_H diff --git a/lib/libcxx/include/__algorithm/ranges_replace_if.h b/lib/libcxx/include/__algorithm/ranges_replace_if.h index 0f9555fc35..65be3c7d76 100644 --- a/lib/libcxx/include/__algorithm/ranges_replace_if.h +++ b/lib/libcxx/include/__algorithm/ranges_replace_if.h @@ -23,7 +23,7 @@ # pragma GCC system_header #endif -#if _LIBCPP_STD_VER > 17 && !defined (_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#if _LIBCPP_STD_VER > 17 _LIBCPP_BEGIN_NAMESPACE_STD @@ -72,6 +72,6 @@ inline namespace __cpo { _LIBCPP_END_NAMESPACE_STD -#endif // _LIBCPP_STD_VER > 17 && !defined (_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#endif // _LIBCPP_STD_VER > 17 #endif // _LIBCPP___ALGORITHM_RANGES_REPLACE_IF_H diff --git a/lib/libcxx/include/__algorithm/ranges_reverse.h b/lib/libcxx/include/__algorithm/ranges_reverse.h index e7555d0f9a..e2a5d9a825 100644 --- a/lib/libcxx/include/__algorithm/ranges_reverse.h +++ b/lib/libcxx/include/__algorithm/ranges_reverse.h @@ -22,7 +22,7 @@ # pragma GCC system_header #endif -#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#if _LIBCPP_STD_VER > 17 _LIBCPP_BEGIN_NAMESPACE_STD @@ -78,6 +78,6 @@ inline namespace __cpo { _LIBCPP_END_NAMESPACE_STD -#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#endif // _LIBCPP_STD_VER > 17 #endif // _LIBCPP___ALGORITHM_RANGES_REVERSE_H diff --git a/lib/libcxx/include/__algorithm/ranges_reverse_copy.h b/lib/libcxx/include/__algorithm/ranges_reverse_copy.h index e2da9b484a..a84b1ad780 100644 --- a/lib/libcxx/include/__algorithm/ranges_reverse_copy.h +++ b/lib/libcxx/include/__algorithm/ranges_reverse_copy.h @@ -25,7 +25,7 @@ # pragma GCC system_header #endif -#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#if _LIBCPP_STD_VER > 17 _LIBCPP_BEGIN_NAMESPACE_STD @@ -62,6 +62,6 @@ inline namespace __cpo { _LIBCPP_END_NAMESPACE_STD -#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#endif // _LIBCPP_STD_VER > 17 #endif // _LIBCPP___ALGORITHM_RANGES_REVERSE_COPY_H diff --git a/lib/libcxx/include/__algorithm/ranges_rotate.h b/lib/libcxx/include/__algorithm/ranges_rotate.h index 1cd69a141f..91ed4027df 100644 --- a/lib/libcxx/include/__algorithm/ranges_rotate.h +++ b/lib/libcxx/include/__algorithm/ranges_rotate.h @@ -25,7 +25,7 @@ # pragma GCC system_header #endif -#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#if _LIBCPP_STD_VER > 17 _LIBCPP_BEGIN_NAMESPACE_STD @@ -66,6 +66,6 @@ inline namespace __cpo { _LIBCPP_END_NAMESPACE_STD -#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#endif // _LIBCPP_STD_VER > 17 #endif // _LIBCPP___ALGORITHM_RANGES_ROTATE_H diff --git a/lib/libcxx/include/__algorithm/ranges_rotate_copy.h b/lib/libcxx/include/__algorithm/ranges_rotate_copy.h index d7a282c867..52f403c16a 100644 --- a/lib/libcxx/include/__algorithm/ranges_rotate_copy.h +++ b/lib/libcxx/include/__algorithm/ranges_rotate_copy.h @@ -23,7 +23,7 @@ # pragma GCC system_header #endif -#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#if _LIBCPP_STD_VER > 17 _LIBCPP_BEGIN_NAMESPACE_STD @@ -63,6 +63,6 @@ inline namespace __cpo { _LIBCPP_END_NAMESPACE_STD -#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#endif // _LIBCPP_STD_VER > 17 #endif // _LIBCPP___ALGORITHM_RANGES_ROTATE_COPY_H diff --git a/lib/libcxx/include/__algorithm/ranges_sample.h b/lib/libcxx/include/__algorithm/ranges_sample.h index a8477f8037..a37cb64fa2 100644 --- a/lib/libcxx/include/__algorithm/ranges_sample.h +++ b/lib/libcxx/include/__algorithm/ranges_sample.h @@ -27,7 +27,7 @@ # pragma GCC system_header #endif -#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#if _LIBCPP_STD_VER > 17 _LIBCPP_BEGIN_NAMESPACE_STD @@ -69,6 +69,6 @@ inline namespace __cpo { _LIBCPP_END_NAMESPACE_STD -#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#endif // _LIBCPP_STD_VER > 17 #endif // _LIBCPP___ALGORITHM_RANGES_SAMPLE_H diff --git a/lib/libcxx/include/__algorithm/ranges_search.h b/lib/libcxx/include/__algorithm/ranges_search.h index 0564bbe1f8..388d5afa49 100644 --- a/lib/libcxx/include/__algorithm/ranges_search.h +++ b/lib/libcxx/include/__algorithm/ranges_search.h @@ -22,12 +22,13 @@ #include <__ranges/concepts.h> #include <__ranges/size.h> #include <__ranges/subrange.h> +#include <__utility/pair.h> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header #endif -#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#if _LIBCPP_STD_VER > 17 _LIBCPP_BEGIN_NAMESPACE_STD @@ -74,7 +75,7 @@ struct __fn { class _Proj1 = identity, class _Proj2 = identity> requires indirectly_comparable<_Iter1, _Iter2, _Pred, _Proj1, _Proj2> - _LIBCPP_HIDE_FROM_ABI constexpr + _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr subrange<_Iter1> operator()(_Iter1 __first1, _Sent1 __last1, _Iter2 __first2, _Sent2 __last2, _Pred __pred = {}, @@ -89,7 +90,7 @@ struct __fn { class _Proj1 = identity, class _Proj2 = identity> requires indirectly_comparable, iterator_t<_Range2>, _Pred, _Proj1, _Proj2> - _LIBCPP_HIDE_FROM_ABI constexpr + _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr borrowed_subrange_t<_Range1> operator()(_Range1&& __range1, _Range2&& __range2, _Pred __pred = {}, @@ -129,6 +130,6 @@ inline namespace __cpo { _LIBCPP_END_NAMESPACE_STD -#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#endif // _LIBCPP_STD_VER > 17 #endif // _LIBCPP___ALGORITHM_RANGES_SEARCH_H diff --git a/lib/libcxx/include/__algorithm/ranges_search_n.h b/lib/libcxx/include/__algorithm/ranges_search_n.h index 29fdbfb1c7..56ec8f33d4 100644 --- a/lib/libcxx/include/__algorithm/ranges_search_n.h +++ b/lib/libcxx/include/__algorithm/ranges_search_n.h @@ -25,12 +25,13 @@ #include <__ranges/size.h> #include <__ranges/subrange.h> #include <__utility/move.h> +#include <__utility/pair.h> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header #endif -#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#if _LIBCPP_STD_VER > 17 _LIBCPP_BEGIN_NAMESPACE_STD @@ -52,12 +53,8 @@ struct __fn { } if constexpr (random_access_iterator<_Iter1>) { - auto __ret = __search_n_random_access_impl<_RangeAlgPolicy>(__first, __last, - __count, - __value, - __pred, - __proj, - __size); + auto __ret = std::__search_n_random_access_impl<_RangeAlgPolicy>( + __first, __last, __count, __value, __pred, __proj, __size); return {std::move(__ret.first), std::move(__ret.second)}; } } @@ -75,7 +72,7 @@ struct __fn { class _Pred = ranges::equal_to, class _Proj = identity> requires indirectly_comparable<_Iter, const _Type*, _Pred, _Proj> - _LIBCPP_HIDE_FROM_ABI constexpr + _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr subrange<_Iter> operator()(_Iter __first, _Sent __last, iter_difference_t<_Iter> __count, const _Type& __value, @@ -86,7 +83,7 @@ struct __fn { template requires indirectly_comparable, const _Type*, _Pred, _Proj> - _LIBCPP_HIDE_FROM_ABI constexpr + _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr borrowed_subrange_t<_Range> operator()(_Range&& __range, range_difference_t<_Range> __count, const _Type& __value, @@ -115,6 +112,6 @@ inline namespace __cpo { _LIBCPP_END_NAMESPACE_STD -#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#endif // _LIBCPP_STD_VER > 17 #endif // _LIBCPP___ALGORITHM_RANGES_SEARCH_N_H diff --git a/lib/libcxx/include/__algorithm/ranges_set_difference.h b/lib/libcxx/include/__algorithm/ranges_set_difference.h index 4eb3efad38..607dd687a5 100644 --- a/lib/libcxx/include/__algorithm/ranges_set_difference.h +++ b/lib/libcxx/include/__algorithm/ranges_set_difference.h @@ -10,6 +10,7 @@ #define _LIBCPP___ALGORITHM_RANGES_SET_DIFFERENCE_H #include <__algorithm/in_out_result.h> +#include <__algorithm/iterator_operations.h> #include <__algorithm/make_projected.h> #include <__algorithm/set_difference.h> #include <__config> @@ -23,12 +24,13 @@ #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 #endif -#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#if _LIBCPP_STD_VER > 17 _LIBCPP_BEGIN_NAMESPACE_STD @@ -59,7 +61,7 @@ struct __fn { _Comp __comp = {}, _Proj1 __proj1 = {}, _Proj2 __proj2 = {}) const { - auto __ret = std::__set_difference( + auto __ret = std::__set_difference<_RangeAlgPolicy>( __first1, __last1, __first2, __last2, __result, ranges::__make_projected_comp(__comp, __proj1, __proj2)); return {std::move(__ret.first), std::move(__ret.second)}; } @@ -71,7 +73,7 @@ struct __fn { class _Comp = less, class _Proj1 = identity, class _Proj2 = identity> - requires mergeable, iterator_t<_Range2>, _OutIter, _Comp, _Proj1, _Proj2> + requires mergeable, iterator_t<_Range2>, _OutIter, _Comp, _Proj1, _Proj2> _LIBCPP_HIDE_FROM_ABI constexpr set_difference_result, _OutIter> operator()( _Range1&& __range1, @@ -80,7 +82,7 @@ struct __fn { _Comp __comp = {}, _Proj1 __proj1 = {}, _Proj2 __proj2 = {}) const { - auto __ret = std::__set_difference( + auto __ret = std::__set_difference<_RangeAlgPolicy>( ranges::begin(__range1), ranges::end(__range1), ranges::begin(__range2), @@ -100,5 +102,5 @@ inline namespace __cpo { _LIBCPP_END_NAMESPACE_STD -#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#endif // _LIBCPP_STD_VER > 17 #endif // _LIBCPP___ALGORITHM_RANGES_SET_DIFFERENCE_H diff --git a/lib/libcxx/include/__algorithm/ranges_set_intersection.h b/lib/libcxx/include/__algorithm/ranges_set_intersection.h index 05af91ae29..aa9fd24ced 100644 --- a/lib/libcxx/include/__algorithm/ranges_set_intersection.h +++ b/lib/libcxx/include/__algorithm/ranges_set_intersection.h @@ -28,7 +28,7 @@ # pragma GCC system_header #endif -#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#if _LIBCPP_STD_VER > 17 _LIBCPP_BEGIN_NAMESPACE_STD @@ -82,7 +82,7 @@ struct __fn { _OutIter, _Comp, _Proj1, - _Proj2> + _Proj2> _LIBCPP_HIDE_FROM_ABI constexpr set_intersection_result, borrowed_iterator_t<_Range2>, _OutIter> @@ -113,5 +113,5 @@ inline namespace __cpo { _LIBCPP_END_NAMESPACE_STD -#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#endif // _LIBCPP_STD_VER > 17 #endif // _LIBCPP___ALGORITHM_RANGES_SET_INTERSECTION_H diff --git a/lib/libcxx/include/__algorithm/ranges_set_symmetric_difference.h b/lib/libcxx/include/__algorithm/ranges_set_symmetric_difference.h index c54cf3a651..bc4a906550 100644 --- a/lib/libcxx/include/__algorithm/ranges_set_symmetric_difference.h +++ b/lib/libcxx/include/__algorithm/ranges_set_symmetric_difference.h @@ -10,6 +10,7 @@ #define _LIBCPP___ALGORITHM_RANGES_SET_SYMMETRIC_DIFFERENCE_H #include <__algorithm/in_in_out_result.h> +#include <__algorithm/iterator_operations.h> #include <__algorithm/make_projected.h> #include <__algorithm/set_symmetric_difference.h> #include <__config> @@ -27,7 +28,7 @@ # pragma GCC system_header #endif -#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#if _LIBCPP_STD_VER > 17 _LIBCPP_BEGIN_NAMESPACE_STD @@ -58,7 +59,7 @@ struct __fn { _Comp __comp = {}, _Proj1 __proj1 = {}, _Proj2 __proj2 = {}) const { - auto __ret = std::__set_symmetric_difference( + auto __ret = std::__set_symmetric_difference<_RangeAlgPolicy>( std::move(__first1), std::move(__last1), std::move(__first2), @@ -81,7 +82,7 @@ struct __fn { _OutIter, _Comp, _Proj1, - _Proj2> + _Proj2> _LIBCPP_HIDE_FROM_ABI constexpr set_symmetric_difference_result, borrowed_iterator_t<_Range2>, _OutIter> @@ -92,7 +93,7 @@ struct __fn { _Comp __comp = {}, _Proj1 __proj1 = {}, _Proj2 __proj2 = {}) const { - auto __ret = std::__set_symmetric_difference( + auto __ret = std::__set_symmetric_difference<_RangeAlgPolicy>( ranges::begin(__range1), ranges::end(__range1), ranges::begin(__range2), @@ -112,5 +113,5 @@ inline namespace __cpo { _LIBCPP_END_NAMESPACE_STD -#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#endif // _LIBCPP_STD_VER > 17 #endif // _LIBCPP___ALGORITHM_RANGES_SET_SYMMETRIC_DIFFERENCE_H diff --git a/lib/libcxx/include/__algorithm/ranges_set_union.h b/lib/libcxx/include/__algorithm/ranges_set_union.h index 3826e55688..f8cd45ca0e 100644 --- a/lib/libcxx/include/__algorithm/ranges_set_union.h +++ b/lib/libcxx/include/__algorithm/ranges_set_union.h @@ -10,6 +10,7 @@ #define _LIBCPP___ALGORITHM_RANGES_SET_UNION_H #include <__algorithm/in_in_out_result.h> +#include <__algorithm/iterator_operations.h> #include <__algorithm/make_projected.h> #include <__algorithm/set_union.h> #include <__config> @@ -30,7 +31,7 @@ # pragma GCC system_header #endif -#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#if _LIBCPP_STD_VER > 17 _LIBCPP_BEGIN_NAMESPACE_STD @@ -61,7 +62,7 @@ struct __fn { _Comp __comp = {}, _Proj1 __proj1 = {}, _Proj2 __proj2 = {}) const { - auto __ret = std::__set_union( + auto __ret = std::__set_union<_RangeAlgPolicy>( std::move(__first1), std::move(__last1), std::move(__first2), @@ -84,7 +85,7 @@ struct __fn { _OutIter, _Comp, _Proj1, - _Proj2> + _Proj2> _LIBCPP_HIDE_FROM_ABI constexpr set_union_result, borrowed_iterator_t<_Range2>, _OutIter> @@ -95,7 +96,7 @@ struct __fn { _Comp __comp = {}, _Proj1 __proj1 = {}, _Proj2 __proj2 = {}) const { - auto __ret = std::__set_union( + auto __ret = std::__set_union<_RangeAlgPolicy>( ranges::begin(__range1), ranges::end(__range1), ranges::begin(__range2), @@ -115,6 +116,6 @@ inline namespace __cpo { _LIBCPP_END_NAMESPACE_STD -#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#endif // _LIBCPP_STD_VER > 17 #endif // _LIBCPP___ALGORITHM_RANGES_SET_UNION_H diff --git a/lib/libcxx/include/__algorithm/ranges_shuffle.h b/lib/libcxx/include/__algorithm/ranges_shuffle.h index 9b7f81e489..a2f2c0edde 100644 --- a/lib/libcxx/include/__algorithm/ranges_shuffle.h +++ b/lib/libcxx/include/__algorithm/ranges_shuffle.h @@ -31,7 +31,7 @@ # pragma GCC system_header #endif -#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#if _LIBCPP_STD_VER > 17 _LIBCPP_BEGIN_NAMESPACE_STD @@ -66,6 +66,6 @@ inline namespace __cpo { _LIBCPP_END_NAMESPACE_STD -#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#endif // _LIBCPP_STD_VER > 17 #endif // _LIBCPP___ALGORITHM_RANGES_SHUFFLE_H diff --git a/lib/libcxx/include/__algorithm/ranges_sort.h b/lib/libcxx/include/__algorithm/ranges_sort.h index c3f3cbff00..32391df5f6 100644 --- a/lib/libcxx/include/__algorithm/ranges_sort.h +++ b/lib/libcxx/include/__algorithm/ranges_sort.h @@ -31,7 +31,7 @@ # pragma GCC system_header #endif -#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#if _LIBCPP_STD_VER > 17 _LIBCPP_BEGIN_NAMESPACE_STD @@ -74,6 +74,6 @@ inline namespace __cpo { _LIBCPP_END_NAMESPACE_STD -#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#endif // _LIBCPP_STD_VER > 17 #endif // _LIBCPP___ALGORITHM_RANGES_SORT_H diff --git a/lib/libcxx/include/__algorithm/ranges_sort_heap.h b/lib/libcxx/include/__algorithm/ranges_sort_heap.h index f6e4dcb43d..9feb0f609b 100644 --- a/lib/libcxx/include/__algorithm/ranges_sort_heap.h +++ b/lib/libcxx/include/__algorithm/ranges_sort_heap.h @@ -32,7 +32,7 @@ # pragma GCC system_header #endif -#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#if _LIBCPP_STD_VER > 17 _LIBCPP_BEGIN_NAMESPACE_STD @@ -75,6 +75,6 @@ inline namespace __cpo { _LIBCPP_END_NAMESPACE_STD -#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#endif // _LIBCPP_STD_VER > 17 #endif // _LIBCPP___ALGORITHM_RANGES_SORT_HEAP_H diff --git a/lib/libcxx/include/__algorithm/ranges_stable_partition.h b/lib/libcxx/include/__algorithm/ranges_stable_partition.h index b20dfa3a8b..c3469f17c7 100644 --- a/lib/libcxx/include/__algorithm/ranges_stable_partition.h +++ b/lib/libcxx/include/__algorithm/ranges_stable_partition.h @@ -34,7 +34,7 @@ # pragma GCC system_header #endif -#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#if _LIBCPP_STD_VER > 17 _LIBCPP_BEGIN_NAMESPACE_STD @@ -45,7 +45,7 @@ struct __fn { template _LIBCPP_HIDE_FROM_ABI static - subrange<__uncvref_t<_Iter>> __stable_partition_fn_impl( + subrange<__remove_cvref_t<_Iter>> __stable_partition_fn_impl( _Iter&& __first, _Sent&& __last, _Pred&& __pred, _Proj&& __proj) { auto __last_iter = ranges::next(__first, __last); @@ -83,6 +83,6 @@ inline namespace __cpo { _LIBCPP_END_NAMESPACE_STD -#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#endif // _LIBCPP_STD_VER > 17 #endif // _LIBCPP___ALGORITHM_RANGES_STABLE_PARTITION_H diff --git a/lib/libcxx/include/__algorithm/ranges_stable_sort.h b/lib/libcxx/include/__algorithm/ranges_stable_sort.h index 7ecffefc19..d3c48ddb9b 100644 --- a/lib/libcxx/include/__algorithm/ranges_stable_sort.h +++ b/lib/libcxx/include/__algorithm/ranges_stable_sort.h @@ -31,7 +31,7 @@ # pragma GCC system_header #endif -#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#if _LIBCPP_STD_VER > 17 _LIBCPP_BEGIN_NAMESPACE_STD @@ -74,6 +74,6 @@ inline namespace __cpo { _LIBCPP_END_NAMESPACE_STD -#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#endif // _LIBCPP_STD_VER > 17 #endif // _LIBCPP___ALGORITHM_RANGES_STABLE_SORT_H diff --git a/lib/libcxx/include/__algorithm/ranges_swap_ranges.h b/lib/libcxx/include/__algorithm/ranges_swap_ranges.h index d980fdec2c..552fd55ff8 100644 --- a/lib/libcxx/include/__algorithm/ranges_swap_ranges.h +++ b/lib/libcxx/include/__algorithm/ranges_swap_ranges.h @@ -24,7 +24,7 @@ # pragma GCC system_header #endif -#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#if _LIBCPP_STD_VER > 17 _LIBCPP_BEGIN_NAMESPACE_STD @@ -63,6 +63,6 @@ inline namespace __cpo { _LIBCPP_END_NAMESPACE_STD -#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#endif // _LIBCPP_STD_VER > 17 #endif // _LIBCPP___ALGORITHM_RANGES_SWAP_RANGES_H diff --git a/lib/libcxx/include/__algorithm/ranges_transform.h b/lib/libcxx/include/__algorithm/ranges_transform.h index 3c13b1b79f..c0981a04a9 100644 --- a/lib/libcxx/include/__algorithm/ranges_transform.h +++ b/lib/libcxx/include/__algorithm/ranges_transform.h @@ -26,7 +26,7 @@ # pragma GCC system_header #endif -#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#if _LIBCPP_STD_VER > 17 _LIBCPP_BEGIN_NAMESPACE_STD @@ -165,6 +165,6 @@ inline namespace __cpo { _LIBCPP_END_NAMESPACE_STD -#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#endif // _LIBCPP_STD_VER > 17 #endif // _LIBCPP___ALGORITHM_RANGES_TRANSFORM_H diff --git a/lib/libcxx/include/__algorithm/ranges_unique.h b/lib/libcxx/include/__algorithm/ranges_unique.h index 11370aeccd..be427ccf7f 100644 --- a/lib/libcxx/include/__algorithm/ranges_unique.h +++ b/lib/libcxx/include/__algorithm/ranges_unique.h @@ -26,12 +26,13 @@ #include <__ranges/subrange.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 #endif -#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#if _LIBCPP_STD_VER > 17 _LIBCPP_BEGIN_NAMESPACE_STD @@ -44,7 +45,7 @@ namespace __unique { sentinel_for<_Iter> _Sent, class _Proj = identity, indirect_equivalence_relation> _Comp = ranges::equal_to> - _LIBCPP_HIDE_FROM_ABI constexpr subrange<_Iter> + _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr subrange<_Iter> operator()(_Iter __first, _Sent __last, _Comp __comp = {}, _Proj __proj = {}) const { auto __ret = std::__unique<_RangeAlgPolicy>( std::move(__first), std::move(__last), std::__make_projected(__comp, __proj)); @@ -56,7 +57,7 @@ namespace __unique { class _Proj = identity, indirect_equivalence_relation, _Proj>> _Comp = ranges::equal_to> requires permutable> - _LIBCPP_HIDE_FROM_ABI constexpr borrowed_subrange_t<_Range> + _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr borrowed_subrange_t<_Range> operator()(_Range&& __range, _Comp __comp = {}, _Proj __proj = {}) const { auto __ret = std::__unique<_RangeAlgPolicy>( ranges::begin(__range), ranges::end(__range), std::__make_projected(__comp, __proj)); @@ -73,6 +74,6 @@ inline namespace __cpo { _LIBCPP_END_NAMESPACE_STD -#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#endif // _LIBCPP_STD_VER > 17 #endif // _LIBCPP___ALGORITHM_RANGES_UNIQUE_H diff --git a/lib/libcxx/include/__algorithm/ranges_unique_copy.h b/lib/libcxx/include/__algorithm/ranges_unique_copy.h index 8c0b970d04..3ad47b06f5 100644 --- a/lib/libcxx/include/__algorithm/ranges_unique_copy.h +++ b/lib/libcxx/include/__algorithm/ranges_unique_copy.h @@ -27,12 +27,13 @@ #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 #endif -#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#if _LIBCPP_STD_VER > 17 _LIBCPP_BEGIN_NAMESPACE_STD @@ -110,6 +111,6 @@ inline constexpr auto unique_copy = __unique_copy::__fn{}; _LIBCPP_END_NAMESPACE_STD -#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#endif // _LIBCPP_STD_VER > 17 #endif // _LIBCPP___ALGORITHM_RANGES_UNIQUE_COPY_H diff --git a/lib/libcxx/include/__algorithm/ranges_upper_bound.h b/lib/libcxx/include/__algorithm/ranges_upper_bound.h index 3c63249248..a134080904 100644 --- a/lib/libcxx/include/__algorithm/ranges_upper_bound.h +++ b/lib/libcxx/include/__algorithm/ranges_upper_bound.h @@ -25,7 +25,7 @@ # pragma GCC system_header #endif -#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#if _LIBCPP_STD_VER > 17 _LIBCPP_BEGIN_NAMESPACE_STD @@ -34,7 +34,7 @@ namespace __upper_bound { struct __fn { template _Sent, class _Type, class _Proj = identity, indirect_strict_weak_order> _Comp = ranges::less> - _LIBCPP_HIDE_FROM_ABI constexpr + _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr _Iter operator()(_Iter __first, _Sent __last, const _Type& __value, _Comp __comp = {}, _Proj __proj = {}) const { auto __comp_lhs_rhs_swapped = [&](const auto& __lhs, const auto& __rhs) { return !std::invoke(__comp, __rhs, __lhs); @@ -45,7 +45,7 @@ struct __fn { template , _Proj>> _Comp = ranges::less> - _LIBCPP_HIDE_FROM_ABI constexpr + _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr borrowed_iterator_t<_Range> operator()(_Range&& __r, const _Type& __value, _Comp __comp = {}, @@ -70,6 +70,6 @@ inline namespace __cpo { _LIBCPP_END_NAMESPACE_STD -#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#endif // _LIBCPP_STD_VER > 17 #endif // _LIBCPP___ALGORITHM_RANGES_UPPER_BOUND_H diff --git a/lib/libcxx/include/__algorithm/remove.h b/lib/libcxx/include/__algorithm/remove.h index 8a7e99ba09..533e41b54f 100644 --- a/lib/libcxx/include/__algorithm/remove.h +++ b/lib/libcxx/include/__algorithm/remove.h @@ -21,7 +21,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD template -_LIBCPP_NODISCARD_EXT _LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator +_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator remove(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value) { __first = _VSTD::find(__first, __last, __value); diff --git a/lib/libcxx/include/__algorithm/remove_copy.h b/lib/libcxx/include/__algorithm/remove_copy.h index 55fc1d90a1..ecba08a053 100644 --- a/lib/libcxx/include/__algorithm/remove_copy.h +++ b/lib/libcxx/include/__algorithm/remove_copy.h @@ -18,7 +18,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD template -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator remove_copy(_InputIterator __first, _InputIterator __last, _OutputIterator __result, const _Tp& __value) { diff --git a/lib/libcxx/include/__algorithm/remove_copy_if.h b/lib/libcxx/include/__algorithm/remove_copy_if.h index 36ddba4883..2f235fd32f 100644 --- a/lib/libcxx/include/__algorithm/remove_copy_if.h +++ b/lib/libcxx/include/__algorithm/remove_copy_if.h @@ -18,7 +18,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD template -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator remove_copy_if(_InputIterator __first, _InputIterator __last, _OutputIterator __result, _Predicate __pred) { diff --git a/lib/libcxx/include/__algorithm/remove_if.h b/lib/libcxx/include/__algorithm/remove_if.h index 0ae131498d..27350728d2 100644 --- a/lib/libcxx/include/__algorithm/remove_if.h +++ b/lib/libcxx/include/__algorithm/remove_if.h @@ -20,7 +20,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD template -_LIBCPP_NODISCARD_EXT _LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator +_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator remove_if(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred) { __first = _VSTD::find_if<_ForwardIterator, _Predicate&>(__first, __last, __pred); diff --git a/lib/libcxx/include/__algorithm/replace.h b/lib/libcxx/include/__algorithm/replace.h index d0ae8f65d4..ce6215066f 100644 --- a/lib/libcxx/include/__algorithm/replace.h +++ b/lib/libcxx/include/__algorithm/replace.h @@ -18,7 +18,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD template -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 void replace(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __old_value, const _Tp& __new_value) { diff --git a/lib/libcxx/include/__algorithm/replace_copy.h b/lib/libcxx/include/__algorithm/replace_copy.h index 7c8a5a0b93..bebb14cbe2 100644 --- a/lib/libcxx/include/__algorithm/replace_copy.h +++ b/lib/libcxx/include/__algorithm/replace_copy.h @@ -18,7 +18,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD template -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator replace_copy(_InputIterator __first, _InputIterator __last, _OutputIterator __result, const _Tp& __old_value, const _Tp& __new_value) diff --git a/lib/libcxx/include/__algorithm/replace_copy_if.h b/lib/libcxx/include/__algorithm/replace_copy_if.h index 9d8a68fdc0..e1ddb527be 100644 --- a/lib/libcxx/include/__algorithm/replace_copy_if.h +++ b/lib/libcxx/include/__algorithm/replace_copy_if.h @@ -18,7 +18,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD template -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator replace_copy_if(_InputIterator __first, _InputIterator __last, _OutputIterator __result, _Predicate __pred, const _Tp& __new_value) diff --git a/lib/libcxx/include/__algorithm/replace_if.h b/lib/libcxx/include/__algorithm/replace_if.h index 37c719a34c..b3a3367d22 100644 --- a/lib/libcxx/include/__algorithm/replace_if.h +++ b/lib/libcxx/include/__algorithm/replace_if.h @@ -18,7 +18,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD template -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 void replace_if(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred, const _Tp& __new_value) { diff --git a/lib/libcxx/include/__algorithm/reverse.h b/lib/libcxx/include/__algorithm/reverse.h index 6484c73752..aa76951707 100644 --- a/lib/libcxx/include/__algorithm/reverse.h +++ b/lib/libcxx/include/__algorithm/reverse.h @@ -22,7 +22,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD template -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 void __reverse_impl(_BidirectionalIterator __first, _BidirectionalIterator __last, bidirectional_iterator_tag) { @@ -36,7 +36,7 @@ __reverse_impl(_BidirectionalIterator __first, _BidirectionalIterator __last, bi } template -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 void __reverse_impl(_RandomAccessIterator __first, _RandomAccessIterator __last, random_access_iterator_tag) { @@ -46,14 +46,14 @@ __reverse_impl(_RandomAccessIterator __first, _RandomAccessIterator __last, rand } template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __reverse(_BidirectionalIterator __first, _Sentinel __last) { using _IterCategory = typename _IterOps<_AlgPolicy>::template __iterator_category<_BidirectionalIterator>; std::__reverse_impl<_AlgPolicy>(std::move(__first), std::move(__last), _IterCategory()); } template -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 void reverse(_BidirectionalIterator __first, _BidirectionalIterator __last) { diff --git a/lib/libcxx/include/__algorithm/reverse_copy.h b/lib/libcxx/include/__algorithm/reverse_copy.h index 1583907078..f4a0e9713d 100644 --- a/lib/libcxx/include/__algorithm/reverse_copy.h +++ b/lib/libcxx/include/__algorithm/reverse_copy.h @@ -18,7 +18,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD template -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator reverse_copy(_BidirectionalIterator __first, _BidirectionalIterator __last, _OutputIterator __result) { diff --git a/lib/libcxx/include/__algorithm/rotate.h b/lib/libcxx/include/__algorithm/rotate.h index beb5409d5b..8934ce095b 100644 --- a/lib/libcxx/include/__algorithm/rotate.h +++ b/lib/libcxx/include/__algorithm/rotate.h @@ -26,7 +26,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD template -_LIBCPP_CONSTEXPR_AFTER_CXX11 _ForwardIterator +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _ForwardIterator __rotate_left(_ForwardIterator __first, _ForwardIterator __last) { typedef typename iterator_traits<_ForwardIterator>::value_type value_type; @@ -40,7 +40,7 @@ __rotate_left(_ForwardIterator __first, _ForwardIterator __last) } template -_LIBCPP_CONSTEXPR_AFTER_CXX11 _BidirectionalIterator +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _BidirectionalIterator __rotate_right(_BidirectionalIterator __first, _BidirectionalIterator __last) { typedef typename iterator_traits<_BidirectionalIterator>::value_type value_type; @@ -48,13 +48,13 @@ __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)); + _BidirectionalIterator __fp1 = std::__move_backward<_AlgPolicy>(__first, __lm1, std::move(__last)).second; *__first = _VSTD::move(__tmp); return __fp1; } template -_LIBCPP_CONSTEXPR_AFTER_CXX14 _ForwardIterator +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 _ForwardIterator __rotate_forward(_ForwardIterator __first, _ForwardIterator __middle, _ForwardIterator __last) { _ForwardIterator __i = __middle; @@ -90,7 +90,7 @@ __rotate_forward(_ForwardIterator __first, _ForwardIterator __middle, _ForwardIt template inline _LIBCPP_INLINE_VISIBILITY -_LIBCPP_CONSTEXPR_AFTER_CXX14 _Integral +_LIBCPP_CONSTEXPR_SINCE_CXX17 _Integral __algo_gcd(_Integral __x, _Integral __y) { do @@ -103,7 +103,7 @@ __algo_gcd(_Integral __x, _Integral __y) } template -_LIBCPP_CONSTEXPR_AFTER_CXX14 _RandomAccessIterator +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 _RandomAccessIterator __rotate_gcd(_RandomAccessIterator __first, _RandomAccessIterator __middle, _RandomAccessIterator __last) { typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type; @@ -140,7 +140,7 @@ __rotate_gcd(_RandomAccessIterator __first, _RandomAccessIterator __middle, _Ran template inline _LIBCPP_INLINE_VISIBILITY -_LIBCPP_CONSTEXPR_AFTER_CXX11 _ForwardIterator +_LIBCPP_CONSTEXPR_SINCE_CXX14 _ForwardIterator __rotate_impl(_ForwardIterator __first, _ForwardIterator __middle, _ForwardIterator __last, _VSTD::forward_iterator_tag) { @@ -155,7 +155,7 @@ __rotate_impl(_ForwardIterator __first, _ForwardIterator __middle, _ForwardItera template inline _LIBCPP_INLINE_VISIBILITY -_LIBCPP_CONSTEXPR_AFTER_CXX11 _BidirectionalIterator +_LIBCPP_CONSTEXPR_SINCE_CXX14 _BidirectionalIterator __rotate_impl(_BidirectionalIterator __first, _BidirectionalIterator __middle, _BidirectionalIterator __last, bidirectional_iterator_tag) { @@ -172,7 +172,7 @@ __rotate_impl(_BidirectionalIterator __first, _BidirectionalIterator __middle, _ template inline _LIBCPP_INLINE_VISIBILITY -_LIBCPP_CONSTEXPR_AFTER_CXX11 _RandomAccessIterator +_LIBCPP_CONSTEXPR_SINCE_CXX14 _RandomAccessIterator __rotate_impl(_RandomAccessIterator __first, _RandomAccessIterator __middle, _RandomAccessIterator __last, random_access_iterator_tag) { @@ -189,7 +189,7 @@ __rotate_impl(_RandomAccessIterator __first, _RandomAccessIterator __middle, _Ra } template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_Iterator, _Iterator> __rotate(_Iterator __first, _Iterator __middle, _Sentinel __last) { using _Ret = pair<_Iterator, _Iterator>; @@ -209,7 +209,7 @@ __rotate(_Iterator __first, _Iterator __middle, _Sentinel __last) { template inline _LIBCPP_INLINE_VISIBILITY -_LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator +_LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator rotate(_ForwardIterator __first, _ForwardIterator __middle, _ForwardIterator __last) { return std::__rotate<_ClassicAlgPolicy>( diff --git a/lib/libcxx/include/__algorithm/rotate_copy.h b/lib/libcxx/include/__algorithm/rotate_copy.h index ab569ef7c6..c154649ab9 100644 --- a/lib/libcxx/include/__algorithm/rotate_copy.h +++ b/lib/libcxx/include/__algorithm/rotate_copy.h @@ -19,7 +19,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD template -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator rotate_copy(_ForwardIterator __first, _ForwardIterator __middle, _ForwardIterator __last, _OutputIterator __result) { diff --git a/lib/libcxx/include/__algorithm/search.h b/lib/libcxx/include/__algorithm/search.h index 4ead6cac82..93771be39e 100644 --- a/lib/libcxx/include/__algorithm/search.h +++ b/lib/libcxx/include/__algorithm/search.h @@ -33,7 +33,7 @@ template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_Iter1, _Iter1> __search_forward_impl(_Iter1 __first1, _Sent1 __last1, _Iter2 __first2, _Sent2 __last2, _Pred& __pred, @@ -80,7 +80,7 @@ template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_Iter1, _Iter1> __search_random_access_impl(_Iter1 __first1, _Sent1 __last1, _Iter2 __first2, _Sent2 __last2, _Pred& __pred, @@ -120,7 +120,7 @@ template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_Iter1, _Iter1> __search_impl(_Iter1 __first1, _Sent1 __last1, _Iter2 __first2, _Sent2 __last2, _Pred& __pred, @@ -152,7 +152,7 @@ template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_Iter1, _Iter1> __search_impl(_Iter1 __first1, _Sent1 __last1, _Iter2 __first2, _Sent2 __last2, _Pred& __pred, @@ -170,7 +170,7 @@ pair<_Iter1, _Iter1> __search_impl(_Iter1 __first1, _Sent1 __last1, } template -_LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +_LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator1 search(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2, _ForwardIterator2 __last2, _BinaryPredicate __pred) { @@ -181,17 +181,15 @@ _ForwardIterator1 search(_ForwardIterator1 __first1, _ForwardIterator1 __last1, } template -_LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +_LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator1 search(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2, _ForwardIterator2 __last2) { - using __v1 = typename iterator_traits<_ForwardIterator1>::value_type; - using __v2 = typename iterator_traits<_ForwardIterator2>::value_type; - return std::search(__first1, __last1, __first2, __last2, __equal_to<__v1, __v2>()); + return std::search(__first1, __last1, __first2, __last2, __equal_to()); } #if _LIBCPP_STD_VER > 14 template -_LIBCPP_NODISCARD_EXT _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator +_LIBCPP_NODISCARD_EXT _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator search(_ForwardIterator __f, _ForwardIterator __l, const _Searcher& __s) { return __s(__f, __l).first; } diff --git a/lib/libcxx/include/__algorithm/search_n.h b/lib/libcxx/include/__algorithm/search_n.h index ccb8e845f5..60a0735651 100644 --- a/lib/libcxx/include/__algorithm/search_n.h +++ b/lib/libcxx/include/__algorithm/search_n.h @@ -19,6 +19,7 @@ #include <__iterator/distance.h> #include <__iterator/iterator_traits.h> #include <__ranges/concepts.h> +#include <__utility/convert_to_integral.h> #include <__utility/pair.h> #include // __convert_to_integral @@ -29,7 +30,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_Iter, _Iter> __search_n_forward_impl(_Iter __first, _Sent __last, _SizeT __count, const _Type& __value, @@ -71,7 +72,7 @@ pair<_Iter, _Iter> __search_n_forward_impl(_Iter __first, _Sent __last, } template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 std::pair<_Iter, _Iter> __search_n_random_access_impl(_Iter __first, _Sent __last, _SizeT __count, const _Type& __value, @@ -122,7 +123,7 @@ template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_Iter, _Iter> __search_n_impl(_Iter __first, _Sent __last, _DiffT __count, const _Type& __value, @@ -142,7 +143,7 @@ template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_Iter1, _Iter1> __search_n_impl(_Iter1 __first, _Sent1 __last, _DiffT __count, const _Type& __value, @@ -158,7 +159,7 @@ pair<_Iter1, _Iter1> __search_n_impl(_Iter1 __first, _Sent1 __last, } template -_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 +_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator search_n(_ForwardIterator __first, _ForwardIterator __last, _Size __count, const _Tp& __value, @@ -170,10 +171,9 @@ _ForwardIterator search_n(_ForwardIterator __first, _ForwardIterator __last, } template -_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 +_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator search_n(_ForwardIterator __first, _ForwardIterator __last, _Size __count, const _Tp& __value) { - typedef typename iterator_traits<_ForwardIterator>::value_type __v; - return std::search_n(__first, __last, std::__convert_to_integral(__count), __value, __equal_to<__v, _Tp>()); + return std::search_n(__first, __last, std::__convert_to_integral(__count), __value, __equal_to()); } _LIBCPP_END_NAMESPACE_STD diff --git a/lib/libcxx/include/__algorithm/set_difference.h b/lib/libcxx/include/__algorithm/set_difference.h index 4378bd5304..cffdc8fc4f 100644 --- a/lib/libcxx/include/__algorithm/set_difference.h +++ b/lib/libcxx/include/__algorithm/set_difference.h @@ -12,6 +12,7 @@ #include <__algorithm/comp.h> #include <__algorithm/comp_ref_type.h> #include <__algorithm/copy.h> +#include <__algorithm/iterator_operations.h> #include <__config> #include <__functional/identity.h> #include <__functional/invoke.h> @@ -26,8 +27,8 @@ _LIBCPP_BEGIN_NAMESPACE_STD -template < class _Comp, class _InIter1, class _Sent1, class _InIter2, class _Sent2, class _OutIter> -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 pair<__uncvref_t<_InIter1>, __uncvref_t<_OutIter> > +template +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<__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) { @@ -42,29 +43,30 @@ __set_difference( ++__first2; } } - return std::__copy(std::move(__first1), std::move(__last1), std::move(__result)); + return std::__copy<_AlgPolicy>(std::move(__first1), std::move(__last1), std::move(__result)); } template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 _OutputIterator set_difference( +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator set_difference( _InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result, _Compare __comp) { - typedef typename __comp_ref_type<_Compare>::type _Comp_ref; - return std::__set_difference<_Comp_ref>(__first1, __last1, __first2, __last2, __result, __comp).second; + return std::__set_difference<_ClassicAlgPolicy, __comp_ref_type<_Compare> >( + __first1, __last1, __first2, __last2, __result, __comp) + .second; } template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 _OutputIterator set_difference( +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator set_difference( _InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result) { - return std::__set_difference( + return std::__set_difference<_ClassicAlgPolicy>( __first1, __last1, __first2, diff --git a/lib/libcxx/include/__algorithm/set_intersection.h b/lib/libcxx/include/__algorithm/set_intersection.h index 77cc83738d..9fa7799aee 100644 --- a/lib/libcxx/include/__algorithm/set_intersection.h +++ b/lib/libcxx/include/__algorithm/set_intersection.h @@ -30,13 +30,13 @@ struct __set_intersection_result { _OutIter __out_; // need a constructor as C++03 aggregate init is hard - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __set_intersection_result(_InIter1&& __in_iter1, _InIter2&& __in_iter2, _OutIter&& __out_iter) : __in1_(std::move(__in_iter1)), __in2_(std::move(__in_iter2)), __out_(std::move(__out_iter)) {} }; template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 __set_intersection_result<_InIter1, _InIter2, _OutIter> +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __set_intersection_result<_InIter1, _InIter2, _OutIter> __set_intersection( _InIter1 __first1, _Sent1 __last1, _InIter2 __first2, _Sent2 __last2, _OutIter __result, _Compare&& __comp) { while (__first1 != __last1 && __first2 != __last2) { @@ -59,15 +59,14 @@ __set_intersection( } template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 _OutputIterator set_intersection( +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator set_intersection( _InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result, _Compare __comp) { - typedef typename __comp_ref_type<_Compare>::type _Comp_ref; - return std::__set_intersection<_ClassicAlgPolicy, _Comp_ref>( + return std::__set_intersection<_ClassicAlgPolicy, __comp_ref_type<_Compare> >( std::move(__first1), std::move(__last1), std::move(__first2), @@ -78,7 +77,7 @@ inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 _OutputIterator set_i } template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 _OutputIterator set_intersection( +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator set_intersection( _InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, diff --git a/lib/libcxx/include/__algorithm/set_symmetric_difference.h b/lib/libcxx/include/__algorithm/set_symmetric_difference.h index cd532ab580..bcb0958703 100644 --- a/lib/libcxx/include/__algorithm/set_symmetric_difference.h +++ b/lib/libcxx/include/__algorithm/set_symmetric_difference.h @@ -12,9 +12,11 @@ #include <__algorithm/comp.h> #include <__algorithm/comp_ref_type.h> #include <__algorithm/copy.h> +#include <__algorithm/iterator_operations.h> #include <__config> #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 @@ -29,18 +31,18 @@ struct __set_symmetric_difference_result { _OutIter __out_; // need a constructor as C++03 aggregate init is hard - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __set_symmetric_difference_result(_InIter1&& __in_iter1, _InIter2&& __in_iter2, _OutIter&& __out_iter) : __in1_(std::move(__in_iter1)), __in2_(std::move(__in_iter2)), __out_(std::move(__out_iter)) {} }; -template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 __set_symmetric_difference_result<_InIter1, _InIter2, _OutIter> +template +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __set_symmetric_difference_result<_InIter1, _InIter2, _OutIter> __set_symmetric_difference( _InIter1 __first1, _Sent1 __last1, _InIter2 __first2, _Sent2 __last2, _OutIter __result, _Compare&& __comp) { while (__first1 != __last1) { if (__first2 == __last2) { - auto __ret1 = std::__copy_impl(std::move(__first1), std::move(__last1), std::move(__result)); + auto __ret1 = std::__copy<_AlgPolicy>(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))); } @@ -58,21 +60,20 @@ __set_symmetric_difference( ++__first2; } } - auto __ret2 = std::__copy_impl(std::move(__first2), std::move(__last2), std::move(__result)); + auto __ret2 = std::__copy<_AlgPolicy>(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))); } template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 _OutputIterator set_symmetric_difference( +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator set_symmetric_difference( _InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result, _Compare __comp) { - typedef typename __comp_ref_type<_Compare>::type _Comp_ref; - return std::__set_symmetric_difference<_Comp_ref>( + return std::__set_symmetric_difference<_ClassicAlgPolicy, __comp_ref_type<_Compare> >( std::move(__first1), std::move(__last1), std::move(__first2), @@ -83,7 +84,7 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 _OutputIterator set_symmetri } template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 _OutputIterator set_symmetric_difference( +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator set_symmetric_difference( _InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, diff --git a/lib/libcxx/include/__algorithm/set_union.h b/lib/libcxx/include/__algorithm/set_union.h index 3bd4379801..4d154b81e0 100644 --- a/lib/libcxx/include/__algorithm/set_union.h +++ b/lib/libcxx/include/__algorithm/set_union.h @@ -12,9 +12,11 @@ #include <__algorithm/comp.h> #include <__algorithm/comp_ref_type.h> #include <__algorithm/copy.h> +#include <__algorithm/iterator_operations.h> #include <__config> #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 @@ -29,17 +31,17 @@ struct __set_union_result { _OutIter __out_; // need a constructor as C++03 aggregate init is hard - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __set_union_result(_InIter1&& __in_iter1, _InIter2&& __in_iter2, _OutIter&& __out_iter) : __in1_(std::move(__in_iter1)), __in2_(std::move(__in_iter2)), __out_(std::move(__out_iter)) {} }; -template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 __set_union_result<_InIter1, _InIter2, _OutIter> __set_union( +template +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __set_union_result<_InIter1, _InIter2, _OutIter> __set_union( _InIter1 __first1, _Sent1 __last1, _InIter2 __first2, _Sent2 __last2, _OutIter __result, _Compare&& __comp) { for (; __first1 != __last1; ++__result) { if (__first2 == __last2) { - auto __ret1 = std::__copy_impl(std::move(__first1), std::move(__last1), std::move(__result)); + auto __ret1 = std::__copy<_AlgPolicy>(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))); } @@ -54,21 +56,20 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 __set_union_result<_InIter1, ++__first1; } } - auto __ret2 = std::__copy_impl(std::move(__first2), std::move(__last2), std::move(__result)); + auto __ret2 = std::__copy<_AlgPolicy>(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))); } template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 _OutputIterator set_union( +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator set_union( _InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result, _Compare __comp) { - typedef typename __comp_ref_type<_Compare>::type _Comp_ref; - return std::__set_union<_Comp_ref>( + return std::__set_union<_ClassicAlgPolicy, __comp_ref_type<_Compare> >( std::move(__first1), std::move(__last1), std::move(__first2), @@ -79,7 +80,7 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 _OutputIterator set_union( } template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 _OutputIterator set_union( +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator set_union( _InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, diff --git a/lib/libcxx/include/__algorithm/shuffle.h b/lib/libcxx/include/__algorithm/shuffle.h index e32c6a7608..f7bce68697 100644 --- a/lib/libcxx/include/__algorithm/shuffle.h +++ b/lib/libcxx/include/__algorithm/shuffle.h @@ -16,6 +16,7 @@ #include <__random/uniform_int_distribution.h> #include <__utility/forward.h> #include <__utility/move.h> +#include <__utility/swap.h> #include #include @@ -31,9 +32,9 @@ _LIBCPP_BEGIN_NAMESPACE_STD class _LIBCPP_TYPE_VIS __libcpp_debug_randomizer { public: __libcpp_debug_randomizer() { - __state = __seed(); - __inc = __state + 0xda3e39cb94b95bdbULL; - __inc = (__inc << 1) | 1; + __state_ = __seed(); + __inc_ = __state_ + 0xda3e39cb94b95bdbULL; + __inc_ = (__inc_ << 1) | 1; } typedef uint_fast32_t result_type; @@ -41,8 +42,8 @@ public: static const result_type _Max = 0xFFFFFFFF; _LIBCPP_HIDE_FROM_ABI result_type operator()() { - uint_fast64_t __oldstate = __state; - __state = __oldstate * 6364136223846793005ULL + __inc; + uint_fast64_t __oldstate = __state_; + __state_ = __oldstate * 6364136223846793005ULL + __inc_; return __oldstate >> 32; } @@ -50,8 +51,8 @@ public: static _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR result_type max() { return _Max; } private: - uint_fast64_t __state; - uint_fast64_t __inc; + uint_fast64_t __state_; + uint_fast64_t __inc_; _LIBCPP_HIDE_FROM_ABI static uint_fast64_t __seed() { #ifdef _LIBCPP_DEBUG_RANDOMIZE_UNSPECIFIED_STABILITY_SEED return _LIBCPP_DEBUG_RANDOMIZE_UNSPECIFIED_STABILITY_SEED; @@ -93,7 +94,7 @@ public: _LIBCPP_FUNC_VIS __rs_default __rs_get(); template -_LIBCPP_DEPRECATED_IN_CXX14 void +_LIBCPP_HIDE_FROM_ABI _LIBCPP_DEPRECATED_IN_CXX14 void random_shuffle(_RandomAccessIterator __first, _RandomAccessIterator __last) { typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type; @@ -114,7 +115,7 @@ random_shuffle(_RandomAccessIterator __first, _RandomAccessIterator __last) } template -_LIBCPP_DEPRECATED_IN_CXX14 void +_LIBCPP_HIDE_FROM_ABI _LIBCPP_DEPRECATED_IN_CXX14 void random_shuffle(_RandomAccessIterator __first, _RandomAccessIterator __last, #ifndef _LIBCPP_CXX03_LANG _RandomNumberGenerator&& __rand) @@ -137,7 +138,7 @@ random_shuffle(_RandomAccessIterator __first, _RandomAccessIterator __last, #endif template -_RandomAccessIterator __shuffle( +_LIBCPP_HIDE_FROM_ABI _RandomAccessIterator __shuffle( _RandomAccessIterator __first, _Sentinel __last_sentinel, _UniformRandomNumberGenerator&& __g) { typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type; typedef uniform_int_distribution _Dp; @@ -161,8 +162,8 @@ _RandomAccessIterator __shuffle( } template -void shuffle(_RandomAccessIterator __first, _RandomAccessIterator __last, - _UniformRandomNumberGenerator&& __g) { +_LIBCPP_HIDE_FROM_ABI void +shuffle(_RandomAccessIterator __first, _RandomAccessIterator __last, _UniformRandomNumberGenerator&& __g) { (void)std::__shuffle<_ClassicAlgPolicy>( std::move(__first), std::move(__last), std::forward<_UniformRandomNumberGenerator>(__g)); } diff --git a/lib/libcxx/include/__algorithm/sift_down.h b/lib/libcxx/include/__algorithm/sift_down.h index 06811239f8..e3972fb6f4 100644 --- a/lib/libcxx/include/__algorithm/sift_down.h +++ b/lib/libcxx/include/__algorithm/sift_down.h @@ -22,7 +22,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD template -_LIBCPP_CONSTEXPR_AFTER_CXX11 void +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void __sift_down(_RandomAccessIterator __first, _Compare&& __comp, typename iterator_traits<_RandomAccessIterator>::difference_type __len, _RandomAccessIterator __start) @@ -78,7 +78,7 @@ __sift_down(_RandomAccessIterator __first, _Compare&& __comp, } template -_LIBCPP_CONSTEXPR_AFTER_CXX11 _RandomAccessIterator +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _RandomAccessIterator __floyd_sift_down(_RandomAccessIterator __first, _Compare&& __comp, typename iterator_traits<_RandomAccessIterator>::difference_type __len) { diff --git a/lib/libcxx/include/__algorithm/sort.h b/lib/libcxx/include/__algorithm/sort.h index 1ca2f1b817..a7d2d55a06 100644 --- a/lib/libcxx/include/__algorithm/sort.h +++ b/lib/libcxx/include/__algorithm/sort.h @@ -11,19 +11,29 @@ #include <__algorithm/comp.h> #include <__algorithm/comp_ref_type.h> +#include <__algorithm/iter_swap.h> #include <__algorithm/iterator_operations.h> #include <__algorithm/min_element.h> #include <__algorithm/partial_sort.h> #include <__algorithm/unwrap_iter.h> -#include <__bits> +#include <__assert> +#include <__bit/blsr.h> +#include <__bit/countl.h> +#include <__bit/countr.h> #include <__config> #include <__debug> #include <__debug_utils/randomize_range.h> #include <__functional/operations.h> #include <__functional/ranges_operations.h> #include <__iterator/iterator_traits.h> +#include <__memory/destruct_n.h> +#include <__memory/unique_ptr.h> +#include <__type_traits/conditional.h> +#include <__type_traits/is_arithmetic.h> +#include <__utility/move.h> +#include <__utility/pair.h> #include -#include +#include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header @@ -43,7 +53,7 @@ struct _WrapAlgPolicy { using _Comp = _CompT; _Comp& __comp; - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _WrapAlgPolicy(_Comp& __c) : __comp(__c) {} }; @@ -62,7 +72,7 @@ struct _UnwrapAlgPolicy { using _AlgPolicy = _ClassicAlgPolicy; using _Comp = _CompT; - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 static + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 static _Comp __get_comp(_Comp __comp) { return __comp; } }; @@ -73,14 +83,15 @@ struct _UnwrapAlgPolicy<_WrapAlgPolicy<_Ts...> > { using _AlgPolicy = typename _Wrapped::_AlgPolicy; using _Comp = typename _Wrapped::_Comp; - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 static + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 static _Comp __get_comp(_Wrapped& __w) { return __w.__comp; } }; // stable, 2-3 compares, 0-2 swaps template -_LIBCPP_CONSTEXPR_AFTER_CXX11 unsigned __sort3(_ForwardIterator __x, _ForwardIterator __y, _ForwardIterator __z, +_LIBCPP_HIDE_FROM_ABI +_LIBCPP_CONSTEXPR_SINCE_CXX14 unsigned __sort3(_ForwardIterator __x, _ForwardIterator __y, _ForwardIterator __z, _Compare __c) { using _Ops = _IterOps<_AlgPolicy>; @@ -118,10 +129,10 @@ _LIBCPP_CONSTEXPR_AFTER_CXX11 unsigned __sort3(_ForwardIterator __x, _ForwardIte // stable, 3-6 compares, 0-5 swaps template +_LIBCPP_HIDE_FROM_ABI unsigned __sort4(_ForwardIterator __x1, _ForwardIterator __x2, _ForwardIterator __x3, _ForwardIterator __x4, _Compare __c) { - using _Ops = _IterOps<_AlgPolicy>; - + using _Ops = _IterOps<_AlgPolicy>; unsigned __r = std::__sort3<_AlgPolicy, _Compare>(__x1, __x2, __x3, __c); if (__c(*__x4, *__x3)) { _Ops::iter_swap(__x3, __x4); @@ -171,12 +182,12 @@ _LIBCPP_HIDDEN unsigned __sort5(_ForwardIterator __x1, _ForwardIterator __x2, _F } template -_LIBCPP_HIDDEN unsigned __sort5_wrap_policy( +_LIBCPP_HIDE_FROM_ABI unsigned __sort5_wrap_policy( _ForwardIterator __x1, _ForwardIterator __x2, _ForwardIterator __x3, _ForwardIterator __x4, _ForwardIterator __x5, _Compare __c) { using _WrappedComp = typename _WrapAlgPolicy<_AlgPolicy, _Compare>::type; _WrappedComp __wrapped_comp(__c); - return std::__sort5<_WrappedComp>( + return std::__sort5<_WrappedComp, _ForwardIterator>( std::move(__x1), std::move(__x2), std::move(__x3), std::move(__x4), std::move(__x5), __wrapped_comp); } @@ -201,6 +212,13 @@ using __use_branchless_sort = integral_constant::value && sizeof(_Tp) <= sizeof(void*) && is_arithmetic<_Tp>::value && __is_simple_comparator<_Compare>::value>; +namespace __detail { + +// Size in bits for the bitset in use. +enum { __block_size = sizeof(uint64_t) * 8 }; + +} // namespace __detail + // Ensures that __c(*__x, *__y) is true by swapping *__x and *__y if necessary. template inline _LIBCPP_HIDE_FROM_ABI void __cond_swap(_RandomAccessIterator __x, _RandomAccessIterator __y, _Compare __c) { @@ -231,8 +249,8 @@ template inline _LIBCPP_HIDE_FROM_ABI __enable_if_t<__use_branchless_sort<_Compare, _RandomAccessIterator>::value, void> __sort3_maybe_branchless(_RandomAccessIterator __x1, _RandomAccessIterator __x2, _RandomAccessIterator __x3, _Compare __c) { - _VSTD::__cond_swap<_Compare>(__x2, __x3, __c); - _VSTD::__partially_sorted_swap<_Compare>(__x1, __x2, __x3, __c); + std::__cond_swap<_Compare>(__x2, __x3, __c); + std::__partially_sorted_swap<_Compare>(__x1, __x2, __x3, __c); } template @@ -246,11 +264,11 @@ template inline _LIBCPP_HIDE_FROM_ABI __enable_if_t<__use_branchless_sort<_Compare, _RandomAccessIterator>::value, void> __sort4_maybe_branchless(_RandomAccessIterator __x1, _RandomAccessIterator __x2, _RandomAccessIterator __x3, _RandomAccessIterator __x4, _Compare __c) { - _VSTD::__cond_swap<_Compare>(__x1, __x3, __c); - _VSTD::__cond_swap<_Compare>(__x2, __x4, __c); - _VSTD::__cond_swap<_Compare>(__x1, __x2, __c); - _VSTD::__cond_swap<_Compare>(__x3, __x4, __c); - _VSTD::__cond_swap<_Compare>(__x2, __x3, __c); + std::__cond_swap<_Compare>(__x1, __x3, __c); + std::__cond_swap<_Compare>(__x2, __x4, __c); + std::__cond_swap<_Compare>(__x1, __x2, __c); + std::__cond_swap<_Compare>(__x3, __x4, __c); + std::__cond_swap<_Compare>(__x2, __x3, __c); } template @@ -260,16 +278,21 @@ __sort4_maybe_branchless(_RandomAccessIterator __x1, _RandomAccessIterator __x2, std::__sort4<_AlgPolicy, _Compare>(__x1, __x2, __x3, __x4, __c); } -template +template inline _LIBCPP_HIDE_FROM_ABI __enable_if_t<__use_branchless_sort<_Compare, _RandomAccessIterator>::value, void> -__sort5_maybe_branchless(_RandomAccessIterator __x1, _RandomAccessIterator __x2, _RandomAccessIterator __x3, - _RandomAccessIterator __x4, _RandomAccessIterator __x5, _Compare __c) { - _VSTD::__cond_swap<_Compare>(__x1, __x2, __c); - _VSTD::__cond_swap<_Compare>(__x4, __x5, __c); - _VSTD::__partially_sorted_swap<_Compare>(__x3, __x4, __x5, __c); - _VSTD::__cond_swap<_Compare>(__x2, __x5, __c); - _VSTD::__partially_sorted_swap<_Compare>(__x1, __x3, __x4, __c); - _VSTD::__partially_sorted_swap<_Compare>(__x2, __x3, __x4, __c); +__sort5_maybe_branchless( + _RandomAccessIterator __x1, + _RandomAccessIterator __x2, + _RandomAccessIterator __x3, + _RandomAccessIterator __x4, + _RandomAccessIterator __x5, + _Compare __c) { + std::__cond_swap<_Compare>(__x1, __x2, __c); + std::__cond_swap<_Compare>(__x4, __x5, __c); + std::__partially_sorted_swap<_Compare>(__x3, __x4, __x5, __c); + std::__cond_swap<_Compare>(__x2, __x5, __c); + std::__partially_sorted_swap<_Compare>(__x1, __x3, __x4, __c); + std::__partially_sorted_swap<_Compare>(__x2, __x3, __x4, __c); } template @@ -281,7 +304,8 @@ __sort5_maybe_branchless(_RandomAccessIterator __x1, _RandomAccessIterator __x2, // Assumes size > 0 template -_LIBCPP_CONSTEXPR_AFTER_CXX11 void __selection_sort(_BidirectionalIterator __first, _BidirectionalIterator __last, +_LIBCPP_HIDE_FROM_ABI +_LIBCPP_CONSTEXPR_SINCE_CXX14 void __selection_sort(_BidirectionalIterator __first, _BidirectionalIterator __last, _Compare __comp) { _BidirectionalIterator __lm1 = __last; for (--__lm1; __first != __lm1; ++__first) { @@ -291,32 +315,48 @@ _LIBCPP_CONSTEXPR_AFTER_CXX11 void __selection_sort(_BidirectionalIterator __fir } } +// Sort the iterator range [__first, __last) using the comparator __comp using +// the insertion sort algorithm. template +_LIBCPP_HIDE_FROM_ABI void __insertion_sort(_BidirectionalIterator __first, _BidirectionalIterator __last, _Compare __comp) { using _Ops = _IterOps<_AlgPolicy>; typedef typename iterator_traits<_BidirectionalIterator>::value_type value_type; - if (__first != __last) { - _BidirectionalIterator __i = __first; - for (++__i; __i != __last; ++__i) { - _BidirectionalIterator __j = __i; - value_type __t(_Ops::__iter_move(__j)); - for (_BidirectionalIterator __k = __i; __k != __first && __comp(__t, *--__k); --__j) + if (__first == __last) + return; + _BidirectionalIterator __i = __first; + for (++__i; __i != __last; ++__i) { + _BidirectionalIterator __j = __i; + --__j; + if (__comp(*__i, *__j)) { + value_type __t(_Ops::__iter_move(__i)); + _BidirectionalIterator __k = __j; + __j = __i; + do { *__j = _Ops::__iter_move(__k); - *__j = _VSTD::move(__t); + __j = __k; + } while (__j != __first && __comp(__t, *--__k)); + *__j = std::move(__t); } } } +// Sort the iterator range [__first, __last) using the comparator __comp using +// the insertion sort algorithm. Insertion sort has two loops, outer and inner. +// The implementation below has not bounds check (unguarded) for the inner loop. +// Assumes that there is an element in the position (__first - 1) and that each +// element in the input range is greater or equal to the element at __first - 1. template -void __insertion_sort_3(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) { +_LIBCPP_HIDE_FROM_ABI void +__insertion_sort_unguarded(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) { using _Ops = _IterOps<_AlgPolicy>; - typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type; typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type; - _RandomAccessIterator __j = __first + difference_type(2); - std::__sort3_maybe_branchless<_AlgPolicy, _Compare>(__first, __first + difference_type(1), __j, __comp); - for (_RandomAccessIterator __i = __j + difference_type(1); __i != __last; ++__i) { + if (__first == __last) + return; + for (_RandomAccessIterator __i = __first + difference_type(1); __i != __last; ++__i) { + _RandomAccessIterator __j = __i - difference_type(1); if (__comp(*__i, *__j)) { value_type __t(_Ops::__iter_move(__i)); _RandomAccessIterator __k = __j; @@ -324,15 +364,14 @@ void __insertion_sort_3(_RandomAccessIterator __first, _RandomAccessIterator __l do { *__j = _Ops::__iter_move(__k); __j = __k; - } while (__j != __first && __comp(__t, *--__k)); - *__j = _VSTD::move(__t); + } while (__comp(__t, *--__k)); // No need for bounds check due to the assumption stated above. + *__j = std::move(__t); } - __j = __i; } } template -bool __insertion_sort_incomplete( +_LIBCPP_HIDDEN bool __insertion_sort_incomplete( _RandomAccessIterator __first, _RandomAccessIterator __last, _WrappedComp __wrapped_comp) { using _Unwrap = _UnwrapAlgPolicy<_WrappedComp>; using _AlgPolicy = typename _Unwrap::_AlgPolicy; @@ -348,7 +387,7 @@ bool __insertion_sort_incomplete( return true; case 2: if (__comp(*--__last, *__first)) - _IterOps<_AlgPolicy>::iter_swap(__first, __last); + _Ops::iter_swap(__first, __last); return true; case 3: std::__sort3_maybe_branchless<_AlgPolicy, _Compare>(__first, __first + difference_type(1), --__last, __comp); @@ -377,7 +416,7 @@ bool __insertion_sort_incomplete( *__j = _Ops::__iter_move(__k); __j = __k; } while (__j != __first && __comp(__t, *--__k)); - *__j = _VSTD::move(__t); + *__j = std::move(__t); if (++__count == __limit) return ++__i == __last; } @@ -387,6 +426,7 @@ bool __insertion_sort_incomplete( } template +_LIBCPP_HIDE_FROM_ABI void __insertion_sort_move(_BidirectionalIterator __first1, _BidirectionalIterator __last1, typename iterator_traits<_BidirectionalIterator>::value_type* __first2, _Compare __comp) { using _Ops = _IterOps<_AlgPolicy>; @@ -416,17 +456,336 @@ void __insertion_sort_move(_BidirectionalIterator __first1, _BidirectionalIterat } } -template -void __introsort(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp, - typename iterator_traits<_RandomAccessIterator>::difference_type __depth) { +template +inline _LIBCPP_HIDE_FROM_ABI void __swap_bitmap_pos( + _RandomAccessIterator __first, _RandomAccessIterator __last, uint64_t& __left_bitset, uint64_t& __right_bitset) { using _Ops = _IterOps<_AlgPolicy>; + typedef typename std::iterator_traits<_RandomAccessIterator>::difference_type difference_type; + // Swap one pair on each iteration as long as both bitsets have at least one + // element for swapping. + while (__left_bitset != 0 && __right_bitset != 0) { + difference_type tz_left = __libcpp_ctz(__left_bitset); + __left_bitset = __libcpp_blsr(__left_bitset); + difference_type tz_right = __libcpp_ctz(__right_bitset); + __right_bitset = __libcpp_blsr(__right_bitset); + _Ops::iter_swap(__first + tz_left, __last - tz_right); + } +} +template ::value_type> +inline _LIBCPP_HIDE_FROM_ABI void +__populate_left_bitset(_RandomAccessIterator __first, _Compare __comp, _ValueType& __pivot, uint64_t& __left_bitset) { + // Possible vectorization. With a proper "-march" flag, the following loop + // will be compiled into a set of SIMD instructions. + _RandomAccessIterator __iter = __first; + for (int __j = 0; __j < __detail::__block_size;) { + bool __comp_result = !__comp(*__iter, __pivot); + __left_bitset |= (static_cast(__comp_result) << __j); + __j++; + ++__iter; + } +} + +template ::value_type> +inline _LIBCPP_HIDE_FROM_ABI void +__populate_right_bitset(_RandomAccessIterator __lm1, _Compare __comp, _ValueType& __pivot, uint64_t& __right_bitset) { + // Possible vectorization. With a proper "-march" flag, the following loop + // will be compiled into a set of SIMD instructions. + _RandomAccessIterator __iter = __lm1; + for (int __j = 0; __j < __detail::__block_size;) { + bool __comp_result = __comp(*__iter, __pivot); + __right_bitset |= (static_cast(__comp_result) << __j); + __j++; + --__iter; + } +} + +template ::value_type> +inline _LIBCPP_HIDE_FROM_ABI void __bitset_partition_partial_blocks( + _RandomAccessIterator& __first, + _RandomAccessIterator& __lm1, + _Compare __comp, + _ValueType& __pivot, + uint64_t& __left_bitset, + uint64_t& __right_bitset) { + typedef typename std::iterator_traits<_RandomAccessIterator>::difference_type difference_type; + difference_type __remaining_len = __lm1 - __first + 1; + difference_type __l_size; + difference_type __r_size; + if (__left_bitset == 0 && __right_bitset == 0) { + __l_size = __remaining_len / 2; + __r_size = __remaining_len - __l_size; + } else if (__left_bitset == 0) { + // We know at least one side is a full block. + __l_size = __remaining_len - __detail::__block_size; + __r_size = __detail::__block_size; + } else { // if (__right_bitset == 0) + __l_size = __detail::__block_size; + __r_size = __remaining_len - __detail::__block_size; + } + // Record the comparison outcomes for the elements currently on the left side. + if (__left_bitset == 0) { + _RandomAccessIterator __iter = __first; + for (int j = 0; j < __l_size; j++) { + bool __comp_result = !__comp(*__iter, __pivot); + __left_bitset |= (static_cast(__comp_result) << j); + ++__iter; + } + } + // Record the comparison outcomes for the elements currently on the right + // side. + if (__right_bitset == 0) { + _RandomAccessIterator __iter = __lm1; + for (int j = 0; j < __r_size; j++) { + bool __comp_result = __comp(*__iter, __pivot); + __right_bitset |= (static_cast(__comp_result) << j); + --__iter; + } + } + std::__swap_bitmap_pos<_AlgPolicy, _RandomAccessIterator>(__first, __lm1, __left_bitset, __right_bitset); + __first += (__left_bitset == 0) ? __l_size : 0; + __lm1 -= (__right_bitset == 0) ? __r_size : 0; +} + +template +inline _LIBCPP_HIDE_FROM_ABI void __swap_bitmap_pos_within( + _RandomAccessIterator& __first, _RandomAccessIterator& __lm1, uint64_t& __left_bitset, uint64_t& __right_bitset) { + using _Ops = _IterOps<_AlgPolicy>; + typedef typename std::iterator_traits<_RandomAccessIterator>::difference_type difference_type; + if (__left_bitset) { + // Swap within the left side. Need to find set positions in the reverse + // order. + while (__left_bitset != 0) { + difference_type __tz_left = __detail::__block_size - 1 - __libcpp_clz(__left_bitset); + __left_bitset &= (static_cast(1) << __tz_left) - 1; + _RandomAccessIterator it = __first + __tz_left; + if (it != __lm1) { + _Ops::iter_swap(it, __lm1); + } + --__lm1; + } + __first = __lm1 + difference_type(1); + } else if (__right_bitset) { + // Swap within the right side. Need to find set positions in the reverse + // order. + while (__right_bitset != 0) { + difference_type __tz_right = __detail::__block_size - 1 - __libcpp_clz(__right_bitset); + __right_bitset &= (static_cast(1) << __tz_right) - 1; + _RandomAccessIterator it = __lm1 - __tz_right; + if (it != __first) { + _Ops::iter_swap(it, __first); + } + ++__first; + } + } +} + +// Partition [__first, __last) using the comparator __comp. *__first has the +// chosen pivot. Elements that are equivalent are kept to the left of the +// pivot. Returns the iterator for the pivot and a bool value which is true if +// the provided range is already sorted, false otherwise. We assume that the +// length of the range is at least three elements. +// +// __bitset_partition uses bitsets for storing outcomes of the comparisons +// between the pivot and other elements. +template +_LIBCPP_HIDE_FROM_ABI std::pair<_RandomAccessIterator, bool> +__bitset_partition(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) { + using _Ops = _IterOps<_AlgPolicy>; + typedef typename std::iterator_traits<_RandomAccessIterator>::value_type value_type; + typedef typename std::iterator_traits<_RandomAccessIterator>::difference_type difference_type; + _LIBCPP_ASSERT(__last - __first >= difference_type(3), ""); + + _RandomAccessIterator __begin = __first; + value_type __pivot(_Ops::__iter_move(__first)); + // Find the first element greater than the pivot. + if (__comp(__pivot, *(__last - difference_type(1)))) { + // Not guarded since we know the last element is greater than the pivot. + while (!__comp(__pivot, *++__first)) { + } + } else { + while (++__first < __last && !__comp(__pivot, *__first)) { + } + } + // Find the last element less than or equal to the pivot. + if (__first < __last) { + // It will be always guarded because __introsort will do the median-of-three + // before calling this. + while (__comp(__pivot, *--__last)) { + } + } + // If the first element greater than the pivot is at or after the + // last element less than or equal to the pivot, then we have covered the + // entire range without swapping elements. This implies the range is already + // partitioned. + bool __already_partitioned = __first >= __last; + if (!__already_partitioned) { + _Ops::iter_swap(__first, __last); + ++__first; + } + + // In [__first, __last) __last is not inclusive. From now on, it uses last + // minus one to be inclusive on both sides. + _RandomAccessIterator __lm1 = __last - difference_type(1); + uint64_t __left_bitset = 0; + uint64_t __right_bitset = 0; + + // Reminder: length = __lm1 - __first + 1. + while (__lm1 - __first >= 2 * __detail::__block_size - 1) { + // Record the comparison outcomes for the elements currently on the left + // side. + if (__left_bitset == 0) + std::__populate_left_bitset<_Compare>(__first, __comp, __pivot, __left_bitset); + // Record the comparison outcomes for the elements currently on the right + // side. + if (__right_bitset == 0) + std::__populate_right_bitset<_Compare>(__lm1, __comp, __pivot, __right_bitset); + // Swap the elements recorded to be the candidates for swapping in the + // bitsets. + std::__swap_bitmap_pos<_AlgPolicy, _RandomAccessIterator>(__first, __lm1, __left_bitset, __right_bitset); + // Only advance the iterator if all the elements that need to be moved to + // other side were moved. + __first += (__left_bitset == 0) ? difference_type(__detail::__block_size) : difference_type(0); + __lm1 -= (__right_bitset == 0) ? difference_type(__detail::__block_size) : difference_type(0); + } + // Now, we have a less-than a block worth of elements on at least one of the + // sides. + std::__bitset_partition_partial_blocks<_AlgPolicy, _Compare>( + __first, __lm1, __comp, __pivot, __left_bitset, __right_bitset); + // At least one the bitsets would be empty. For the non-empty one, we need to + // properly partition the elements that appear within that bitset. + std::__swap_bitmap_pos_within<_AlgPolicy>(__first, __lm1, __left_bitset, __right_bitset); + + // Move the pivot to its correct position. + _RandomAccessIterator __pivot_pos = __first - difference_type(1); + if (__begin != __pivot_pos) { + *__begin = _Ops::__iter_move(__pivot_pos); + } + *__pivot_pos = std::move(__pivot); + return std::make_pair(__pivot_pos, __already_partitioned); +} + +// Partition [__first, __last) using the comparator __comp. *__first has the +// chosen pivot. Elements that are equivalent are kept to the right of the +// pivot. Returns the iterator for the pivot and a bool value which is true if +// the provided range is already sorted, false otherwise. We assume that the +// length of the range is at least three elements. +template +_LIBCPP_HIDE_FROM_ABI std::pair<_RandomAccessIterator, bool> +__partition_with_equals_on_right(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) { + using _Ops = _IterOps<_AlgPolicy>; typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type; - typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type; - const difference_type __limit = - is_trivially_copy_constructible::value && is_trivially_copy_assignable::value ? 30 : 6; + typedef typename std::iterator_traits<_RandomAccessIterator>::value_type value_type; + _LIBCPP_ASSERT(__last - __first >= difference_type(3), ""); + _RandomAccessIterator __begin = __first; + value_type __pivot(_Ops::__iter_move(__first)); + // Find the first element greater or equal to the pivot. It will be always + // guarded because __introsort will do the median-of-three before calling + // this. + while (__comp(*++__first, __pivot)) + ; + + // Find the last element less than the pivot. + if (__begin == __first - difference_type(1)) { + while (__first < __last && !__comp(*--__last, __pivot)) + ; + } else { + // Guarded. + while (!__comp(*--__last, __pivot)) + ; + } + + // If the first element greater than or equal to the pivot is at or after the + // last element less than the pivot, then we have covered the entire range + // without swapping elements. This implies the range is already partitioned. + bool __already_partitioned = __first >= __last; + // Go through the remaining elements. Swap pairs of elements (one to the + // right of the pivot and the other to left of the pivot) that are not on the + // correct side of the pivot. + while (__first < __last) { + _Ops::iter_swap(__first, __last); + while (__comp(*++__first, __pivot)) + ; + while (!__comp(*--__last, __pivot)) + ; + } + // Move the pivot to its correct position. + _RandomAccessIterator __pivot_pos = __first - difference_type(1); + if (__begin != __pivot_pos) { + *__begin = _Ops::__iter_move(__pivot_pos); + } + *__pivot_pos = std::move(__pivot); + return std::make_pair(__pivot_pos, __already_partitioned); +} + +// Similar to the above function. Elements equivalent to the pivot are put to +// the left of the pivot. Returns the iterator to the pivot element. +template +_LIBCPP_HIDE_FROM_ABI _RandomAccessIterator +__partition_with_equals_on_left(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) { + using _Ops = _IterOps<_AlgPolicy>; + typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type; + typedef typename std::iterator_traits<_RandomAccessIterator>::value_type value_type; + _RandomAccessIterator __begin = __first; + value_type __pivot(_Ops::__iter_move(__first)); + if (__comp(__pivot, *(__last - difference_type(1)))) { + // Guarded. + while (!__comp(__pivot, *++__first)) { + } + } else { + while (++__first < __last && !__comp(__pivot, *__first)) { + } + } + + if (__first < __last) { + // It will be always guarded because __introsort will do the + // median-of-three before calling this. + while (__comp(__pivot, *--__last)) { + } + } + while (__first < __last) { + _Ops::iter_swap(__first, __last); + while (!__comp(__pivot, *++__first)) + ; + while (__comp(__pivot, *--__last)) + ; + } + _RandomAccessIterator __pivot_pos = __first - difference_type(1); + if (__begin != __pivot_pos) { + *__begin = _Ops::__iter_move(__pivot_pos); + } + *__pivot_pos = std::move(__pivot); + return __first; +} + +// The main sorting function. Implements introsort combined with other ideas: +// - option of using block quick sort for partitioning, +// - guarded and unguarded insertion sort for small lengths, +// - Tuckey's ninther technique for computing the pivot, +// - check on whether partition was not required. +// The implementation is partly based on Orson Peters' pattern-defeating +// quicksort, published at: . +template +void __introsort(_RandomAccessIterator __first, + _RandomAccessIterator __last, + _Compare __comp, + typename iterator_traits<_RandomAccessIterator>::difference_type __depth, + bool __leftmost = true) { + using _Ops = _IterOps<_AlgPolicy>; + typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type; + using _Comp_ref = __comp_ref_type<_Compare>; + // Upper bound for using insertion sort for sorting. + _LIBCPP_CONSTEXPR difference_type __limit = 24; + // Lower bound for using Tuckey's ninther technique for median computation. + _LIBCPP_CONSTEXPR difference_type __ninther_threshold = 128; while (true) { - __restart: difference_type __len = __last - __first; switch (__len) { case 0: @@ -434,7 +793,7 @@ void __introsort(_RandomAccessIterator __first, _RandomAccessIterator __last, _C return; case 2: if (__comp(*--__last, *__first)) - _IterOps<_AlgPolicy>::iter_swap(__first, __last); + _Ops::iter_swap(__first, __last); return; case 3: std::__sort3_maybe_branchless<_AlgPolicy, _Compare>(__first, __first + difference_type(1), --__last, __comp); @@ -449,127 +808,60 @@ void __introsort(_RandomAccessIterator __first, _RandomAccessIterator __last, _C --__last, __comp); return; } - if (__len <= __limit) { - std::__insertion_sort_3<_AlgPolicy, _Compare>(__first, __last, __comp); + // Use insertion sort if the length of the range is below the specified limit. + if (__len < __limit) { + if (__leftmost) { + std::__insertion_sort<_AlgPolicy, _Compare>(__first, __last, __comp); + } else { + std::__insertion_sort_unguarded<_AlgPolicy, _Compare>(__first, __last, __comp); + } return; } - // __len > 5 if (__depth == 0) { // Fallback to heap sort as Introsort suggests. std::__partial_sort<_AlgPolicy, _Compare>(__first, __last, __last, __comp); return; } --__depth; - _RandomAccessIterator __m = __first; - _RandomAccessIterator __lm1 = __last; - --__lm1; - unsigned __n_swaps; { - difference_type __delta; - if (__len >= 1000) { - __delta = __len / 2; - __m += __delta; - __delta /= 2; - __n_swaps = std::__sort5_wrap_policy<_AlgPolicy, _Compare>( - __first, __first + __delta, __m, __m + __delta, __lm1, __comp); + difference_type __half_len = __len / 2; + // Use Tuckey's ninther technique or median of 3 for pivot selection + // depending on the length of the range being sorted. + if (__len > __ninther_threshold) { + std::__sort3<_AlgPolicy, _Compare>(__first, __first + __half_len, __last - difference_type(1), __comp); + std::__sort3<_AlgPolicy, _Compare>( + __first + difference_type(1), __first + (__half_len - 1), __last - difference_type(2), __comp); + std::__sort3<_AlgPolicy, _Compare>( + __first + difference_type(2), __first + (__half_len + 1), __last - difference_type(3), __comp); + std::__sort3<_AlgPolicy, _Compare>( + __first + (__half_len - 1), __first + __half_len, __first + (__half_len + 1), __comp); + _Ops::iter_swap(__first, __first + __half_len); } else { - __delta = __len / 2; - __m += __delta; - __n_swaps = std::__sort3<_AlgPolicy, _Compare>(__first, __m, __lm1, __comp); + std::__sort3<_AlgPolicy, _Compare>(__first + __half_len, __first, __last - difference_type(1), __comp); } } - // *__m is median - // partition [__first, __m) < *__m and *__m <= [__m, __last) - // (this inhibits tossing elements equivalent to __m around unnecessarily) - _RandomAccessIterator __i = __first; - _RandomAccessIterator __j = __lm1; - // j points beyond range to be tested, *__m is known to be <= *__lm1 - // The search going up is known to be guarded but the search coming down isn't. - // Prime the downward search with a guard. - if (!__comp(*__i, *__m)) // if *__first == *__m - { - // *__first == *__m, *__first doesn't go in first part - // manually guard downward moving __j against __i - while (true) { - if (__i == --__j) { - // *__first == *__m, *__m <= all other elements - // Parition instead into [__first, __i) == *__first and *__first < [__i, __last) - ++__i; // __first + 1 - __j = __last; - if (!__comp(*__first, *--__j)) // we need a guard if *__first == *(__last-1) - { - while (true) { - if (__i == __j) - return; // [__first, __last) all equivalent elements - if (__comp(*__first, *__i)) { - _Ops::iter_swap(__i, __j); - ++__n_swaps; - ++__i; - break; - } - ++__i; - } - } - // [__first, __i) == *__first and *__first < [__j, __last) and __j == __last - 1 - if (__i == __j) - return; - while (true) { - while (!__comp(*__first, *__i)) - ++__i; - while (__comp(*__first, *--__j)) - ; - if (__i >= __j) - break; - _Ops::iter_swap(__i, __j); - ++__n_swaps; - ++__i; - } - // [__first, __i) == *__first and *__first < [__i, __last) - // The first part is sorted, sort the second part - // _VSTD::__sort<_Compare>(__i, __last, __comp); - __first = __i; - goto __restart; - } - if (__comp(*__j, *__m)) { - _Ops::iter_swap(__i, __j); - ++__n_swaps; - break; // found guard for downward moving __j, now use unguarded partition - } - } - } - // It is known that *__i < *__m - ++__i; - // j points beyond range to be tested, *__m is known to be <= *__lm1 - // if not yet partitioned... - if (__i < __j) { - // known that *(__i - 1) < *__m - // known that __i <= __m - while (true) { - // __m still guards upward moving __i - while (__comp(*__i, *__m)) - ++__i; - // It is now known that a guard exists for downward moving __j - while (!__comp(*--__j, *__m)) - ; - if (__i > __j) - break; - _Ops::iter_swap(__i, __j); - ++__n_swaps; - // It is known that __m != __j - // If __m just moved, follow it - if (__m == __i) - __m = __j; - ++__i; - } - } - // [__first, __i) < *__m and *__m <= [__i, __last) - if (__i != __m && __comp(*__m, *__i)) { - _Ops::iter_swap(__i, __m); - ++__n_swaps; + // The elements to the left of the current iterator range are already + // sorted. If the current iterator range to be sorted is not the + // leftmost part of the entire iterator range and the pivot is same as + // the highest element in the range to the left, then we know that all + // the elements in the range [first, pivot] would be equal to the pivot, + // assuming the equal elements are put on the left side when + // partitioned. This also means that we do not need to sort the left + // side of the partition. + if (!__leftmost && !__comp(*(__first - difference_type(1)), *__first)) { + __first = std::__partition_with_equals_on_left<_AlgPolicy, _RandomAccessIterator, _Comp_ref>( + __first, __last, _Comp_ref(__comp)); + continue; } + // Use bitset partition only if asked for. + auto __ret = + _UseBitSetPartition + ? std::__bitset_partition<_AlgPolicy, _RandomAccessIterator, _Compare>(__first, __last, __comp) + : std::__partition_with_equals_on_right<_AlgPolicy, _RandomAccessIterator, _Compare>(__first, __last, __comp); + _RandomAccessIterator __i = __ret.first; // [__first, __i) < *__i and *__i <= [__i+1, __last) // If we were given a perfect partition, see if insertion sort is quick... - if (__n_swaps == 0) { + if (__ret.second) { using _WrappedComp = typename _WrapAlgPolicy<_AlgPolicy, _Compare>::type; _WrappedComp __wrapped_comp(__comp); bool __fs = std::__insertion_sort_incomplete<_WrappedComp>(__first, __i, __wrapped_comp); @@ -585,14 +877,11 @@ void __introsort(_RandomAccessIterator __first, _RandomAccessIterator __last, _C } } } - // sort smaller range with recursive call and larger with tail recursion elimination - if (__i - __first < __last - __i) { - std::__introsort<_AlgPolicy, _Compare>(__first, __i, __comp, __depth); - __first = ++__i; - } else { - std::__introsort<_AlgPolicy, _Compare>(__i + difference_type(1), __last, __comp, __depth); - __last = __i; - } + // Sort the left partiton recursively and the right partition with tail recursion elimination. + std::__introsort<_AlgPolicy, _Compare, _RandomAccessIterator, _UseBitSetPartition>( + __first, __i, __comp, __depth, __leftmost); + __leftmost = false; + __first = ++__i; } } @@ -616,15 +905,22 @@ inline _LIBCPP_HIDE_FROM_ABI _Number __log2i(_Number __n) { } template -void __sort(_RandomAccessIterator __first, _RandomAccessIterator __last, _WrappedComp __wrapped_comp) { +_LIBCPP_HIDDEN void __sort(_RandomAccessIterator __first, _RandomAccessIterator __last, _WrappedComp __wrapped_comp) { typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type; - difference_type __depth_limit = 2 * __log2i(__last - __first); + difference_type __depth_limit = 2 * std::__log2i(__last - __first); using _Unwrap = _UnwrapAlgPolicy<_WrappedComp>; using _AlgPolicy = typename _Unwrap::_AlgPolicy; using _Compare = typename _Unwrap::_Comp; _Compare __comp = _Unwrap::__get_comp(__wrapped_comp); - std::__introsort<_AlgPolicy, _Compare>(__first, __last, __comp, __depth_limit); + // Only use bitset partitioning for arithmetic types. We should also check + // that the default comparator is in use so that we are sure that there are no + // branches in the comparator. + std::__introsort<_AlgPolicy, + _Compare, + _RandomAccessIterator, + __use_branchless_sort<_Compare, _RandomAccessIterator>::value>( + __first, __last, __comp, __depth_limit); } template @@ -672,11 +968,11 @@ extern template _LIBCPP_FUNC_VIS bool __insertion_sort_incomplete<__less&, long double*>(long double*, long double*, long double*, long double*, long double*, __less&); template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __sort_impl(_RandomAccessIterator __first, _RandomAccessIterator __last, _Comp& __comp) { std::__debug_randomize_range<_AlgPolicy>(__first, __last); - using _Comp_ref = typename __comp_ref_type<_Comp>::type; + using _Comp_ref = __comp_ref_type<_Comp>; if (__libcpp_is_constant_evaluated()) { std::__partial_sort<_AlgPolicy>(__first, __last, __last, __comp); @@ -689,13 +985,13 @@ void __sort_impl(_RandomAccessIterator __first, _RandomAccessIterator __last, _C } template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void sort(_RandomAccessIterator __first, _RandomAccessIterator __last, _Comp __comp) { std::__sort_impl<_ClassicAlgPolicy>(std::move(__first), std::move(__last), __comp); } template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void sort(_RandomAccessIterator __first, _RandomAccessIterator __last) { std::sort(__first, __last, __less::value_type>()); } diff --git a/lib/libcxx/include/__algorithm/sort_heap.h b/lib/libcxx/include/__algorithm/sort_heap.h index 7713b766f9..8249407b55 100644 --- a/lib/libcxx/include/__algorithm/sort_heap.h +++ b/lib/libcxx/include/__algorithm/sort_heap.h @@ -25,10 +25,9 @@ _LIBCPP_BEGIN_NAMESPACE_STD template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void __sort_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare&& __comp) { - using _CompRef = typename __comp_ref_type<_Compare>::type; - _CompRef __comp_ref = __comp; + __comp_ref_type<_Compare> __comp_ref = __comp; using difference_type = typename iterator_traits<_RandomAccessIterator>::difference_type; for (difference_type __n = __last - __first; __n > 1; --__last, (void) --__n) @@ -36,7 +35,7 @@ void __sort_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _C } template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void sort_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) { static_assert(std::is_copy_constructible<_RandomAccessIterator>::value, "Iterators must be copy constructible."); static_assert(std::is_copy_assignable<_RandomAccessIterator>::value, "Iterators must be copy assignable."); @@ -45,7 +44,7 @@ void sort_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Com } template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void sort_heap(_RandomAccessIterator __first, _RandomAccessIterator __last) { std::sort_heap(std::move(__first), std::move(__last), __less::value_type>()); diff --git a/lib/libcxx/include/__algorithm/stable_partition.h b/lib/libcxx/include/__algorithm/stable_partition.h index c7aa3f07a8..a49de6dbb0 100644 --- a/lib/libcxx/include/__algorithm/stable_partition.h +++ b/lib/libcxx/include/__algorithm/stable_partition.h @@ -15,7 +15,12 @@ #include <__iterator/advance.h> #include <__iterator/distance.h> #include <__iterator/iterator_traits.h> -#include +#include <__memory/destruct_n.h> +#include <__memory/temporary_buffer.h> +#include <__memory/unique_ptr.h> +#include <__utility/move.h> +#include <__utility/pair.h> +#include #include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) @@ -25,7 +30,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD template -_ForwardIterator +_LIBCPP_HIDE_FROM_ABI _ForwardIterator __stable_partition_impl(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred, _Distance __len, _Pair __p, forward_iterator_tag __fit) { @@ -114,7 +119,7 @@ __second_half_done: } template -_ForwardIterator +_LIBCPP_HIDE_FROM_ABI _ForwardIterator __stable_partition_impl(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred, forward_iterator_tag) { @@ -259,7 +264,7 @@ __second_half_done: } template -_BidirectionalIterator +_LIBCPP_HIDE_FROM_ABI _BidirectionalIterator __stable_partition_impl(_BidirectionalIterator __first, _BidirectionalIterator __last, _Predicate __pred, bidirectional_iterator_tag) { @@ -305,7 +310,7 @@ template &>( + return std::__stable_partition_impl<_AlgPolicy, __remove_cvref_t<_Predicate>&>( std::move(__first), std::move(__last), __pred, __iter_category); } diff --git a/lib/libcxx/include/__algorithm/stable_sort.h b/lib/libcxx/include/__algorithm/stable_sort.h index fb149eeb65..8e70978ab6 100644 --- a/lib/libcxx/include/__algorithm/stable_sort.h +++ b/lib/libcxx/include/__algorithm/stable_sort.h @@ -16,8 +16,12 @@ #include <__algorithm/sort.h> #include <__config> #include <__iterator/iterator_traits.h> +#include <__memory/destruct_n.h> +#include <__memory/temporary_buffer.h> +#include <__memory/unique_ptr.h> #include <__utility/move.h> -#include +#include <__utility/pair.h> +#include #include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) @@ -27,7 +31,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD template -void +_LIBCPP_HIDE_FROM_ABI void __merge_move_construct(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2, typename iterator_traits<_InputIterator1>::value_type* __result, _Compare __comp) @@ -69,7 +73,7 @@ __merge_move_construct(_InputIterator1 __first1, _InputIterator1 __last1, } template -void +_LIBCPP_HIDE_FROM_ABI void __merge_move_assign(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result, _Compare __comp) @@ -223,8 +227,7 @@ _LIBCPP_SUPPRESS_DEPRECATED_POP __h.reset(__buf.first); } - using _Comp_ref = typename __comp_ref_type<_Compare>::type; - std::__stable_sort<_AlgPolicy, _Comp_ref>(__first, __last, __comp, __len, __buf.first, __buf.second); + std::__stable_sort<_AlgPolicy, __comp_ref_type<_Compare> >(__first, __last, __comp, __len, __buf.first, __buf.second); } template diff --git a/lib/libcxx/include/__algorithm/swap_ranges.h b/lib/libcxx/include/__algorithm/swap_ranges.h index 0cff519a8d..5ce5ed8c88 100644 --- a/lib/libcxx/include/__algorithm/swap_ranges.h +++ b/lib/libcxx/include/__algorithm/swap_ranges.h @@ -22,7 +22,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD // 2+2 iterators: the shorter size will be used. template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 +_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) { @@ -36,7 +36,7 @@ __swap_ranges(_ForwardIterator1 __first1, _Sentinel1 __last1, _ForwardIterator2 // 2+1 iterators: size2 >= size1. template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_ForwardIterator1, _ForwardIterator2> __swap_ranges(_ForwardIterator1 __first1, _Sentinel1 __last1, _ForwardIterator2 __first2) { while (__first1 != __last1) { @@ -49,7 +49,7 @@ __swap_ranges(_ForwardIterator1 __first1, _Sentinel1 __last1, _ForwardIterator2 } template -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator2 +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator2 swap_ranges(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2) { return std::__swap_ranges<_ClassicAlgPolicy>( std::move(__first1), std::move(__last1), std::move(__first2)).second; diff --git a/lib/libcxx/include/__algorithm/transform.h b/lib/libcxx/include/__algorithm/transform.h index f9db806f5b..4722c154cf 100644 --- a/lib/libcxx/include/__algorithm/transform.h +++ b/lib/libcxx/include/__algorithm/transform.h @@ -18,7 +18,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD template -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator transform(_InputIterator __first, _InputIterator __last, _OutputIterator __result, _UnaryOperation __op) { @@ -28,7 +28,7 @@ transform(_InputIterator __first, _InputIterator __last, _OutputIterator __resul } template -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator transform(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _OutputIterator __result, _BinaryOperation __binary_op) diff --git a/lib/libcxx/include/__algorithm/uniform_random_bit_generator_adaptor.h b/lib/libcxx/include/__algorithm/uniform_random_bit_generator_adaptor.h index 04a67752dd..1e86074b3d 100644 --- a/lib/libcxx/include/__algorithm/uniform_random_bit_generator_adaptor.h +++ b/lib/libcxx/include/__algorithm/uniform_random_bit_generator_adaptor.h @@ -36,21 +36,21 @@ template class _ClassicGenAdaptor { private: // The generator is not required to be copyable or movable, so it has to be stored as a reference. - _Gen& __gen; + _Gen& __gen_; public: using result_type = invoke_result_t<_Gen&>; _LIBCPP_HIDE_FROM_ABI - static constexpr auto min() { return __uncvref_t<_Gen>::min(); } + static constexpr auto min() { return __remove_cvref_t<_Gen>::min(); } _LIBCPP_HIDE_FROM_ABI - static constexpr auto max() { return __uncvref_t<_Gen>::max(); } + static constexpr auto max() { return __remove_cvref_t<_Gen>::max(); } _LIBCPP_HIDE_FROM_ABI - constexpr explicit _ClassicGenAdaptor(_Gen& __g) : __gen(__g) {} + constexpr explicit _ClassicGenAdaptor(_Gen& __g) : __gen_(__g) {} _LIBCPP_HIDE_FROM_ABI - constexpr auto operator()() const { return __gen(); } + constexpr auto operator()() const { return __gen_(); } }; _LIBCPP_END_NAMESPACE_STD diff --git a/lib/libcxx/include/__algorithm/unique.h b/lib/libcxx/include/__algorithm/unique.h index 1727225a91..1717a00c8a 100644 --- a/lib/libcxx/include/__algorithm/unique.h +++ b/lib/libcxx/include/__algorithm/unique.h @@ -26,7 +26,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD // unique template -_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 std::pair<_Iter, _Iter> +_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 std::pair<_Iter, _Iter> __unique(_Iter __first, _Sent __last, _BinaryPredicate&& __pred) { __first = std::__adjacent_find(__first, __last, __pred); if (__first != __last) { @@ -43,16 +43,15 @@ __unique(_Iter __first, _Sent __last, _BinaryPredicate&& __pred) { } template -_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator +_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator unique(_ForwardIterator __first, _ForwardIterator __last, _BinaryPredicate __pred) { return std::__unique<_ClassicAlgPolicy>(std::move(__first), std::move(__last), __pred).first; } template -_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator +_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator unique(_ForwardIterator __first, _ForwardIterator __last) { - typedef typename iterator_traits<_ForwardIterator>::value_type __v; - return std::unique(__first, __last, __equal_to<__v>()); + return std::unique(__first, __last, __equal_to()); } _LIBCPP_END_NAMESPACE_STD diff --git a/lib/libcxx/include/__algorithm/unique_copy.h b/lib/libcxx/include/__algorithm/unique_copy.h index c7c8d8e9d8..81fcd50f01 100644 --- a/lib/libcxx/include/__algorithm/unique_copy.h +++ b/lib/libcxx/include/__algorithm/unique_copy.h @@ -34,7 +34,7 @@ struct __read_from_tmp_value_tag {}; } // namespace __unique_copy_tags template -_LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_HIDE_FROM_ABI pair<_InputIterator, _OutputIterator> +_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI pair<_InputIterator, _OutputIterator> __unique_copy(_InputIterator __first, _Sent __last, _OutputIterator __result, @@ -56,7 +56,7 @@ __unique_copy(_InputIterator __first, } template -_LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_HIDE_FROM_ABI pair<_ForwardIterator, _OutputIterator> +_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI pair<_ForwardIterator, _OutputIterator> __unique_copy(_ForwardIterator __first, _Sent __last, _OutputIterator __result, @@ -78,7 +78,7 @@ __unique_copy(_ForwardIterator __first, } template -_LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_HIDE_FROM_ABI pair<_InputIterator, _InputAndOutputIterator> +_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI pair<_InputIterator, _InputAndOutputIterator> __unique_copy(_InputIterator __first, _Sent __last, _InputAndOutputIterator __result, @@ -95,27 +95,26 @@ __unique_copy(_InputIterator __first, } template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 _OutputIterator +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator unique_copy(_InputIterator __first, _InputIterator __last, _OutputIterator __result, _BinaryPredicate __pred) { - using __algo_tag = typename conditional< + using __algo_tag = __conditional_t< is_base_of::iterator_category>::value, __unique_copy_tags::__reread_from_input_tag, - typename conditional< + __conditional_t< is_base_of::iterator_category>::value && is_same< typename iterator_traits<_InputIterator>::value_type, typename iterator_traits<_OutputIterator>::value_type>::value, __unique_copy_tags::__reread_from_output_tag, - __unique_copy_tags::__read_from_tmp_value_tag>::type >::type; + __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; } template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 _OutputIterator +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator unique_copy(_InputIterator __first, _InputIterator __last, _OutputIterator __result) { - typedef typename iterator_traits<_InputIterator>::value_type __v; - return std::unique_copy(std::move(__first), std::move(__last), std::move(__result), __equal_to<__v>()); + return std::unique_copy(std::move(__first), std::move(__last), std::move(__result), __equal_to()); } _LIBCPP_END_NAMESPACE_STD diff --git a/lib/libcxx/include/__algorithm/unwrap_iter.h b/lib/libcxx/include/__algorithm/unwrap_iter.h index fa9a8fbf2d..0f661e10a7 100644 --- a/lib/libcxx/include/__algorithm/unwrap_iter.h +++ b/lib/libcxx/include/__algorithm/unwrap_iter.h @@ -12,8 +12,10 @@ #include <__config> #include <__iterator/iterator_traits.h> #include <__memory/pointer_traits.h> +#include <__type_traits/enable_if.h> +#include <__type_traits/is_copy_constructible.h> +#include <__utility/declval.h> #include <__utility/move.h> -#include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header @@ -57,7 +59,7 @@ struct __unwrap_iter_impl<_Iter, true> { template, __enable_if_t::value, int> = 0> -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 decltype(_Impl::__unwrap(std::declval<_Iter>())) __unwrap_iter(_Iter __i) _NOEXCEPT { return _Impl::__unwrap(__i); } diff --git a/lib/libcxx/include/__algorithm/unwrap_range.h b/lib/libcxx/include/__algorithm/unwrap_range.h index 745906a96e..2c5d23e69f 100644 --- a/lib/libcxx/include/__algorithm/unwrap_range.h +++ b/lib/libcxx/include/__algorithm/unwrap_range.h @@ -28,7 +28,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD // __unwrap_iter and __rewrap_iter don't work for this, because they assume that the iterator and sentinel have // the same type. __unwrap_range tries to get two iterators and then forward to __unwrap_iter. -#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#if _LIBCPP_STD_VER > 17 template struct __unwrap_range_impl { _LIBCPP_HIDE_FROM_ABI static constexpr auto __unwrap(_Iter __first, _Sent __sent) diff --git a/lib/libcxx/include/__algorithm/upper_bound.h b/lib/libcxx/include/__algorithm/upper_bound.h index 1045380bc8..96552ce1f8 100644 --- a/lib/libcxx/include/__algorithm/upper_bound.h +++ b/lib/libcxx/include/__algorithm/upper_bound.h @@ -28,7 +28,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 _Iter +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Iter __upper_bound(_Iter __first, _Sent __last, const _Tp& __value, _Compare&& __comp, _Proj&& __proj) { auto __len = _IterOps<_AlgPolicy>::distance(__first, __last); while (__len != 0) { @@ -45,7 +45,7 @@ __upper_bound(_Iter __first, _Sent __last, const _Tp& __value, _Compare&& __comp } template -_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator +_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator upper_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value, _Compare __comp) { static_assert(is_copy_constructible<_ForwardIterator>::value, "Iterator has to be copy constructible"); @@ -54,7 +54,7 @@ upper_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __valu } template -_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator +_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator upper_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value) { return std::upper_bound( std::move(__first), diff --git a/lib/libcxx/include/__assert b/lib/libcxx/include/__assert index 87556085ea..9c0cd1b119 100644 --- a/lib/libcxx/include/__assert +++ b/lib/libcxx/include/__assert @@ -17,13 +17,9 @@ # pragma GCC system_header #endif -// This is for backwards compatibility with code that might have been enabling -// assertions through the Debug mode previously. -// TODO: In LLVM 16, make it an error to define _LIBCPP_DEBUG +// TODO: Remove in LLVM 17. #if defined(_LIBCPP_DEBUG) -# ifndef _LIBCPP_ENABLE_ASSERTIONS -# define _LIBCPP_ENABLE_ASSERTIONS 1 -# endif +# error "Defining _LIBCPP_DEBUG is not supported anymore. Please use _LIBCPP_ENABLE_DEBUG_MODE instead." #endif // Automatically enable assertions when the debug mode is enabled. @@ -45,7 +41,7 @@ # define _LIBCPP_ASSERT(expression, message) \ (__builtin_expect(static_cast(expression), 1) ? \ (void)0 : \ - ::std::__libcpp_verbose_abort("%s:%d: assertion %s failed: %s", __FILE__, __LINE__, #expression, message)) + _LIBCPP_VERBOSE_ABORT("%s:%d: assertion %s failed: %s", __FILE__, __LINE__, #expression, message)) #elif !defined(_LIBCPP_ASSERTIONS_DISABLE_ASSUME) && __has_builtin(__builtin_assume) # define _LIBCPP_ASSERT(expression, message) \ (_LIBCPP_DIAGNOSTIC_PUSH \ diff --git a/lib/libcxx/include/__availability b/lib/libcxx/include/__availability index 72ff663334..6dfca3fa8b 100644 --- a/lib/libcxx/include/__availability +++ b/lib/libcxx/include/__availability @@ -156,20 +156,9 @@ # define _LIBCPP_AVAILABILITY_FORMAT // # define _LIBCPP_AVAILABILITY_DISABLE_FTM___cpp_lib_format - // This controls whether the default verbose termination function is - // provided by the library. - // - // Note that when users provide their own custom function, it doesn't - // matter whether the dylib provides a default function, and the - // availability markup can actually give a false positive diagnostic - // (it will think that no function is provided, when in reality the - // user has provided their own). - // - // Users can pass -D_LIBCPP_AVAILABILITY_CUSTOM_VERBOSE_ABORT_PROVIDED - // to the compiler to tell the library not to define its own verbose abort. - // Note that defining this macro but failing to define a custom function - // will lead to a load-time error on back-deployment targets, so it should - // be avoided. + // 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_HAS_NO_VERBOSE_ABORT_IN_LIBRARY #elif defined(__APPLE__) diff --git a/lib/libcxx/include/__bit/bit_cast.h b/lib/libcxx/include/__bit/bit_cast.h index 831207671e..2ca4120c76 100644 --- a/lib/libcxx/include/__bit/bit_cast.h +++ b/lib/libcxx/include/__bit/bit_cast.h @@ -11,7 +11,7 @@ #define _LIBCPP___BIT_BIT_CAST_H #include <__config> -#include +#include <__type_traits/is_trivially_copyable.h> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header diff --git a/lib/libcxx/include/__bit/bit_ceil.h b/lib/libcxx/include/__bit/bit_ceil.h new file mode 100644 index 0000000000..a558d61942 --- /dev/null +++ b/lib/libcxx/include/__bit/bit_ceil.h @@ -0,0 +1,46 @@ +//===----------------------------------------------------------------------===// +// +// 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___BIT_BIT_CEIL_H +#define _LIBCPP___BIT_BIT_CEIL_H + +#include <__assert> +#include <__bit/countl.h> +#include <__concepts/arithmetic.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 + +template <__libcpp_unsigned_integer _Tp> +_LIBCPP_HIDE_FROM_ABI constexpr _Tp bit_ceil(_Tp __t) noexcept { + if (__t < 2) + return 1; + const unsigned __n = numeric_limits<_Tp>::digits - std::countl_zero((_Tp)(__t - 1u)); + _LIBCPP_ASSERT(__n != numeric_limits<_Tp>::digits, "Bad input to bit_ceil"); + + if constexpr (sizeof(_Tp) >= sizeof(unsigned)) + return _Tp{1} << __n; + else { + const unsigned __extra = numeric_limits::digits - numeric_limits<_Tp>::digits; + const unsigned __retVal = 1u << (__n + __extra); + return (_Tp)(__retVal >> __extra); + } +} + +#endif // _LIBCPP_STD_VER >= 20 + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___BIT_BIT_CEIL_H diff --git a/lib/libcxx/include/__bit/bit_floor.h b/lib/libcxx/include/__bit/bit_floor.h new file mode 100644 index 0000000000..b2e38092f2 --- /dev/null +++ b/lib/libcxx/include/__bit/bit_floor.h @@ -0,0 +1,34 @@ +//===----------------------------------------------------------------------===// +// +// 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___BIT_BIT_FLOOR_H +#define _LIBCPP___BIT_BIT_FLOOR_H + +#include <__bit/bit_log2.h> +#include <__concepts/arithmetic.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 + +template <__libcpp_unsigned_integer _Tp> +_LIBCPP_HIDE_FROM_ABI constexpr _Tp bit_floor(_Tp __t) noexcept { + return __t == 0 ? 0 : _Tp{1} << std::__bit_log2(__t); +} + +#endif // _LIBCPP_STD_VER >= 20 + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___BIT_BIT_FLOOR_H diff --git a/lib/libcxx/include/__bit/bit_log2.h b/lib/libcxx/include/__bit/bit_log2.h new file mode 100644 index 0000000000..62936f6786 --- /dev/null +++ b/lib/libcxx/include/__bit/bit_log2.h @@ -0,0 +1,34 @@ +//===----------------------------------------------------------------------===// +// +// 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___BIT_BIT_LOG2_H +#define _LIBCPP___BIT_BIT_LOG2_H + +#include <__bit/countl.h> +#include <__concepts/arithmetic.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 + +template <__libcpp_unsigned_integer _Tp> +_LIBCPP_HIDE_FROM_ABI constexpr _Tp __bit_log2(_Tp __t) noexcept { + return numeric_limits<_Tp>::digits - 1 - std::countl_zero(__t); +} + +#endif // _LIBCPP_STD_VER >= 20 + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___BIT_BIT_LOG2_H diff --git a/lib/libcxx/include/__bit/bit_width.h b/lib/libcxx/include/__bit/bit_width.h new file mode 100644 index 0000000000..4381f227f5 --- /dev/null +++ b/lib/libcxx/include/__bit/bit_width.h @@ -0,0 +1,33 @@ +//===----------------------------------------------------------------------===// +// +// 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___BIT_BIT_WIDTH_H +#define _LIBCPP___BIT_BIT_WIDTH_H + +#include <__bit/bit_log2.h> +#include <__concepts/arithmetic.h> +#include <__config> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +#if _LIBCPP_STD_VER >= 20 + +_LIBCPP_BEGIN_NAMESPACE_STD + +template <__libcpp_unsigned_integer _Tp> +_LIBCPP_HIDE_FROM_ABI constexpr int bit_width(_Tp __t) noexcept { + return __t == 0 ? 0 : std::__bit_log2(__t) + 1; +} + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_STD_VER >= 20 + +#endif // _LIBCPP___BIT_BIT_WIDTH_H diff --git a/lib/libcxx/include/__bit/blsr.h b/lib/libcxx/include/__bit/blsr.h new file mode 100644 index 0000000000..de991e9adb --- /dev/null +++ b/lib/libcxx/include/__bit/blsr.h @@ -0,0 +1,34 @@ +//===----------------------------------------------------------------------===// +// +// 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___BIT_BLSR_H +#define _LIBCPP___BIT_BLSR_H + +#include <__config> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR unsigned __libcpp_blsr(unsigned __x) _NOEXCEPT { + return __x ^ (__x & -__x); +} + +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR unsigned long __libcpp_blsr(unsigned long __x) _NOEXCEPT { + return __x ^ (__x & -__x); +} + +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR unsigned long long __libcpp_blsr(unsigned long long __x) _NOEXCEPT { + return __x ^ (__x & -__x); +} + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___BIT_BLSR_H diff --git a/lib/libcxx/include/__bit/countl.h b/lib/libcxx/include/__bit/countl.h new file mode 100644 index 0000000000..86eaee0c1b --- /dev/null +++ b/lib/libcxx/include/__bit/countl.h @@ -0,0 +1,104 @@ +//===----------------------------------------------------------------------===// +// +// 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___BIT_COUNTL_H +#define _LIBCPP___BIT_COUNTL_H + +#include <__bit/rotate.h> +#include <__concepts/arithmetic.h> +#include <__config> +#include <__type_traits/is_unsigned_integer.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 + +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR +int __libcpp_clz(unsigned __x) _NOEXCEPT { return __builtin_clz(__x); } + +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR +int __libcpp_clz(unsigned long __x) _NOEXCEPT { return __builtin_clzl(__x); } + +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR +int __libcpp_clz(unsigned long long __x) _NOEXCEPT { return __builtin_clzll(__x); } + +# ifndef _LIBCPP_HAS_NO_INT128 +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR +int __libcpp_clz(__uint128_t __x) _NOEXCEPT { + // The function is written in this form due to C++ constexpr limitations. + // The algorithm: + // - Test whether any bit in the high 64-bits is set + // - No bits set: + // - The high 64-bits contain 64 leading zeros, + // - Add the result of the low 64-bits. + // - Any bits set: + // - The number of leading zeros of the input is the number of leading + // zeros in the high 64-bits. + return ((__x >> 64) == 0) + ? (64 + __builtin_clzll(static_cast(__x))) + : __builtin_clzll(static_cast(__x >> 64)); +} +# endif // _LIBCPP_HAS_NO_INT128 + +template +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 +int __countl_zero(_Tp __t) _NOEXCEPT +{ + static_assert(__libcpp_is_unsigned_integer<_Tp>::value, "__countl_zero requires an unsigned integer type"); + if (__t == 0) + return numeric_limits<_Tp>::digits; + + if (sizeof(_Tp) <= sizeof(unsigned int)) + return std::__libcpp_clz(static_cast(__t)) + - (numeric_limits::digits - numeric_limits<_Tp>::digits); + else if (sizeof(_Tp) <= sizeof(unsigned long)) + return std::__libcpp_clz(static_cast(__t)) + - (numeric_limits::digits - numeric_limits<_Tp>::digits); + else if (sizeof(_Tp) <= sizeof(unsigned long long)) + return std::__libcpp_clz(static_cast(__t)) + - (numeric_limits::digits - numeric_limits<_Tp>::digits); + else + { + int __ret = 0; + int __iter = 0; + const unsigned int __ulldigits = numeric_limits::digits; + while (true) { + __t = std::__rotr(__t, __ulldigits); + if ((__iter = std::__countl_zero(static_cast(__t))) != __ulldigits) + break; + __ret += __iter; + } + return __ret + __iter; + } +} + +#if _LIBCPP_STD_VER >= 20 + +template <__libcpp_unsigned_integer _Tp> +_LIBCPP_HIDE_FROM_ABI constexpr int countl_zero(_Tp __t) noexcept { + return std::__countl_zero(__t); +} + +template <__libcpp_unsigned_integer _Tp> +_LIBCPP_HIDE_FROM_ABI constexpr int countl_one(_Tp __t) noexcept { + return __t != numeric_limits<_Tp>::max() ? std::countl_zero(static_cast<_Tp>(~__t)) : numeric_limits<_Tp>::digits; +} + +#endif // _LIBCPP_STD_VER >= 20 + +_LIBCPP_END_NAMESPACE_STD + +_LIBCPP_POP_MACROS + +#endif // _LIBCPP___BIT_COUNTL_H diff --git a/lib/libcxx/include/__bit/countr.h b/lib/libcxx/include/__bit/countr.h new file mode 100644 index 0000000000..d3ca5b6c94 --- /dev/null +++ b/lib/libcxx/include/__bit/countr.h @@ -0,0 +1,70 @@ +//===----------------------------------------------------------------------===// +// +// 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___BIT_COUNTR_H +#define _LIBCPP___BIT_COUNTR_H + +#include <__bit/rotate.h> +#include <__concepts/arithmetic.h> +#include <__config> +#include + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + +_LIBCPP_BEGIN_NAMESPACE_STD + +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR +int __libcpp_ctz(unsigned __x) _NOEXCEPT { return __builtin_ctz(__x); } + +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR +int __libcpp_ctz(unsigned long __x) _NOEXCEPT { return __builtin_ctzl(__x); } + +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR +int __libcpp_ctz(unsigned long long __x) _NOEXCEPT { return __builtin_ctzll(__x); } + +#if _LIBCPP_STD_VER >= 20 + +template <__libcpp_unsigned_integer _Tp> +_LIBCPP_HIDE_FROM_ABI constexpr int countr_zero(_Tp __t) noexcept { + if (__t == 0) + return numeric_limits<_Tp>::digits; + + if (sizeof(_Tp) <= sizeof(unsigned int)) + return std::__libcpp_ctz(static_cast(__t)); + else if (sizeof(_Tp) <= sizeof(unsigned long)) + return std::__libcpp_ctz(static_cast(__t)); + else if (sizeof(_Tp) <= sizeof(unsigned long long)) + return std::__libcpp_ctz(static_cast(__t)); + else { + int __ret = 0; + const unsigned int __ulldigits = numeric_limits::digits; + while (static_cast(__t) == 0uLL) { + __ret += __ulldigits; + __t >>= __ulldigits; + } + return __ret + std::__libcpp_ctz(static_cast(__t)); + } +} + +template <__libcpp_unsigned_integer _Tp> +_LIBCPP_HIDE_FROM_ABI constexpr int countr_one(_Tp __t) noexcept { + return __t != numeric_limits<_Tp>::max() ? std::countr_zero(static_cast<_Tp>(~__t)) : numeric_limits<_Tp>::digits; +} + +#endif // _LIBCPP_STD_VER >= 20 + +_LIBCPP_END_NAMESPACE_STD + +_LIBCPP_POP_MACROS + +#endif // _LIBCPP___BIT_COUNTR_H diff --git a/lib/libcxx/include/__bit/endian.h b/lib/libcxx/include/__bit/endian.h new file mode 100644 index 0000000000..52635f2d24 --- /dev/null +++ b/lib/libcxx/include/__bit/endian.h @@ -0,0 +1,38 @@ +//===----------------------------------------------------------------------===// +// +// 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___BIT_ENDIAN_H +#define _LIBCPP___BIT_ENDIAN_H + +#include <__config> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +#if _LIBCPP_STD_VER >= 20 + +_LIBCPP_BEGIN_NAMESPACE_STD + +enum class endian { + little = 0xDEAD, + big = 0xFACE, +# if defined(_LIBCPP_LITTLE_ENDIAN) + native = little +# elif defined(_LIBCPP_BIG_ENDIAN) + native = big +# else + native = 0xCAFE +# endif +}; + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_STD_VER >= 20 + +#endif // _LIBCPP___BIT_ENDIAN_H diff --git a/lib/libcxx/include/__bit/has_single_bit.h b/lib/libcxx/include/__bit/has_single_bit.h new file mode 100644 index 0000000000..b89f5995b3 --- /dev/null +++ b/lib/libcxx/include/__bit/has_single_bit.h @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +// 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___BIT_HAS_SINGLE_BIT_H +#define _LIBCPP___BIT_HAS_SINGLE_BIT_H + +#include <__concepts/arithmetic.h> +#include <__config> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + +#if _LIBCPP_STD_VER >= 20 + +_LIBCPP_BEGIN_NAMESPACE_STD + +template <__libcpp_unsigned_integer _Tp> +_LIBCPP_HIDE_FROM_ABI constexpr bool has_single_bit(_Tp __t) noexcept { + return __t != 0 && (((__t & (__t - 1)) == 0)); +} + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_STD_VER >= 20 + +_LIBCPP_POP_MACROS + +#endif // _LIBCPP___BIT_HAS_SINGLE_BIT_H diff --git a/lib/libcxx/include/__bit/popcount.h b/lib/libcxx/include/__bit/popcount.h new file mode 100644 index 0000000000..33b94cff71 --- /dev/null +++ b/lib/libcxx/include/__bit/popcount.h @@ -0,0 +1,61 @@ +//===----------------------------------------------------------------------===// +// +// 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___BIT_POPCOUNT_H +#define _LIBCPP___BIT_POPCOUNT_H + +#include <__bit/rotate.h> +#include <__concepts/arithmetic.h> +#include <__config> +#include + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + +_LIBCPP_BEGIN_NAMESPACE_STD + +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR +int __libcpp_popcount(unsigned __x) _NOEXCEPT { return __builtin_popcount(__x); } + +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR +int __libcpp_popcount(unsigned long __x) _NOEXCEPT { return __builtin_popcountl(__x); } + +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR +int __libcpp_popcount(unsigned long long __x) _NOEXCEPT { return __builtin_popcountll(__x); } + +#if _LIBCPP_STD_VER >= 20 + +template <__libcpp_unsigned_integer _Tp> +_LIBCPP_HIDE_FROM_ABI constexpr int popcount(_Tp __t) noexcept { + if (sizeof(_Tp) <= sizeof(unsigned int)) + return std::__libcpp_popcount(static_cast(__t)); + else if (sizeof(_Tp) <= sizeof(unsigned long)) + return std::__libcpp_popcount(static_cast(__t)); + else if (sizeof(_Tp) <= sizeof(unsigned long long)) + return std::__libcpp_popcount(static_cast(__t)); + else { + int __ret = 0; + while (__t != 0) { + __ret += std::__libcpp_popcount(static_cast(__t)); + __t >>= numeric_limits::digits; + } + return __ret; + } +} + +#endif // _LIBCPP_STD_VER >= 20 + +_LIBCPP_END_NAMESPACE_STD + +_LIBCPP_POP_MACROS + +#endif // _LIBCPP___BIT_POPCOUNT_H diff --git a/lib/libcxx/include/__bit/rotate.h b/lib/libcxx/include/__bit/rotate.h new file mode 100644 index 0000000000..5aa7518b3c --- /dev/null +++ b/lib/libcxx/include/__bit/rotate.h @@ -0,0 +1,53 @@ +//===----------------------------------------------------------------------===// +// +// 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___BIT_ROTATE_H +#define _LIBCPP___BIT_ROTATE_H + +#include <__concepts/arithmetic.h> +#include <__config> +#include <__type_traits/is_unsigned_integer.h> +#include + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +template +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 +_Tp __rotr(_Tp __t, unsigned int __cnt) _NOEXCEPT +{ + static_assert(__libcpp_is_unsigned_integer<_Tp>::value, "__rotr requires an unsigned integer type"); + const unsigned int __dig = numeric_limits<_Tp>::digits; + if ((__cnt % __dig) == 0) + return __t; + return (__t >> (__cnt % __dig)) | (__t << (__dig - (__cnt % __dig))); +} + +#if _LIBCPP_STD_VER >= 20 + +template <__libcpp_unsigned_integer _Tp> +_LIBCPP_HIDE_FROM_ABI constexpr _Tp rotl(_Tp __t, unsigned int __cnt) noexcept { + const unsigned int __dig = numeric_limits<_Tp>::digits; + if ((__cnt % __dig) == 0) + return __t; + return (__t << (__cnt % __dig)) | (__t >> (__dig - (__cnt % __dig))); +} + +template <__libcpp_unsigned_integer _Tp> +_LIBCPP_HIDE_FROM_ABI constexpr _Tp rotr(_Tp __t, unsigned int __cnt) noexcept { + return std::__rotr(__t, __cnt); +} + +#endif // _LIBCPP_STD_VER >= 20 + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___BIT_ROTATE_H diff --git a/lib/libcxx/include/__bit_reference b/lib/libcxx/include/__bit_reference index 60f57d665a..2665749139 100644 --- a/lib/libcxx/include/__bit_reference +++ b/lib/libcxx/include/__bit_reference @@ -13,7 +13,8 @@ #include <__algorithm/copy_n.h> #include <__algorithm/fill_n.h> #include <__algorithm/min.h> -#include <__bits> +#include <__bit/countr.h> +#include <__bit/popcount.h> #include <__config> #include <__iterator/iterator_traits.h> #include <__memory/construct_at.h> @@ -54,15 +55,17 @@ class __bit_reference friend class __bit_const_reference<_Cp>; friend class __bit_iterator<_Cp, false>; public: - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 + using __container = typename _Cp::__self; + + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 __bit_reference(const __bit_reference&) = default; - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 operator bool() const _NOEXCEPT + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 operator bool() const _NOEXCEPT {return static_cast(*__seg_ & __mask_);} - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 bool operator ~() const _NOEXCEPT + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 bool operator ~() const _NOEXCEPT {return !static_cast(*this);} - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 __bit_reference& operator=(bool __x) _NOEXCEPT { if (__x) @@ -82,15 +85,15 @@ public: } #endif - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 __bit_reference& operator=(const __bit_reference& __x) _NOEXCEPT {return operator=(static_cast(__x));} - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 void flip() _NOEXCEPT {*__seg_ ^= __mask_;} - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 __bit_iterator<_Cp, false> operator&() const _NOEXCEPT - {return __bit_iterator<_Cp, false>(__seg_, static_cast(__libcpp_ctz(__mask_)));} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 void flip() _NOEXCEPT {*__seg_ ^= __mask_;} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 __bit_iterator<_Cp, false> operator&() const _NOEXCEPT + {return __bit_iterator<_Cp, false>(__seg_, static_cast(std::__libcpp_ctz(__mask_)));} private: - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit __bit_reference(__storage_pointer __s, __storage_type __m) _NOEXCEPT : __seg_(__s), __mask_(__m) {} }; @@ -101,7 +104,7 @@ class __bit_reference<_Cp, false> }; template -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 void swap(__bit_reference<_Cp> __x, __bit_reference<_Cp> __y) _NOEXCEPT { @@ -111,7 +114,7 @@ swap(__bit_reference<_Cp> __x, __bit_reference<_Cp> __y) _NOEXCEPT } template -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 void swap(__bit_reference<_Cp> __x, __bit_reference<_Dp> __y) _NOEXCEPT { @@ -121,7 +124,7 @@ swap(__bit_reference<_Cp> __x, __bit_reference<_Dp> __y) _NOEXCEPT } template -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 void swap(__bit_reference<_Cp> __x, bool& __y) _NOEXCEPT { @@ -131,7 +134,7 @@ swap(__bit_reference<_Cp> __x, bool& __y) _NOEXCEPT } template -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 void swap(bool& __x, __bit_reference<_Cp> __y) _NOEXCEPT { @@ -155,15 +158,15 @@ public: _LIBCPP_INLINE_VISIBILITY __bit_const_reference(const __bit_const_reference&) = default; - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 __bit_const_reference(const __bit_reference<_Cp>& __x) _NOEXCEPT : __seg_(__x.__seg_), __mask_(__x.__mask_) {} _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR operator bool() const _NOEXCEPT {return static_cast(*__seg_ & __mask_);} - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 __bit_iterator<_Cp, true> operator&() const _NOEXCEPT - {return __bit_iterator<_Cp, true>(__seg_, static_cast(__libcpp_ctz(__mask_)));} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 __bit_iterator<_Cp, true> operator&() const _NOEXCEPT + {return __bit_iterator<_Cp, true>(__seg_, static_cast(std::__libcpp_ctz(__mask_)));} private: _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR @@ -176,7 +179,7 @@ private: // find template -_LIBCPP_CONSTEXPR_AFTER_CXX17 __bit_iterator<_Cp, _IsConst> +_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI __bit_iterator<_Cp, _IsConst> __find_bool_true(__bit_iterator<_Cp, _IsConst> __first, typename _Cp::size_type __n) { typedef __bit_iterator<_Cp, _IsConst> _It; @@ -212,7 +215,7 @@ __find_bool_true(__bit_iterator<_Cp, _IsConst> __first, typename _Cp::size_type } template -_LIBCPP_CONSTEXPR_AFTER_CXX17 __bit_iterator<_Cp, _IsConst> +_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI __bit_iterator<_Cp, _IsConst> __find_bool_false(__bit_iterator<_Cp, _IsConst> __first, typename _Cp::size_type __n) { typedef __bit_iterator<_Cp, _IsConst> _It; @@ -251,7 +254,7 @@ __find_bool_false(__bit_iterator<_Cp, _IsConst> __first, typename _Cp::size_type } template -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 __bit_iterator<_Cp, _IsConst> find(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, const _Tp& __value) { @@ -263,7 +266,7 @@ find(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last // count template -typename __bit_iterator<_Cp, _IsConst>::difference_type +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 typename __bit_iterator<_Cp, _IsConst>::difference_type __count_bool_true(__bit_iterator<_Cp, _IsConst> __first, typename _Cp::size_type __n) { typedef __bit_iterator<_Cp, _IsConst> _It; @@ -294,7 +297,7 @@ __count_bool_true(__bit_iterator<_Cp, _IsConst> __first, typename _Cp::size_type } template -typename __bit_iterator<_Cp, _IsConst>::difference_type +_LIBCPP_HIDE_FROM_ABI typename __bit_iterator<_Cp, _IsConst>::difference_type __count_bool_false(__bit_iterator<_Cp, _IsConst> __first, typename _Cp::size_type __n) { typedef __bit_iterator<_Cp, _IsConst> _It; @@ -337,7 +340,7 @@ count(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __las // fill_n template -_LIBCPP_CONSTEXPR_AFTER_CXX17 void +_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __fill_n_false(__bit_iterator<_Cp, false> __first, typename _Cp::size_type __n) { typedef __bit_iterator<_Cp, false> _It; @@ -367,7 +370,7 @@ __fill_n_false(__bit_iterator<_Cp, false> __first, typename _Cp::size_type __n) } template -_LIBCPP_CONSTEXPR_AFTER_CXX17 void +_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __fill_n_true(__bit_iterator<_Cp, false> __first, typename _Cp::size_type __n) { typedef __bit_iterator<_Cp, false> _It; @@ -398,7 +401,7 @@ __fill_n_true(__bit_iterator<_Cp, false> __first, typename _Cp::size_type __n) } template -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 void fill_n(__bit_iterator<_Cp, false> __first, typename _Cp::size_type __n, bool __value) { @@ -414,7 +417,7 @@ fill_n(__bit_iterator<_Cp, false> __first, typename _Cp::size_type __n, bool __v // fill template -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 void fill(__bit_iterator<_Cp, false> __first, __bit_iterator<_Cp, false> __last, bool __value) { @@ -424,8 +427,7 @@ fill(__bit_iterator<_Cp, false> __first, __bit_iterator<_Cp, false> __last, bool // copy template -_LIBCPP_CONSTEXPR_AFTER_CXX17 -__bit_iterator<_Cp, false> +_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI __bit_iterator<_Cp, false> __copy_aligned(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, __bit_iterator<_Cp, false> __result) { @@ -472,8 +474,7 @@ __copy_aligned(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsCon } template -_LIBCPP_CONSTEXPR_AFTER_CXX17 -__bit_iterator<_Cp, false> +_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI __bit_iterator<_Cp, false> __copy_unaligned(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, __bit_iterator<_Cp, false> __result) { @@ -551,7 +552,7 @@ __copy_unaligned(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsC } template -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 __bit_iterator<_Cp, false> copy(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, __bit_iterator<_Cp, false> __result) { @@ -563,7 +564,7 @@ copy(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last // copy_backward template -_LIBCPP_CONSTEXPR_AFTER_CXX17 __bit_iterator<_Cp, false> +_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI __bit_iterator<_Cp, false> __copy_backward_aligned(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, __bit_iterator<_Cp, false> __result) { @@ -610,7 +611,7 @@ __copy_backward_aligned(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_C } template -_LIBCPP_CONSTEXPR_AFTER_CXX17 __bit_iterator<_Cp, false> +_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI __bit_iterator<_Cp, false> __copy_backward_unaligned(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, __bit_iterator<_Cp, false> __result) { @@ -696,7 +697,7 @@ __copy_backward_unaligned(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator< } template -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 __bit_iterator<_Cp, false> copy_backward(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, __bit_iterator<_Cp, false> __result) { @@ -728,7 +729,7 @@ move_backward(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsCons // swap_ranges template -__bit_iterator<__C2, false> +_LIBCPP_HIDE_FROM_ABI __bit_iterator<__C2, false> __swap_ranges_aligned(__bit_iterator<__C1, false> __first, __bit_iterator<__C1, false> __last, __bit_iterator<__C2, false> __result) { @@ -778,7 +779,7 @@ __swap_ranges_aligned(__bit_iterator<__C1, false> __first, __bit_iterator<__C1, } template -__bit_iterator<__C2, false> +_LIBCPP_HIDE_FROM_ABI __bit_iterator<__C2, false> __swap_ranges_unaligned(__bit_iterator<__C1, false> __first, __bit_iterator<__C1, false> __last, __bit_iterator<__C2, false> __result) { @@ -903,19 +904,19 @@ struct __bit_array difference_type __size_; __storage_type __word_[_Np]; - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 static difference_type capacity() + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 static difference_type capacity() {return static_cast(_Np * __bits_per_word);} - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 explicit __bit_array(difference_type __s) : __size_(__s) { + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit __bit_array(difference_type __s) : __size_(__s) { if (__libcpp_is_constant_evaluated()) { for (size_t __i = 0; __i != __bit_array<_Cp>::_Np; ++__i) std::__construct_at(__word_ + __i, 0); } } - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 iterator begin() + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator begin() { return iterator(pointer_traits<__storage_pointer>::pointer_to(__word_[0]), 0); } - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 iterator end() + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator end() { return iterator(pointer_traits<__storage_pointer>::pointer_to(__word_[0]) + __size_ / __bits_per_word, static_cast(__size_ % __bits_per_word)); @@ -923,7 +924,7 @@ struct __bit_array }; template -_LIBCPP_CONSTEXPR_AFTER_CXX17 __bit_iterator<_Cp, false> +_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI __bit_iterator<_Cp, false> rotate(__bit_iterator<_Cp, false> __first, __bit_iterator<_Cp, false> __middle, __bit_iterator<_Cp, false> __last) { typedef __bit_iterator<_Cp, false> _I1; @@ -974,7 +975,7 @@ rotate(__bit_iterator<_Cp, false> __first, __bit_iterator<_Cp, false> __middle, // equal template -_LIBCPP_CONSTEXPR_AFTER_CXX17 bool +_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI bool __equal_unaligned(__bit_iterator<_Cp, _IC1> __first1, __bit_iterator<_Cp, _IC1> __last1, __bit_iterator<_Cp, _IC2> __first2) { @@ -1056,7 +1057,7 @@ __equal_unaligned(__bit_iterator<_Cp, _IC1> __first1, __bit_iterator<_Cp, _IC1> } template -_LIBCPP_CONSTEXPR_AFTER_CXX17 bool +_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI bool __equal_aligned(__bit_iterator<_Cp, _IC1> __first1, __bit_iterator<_Cp, _IC1> __last1, __bit_iterator<_Cp, _IC2> __first2) { @@ -1099,7 +1100,7 @@ __equal_aligned(__bit_iterator<_Cp, _IC1> __first1, __bit_iterator<_Cp, _IC1> __ } template -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 bool equal(__bit_iterator<_Cp, _IC1> __first1, __bit_iterator<_Cp, _IC1> __last1, __bit_iterator<_Cp, _IC2> __first2) { @@ -1117,23 +1118,23 @@ public: typedef bool value_type; typedef __bit_iterator pointer; #ifndef _LIBCPP_ABI_BITSET_VECTOR_BOOL_CONST_SUBSCRIPT_RETURN_BOOL - typedef typename conditional<_IsConst, __bit_const_reference<_Cp>, __bit_reference<_Cp> >::type reference; + typedef __conditional_t<_IsConst, __bit_const_reference<_Cp>, __bit_reference<_Cp> > reference; #else - using reference = typename conditional<_IsConst, bool, __bit_reference<_Cp> >::type; + using reference = __conditional_t<_IsConst, bool, __bit_reference<_Cp> >; #endif typedef random_access_iterator_tag iterator_category; private: typedef typename _Cp::__storage_type __storage_type; - typedef typename conditional<_IsConst, typename _Cp::__const_storage_pointer, - typename _Cp::__storage_pointer>::type __storage_pointer; + typedef __conditional_t<_IsConst, typename _Cp::__const_storage_pointer, typename _Cp::__storage_pointer> + __storage_pointer; static const unsigned __bits_per_word = _Cp::__bits_per_word; __storage_pointer __seg_; unsigned __ctz_; public: - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 __bit_iterator() _NOEXCEPT + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 __bit_iterator() _NOEXCEPT #if _LIBCPP_STD_VER > 11 : __seg_(nullptr), __ctz_(0) #endif @@ -1144,7 +1145,7 @@ public: // When _IsConst=true, this is a converting constructor; // the copy and move constructors are implicitly generated // and trivial. - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 __bit_iterator(const __bit_iterator<_Cp, false>& __it) _NOEXCEPT : __seg_(__it.__seg_), __ctz_(__it.__ctz_) {} @@ -1153,19 +1154,19 @@ public: // the implicit generation of a defaulted one is deprecated. // When _IsConst=true, the assignment operators are // implicitly generated and trivial. - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 __bit_iterator& operator=(const _If<_IsConst, struct __private_nat, __bit_iterator>& __it) { __seg_ = __it.__seg_; __ctz_ = __it.__ctz_; return *this; } - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 reference operator*() const _NOEXCEPT { - return typename conditional<_IsConst, __bit_const_reference<_Cp>, __bit_reference<_Cp> > - ::type(__seg_, __storage_type(1) << __ctz_); + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 reference operator*() const _NOEXCEPT { + return __conditional_t<_IsConst, __bit_const_reference<_Cp>, __bit_reference<_Cp> >( + __seg_, __storage_type(1) << __ctz_); } - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 __bit_iterator& operator++() + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 __bit_iterator& operator++() { if (__ctz_ != __bits_per_word-1) ++__ctz_; @@ -1177,14 +1178,14 @@ public: return *this; } - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 __bit_iterator operator++(int) + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 __bit_iterator operator++(int) { __bit_iterator __tmp = *this; ++(*this); return __tmp; } - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 __bit_iterator& operator--() + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 __bit_iterator& operator--() { if (__ctz_ != 0) --__ctz_; @@ -1196,14 +1197,14 @@ public: return *this; } - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 __bit_iterator operator--(int) + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 __bit_iterator operator--(int) { __bit_iterator __tmp = *this; --(*this); return __tmp; } - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 __bit_iterator& operator+=(difference_type __n) + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 __bit_iterator& operator+=(difference_type __n) { if (__n >= 0) __seg_ += (__n + __ctz_) / __bits_per_word; @@ -1215,54 +1216,54 @@ public: return *this; } - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 __bit_iterator& operator-=(difference_type __n) + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 __bit_iterator& operator-=(difference_type __n) { return *this += -__n; } - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 __bit_iterator operator+(difference_type __n) const + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 __bit_iterator operator+(difference_type __n) const { __bit_iterator __t(*this); __t += __n; return __t; } - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 __bit_iterator operator-(difference_type __n) const + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 __bit_iterator operator-(difference_type __n) const { __bit_iterator __t(*this); __t -= __n; return __t; } - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 friend __bit_iterator operator+(difference_type __n, const __bit_iterator& __it) {return __it + __n;} - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 + _LIBCPP_INLINE_VISIBILITY _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_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 reference operator[](difference_type __n) const {return *(*this + __n);} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 reference operator[](difference_type __n) const {return *(*this + __n);} - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 friend bool operator==(const __bit_iterator& __x, const __bit_iterator& __y) + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 friend bool operator==(const __bit_iterator& __x, const __bit_iterator& __y) {return __x.__seg_ == __y.__seg_ && __x.__ctz_ == __y.__ctz_;} - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 friend bool operator!=(const __bit_iterator& __x, const __bit_iterator& __y) + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 friend bool operator!=(const __bit_iterator& __x, const __bit_iterator& __y) {return !(__x == __y);} - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 friend bool operator<(const __bit_iterator& __x, const __bit_iterator& __y) + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 friend bool operator<(const __bit_iterator& __x, const __bit_iterator& __y) {return __x.__seg_ < __y.__seg_ || (__x.__seg_ == __y.__seg_ && __x.__ctz_ < __y.__ctz_);} - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 friend bool operator>(const __bit_iterator& __x, const __bit_iterator& __y) + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 friend bool operator>(const __bit_iterator& __x, const __bit_iterator& __y) {return __y < __x;} - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 friend bool operator<=(const __bit_iterator& __x, const __bit_iterator& __y) + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 friend bool operator<=(const __bit_iterator& __x, const __bit_iterator& __y) {return !(__y < __x);} - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 friend bool operator>=(const __bit_iterator& __x, const __bit_iterator& __y) + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 friend bool operator>=(const __bit_iterator& __x, const __bit_iterator& __y) {return !(__x < __y);} private: - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit __bit_iterator(__storage_pointer __s, unsigned __ctz) _NOEXCEPT : __seg_(__s), __ctz_(__ctz) {} @@ -1273,40 +1274,40 @@ private: friend class __bit_iterator<_Cp, true>; template friend struct __bit_array; template - _LIBCPP_CONSTEXPR_AFTER_CXX17 + _LIBCPP_CONSTEXPR_SINCE_CXX20 friend void __fill_n_false(__bit_iterator<_Dp, false> __first, typename _Dp::size_type __n); template - _LIBCPP_CONSTEXPR_AFTER_CXX17 + _LIBCPP_CONSTEXPR_SINCE_CXX20 friend void __fill_n_true(__bit_iterator<_Dp, false> __first, typename _Dp::size_type __n); template - _LIBCPP_CONSTEXPR_AFTER_CXX17 + _LIBCPP_CONSTEXPR_SINCE_CXX20 friend __bit_iterator<_Dp, false> __copy_aligned(__bit_iterator<_Dp, _IC> __first, __bit_iterator<_Dp, _IC> __last, __bit_iterator<_Dp, false> __result); template - _LIBCPP_CONSTEXPR_AFTER_CXX17 + _LIBCPP_CONSTEXPR_SINCE_CXX20 friend __bit_iterator<_Dp, false> __copy_unaligned(__bit_iterator<_Dp, _IC> __first, __bit_iterator<_Dp, _IC> __last, __bit_iterator<_Dp, false> __result); template - _LIBCPP_CONSTEXPR_AFTER_CXX17 + _LIBCPP_CONSTEXPR_SINCE_CXX20 friend __bit_iterator<_Dp, false> copy(__bit_iterator<_Dp, _IC> __first, __bit_iterator<_Dp, _IC> __last, __bit_iterator<_Dp, false> __result); template - _LIBCPP_CONSTEXPR_AFTER_CXX17 + _LIBCPP_CONSTEXPR_SINCE_CXX20 friend __bit_iterator<_Dp, false> __copy_backward_aligned(__bit_iterator<_Dp, _IC> __first, __bit_iterator<_Dp, _IC> __last, __bit_iterator<_Dp, false> __result); template - _LIBCPP_CONSTEXPR_AFTER_CXX17 + _LIBCPP_CONSTEXPR_SINCE_CXX20 friend __bit_iterator<_Dp, false> __copy_backward_unaligned(__bit_iterator<_Dp, _IC> __first, __bit_iterator<_Dp, _IC> __last, __bit_iterator<_Dp, false> __result); template - _LIBCPP_CONSTEXPR_AFTER_CXX17 + _LIBCPP_CONSTEXPR_SINCE_CXX20 friend __bit_iterator<_Dp, false> copy_backward(__bit_iterator<_Dp, _IC> __first, __bit_iterator<_Dp, _IC> __last, __bit_iterator<_Dp, false> __result); @@ -1320,32 +1321,33 @@ private: __bit_iterator<__C1, false>, __bit_iterator<__C2, false>); template - _LIBCPP_CONSTEXPR_AFTER_CXX17 + _LIBCPP_CONSTEXPR_SINCE_CXX20 friend __bit_iterator<_Dp, false> rotate(__bit_iterator<_Dp, false>, __bit_iterator<_Dp, false>, __bit_iterator<_Dp, false>); template - _LIBCPP_CONSTEXPR_AFTER_CXX17 + _LIBCPP_CONSTEXPR_SINCE_CXX20 friend bool __equal_aligned(__bit_iterator<_Dp, _IC1>, __bit_iterator<_Dp, _IC1>, __bit_iterator<_Dp, _IC2>); template - _LIBCPP_CONSTEXPR_AFTER_CXX17 + _LIBCPP_CONSTEXPR_SINCE_CXX20 friend bool __equal_unaligned(__bit_iterator<_Dp, _IC1>, __bit_iterator<_Dp, _IC1>, __bit_iterator<_Dp, _IC2>); template - _LIBCPP_CONSTEXPR_AFTER_CXX17 + _LIBCPP_CONSTEXPR_SINCE_CXX20 friend bool equal(__bit_iterator<_Dp, _IC1>, __bit_iterator<_Dp, _IC1>, __bit_iterator<_Dp, _IC2>); template - _LIBCPP_CONSTEXPR_AFTER_CXX17 + _LIBCPP_CONSTEXPR_SINCE_CXX20 friend __bit_iterator<_Dp, _IC> __find_bool_true(__bit_iterator<_Dp, _IC>, typename _Dp::size_type); template - _LIBCPP_CONSTEXPR_AFTER_CXX17 + _LIBCPP_CONSTEXPR_SINCE_CXX20 friend __bit_iterator<_Dp, _IC> __find_bool_false(__bit_iterator<_Dp, _IC>, typename _Dp::size_type); template friend typename __bit_iterator<_Dp, _IC>::difference_type + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 __count_bool_true(__bit_iterator<_Dp, _IC>, typename _Dp::size_type); template friend typename __bit_iterator<_Dp, _IC>::difference_type __count_bool_false(__bit_iterator<_Dp, _IC>, typename _Dp::size_type); diff --git a/lib/libcxx/include/__bits b/lib/libcxx/include/__bits deleted file mode 100644 index 92ef5c0a7b..0000000000 --- a/lib/libcxx/include/__bits +++ /dev/null @@ -1,162 +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___BITS -#define _LIBCPP___BITS - -#include <__config> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - - -_LIBCPP_BEGIN_NAMESPACE_STD - -#ifndef _LIBCPP_COMPILER_MSVC - -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR -int __libcpp_ctz(unsigned __x) _NOEXCEPT { return __builtin_ctz(__x); } - -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR -int __libcpp_ctz(unsigned long __x) _NOEXCEPT { return __builtin_ctzl(__x); } - -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR -int __libcpp_ctz(unsigned long long __x) _NOEXCEPT { return __builtin_ctzll(__x); } - - -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR -int __libcpp_clz(unsigned __x) _NOEXCEPT { return __builtin_clz(__x); } - -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR -int __libcpp_clz(unsigned long __x) _NOEXCEPT { return __builtin_clzl(__x); } - -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR -int __libcpp_clz(unsigned long long __x) _NOEXCEPT { return __builtin_clzll(__x); } - -# ifndef _LIBCPP_HAS_NO_INT128 -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR -int __libcpp_clz(__uint128_t __x) _NOEXCEPT { - // The function is written in this form due to C++ constexpr limitations. - // The algorithm: - // - Test whether any bit in the high 64-bits is set - // - No bits set: - // - The high 64-bits contain 64 leading zeros, - // - Add the result of the low 64-bits. - // - Any bits set: - // - The number of leading zeros of the input is the number of leading - // zeros in the high 64-bits. - return ((__x >> 64) == 0) - ? (64 + __builtin_clzll(static_cast(__x))) - : __builtin_clzll(static_cast(__x >> 64)); -} -# endif - -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR -int __libcpp_popcount(unsigned __x) _NOEXCEPT { return __builtin_popcount(__x); } - -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR -int __libcpp_popcount(unsigned long __x) _NOEXCEPT { return __builtin_popcountl(__x); } - -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR -int __libcpp_popcount(unsigned long long __x) _NOEXCEPT { return __builtin_popcountll(__x); } - -#else // _LIBCPP_COMPILER_MSVC - -// Precondition: __x != 0 -inline _LIBCPP_INLINE_VISIBILITY -int __libcpp_ctz(unsigned __x) { - static_assert(sizeof(unsigned) == sizeof(unsigned long), ""); - static_assert(sizeof(unsigned long) == 4, ""); - unsigned long __where; - if (_BitScanForward(&__where, __x)) - return static_cast(__where); - return 32; -} - -inline _LIBCPP_INLINE_VISIBILITY -int __libcpp_ctz(unsigned long __x) { - static_assert(sizeof(unsigned long) == sizeof(unsigned), ""); - return __ctz(static_cast(__x)); -} - -inline _LIBCPP_INLINE_VISIBILITY -int __libcpp_ctz(unsigned long long __x) { - unsigned long __where; -#if defined(_LIBCPP_HAS_BITSCAN64) - if (_BitScanForward64(&__where, __x)) - return static_cast(__where); -#else - // Win32 doesn't have _BitScanForward64 so emulate it with two 32 bit calls. - if (_BitScanForward(&__where, static_cast(__x))) - return static_cast(__where); - if (_BitScanForward(&__where, static_cast(__x >> 32))) - return static_cast(__where + 32); -#endif - return 64; -} - -// Precondition: __x != 0 -inline _LIBCPP_INLINE_VISIBILITY -int __libcpp_clz(unsigned __x) { - static_assert(sizeof(unsigned) == sizeof(unsigned long), ""); - static_assert(sizeof(unsigned long) == 4, ""); - unsigned long __where; - if (_BitScanReverse(&__where, __x)) - return static_cast(31 - __where); - return 32; // Undefined Behavior. -} - -inline _LIBCPP_INLINE_VISIBILITY -int __libcpp_clz(unsigned long __x) { - static_assert(sizeof(unsigned) == sizeof(unsigned long), ""); - return __libcpp_clz(static_cast(__x)); -} - -inline _LIBCPP_INLINE_VISIBILITY -int __libcpp_clz(unsigned long long __x) { - unsigned long __where; -#if defined(_LIBCPP_HAS_BITSCAN64) - if (_BitScanReverse64(&__where, __x)) - return static_cast(63 - __where); -#else - // Win32 doesn't have _BitScanReverse64 so emulate it with two 32 bit calls. - if (_BitScanReverse(&__where, static_cast(__x >> 32))) - return static_cast(63 - (__where + 32)); - if (_BitScanReverse(&__where, static_cast(__x))) - return static_cast(63 - __where); -#endif - return 64; // Undefined Behavior. -} - -inline _LIBCPP_INLINE_VISIBILITY int __libcpp_popcount(unsigned __x) { - static_assert(sizeof(unsigned) == 4, ""); - return __popcnt(__x); -} - -inline _LIBCPP_INLINE_VISIBILITY int __libcpp_popcount(unsigned long __x) { - static_assert(sizeof(unsigned long) == 4, ""); - return __popcnt(__x); -} - -inline _LIBCPP_INLINE_VISIBILITY int __libcpp_popcount(unsigned long long __x) { - static_assert(sizeof(unsigned long long) == 8, ""); - return __popcnt64(__x); -} - -#endif // _LIBCPP_COMPILER_MSVC - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___BITS diff --git a/lib/libcxx/include/__bsd_locale_fallbacks.h b/lib/libcxx/include/__bsd_locale_fallbacks.h index 3d5b785744..9abd7e7e5f 100644 --- a/lib/libcxx/include/__bsd_locale_fallbacks.h +++ b/lib/libcxx/include/__bsd_locale_fallbacks.h @@ -13,7 +13,6 @@ #ifndef _LIBCPP___BSD_LOCALE_FALLBACKS_H #define _LIBCPP___BSD_LOCALE_FALLBACKS_H -#include #include #include diff --git a/lib/libcxx/include/__charconv/chars_format.h b/lib/libcxx/include/__charconv/chars_format.h index 0875079e6c..695bd87318 100644 --- a/lib/libcxx/include/__charconv/chars_format.h +++ b/lib/libcxx/include/__charconv/chars_format.h @@ -19,7 +19,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD -#ifndef _LIBCPP_CXX03_LANG +#if _LIBCPP_STD_VER > 14 enum class _LIBCPP_ENUM_VIS chars_format { @@ -52,25 +52,25 @@ operator^(chars_format __x, chars_format __y) { _VSTD::__to_underlying(__y)); } -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 chars_format& +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14 chars_format& operator&=(chars_format& __x, chars_format __y) { __x = __x & __y; return __x; } -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 chars_format& +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14 chars_format& operator|=(chars_format& __x, chars_format __y) { __x = __x | __y; return __x; } -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 chars_format& +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14 chars_format& operator^=(chars_format& __x, chars_format __y) { __x = __x ^ __y; return __x; } -#endif // _LIBCPP_CXX03_LANG +#endif // _LIBCPP_STD_VER > 14 _LIBCPP_END_NAMESPACE_STD diff --git a/lib/libcxx/include/__charconv/from_chars_result.h b/lib/libcxx/include/__charconv/from_chars_result.h index 2cc3c11ef6..05ffe1485c 100644 --- a/lib/libcxx/include/__charconv/from_chars_result.h +++ b/lib/libcxx/include/__charconv/from_chars_result.h @@ -19,7 +19,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD -#ifndef _LIBCPP_CXX03_LANG +#if _LIBCPP_STD_VER > 14 struct _LIBCPP_TYPE_VIS from_chars_result { @@ -30,7 +30,7 @@ struct _LIBCPP_TYPE_VIS from_chars_result # endif }; -#endif // _LIBCPP_CXX03_LANG +#endif // _LIBCPP_STD_VER > 14 _LIBCPP_END_NAMESPACE_STD diff --git a/lib/libcxx/include/__charconv/tables.h b/lib/libcxx/include/__charconv/tables.h index 83f39e6fd2..9b82440348 100644 --- a/lib/libcxx/include/__charconv/tables.h +++ b/lib/libcxx/include/__charconv/tables.h @@ -19,38 +19,16 @@ _LIBCPP_BEGIN_NAMESPACE_STD -#ifndef _LIBCPP_CXX03_LANG +#if _LIBCPP_STD_VER > 14 namespace __itoa { -/// Contains the charconv helper tables. -/// -/// In C++17 these could be inline constexpr variable, but libc++ supports -/// charconv for integrals in C++11 mode. -template -struct __table { - static const char __base_2_lut[64]; - static const char __base_8_lut[128]; - static const char __base_16_lut[512]; - - static const uint32_t __pow10_32[10]; - static const uint64_t __pow10_64[20]; -# ifndef _LIBCPP_HAS_NO_INT128 - // TODO FMT Reduce the number of entries in this table. - static const __uint128_t __pow10_128[40]; - static const int __pow10_128_offset = 0; -# endif - static const char __digits_base_10[200]; -}; - -template -const char __table<_Tp>::__base_2_lut[64] = { +inline constexpr char __base_2_lut[64] = { '0', '0', '0', '0', '0', '0', '0', '1', '0', '0', '1', '0', '0', '0', '1', '1', '0', '1', '0', '0', '0', '1', '0', '1', '0', '1', '1', '0', '0', '1', '1', '1', '1', '0', '0', '0', '1', '0', '0', '1', '1', '0', '1', '0', '1', '0', '1', '1', '1', '1', '0', '0', '1', '1', '0', '1', '1', '1', '1', '0', '1', '1', '1', '1'}; -template -const char __table<_Tp>::__base_8_lut[128] = { +inline constexpr char __base_8_lut[128] = { '0', '0', '0', '1', '0', '2', '0', '3', '0', '4', '0', '5', '0', '6', '0', '7', '1', '0', '1', '1', '1', '2', '1', '3', '1', '4', '1', '5', '1', '6', '1', '7', '2', '0', '2', '1', '2', '2', '2', '3', '2', '4', '2', '5', '2', '6', '2', '7', '3', '0', '3', '1', '3', '2', '3', '3', '3', '4', '3', '5', '3', '6', '3', '7', '4', '0', @@ -58,8 +36,7 @@ const char __table<_Tp>::__base_8_lut[128] = { '5', '4', '5', '5', '5', '6', '5', '7', '6', '0', '6', '1', '6', '2', '6', '3', '6', '4', '6', '5', '6', '6', '6', '7', '7', '0', '7', '1', '7', '2', '7', '3', '7', '4', '7', '5', '7', '6', '7', '7'}; -template -const char __table<_Tp>::__base_16_lut[512] = { +inline constexpr char __base_16_lut[512] = { '0', '0', '0', '1', '0', '2', '0', '3', '0', '4', '0', '5', '0', '6', '0', '7', '0', '8', '0', '9', '0', 'a', '0', 'b', '0', 'c', '0', 'd', '0', 'e', '0', 'f', '1', '0', '1', '1', '1', '2', '1', '3', '1', '4', '1', '5', '1', '6', '1', '7', '1', '8', '1', '9', '1', 'a', '1', 'b', '1', 'c', '1', 'd', '1', 'e', '1', 'f', '2', '0', '2', '1', '2', @@ -84,13 +61,11 @@ const char __table<_Tp>::__base_16_lut[512] = { '1', 'f', '2', 'f', '3', 'f', '4', 'f', '5', 'f', '6', 'f', '7', 'f', '8', 'f', '9', 'f', 'a', 'f', 'b', 'f', 'c', 'f', 'd', 'f', 'e', 'f', 'f'}; -template -const uint32_t __table<_Tp>::__pow10_32[10] = { +inline constexpr uint32_t __pow10_32[10] = { UINT32_C(0), UINT32_C(10), UINT32_C(100), UINT32_C(1000), UINT32_C(10000), UINT32_C(100000), UINT32_C(1000000), UINT32_C(10000000), UINT32_C(100000000), UINT32_C(1000000000)}; -template -const uint64_t __table<_Tp>::__pow10_64[20] = {UINT64_C(0), +inline constexpr uint64_t __pow10_64[20] = {UINT64_C(0), UINT64_C(10), UINT64_C(100), UINT64_C(1000), @@ -112,8 +87,8 @@ const uint64_t __table<_Tp>::__pow10_64[20] = {UINT64_C(0), UINT64_C(10000000000000000000)}; # ifndef _LIBCPP_HAS_NO_INT128 -template -const __uint128_t __table<_Tp>::__pow10_128[40] = { +inline constexpr int __pow10_128_offset = 0; +inline constexpr __uint128_t __pow10_128[40] = { UINT64_C(0), UINT64_C(10), UINT64_C(100), @@ -156,8 +131,7 @@ const __uint128_t __table<_Tp>::__pow10_128[40] = { (__uint128_t(UINT64_C(10000000000000000000)) * UINT64_C(10000000000000000000)) * 10}; # endif -template -const char __table<_Tp>::__digits_base_10[200] = { +inline constexpr char __digits_base_10[200] = { // clang-format off '0', '0', '0', '1', '0', '2', '0', '3', '0', '4', '0', '5', '0', '6', '0', '7', '0', '8', '0', '9', '1', '0', '1', '1', '1', '2', '1', '3', '1', '4', '1', '5', '1', '6', '1', '7', '1', '8', '1', '9', @@ -173,7 +147,7 @@ const char __table<_Tp>::__digits_base_10[200] = { } // namespace __itoa -#endif // _LIBCPP_CXX03_LANG +#endif // _LIBCPP_STD_VER > 14 _LIBCPP_END_NAMESPACE_STD diff --git a/lib/libcxx/include/__charconv/to_chars_base_10.h b/lib/libcxx/include/__charconv/to_chars_base_10.h index d25deffc59..fc7fb76e3e 100644 --- a/lib/libcxx/include/__charconv/to_chars_base_10.h +++ b/lib/libcxx/include/__charconv/to_chars_base_10.h @@ -25,54 +25,54 @@ _LIBCPP_PUSH_MACROS _LIBCPP_BEGIN_NAMESPACE_STD -#ifndef _LIBCPP_CXX03_LANG +#if _LIBCPP_STD_VER > 14 namespace __itoa { -_LIBCPP_HIDE_FROM_ABI inline char* __append1(char* __first, uint32_t __value) noexcept { +_LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI inline char* __append1(char* __first, uint32_t __value) noexcept { *__first = '0' + static_cast(__value); return __first + 1; } -_LIBCPP_HIDE_FROM_ABI inline char* __append2(char* __first, uint32_t __value) noexcept { - return std::copy_n(&__table<>::__digits_base_10[__value * 2], 2, __first); +_LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI inline char* __append2(char* __first, uint32_t __value) noexcept { + return std::copy_n(&__digits_base_10[__value * 2], 2, __first); } -_LIBCPP_HIDE_FROM_ABI inline char* __append3(char* __first, uint32_t __value) noexcept { +_LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI inline char* __append3(char* __first, uint32_t __value) noexcept { return __itoa::__append2(__itoa::__append1(__first, __value / 100), __value % 100); } -_LIBCPP_HIDE_FROM_ABI inline char* __append4(char* __first, uint32_t __value) noexcept { +_LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI inline char* __append4(char* __first, uint32_t __value) noexcept { return __itoa::__append2(__itoa::__append2(__first, __value / 100), __value % 100); } -_LIBCPP_HIDE_FROM_ABI inline char* __append5(char* __first, uint32_t __value) noexcept { +_LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI inline char* __append5(char* __first, uint32_t __value) noexcept { return __itoa::__append4(__itoa::__append1(__first, __value / 10000), __value % 10000); } -_LIBCPP_HIDE_FROM_ABI inline char* __append6(char* __first, uint32_t __value) noexcept { +_LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI inline char* __append6(char* __first, uint32_t __value) noexcept { return __itoa::__append4(__itoa::__append2(__first, __value / 10000), __value % 10000); } -_LIBCPP_HIDE_FROM_ABI inline char* __append7(char* __first, uint32_t __value) noexcept { +_LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI inline char* __append7(char* __first, uint32_t __value) noexcept { return __itoa::__append6(__itoa::__append1(__first, __value / 1000000), __value % 1000000); } -_LIBCPP_HIDE_FROM_ABI inline char* __append8(char* __first, uint32_t __value) noexcept { +_LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI inline char* __append8(char* __first, uint32_t __value) noexcept { return __itoa::__append6(__itoa::__append2(__first, __value / 1000000), __value % 1000000); } -_LIBCPP_HIDE_FROM_ABI inline char* __append9(char* __first, uint32_t __value) noexcept { +_LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI inline char* __append9(char* __first, uint32_t __value) noexcept { return __itoa::__append8(__itoa::__append1(__first, __value / 100000000), __value % 100000000); } template -_LIBCPP_HIDE_FROM_ABI char* __append10(char* __first, _Tp __value) noexcept { +_LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI char* __append10(char* __first, _Tp __value) noexcept { return __itoa::__append8(__itoa::__append2(__first, static_cast(__value / 100000000)), static_cast(__value % 100000000)); } -_LIBCPP_HIDE_FROM_ABI inline char* __base_10_u32(char* __first, uint32_t __value) noexcept { +_LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI inline char* __base_10_u32(char* __first, uint32_t __value) noexcept { if (__value < 1000000) { if (__value < 10000) { if (__value < 100) { @@ -107,7 +107,7 @@ _LIBCPP_HIDE_FROM_ABI inline char* __base_10_u32(char* __first, uint32_t __value return __itoa::__append10(__first, __value); } -_LIBCPP_HIDE_FROM_ABI inline char* __base_10_u64(char* __buffer, uint64_t __value) noexcept { +_LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI inline char* __base_10_u64(char* __buffer, uint64_t __value) noexcept { if (__value <= UINT32_MAX) return __itoa::__base_10_u32(__buffer, static_cast(__value)); @@ -129,12 +129,12 @@ _LIBCPP_HIDE_FROM_ABI inline char* __base_10_u64(char* __buffer, uint64_t __valu /// \note The lookup table contains a partial set of exponents limiting the /// range that can be used. However the range is sufficient for /// \ref __base_10_u128. -_LIBCPP_HIDE_FROM_ABI inline __uint128_t __pow_10(int __exp) noexcept { - _LIBCPP_ASSERT(__exp >= __table<>::__pow10_128_offset, "Index out of bounds"); - return __table<>::__pow10_128[__exp - __table<>::__pow10_128_offset]; +_LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI inline __uint128_t __pow_10(int __exp) noexcept { + _LIBCPP_ASSERT(__exp >= __pow10_128_offset, "Index out of bounds"); + return __pow10_128[__exp - __pow10_128_offset]; } -_LIBCPP_HIDE_FROM_ABI inline char* __base_10_u128(char* __buffer, __uint128_t __value) noexcept { +_LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI inline char* __base_10_u128(char* __buffer, __uint128_t __value) noexcept { _LIBCPP_ASSERT( __value > numeric_limits::max(), "The optimizations for this algorithm fail when this isn't true."); @@ -176,7 +176,7 @@ _LIBCPP_HIDE_FROM_ABI inline char* __base_10_u128(char* __buffer, __uint128_t __ # endif } // namespace __itoa -#endif // _LIBCPP_CXX03_LANG +#endif // _LIBCPP_STD_VER > 14 _LIBCPP_END_NAMESPACE_STD diff --git a/lib/libcxx/include/__charconv/to_chars_result.h b/lib/libcxx/include/__charconv/to_chars_result.h index b4bc6ac263..2eb4098dfc 100644 --- a/lib/libcxx/include/__charconv/to_chars_result.h +++ b/lib/libcxx/include/__charconv/to_chars_result.h @@ -19,7 +19,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD -#ifndef _LIBCPP_CXX03_LANG +#if _LIBCPP_STD_VER > 14 struct _LIBCPP_TYPE_VIS to_chars_result { @@ -30,7 +30,7 @@ struct _LIBCPP_TYPE_VIS to_chars_result # endif }; -#endif // _LIBCPP_CXX03_LANG +#endif // _LIBCPP_STD_VER > 14 _LIBCPP_END_NAMESPACE_STD diff --git a/lib/libcxx/include/__chrono/convert_to_timespec.h b/lib/libcxx/include/__chrono/convert_to_timespec.h index e8631d135f..fab07f2567 100644 --- a/lib/libcxx/include/__chrono/convert_to_timespec.h +++ b/lib/libcxx/include/__chrono/convert_to_timespec.h @@ -6,6 +6,7 @@ // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// + #ifndef _LIBCPP___CHRONO_CONVERT_TO_TIMESPEC_H #define _LIBCPP___CHRONO_CONVERT_TO_TIMESPEC_H diff --git a/lib/libcxx/include/__chrono/convert_to_tm.h b/lib/libcxx/include/__chrono/convert_to_tm.h new file mode 100644 index 0000000000..36846b3f71 --- /dev/null +++ b/lib/libcxx/include/__chrono/convert_to_tm.h @@ -0,0 +1,127 @@ +// -*- 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___CHRONO_CONVERT_TO_TM_H +#define _LIBCPP___CHRONO_CONVERT_TO_TM_H + +#include <__chrono/day.h> +#include <__chrono/duration.h> +#include <__chrono/hh_mm_ss.h> +#include <__chrono/month.h> +#include <__chrono/month_weekday.h> +#include <__chrono/monthday.h> +#include <__chrono/statically_widen.h> +#include <__chrono/system_clock.h> +#include <__chrono/time_point.h> +#include <__chrono/weekday.h> +#include <__chrono/year.h> +#include <__chrono/year_month.h> +#include <__chrono/year_month_day.h> +#include <__chrono/year_month_weekday.h> +#include <__concepts/same_as.h> +#include <__config> +#include <__memory/addressof.h> +#include +#include + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +#if _LIBCPP_STD_VER > 17 + +// Conerts a chrono date and weekday to a given _Tm type. +// +// This is an implementation detail for the function +// template +// _Tm __convert_to_tm(const _ChronoT& __value) +// +// This manually converts the two values to the proper type. It is possible to +// convert from sys_days to time_t and then to _Tm. But this leads to the Y2K +// bug when time_t is a 32-bit signed integer. Chrono considers years beyond +// the year 2038 valid, so instead do the transformation manually. +template + requires(same_as<_Date, chrono::year_month_day> || same_as<_Date, chrono::year_month_day_last>) +_LIBCPP_HIDE_FROM_ABI _Tm __convert_to_tm(const _Date& __date, chrono::weekday __weekday) { + _Tm __result = {}; +# ifdef __GLIBC__ + __result.tm_zone = "UTC"; +# endif + __result.tm_year = static_cast(__date.year()) - 1900; + __result.tm_mon = static_cast(__date.month()) - 1; + __result.tm_mday = static_cast(__date.day()); + __result.tm_wday = static_cast(__weekday.c_encoding()); + __result.tm_yday = + (static_cast(__date) - + static_cast(chrono::year_month_day{__date.year(), chrono::January, chrono::day{1}})) + .count(); + + return __result; +} + +// Convert a chrono (calendar) time point, or dururation to the given _Tm type, +// which must have the same properties as std::tm. +template +_LIBCPP_HIDE_FROM_ABI _Tm __convert_to_tm(const _ChronoT& __value) { + _Tm __result = {}; +# ifdef __GLIBC__ + __result.tm_zone = "UTC"; +# endif + + if constexpr (chrono::__is_duration<_ChronoT>::value) { + // [time.format]/6 + // ... However, if a flag refers to a "time of day" (e.g. %H, %I, %p, + // etc.), then a specialization of duration is interpreted as the time of + // day elapsed since midnight. + uint64_t __sec = chrono::duration_cast(__value).count(); + __sec %= 24 * 3600; + __result.tm_hour = __sec / 3600; + __sec %= 3600; + __result.tm_min = __sec / 60; + __result.tm_sec = __sec % 60; + } else if constexpr (same_as<_ChronoT, chrono::day>) + __result.tm_mday = static_cast(__value); + else if constexpr (same_as<_ChronoT, chrono::month>) + __result.tm_mon = static_cast(__value) - 1; + else if constexpr (same_as<_ChronoT, chrono::year>) + __result.tm_year = static_cast(__value) - 1900; + else if constexpr (same_as<_ChronoT, chrono::weekday>) + __result.tm_wday = __value.c_encoding(); + else if constexpr (same_as<_ChronoT, chrono::weekday_indexed> || same_as<_ChronoT, chrono::weekday_last>) + __result.tm_wday = __value.weekday().c_encoding(); + else if constexpr (same_as<_ChronoT, chrono::month_day>) { + __result.tm_mday = static_cast(__value.day()); + __result.tm_mon = static_cast(__value.month()) - 1; + } else if constexpr (same_as<_ChronoT, chrono::month_day_last>) { + __result.tm_mon = static_cast(__value.month()) - 1; + } else if constexpr (same_as<_ChronoT, chrono::month_weekday> || same_as<_ChronoT, chrono::month_weekday_last>) { + __result.tm_wday = __value.weekday_indexed().weekday().c_encoding(); + __result.tm_mon = static_cast(__value.month()) - 1; + } else if constexpr (same_as<_ChronoT, chrono::year_month>) { + __result.tm_year = static_cast(__value.year()) - 1900; + __result.tm_mon = static_cast(__value.month()) - 1; + } else if constexpr (same_as<_ChronoT, chrono::year_month_day> || same_as<_ChronoT, chrono::year_month_day_last>) { + return std::__convert_to_tm<_Tm>( + chrono::year_month_day{__value}, chrono::weekday{static_cast(__value)}); + } else if constexpr (same_as<_ChronoT, chrono::year_month_weekday> || + same_as<_ChronoT, chrono::year_month_weekday_last>) { + return std::__convert_to_tm<_Tm>(chrono::year_month_day{static_cast(__value)}, __value.weekday()); + } else + static_assert(sizeof(_ChronoT) == 0, "Add the missing type specialization"); + + return __result; +} + +#endif //if _LIBCPP_STD_VER > 17 + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___CHRONO_CONVERT_TO_TM_H diff --git a/lib/libcxx/include/__chrono/day.h b/lib/libcxx/include/__chrono/day.h index d9fa4ffbc4..35ecfcf9e5 100644 --- a/lib/libcxx/include/__chrono/day.h +++ b/lib/libcxx/include/__chrono/day.h @@ -27,18 +27,18 @@ namespace chrono class day { private: - unsigned char __d; + unsigned char __d_; public: _LIBCPP_HIDE_FROM_ABI day() = default; - _LIBCPP_HIDE_FROM_ABI explicit inline constexpr day(unsigned __val) noexcept : __d(static_cast(__val)) {} - _LIBCPP_HIDE_FROM_ABI inline constexpr day& operator++() noexcept { ++__d; return *this; } + _LIBCPP_HIDE_FROM_ABI explicit inline constexpr day(unsigned __val) noexcept : __d_(static_cast(__val)) {} + _LIBCPP_HIDE_FROM_ABI inline constexpr day& operator++() noexcept { ++__d_; return *this; } _LIBCPP_HIDE_FROM_ABI inline constexpr day operator++(int) noexcept { day __tmp = *this; ++(*this); return __tmp; } - _LIBCPP_HIDE_FROM_ABI inline constexpr day& operator--() noexcept { --__d; return *this; } + _LIBCPP_HIDE_FROM_ABI inline constexpr day& operator--() noexcept { --__d_; return *this; } _LIBCPP_HIDE_FROM_ABI inline constexpr day operator--(int) noexcept { day __tmp = *this; --(*this); return __tmp; } _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; } + _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; } }; diff --git a/lib/libcxx/include/__chrono/duration.h b/lib/libcxx/include/__chrono/duration.h index c502574fb2..afcc38b5cf 100644 --- a/lib/libcxx/include/__chrono/duration.h +++ b/lib/libcxx/include/__chrono/duration.h @@ -11,9 +11,12 @@ #define _LIBCPP___CHRONO_DURATION_H #include <__config> +#include <__type_traits/common_type.h> +#include <__type_traits/enable_if.h> +#include <__type_traits/is_convertible.h> +#include <__type_traits/is_floating_point.h> #include #include -#include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header @@ -151,7 +154,7 @@ typename enable_if >::type floor(const duration<_Rep, _Period>& __d) { - _ToDuration __t = duration_cast<_ToDuration>(__d); + _ToDuration __t = chrono::duration_cast<_ToDuration>(__d); if (__t > __d) __t = __t - _ToDuration{1}; return __t; @@ -166,7 +169,7 @@ typename enable_if >::type ceil(const duration<_Rep, _Period>& __d) { - _ToDuration __t = duration_cast<_ToDuration>(__d); + _ToDuration __t = chrono::duration_cast<_ToDuration>(__d); if (__t < __d) __t = __t + _ToDuration{1}; return __t; @@ -181,7 +184,7 @@ typename enable_if >::type round(const duration<_Rep, _Period>& __d) { - _ToDuration __lower = floor<_ToDuration>(__d); + _ToDuration __lower = chrono::floor<_ToDuration>(__d); _ToDuration __upper = __lower + _ToDuration{1}; auto __lowerDiff = __d - __lower; auto __upperDiff = __upper - __d; @@ -278,18 +281,18 @@ public: _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR typename common_type::type operator+() const {return typename common_type::type(*this);} _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR typename common_type::type operator-() const {return typename common_type::type(-__rep_);} - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator++() {++__rep_; return *this;} - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration operator++(int) {return duration(__rep_++);} - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator--() {--__rep_; return *this;} - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration operator--(int) {return duration(__rep_--);} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17 duration& operator++() {++__rep_; return *this;} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17 duration operator++(int) {return duration(__rep_++);} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17 duration& operator--() {--__rep_; return *this;} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17 duration operator--(int) {return duration(__rep_--);} - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator+=(const duration& __d) {__rep_ += __d.count(); return *this;} - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator-=(const duration& __d) {__rep_ -= __d.count(); return *this;} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17 duration& operator+=(const duration& __d) {__rep_ += __d.count(); return *this;} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17 duration& operator-=(const duration& __d) {__rep_ -= __d.count(); return *this;} - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator*=(const rep& __rhs) {__rep_ *= __rhs; return *this;} - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator/=(const rep& __rhs) {__rep_ /= __rhs; return *this;} - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator%=(const rep& __rhs) {__rep_ %= __rhs; return *this;} - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator%=(const duration& __rhs) {__rep_ %= __rhs.count(); return *this;} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17 duration& operator*=(const rep& __rhs) {__rep_ *= __rhs; return *this;} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17 duration& operator/=(const rep& __rhs) {__rep_ /= __rhs; return *this;} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17 duration& operator%=(const rep& __rhs) {__rep_ %= __rhs; return *this;} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17 duration& operator%=(const duration& __rhs) {__rep_ %= __rhs.count(); return *this;} // special values @@ -534,67 +537,67 @@ inline namespace literals inline namespace chrono_literals { - constexpr chrono::hours operator""h(unsigned long long __h) + _LIBCPP_HIDE_FROM_ABI constexpr chrono::hours operator""h(unsigned long long __h) { return chrono::hours(static_cast(__h)); } - constexpr chrono::duration> operator""h(long double __h) + _LIBCPP_HIDE_FROM_ABI constexpr chrono::duration> operator""h(long double __h) { return chrono::duration>(__h); } - constexpr chrono::minutes operator""min(unsigned long long __m) + _LIBCPP_HIDE_FROM_ABI constexpr chrono::minutes operator""min(unsigned long long __m) { return chrono::minutes(static_cast(__m)); } - constexpr chrono::duration> operator""min(long double __m) + _LIBCPP_HIDE_FROM_ABI constexpr chrono::duration> operator""min(long double __m) { return chrono::duration> (__m); } - constexpr chrono::seconds operator""s(unsigned long long __s) + _LIBCPP_HIDE_FROM_ABI constexpr chrono::seconds operator""s(unsigned long long __s) { return chrono::seconds(static_cast(__s)); } - constexpr chrono::duration operator""s(long double __s) + _LIBCPP_HIDE_FROM_ABI constexpr chrono::duration operator""s(long double __s) { return chrono::duration (__s); } - constexpr chrono::milliseconds operator""ms(unsigned long long __ms) + _LIBCPP_HIDE_FROM_ABI constexpr chrono::milliseconds operator""ms(unsigned long long __ms) { return chrono::milliseconds(static_cast(__ms)); } - constexpr chrono::duration operator""ms(long double __ms) + _LIBCPP_HIDE_FROM_ABI constexpr chrono::duration operator""ms(long double __ms) { return chrono::duration(__ms); } - constexpr chrono::microseconds operator""us(unsigned long long __us) + _LIBCPP_HIDE_FROM_ABI constexpr chrono::microseconds operator""us(unsigned long long __us) { return chrono::microseconds(static_cast(__us)); } - constexpr chrono::duration operator""us(long double __us) + _LIBCPP_HIDE_FROM_ABI constexpr chrono::duration operator""us(long double __us) { return chrono::duration (__us); } - constexpr chrono::nanoseconds operator""ns(unsigned long long __ns) + _LIBCPP_HIDE_FROM_ABI constexpr chrono::nanoseconds operator""ns(unsigned long long __ns) { return chrono::nanoseconds(static_cast(__ns)); } - constexpr chrono::duration operator""ns(long double __ns) + _LIBCPP_HIDE_FROM_ABI constexpr chrono::duration operator""ns(long double __ns) { return chrono::duration (__ns); } @@ -612,4 +615,8 @@ _LIBCPP_END_NAMESPACE_STD _LIBCPP_POP_MACROS +#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20 +# include +#endif + #endif // _LIBCPP___CHRONO_DURATION_H diff --git a/lib/libcxx/include/__chrono/file_clock.h b/lib/libcxx/include/__chrono/file_clock.h index b8e08e78ba..ef62b83295 100644 --- a/lib/libcxx/include/__chrono/file_clock.h +++ b/lib/libcxx/include/__chrono/file_clock.h @@ -61,7 +61,7 @@ struct _FilesystemClock { typedef chrono::time_point<_FilesystemClock> time_point; _LIBCPP_EXPORTED_FROM_ABI - static _LIBCPP_CONSTEXPR_AFTER_CXX11 const bool is_steady = false; + static _LIBCPP_CONSTEXPR_SINCE_CXX14 const bool is_steady = false; _LIBCPP_AVAILABILITY_FILESYSTEM _LIBCPP_FUNC_VIS static time_point now() noexcept; diff --git a/lib/libcxx/include/__chrono/formatter.h b/lib/libcxx/include/__chrono/formatter.h new file mode 100644 index 0000000000..2015783acb --- /dev/null +++ b/lib/libcxx/include/__chrono/formatter.h @@ -0,0 +1,716 @@ +// -*- 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___CHRONO_FORMATTER_H +#define _LIBCPP___CHRONO_FORMATTER_H + +#include <__chrono/calendar.h> +#include <__chrono/convert_to_tm.h> +#include <__chrono/day.h> +#include <__chrono/duration.h> +#include <__chrono/hh_mm_ss.h> +#include <__chrono/month.h> +#include <__chrono/month_weekday.h> +#include <__chrono/monthday.h> +#include <__chrono/ostream.h> +#include <__chrono/parser_std_format_spec.h> +#include <__chrono/statically_widen.h> +#include <__chrono/time_point.h> +#include <__chrono/weekday.h> +#include <__chrono/year.h> +#include <__chrono/year_month.h> +#include <__chrono/year_month_day.h> +#include <__chrono/year_month_weekday.h> +#include <__concepts/arithmetic.h> +#include <__concepts/same_as.h> +#include <__config> +#include <__format/concepts.h> +#include <__format/format_error.h> +#include <__format/format_functions.h> +#include <__format/format_parse_context.h> +#include <__format/formatter.h> +#include <__format/formatter_output.h> +#include <__format/parser_std_format_spec.h> +#include <__memory/addressof.h> +#include +#include +#include +#include +#include + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_FORMAT) + +namespace __formatter { + +/// Formats a time based on a tm struct. +/// +/// This formatter passes the formatting to time_put which uses strftime. When +/// the value is outside the valid range it's unspecified what strftime will +/// output. For example weekday 8 can print 1 when the day is processed modulo +/// 7 since that handles the Sunday for 0-based weekday. It can also print 8 if +/// 7 is handled as a special case. +/// +/// The Standard doesn't specify what to do in this case so the result depends +/// on the result of the underlying code. +/// +/// \pre When the (abbreviated) weekday or month name are used, the caller +/// validates whether the value is valid. So the caller handles that +/// requirement of Table 97: Meaning of conversion specifiers +/// [tab:time.format.spec]. +/// +/// When no chrono-specs are provided it uses the stream formatter. + +// For tiny ratios it's not possible to convert a duration to a hh_mm_ss. This +// fails compile-time due to the limited precision of the ratio (64-bit is too +// small). Therefore a duration uses its own conversion. +template + requires(chrono::__is_duration<_Tp>::value) +_LIBCPP_HIDE_FROM_ABI void __format_sub_seconds(const _Tp& __value, basic_stringstream<_CharT>& __sstr) { + __sstr << std::use_facet>(__sstr.getloc()).decimal_point(); + + auto __fraction = __value - chrono::duration_cast(__value); + if constexpr (chrono::treat_as_floating_point_v) + // When the floating-point value has digits itself they are ignored based + // on the wording in [tab:time.format.spec] + // If the precision of the input cannot be exactly represented with + // seconds, then the format is a decimal floating-point number with a + // fixed format and a precision matching that of the precision of the + // input (or to a microseconds precision if the conversion to + // floating-point decimal seconds cannot be made within 18 fractional + // digits). + // + // This matches the behaviour of MSVC STL, fmtlib interprets this + // differently and uses 3 decimals. + // https://godbolt.org/z/6dsbnW8ba + std::format_to(std::ostreambuf_iterator<_CharT>{__sstr}, + _LIBCPP_STATICALLY_WIDEN(_CharT, "{:0{}.0f}"), + __fraction.count(), + chrono::hh_mm_ss<_Tp>::fractional_width); + else + std::format_to(std::ostreambuf_iterator<_CharT>{__sstr}, + _LIBCPP_STATICALLY_WIDEN(_CharT, "{:0{}}"), + __fraction.count(), + chrono::hh_mm_ss<_Tp>::fractional_width); +} + +template +consteval bool __use_fraction() { + if constexpr (chrono::__is_duration<_Tp>::value) + return chrono::hh_mm_ss<_Tp>::fractional_width; + else + return false; +} + +template +_LIBCPP_HIDE_FROM_ABI void __format_year(int __year, basic_stringstream<_CharT>& __sstr) { + if (__year < 0) { + __sstr << _CharT('-'); + __year = -__year; + } + + // TODO FMT Write an issue + // If the result has less than four digits it is zero-padded with 0 to two digits. + // is less -> has less + // left-padded -> zero-padded, otherwise the proper value would be 000-0. + + // Note according to the wording it should be left padded, which is odd. + __sstr << std::format(_LIBCPP_STATICALLY_WIDEN(_CharT, "{:04}"), __year); +} + +template +_LIBCPP_HIDE_FROM_ABI void __format_century(int __year, basic_stringstream<_CharT>& __sstr) { + // TODO FMT Write an issue + // [tab:time.format.spec] + // %C The year divided by 100 using floored division. If the result is a + // single decimal digit, it is prefixed with 0. + + bool __negative = __year < 0; + int __century = (__year - (99 * __negative)) / 100; // floored division + __sstr << std::format(_LIBCPP_STATICALLY_WIDEN(_CharT, "{:02}"), __century); +} + +template +_LIBCPP_HIDE_FROM_ABI void __format_chrono_using_chrono_specs( + const _Tp& __value, basic_stringstream<_CharT>& __sstr, basic_string_view<_CharT> __chrono_specs) { + tm __t = std::__convert_to_tm(__value); + const auto& __facet = std::use_facet>(__sstr.getloc()); + for (auto __it = __chrono_specs.begin(); __it != __chrono_specs.end(); ++__it) { + if (*__it == _CharT('%')) { + auto __s = __it; + ++__it; + // We only handle the types that can't be directly handled by time_put. + // (as an optimization n, t, and % are also handled directly.) + switch (*__it) { + case _CharT('n'): + __sstr << _CharT('\n'); + break; + case _CharT('t'): + __sstr << _CharT('\t'); + break; + case _CharT('%'): + __sstr << *__it; + break; + + case _CharT('C'): { + // strftime's output is only defined in the range [00, 99]. + int __year = __t.tm_year + 1900; + if (__year < 1000 || __year > 9999) + __formatter::__format_century(__year, __sstr); + else + __facet.put({__sstr}, __sstr, _CharT(' '), std::addressof(__t), __s, __it + 1); + } break; + + case _CharT('j'): + if constexpr (chrono::__is_duration<_Tp>::value) + // Converting a duration where the period has a small ratio to days + // may fail to compile. This due to loss of precision in the + // conversion. In order to avoid that issue convert to seconds as + // an intemediate step. + __sstr << chrono::duration_cast(chrono::duration_cast(__value)).count(); + else + __facet.put({__sstr}, __sstr, _CharT(' '), std::addressof(__t), __s, __it + 1); + break; + + case _CharT('q'): + if constexpr (chrono::__is_duration<_Tp>::value) { + __sstr << chrono::__units_suffix<_CharT, typename _Tp::period>(); + break; + } + __builtin_unreachable(); + + case _CharT('Q'): + // TODO FMT Determine the proper ideas + // - Should it honour the precision? + // - Shoult it honour the locale setting for the separators? + // The wording for Q doesn't use the word locale and the effect of + // precision is unspecified. + // + // MSVC STL ignores precision but uses separator + // FMT honours precision and has a bug for separator + // https://godbolt.org/z/78b7sMxns + if constexpr (chrono::__is_duration<_Tp>::value) { + __sstr << std::format(_LIBCPP_STATICALLY_WIDEN(_CharT, "{}"), __value.count()); + break; + } + __builtin_unreachable(); + + case _CharT('S'): + case _CharT('T'): + __facet.put({__sstr}, __sstr, _CharT(' '), std::addressof(__t), __s, __it + 1); + if constexpr (__use_fraction<_Tp>()) + __formatter::__format_sub_seconds(__value, __sstr); + break; + + // Unlike time_put and strftime the formatting library requires %Y + // + // [tab:time.format.spec] + // The year as a decimal number. If the result is less than four digits + // it is left-padded with 0 to four digits. + // + // This means years in the range (-1000, 1000) need manual formatting. + // It's unclear whether %EY needs the same treatment. For example the + // Japanese EY contains the era name and year. This is zero-padded to 2 + // digits in time_put (note that older glibc versions didn't do + // padding.) However most eras won't reach 100 years, let alone 1000. + // So padding to 4 digits seems unwanted for Japanese. + // + // The same applies to %Ex since that too depends on the era. + // + // %x the locale's date representation is currently doesn't handle the + // zero-padding too. + // + // The 4 digits can be implemented better at a later time. On POSIX + // systems the required information can be extracted by nl_langinfo + // https://man7.org/linux/man-pages/man3/nl_langinfo.3.html + // + // Note since year < -1000 is expected to be rare it uses the more + // expensive year routine. + // + // TODO FMT evaluate the comment above. + +# if defined(__GLIBC__) || defined(_AIX) + case _CharT('y'): + // Glibc fails for negative values, AIX for positive values too. + __sstr << std::format(_LIBCPP_STATICALLY_WIDEN(_CharT, "{:02}"), (std::abs(__t.tm_year + 1900)) % 100); + break; +# endif // defined(__GLIBC__) || defined(_AIX) + + case _CharT('Y'): { + int __year = __t.tm_year + 1900; + if (__year < 1000) + __formatter::__format_year(__year, __sstr); + else + __facet.put({__sstr}, __sstr, _CharT(' '), std::addressof(__t), __s, __it + 1); + } break; + + case _CharT('F'): { + int __year = __t.tm_year + 1900; + if (__year < 1000) { + __formatter::__format_year(__year, __sstr); + __sstr << std::format(_LIBCPP_STATICALLY_WIDEN(_CharT, "-{:02}-{:02}"), __t.tm_mon + 1, __t.tm_mday); + } else + __facet.put({__sstr}, __sstr, _CharT(' '), std::addressof(__t), __s, __it + 1); + } break; + + case _CharT('O'): + if constexpr (__use_fraction<_Tp>()) { + // Handle OS using the normal representation for the non-fractional + // part. There seems to be no locale information regarding how the + // fractional part should be formatted. + if (*(__it + 1) == 'S') { + ++__it; + __facet.put({__sstr}, __sstr, _CharT(' '), std::addressof(__t), __s, __it + 1); + __formatter::__format_sub_seconds(__value, __sstr); + break; + } + } + [[fallthrough]]; + case _CharT('E'): + ++__it; + [[fallthrough]]; + default: + __facet.put({__sstr}, __sstr, _CharT(' '), std::addressof(__t), __s, __it + 1); + break; + } + } else { + __sstr << *__it; + } + } +} + +template +_LIBCPP_HIDE_FROM_ABI constexpr bool __weekday_ok(const _Tp& __value) { + if constexpr (same_as<_Tp, chrono::day>) + return true; + else if constexpr (same_as<_Tp, chrono::month>) + return __value.ok(); + else if constexpr (same_as<_Tp, chrono::year>) + return true; + else if constexpr (same_as<_Tp, chrono::weekday>) + return true; + else if constexpr (same_as<_Tp, chrono::weekday_indexed>) + return true; + else if constexpr (same_as<_Tp, chrono::weekday_last>) + return true; + else if constexpr (same_as<_Tp, chrono::month_day>) + return true; + else if constexpr (same_as<_Tp, chrono::month_day_last>) + return true; + else if constexpr (same_as<_Tp, chrono::month_weekday>) + return true; + else if constexpr (same_as<_Tp, chrono::month_weekday_last>) + return true; + else if constexpr (same_as<_Tp, chrono::year_month>) + return true; + else if constexpr (same_as<_Tp, chrono::year_month_day>) + return __value.ok(); + else if constexpr (same_as<_Tp, chrono::year_month_day_last>) + return __value.ok(); + else if constexpr (same_as<_Tp, chrono::year_month_weekday>) + return __value.weekday().ok(); + else if constexpr (same_as<_Tp, chrono::year_month_weekday_last>) + return __value.weekday().ok(); + else + static_assert(sizeof(_Tp) == 0, "Add the missing type specialization"); +} + +template +_LIBCPP_HIDE_FROM_ABI constexpr bool __weekday_name_ok(const _Tp& __value) { + if constexpr (same_as<_Tp, chrono::day>) + return true; + else if constexpr (same_as<_Tp, chrono::month>) + return __value.ok(); + else if constexpr (same_as<_Tp, chrono::year>) + return true; + else if constexpr (same_as<_Tp, chrono::weekday>) + return __value.ok(); + else if constexpr (same_as<_Tp, chrono::weekday_indexed>) + return __value.weekday().ok(); + else if constexpr (same_as<_Tp, chrono::weekday_last>) + return __value.weekday().ok(); + else if constexpr (same_as<_Tp, chrono::month_day>) + return true; + else if constexpr (same_as<_Tp, chrono::month_day_last>) + return true; + else if constexpr (same_as<_Tp, chrono::month_weekday>) + return __value.weekday_indexed().ok(); + else if constexpr (same_as<_Tp, chrono::month_weekday_last>) + return __value.weekday_indexed().ok(); + else if constexpr (same_as<_Tp, chrono::year_month>) + return true; + else if constexpr (same_as<_Tp, chrono::year_month_day>) + return __value.ok(); + else if constexpr (same_as<_Tp, chrono::year_month_day_last>) + return __value.ok(); + else if constexpr (same_as<_Tp, chrono::year_month_weekday>) + return __value.weekday().ok(); + else if constexpr (same_as<_Tp, chrono::year_month_weekday_last>) + return __value.weekday().ok(); + else + static_assert(sizeof(_Tp) == 0, "Add the missing type specialization"); +} + +template +_LIBCPP_HIDE_FROM_ABI constexpr bool __date_ok(const _Tp& __value) { + if constexpr (same_as<_Tp, chrono::day>) + return true; + else if constexpr (same_as<_Tp, chrono::month>) + return __value.ok(); + else if constexpr (same_as<_Tp, chrono::year>) + return true; + else if constexpr (same_as<_Tp, chrono::weekday>) + return true; + else if constexpr (same_as<_Tp, chrono::weekday_indexed>) + return true; + else if constexpr (same_as<_Tp, chrono::weekday_last>) + return true; + else if constexpr (same_as<_Tp, chrono::month_day>) + return true; + else if constexpr (same_as<_Tp, chrono::month_day_last>) + return true; + else if constexpr (same_as<_Tp, chrono::month_weekday>) + return true; + else if constexpr (same_as<_Tp, chrono::month_weekday_last>) + return true; + else if constexpr (same_as<_Tp, chrono::year_month>) + return true; + else if constexpr (same_as<_Tp, chrono::year_month_day>) + return __value.ok(); + else if constexpr (same_as<_Tp, chrono::year_month_day_last>) + return __value.ok(); + else if constexpr (same_as<_Tp, chrono::year_month_weekday>) + return __value.ok(); + else if constexpr (same_as<_Tp, chrono::year_month_weekday_last>) + return __value.ok(); + else + static_assert(sizeof(_Tp) == 0, "Add the missing type specialization"); +} + +template +_LIBCPP_HIDE_FROM_ABI constexpr bool __month_name_ok(const _Tp& __value) { + if constexpr (same_as<_Tp, chrono::day>) + return true; + else if constexpr (same_as<_Tp, chrono::month>) + return __value.ok(); + else if constexpr (same_as<_Tp, chrono::year>) + return true; + else if constexpr (same_as<_Tp, chrono::weekday>) + return true; + else if constexpr (same_as<_Tp, chrono::weekday_indexed>) + return true; + else if constexpr (same_as<_Tp, chrono::weekday_last>) + return true; + else if constexpr (same_as<_Tp, chrono::month_day>) + return __value.month().ok(); + else if constexpr (same_as<_Tp, chrono::month_day_last>) + return __value.month().ok(); + else if constexpr (same_as<_Tp, chrono::month_weekday>) + return __value.month().ok(); + else if constexpr (same_as<_Tp, chrono::month_weekday_last>) + return __value.month().ok(); + else if constexpr (same_as<_Tp, chrono::year_month>) + return __value.month().ok(); + else if constexpr (same_as<_Tp, chrono::year_month_day>) + return __value.month().ok(); + else if constexpr (same_as<_Tp, chrono::year_month_day_last>) + return __value.month().ok(); + else if constexpr (same_as<_Tp, chrono::year_month_weekday>) + return __value.month().ok(); + else if constexpr (same_as<_Tp, chrono::year_month_weekday_last>) + return __value.month().ok(); + else + static_assert(sizeof(_Tp) == 0, "Add the missing type specialization"); +} + +template +_LIBCPP_HIDE_FROM_ABI auto +__format_chrono(const _Tp& __value, + auto& __ctx, + __format_spec::__parsed_specifications<_CharT> __specs, + basic_string_view<_CharT> __chrono_specs) -> decltype(__ctx.out()) { + basic_stringstream<_CharT> __sstr; + // [time.format]/2 + // 2.1 - the "C" locale if the L option is not present in chrono-format-spec, otherwise + // 2.2 - the locale passed to the formatting function if any, otherwise + // 2.3 - the global locale. + // Note that the __ctx's locale() call does 2.2 and 2.3. + if (__specs.__chrono_.__locale_specific_form_) + __sstr.imbue(__ctx.locale()); + else + __sstr.imbue(locale::classic()); + + if (__chrono_specs.empty()) + __sstr << __value; + else { + if constexpr (chrono::__is_duration<_Tp>::value) { + if (__value < __value.zero()) + __sstr << _CharT('-'); + __formatter::__format_chrono_using_chrono_specs(chrono::abs(__value), __sstr, __chrono_specs); + // TODO FMT When keeping the precision it will truncate the string. + // Note that the behaviour what the precision does isn't specified. + __specs.__precision_ = -1; + } else { + // Test __weekday_name_ before __weekday_ to give a better error. + if (__specs.__chrono_.__weekday_name_ && !__formatter::__weekday_name_ok(__value)) + std::__throw_format_error("formatting a weekday name needs a valid weekday"); + + if (__specs.__chrono_.__weekday_ && !__formatter::__weekday_ok(__value)) + std::__throw_format_error("formatting a weekday needs a valid weekday"); + + if (__specs.__chrono_.__day_of_year_ && !__formatter::__date_ok(__value)) + std::__throw_format_error("formatting a day of year needs a valid date"); + + if (__specs.__chrono_.__week_of_year_ && !__formatter::__date_ok(__value)) + std::__throw_format_error("formatting a week of year needs a valid date"); + + if (__specs.__chrono_.__month_name_ && !__formatter::__month_name_ok(__value)) + std::__throw_format_error("formatting a month name from an invalid month number"); + + __formatter::__format_chrono_using_chrono_specs(__value, __sstr, __chrono_specs); + } + } + + // TODO FMT Use the stringstream's view after P0408R7 has been implemented. + basic_string<_CharT> __str = __sstr.str(); + return __formatter::__write_string(basic_string_view<_CharT>{__str}, __ctx.out(), __specs); +} + +} // namespace __formatter + +template <__fmt_char_type _CharT> +struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT __formatter_chrono { +public: + _LIBCPP_HIDE_FROM_ABI constexpr auto __parse( + basic_format_parse_context<_CharT>& __parse_ctx, __format_spec::__fields __fields, __format_spec::__flags __flags) + -> decltype(__parse_ctx.begin()) { + return __parser_.__parse(__parse_ctx, __fields, __flags); + } + + template + _LIBCPP_HIDE_FROM_ABI auto format(const _Tp& __value, auto& __ctx) const -> decltype(__ctx.out()) const { + return __formatter::__format_chrono( + __value, __ctx, __parser_.__parser_.__get_parsed_chrono_specifications(__ctx), __parser_.__chrono_specs_); + } + + __format_spec::__parser_chrono<_CharT> __parser_; +}; + +template +struct formatter, _CharT> : public __formatter_chrono<_CharT> { +public: + using _Base = __formatter_chrono<_CharT>; + + _LIBCPP_HIDE_FROM_ABI constexpr auto parse(basic_format_parse_context<_CharT>& __parse_ctx) + -> decltype(__parse_ctx.begin()) { + // [time.format]/1 + // Giving a precision specification in the chrono-format-spec is valid only + // for std::chrono::duration types where the representation type Rep is a + // floating-point type. For all other Rep types, an exception of type + // format_error is thrown if the chrono-format-spec contains a precision + // specification. + // + // Note this doesn't refer to chrono::treat_as_floating_point_v<_Rep>. + if constexpr (std::floating_point<_Rep>) + return _Base::__parse(__parse_ctx, __format_spec::__fields_chrono_fractional, __format_spec::__flags::__duration); + else + return _Base::__parse(__parse_ctx, __format_spec::__fields_chrono, __format_spec::__flags::__duration); + } +}; + +template <__fmt_char_type _CharT> +struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter + : public __formatter_chrono<_CharT> { +public: + using _Base = __formatter_chrono<_CharT>; + + _LIBCPP_HIDE_FROM_ABI constexpr auto parse(basic_format_parse_context<_CharT>& __parse_ctx) + -> decltype(__parse_ctx.begin()) { + return _Base::__parse(__parse_ctx, __format_spec::__fields_chrono, __format_spec::__flags::__day); + } +}; + +template <__fmt_char_type _CharT> +struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter + : public __formatter_chrono<_CharT> { +public: + using _Base = __formatter_chrono<_CharT>; + + _LIBCPP_HIDE_FROM_ABI constexpr auto parse(basic_format_parse_context<_CharT>& __parse_ctx) + -> decltype(__parse_ctx.begin()) { + return _Base::__parse(__parse_ctx, __format_spec::__fields_chrono, __format_spec::__flags::__month); + } +}; + +template <__fmt_char_type _CharT> +struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter + : public __formatter_chrono<_CharT> { +public: + using _Base = __formatter_chrono<_CharT>; + + _LIBCPP_HIDE_FROM_ABI constexpr auto parse(basic_format_parse_context<_CharT>& __parse_ctx) + -> decltype(__parse_ctx.begin()) { + return _Base::__parse(__parse_ctx, __format_spec::__fields_chrono, __format_spec::__flags::__year); + } +}; + +template <__fmt_char_type _CharT> +struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter + : public __formatter_chrono<_CharT> { +public: + using _Base = __formatter_chrono<_CharT>; + + _LIBCPP_HIDE_FROM_ABI constexpr auto parse(basic_format_parse_context<_CharT>& __parse_ctx) + -> decltype(__parse_ctx.begin()) { + return _Base::__parse(__parse_ctx, __format_spec::__fields_chrono, __format_spec::__flags::__weekday); + } +}; + +template <__fmt_char_type _CharT> +struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter + : public __formatter_chrono<_CharT> { +public: + using _Base = __formatter_chrono<_CharT>; + + _LIBCPP_HIDE_FROM_ABI constexpr auto parse(basic_format_parse_context<_CharT>& __parse_ctx) + -> decltype(__parse_ctx.begin()) { + return _Base::__parse(__parse_ctx, __format_spec::__fields_chrono, __format_spec::__flags::__weekday); + } +}; + +template <__fmt_char_type _CharT> +struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter + : public __formatter_chrono<_CharT> { +public: + using _Base = __formatter_chrono<_CharT>; + + _LIBCPP_HIDE_FROM_ABI constexpr auto parse(basic_format_parse_context<_CharT>& __parse_ctx) + -> decltype(__parse_ctx.begin()) { + return _Base::__parse(__parse_ctx, __format_spec::__fields_chrono, __format_spec::__flags::__weekday); + } +}; + +template <__fmt_char_type _CharT> +struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter + : public __formatter_chrono<_CharT> { +public: + using _Base = __formatter_chrono<_CharT>; + + _LIBCPP_HIDE_FROM_ABI constexpr auto parse(basic_format_parse_context<_CharT>& __parse_ctx) + -> decltype(__parse_ctx.begin()) { + return _Base::__parse(__parse_ctx, __format_spec::__fields_chrono, __format_spec::__flags::__month_day); + } +}; + +template <__fmt_char_type _CharT> +struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter + : public __formatter_chrono<_CharT> { +public: + using _Base = __formatter_chrono<_CharT>; + + _LIBCPP_HIDE_FROM_ABI constexpr auto parse(basic_format_parse_context<_CharT>& __parse_ctx) + -> decltype(__parse_ctx.begin()) { + return _Base::__parse(__parse_ctx, __format_spec::__fields_chrono, __format_spec::__flags::__month); + } +}; + +template <__fmt_char_type _CharT> +struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter + : public __formatter_chrono<_CharT> { +public: + using _Base = __formatter_chrono<_CharT>; + + _LIBCPP_HIDE_FROM_ABI constexpr auto parse(basic_format_parse_context<_CharT>& __parse_ctx) + -> decltype(__parse_ctx.begin()) { + return _Base::__parse(__parse_ctx, __format_spec::__fields_chrono, __format_spec::__flags::__month_weekday); + } +}; + +template <__fmt_char_type _CharT> +struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter + : public __formatter_chrono<_CharT> { +public: + using _Base = __formatter_chrono<_CharT>; + + _LIBCPP_HIDE_FROM_ABI constexpr auto parse(basic_format_parse_context<_CharT>& __parse_ctx) + -> decltype(__parse_ctx.begin()) { + return _Base::__parse(__parse_ctx, __format_spec::__fields_chrono, __format_spec::__flags::__month_weekday); + } +}; + +template <__fmt_char_type _CharT> +struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter + : public __formatter_chrono<_CharT> { +public: + using _Base = __formatter_chrono<_CharT>; + + _LIBCPP_HIDE_FROM_ABI constexpr auto parse(basic_format_parse_context<_CharT>& __parse_ctx) + -> decltype(__parse_ctx.begin()) { + return _Base::__parse(__parse_ctx, __format_spec::__fields_chrono, __format_spec::__flags::__year_month); + } +}; + +template <__fmt_char_type _CharT> +struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter + : public __formatter_chrono<_CharT> { +public: + using _Base = __formatter_chrono<_CharT>; + + _LIBCPP_HIDE_FROM_ABI constexpr auto parse(basic_format_parse_context<_CharT>& __parse_ctx) + -> decltype(__parse_ctx.begin()) { + return _Base::__parse(__parse_ctx, __format_spec::__fields_chrono, __format_spec::__flags::__date); + } +}; + +template <__fmt_char_type _CharT> +struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter + : public __formatter_chrono<_CharT> { +public: + using _Base = __formatter_chrono<_CharT>; + + _LIBCPP_HIDE_FROM_ABI constexpr auto parse(basic_format_parse_context<_CharT>& __parse_ctx) + -> decltype(__parse_ctx.begin()) { + return _Base::__parse(__parse_ctx, __format_spec::__fields_chrono, __format_spec::__flags::__date); + } +}; + +template <__fmt_char_type _CharT> +struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter + : public __formatter_chrono<_CharT> { +public: + using _Base = __formatter_chrono<_CharT>; + + _LIBCPP_HIDE_FROM_ABI constexpr auto parse(basic_format_parse_context<_CharT>& __parse_ctx) + -> decltype(__parse_ctx.begin()) { + return _Base::__parse(__parse_ctx, __format_spec::__fields_chrono, __format_spec::__flags::__date); + } +}; + +template <__fmt_char_type _CharT> +struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter + : public __formatter_chrono<_CharT> { +public: + using _Base = __formatter_chrono<_CharT>; + + _LIBCPP_HIDE_FROM_ABI constexpr auto parse(basic_format_parse_context<_CharT>& __parse_ctx) + -> decltype(__parse_ctx.begin()) { + return _Base::__parse(__parse_ctx, __format_spec::__fields_chrono, __format_spec::__flags::__date); + } +}; + +#endif // if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_FORMAT) + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___CHRONO_FORMATTER_H diff --git a/lib/libcxx/include/__chrono/hh_mm_ss.h b/lib/libcxx/include/__chrono/hh_mm_ss.h index 6b3c5c09e6..fd61cbe8f8 100644 --- a/lib/libcxx/include/__chrono/hh_mm_ss.h +++ b/lib/libcxx/include/__chrono/hh_mm_ss.h @@ -57,33 +57,33 @@ public: _LIBCPP_HIDE_FROM_ABI constexpr hh_mm_ss() noexcept : hh_mm_ss{_Duration::zero()} {} _LIBCPP_HIDE_FROM_ABI constexpr explicit hh_mm_ss(_Duration __d) noexcept : - __is_neg(__d < _Duration(0)), - __h(duration_cast (abs(__d))), - __m(duration_cast(abs(__d) - hours())), - __s(duration_cast(abs(__d) - hours() - minutes())), - __f(duration_cast (abs(__d) - hours() - minutes() - seconds())) + __is_neg_(__d < _Duration(0)), + __h_(chrono::duration_cast (chrono::abs(__d))), + __m_(chrono::duration_cast(chrono::abs(__d) - hours())), + __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; } + _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_; } _LIBCPP_HIDE_FROM_ABI constexpr precision to_duration() const noexcept { - auto __dur = __h + __m + __s + __f; - return __is_neg ? -__dur : __dur; + auto __dur = __h_ + __m_ + __s_ + __f_; + return __is_neg_ ? -__dur : __dur; } _LIBCPP_HIDE_FROM_ABI constexpr explicit operator precision() const noexcept { return to_duration(); } private: - bool __is_neg; - chrono::hours __h; - chrono::minutes __m; - chrono::seconds __s; - precision __f; + bool __is_neg_; + chrono::hours __h_; + chrono::minutes __m_; + chrono::seconds __s_; + precision __f_; }; _LIBCPP_HIDE_FROM_ABI constexpr bool is_am(const hours& __h) noexcept { return __h >= hours( 0) && __h < hours(12); } diff --git a/lib/libcxx/include/__chrono/month.h b/lib/libcxx/include/__chrono/month.h index 5aeb5b3971..e929f24884 100644 --- a/lib/libcxx/include/__chrono/month.h +++ b/lib/libcxx/include/__chrono/month.h @@ -12,6 +12,7 @@ #include <__chrono/duration.h> #include <__config> +#include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header @@ -26,18 +27,18 @@ namespace chrono class month { private: - unsigned char __m; + unsigned char __m_; public: _LIBCPP_HIDE_FROM_ABI month() = default; - _LIBCPP_HIDE_FROM_ABI explicit inline constexpr month(unsigned __val) noexcept : __m(static_cast(__val)) {} - _LIBCPP_HIDE_FROM_ABI inline constexpr month& operator++() noexcept { ++__m; return *this; } + _LIBCPP_HIDE_FROM_ABI explicit inline constexpr month(unsigned __val) noexcept : __m_(static_cast(__val)) {} + _LIBCPP_HIDE_FROM_ABI inline constexpr month& operator++() noexcept { ++__m_; return *this; } _LIBCPP_HIDE_FROM_ABI inline constexpr month operator++(int) noexcept { month __tmp = *this; ++(*this); return __tmp; } - _LIBCPP_HIDE_FROM_ABI inline constexpr month& operator--() noexcept { --__m; return *this; } + _LIBCPP_HIDE_FROM_ABI inline constexpr month& operator--() noexcept { --__m_; return *this; } _LIBCPP_HIDE_FROM_ABI inline constexpr month operator--(int) noexcept { month __tmp = *this; --(*this); return __tmp; } _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; } + _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; } }; @@ -45,25 +46,9 @@ _LIBCPP_HIDE_FROM_ABI inline constexpr bool operator==(const month& __lhs, const month& __rhs) noexcept { return static_cast(__lhs) == static_cast(__rhs); } -_LIBCPP_HIDE_FROM_ABI inline constexpr -bool operator!=(const month& __lhs, const month& __rhs) noexcept -{ return !(__lhs == __rhs); } - -_LIBCPP_HIDE_FROM_ABI inline constexpr -bool operator< (const month& __lhs, const month& __rhs) noexcept -{ return static_cast(__lhs) < static_cast(__rhs); } - -_LIBCPP_HIDE_FROM_ABI inline constexpr -bool operator> (const month& __lhs, const month& __rhs) noexcept -{ return __rhs < __lhs; } - -_LIBCPP_HIDE_FROM_ABI inline constexpr -bool operator<=(const month& __lhs, const month& __rhs) noexcept -{ return !(__rhs < __lhs); } - -_LIBCPP_HIDE_FROM_ABI inline constexpr -bool operator>=(const month& __lhs, const month& __rhs) noexcept -{ return !(__lhs < __rhs); } +_LIBCPP_HIDE_FROM_ABI constexpr strong_ordering operator<=>(const month& __lhs, const month& __rhs) noexcept { + return static_cast(__lhs) <=> static_cast(__rhs); +} _LIBCPP_HIDE_FROM_ABI inline constexpr month operator+ (const month& __lhs, const months& __rhs) noexcept diff --git a/lib/libcxx/include/__chrono/month_weekday.h b/lib/libcxx/include/__chrono/month_weekday.h index 2700513970..01cdf76d84 100644 --- a/lib/libcxx/include/__chrono/month_weekday.h +++ b/lib/libcxx/include/__chrono/month_weekday.h @@ -27,14 +27,14 @@ namespace chrono class month_weekday { private: - chrono::month __m; - chrono::weekday_indexed __wdi; + chrono::month __m_; + chrono::weekday_indexed __wdi_; 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(); } + : __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(); } }; _LIBCPP_HIDE_FROM_ABI inline constexpr @@ -63,14 +63,14 @@ month_weekday operator/(const weekday_indexed& __lhs, int __rhs) noexcept class month_weekday_last { - chrono::month __m; - chrono::weekday_last __wdl; + chrono::month __m_; + chrono::weekday_last __wdl_; 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(); } + : __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(); } }; _LIBCPP_HIDE_FROM_ABI inline constexpr diff --git a/lib/libcxx/include/__chrono/monthday.h b/lib/libcxx/include/__chrono/monthday.h index 485f0d4299..c0ee3e4a94 100644 --- a/lib/libcxx/include/__chrono/monthday.h +++ b/lib/libcxx/include/__chrono/monthday.h @@ -14,6 +14,7 @@ #include <__chrono/day.h> #include <__chrono/month.h> #include <__config> +#include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header @@ -28,26 +29,26 @@ namespace chrono class month_day { private: - chrono::month __m; - chrono::day __d; + chrono::month __m_; + chrono::day __d_; public: _LIBCPP_HIDE_FROM_ABI 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; } + : __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; }; _LIBCPP_HIDE_FROM_ABI inline constexpr bool month_day::ok() const noexcept { - if (!__m.ok()) return false; - const unsigned __dval = static_cast(__d); + if (!__m_.ok()) return false; + const unsigned __dval = static_cast(__d_); if (__dval < 1 || __dval > 31) return false; if (__dval <= 29) return true; // Now we've got either 30 or 31 - const unsigned __mval = static_cast(__m); + const unsigned __mval = static_cast(__m_); if (__mval == 2) return false; if (__mval == 4 || __mval == 6 || __mval == 9 || __mval == 11) return __dval == 30; @@ -58,9 +59,11 @@ _LIBCPP_HIDE_FROM_ABI inline constexpr bool operator==(const month_day& __lhs, const month_day& __rhs) noexcept { return __lhs.month() == __rhs.month() && __lhs.day() == __rhs.day(); } -_LIBCPP_HIDE_FROM_ABI inline constexpr -bool operator!=(const month_day& __lhs, const month_day& __rhs) noexcept -{ return !(__lhs == __rhs); } +_LIBCPP_HIDE_FROM_ABI constexpr strong_ordering operator<=>(const month_day& __lhs, const month_day& __rhs) noexcept { + if (auto __c = __lhs.month() <=> __rhs.month(); __c != 0) + return __c; + return __lhs.day() <=> __rhs.day(); +} _LIBCPP_HIDE_FROM_ABI inline constexpr month_day operator/(const month& __lhs, const day& __rhs) noexcept @@ -82,58 +85,24 @@ _LIBCPP_HIDE_FROM_ABI constexpr month_day operator/(const day& __lhs, int __rhs) noexcept { return month(__rhs) / __lhs; } - -_LIBCPP_HIDE_FROM_ABI inline constexpr -bool operator< (const month_day& __lhs, const month_day& __rhs) noexcept -{ return __lhs.month() != __rhs.month() ? __lhs.month() < __rhs.month() : __lhs.day() < __rhs.day(); } - -_LIBCPP_HIDE_FROM_ABI inline constexpr -bool operator> (const month_day& __lhs, const month_day& __rhs) noexcept -{ return __rhs < __lhs; } - -_LIBCPP_HIDE_FROM_ABI inline constexpr -bool operator<=(const month_day& __lhs, const month_day& __rhs) noexcept -{ return !(__rhs < __lhs);} - -_LIBCPP_HIDE_FROM_ABI inline constexpr -bool operator>=(const month_day& __lhs, const month_day& __rhs) noexcept -{ return !(__lhs < __rhs); } - - - class month_day_last { private: - chrono::month __m; + chrono::month __m_; 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(); } + : __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(); } }; _LIBCPP_HIDE_FROM_ABI inline constexpr bool operator==(const month_day_last& __lhs, const month_day_last& __rhs) noexcept { return __lhs.month() == __rhs.month(); } -_LIBCPP_HIDE_FROM_ABI inline constexpr -bool operator!=(const month_day_last& __lhs, const month_day_last& __rhs) noexcept -{ return !(__lhs == __rhs); } - -_LIBCPP_HIDE_FROM_ABI inline constexpr -bool operator< (const month_day_last& __lhs, const month_day_last& __rhs) noexcept -{ return __lhs.month() < __rhs.month(); } - -_LIBCPP_HIDE_FROM_ABI inline constexpr -bool operator> (const month_day_last& __lhs, const month_day_last& __rhs) noexcept -{ return __rhs < __lhs; } - -_LIBCPP_HIDE_FROM_ABI inline constexpr -bool operator<=(const month_day_last& __lhs, const month_day_last& __rhs) noexcept -{ return !(__rhs < __lhs);} - -_LIBCPP_HIDE_FROM_ABI inline constexpr -bool operator>=(const month_day_last& __lhs, const month_day_last& __rhs) noexcept -{ return !(__lhs < __rhs); } +_LIBCPP_HIDE_FROM_ABI constexpr strong_ordering +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 diff --git a/lib/libcxx/include/__chrono/ostream.h b/lib/libcxx/include/__chrono/ostream.h new file mode 100644 index 0000000000..30a04bd265 --- /dev/null +++ b/lib/libcxx/include/__chrono/ostream.h @@ -0,0 +1,238 @@ +// -*- 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___CHRONO_OSTREAM_H +#define _LIBCPP___CHRONO_OSTREAM_H + +#include <__chrono/day.h> +#include <__chrono/duration.h> +#include <__chrono/month.h> +#include <__chrono/month_weekday.h> +#include <__chrono/monthday.h> +#include <__chrono/statically_widen.h> +#include <__chrono/weekday.h> +#include <__chrono/year.h> +#include <__chrono/year_month.h> +#include <__chrono/year_month_day.h> +#include <__chrono/year_month_weekday.h> +#include <__concepts/same_as.h> +#include <__config> +#include <__format/format_functions.h> +#include +#include + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_FORMAT) + +namespace chrono { + +// Depending on the type the return is a const _CharT* or a basic_string<_CharT> +template +_LIBCPP_HIDE_FROM_ABI auto __units_suffix() { + // TODO FMT LWG issue the suffixes are always char and not STATICALLY-WIDEN'ed. + if constexpr (same_as) + return _LIBCPP_STATICALLY_WIDEN(_CharT, "as"); + else if constexpr (same_as) + return _LIBCPP_STATICALLY_WIDEN(_CharT, "fs"); + else if constexpr (same_as) + return _LIBCPP_STATICALLY_WIDEN(_CharT, "ps"); + else if constexpr (same_as) + return _LIBCPP_STATICALLY_WIDEN(_CharT, "ns"); + else if constexpr (same_as) +# ifndef _LIBCPP_HAS_NO_UNICODE + return _LIBCPP_STATICALLY_WIDEN(_CharT, "\u00b5s"); +# else + return _LIBCPP_STATICALLY_WIDEN(_CharT, "us"); +# endif + else if constexpr (same_as) + return _LIBCPP_STATICALLY_WIDEN(_CharT, "ms"); + else if constexpr (same_as) + return _LIBCPP_STATICALLY_WIDEN(_CharT, "cs"); + else if constexpr (same_as) + return _LIBCPP_STATICALLY_WIDEN(_CharT, "ds"); + else if constexpr (same_as>) + return _LIBCPP_STATICALLY_WIDEN(_CharT, "s"); + else if constexpr (same_as) + return _LIBCPP_STATICALLY_WIDEN(_CharT, "das"); + else if constexpr (same_as) + return _LIBCPP_STATICALLY_WIDEN(_CharT, "hs"); + else if constexpr (same_as) + return _LIBCPP_STATICALLY_WIDEN(_CharT, "ks"); + else if constexpr (same_as) + return _LIBCPP_STATICALLY_WIDEN(_CharT, "Ms"); + else if constexpr (same_as) + return _LIBCPP_STATICALLY_WIDEN(_CharT, "Gs"); + else if constexpr (same_as) + return _LIBCPP_STATICALLY_WIDEN(_CharT, "Ts"); + else if constexpr (same_as) + return _LIBCPP_STATICALLY_WIDEN(_CharT, "Ps"); + else if constexpr (same_as) + return _LIBCPP_STATICALLY_WIDEN(_CharT, "Es"); + else if constexpr (same_as>) + return _LIBCPP_STATICALLY_WIDEN(_CharT, "min"); + else if constexpr (same_as>) + return _LIBCPP_STATICALLY_WIDEN(_CharT, "h"); + else if constexpr (same_as>) + return _LIBCPP_STATICALLY_WIDEN(_CharT, "d"); + else if constexpr (_Period::den == 1) + return std::format(_LIBCPP_STATICALLY_WIDEN(_CharT, "[{}]s"), _Period::num); + else + return std::format(_LIBCPP_STATICALLY_WIDEN(_CharT, "[{}/{}]s"), _Period::num, _Period::den); +} + +template +_LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT basic_ostream<_CharT, _Traits>& +operator<<(basic_ostream<_CharT, _Traits>& __os, const duration<_Rep, _Period>& __d) { + basic_ostringstream<_CharT, _Traits> __s; + __s.flags(__os.flags()); + __s.imbue(__os.getloc()); + __s.precision(__os.precision()); + __s << __d.count() << chrono::__units_suffix<_CharT, _Period>(); + return __os << __s.str(); +} + +template +_LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT basic_ostream<_CharT, _Traits>& +operator<<(basic_ostream<_CharT, _Traits>& __os, const day& __d) { + return __os + << (__d.ok() + ? std::format(_LIBCPP_STATICALLY_WIDEN(_CharT, "{:%d}"), __d) + // Note this error differs from the wording of the Standard. The + // Standard wording doesn't work well on AIX or Windows. There + // the formatted day seems to be either modulo 100 or completely + // omitted. Judging by the wording this is valid. + // TODO FMT Write a paper of file an LWG issue. + : std::format(_LIBCPP_STATICALLY_WIDEN(_CharT, "{:02} is not a valid day"), static_cast(__d))); +} + +template +_LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT basic_ostream<_CharT, _Traits>& +operator<<(basic_ostream<_CharT, _Traits>& __os, const month& __m) { + return __os << (__m.ok() ? std::format(__os.getloc(), _LIBCPP_STATICALLY_WIDEN(_CharT, "{:L%b}"), __m) + : std::format(__os.getloc(), + _LIBCPP_STATICALLY_WIDEN(_CharT, "{} is not a valid month"), + static_cast(__m))); // TODO FMT Standard mandated locale isn't used. +} + +template +_LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT basic_ostream<_CharT, _Traits>& +operator<<(basic_ostream<_CharT, _Traits>& __os, const year& __y) { + return __os << (__y.ok() ? std::format(_LIBCPP_STATICALLY_WIDEN(_CharT, "{:%Y}"), __y) + : std::format(_LIBCPP_STATICALLY_WIDEN(_CharT, "{:%Y} is not a valid year"), __y)); +} + +template +_LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT basic_ostream<_CharT, _Traits>& +operator<<(basic_ostream<_CharT, _Traits>& __os, const weekday& __wd) { + return __os << (__wd.ok() ? std::format(__os.getloc(), _LIBCPP_STATICALLY_WIDEN(_CharT, "{:L%a}"), __wd) + : std::format(__os.getloc(), // TODO FMT Standard mandated locale isn't used. + _LIBCPP_STATICALLY_WIDEN(_CharT, "{} is not a valid weekday"), + static_cast(__wd.c_encoding()))); +} + +template +_LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT basic_ostream<_CharT, _Traits>& +operator<<(basic_ostream<_CharT, _Traits>& __os, const weekday_indexed& __wdi) { + auto __i = __wdi.index(); + return __os << (__i >= 1 && __i <= 5 + ? std::format(__os.getloc(), _LIBCPP_STATICALLY_WIDEN(_CharT, "{:L}[{}]"), __wdi.weekday(), __i) + : std::format(__os.getloc(), + _LIBCPP_STATICALLY_WIDEN(_CharT, "{:L}[{} is not a valid index]"), + __wdi.weekday(), + __i)); +} + +template +_LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT basic_ostream<_CharT, _Traits>& +operator<<(basic_ostream<_CharT, _Traits>& __os, const weekday_last& __wdl) { + return __os << std::format(__os.getloc(), _LIBCPP_STATICALLY_WIDEN(_CharT, "{:L}[last]"), __wdl.weekday()); +} + +template +_LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT basic_ostream<_CharT, _Traits>& +operator<<(basic_ostream<_CharT, _Traits>& __os, const month_day& __md) { + // TODO FMT The Standard allows 30th of February to be printed. + // It would be nice to show an error message instead. + return __os << std::format(__os.getloc(), _LIBCPP_STATICALLY_WIDEN(_CharT, "{:L}/{}"), __md.month(), __md.day()); +} + +template +_LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT basic_ostream<_CharT, _Traits>& +operator<<(basic_ostream<_CharT, _Traits>& __os, const month_day_last& __mdl) { + return __os << std::format(__os.getloc(), _LIBCPP_STATICALLY_WIDEN(_CharT, "{:L}/last"), __mdl.month()); +} + +template +_LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT basic_ostream<_CharT, _Traits>& +operator<<(basic_ostream<_CharT, _Traits>& __os, const month_weekday& __mwd) { + return __os << std::format( + __os.getloc(), _LIBCPP_STATICALLY_WIDEN(_CharT, "{:L}/{:L}"), __mwd.month(), __mwd.weekday_indexed()); +} + +template +_LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT basic_ostream<_CharT, _Traits>& +operator<<(basic_ostream<_CharT, _Traits>& __os, const month_weekday_last& __mwdl) { + return __os << std::format( + __os.getloc(), _LIBCPP_STATICALLY_WIDEN(_CharT, "{:L}/{:L}"), __mwdl.month(), __mwdl.weekday_last()); +} + +template +_LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT basic_ostream<_CharT, _Traits>& +operator<<(basic_ostream<_CharT, _Traits>& __os, const year_month& __ym) { + return __os << std::format(__os.getloc(), _LIBCPP_STATICALLY_WIDEN(_CharT, "{}/{:L}"), __ym.year(), __ym.month()); +} + +template +_LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT basic_ostream<_CharT, _Traits>& +operator<<(basic_ostream<_CharT, _Traits>& __os, const year_month_day& __ymd) { + return __os << (__ymd.ok() ? std::format(_LIBCPP_STATICALLY_WIDEN(_CharT, "{:%F}"), __ymd) + : std::format(_LIBCPP_STATICALLY_WIDEN(_CharT, "{:%F} is not a valid date"), __ymd)); +} + +template +_LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT basic_ostream<_CharT, _Traits>& +operator<<(basic_ostream<_CharT, _Traits>& __os, const year_month_day_last& __ymdl) { + return __os << std::format( + __os.getloc(), _LIBCPP_STATICALLY_WIDEN(_CharT, "{}/{:L}"), __ymdl.year(), __ymdl.month_day_last()); +} + +template +_LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT basic_ostream<_CharT, _Traits>& +operator<<(basic_ostream<_CharT, _Traits>& __os, const year_month_weekday& __ymwd) { + return __os << std::format( + __os.getloc(), + _LIBCPP_STATICALLY_WIDEN(_CharT, "{}/{:L}/{:L}"), + __ymwd.year(), + __ymwd.month(), + __ymwd.weekday_indexed()); +} + +template +_LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT basic_ostream<_CharT, _Traits>& +operator<<(basic_ostream<_CharT, _Traits>& __os, const year_month_weekday_last& __ymwdl) { + return __os << std::format( + __os.getloc(), + _LIBCPP_STATICALLY_WIDEN(_CharT, "{}/{:L}/{:L}"), + __ymwdl.year(), + __ymwdl.month(), + __ymwdl.weekday_last()); +} + +} // namespace chrono + +#endif //if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_FORMAT) + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___CHRONO_OSTREAM_H diff --git a/lib/libcxx/include/__chrono/parser_std_format_spec.h b/lib/libcxx/include/__chrono/parser_std_format_spec.h new file mode 100644 index 0000000000..dbcfe6da60 --- /dev/null +++ b/lib/libcxx/include/__chrono/parser_std_format_spec.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___CHRONO_PARSER_STD_FORMAT_SPEC_H +#define _LIBCPP___CHRONO_PARSER_STD_FORMAT_SPEC_H + +#include <__config> +#include <__format/concepts.h> +#include <__format/format_error.h> +#include <__format/format_parse_context.h> +#include <__format/formatter_string.h> +#include <__format/parser_std_format_spec.h> +#include + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_FORMAT) + +namespace __format_spec { + +// By not placing this constant in the formatter class it's not duplicated for char and wchar_t +inline constexpr __fields __fields_chrono_fractional{ + .__precision_ = true, .__locale_specific_form_ = true, .__type_ = false}; +inline constexpr __fields __fields_chrono{.__locale_specific_form_ = true, .__type_ = false}; + +/// Flags available or required in a chrono type. +/// +/// The caller of the chrono formatter lists the types it has available and the +/// validation tests whether the requested type spec (e.g. %M) is available in +/// the formatter. +/// When the type in the chrono-format-spec isn't present in the data a +/// \ref format_error is thrown. +enum class __flags { + __second = 0x1, + __minute = 0x2, + __hour = 0x4, + __time = __hour | __minute | __second, + + __day = 0x8, + __month = 0x10, + __year = 0x20, + + __weekday = 0x40, + + __month_day = __day | __month, + __month_weekday = __weekday | __month, + __year_month = __month | __year, + __date = __day | __month | __year | __weekday, + + __date_time = __date | __time, + + __duration = 0x80 | __time, + + __time_zone = 0x100, + + __clock = __date_time | __time_zone +}; + +_LIBCPP_HIDE_FROM_ABI constexpr __flags operator&(__flags __lhs, __flags __rhs) { + return static_cast<__flags>(static_cast(__lhs) & static_cast(__rhs)); +} + +_LIBCPP_HIDE_FROM_ABI constexpr void __validate_second(__flags __flags) { + if ((__flags & __flags::__second) != __flags::__second) + std::__throw_format_error("The supplied date time doesn't contain a second"); +} + +_LIBCPP_HIDE_FROM_ABI constexpr void __validate_minute(__flags __flags) { + if ((__flags & __flags::__minute) != __flags::__minute) + std::__throw_format_error("The supplied date time doesn't contain a minute"); +} + +_LIBCPP_HIDE_FROM_ABI constexpr void __validate_hour(__flags __flags) { + if ((__flags & __flags::__hour) != __flags::__hour) + std::__throw_format_error("The supplied date time doesn't contain an hour"); +} + +_LIBCPP_HIDE_FROM_ABI constexpr void __validate_time(__flags __flags) { + if ((__flags & __flags::__time) != __flags::__time) + std::__throw_format_error("The supplied date time doesn't contain a time"); +} + +_LIBCPP_HIDE_FROM_ABI constexpr void __validate_day(__flags __flags) { + if ((__flags & __flags::__day) != __flags::__day) + std::__throw_format_error("The supplied date time doesn't contain a day"); +} + +_LIBCPP_HIDE_FROM_ABI constexpr void __validate_month(__flags __flags) { + if ((__flags & __flags::__month) != __flags::__month) + std::__throw_format_error("The supplied date time doesn't contain a month"); +} + +_LIBCPP_HIDE_FROM_ABI constexpr void __validate_year(__flags __flags) { + if ((__flags & __flags::__year) != __flags::__year) + std::__throw_format_error("The supplied date time doesn't contain a year"); +} + +_LIBCPP_HIDE_FROM_ABI constexpr void __validate_date(__flags __flags) { + if ((__flags & __flags::__date) != __flags::__date) + std::__throw_format_error("The supplied date time doesn't contain a date"); +} + +_LIBCPP_HIDE_FROM_ABI constexpr void __validate_date_or_duration(__flags __flags) { + if (((__flags & __flags::__date) != __flags::__date) && ((__flags & __flags::__duration) != __flags::__duration)) + std::__throw_format_error("The supplied date time doesn't contain a date or duration"); +} + +_LIBCPP_HIDE_FROM_ABI constexpr void __validate_date_time(__flags __flags) { + if ((__flags & __flags::__date_time) != __flags::__date_time) + std::__throw_format_error("The supplied date time doesn't contain a date and time"); +} + +_LIBCPP_HIDE_FROM_ABI constexpr void __validate_weekday(__flags __flags) { + if ((__flags & __flags::__weekday) != __flags::__weekday) + std::__throw_format_error("The supplied date time doesn't contain a weekday"); +} + +_LIBCPP_HIDE_FROM_ABI constexpr void __validate_duration(__flags __flags) { + if ((__flags & __flags::__duration) != __flags::__duration) + std::__throw_format_error("The supplied date time doesn't contain a duration"); +} + +_LIBCPP_HIDE_FROM_ABI constexpr void __validate_time_zone(__flags __flags) { + if ((__flags & __flags::__time_zone) != __flags::__time_zone) + std::__throw_format_error("The supplied date time doesn't contain a time zone"); +} + +template +class _LIBCPP_TEMPLATE_VIS __parser_chrono { +public: + _LIBCPP_HIDE_FROM_ABI constexpr auto + __parse(basic_format_parse_context<_CharT>& __parse_ctx, __fields __fields, __flags __flags) + -> decltype(__parse_ctx.begin()) { + const _CharT* __begin = __parser_.__parse(__parse_ctx, __fields); + const _CharT* __end = __parse_ctx.end(); + if (__begin == __end) + return __begin; + + const _CharT* __last = __parse_chrono_specs(__begin, __end, __flags); + __chrono_specs_ = basic_string_view<_CharT>{__begin, __last}; + + return __last; + } + + __parser<_CharT> __parser_; + basic_string_view<_CharT> __chrono_specs_; + +private: + _LIBCPP_HIDE_FROM_ABI constexpr const _CharT* + __parse_chrono_specs(const _CharT* __begin, const _CharT* __end, __flags __flags) { + _LIBCPP_ASSERT(__begin != __end, + "When called with an empty input the function will cause " + "undefined behavior by evaluating data not in the input"); + + if (*__begin != _CharT('%') && *__begin != _CharT('}')) + std::__throw_format_error("Expected '%' or '}' in the chrono format-string"); + + do { + switch (*__begin) { + case _CharT('{'): + std::__throw_format_error("The chrono-specs contains a '{'"); + + case _CharT('}'): + return __begin; + + case _CharT('%'): + __parse_conversion_spec(__begin, __end, __flags); + [[fallthrough]]; + + default: + // All other literals + ++__begin; + } + + } while (__begin != __end && *__begin != _CharT('}')); + + return __begin; + } + + /// \pre *__begin == '%' + /// \post __begin points at the end parsed conversion-spec + _LIBCPP_HIDE_FROM_ABI constexpr void + __parse_conversion_spec(const _CharT*& __begin, const _CharT* __end, __flags __flags) { + ++__begin; + if (__begin == __end) + std::__throw_format_error("End of input while parsing the modifier chrono conversion-spec"); + + switch (*__begin) { + case _CharT('n'): + case _CharT('t'): + case _CharT('%'): + break; + + case _CharT('S'): + __format_spec::__validate_second(__flags); + break; + + case _CharT('M'): + __format_spec::__validate_minute(__flags); + break; + + case _CharT('p'): // TODO FMT does the formater require an hour or a time? + case _CharT('H'): + case _CharT('I'): + __validate_hour(__flags); + break; + + case _CharT('r'): + case _CharT('R'): + case _CharT('T'): + case _CharT('X'): + __format_spec::__validate_time(__flags); + break; + + case _CharT('d'): + case _CharT('e'): + __format_spec::__validate_day(__flags); + break; + + case _CharT('b'): + case _CharT('h'): + case _CharT('B'): + __parser_.__month_name_ = true; + [[fallthrough]]; + case _CharT('m'): + __format_spec::__validate_month(__flags); + break; + + case _CharT('y'): + case _CharT('C'): + case _CharT('Y'): + __format_spec::__validate_year(__flags); + break; + + case _CharT('j'): + __parser_.__day_of_year_ = true; + __format_spec::__validate_date_or_duration(__flags); + break; + + case _CharT('g'): + case _CharT('G'): + case _CharT('U'): + case _CharT('V'): + case _CharT('W'): + __parser_.__week_of_year_ = true; + [[fallthrough]]; + case _CharT('x'): + case _CharT('D'): + case _CharT('F'): + __format_spec::__validate_date(__flags); + break; + + case _CharT('c'): + __format_spec::__validate_date_time(__flags); + break; + + case _CharT('a'): + case _CharT('A'): + __parser_.__weekday_name_ = true; + [[fallthrough]]; + case _CharT('u'): + case _CharT('w'): + __parser_.__weekday_ = true; + __validate_weekday(__flags); + __format_spec::__validate_weekday(__flags); + break; + + case _CharT('q'): + case _CharT('Q'): + __format_spec::__validate_duration(__flags); + break; + + case _CharT('E'): + __parse_modifier_E(__begin, __end, __flags); + break; + + case _CharT('O'): + __parse_modifier_O(__begin, __end, __flags); + break; + + case _CharT('z'): + case _CharT('Z'): + // Currently there's no time zone information. However some clocks have a + // hard-coded "time zone", for these clocks the information can be used. + // TODO FMT implement time zones. + __format_spec::__validate_time_zone(__flags); + break; + + default: // unknown type; + std::__throw_format_error("The date time type specifier is invalid"); + } + } + + /// \pre *__begin == 'E' + /// \post __begin is incremented by one. + _LIBCPP_HIDE_FROM_ABI constexpr void + __parse_modifier_E(const _CharT*& __begin, const _CharT* __end, __flags __flags) { + ++__begin; + if (__begin == __end) + std::__throw_format_error("End of input while parsing the modifier E"); + + switch (*__begin) { + case _CharT('X'): + __format_spec::__validate_time(__flags); + break; + + case _CharT('y'): + case _CharT('C'): + case _CharT('Y'): + __format_spec::__validate_year(__flags); + break; + + case _CharT('x'): + __format_spec::__validate_date(__flags); + break; + + case _CharT('c'): + __format_spec::__validate_date_time(__flags); + break; + + case _CharT('z'): + // Currently there's no time zone information. However some clocks have a + // hard-coded "time zone", for these clocks the information can be used. + // TODO FMT implement time zones. + __format_spec::__validate_time_zone(__flags); + break; + + default: + std::__throw_format_error("The date time type specifier for modifier E is invalid"); + } + } + + /// \pre *__begin == 'O' + /// \post __begin is incremented by one. + _LIBCPP_HIDE_FROM_ABI constexpr void + __parse_modifier_O(const _CharT*& __begin, const _CharT* __end, __flags __flags) { + ++__begin; + if (__begin == __end) + std::__throw_format_error("End of input while parsing the modifier O"); + + switch (*__begin) { + case _CharT('S'): + __format_spec::__validate_second(__flags); + break; + + case _CharT('M'): + __format_spec::__validate_minute(__flags); + break; + + case _CharT('I'): + case _CharT('H'): + __format_spec::__validate_hour(__flags); + break; + + case _CharT('d'): + case _CharT('e'): + __format_spec::__validate_day(__flags); + break; + + case _CharT('m'): + __format_spec::__validate_month(__flags); + break; + + case _CharT('y'): + __format_spec::__validate_year(__flags); + break; + + case _CharT('U'): + case _CharT('V'): + case _CharT('W'): + __parser_.__week_of_year_ = true; + __format_spec::__validate_date(__flags); + break; + + case _CharT('u'): + case _CharT('w'): + __parser_.__weekday_ = true; + __format_spec::__validate_weekday(__flags); + break; + + case _CharT('z'): + // Currently there's no time zone information. However some clocks have a + // hard-coded "time zone", for these clocks the information can be used. + // TODO FMT implement time zones. + __format_spec::__validate_time_zone(__flags); + break; + + default: + std::__throw_format_error("The date time type specifier for modifier O is invalid"); + } + } +}; + +} // namespace __format_spec + +#endif //_LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_FORMAT) + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___CHRONO_PARSER_STD_FORMAT_SPEC_H diff --git a/lib/libcxx/include/__chrono/statically_widen.h b/lib/libcxx/include/__chrono/statically_widen.h new file mode 100644 index 0000000000..360b6c2c7d --- /dev/null +++ b/lib/libcxx/include/__chrono/statically_widen.h @@ -0,0 +1,52 @@ +// -*- 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___CHRONO_STATICALLY_WIDEN_H +#define _LIBCPP___CHRONO_STATICALLY_WIDEN_H + +// Implements the STATICALLY-WIDEN exposition-only function. ([time.general]/2) + +#include <__concepts/same_as.h> +#include <__config> +#include <__format/concepts.h> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +#if _LIBCPP_STD_VER > 17 + +# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS +template <__fmt_char_type _CharT> +_LIBCPP_HIDE_FROM_ABI constexpr const _CharT* __statically_widen(const char* __str, const wchar_t* __wstr) { + if constexpr (same_as<_CharT, char>) + return __str; + else + return __wstr; +} +# define _LIBCPP_STATICALLY_WIDEN(_CharT, __str) ::std::__statically_widen<_CharT>(__str, L##__str) +# else // _LIBCPP_HAS_NO_WIDE_CHARACTERS + +// Without this indirection the unit test test/libcxx/modules_include.sh.cpp +// fails for the CI build "No wide characters". This seems like a bug. +// TODO FMT investigate why this is needed. +template <__fmt_char_type _CharT> +_LIBCPP_HIDE_FROM_ABI constexpr const _CharT* __statically_widen(const char* __str) { + return __str; +} +# define _LIBCPP_STATICALLY_WIDEN(_CharT, __str) ::std::__statically_widen<_CharT>(__str) +# endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS + +#endif //_LIBCPP_STD_VER > 17 + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___CHRONO_STATICALLY_WIDEN_H diff --git a/lib/libcxx/include/__chrono/steady_clock.h b/lib/libcxx/include/__chrono/steady_clock.h index 657e5eef6c..ba83351738 100644 --- a/lib/libcxx/include/__chrono/steady_clock.h +++ b/lib/libcxx/include/__chrono/steady_clock.h @@ -31,7 +31,7 @@ public: typedef duration::rep rep; typedef duration::period period; typedef chrono::time_point time_point; - static _LIBCPP_CONSTEXPR_AFTER_CXX11 const bool is_steady = true; + static _LIBCPP_CONSTEXPR_SINCE_CXX14 const bool is_steady = true; static time_point now() _NOEXCEPT; }; diff --git a/lib/libcxx/include/__chrono/system_clock.h b/lib/libcxx/include/__chrono/system_clock.h index 2922b78a74..331db46801 100644 --- a/lib/libcxx/include/__chrono/system_clock.h +++ b/lib/libcxx/include/__chrono/system_clock.h @@ -31,7 +31,7 @@ public: typedef duration::rep rep; typedef duration::period period; typedef chrono::time_point time_point; - static _LIBCPP_CONSTEXPR_AFTER_CXX11 const bool is_steady = false; + static _LIBCPP_CONSTEXPR_SINCE_CXX14 const bool is_steady = false; static time_point now() _NOEXCEPT; static time_t to_time_t (const time_point& __t) _NOEXCEPT; diff --git a/lib/libcxx/include/__chrono/time_point.h b/lib/libcxx/include/__chrono/time_point.h index 63d67d77dd..8a8fa2176d 100644 --- a/lib/libcxx/include/__chrono/time_point.h +++ b/lib/libcxx/include/__chrono/time_point.h @@ -12,8 +12,10 @@ #include <__chrono/duration.h> #include <__config> +#include <__type_traits/common_type.h> +#include <__type_traits/enable_if.h> +#include <__type_traits/is_convertible.h> #include -#include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header @@ -41,12 +43,12 @@ private: duration __d_; public: - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 time_point() : __d_(duration::zero()) {} - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 explicit time_point(const duration& __d) : __d_(__d) {} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14 time_point() : __d_(duration::zero()) {} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit time_point(const duration& __d) : __d_(__d) {} // conversions template - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14 time_point(const time_point& __t, typename enable_if < @@ -56,12 +58,12 @@ public: // observer - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 duration time_since_epoch() const {return __d_;} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14 duration time_since_epoch() const {return __d_;} // arithmetic - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 time_point& operator+=(const duration& __d) {__d_ += __d; return *this;} - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 time_point& operator-=(const duration& __d) {__d_ -= __d; return *this;} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17 time_point& operator+=(const duration& __d) {__d_ += __d; return *this;} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17 time_point& operator-=(const duration& __d) {__d_ -= __d; return *this;} // special values @@ -81,7 +83,7 @@ struct _LIBCPP_TEMPLATE_VIS common_type, namespace chrono { template -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14 time_point<_Clock, _ToDuration> time_point_cast(const time_point<_Clock, _Duration>& __t) { @@ -98,7 +100,7 @@ typename enable_if >::type floor(const time_point<_Clock, _Duration>& __t) { - return time_point<_Clock, _ToDuration>{floor<_ToDuration>(__t.time_since_epoch())}; + return time_point<_Clock, _ToDuration>{chrono::floor<_ToDuration>(__t.time_since_epoch())}; } template @@ -110,7 +112,7 @@ typename enable_if >::type ceil(const time_point<_Clock, _Duration>& __t) { - return time_point<_Clock, _ToDuration>{ceil<_ToDuration>(__t.time_since_epoch())}; + return time_point<_Clock, _ToDuration>{chrono::ceil<_ToDuration>(__t.time_since_epoch())}; } template @@ -122,7 +124,7 @@ typename enable_if >::type round(const time_point<_Clock, _Duration>& __t) { - return time_point<_Clock, _ToDuration>{round<_ToDuration>(__t.time_since_epoch())}; + return time_point<_Clock, _ToDuration>{chrono::round<_ToDuration>(__t.time_since_epoch())}; } template @@ -141,7 +143,7 @@ abs(duration<_Rep, _Period> __d) // time_point == template -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14 bool operator==(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs) { @@ -151,7 +153,7 @@ operator==(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, // time_point != template -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14 bool operator!=(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs) { @@ -161,7 +163,7 @@ operator!=(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, // time_point < template -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14 bool operator<(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs) { @@ -171,7 +173,7 @@ operator<(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, // time_point > template -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14 bool operator>(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs) { @@ -181,7 +183,7 @@ operator>(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, // time_point <= template -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14 bool operator<=(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs) { @@ -191,7 +193,7 @@ operator<=(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, // time_point >= template -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14 bool operator>=(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs) { @@ -201,7 +203,7 @@ operator>=(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, // time_point operator+(time_point x, duration y); template -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14 time_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type> operator+(const time_point<_Clock, _Duration1>& __lhs, const duration<_Rep2, _Period2>& __rhs) { @@ -212,7 +214,7 @@ operator+(const time_point<_Clock, _Duration1>& __lhs, const duration<_Rep2, _Pe // time_point operator+(duration x, time_point y); template -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14 time_point<_Clock, typename common_type, _Duration2>::type> operator+(const duration<_Rep1, _Period1>& __lhs, const time_point<_Clock, _Duration2>& __rhs) { @@ -222,7 +224,7 @@ operator+(const duration<_Rep1, _Period1>& __lhs, const time_point<_Clock, _Dura // time_point operator-(time_point x, duration y); template -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14 time_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type> operator-(const time_point<_Clock, _Duration1>& __lhs, const duration<_Rep2, _Period2>& __rhs) { @@ -233,7 +235,7 @@ operator-(const time_point<_Clock, _Duration1>& __lhs, const duration<_Rep2, _Pe // duration operator-(time_point x, time_point y); template -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14 typename common_type<_Duration1, _Duration2>::type operator-(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs) { diff --git a/lib/libcxx/include/__chrono/weekday.h b/lib/libcxx/include/__chrono/weekday.h index bad6781110..e0bc8a4cae 100644 --- a/lib/libcxx/include/__chrono/weekday.h +++ b/lib/libcxx/include/__chrono/weekday.h @@ -32,25 +32,25 @@ class weekday_last; class weekday { private: - unsigned char __wd; + unsigned char __wd_; _LIBCPP_HIDE_FROM_ABI static constexpr unsigned char __weekday_from_days(int __days) noexcept; public: _LIBCPP_HIDE_FROM_ABI weekday() = default; - _LIBCPP_HIDE_FROM_ABI inline explicit constexpr weekday(unsigned __val) noexcept : __wd(static_cast(__val == 7 ? 0 : __val)) {} + _LIBCPP_HIDE_FROM_ABI inline explicit constexpr weekday(unsigned __val) noexcept : __wd_(static_cast(__val == 7 ? 0 : __val)) {} _LIBCPP_HIDE_FROM_ABI inline constexpr weekday(const sys_days& __sysd) noexcept - : __wd(__weekday_from_days(__sysd.time_since_epoch().count())) {} + : __wd_(__weekday_from_days(__sysd.time_since_epoch().count())) {} _LIBCPP_HIDE_FROM_ABI inline explicit constexpr weekday(const local_days& __locd) noexcept - : __wd(__weekday_from_days(__locd.time_since_epoch().count())) {} + : __wd_(__weekday_from_days(__locd.time_since_epoch().count())) {} - _LIBCPP_HIDE_FROM_ABI inline constexpr weekday& operator++() noexcept { __wd = (__wd == 6 ? 0 : __wd + 1); return *this; } + _LIBCPP_HIDE_FROM_ABI inline constexpr weekday& operator++() noexcept { __wd_ = (__wd_ == 6 ? 0 : __wd_ + 1); return *this; } _LIBCPP_HIDE_FROM_ABI inline constexpr weekday operator++(int) noexcept { weekday __tmp = *this; ++(*this); return __tmp; } - _LIBCPP_HIDE_FROM_ABI inline constexpr weekday& operator--() noexcept { __wd = (__wd == 0 ? 6 : __wd - 1); return *this; } + _LIBCPP_HIDE_FROM_ABI inline constexpr weekday& operator--() noexcept { __wd_ = (__wd_ == 0 ? 6 : __wd_ - 1); return *this; } _LIBCPP_HIDE_FROM_ABI inline constexpr weekday operator--(int) noexcept { weekday __tmp = *this; --(*this); return __tmp; } _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 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; }; @@ -123,15 +123,15 @@ weekday& weekday::operator-=(const days& __dd) noexcept class weekday_indexed { private: - chrono::weekday __wd; - unsigned char __idx; + chrono::weekday __wd_; + unsigned char __idx_; public: _LIBCPP_HIDE_FROM_ABI 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; } + : __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; } }; _LIBCPP_HIDE_FROM_ABI inline constexpr @@ -145,12 +145,12 @@ bool operator!=(const weekday_indexed& __lhs, const weekday_indexed& __rhs) noex class weekday_last { private: - chrono::weekday __wd; + chrono::weekday __wd_; 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(); } + : __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(); } }; _LIBCPP_HIDE_FROM_ABI inline constexpr diff --git a/lib/libcxx/include/__chrono/year.h b/lib/libcxx/include/__chrono/year.h index c7f0027eba..79ee8a02b8 100644 --- a/lib/libcxx/include/__chrono/year.h +++ b/lib/libcxx/include/__chrono/year.h @@ -12,6 +12,7 @@ #include <__chrono/duration.h> #include <__config> +#include #include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) @@ -30,22 +31,22 @@ namespace chrono class year { private: - short __y; + short __y_; public: _LIBCPP_HIDE_FROM_ABI year() = default; - _LIBCPP_HIDE_FROM_ABI explicit inline constexpr year(int __val) noexcept : __y(static_cast(__val)) {} + _LIBCPP_HIDE_FROM_ABI explicit inline constexpr year(int __val) noexcept : __y_(static_cast(__val)) {} - _LIBCPP_HIDE_FROM_ABI inline constexpr year& operator++() noexcept { ++__y; return *this; } + _LIBCPP_HIDE_FROM_ABI inline constexpr year& operator++() noexcept { ++__y_; return *this; } _LIBCPP_HIDE_FROM_ABI inline constexpr year operator++(int) noexcept { year __tmp = *this; ++(*this); return __tmp; } - _LIBCPP_HIDE_FROM_ABI inline constexpr year& operator--() noexcept { --__y; return *this; } + _LIBCPP_HIDE_FROM_ABI inline constexpr year& operator--() noexcept { --__y_; return *this; } _LIBCPP_HIDE_FROM_ABI inline constexpr year operator--(int) noexcept { year __tmp = *this; --(*this); return __tmp; } _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}; } + _LIBCPP_HIDE_FROM_ABI inline constexpr year operator-() const noexcept { return year{-__y_}; } - _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 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}; } @@ -56,25 +57,9 @@ _LIBCPP_HIDE_FROM_ABI inline constexpr bool operator==(const year& __lhs, const year& __rhs) noexcept { return static_cast(__lhs) == static_cast(__rhs); } -_LIBCPP_HIDE_FROM_ABI inline constexpr -bool operator!=(const year& __lhs, const year& __rhs) noexcept -{ return !(__lhs == __rhs); } - -_LIBCPP_HIDE_FROM_ABI inline constexpr -bool operator< (const year& __lhs, const year& __rhs) noexcept -{ return static_cast(__lhs) < static_cast(__rhs); } - -_LIBCPP_HIDE_FROM_ABI inline constexpr -bool operator> (const year& __lhs, const year& __rhs) noexcept -{ return __rhs < __lhs; } - -_LIBCPP_HIDE_FROM_ABI inline constexpr -bool operator<=(const year& __lhs, const year& __rhs) noexcept -{ return !(__rhs < __lhs); } - -_LIBCPP_HIDE_FROM_ABI inline constexpr -bool operator>=(const year& __lhs, const year& __rhs) noexcept -{ return !(__lhs < __rhs); } +_LIBCPP_HIDE_FROM_ABI constexpr strong_ordering operator<=>(const year& __lhs, const year& __rhs) noexcept { + return static_cast(__lhs) <=> static_cast(__rhs); +} _LIBCPP_HIDE_FROM_ABI inline constexpr year operator+ (const year& __lhs, const years& __rhs) noexcept @@ -102,8 +87,8 @@ year& year::operator-=(const years& __dy) noexcept { *this = *this - __dy; return *this; } _LIBCPP_HIDE_FROM_ABI constexpr bool year::ok() const noexcept { - static_assert(static_cast(std::numeric_limits::max()) == static_cast(max())); - return static_cast(min()) <= __y; + static_assert(static_cast(std::numeric_limits::max()) == static_cast(max())); + return static_cast(min()) <= __y_; } } // namespace chrono diff --git a/lib/libcxx/include/__chrono/year_month.h b/lib/libcxx/include/__chrono/year_month.h index 51b19caa11..9f1e65c8c8 100644 --- a/lib/libcxx/include/__chrono/year_month.h +++ b/lib/libcxx/include/__chrono/year_month.h @@ -14,6 +14,7 @@ #include <__chrono/month.h> #include <__chrono/year.h> #include <__config> +#include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header @@ -27,19 +28,19 @@ namespace chrono { class year_month { - chrono::year __y; - chrono::month __m; + chrono::year __y_; + chrono::month __m_; public: _LIBCPP_HIDE_FROM_ABI 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; } - _LIBCPP_HIDE_FROM_ABI inline constexpr year_month& operator+=(const months& __dm) noexcept { this->__m += __dm; return *this; } - _LIBCPP_HIDE_FROM_ABI inline constexpr year_month& operator-=(const months& __dm) noexcept { this->__m -= __dm; return *this; } - _LIBCPP_HIDE_FROM_ABI inline constexpr year_month& operator+=(const years& __dy) noexcept { this->__y += __dy; return *this; } - _LIBCPP_HIDE_FROM_ABI inline constexpr year_month& operator-=(const years& __dy) noexcept { this->__y -= __dy; return *this; } - _LIBCPP_HIDE_FROM_ABI inline constexpr bool ok() const noexcept { return __y.ok() && __m.ok(); } + : __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_; } + _LIBCPP_HIDE_FROM_ABI inline constexpr year_month& operator+=(const months& __dm) noexcept { this->__m_ += __dm; return *this; } + _LIBCPP_HIDE_FROM_ABI inline constexpr year_month& operator-=(const months& __dm) noexcept { this->__m_ -= __dm; return *this; } + _LIBCPP_HIDE_FROM_ABI inline constexpr year_month& operator+=(const years& __dy) noexcept { this->__y_ += __dy; return *this; } + _LIBCPP_HIDE_FROM_ABI inline constexpr year_month& operator-=(const years& __dy) noexcept { this->__y_ -= __dy; return *this; } + _LIBCPP_HIDE_FROM_ABI inline constexpr bool ok() const noexcept { return __y_.ok() && __m_.ok(); } }; _LIBCPP_HIDE_FROM_ABI inline constexpr @@ -52,25 +53,11 @@ _LIBCPP_HIDE_FROM_ABI inline constexpr bool operator==(const year_month& __lhs, const year_month& __rhs) noexcept { return __lhs.year() == __rhs.year() && __lhs.month() == __rhs.month(); } -_LIBCPP_HIDE_FROM_ABI inline constexpr -bool operator!=(const year_month& __lhs, const year_month& __rhs) noexcept -{ return !(__lhs == __rhs); } - -_LIBCPP_HIDE_FROM_ABI inline constexpr -bool operator< (const year_month& __lhs, const year_month& __rhs) noexcept -{ return __lhs.year() != __rhs.year() ? __lhs.year() < __rhs.year() : __lhs.month() < __rhs.month(); } - -_LIBCPP_HIDE_FROM_ABI inline constexpr -bool operator> (const year_month& __lhs, const year_month& __rhs) noexcept -{ return __rhs < __lhs; } - -_LIBCPP_HIDE_FROM_ABI inline constexpr -bool operator<=(const year_month& __lhs, const year_month& __rhs) noexcept -{ return !(__rhs < __lhs);} - -_LIBCPP_HIDE_FROM_ABI inline constexpr -bool operator>=(const year_month& __lhs, const year_month& __rhs) noexcept -{ return !(__lhs < __rhs); } +_LIBCPP_HIDE_FROM_ABI constexpr strong_ordering operator<=>(const year_month& __lhs, const year_month& __rhs) noexcept { + if (auto __c = __lhs.year() <=> __rhs.year(); __c != 0) + return __c; + return __lhs.month() <=> __rhs.month(); +} _LIBCPP_HIDE_FROM_ABI constexpr year_month operator+(const year_month& __lhs, const months& __rhs) noexcept diff --git a/lib/libcxx/include/__chrono/year_month_day.h b/lib/libcxx/include/__chrono/year_month_day.h index 957716aab6..b74901470c 100644 --- a/lib/libcxx/include/__chrono/year_month_day.h +++ b/lib/libcxx/include/__chrono/year_month_day.h @@ -20,6 +20,7 @@ #include <__chrono/year.h> #include <__chrono/year_month.h> #include <__config> +#include #include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) @@ -37,14 +38,14 @@ class year_month_day_last; class year_month_day { private: - chrono::year __y; - chrono::month __m; - chrono::day __d; + chrono::year __y_; + chrono::month __m_; + chrono::day __d_; public: _LIBCPP_HIDE_FROM_ABI year_month_day() = default; _LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day( const chrono::year& __yval, const chrono::month& __mval, const chrono::day& __dval) noexcept - : __y{__yval}, __m{__mval}, __d{__dval} {} + : __y_{__yval}, __m_{__mval}, __d_{__dval} {} _LIBCPP_HIDE_FROM_ABI constexpr year_month_day(const year_month_day_last& __ymdl) noexcept; _LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day(const sys_days& __sysd) noexcept : year_month_day(__from_days(__sysd.time_since_epoch())) {} @@ -56,9 +57,9 @@ 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; } + _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_; } _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()}; } @@ -94,9 +95,9 @@ days year_month_day::__to_days() const noexcept static_assert(numeric_limits::digits >= 18, ""); static_assert(numeric_limits::digits >= 20 , ""); - const int __yr = static_cast(__y) - (__m <= February); - const unsigned __mth = static_cast(__m); - const unsigned __dy = static_cast(__d); + const int __yr = static_cast(__y_) - (__m_ <= February); + const unsigned __mth = static_cast(__m_); + const unsigned __dy = static_cast(__d_); const int __era = (__yr >= 0 ? __yr : __yr - 399) / 400; const unsigned __yoe = static_cast(__yr - __era * 400); // [0, 399] @@ -109,32 +110,15 @@ _LIBCPP_HIDE_FROM_ABI inline constexpr bool operator==(const year_month_day& __lhs, const year_month_day& __rhs) noexcept { return __lhs.year() == __rhs.year() && __lhs.month() == __rhs.month() && __lhs.day() == __rhs.day(); } -_LIBCPP_HIDE_FROM_ABI inline constexpr -bool operator!=(const year_month_day& __lhs, const year_month_day& __rhs) noexcept -{ return !(__lhs == __rhs); } - -_LIBCPP_HIDE_FROM_ABI inline constexpr -bool operator< (const year_month_day& __lhs, const year_month_day& __rhs) noexcept -{ - if (__lhs.year() < __rhs.year()) return true; - if (__lhs.year() > __rhs.year()) return false; - if (__lhs.month() < __rhs.month()) return true; - if (__lhs.month() > __rhs.month()) return false; - return __lhs.day() < __rhs.day(); +_LIBCPP_HIDE_FROM_ABI constexpr strong_ordering +operator<=>(const year_month_day& __lhs, const year_month_day& __rhs) noexcept { + if (auto __c = __lhs.year() <=> __rhs.year(); __c != 0) + return __c; + if (auto __c = __lhs.month() <=> __rhs.month(); __c != 0) + return __c; + return __lhs.day() <=> __rhs.day(); } -_LIBCPP_HIDE_FROM_ABI inline constexpr -bool operator> (const year_month_day& __lhs, const year_month_day& __rhs) noexcept -{ return __rhs < __lhs; } - -_LIBCPP_HIDE_FROM_ABI inline constexpr -bool operator<=(const year_month_day& __lhs, const year_month_day& __rhs) noexcept -{ return !(__rhs < __lhs);} - -_LIBCPP_HIDE_FROM_ABI inline constexpr -bool operator>=(const year_month_day& __lhs, const year_month_day& __rhs) noexcept -{ return !(__lhs < __rhs); } - _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}; } @@ -191,24 +175,24 @@ _LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day& year_month_day::operator- class year_month_day_last { private: - chrono::year __y; - chrono::month_day_last __mdl; + chrono::year __y_; + chrono::month_day_last __mdl_; public: _LIBCPP_HIDE_FROM_ABI constexpr year_month_day_last(const year& __yval, const month_day_last& __mdlval) noexcept - : __y{__yval}, __mdl{__mdlval} {} + : __y_{__yval}, __mdl_{__mdlval} {} _LIBCPP_HIDE_FROM_ABI constexpr year_month_day_last& operator+=(const months& __m) noexcept; _LIBCPP_HIDE_FROM_ABI constexpr year_month_day_last& operator-=(const months& __m) noexcept; _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 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; _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(); } + _LIBCPP_HIDE_FROM_ABI inline constexpr bool ok() const noexcept { return __y_.ok() && __mdl_.ok(); } }; _LIBCPP_HIDE_FROM_ABI inline constexpr @@ -221,7 +205,7 @@ chrono::day year_month_day_last::day() const noexcept chrono::day(31), chrono::day(31), chrono::day(30), chrono::day(31), chrono::day(30), chrono::day(31) }; - return (month() != February || !__y.is_leap()) && month().ok() ? + return (month() != February || !__y_.is_leap()) && month().ok() ? __d[static_cast(month()) - 1] : chrono::day{29}; } @@ -305,13 +289,13 @@ _LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day_last& year_month_day_last: _LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day::year_month_day(const year_month_day_last& __ymdl) noexcept - : __y{__ymdl.year()}, __m{__ymdl.month()}, __d{__ymdl.day()} {} + : __y_{__ymdl.year()}, __m_{__ymdl.month()}, __d_{__ymdl.day()} {} _LIBCPP_HIDE_FROM_ABI inline constexpr bool year_month_day::ok() const noexcept { - if (!__y.ok() || !__m.ok()) return false; - return chrono::day{1} <= __d && __d <= (__y / __m / last).day(); + if (!__y_.ok() || !__m_.ok()) return false; + return chrono::day{1} <= __d_ && __d_ <= (__y_ / __m_ / last).day(); } } // namespace chrono diff --git a/lib/libcxx/include/__chrono/year_month_weekday.h b/lib/libcxx/include/__chrono/year_month_weekday.h index b69b77152f..6604deaf12 100644 --- a/lib/libcxx/include/__chrono/year_month_weekday.h +++ b/lib/libcxx/include/__chrono/year_month_weekday.h @@ -35,14 +35,14 @@ namespace chrono { class year_month_weekday { - chrono::year __y; - chrono::month __m; - chrono::weekday_indexed __wdi; + chrono::year __y_; + chrono::month __m_; + chrono::weekday_indexed __wdi_; public: _LIBCPP_HIDE_FROM_ABI year_month_weekday() = default; _LIBCPP_HIDE_FROM_ABI constexpr year_month_weekday(const chrono::year& __yval, const chrono::month& __mval, const chrono::weekday_indexed& __wdival) noexcept - : __y{__yval}, __m{__mval}, __wdi{__wdival} {} + : __y_{__yval}, __m_{__mval}, __wdi_{__wdival} {} _LIBCPP_HIDE_FROM_ABI constexpr year_month_weekday(const sys_days& __sysd) noexcept : year_month_weekday(__from_days(__sysd.time_since_epoch())) {} _LIBCPP_HIDE_FROM_ABI inline explicit constexpr year_month_weekday(const local_days& __locd) noexcept @@ -52,24 +52,24 @@ 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; } + _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_; } _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 { - if (!__y.ok() || !__m.ok() || !__wdi.ok()) return false; - if (__wdi.index() <= 4) return true; + if (!__y_.ok() || !__m_.ok() || !__wdi_.ok()) return false; + if (__wdi_.index() <= 4) return true; auto __nth_weekday_day = - __wdi.weekday() - - chrono::weekday{static_cast(__y / __m / 1)} + - days{(__wdi.index() - 1) * 7 + 1}; + __wdi_.weekday() - + chrono::weekday{static_cast(__y_ / __m_ / 1)} + + days{(__wdi_.index() - 1) * 7 + 1}; return static_cast(__nth_weekday_day.count()) <= - static_cast((__y / __m / last).day()); + static_cast((__y_ / __m_ / last).day()); } _LIBCPP_HIDE_FROM_ABI static constexpr year_month_weekday __from_days(days __d) noexcept; @@ -89,8 +89,8 @@ year_month_weekday year_month_weekday::__from_days(days __d) noexcept _LIBCPP_HIDE_FROM_ABI inline constexpr days year_month_weekday::__to_days() const noexcept { - const sys_days __sysd = sys_days(__y/__m/1); - return (__sysd + (__wdi.weekday() - chrono::weekday(__sysd) + days{(__wdi.index()-1)*7})) + const sys_days __sysd = sys_days(__y_/__m_/1); + return (__sysd + (__wdi_.weekday() - chrono::weekday(__sysd) + days{(__wdi_.index()-1)*7})) .time_since_epoch(); } @@ -155,25 +155,25 @@ _LIBCPP_HIDE_FROM_ABI inline constexpr year_month_weekday& year_month_weekday::o class year_month_weekday_last { private: - chrono::year __y; - chrono::month __m; - chrono::weekday_last __wdl; + chrono::year __y_; + chrono::month __m_; + chrono::weekday_last __wdl_; public: _LIBCPP_HIDE_FROM_ABI constexpr year_month_weekday_last(const chrono::year& __yval, const chrono::month& __mval, const chrono::weekday_last& __wdlval) noexcept - : __y{__yval}, __m{__mval}, __wdl{__wdlval} {} + : __y_{__yval}, __m_{__mval}, __wdl_{__wdlval} {} _LIBCPP_HIDE_FROM_ABI constexpr year_month_weekday_last& operator+=(const months& __dm) noexcept; _LIBCPP_HIDE_FROM_ABI constexpr year_month_weekday_last& operator-=(const months& __dm) noexcept; _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; } + _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_; } _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(); } + _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; @@ -182,8 +182,8 @@ public: _LIBCPP_HIDE_FROM_ABI inline constexpr days year_month_weekday_last::__to_days() const noexcept { - const sys_days __last = sys_days{__y/__m/last}; - return (__last - (chrono::weekday{__last} - __wdl.weekday())).time_since_epoch(); + const sys_days __last = sys_days{__y_/__m_/last}; + return (__last - (chrono::weekday{__last} - __wdl_.weekday())).time_since_epoch(); } diff --git a/lib/libcxx/include/__compare/common_comparison_category.h b/lib/libcxx/include/__compare/common_comparison_category.h index deab171846..06c4b28491 100644 --- a/lib/libcxx/include/__compare/common_comparison_category.h +++ b/lib/libcxx/include/__compare/common_comparison_category.h @@ -11,7 +11,8 @@ #include <__compare/ordering.h> #include <__config> -#include +#include <__type_traits/is_same.h> +#include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header @@ -64,7 +65,7 @@ _LIBCPP_HIDE_FROM_ABI constexpr auto __get_comp_type() { using _CCC = _ClassifyCompCategory; constexpr _CCC __type_kinds[] = {_StrongOrd, __type_to_enum<_Ts>()...}; - constexpr _CCC _Cat = __compute_comp_type(__type_kinds); + constexpr _CCC _Cat = __comp_detail::__compute_comp_type(__type_kinds); if constexpr (_Cat == _None) return void(); else if constexpr (_Cat == _PartialOrd) diff --git a/lib/libcxx/include/__compare/compare_partial_order_fallback.h b/lib/libcxx/include/__compare/compare_partial_order_fallback.h index ba746d6c7d..06f03fe7ad 100644 --- a/lib/libcxx/include/__compare/compare_partial_order_fallback.h +++ b/lib/libcxx/include/__compare/compare_partial_order_fallback.h @@ -12,9 +12,10 @@ #include <__compare/ordering.h> #include <__compare/partial_order.h> #include <__config> +#include <__type_traits/decay.h> +#include <__type_traits/is_same.h> #include <__utility/forward.h> #include <__utility/priority_tag.h> -#include #ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER # pragma GCC system_header diff --git a/lib/libcxx/include/__compare/compare_strong_order_fallback.h b/lib/libcxx/include/__compare/compare_strong_order_fallback.h index 312a08ef7e..869386817a 100644 --- a/lib/libcxx/include/__compare/compare_strong_order_fallback.h +++ b/lib/libcxx/include/__compare/compare_strong_order_fallback.h @@ -12,9 +12,10 @@ #include <__compare/ordering.h> #include <__compare/strong_order.h> #include <__config> +#include <__type_traits/decay.h> +#include <__type_traits/is_same.h> #include <__utility/forward.h> #include <__utility/priority_tag.h> -#include #ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER # pragma GCC system_header diff --git a/lib/libcxx/include/__compare/compare_three_way_result.h b/lib/libcxx/include/__compare/compare_three_way_result.h index 7b03597ab1..8885d7effa 100644 --- a/lib/libcxx/include/__compare/compare_three_way_result.h +++ b/lib/libcxx/include/__compare/compare_three_way_result.h @@ -10,7 +10,8 @@ #define _LIBCPP___COMPARE_COMPARE_THREE_WAY_RESULT_H #include <__config> -#include +#include <__type_traits/make_const_lvalue_ref.h> +#include <__utility/declval.h> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header @@ -25,9 +26,9 @@ struct _LIBCPP_HIDE_FROM_ABI __compare_three_way_result { }; template struct _LIBCPP_HIDE_FROM_ABI __compare_three_way_result<_Tp, _Up, decltype( - declval<__make_const_lvalue_ref<_Tp>>() <=> declval<__make_const_lvalue_ref<_Up>>(), void() + std::declval<__make_const_lvalue_ref<_Tp>>() <=> std::declval<__make_const_lvalue_ref<_Up>>(), void() )> { - using type = decltype(declval<__make_const_lvalue_ref<_Tp>>() <=> declval<__make_const_lvalue_ref<_Up>>()); + using type = decltype(std::declval<__make_const_lvalue_ref<_Tp>>() <=> std::declval<__make_const_lvalue_ref<_Up>>()); }; template diff --git a/lib/libcxx/include/__compare/compare_weak_order_fallback.h b/lib/libcxx/include/__compare/compare_weak_order_fallback.h index 844d676087..f434dcb4a3 100644 --- a/lib/libcxx/include/__compare/compare_weak_order_fallback.h +++ b/lib/libcxx/include/__compare/compare_weak_order_fallback.h @@ -12,9 +12,10 @@ #include <__compare/ordering.h> #include <__compare/weak_order.h> #include <__config> +#include <__type_traits/decay.h> +#include <__type_traits/is_same.h> #include <__utility/forward.h> #include <__utility/priority_tag.h> -#include #ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER # pragma GCC system_header diff --git a/lib/libcxx/include/__compare/ordering.h b/lib/libcxx/include/__compare/ordering.h index 1d466d669e..ff148abf23 100644 --- a/lib/libcxx/include/__compare/ordering.h +++ b/lib/libcxx/include/__compare/ordering.h @@ -10,7 +10,8 @@ #define _LIBCPP___COMPARE_ORDERING_H #include <__config> -#include +#include <__type_traits/enable_if.h> +#include <__type_traits/is_same.h> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header @@ -312,6 +313,12 @@ inline constexpr strong_ordering strong_ordering::equal(_OrdResult::__equiv); inline constexpr strong_ordering strong_ordering::equivalent(_OrdResult::__equiv); inline constexpr strong_ordering strong_ordering::greater(_OrdResult::__greater); +/// [cmp.categories.pre]/1 +/// The types partial_ordering, weak_ordering, and strong_ordering are +/// collectively termed the comparison category types. +template +concept __comparison_category = __one_of_v<_Tp, partial_ordering, weak_ordering, strong_ordering>; + #endif // _LIBCPP_STD_VER > 17 _LIBCPP_END_NAMESPACE_STD diff --git a/lib/libcxx/include/__compare/partial_order.h b/lib/libcxx/include/__compare/partial_order.h index 970f01b3f1..aee07ebb42 100644 --- a/lib/libcxx/include/__compare/partial_order.h +++ b/lib/libcxx/include/__compare/partial_order.h @@ -13,9 +13,10 @@ #include <__compare/ordering.h> #include <__compare/weak_order.h> #include <__config> +#include <__type_traits/decay.h> +#include <__type_traits/is_same.h> #include <__utility/forward.h> #include <__utility/priority_tag.h> -#include #ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER # pragma GCC system_header @@ -28,6 +29,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD // [cmp.alg] namespace __partial_order { struct __fn { + // NOLINTBEGIN(libcpp-robust-against-adl) partial_order should use ADL, but only here template requires is_same_v, decay_t<_Up>> _LIBCPP_HIDE_FROM_ABI static constexpr auto @@ -35,6 +37,7 @@ namespace __partial_order { noexcept(noexcept(partial_ordering(partial_order(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u))))) -> decltype( partial_ordering(partial_order(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u)))) { return partial_ordering(partial_order(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u))); } + // NOLINTEND(libcpp-robust-against-adl) template requires is_same_v, decay_t<_Up>> diff --git a/lib/libcxx/include/__compare/strong_order.h b/lib/libcxx/include/__compare/strong_order.h index 67c7b2910b..05856c2093 100644 --- a/lib/libcxx/include/__compare/strong_order.h +++ b/lib/libcxx/include/__compare/strong_order.h @@ -13,12 +13,13 @@ #include <__compare/compare_three_way.h> #include <__compare/ordering.h> #include <__config> +#include <__type_traits/conditional.h> +#include <__type_traits/decay.h> #include <__utility/forward.h> #include <__utility/priority_tag.h> #include #include #include -#include #ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER # pragma GCC system_header @@ -34,6 +35,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD // [cmp.alg] namespace __strong_order { struct __fn { + // NOLINTBEGIN(libcpp-robust-against-adl) strong_order should use ADL, but only here template requires is_same_v, decay_t<_Up>> _LIBCPP_HIDE_FROM_ABI static constexpr auto @@ -41,6 +43,7 @@ namespace __strong_order { noexcept(noexcept(strong_ordering(strong_order(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u))))) -> decltype( strong_ordering(strong_order(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u)))) { return strong_ordering(strong_order(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u))); } + // NOLINTEND(libcpp-robust-against-adl) template> requires is_same_v<_Dp, decay_t<_Up>> && is_floating_point_v<_Dp> diff --git a/lib/libcxx/include/__compare/synth_three_way.h b/lib/libcxx/include/__compare/synth_three_way.h index fa8cbda79b..7d338987e0 100644 --- a/lib/libcxx/include/__compare/synth_three_way.h +++ b/lib/libcxx/include/__compare/synth_three_way.h @@ -42,7 +42,7 @@ _LIBCPP_HIDE_FROM_ABI inline constexpr auto __synth_three_way = }; template -using __synth_three_way_result = decltype(std::__synth_three_way(declval<_Tp&>(), declval<_Up&>())); +using __synth_three_way_result = decltype(std::__synth_three_way(std::declval<_Tp&>(), std::declval<_Up&>())); #endif // _LIBCPP_STD_VER > 17 diff --git a/lib/libcxx/include/__compare/three_way_comparable.h b/lib/libcxx/include/__compare/three_way_comparable.h index b317d75059..6c98916d85 100644 --- a/lib/libcxx/include/__compare/three_way_comparable.h +++ b/lib/libcxx/include/__compare/three_way_comparable.h @@ -16,7 +16,8 @@ #include <__concepts/same_as.h> #include <__concepts/totally_ordered.h> #include <__config> -#include +#include <__type_traits/common_reference.h> +#include <__type_traits/make_const_lvalue_ref.h> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header diff --git a/lib/libcxx/include/__compare/weak_order.h b/lib/libcxx/include/__compare/weak_order.h index c2fae1a98d..abb24e3665 100644 --- a/lib/libcxx/include/__compare/weak_order.h +++ b/lib/libcxx/include/__compare/weak_order.h @@ -13,10 +13,10 @@ #include <__compare/ordering.h> #include <__compare/strong_order.h> #include <__config> +#include <__type_traits/decay.h> #include <__utility/forward.h> #include <__utility/priority_tag.h> #include -#include #ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER # pragma GCC system_header @@ -29,6 +29,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD // [cmp.alg] namespace __weak_order { struct __fn { + // NOLINTBEGIN(libcpp-robust-against-adl) weak_order should use ADL, but only here template requires is_same_v, decay_t<_Up>> _LIBCPP_HIDE_FROM_ABI static constexpr auto @@ -36,6 +37,7 @@ namespace __weak_order { noexcept(noexcept(weak_ordering(weak_order(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u))))) -> decltype( weak_ordering(weak_order(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u)))) { return weak_ordering(weak_order(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u))); } + // NOLINTEND(libcpp-robust-against-adl) template> requires is_same_v<_Dp, decay_t<_Up>> && is_floating_point_v<_Dp> diff --git a/lib/libcxx/include/__concepts/arithmetic.h b/lib/libcxx/include/__concepts/arithmetic.h index d91570f02b..215b52aa02 100644 --- a/lib/libcxx/include/__concepts/arithmetic.h +++ b/lib/libcxx/include/__concepts/arithmetic.h @@ -10,9 +10,11 @@ #define _LIBCPP___CONCEPTS_ARITHMETIC_H #include <__config> +#include <__type_traits/is_floating_point.h> +#include <__type_traits/is_integral.h> +#include <__type_traits/is_signed.h> #include <__type_traits/is_signed_integer.h> #include <__type_traits/is_unsigned_integer.h> -#include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header diff --git a/lib/libcxx/include/__concepts/assignable.h b/lib/libcxx/include/__concepts/assignable.h index 7f187a39f8..91edd400ad 100644 --- a/lib/libcxx/include/__concepts/assignable.h +++ b/lib/libcxx/include/__concepts/assignable.h @@ -12,8 +12,9 @@ #include <__concepts/common_reference_with.h> #include <__concepts/same_as.h> #include <__config> +#include <__type_traits/is_reference.h> +#include <__type_traits/make_const_lvalue_ref.h> #include <__utility/forward.h> -#include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header diff --git a/lib/libcxx/include/__concepts/class_or_enum.h b/lib/libcxx/include/__concepts/class_or_enum.h index 9fd62ba892..c4d2f98952 100644 --- a/lib/libcxx/include/__concepts/class_or_enum.h +++ b/lib/libcxx/include/__concepts/class_or_enum.h @@ -10,7 +10,10 @@ #define _LIBCPP___CONCEPTS_CLASS_OR_ENUM_H #include <__config> -#include +#include <__type_traits/is_class.h> +#include <__type_traits/is_enum.h> +#include <__type_traits/is_union.h> +#include <__type_traits/remove_cvref.h> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header @@ -28,7 +31,7 @@ concept __class_or_enum = is_class_v<_Tp> || is_union_v<_Tp> || is_enum_v<_Tp>; // Work around Clang bug https://llvm.org/PR52970 // TODO: remove this workaround once libc++ no longer has to support Clang 13 (it was fixed in Clang 14). template -concept __workaround_52970 = is_class_v<__uncvref_t<_Tp>> || is_union_v<__uncvref_t<_Tp>>; +concept __workaround_52970 = is_class_v<__remove_cvref_t<_Tp>> || is_union_v<__remove_cvref_t<_Tp>>; #endif // _LIBCPP_STD_VER > 17 diff --git a/lib/libcxx/include/__concepts/common_reference_with.h b/lib/libcxx/include/__concepts/common_reference_with.h index cae2f5bccc..cc92762d31 100644 --- a/lib/libcxx/include/__concepts/common_reference_with.h +++ b/lib/libcxx/include/__concepts/common_reference_with.h @@ -12,7 +12,7 @@ #include <__concepts/convertible_to.h> #include <__concepts/same_as.h> #include <__config> -#include +#include <__type_traits/common_reference.h> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header diff --git a/lib/libcxx/include/__concepts/common_with.h b/lib/libcxx/include/__concepts/common_with.h index 1b5f4da4af..569a0ee3b7 100644 --- a/lib/libcxx/include/__concepts/common_with.h +++ b/lib/libcxx/include/__concepts/common_with.h @@ -12,7 +12,10 @@ #include <__concepts/common_reference_with.h> #include <__concepts/same_as.h> #include <__config> -#include +#include <__type_traits/add_lvalue_reference.h> +#include <__type_traits/common_reference.h> +#include <__type_traits/common_type.h> +#include <__utility/declval.h> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header @@ -28,8 +31,8 @@ template concept common_with = same_as, common_type_t<_Up, _Tp>> && requires { - static_cast>(declval<_Tp>()); - static_cast>(declval<_Up>()); + static_cast>(std::declval<_Tp>()); + static_cast>(std::declval<_Up>()); } && common_reference_with< add_lvalue_reference_t, diff --git a/lib/libcxx/include/__concepts/constructible.h b/lib/libcxx/include/__concepts/constructible.h index aaf515417e..1d78eb5fd1 100644 --- a/lib/libcxx/include/__concepts/constructible.h +++ b/lib/libcxx/include/__concepts/constructible.h @@ -12,7 +12,7 @@ #include <__concepts/convertible_to.h> #include <__concepts/destructible.h> #include <__config> -#include +#include <__type_traits/is_constructible.h> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header diff --git a/lib/libcxx/include/__concepts/convertible_to.h b/lib/libcxx/include/__concepts/convertible_to.h index 5d9d437104..2c1d267410 100644 --- a/lib/libcxx/include/__concepts/convertible_to.h +++ b/lib/libcxx/include/__concepts/convertible_to.h @@ -10,8 +10,8 @@ #define _LIBCPP___CONCEPTS_CONVERTIBLE_TO_H #include <__config> +#include <__type_traits/is_convertible.h> #include <__utility/declval.h> -#include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header @@ -27,7 +27,7 @@ template concept convertible_to = is_convertible_v<_From, _To> && requires { - static_cast<_To>(declval<_From>()); + static_cast<_To>(std::declval<_From>()); }; #endif // _LIBCPP_STD_VER > 17 diff --git a/lib/libcxx/include/__concepts/derived_from.h b/lib/libcxx/include/__concepts/derived_from.h index 4b29147947..0d3462df6a 100644 --- a/lib/libcxx/include/__concepts/derived_from.h +++ b/lib/libcxx/include/__concepts/derived_from.h @@ -10,7 +10,8 @@ #define _LIBCPP___CONCEPTS_DERIVED_FROM_H #include <__config> -#include +#include <__type_traits/is_base_of.h> +#include <__type_traits/is_convertible.h> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header diff --git a/lib/libcxx/include/__concepts/destructible.h b/lib/libcxx/include/__concepts/destructible.h index 90a043d314..ad3819d5dc 100644 --- a/lib/libcxx/include/__concepts/destructible.h +++ b/lib/libcxx/include/__concepts/destructible.h @@ -10,7 +10,7 @@ #define _LIBCPP___CONCEPTS_DESTRUCTIBLE_H #include <__config> -#include +#include <__type_traits/is_nothrow_destructible.h> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header diff --git a/lib/libcxx/include/__concepts/different_from.h b/lib/libcxx/include/__concepts/different_from.h index 3066372e86..15fd8f0551 100644 --- a/lib/libcxx/include/__concepts/different_from.h +++ b/lib/libcxx/include/__concepts/different_from.h @@ -11,7 +11,7 @@ #include <__concepts/same_as.h> #include <__config> -#include +#include <__type_traits/remove_cvref.h> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header diff --git a/lib/libcxx/include/__concepts/equality_comparable.h b/lib/libcxx/include/__concepts/equality_comparable.h index 7c750c5937..b865141705 100644 --- a/lib/libcxx/include/__concepts/equality_comparable.h +++ b/lib/libcxx/include/__concepts/equality_comparable.h @@ -12,7 +12,8 @@ #include <__concepts/boolean_testable.h> #include <__concepts/common_reference_with.h> #include <__config> -#include +#include <__type_traits/common_reference.h> +#include <__type_traits/make_const_lvalue_ref.h> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header diff --git a/lib/libcxx/include/__concepts/invocable.h b/lib/libcxx/include/__concepts/invocable.h index d90389e97f..ec39b7b817 100644 --- a/lib/libcxx/include/__concepts/invocable.h +++ b/lib/libcxx/include/__concepts/invocable.h @@ -12,7 +12,6 @@ #include <__config> #include <__functional/invoke.h> #include <__utility/forward.h> -#include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header diff --git a/lib/libcxx/include/__concepts/movable.h b/lib/libcxx/include/__concepts/movable.h index 639219ed6b..749b78ad10 100644 --- a/lib/libcxx/include/__concepts/movable.h +++ b/lib/libcxx/include/__concepts/movable.h @@ -13,7 +13,7 @@ #include <__concepts/constructible.h> #include <__concepts/swappable.h> #include <__config> -#include +#include <__type_traits/is_object.h> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header diff --git a/lib/libcxx/include/__concepts/predicate.h b/lib/libcxx/include/__concepts/predicate.h index cb23975230..7ae9783264 100644 --- a/lib/libcxx/include/__concepts/predicate.h +++ b/lib/libcxx/include/__concepts/predicate.h @@ -12,7 +12,7 @@ #include <__concepts/boolean_testable.h> #include <__concepts/invocable.h> #include <__config> -#include +#include <__functional/invoke.h> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header diff --git a/lib/libcxx/include/__concepts/same_as.h b/lib/libcxx/include/__concepts/same_as.h index 7654906611..554ebc3b07 100644 --- a/lib/libcxx/include/__concepts/same_as.h +++ b/lib/libcxx/include/__concepts/same_as.h @@ -10,7 +10,7 @@ #define _LIBCPP___CONCEPTS_SAME_AS_H #include <__config> -#include +#include <__type_traits/is_same.h> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header diff --git a/lib/libcxx/include/__concepts/swappable.h b/lib/libcxx/include/__concepts/swappable.h index fef940f21f..d91a7a1dc3 100644 --- a/lib/libcxx/include/__concepts/swappable.h +++ b/lib/libcxx/include/__concepts/swappable.h @@ -14,10 +14,15 @@ #include <__concepts/common_reference_with.h> #include <__concepts/constructible.h> #include <__config> +#include <__type_traits/extent.h> +#include <__type_traits/is_nothrow_move_assignable.h> +#include <__type_traits/is_nothrow_move_constructible.h> +#include <__type_traits/remove_cvref.h> #include <__utility/exchange.h> #include <__utility/forward.h> #include <__utility/move.h> -#include +#include <__utility/swap.h> +#include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header diff --git a/lib/libcxx/include/__concepts/totally_ordered.h b/lib/libcxx/include/__concepts/totally_ordered.h index 25347790de..f12d26b108 100644 --- a/lib/libcxx/include/__concepts/totally_ordered.h +++ b/lib/libcxx/include/__concepts/totally_ordered.h @@ -12,7 +12,8 @@ #include <__concepts/boolean_testable.h> #include <__concepts/equality_comparable.h> #include <__config> -#include +#include <__type_traits/common_reference.h> +#include <__type_traits/make_const_lvalue_ref.h> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header diff --git a/lib/libcxx/include/__config b/lib/libcxx/include/__config index 0aab23b9b4..b9203e640a 100644 --- a/lib/libcxx/include/__config +++ b/lib/libcxx/include/__config @@ -10,6 +10,8 @@ #ifndef _LIBCPP___CONFIG #define _LIBCPP___CONFIG +#include <__config_site> + #if defined(_MSC_VER) && !defined(__clang__) # if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # define _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER @@ -28,13 +30,14 @@ # define _LIBCPP_CLANG_VER (__clang_major__ * 100 + __clang_minor__) #elif defined(__GNUC__) # define _LIBCPP_COMPILER_GCC -#elif defined(_MSC_VER) -# define _LIBCPP_COMPILER_MSVC #endif #ifdef __cplusplus -# define _LIBCPP_VERSION 15003 +// _LIBCPP_VERSION represents the version of libc++, which matches the version of LLVM. +// Given a LLVM release LLVM XX.YY.ZZ (e.g. LLVM 16.0.1 == 16.00.01), _LIBCPP_VERSION is +// defined to XXYYZZ. +# define _LIBCPP_VERSION 160000 # define _LIBCPP_CONCAT_IMPL(_X, _Y) _X##_Y # define _LIBCPP_CONCAT(_X, _Y) _LIBCPP_CONCAT_IMPL(_X, _Y) @@ -57,7 +60,8 @@ # elif __cplusplus <= 202002L # define _LIBCPP_STD_VER 20 # else -# define _LIBCPP_STD_VER 22 // current year, or date of c++2b ratification +// Expected release year of the next C++ standard +# define _LIBCPP_STD_VER 23 # endif # endif // _LIBCPP_STD_VER @@ -148,7 +152,7 @@ # endif // Feature macros for disabling pre ABI v1 features. All of these options // are deprecated. -# if defined(__FreeBSD__) || defined(__DragonFly__) +# if defined(__FreeBSD__) # define _LIBCPP_DEPRECATED_ABI_DISABLE_PAIR_TRIVIAL_COPY_CTOR # endif # endif @@ -165,7 +169,7 @@ # define _LIBCPP_ABI_BAD_FUNCTION_CALL_KEY_FUNCTION # endif -# define _LIBCPP_TOSTRING2(x) # x +# define _LIBCPP_TOSTRING2(x) #x # define _LIBCPP_TOSTRING(x) _LIBCPP_TOSTRING2(x) # if __cplusplus < 201103L @@ -192,6 +196,10 @@ # define __has_cpp_attribute(__x) 0 # endif +# ifndef __has_constexpr_builtin +# define __has_constexpr_builtin(x) 0 +# endif + // '__is_identifier' returns '0' if '__x' is a reserved identifier provided by // the compiler and '1' otherwise. # ifndef __is_identifier @@ -212,12 +220,6 @@ # error "libc++ only supports C++03 with Clang-based compilers. Please enable C++11" # endif -# ifdef _LIBCPP_COMPILER_MSVC -# error If you successfully use libc++ with MSVC please tell the libc++ developers and consider upstreaming your \ -changes. We are not aware of anybody using this configuration and know that at least some code is currently broken. \ -If there are users of this configuration we are happy to provide support. -# endif - // FIXME: ABI detection should be done via compiler builtin macros. This // is just a placeholder until Clang implements such macros. For now assume // that Windows compilers pretending to be MSVC++ target the Microsoft ABI, @@ -251,7 +253,6 @@ If there are users of this configuration we are happy to provide support. // easier to grep for target specific flags once the feature is complete. # if !defined(_LIBCPP_ENABLE_EXPERIMENTAL) && !defined(_LIBCPP_BUILDING_LIBRARY) # define _LIBCPP_HAS_NO_INCOMPLETE_FORMAT -# define _LIBCPP_HAS_NO_INCOMPLETE_RANGES # endif // Need to detect which libc we're using if we're on Linux. @@ -416,17 +417,21 @@ If there are users of this configuration we are happy to provide support. # define _LIBCPP_NORETURN [[noreturn]] # define _NOEXCEPT noexcept # define _NOEXCEPT_(x) noexcept(x) +# define _LIBCPP_CONSTEXPR constexpr # else # define _LIBCPP_ALIGNOF(_Tp) _Alignof(_Tp) # define _ALIGNAS_TYPE(x) __attribute__((__aligned__(_LIBCPP_ALIGNOF(x)))) # define _ALIGNAS(x) __attribute__((__aligned__(x))) -# define _LIBCPP_NORETURN __attribute__((noreturn)) +# define _LIBCPP_NORETURN __attribute__((__noreturn__)) # define _LIBCPP_HAS_NO_NOEXCEPT # define nullptr __nullptr # define _NOEXCEPT throw() # define _NOEXCEPT_(x) +# define static_assert(...) _Static_assert(__VA_ARGS__) +# define decltype(...) __decltype(__VA_ARGS__) +# define _LIBCPP_CONSTEXPR typedef __char16_t char16_t; typedef __char32_t char32_t; @@ -485,27 +490,7 @@ typedef __char32_t char32_t; # define _LIBCPP_DISABLE_EXTENSION_WARNING __extension__ -# elif defined(_LIBCPP_COMPILER_MSVC) - -# define _LIBCPP_WARNING(x) __pragma(message(__FILE__ "(" _LIBCPP_TOSTRING(__LINE__) ") : warning note: " x)) - -# if _MSC_VER < 1900 -# error "MSVC versions prior to Visual Studio 2015 are not supported" -# endif - -# define _LIBCPP_NORETURN __declspec(noreturn) - -# define _LIBCPP_WEAK - -# define _LIBCPP_HAS_NO_ASAN - -# define _LIBCPP_ALWAYS_INLINE __forceinline - -# define _LIBCPP_HAS_NO_VECTOR_EXTENSION - -# define _LIBCPP_DISABLE_EXTENSION_WARNING - -# endif // _LIBCPP_COMPILER_[CLANG|GCC|MSVC] +# endif // _LIBCPP_COMPILER_[CLANG|GCC] # if defined(_LIBCPP_OBJECT_FORMAT_COFF) @@ -625,6 +610,15 @@ typedef __char32_t char32_t; // 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. +// // 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. @@ -635,6 +629,7 @@ typedef __char32_t char32_t; # 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 # ifdef _LIBCPP_BUILDING_LIBRARY # if _LIBCPP_ABI_VERSION > 1 @@ -678,31 +673,20 @@ _LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_END_NAMESPACE_STD # define _LIBCPP_HAS_NO_INT128 # endif -# ifdef _LIBCPP_CXX03_LANG -# define static_assert(...) _Static_assert(__VA_ARGS__) -# define decltype(...) __decltype(__VA_ARGS__) -# endif // _LIBCPP_CXX03_LANG - -# ifdef _LIBCPP_CXX03_LANG -# define _LIBCPP_CONSTEXPR -# else -# define _LIBCPP_CONSTEXPR constexpr -# endif - # ifndef __cpp_consteval # define _LIBCPP_CONSTEVAL _LIBCPP_CONSTEXPR # else # define _LIBCPP_CONSTEVAL consteval # endif -# ifdef __GNUC__ +# if __has_attribute(__malloc__) # define _LIBCPP_NOALIAS __attribute__((__malloc__)) # else # define _LIBCPP_NOALIAS # endif -# if __has_attribute(using_if_exists) -# define _LIBCPP_USING_IF_EXISTS __attribute__((using_if_exists)) +# if __has_attribute(__using_if_exists__) +# define _LIBCPP_USING_IF_EXISTS __attribute__((__using_if_exists__)) # else # define _LIBCPP_USING_IF_EXISTS # endif @@ -726,11 +710,11 @@ _LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_END_NAMESPACE_STD # endif // _LIBCPP_CXX03_LANG # if defined(__APPLE__) || defined(__FreeBSD__) || defined(_LIBCPP_MSVCRT_LIKE) || defined(__sun__) || \ - defined(__NetBSD__) || defined(__DragonFly__) + defined(__NetBSD__) # define _LIBCPP_LOCALE__L_EXTENSIONS 1 # endif -# if defined(__FreeBSD__) || defined(__DragonFly__) +# ifdef __FreeBSD__ # define _DECLARE_C99_LDBL_MATH 1 # endif @@ -750,11 +734,23 @@ _LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_END_NAMESPACE_STD # define _LIBCPP_HAS_NO_ALIGNED_ALLOCATION # endif -# if defined(__APPLE__) || defined(__FreeBSD__) || defined(__DragonFly__) +// It is not yet possible to use aligned_alloc() on all Apple platforms since +// 10.15 was the first version to ship an implementation of aligned_alloc(). +# if defined(__APPLE__) +# if (defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && \ + __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 101500) +# define _LIBCPP_HAS_NO_C11_ALIGNED_ALLOC +# endif +# elif defined(__ANDROID__) && __ANDROID_API__ < 28 +// Android only provides aligned_alloc when targeting API 28 or higher. +# define _LIBCPP_HAS_NO_C11_ALIGNED_ALLOC +# endif + +# if defined(__APPLE__) || defined(__FreeBSD__) # define _LIBCPP_HAS_DEFAULTRUNELOCALE # endif -# if defined(__APPLE__) || defined(__FreeBSD__) || defined(__sun__) || defined(__DragonFly__) +# if defined(__APPLE__) || defined(__FreeBSD__) || defined(__sun__) # define _LIBCPP_WCTYPE_IS_MASK # endif @@ -769,7 +765,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_END_NAMESPACE_STD # if !defined(_LIBCPP_DISABLE_DEPRECATION_WARNINGS) # if __has_attribute(deprecated) # define _LIBCPP_DEPRECATED __attribute__((deprecated)) -# define _LIBCPP_DEPRECATED_(m) __attribute__((deprected(m))) +# define _LIBCPP_DEPRECATED_(m) __attribute__((deprecated(m))) # elif _LIBCPP_STD_VER > 11 # define _LIBCPP_DEPRECATED [[deprecated]] # define _LIBCPP_DEPRECATED_(m) [[deprecated(m)]] @@ -806,6 +802,12 @@ _LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_END_NAMESPACE_STD # 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 !defined(_LIBCPP_HAS_NO_CHAR8_T) # define _LIBCPP_DEPRECATED_WITH_CHAR8_T _LIBCPP_DEPRECATED # else @@ -830,27 +832,31 @@ _LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_END_NAMESPACE_STD # endif # if _LIBCPP_STD_VER > 11 -# define _LIBCPP_CONSTEXPR_AFTER_CXX11 constexpr +# define _LIBCPP_CONSTEXPR_SINCE_CXX14 constexpr # else -# define _LIBCPP_CONSTEXPR_AFTER_CXX11 +# define _LIBCPP_CONSTEXPR_SINCE_CXX14 # endif # if _LIBCPP_STD_VER > 14 -# define _LIBCPP_CONSTEXPR_AFTER_CXX14 constexpr +# define _LIBCPP_CONSTEXPR_SINCE_CXX17 constexpr # else -# define _LIBCPP_CONSTEXPR_AFTER_CXX14 +# define _LIBCPP_CONSTEXPR_SINCE_CXX17 # endif # if _LIBCPP_STD_VER > 17 -# define _LIBCPP_CONSTEXPR_AFTER_CXX17 constexpr +# define _LIBCPP_CONSTEXPR_SINCE_CXX20 constexpr # else -# define _LIBCPP_CONSTEXPR_AFTER_CXX17 +# define _LIBCPP_CONSTEXPR_SINCE_CXX20 # endif -# if __has_cpp_attribute(nodiscard) || defined(_LIBCPP_COMPILER_MSVC) +# if _LIBCPP_STD_VER > 20 +# define _LIBCPP_CONSTEXPR_SINCE_CXX23 constexpr +# else +# define _LIBCPP_CONSTEXPR_SINCE_CXX23 +# endif + +# if __has_cpp_attribute(nodiscard) # define _LIBCPP_NODISCARD [[nodiscard]] -# elif defined(_LIBCPP_COMPILER_CLANG_BASED) && !defined(_LIBCPP_CXX03_LANG) -# define _LIBCPP_NODISCARD [[clang::warn_unused_result]] # else // We can't use GCC's [[gnu::warn_unused_result]] and // __attribute__((warn_unused_result)), because GCC does not silence them via @@ -860,19 +866,19 @@ _LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_END_NAMESPACE_STD // _LIBCPP_NODISCARD_EXT may be used to apply [[nodiscard]] to entities not // specified as such as an extension. -# if defined(_LIBCPP_ENABLE_NODISCARD) && !defined(_LIBCPP_DISABLE_NODISCARD_EXT) +# if !defined(_LIBCPP_DISABLE_NODISCARD_EXT) # define _LIBCPP_NODISCARD_EXT _LIBCPP_NODISCARD # else # define _LIBCPP_NODISCARD_EXT # endif -# if !defined(_LIBCPP_DISABLE_NODISCARD_AFTER_CXX17) && (_LIBCPP_STD_VER > 17 || defined(_LIBCPP_ENABLE_NODISCARD)) +# if _LIBCPP_STD_VER > 17 || !defined(_LIBCPP_DISABLE_NODISCARD_EXT) # define _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_NODISCARD # else # define _LIBCPP_NODISCARD_AFTER_CXX17 # endif -# if __has_attribute(no_destroy) +# if __has_attribute(__no_destroy__) # define _LIBCPP_NO_DESTROY __attribute__((__no_destroy__)) # else # define _LIBCPP_NO_DESTROY @@ -901,7 +907,6 @@ _LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_END_NAMESPACE_STD # if defined(__FreeBSD__) || \ defined(__wasi__) || \ - defined(__DragonFly__) || \ defined(__NetBSD__) || \ defined(__OpenBSD__) || \ defined(__NuttX__) || \ @@ -1035,18 +1040,16 @@ _LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_END_NAMESPACE_STD # if _LIBCPP_STD_VER > 17 # define _LIBCPP_CONSTINIT constinit -# elif __has_attribute(require_constant_initialization) +# elif __has_attribute(__require_constant_initialization__) # define _LIBCPP_CONSTINIT __attribute__((__require_constant_initialization__)) # else # define _LIBCPP_CONSTINIT # endif -# if __has_attribute(diagnose_if) && !defined(_LIBCPP_DISABLE_ADDITIONAL_DIAGNOSTICS) -# define _LIBCPP_DIAGNOSE_WARNING(...) __attribute__((diagnose_if(__VA_ARGS__, "warning"))) -# define _LIBCPP_DIAGNOSE_ERROR(...) __attribute__((diagnose_if(__VA_ARGS__, "error"))) +# if __has_attribute(__diagnose_if__) && !defined(_LIBCPP_DISABLE_ADDITIONAL_DIAGNOSTICS) +# define _LIBCPP_DIAGNOSE_WARNING(...) __attribute__((__diagnose_if__(__VA_ARGS__, "warning"))) # else # define _LIBCPP_DIAGNOSE_WARNING(...) -# define _LIBCPP_DIAGNOSE_ERROR(...) # endif // Use a function like macro to imply that it must be followed by a semicolon @@ -1058,6 +1061,12 @@ _LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_END_NAMESPACE_STD # define _LIBCPP_FALLTHROUGH() ((void)0) # endif +# if __has_cpp_attribute(_Clang::__lifetimebound__) +# define _LIBCPP_LIFETIMEBOUND [[_Clang::__lifetimebound__]] +# else +# define _LIBCPP_LIFETIMEBOUND +# endif + # if __has_attribute(__nodebug__) # define _LIBCPP_NODEBUG __attribute__((__nodebug__)) # else @@ -1086,7 +1095,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_END_NAMESPACE_STD # define _LIBCPP_IF_WIDE_CHARACTERS(...) __VA_ARGS__ # endif -# if defined(_LIBCPP_ABI_MICROSOFT) && (defined(_LIBCPP_COMPILER_MSVC) || __has_declspec_attribute(empty_bases)) +# if defined(_LIBCPP_ABI_MICROSOFT) && __has_declspec_attribute(empty_bases) # define _LIBCPP_DECLSPEC_EMPTY_BASES __declspec(empty_bases) # else # define _LIBCPP_DECLSPEC_EMPTY_BASES @@ -1100,13 +1109,6 @@ _LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_END_NAMESPACE_STD # define _LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION # endif // _LIBCPP_ENABLE_CXX17_REMOVED_FEATURES -// Leave the deprecation notices in by default, but don't remove unary_function and -// binary_function entirely just yet. That way, folks will have one release to act -// on the deprecation warnings. -# ifndef _LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION -# define _LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION -# endif - # if defined(_LIBCPP_ENABLE_CXX20_REMOVED_FEATURES) # define _LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS # define _LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_VOID_SPECIALIZATION @@ -1116,10 +1118,6 @@ _LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_END_NAMESPACE_STD # define _LIBCPP_ENABLE_CXX20_REMOVED_TYPE_TRAITS # endif // _LIBCPP_ENABLE_CXX20_REMOVED_FEATURES -# if !defined(__cpp_impl_coroutine) || __cpp_impl_coroutine < 201902L -# define _LIBCPP_HAS_NO_CXX20_COROUTINES -# endif - # define _LIBCPP_PUSH_MACROS _Pragma("push_macro(\"min\")") _Pragma("push_macro(\"max\")") # define _LIBCPP_POP_MACROS _Pragma("pop_macro(\"min\")") _Pragma("pop_macro(\"max\")") @@ -1151,19 +1149,13 @@ _LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_END_NAMESPACE_STD # define _LIBCPP_HAS_NO_FGETPOS_FSETPOS # endif -# if __has_attribute(init_priority) -// TODO: Remove this once we drop support for building libc++ with old Clangs -# if (defined(_LIBCPP_CLANG_VER) && _LIBCPP_CLANG_VER < 1200) || \ - (defined(__apple_build_version__) && __apple_build_version__ < 13000000) -# define _LIBCPP_INIT_PRIORITY_MAX __attribute__((init_priority(101))) -# else -# define _LIBCPP_INIT_PRIORITY_MAX __attribute__((init_priority(100))) -# endif +# if __has_attribute(__init_priority__) +# define _LIBCPP_INIT_PRIORITY_MAX __attribute__((__init_priority__(100))) # else # define _LIBCPP_INIT_PRIORITY_MAX # endif -# if defined(__GNUC__) || defined(__clang__) +# if __has_attribute(__format__) // The attribute uses 1-based indices for ordinary and static member functions. // The attribute uses 2-based indices for non-static member functions. # define _LIBCPP_ATTRIBUTE_FORMAT(archetype, format_string_index, first_format_arg_index) \ @@ -1225,6 +1217,35 @@ _LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_END_NAMESPACE_STD # define _LIBCPP_PACKED # 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 +// functions are declared by the C library. +# define _LIBCPP_HAS_NO_C8RTOMB_MBRTOC8 +// GNU libc 2.36 and newer declare c8rtomb() and mbrtoc8() in C++ modes if +// __cpp_char8_t is defined or if C2X extensions are enabled. Unfortunately, +// determining the latter depends on internal GNU libc details. If the +// __cpp_char8_t feature test macro is not defined, then a char8_t typedef +// will be declared as well. +# if defined(_LIBCPP_GLIBC_PREREQ) && defined(__GLIBC_USE) +# if _LIBCPP_GLIBC_PREREQ(2, 36) && (defined(__cpp_char8_t) || __GLIBC_USE(ISOC2X)) +# undef _LIBCPP_HAS_NO_C8RTOMB_MBRTOC8 +# endif +# endif + +// There are a handful of public standard library types that are intended to +// support CTAD but don't need any explicit deduction guides to do so. This +// macro is used to mark them as such, which suppresses the +// '-Wctad-maybe-unsupported' compiler warning when CTAD is used in user code +// with these classes. +#if _LIBCPP_STD_VER >= 17 +# define _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(_ClassName) \ + template \ + _ClassName(typename _Tag::__allow_ctad...) -> _ClassName<_Tag...> +#else +# define _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(_ClassName) static_assert(true, "") +#endif + #endif // __cplusplus #endif // _LIBCPP___CONFIG diff --git a/lib/libcxx/include/__coroutine/coroutine_handle.h b/lib/libcxx/include/__coroutine/coroutine_handle.h index 4bf3237892..0a6cc1cab6 100644 --- a/lib/libcxx/include/__coroutine/coroutine_handle.h +++ b/lib/libcxx/include/__coroutine/coroutine_handle.h @@ -13,14 +13,15 @@ #include <__config> #include <__functional/hash.h> #include <__memory/addressof.h> +#include <__type_traits/remove_cv.h> #include -#include +#include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header #endif -#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_CXX20_COROUTINES) +#if _LIBCPP_STD_VER > 17 _LIBCPP_BEGIN_NAMESPACE_STD @@ -115,7 +116,7 @@ public: _LIBCPP_HIDE_FROM_ABI static coroutine_handle from_promise(_Promise& __promise) { - using _RawPromise = typename remove_cv<_Promise>::type; + using _RawPromise = __remove_cv_t<_Promise>; coroutine_handle __tmp; __tmp.__handle_ = __builtin_coro_promise(_VSTD::addressof(const_cast<_RawPromise&>(__promise)), alignof(_Promise), true); @@ -197,6 +198,6 @@ struct hash> { _LIBCPP_END_NAMESPACE_STD -#endif // __LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_CXX20_COROUTINES) +#endif // __LIBCPP_STD_VER > 17 #endif // _LIBCPP___COROUTINE_COROUTINE_HANDLE_H diff --git a/lib/libcxx/include/__coroutine/coroutine_traits.h b/lib/libcxx/include/__coroutine/coroutine_traits.h index 0a5229b459..d513075098 100644 --- a/lib/libcxx/include/__coroutine/coroutine_traits.h +++ b/lib/libcxx/include/__coroutine/coroutine_traits.h @@ -10,13 +10,13 @@ #define _LIBCPP___COROUTINE_COROUTINE_TRAITS_H #include <__config> -#include +#include <__type_traits/void_t.h> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header #endif -#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_CXX20_COROUTINES) +#if _LIBCPP_STD_VER > 17 _LIBCPP_BEGIN_NAMESPACE_STD @@ -35,7 +35,7 @@ struct __coroutine_traits_sfinae {}; template struct __coroutine_traits_sfinae< - _Tp, typename __void_t::type> + _Tp, __void_t > { using promise_type = typename _Tp::promise_type; }; @@ -48,6 +48,6 @@ struct coroutine_traits _LIBCPP_END_NAMESPACE_STD -#endif // __LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_CXX20_COROUTINES) +#endif // __LIBCPP_STD_VER > 17 #endif // _LIBCPP___COROUTINE_COROUTINE_TRAITS_H diff --git a/lib/libcxx/include/__coroutine/noop_coroutine_handle.h b/lib/libcxx/include/__coroutine/noop_coroutine_handle.h index 7a2c672057..299304794c 100644 --- a/lib/libcxx/include/__coroutine/noop_coroutine_handle.h +++ b/lib/libcxx/include/__coroutine/noop_coroutine_handle.h @@ -16,7 +16,7 @@ # pragma GCC system_header #endif -#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_CXX20_COROUTINES) +#if _LIBCPP_STD_VER > 17 _LIBCPP_BEGIN_NAMESPACE_STD @@ -107,6 +107,6 @@ noop_coroutine_handle noop_coroutine() noexcept { return noop_coroutine_handle() _LIBCPP_END_NAMESPACE_STD -#endif // __LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_CXX20_COROUTINES) +#endif // __LIBCPP_STD_VER > 17 #endif // _LIBCPP___COROUTINE_NOOP_COROUTINE_HANDLE_H diff --git a/lib/libcxx/include/__coroutine/trivial_awaitables.h b/lib/libcxx/include/__coroutine/trivial_awaitables.h index 31399ab29a..bbbae7a47f 100644 --- a/lib/libcxx/include/__coroutine/trivial_awaitables.h +++ b/lib/libcxx/include/__coroutine/trivial_awaitables.h @@ -16,7 +16,7 @@ # pragma GCC system_header #endif -#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_CXX20_COROUTINES) +#if _LIBCPP_STD_VER > 17 _LIBCPP_BEGIN_NAMESPACE_STD @@ -41,6 +41,6 @@ struct suspend_always { _LIBCPP_END_NAMESPACE_STD -#endif // __LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_CXX20_COROUTINES) +#endif // __LIBCPP_STD_VER > 17 #endif // __LIBCPP___COROUTINE_TRIVIAL_AWAITABLES_H diff --git a/lib/libcxx/include/__debug b/lib/libcxx/include/__debug index 59e85cb7d1..140cc9142a 100644 --- a/lib/libcxx/include/__debug +++ b/lib/libcxx/include/__debug @@ -12,22 +12,21 @@ #include <__assert> #include <__config> +#include <__type_traits/is_constant_evaluated.h> #include -#include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header #endif -// Catch invalid uses of the legacy _LIBCPP_DEBUG toggle. -#if defined(_LIBCPP_DEBUG) && _LIBCPP_DEBUG != 0 && !defined(_LIBCPP_ENABLE_DEBUG_MODE) -# error "Enabling the debug mode now requires having configured the library with support for the debug mode" -#endif - #if defined(_LIBCPP_ENABLE_DEBUG_MODE) && !defined(_LIBCPP_CXX03_LANG) && !defined(_LIBCPP_DEBUG_RANDOMIZE_UNSPECIFIED_STABILITY) # define _LIBCPP_DEBUG_RANDOMIZE_UNSPECIFIED_STABILITY #endif +#if defined(_LIBCPP_ENABLE_DEBUG_MODE) && !defined(_LIBCPP_DEBUG_ITERATOR_BOUNDS_CHECKING) +# define _LIBCPP_DEBUG_ITERATOR_BOUNDS_CHECKING +#endif + #ifdef _LIBCPP_ENABLE_DEBUG_MODE # define _LIBCPP_DEBUG_ASSERT(x, m) _LIBCPP_ASSERT(::std::__libcpp_is_constant_evaluated() || (x), m) #else @@ -87,10 +86,10 @@ struct _C_node explicit _C_node(void* __c, __c_node* __n) : __c_node(__c, __n) {} - virtual bool __dereferenceable(const void*) const; - virtual bool __decrementable(const void*) const; - virtual bool __addable(const void*, ptrdiff_t) const; - virtual bool __subscriptable(const void*, ptrdiff_t) const; + bool __dereferenceable(const void*) const override; + bool __decrementable(const void*) const override; + bool __addable(const void*, ptrdiff_t) const override; + bool __subscriptable(const void*, ptrdiff_t) const override; }; template @@ -212,7 +211,7 @@ _LIBCPP_END_NAMESPACE_STD _LIBCPP_BEGIN_NAMESPACE_STD template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 inline void __debug_db_insert_c(_Tp* __c) { +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 inline void __debug_db_insert_c(_Tp* __c) { #ifdef _LIBCPP_ENABLE_DEBUG_MODE if (!__libcpp_is_constant_evaluated()) __get_db()->__insert_c(__c); @@ -222,7 +221,7 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 inline void __debug_db_inser } template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 inline void __debug_db_insert_i(_Tp* __i) { +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 inline void __debug_db_insert_i(_Tp* __i) { #ifdef _LIBCPP_ENABLE_DEBUG_MODE if (!__libcpp_is_constant_evaluated()) __get_db()->__insert_i(__i); @@ -232,7 +231,7 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 inline void __debug_db_inser } template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 inline void __debug_db_erase_c(_Tp* __c) { +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 inline void __debug_db_erase_c(_Tp* __c) { #ifdef _LIBCPP_ENABLE_DEBUG_MODE if (!__libcpp_is_constant_evaluated()) __get_db()->__erase_c(__c); @@ -242,7 +241,7 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 inline void __debug_db_erase } template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 inline void __debug_db_swap(_Tp* __lhs, _Tp* __rhs) { +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 inline void __debug_db_swap(_Tp* __lhs, _Tp* __rhs) { #ifdef _LIBCPP_ENABLE_DEBUG_MODE if (!__libcpp_is_constant_evaluated()) __get_db()->swap(__lhs, __rhs); @@ -253,7 +252,7 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 inline void __debug_db_swap( } template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 inline void __debug_db_invalidate_all(_Tp* __c) { +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 inline void __debug_db_invalidate_all(_Tp* __c) { #ifdef _LIBCPP_ENABLE_DEBUG_MODE if (!__libcpp_is_constant_evaluated()) __get_db()->__invalidate_all(__c); diff --git a/lib/libcxx/include/__debug_utils/randomize_range.h b/lib/libcxx/include/__debug_utils/randomize_range.h index 9843709019..dce61923bc 100644 --- a/lib/libcxx/include/__debug_utils/randomize_range.h +++ b/lib/libcxx/include/__debug_utils/randomize_range.h @@ -23,7 +23,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void __debug_randomize_range(_Iterator __first, _Sentinel __last) { #ifdef _LIBCPP_DEBUG_RANDOMIZE_UNSPECIFIED_STABILITY # ifdef _LIBCPP_CXX03_LANG diff --git a/lib/libcxx/include/__expected/bad_expected_access.h b/lib/libcxx/include/__expected/bad_expected_access.h new file mode 100644 index 0000000000..361eab4b60 --- /dev/null +++ b/lib/libcxx/include/__expected/bad_expected_access.h @@ -0,0 +1,64 @@ +// -*- 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___EXPECTED_BAD_EXPECTED_ACCESS_H +#define _LIBCPP___EXPECTED_BAD_EXPECTED_ACCESS_H + +#include <__config> +#include <__utility/move.h> + +#include + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +#if _LIBCPP_STD_VER >= 23 + +_LIBCPP_BEGIN_NAMESPACE_STD + +template +class bad_expected_access; + +template <> +class bad_expected_access : public exception { +protected: + _LIBCPP_HIDE_FROM_ABI bad_expected_access() noexcept = default; + _LIBCPP_HIDE_FROM_ABI bad_expected_access(const bad_expected_access&) = default; + _LIBCPP_HIDE_FROM_ABI bad_expected_access(bad_expected_access&&) = default; + _LIBCPP_HIDE_FROM_ABI bad_expected_access& operator=(const bad_expected_access&) = default; + _LIBCPP_HIDE_FROM_ABI bad_expected_access& operator=(bad_expected_access&&) = default; + ~bad_expected_access() override = default; + +public: + // The way this has been designed (by using a class template below) means that we'll already + // have a profusion of these vtables in TUs, and the dynamic linker will already have a bunch + // of work to do. So it is not worth hiding the specialization in the dylib, given that + // it adds deployment target restrictions. + const char* what() const noexcept override { return "bad access to std::expected"; } +}; + +template +class bad_expected_access : public bad_expected_access { +public: + _LIBCPP_HIDE_FROM_ABI explicit bad_expected_access(_Err __e) : __unex_(std::move(__e)) {} + + _LIBCPP_HIDE_FROM_ABI _Err& error() & noexcept { return __unex_; } + _LIBCPP_HIDE_FROM_ABI const _Err& error() const& noexcept { return __unex_; } + _LIBCPP_HIDE_FROM_ABI _Err&& error() && noexcept { return std::move(__unex_); } + _LIBCPP_HIDE_FROM_ABI const _Err&& error() const&& noexcept { return std::move(__unex_); } + +private: + _Err __unex_; +}; + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_STD_VER >= 23 + +#endif // _LIBCPP___EXPECTED_BAD_EXPECTED_ACCESS_H diff --git a/lib/libcxx/include/__expected/expected.h b/lib/libcxx/include/__expected/expected.h new file mode 100644 index 0000000000..e1f590c65e --- /dev/null +++ b/lib/libcxx/include/__expected/expected.h @@ -0,0 +1,973 @@ +// -*- 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___EXPECTED_EXPECTED_H +#define _LIBCPP___EXPECTED_EXPECTED_H + +#include <__assert> +#include <__config> +#include <__expected/bad_expected_access.h> +#include <__expected/unexpect.h> +#include <__expected/unexpected.h> +#include <__memory/addressof.h> +#include <__memory/construct_at.h> +#include <__type_traits/conjunction.h> +#include <__type_traits/disjunction.h> +#include <__type_traits/is_assignable.h> +#include <__type_traits/is_constructible.h> +#include <__type_traits/is_convertible.h> +#include <__type_traits/is_copy_assignable.h> +#include <__type_traits/is_copy_constructible.h> +#include <__type_traits/is_default_constructible.h> +#include <__type_traits/is_function.h> +#include <__type_traits/is_move_assignable.h> +#include <__type_traits/is_move_constructible.h> +#include <__type_traits/is_nothrow_constructible.h> +#include <__type_traits/is_nothrow_copy_assignable.h> +#include <__type_traits/is_nothrow_copy_constructible.h> +#include <__type_traits/is_nothrow_default_constructible.h> +#include <__type_traits/is_nothrow_move_assignable.h> +#include <__type_traits/is_nothrow_move_constructible.h> +#include <__type_traits/is_reference.h> +#include <__type_traits/is_same.h> +#include <__type_traits/is_swappable.h> +#include <__type_traits/is_trivially_copy_constructible.h> +#include <__type_traits/is_trivially_destructible.h> +#include <__type_traits/is_trivially_move_constructible.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> +#include <__utility/exception_guard.h> +#include <__utility/forward.h> +#include <__utility/in_place.h> +#include <__utility/move.h> +#include <__utility/swap.h> +#include // for std::abort +#include + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +#if _LIBCPP_STD_VER >= 23 + +_LIBCPP_BEGIN_NAMESPACE_STD + +namespace __expected { + +template +_LIBCPP_HIDE_FROM_ABI void __throw_bad_expected_access(_Arg&& __arg) { +# ifndef _LIBCPP_NO_EXCEPTIONS + throw bad_expected_access<_Err>(std::forward<_Arg>(__arg)); +# else + (void)__arg; + std::abort(); +# endif +} + +} // namespace __expected + +template +class expected { + static_assert( + !is_reference_v<_Tp> && + !is_function_v<_Tp> && + !is_same_v, in_place_t> && + !is_same_v, unexpect_t> && + !__is_std_unexpected>::value && + __valid_std_unexpected<_Err>::value + , + "[expected.object.general] A program that instantiates the definition of template expected for a " + "reference type, a function type, or for possibly cv-qualified types in_place_t, unexpect_t, or a " + "specialization of unexpected for the T parameter is ill-formed. A program that instantiates the " + "definition of the template expected with a type for the E parameter that is not a valid " + "template argument for unexpected is ill-formed."); + + template + friend class expected; + +public: + using value_type = _Tp; + using error_type = _Err; + using unexpected_type = unexpected<_Err>; + + template + using rebind = expected<_Up, error_type>; + + // [expected.object.ctor], constructors + _LIBCPP_HIDE_FROM_ABI constexpr expected() + noexcept(is_nothrow_default_constructible_v<_Tp>) // strengthened + requires is_default_constructible_v<_Tp> + : __has_val_(true) { + std::construct_at(std::addressof(__union_.__val_)); + } + + _LIBCPP_HIDE_FROM_ABI constexpr expected(const expected&) = delete; + + _LIBCPP_HIDE_FROM_ABI constexpr expected(const expected&) + requires(is_copy_constructible_v<_Tp> && + is_copy_constructible_v<_Err> && + is_trivially_copy_constructible_v<_Tp> && + is_trivially_copy_constructible_v<_Err>) + = default; + + _LIBCPP_HIDE_FROM_ABI constexpr expected(const expected& __other) + noexcept(is_nothrow_copy_constructible_v<_Tp> && is_nothrow_copy_constructible_v<_Err>) // strengthened + requires(is_copy_constructible_v<_Tp> && is_copy_constructible_v<_Err> && + !(is_trivially_copy_constructible_v<_Tp> && is_trivially_copy_constructible_v<_Err>)) + : __has_val_(__other.__has_val_) { + if (__has_val_) { + std::construct_at(std::addressof(__union_.__val_), __other.__union_.__val_); + } else { + std::construct_at(std::addressof(__union_.__unex_), __other.__union_.__unex_); + } + } + + + _LIBCPP_HIDE_FROM_ABI constexpr expected(expected&&) + requires(is_move_constructible_v<_Tp> && is_move_constructible_v<_Err> + && is_trivially_move_constructible_v<_Tp> && is_trivially_move_constructible_v<_Err>) + = default; + + _LIBCPP_HIDE_FROM_ABI constexpr expected(expected&& __other) + noexcept(is_nothrow_move_constructible_v<_Tp> && is_nothrow_move_constructible_v<_Err>) + requires(is_move_constructible_v<_Tp> && is_move_constructible_v<_Err> && + !(is_trivially_move_constructible_v<_Tp> && is_trivially_move_constructible_v<_Err>)) + : __has_val_(__other.__has_val_) { + if (__has_val_) { + std::construct_at(std::addressof(__union_.__val_), std::move(__other.__union_.__val_)); + } else { + std::construct_at(std::addressof(__union_.__unex_), std::move(__other.__union_.__unex_)); + } + } + +private: + template + using __can_convert = + _And< is_constructible<_Tp, _UfQual>, + is_constructible<_Err, _OtherErrQual>, + _Not&>>, + _Not>>, + _Not&>>, + _Not>>, + _Not&, _Tp>>, + _Not&&, _Tp>>, + _Not&, _Tp>>, + _Not&&, _Tp>>, + _Not, expected<_Up, _OtherErr>&>>, + _Not, expected<_Up, _OtherErr>>>, + _Not, const expected<_Up, _OtherErr>&>>, + _Not, const expected<_Up, _OtherErr>>> >; + + +public: + template + requires __can_convert<_Up, _OtherErr, const _Up&, const _OtherErr&>::value + _LIBCPP_HIDE_FROM_ABI constexpr explicit(!is_convertible_v || + !is_convertible_v) + expected(const expected<_Up, _OtherErr>& __other) + noexcept(is_nothrow_constructible_v<_Tp, const _Up&> && + is_nothrow_constructible_v<_Err, const _OtherErr&>) // strengthened + : __has_val_(__other.__has_val_) { + if (__has_val_) { + std::construct_at(std::addressof(__union_.__val_), __other.__union_.__val_); + } else { + std::construct_at(std::addressof(__union_.__unex_), __other.__union_.__unex_); + } + } + + template + requires __can_convert<_Up, _OtherErr, _Up, _OtherErr>::value + _LIBCPP_HIDE_FROM_ABI constexpr explicit(!is_convertible_v<_Up, _Tp> || !is_convertible_v<_OtherErr, _Err>) + expected(expected<_Up, _OtherErr>&& __other) + noexcept(is_nothrow_constructible_v<_Tp, _Up> && is_nothrow_constructible_v<_Err, _OtherErr>) // strengthened + : __has_val_(__other.__has_val_) { + if (__has_val_) { + std::construct_at(std::addressof(__union_.__val_), std::move(__other.__union_.__val_)); + } else { + std::construct_at(std::addressof(__union_.__unex_), std::move(__other.__union_.__unex_)); + } + } + + template + requires(!is_same_v, in_place_t> && !is_same_v> && + !__is_std_unexpected>::value && is_constructible_v<_Tp, _Up>) + _LIBCPP_HIDE_FROM_ABI constexpr explicit(!is_convertible_v<_Up, _Tp>) + expected(_Up&& __u) + noexcept(is_nothrow_constructible_v<_Tp, _Up>) // strengthened + : __has_val_(true) { + std::construct_at(std::addressof(__union_.__val_), std::forward<_Up>(__u)); + } + + + template + requires is_constructible_v<_Err, const _OtherErr&> + _LIBCPP_HIDE_FROM_ABI constexpr explicit(!is_convertible_v) + expected(const unexpected<_OtherErr>& __unex) + noexcept(is_nothrow_constructible_v<_Err, const _OtherErr&>) // strengthened + : __has_val_(false) { + std::construct_at(std::addressof(__union_.__unex_), __unex.error()); + } + + template + requires is_constructible_v<_Err, _OtherErr> + _LIBCPP_HIDE_FROM_ABI constexpr explicit(!is_convertible_v<_OtherErr, _Err>) + expected(unexpected<_OtherErr>&& __unex) + noexcept(is_nothrow_constructible_v<_Err, _OtherErr>) // strengthened + : __has_val_(false) { + std::construct_at(std::addressof(__union_.__unex_), std::move(__unex.error())); + } + + template + requires is_constructible_v<_Tp, _Args...> + _LIBCPP_HIDE_FROM_ABI constexpr explicit expected(in_place_t, _Args&&... __args) + noexcept(is_nothrow_constructible_v<_Tp, _Args...>) // strengthened + : __has_val_(true) { + std::construct_at(std::addressof(__union_.__val_), std::forward<_Args>(__args)...); + } + + template + requires is_constructible_v< _Tp, initializer_list<_Up>&, _Args... > + _LIBCPP_HIDE_FROM_ABI constexpr explicit + expected(in_place_t, initializer_list<_Up> __il, _Args&&... __args) + noexcept(is_nothrow_constructible_v<_Tp, initializer_list<_Up>&, _Args...>) // strengthened + : __has_val_(true) { + std::construct_at(std::addressof(__union_.__val_), __il, std::forward<_Args>(__args)...); + } + + template + requires is_constructible_v<_Err, _Args...> + _LIBCPP_HIDE_FROM_ABI constexpr explicit expected(unexpect_t, _Args&&... __args) + noexcept(is_nothrow_constructible_v<_Err, _Args...>) // strengthened + : __has_val_(false) { + std::construct_at(std::addressof(__union_.__unex_), std::forward<_Args>(__args)...); + } + + template + requires is_constructible_v< _Err, initializer_list<_Up>&, _Args... > + _LIBCPP_HIDE_FROM_ABI constexpr explicit + expected(unexpect_t, initializer_list<_Up> __il, _Args&&... __args) + noexcept(is_nothrow_constructible_v<_Err, initializer_list<_Up>&, _Args...>) // strengthened + : __has_val_(false) { + std::construct_at(std::addressof(__union_.__unex_), __il, std::forward<_Args>(__args)...); + } + + // [expected.object.dtor], destructor + + _LIBCPP_HIDE_FROM_ABI constexpr ~expected() + requires(is_trivially_destructible_v<_Tp> && is_trivially_destructible_v<_Err>) + = default; + + _LIBCPP_HIDE_FROM_ABI constexpr ~expected() + requires(!is_trivially_destructible_v<_Tp> || !is_trivially_destructible_v<_Err>) + { + if (__has_val_) { + std::destroy_at(std::addressof(__union_.__val_)); + } else { + std::destroy_at(std::addressof(__union_.__unex_)); + } + } + +private: + template + _LIBCPP_HIDE_FROM_ABI static constexpr void __reinit_expected(_T1& __newval, _T2& __oldval, _Args&&... __args) { + if constexpr (is_nothrow_constructible_v<_T1, _Args...>) { + std::destroy_at(std::addressof(__oldval)); + std::construct_at(std::addressof(__newval), std::forward<_Args>(__args)...); + } else if constexpr (is_nothrow_move_constructible_v<_T1>) { + _T1 __tmp(std::forward<_Args>(__args)...); + std::destroy_at(std::addressof(__oldval)); + std::construct_at(std::addressof(__newval), std::move(__tmp)); + } else { + static_assert( + is_nothrow_move_constructible_v<_T2>, + "To provide strong exception guarantee, T2 has to satisfy `is_nothrow_move_constructible_v` so that it can " + "be reverted to the previous state in case an exception is thrown during the assignment."); + _T2 __tmp(std::move(__oldval)); + std::destroy_at(std::addressof(__oldval)); + __exception_guard __trans([&] { std::construct_at(std::addressof(__oldval), std::move(__tmp)); }); + std::construct_at(std::addressof(__newval), std::forward<_Args>(__args)...); + __trans.__complete(); + } + } + +public: + // [expected.object.assign], assignment + _LIBCPP_HIDE_FROM_ABI constexpr expected& operator=(const expected&) = delete; + + _LIBCPP_HIDE_FROM_ABI constexpr expected& operator=(const expected& __rhs) + noexcept(is_nothrow_copy_assignable_v<_Tp> && + is_nothrow_copy_constructible_v<_Tp> && + is_nothrow_copy_assignable_v<_Err> && + is_nothrow_copy_constructible_v<_Err>) // strengthened + requires(is_copy_assignable_v<_Tp> && + is_copy_constructible_v<_Tp> && + is_copy_assignable_v<_Err> && + is_copy_constructible_v<_Err> && + (is_nothrow_move_constructible_v<_Tp> || + is_nothrow_move_constructible_v<_Err>)) + { + if (__has_val_ && __rhs.__has_val_) { + __union_.__val_ = __rhs.__union_.__val_; + } else if (__has_val_) { + __reinit_expected(__union_.__unex_, __union_.__val_, __rhs.__union_.__unex_); + } else if (__rhs.__has_val_) { + __reinit_expected(__union_.__val_, __union_.__unex_, __rhs.__union_.__val_); + } else { + __union_.__unex_ = __rhs.__union_.__unex_; + } + // note: only reached if no exception+rollback was done inside __reinit_expected + __has_val_ = __rhs.__has_val_; + return *this; + } + + _LIBCPP_HIDE_FROM_ABI constexpr expected& operator=(expected&& __rhs) + noexcept(is_nothrow_move_assignable_v<_Tp> && + is_nothrow_move_constructible_v<_Tp> && + is_nothrow_move_assignable_v<_Err> && + is_nothrow_move_constructible_v<_Err>) + requires(is_move_constructible_v<_Tp> && + is_move_assignable_v<_Tp> && + is_move_constructible_v<_Err> && + is_move_assignable_v<_Err> && + (is_nothrow_move_constructible_v<_Tp> || + is_nothrow_move_constructible_v<_Err>)) + { + if (__has_val_ && __rhs.__has_val_) { + __union_.__val_ = std::move(__rhs.__union_.__val_); + } else if (__has_val_) { + __reinit_expected(__union_.__unex_, __union_.__val_, std::move(__rhs.__union_.__unex_)); + } else if (__rhs.__has_val_) { + __reinit_expected(__union_.__val_, __union_.__unex_, std::move(__rhs.__union_.__val_)); + } else { + __union_.__unex_ = std::move(__rhs.__union_.__unex_); + } + // note: only reached if no exception+rollback was done inside __reinit_expected + __has_val_ = __rhs.__has_val_; + return *this; + } + + template + _LIBCPP_HIDE_FROM_ABI constexpr expected& operator=(_Up&& __v) + requires(!is_same_v> && + !__is_std_unexpected>::value && + is_constructible_v<_Tp, _Up> && + is_assignable_v<_Tp&, _Up> && + (is_nothrow_constructible_v<_Tp, _Up> || + is_nothrow_move_constructible_v<_Tp> || + is_nothrow_move_constructible_v<_Err>)) + { + if (__has_val_) { + __union_.__val_ = std::forward<_Up>(__v); + } else { + __reinit_expected(__union_.__val_, __union_.__unex_, std::forward<_Up>(__v)); + __has_val_ = true; + } + return *this; + } + +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; + +public: + template + requires(__can_assign_from_unexpected) + _LIBCPP_HIDE_FROM_ABI constexpr expected& operator=(const unexpected<_OtherErr>& __un) { + if (__has_val_) { + __reinit_expected(__union_.__unex_, __union_.__val_, __un.error()); + __has_val_ = false; + } else { + __union_.__unex_ = __un.error(); + } + return *this; + } + + template + requires(__can_assign_from_unexpected<_OtherErr>) + _LIBCPP_HIDE_FROM_ABI constexpr expected& operator=(unexpected<_OtherErr>&& __un) { + if (__has_val_) { + __reinit_expected(__union_.__unex_, __union_.__val_, std::move(__un.error())); + __has_val_ = false; + } else { + __union_.__unex_ = std::move(__un.error()); + } + return *this; + } + + template + requires is_nothrow_constructible_v<_Tp, _Args...> + _LIBCPP_HIDE_FROM_ABI constexpr _Tp& emplace(_Args&&... __args) noexcept { + if (__has_val_) { + std::destroy_at(std::addressof(__union_.__val_)); + } else { + std::destroy_at(std::addressof(__union_.__unex_)); + __has_val_ = true; + } + return *std::construct_at(std::addressof(__union_.__val_), std::forward<_Args>(__args)...); + } + + template + requires is_nothrow_constructible_v< _Tp, initializer_list<_Up>&, _Args... > + _LIBCPP_HIDE_FROM_ABI constexpr _Tp& emplace(initializer_list<_Up> __il, _Args&&... __args) noexcept { + if (__has_val_) { + std::destroy_at(std::addressof(__union_.__val_)); + } else { + std::destroy_at(std::addressof(__union_.__unex_)); + __has_val_ = true; + } + return *std::construct_at(std::addressof(__union_.__val_), __il, std::forward<_Args>(__args)...); + } + + +public: + // [expected.object.swap], swap + _LIBCPP_HIDE_FROM_ABI constexpr void swap(expected& __rhs) + noexcept(is_nothrow_move_constructible_v<_Tp> && + is_nothrow_swappable_v<_Tp> && + is_nothrow_move_constructible_v<_Err> && + is_nothrow_swappable_v<_Err>) + requires(is_swappable_v<_Tp> && + is_swappable_v<_Err> && + is_move_constructible_v<_Tp> && + is_move_constructible_v<_Err> && + (is_nothrow_move_constructible_v<_Tp> || + is_nothrow_move_constructible_v<_Err>)) + { + auto __swap_val_unex_impl = [&](expected& __with_val, expected& __with_err) { + if constexpr (is_nothrow_move_constructible_v<_Err>) { + _Err __tmp(std::move(__with_err.__union_.__unex_)); + std::destroy_at(std::addressof(__with_err.__union_.__unex_)); + __exception_guard __trans([&] { + std::construct_at(std::addressof(__with_err.__union_.__unex_), std::move(__tmp)); + }); + std::construct_at(std::addressof(__with_err.__union_.__val_), std::move(__with_val.__union_.__val_)); + __trans.__complete(); + std::destroy_at(std::addressof(__with_val.__union_.__val_)); + std::construct_at(std::addressof(__with_val.__union_.__unex_), std::move(__tmp)); + } else { + static_assert(is_nothrow_move_constructible_v<_Tp>, + "To provide strong exception guarantee, Tp has to satisfy `is_nothrow_move_constructible_v` so " + "that it can be reverted to the previous state in case an exception is thrown during swap."); + _Tp __tmp(std::move(__with_val.__union_.__val_)); + std::destroy_at(std::addressof(__with_val.__union_.__val_)); + __exception_guard __trans([&] { + std::construct_at(std::addressof(__with_val.__union_.__val_), std::move(__tmp)); + }); + std::construct_at(std::addressof(__with_val.__union_.__unex_), std::move(__with_err.__union_.__unex_)); + __trans.__complete(); + std::destroy_at(std::addressof(__with_err.__union_.__unex_)); + std::construct_at(std::addressof(__with_err.__union_.__val_), std::move(__tmp)); + } + __with_val.__has_val_ = false; + __with_err.__has_val_ = true; + }; + + if (__has_val_) { + if (__rhs.__has_val_) { + using std::swap; + swap(__union_.__val_, __rhs.__union_.__val_); + } else { + __swap_val_unex_impl(*this, __rhs); + } + } else { + if (__rhs.__has_val_) { + __swap_val_unex_impl(__rhs, *this); + } else { + using std::swap; + swap(__union_.__unex_, __rhs.__union_.__unex_); + } + } + } + + _LIBCPP_HIDE_FROM_ABI friend constexpr void swap(expected& __x, expected& __y) + noexcept(noexcept(__x.swap(__y))) + requires requires { __x.swap(__y); } + { + __x.swap(__y); + } + + // [expected.object.obs], observers + _LIBCPP_HIDE_FROM_ABI constexpr const _Tp* operator->() const noexcept { + _LIBCPP_ASSERT(__has_val_, "expected::operator-> requires the expected to contain a value"); + return std::addressof(__union_.__val_); + } + + _LIBCPP_HIDE_FROM_ABI constexpr _Tp* operator->() noexcept { + _LIBCPP_ASSERT(__has_val_, "expected::operator-> requires the expected to contain a value"); + return std::addressof(__union_.__val_); + } + + _LIBCPP_HIDE_FROM_ABI constexpr const _Tp& operator*() const& noexcept { + _LIBCPP_ASSERT(__has_val_, "expected::operator* requires the expected to contain a value"); + return __union_.__val_; + } + + _LIBCPP_HIDE_FROM_ABI constexpr _Tp& operator*() & noexcept { + _LIBCPP_ASSERT(__has_val_, "expected::operator* requires the expected to contain a value"); + return __union_.__val_; + } + + _LIBCPP_HIDE_FROM_ABI constexpr const _Tp&& operator*() const&& noexcept { + _LIBCPP_ASSERT(__has_val_, "expected::operator* requires the expected to contain a value"); + return std::move(__union_.__val_); + } + + _LIBCPP_HIDE_FROM_ABI constexpr _Tp&& operator*() && noexcept { + _LIBCPP_ASSERT(__has_val_, "expected::operator* requires the expected to contain a value"); + return std::move(__union_.__val_); + } + + _LIBCPP_HIDE_FROM_ABI constexpr explicit operator bool() const noexcept { return __has_val_; } + + _LIBCPP_HIDE_FROM_ABI constexpr bool has_value() const noexcept { return __has_val_; } + + _LIBCPP_HIDE_FROM_ABI constexpr const _Tp& value() const& { + if (!__has_val_) { + __expected::__throw_bad_expected_access<_Err>(__union_.__unex_); + } + return __union_.__val_; + } + + _LIBCPP_HIDE_FROM_ABI constexpr _Tp& value() & { + if (!__has_val_) { + __expected::__throw_bad_expected_access<_Err>(__union_.__unex_); + } + return __union_.__val_; + } + + _LIBCPP_HIDE_FROM_ABI constexpr const _Tp&& value() const&& { + if (!__has_val_) { + __expected::__throw_bad_expected_access<_Err>(std::move(__union_.__unex_)); + } + return std::move(__union_.__val_); + } + + _LIBCPP_HIDE_FROM_ABI constexpr _Tp&& value() && { + if (!__has_val_) { + __expected::__throw_bad_expected_access<_Err>(std::move(__union_.__unex_)); + } + return std::move(__union_.__val_); + } + + _LIBCPP_HIDE_FROM_ABI constexpr const _Err& error() const& noexcept { + _LIBCPP_ASSERT(!__has_val_, "expected::error requires the expected to contain an error"); + return __union_.__unex_; + } + + _LIBCPP_HIDE_FROM_ABI constexpr _Err& error() & noexcept { + _LIBCPP_ASSERT(!__has_val_, "expected::error requires the expected to contain an error"); + return __union_.__unex_; + } + + _LIBCPP_HIDE_FROM_ABI constexpr const _Err&& error() const&& noexcept { + _LIBCPP_ASSERT(!__has_val_, "expected::error requires the expected to contain an error"); + return std::move(__union_.__unex_); + } + + _LIBCPP_HIDE_FROM_ABI constexpr _Err&& error() && noexcept { + _LIBCPP_ASSERT(!__has_val_, "expected::error requires the expected to contain an error"); + return std::move(__union_.__unex_); + } + + template + _LIBCPP_HIDE_FROM_ABI constexpr _Tp value_or(_Up&& __v) const& { + static_assert(is_copy_constructible_v<_Tp>, "value_type has to be copy constructible"); + static_assert(is_convertible_v<_Up, _Tp>, "argument has to be convertible to value_type"); + return __has_val_ ? __union_.__val_ : static_cast<_Tp>(std::forward<_Up>(__v)); + } + + template + _LIBCPP_HIDE_FROM_ABI constexpr _Tp value_or(_Up&& __v) && { + static_assert(is_move_constructible_v<_Tp>, "value_type has to be move constructible"); + static_assert(is_convertible_v<_Up, _Tp>, "argument has to be convertible to value_type"); + return __has_val_ ? std::move(__union_.__val_) : static_cast<_Tp>(std::forward<_Up>(__v)); + } + + // [expected.object.eq], equality operators + template + requires(!is_void_v<_T2>) + _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(const expected& __x, const expected<_T2, _E2>& __y) { + if (__x.__has_val_ != __y.__has_val_) { + return false; + } else { + if (__x.__has_val_) { + return __x.__union_.__val_ == __y.__union_.__val_; + } else { + return __x.__union_.__unex_ == __y.__union_.__unex_; + } + } + } + + template + _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(const expected& __x, const _T2& __v) { + return __x.__has_val_ && static_cast(__x.__union_.__val_ == __v); + } + + template + _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(const expected& __x, const unexpected<_E2>& __e) { + return !__x.__has_val_ && static_cast(__x.__union_.__unex_ == __e.error()); + } + +private: + struct __empty_t {}; + // use named union because [[no_unique_address]] cannot be applied to an unnamed union + _LIBCPP_NO_UNIQUE_ADDRESS union __union_t { + _LIBCPP_HIDE_FROM_ABI constexpr __union_t() : __empty_() {} + + _LIBCPP_HIDE_FROM_ABI constexpr ~__union_t() + requires(is_trivially_destructible_v<_Tp> && is_trivially_destructible_v<_Err>) + = default; + + // the expected's destructor handles this + _LIBCPP_HIDE_FROM_ABI constexpr ~__union_t() + requires(!is_trivially_destructible_v<_Tp> || !is_trivially_destructible_v<_Err>) + {} + + _LIBCPP_NO_UNIQUE_ADDRESS __empty_t __empty_; + _LIBCPP_NO_UNIQUE_ADDRESS _Tp __val_; + _LIBCPP_NO_UNIQUE_ADDRESS _Err __unex_; + } __union_; + + bool __has_val_; +}; + +template + requires is_void_v<_Tp> +class expected<_Tp, _Err> { + static_assert(__valid_std_unexpected<_Err>::value, + "[expected.void.general] A program that instantiates expected with a E that is not a " + "valid argument for unexpected is ill-formed"); + + template + friend class expected; + + template + using __can_convert = + _And< is_void<_Up>, + is_constructible<_Err, _OtherErrQual>, + _Not, expected<_Up, _OtherErr>&>>, + _Not, expected<_Up, _OtherErr>>>, + _Not, const expected<_Up, _OtherErr>&>>, + _Not, const expected<_Up, _OtherErr>>>>; + +public: + using value_type = _Tp; + using error_type = _Err; + using unexpected_type = unexpected<_Err>; + + template + using rebind = expected<_Up, error_type>; + + // [expected.void.ctor], constructors + _LIBCPP_HIDE_FROM_ABI constexpr expected() noexcept : __has_val_(true) {} + + _LIBCPP_HIDE_FROM_ABI constexpr expected(const expected&) = delete; + + _LIBCPP_HIDE_FROM_ABI constexpr expected(const expected&) + requires(is_copy_constructible_v<_Err> && is_trivially_copy_constructible_v<_Err>) + = default; + + _LIBCPP_HIDE_FROM_ABI constexpr expected(const expected& __rhs) + noexcept(is_nothrow_copy_constructible_v<_Err>) // strengthened + requires(is_copy_constructible_v<_Err> && !is_trivially_copy_constructible_v<_Err>) + : __has_val_(__rhs.__has_val_) { + if (!__rhs.__has_val_) { + std::construct_at(std::addressof(__union_.__unex_), __rhs.__union_.__unex_); + } + } + + _LIBCPP_HIDE_FROM_ABI constexpr expected(expected&&) + requires(is_move_constructible_v<_Err> && is_trivially_move_constructible_v<_Err>) + = default; + + _LIBCPP_HIDE_FROM_ABI constexpr expected(expected&& __rhs) + noexcept(is_nothrow_move_constructible_v<_Err>) + requires(is_move_constructible_v<_Err> && !is_trivially_move_constructible_v<_Err>) + : __has_val_(__rhs.__has_val_) { + if (!__rhs.__has_val_) { + std::construct_at(std::addressof(__union_.__unex_), std::move(__rhs.__union_.__unex_)); + } + } + + template + requires __can_convert<_Up, _OtherErr, const _OtherErr&>::value + _LIBCPP_HIDE_FROM_ABI constexpr explicit(!is_convertible_v) + expected(const expected<_Up, _OtherErr>& __rhs) + noexcept(is_nothrow_constructible_v<_Err, const _OtherErr&>) // strengthened + : __has_val_(__rhs.__has_val_) { + if (!__rhs.__has_val_) { + std::construct_at(std::addressof(__union_.__unex_), __rhs.__union_.__unex_); + } + } + + template + requires __can_convert<_Up, _OtherErr, _OtherErr>::value + _LIBCPP_HIDE_FROM_ABI constexpr explicit(!is_convertible_v<_OtherErr, _Err>) + expected(expected<_Up, _OtherErr>&& __rhs) + noexcept(is_nothrow_constructible_v<_Err, _OtherErr>) // strengthened + : __has_val_(__rhs.__has_val_) { + if (!__rhs.__has_val_) { + std::construct_at(std::addressof(__union_.__unex_), std::move(__rhs.__union_.__unex_)); + } + } + + template + requires is_constructible_v<_Err, const _OtherErr&> + _LIBCPP_HIDE_FROM_ABI constexpr explicit(!is_convertible_v) + expected(const unexpected<_OtherErr>& __unex) + noexcept(is_nothrow_constructible_v<_Err, const _OtherErr&>) // strengthened + : __has_val_(false) { + std::construct_at(std::addressof(__union_.__unex_), __unex.error()); + } + + template + requires is_constructible_v<_Err, _OtherErr> + _LIBCPP_HIDE_FROM_ABI constexpr explicit(!is_convertible_v<_OtherErr, _Err>) + expected(unexpected<_OtherErr>&& __unex) + noexcept(is_nothrow_constructible_v<_Err, _OtherErr>) // strengthened + : __has_val_(false) { + std::construct_at(std::addressof(__union_.__unex_), std::move(__unex.error())); + } + + _LIBCPP_HIDE_FROM_ABI constexpr explicit expected(in_place_t) noexcept : __has_val_(true) {} + + template + requires is_constructible_v<_Err, _Args...> + _LIBCPP_HIDE_FROM_ABI constexpr explicit expected(unexpect_t, _Args&&... __args) + noexcept(is_nothrow_constructible_v<_Err, _Args...>) // strengthened + : __has_val_(false) { + std::construct_at(std::addressof(__union_.__unex_), std::forward<_Args>(__args)...); + } + + template + requires is_constructible_v< _Err, initializer_list<_Up>&, _Args... > + _LIBCPP_HIDE_FROM_ABI constexpr explicit expected(unexpect_t, initializer_list<_Up> __il, _Args&&... __args) + noexcept(is_nothrow_constructible_v<_Err, initializer_list<_Up>&, _Args...>) // strengthened + : __has_val_(false) { + std::construct_at(std::addressof(__union_.__unex_), __il, std::forward<_Args>(__args)...); + } + + // [expected.void.dtor], destructor + + _LIBCPP_HIDE_FROM_ABI constexpr ~expected() + requires is_trivially_destructible_v<_Err> + = default; + + _LIBCPP_HIDE_FROM_ABI constexpr ~expected() + requires(!is_trivially_destructible_v<_Err>) + { + if (!__has_val_) { + std::destroy_at(std::addressof(__union_.__unex_)); + } + } + + // [expected.void.assign], assignment + + _LIBCPP_HIDE_FROM_ABI constexpr expected& operator=(const expected&) = delete; + + _LIBCPP_HIDE_FROM_ABI constexpr expected& operator=(const expected& __rhs) + noexcept(is_nothrow_copy_assignable_v<_Err> && is_nothrow_copy_constructible_v<_Err>) // strengthened + requires(is_copy_assignable_v<_Err> && is_copy_constructible_v<_Err>) + { + if (__has_val_) { + if (!__rhs.__has_val_) { + std::construct_at(std::addressof(__union_.__unex_), __rhs.__union_.__unex_); + __has_val_ = false; + } + } else { + if (__rhs.__has_val_) { + std::destroy_at(std::addressof(__union_.__unex_)); + __has_val_ = true; + } else { + __union_.__unex_ = __rhs.__union_.__unex_; + } + } + return *this; + } + + _LIBCPP_HIDE_FROM_ABI constexpr expected& operator=(expected&&) = delete; + + _LIBCPP_HIDE_FROM_ABI constexpr expected& operator=(expected&& __rhs) + noexcept(is_nothrow_move_assignable_v<_Err> && + is_nothrow_move_constructible_v<_Err>) + requires(is_move_assignable_v<_Err> && + is_move_constructible_v<_Err>) + { + if (__has_val_) { + if (!__rhs.__has_val_) { + std::construct_at(std::addressof(__union_.__unex_), std::move(__rhs.__union_.__unex_)); + __has_val_ = false; + } + } else { + if (__rhs.__has_val_) { + std::destroy_at(std::addressof(__union_.__unex_)); + __has_val_ = true; + } else { + __union_.__unex_ = std::move(__rhs.__union_.__unex_); + } + } + return *this; + } + + template + requires(is_constructible_v<_Err, const _OtherErr&> && is_assignable_v<_Err&, const _OtherErr&>) + _LIBCPP_HIDE_FROM_ABI constexpr expected& operator=(const unexpected<_OtherErr>& __un) { + if (__has_val_) { + std::construct_at(std::addressof(__union_.__unex_), __un.error()); + __has_val_ = false; + } else { + __union_.__unex_ = __un.error(); + } + return *this; + } + + template + requires(is_constructible_v<_Err, _OtherErr> && is_assignable_v<_Err&, _OtherErr>) + _LIBCPP_HIDE_FROM_ABI constexpr expected& operator=(unexpected<_OtherErr>&& __un) { + if (__has_val_) { + std::construct_at(std::addressof(__union_.__unex_), std::move(__un.error())); + __has_val_ = false; + } else { + __union_.__unex_ = std::move(__un.error()); + } + return *this; + } + + _LIBCPP_HIDE_FROM_ABI constexpr void emplace() noexcept { + if (!__has_val_) { + std::destroy_at(std::addressof(__union_.__unex_)); + __has_val_ = true; + } + } + + // [expected.void.swap], swap + _LIBCPP_HIDE_FROM_ABI constexpr void swap(expected& __rhs) + noexcept(is_nothrow_move_constructible_v<_Err> && is_nothrow_swappable_v<_Err>) + requires(is_swappable_v<_Err> && is_move_constructible_v<_Err>) + { + auto __swap_val_unex_impl = [&](expected& __with_val, expected& __with_err) { + std::construct_at(std::addressof(__with_val.__union_.__unex_), std::move(__with_err.__union_.__unex_)); + std::destroy_at(std::addressof(__with_err.__union_.__unex_)); + __with_val.__has_val_ = false; + __with_err.__has_val_ = true; + }; + + if (__has_val_) { + if (!__rhs.__has_val_) { + __swap_val_unex_impl(*this, __rhs); + } + } else { + if (__rhs.__has_val_) { + __swap_val_unex_impl(__rhs, *this); + } else { + using std::swap; + swap(__union_.__unex_, __rhs.__union_.__unex_); + } + } + } + + _LIBCPP_HIDE_FROM_ABI friend constexpr void swap(expected& __x, expected& __y) + noexcept(noexcept(__x.swap(__y))) + requires requires { __x.swap(__y); } + { + __x.swap(__y); + } + + // [expected.void.obs], observers + _LIBCPP_HIDE_FROM_ABI constexpr explicit operator bool() const noexcept { return __has_val_; } + + _LIBCPP_HIDE_FROM_ABI constexpr bool has_value() const noexcept { return __has_val_; } + + _LIBCPP_HIDE_FROM_ABI constexpr void operator*() const noexcept { + _LIBCPP_ASSERT(__has_val_, "expected::operator* requires the expected to contain a value"); + } + + _LIBCPP_HIDE_FROM_ABI constexpr void value() const& { + if (!__has_val_) { + __expected::__throw_bad_expected_access<_Err>(__union_.__unex_); + } + } + + _LIBCPP_HIDE_FROM_ABI constexpr void value() && { + if (!__has_val_) { + __expected::__throw_bad_expected_access<_Err>(std::move(__union_.__unex_)); + } + } + + _LIBCPP_HIDE_FROM_ABI constexpr const _Err& error() const& noexcept { + _LIBCPP_ASSERT(!__has_val_, "expected::error requires the expected to contain an error"); + return __union_.__unex_; + } + + _LIBCPP_HIDE_FROM_ABI constexpr _Err& error() & noexcept { + _LIBCPP_ASSERT(!__has_val_, "expected::error requires the expected to contain an error"); + return __union_.__unex_; + } + + _LIBCPP_HIDE_FROM_ABI constexpr const _Err&& error() const&& noexcept { + _LIBCPP_ASSERT(!__has_val_, "expected::error requires the expected to contain an error"); + return std::move(__union_.__unex_); + } + + _LIBCPP_HIDE_FROM_ABI constexpr _Err&& error() && noexcept { + _LIBCPP_ASSERT(!__has_val_, "expected::error requires the expected to contain an error"); + return std::move(__union_.__unex_); + } + + // [expected.void.eq], equality operators + template + requires is_void_v<_T2> + _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(const expected& __x, const expected<_T2, _E2>& __y) { + if (__x.__has_val_ != __y.__has_val_) { + return false; + } else { + return __x.__has_val_ || static_cast(__x.__union_.__unex_ == __y.__union_.__unex_); + } + } + + template + _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(const expected& __x, const unexpected<_E2>& __y) { + return !__x.__has_val_ && static_cast(__x.__union_.__unex_ == __y.error()); + } + +private: + struct __empty_t {}; + // use named union because [[no_unique_address]] cannot be applied to an unnamed union + _LIBCPP_NO_UNIQUE_ADDRESS union __union_t { + _LIBCPP_HIDE_FROM_ABI constexpr __union_t() : __empty_() {} + + _LIBCPP_HIDE_FROM_ABI constexpr ~__union_t() + requires(is_trivially_destructible_v<_Err>) + = default; + + // the expected's destructor handles this + _LIBCPP_HIDE_FROM_ABI constexpr ~__union_t() + requires(!is_trivially_destructible_v<_Err>) + {} + + _LIBCPP_NO_UNIQUE_ADDRESS __empty_t __empty_; + _LIBCPP_NO_UNIQUE_ADDRESS _Err __unex_; + } __union_; + + bool __has_val_; +}; + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_STD_VER >= 23 + +#endif // _LIBCPP___EXPECTED_EXPECTED_H diff --git a/lib/libcxx/include/__expected/unexpect.h b/lib/libcxx/include/__expected/unexpect.h new file mode 100644 index 0000000000..20bafc1107 --- /dev/null +++ b/lib/libcxx/include/__expected/unexpect.h @@ -0,0 +1,32 @@ +// -*- 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___EXPECTED_UNEXPECT_H +#define _LIBCPP___EXPECTED_UNEXPECT_H + +#include <__config> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +#if _LIBCPP_STD_VER >= 23 + +_LIBCPP_BEGIN_NAMESPACE_STD + +struct unexpect_t { + _LIBCPP_HIDE_FROM_ABI explicit unexpect_t() = default; +}; + +inline constexpr unexpect_t unexpect{}; + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_STD_VER >= 23 + +#endif // _LIBCPP___EXPECTED_UNEXPECT_H diff --git a/lib/libcxx/include/__expected/unexpected.h b/lib/libcxx/include/__expected/unexpected.h new file mode 100644 index 0000000000..075963a84d --- /dev/null +++ b/lib/libcxx/include/__expected/unexpected.h @@ -0,0 +1,122 @@ +// -*- 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___EXPECTED_UNEXPECTED_H +#define _LIBCPP___EXPECTED_UNEXPECTED_H + +#include <__config> +#include <__type_traits/conjunction.h> +#include <__type_traits/is_array.h> +#include <__type_traits/is_const.h> +#include <__type_traits/is_constructible.h> +#include <__type_traits/is_nothrow_constructible.h> +#include <__type_traits/is_object.h> +#include <__type_traits/is_same.h> +#include <__type_traits/is_swappable.h> +#include <__type_traits/is_volatile.h> +#include <__type_traits/negation.h> +#include <__type_traits/remove_cvref.h> +#include <__utility/forward.h> +#include <__utility/in_place.h> +#include <__utility/move.h> +#include <__utility/swap.h> +#include + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +#if _LIBCPP_STD_VER >= 23 + +_LIBCPP_BEGIN_NAMESPACE_STD + +template +class unexpected; + +template +struct __is_std_unexpected : false_type {}; + +template +struct __is_std_unexpected> : true_type {}; + +template +using __valid_std_unexpected = _BoolConstant< // + is_object_v<_Tp> && // + !is_array_v<_Tp> && // + !__is_std_unexpected<_Tp>::value && // + !is_const_v<_Tp> && // + !is_volatile_v<_Tp> // + >; + +template +class unexpected { + static_assert(__valid_std_unexpected<_Err>::value, + "[expected.un.general] states a program that instantiates std::unexpected for a non-object type, an " + "array type, a specialization of unexpected, or a cv-qualified type is ill-formed."); + +public: + _LIBCPP_HIDE_FROM_ABI constexpr unexpected(const unexpected&) = default; + _LIBCPP_HIDE_FROM_ABI constexpr unexpected(unexpected&&) = default; + + template + requires(!is_same_v, unexpected> && // + !is_same_v, in_place_t> && // + is_constructible_v<_Err, _Error>) + _LIBCPP_HIDE_FROM_ABI constexpr explicit unexpected(_Error&& __error) // + noexcept(is_nothrow_constructible_v<_Err, _Error>) // strengthened + : __unex_(std::forward<_Error>(__error)) {} + + template + requires is_constructible_v<_Err, _Args...> + _LIBCPP_HIDE_FROM_ABI constexpr explicit unexpected(in_place_t, _Args&&... __args) // + noexcept(is_nothrow_constructible_v<_Err, _Args...>) // strengthened + : __unex_(std::forward<_Args>(__args)...) {} + + template + requires is_constructible_v<_Err, initializer_list<_Up>&, _Args...> + _LIBCPP_HIDE_FROM_ABI constexpr explicit unexpected(in_place_t, initializer_list<_Up> __il, _Args&&... __args) // + noexcept(is_nothrow_constructible_v<_Err, initializer_list<_Up>&, _Args...>) // strengthened + : __unex_(__il, std::forward<_Args>(__args)...) {} + + _LIBCPP_HIDE_FROM_ABI constexpr unexpected& operator=(const unexpected&) = default; + _LIBCPP_HIDE_FROM_ABI constexpr unexpected& operator=(unexpected&&) = default; + + _LIBCPP_HIDE_FROM_ABI constexpr const _Err& error() const& noexcept { return __unex_; } + _LIBCPP_HIDE_FROM_ABI constexpr _Err& error() & noexcept { return __unex_; } + _LIBCPP_HIDE_FROM_ABI constexpr const _Err&& error() const&& noexcept { return std::move(__unex_); } + _LIBCPP_HIDE_FROM_ABI constexpr _Err&& error() && noexcept { return std::move(__unex_); } + + _LIBCPP_HIDE_FROM_ABI constexpr void swap(unexpected& __other) noexcept(is_nothrow_swappable_v<_Err>) { + static_assert(is_swappable_v<_Err>, "unexpected::swap requires is_swappable_v to be true"); + using std::swap; + swap(__unex_, __other.__unex_); + } + + _LIBCPP_HIDE_FROM_ABI friend constexpr void swap(unexpected& __x, unexpected& __y) noexcept(noexcept(__x.swap(__y))) + requires is_swappable_v<_Err> + { + __x.swap(__y); + } + + template + _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(const unexpected& __x, const unexpected<_Err2>& __y) { + return __x.__unex_ == __y.__unex_; + } + +private: + _Err __unex_; +}; + +template +unexpected(_Err) -> unexpected<_Err>; + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_STD_VER >= 23 + +#endif // _LIBCPP___EXPECTED_UNEXPECTED_H diff --git a/lib/libcxx/include/__filesystem/directory_entry.h b/lib/libcxx/include/__filesystem/directory_entry.h index 5ba3ef96de..b17eaaab4c 100644 --- a/lib/libcxx/include/__filesystem/directory_entry.h +++ b/lib/libcxx/include/__filesystem/directory_entry.h @@ -215,21 +215,23 @@ public: return __get_symlink_status(&__ec); } - _LIBCPP_INLINE_VISIBILITY - bool operator<(directory_entry const& __rhs) const noexcept { - return __p_ < __rhs.__p_; - } _LIBCPP_INLINE_VISIBILITY bool operator==(directory_entry const& __rhs) const noexcept { return __p_ == __rhs.__p_; } +#if _LIBCPP_STD_VER <= 17 _LIBCPP_INLINE_VISIBILITY bool operator!=(directory_entry const& __rhs) const noexcept { return __p_ != __rhs.__p_; } + _LIBCPP_INLINE_VISIBILITY + bool operator<(directory_entry const& __rhs) const noexcept { + return __p_ < __rhs.__p_; + } + _LIBCPP_INLINE_VISIBILITY bool operator<=(directory_entry const& __rhs) const noexcept { return __p_ <= __rhs.__p_; @@ -245,6 +247,15 @@ public: return __p_ >= __rhs.__p_; } +#else // _LIBCPP_STD_VER <= 17 + + _LIBCPP_HIDE_FROM_ABI + strong_ordering operator<=>(const directory_entry& __rhs) const noexcept { + return __p_ <=> __rhs.__p_; + } + +#endif // _LIBCPP_STD_VER <= 17 + template _LIBCPP_INLINE_VISIBILITY friend basic_ostream<_CharT, _Traits>& operator<<(basic_ostream<_CharT, _Traits>& __os, const directory_entry& __d) { diff --git a/lib/libcxx/include/__filesystem/filesystem_error.h b/lib/libcxx/include/__filesystem/filesystem_error.h index e32b14c1b7..effe699833 100644 --- a/lib/libcxx/include/__filesystem/filesystem_error.h +++ b/lib/libcxx/include/__filesystem/filesystem_error.h @@ -14,6 +14,7 @@ #include <__config> #include <__filesystem/path.h> #include <__memory/shared_ptr.h> +#include <__utility/forward.h> #include #include #include @@ -60,7 +61,7 @@ public: filesystem_error(const filesystem_error&) = default; ~filesystem_error() override; // key function - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_HIDE_FROM_ABI_VIRTUAL const char* what() const noexcept override { return __storage_->__what_.c_str(); } diff --git a/lib/libcxx/include/__filesystem/path.h b/lib/libcxx/include/__filesystem/path.h index 8fafd72c7e..4e6912fcf3 100644 --- a/lib/libcxx/include/__filesystem/path.h +++ b/lib/libcxx/include/__filesystem/path.h @@ -141,15 +141,15 @@ struct __is_pathable_string< template ::type, class _UnqualPtrType = - typename remove_const::type>::type, + __remove_const_t<__remove_pointer_t<_DS> >, bool _IsCharPtr = is_pointer<_DS>::value&& __can_convert_char<_UnqualPtrType>::value> struct __is_pathable_char_array : false_type {}; template struct __is_pathable_char_array<_Source, _ECharT*, _UPtr, true> - : __can_convert_char::type> { - using _Base = __can_convert_char::type>; + : __can_convert_char<__remove_const_t<_ECharT> > { + using _Base = __can_convert_char<__remove_const_t<_ECharT> >; _LIBCPP_HIDE_FROM_ABI static _ECharT const* __range_begin(const _ECharT* __b) { return __b; } @@ -619,7 +619,7 @@ public: _EnableIfPathable<_Source> append(const _Source& __src) { using _Traits = __is_pathable<_Source>; using _CVT = _PathCVT<_SourceChar<_Source> >; - bool __source_is_absolute = __is_separator(_Traits::__first_or_null(__src)); + bool __source_is_absolute = _VSTD_FS::__is_separator(_Traits::__first_or_null(__src)); if (__source_is_absolute) __pn_.clear(); else if (has_filename()) @@ -634,7 +634,7 @@ public: typedef typename iterator_traits<_InputIt>::value_type _ItVal; static_assert(__can_convert_char<_ItVal>::value, "Must convertible"); using _CVT = _PathCVT<_ItVal>; - if (__first != __last && __is_separator(*__first)) + if (__first != __last && _VSTD_FS::__is_separator(*__first)) __pn_.clear(); else if (has_filename()) __pn_ += preferred_separator; @@ -732,6 +732,37 @@ public: path& replace_extension(const path& __replacement = path()); + friend _LIBCPP_HIDE_FROM_ABI bool operator==(const path& __lhs, const path& __rhs) noexcept { + return __lhs.__compare(__rhs.__pn_) == 0; + } +# if _LIBCPP_STD_VER <= 17 + friend _LIBCPP_HIDE_FROM_ABI bool operator!=(const path& __lhs, const path& __rhs) noexcept { + return __lhs.__compare(__rhs.__pn_) != 0; + } + friend _LIBCPP_HIDE_FROM_ABI bool operator<(const path& __lhs, const path& __rhs) noexcept { + return __lhs.__compare(__rhs.__pn_) < 0; + } + friend _LIBCPP_HIDE_FROM_ABI bool operator<=(const path& __lhs, const path& __rhs) noexcept { + return __lhs.__compare(__rhs.__pn_) <= 0; + } + friend _LIBCPP_HIDE_FROM_ABI bool operator>(const path& __lhs, const path& __rhs) noexcept { + return __lhs.__compare(__rhs.__pn_) > 0; + } + friend _LIBCPP_HIDE_FROM_ABI bool operator>=(const path& __lhs, const path& __rhs) noexcept { + return __lhs.__compare(__rhs.__pn_) >= 0; + } +# else // _LIBCPP_STD_VER <= 17 + friend _LIBCPP_HIDE_FROM_ABI strong_ordering operator<=>(const path& __lhs, const path& __rhs) noexcept { + return __lhs.__compare(__rhs.__pn_) <=> 0; + } +# endif // _LIBCPP_STD_VER <= 17 + + friend _LIBCPP_HIDE_FROM_ABI path operator/(const path& __lhs, const path& __rhs) { + path __result(__lhs); + __result /= __rhs; + return __result; + } + _LIBCPP_HIDE_FROM_ABI void swap(path& __rhs) noexcept { __pn_.swap(__rhs.__pn_); } @@ -835,7 +866,7 @@ public: using _Str = basic_string<_ECharT, _Traits, _Allocator>; _Str __s(__a); __s.reserve(__pn_.size()); - _CVT()(back_inserter(__s), __pn_.data(), __pn_.data() + __pn_.size()); + _CVT()(std::back_inserter(__s), __pn_.data(), __pn_.data() + __pn_.size()); return __s; } @@ -1035,30 +1066,6 @@ public: } #endif // !_LIBCPP_HAS_NO_LOCALIZATION - friend _LIBCPP_HIDE_FROM_ABI bool operator==(const path& __lhs, const path& __rhs) noexcept { - return __lhs.__compare(__rhs.__pn_) == 0; - } - friend _LIBCPP_HIDE_FROM_ABI bool operator!=(const path& __lhs, const path& __rhs) noexcept { - return __lhs.__compare(__rhs.__pn_) != 0; - } - friend _LIBCPP_HIDE_FROM_ABI bool operator<(const path& __lhs, const path& __rhs) noexcept { - return __lhs.__compare(__rhs.__pn_) < 0; - } - friend _LIBCPP_HIDE_FROM_ABI bool operator<=(const path& __lhs, const path& __rhs) noexcept { - return __lhs.__compare(__rhs.__pn_) <= 0; - } - friend _LIBCPP_HIDE_FROM_ABI bool operator>(const path& __lhs, const path& __rhs) noexcept { - return __lhs.__compare(__rhs.__pn_) > 0; - } - friend _LIBCPP_HIDE_FROM_ABI bool operator>=(const path& __lhs, const path& __rhs) noexcept { - return __lhs.__compare(__rhs.__pn_) >= 0; - } - - friend _LIBCPP_HIDE_FROM_ABI path operator/(const path& __lhs, const path& __rhs) { - path __result(__lhs); - __result /= __rhs; - return __result; - } private: inline _LIBCPP_HIDE_FROM_ABI path& __assign_view(__string_view const& __s) noexcept { diff --git a/lib/libcxx/include/__filesystem/space_info.h b/lib/libcxx/include/__filesystem/space_info.h index d7dc03af75..d0747e35eb 100644 --- a/lib/libcxx/include/__filesystem/space_info.h +++ b/lib/libcxx/include/__filesystem/space_info.h @@ -28,6 +28,10 @@ struct _LIBCPP_TYPE_VIS space_info { uintmax_t capacity; uintmax_t free; uintmax_t available; + +# if _LIBCPP_STD_VER > 17 + friend _LIBCPP_HIDE_FROM_ABI bool operator==(const space_info&, const space_info&) = default; +# endif }; _LIBCPP_AVAILABILITY_FILESYSTEM_POP diff --git a/lib/libcxx/include/__format/buffer.h b/lib/libcxx/include/__format/buffer.h index d9b08064df..ddfe76728e 100644 --- a/lib/libcxx/include/__format/buffer.h +++ b/lib/libcxx/include/__format/buffer.h @@ -11,22 +11,27 @@ #define _LIBCPP___FORMAT_BUFFER_H #include <__algorithm/copy_n.h> +#include <__algorithm/fill_n.h> #include <__algorithm/max.h> #include <__algorithm/min.h> +#include <__algorithm/ranges_copy_n.h> +#include <__algorithm/transform.h> #include <__algorithm/unwrap_iter.h> +#include <__concepts/same_as.h> #include <__config> +#include <__format/concepts.h> #include <__format/enable_insertable.h> #include <__format/format_to_n_result.h> -#include <__format/formatter.h> // for __char_type TODO FMT Move the concept? #include <__iterator/back_insert_iterator.h> #include <__iterator/concepts.h> #include <__iterator/incrementable_traits.h> #include <__iterator/iterator_traits.h> #include <__iterator/wrap_iter.h> #include <__utility/move.h> -#include #include +#include #include +#include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header @@ -46,41 +51,125 @@ namespace __format { /// This helper is used together with the @ref back_insert_iterator to offer /// type-erasure for the formatting functions. This reduces the number to /// template instantiations. -template <__formatter::__char_type _CharT> +template <__fmt_char_type _CharT> class _LIBCPP_TEMPLATE_VIS __output_buffer { public: using value_type = _CharT; template - _LIBCPP_HIDE_FROM_ABI explicit __output_buffer(_CharT* __ptr, - size_t __capacity, _Tp* __obj) - : __ptr_(__ptr), __capacity_(__capacity), - __flush_([](_CharT* __p, size_t __size, void* __o) { - static_cast<_Tp*>(__o)->flush(__p, __size); - }), + _LIBCPP_HIDE_FROM_ABI explicit __output_buffer(_CharT* __ptr, size_t __capacity, _Tp* __obj) + : __ptr_(__ptr), + __capacity_(__capacity), + __flush_([](_CharT* __p, size_t __n, void* __o) { static_cast<_Tp*>(__o)->__flush(__p, __n); }), __obj_(__obj) {} - _LIBCPP_HIDE_FROM_ABI void reset(_CharT* __ptr, size_t __capacity) { + _LIBCPP_HIDE_FROM_ABI void __reset(_CharT* __ptr, size_t __capacity) { __ptr_ = __ptr; __capacity_ = __capacity; } - _LIBCPP_HIDE_FROM_ABI auto make_output_iterator() { - return back_insert_iterator{*this}; - } + _LIBCPP_HIDE_FROM_ABI auto __make_output_iterator() { return std::back_insert_iterator{*this}; } - // TODO FMT It would be nice to have an overload taking a - // basic_string_view<_CharT> and append it directly. + // Used in std::back_insert_iterator. _LIBCPP_HIDE_FROM_ABI void push_back(_CharT __c) { __ptr_[__size_++] = __c; // Profiling showed flushing after adding is more efficient than flushing // when entering the function. if (__size_ == __capacity_) - flush(); + __flush(); } - _LIBCPP_HIDE_FROM_ABI void flush() { + /// Copies the input __str to the buffer. + /// + /// Since some of the input is generated by std::to_chars, there needs to be a + /// conversion when _CharT is wchar_t. + template <__fmt_char_type _InCharT> + _LIBCPP_HIDE_FROM_ABI void __copy(basic_string_view<_InCharT> __str) { + // When the underlying iterator is a simple iterator the __capacity_ is + // infinite. For a string or container back_inserter it isn't. This means + // adding a large string the the buffer can cause some overhead. In that + // case a better approach could be: + // - flush the buffer + // - container.append(__str.begin(), __str.end()); + // The same holds true for the fill. + // For transform it might be slightly harder, however the use case for + // transform is slightly less common; it converts hexadecimal values to + // upper case. For integral these strings are short. + // TODO FMT Look at the improvements above. + size_t __n = __str.size(); + + __flush_on_overflow(__n); + if (__n <= __capacity_) { + _VSTD::copy_n(__str.data(), __n, _VSTD::addressof(__ptr_[__size_])); + __size_ += __n; + return; + } + + // The output doesn't fit in the internal buffer. + // Copy the data in "__capacity_" sized chunks. + _LIBCPP_ASSERT(__size_ == 0, "the buffer should be flushed by __flush_on_overflow"); + const _InCharT* __first = __str.data(); + do { + size_t __chunk = _VSTD::min(__n, __capacity_); + _VSTD::copy_n(__first, __chunk, _VSTD::addressof(__ptr_[__size_])); + __size_ = __chunk; + __first += __chunk; + __n -= __chunk; + __flush(); + } while (__n); + } + + /// A std::transform wrapper. + /// + /// Like @ref __copy it may need to do type conversion. + template <__fmt_char_type _InCharT, class _UnaryOperation> + _LIBCPP_HIDE_FROM_ABI void __transform(const _InCharT* __first, const _InCharT* __last, _UnaryOperation __operation) { + _LIBCPP_ASSERT(__first <= __last, "not a valid range"); + + size_t __n = static_cast(__last - __first); + __flush_on_overflow(__n); + if (__n <= __capacity_) { + _VSTD::transform(__first, __last, _VSTD::addressof(__ptr_[__size_]), _VSTD::move(__operation)); + __size_ += __n; + return; + } + + // The output doesn't fit in the internal buffer. + // Transform the data in "__capacity_" sized chunks. + _LIBCPP_ASSERT(__size_ == 0, "the buffer should be flushed by __flush_on_overflow"); + do { + size_t __chunk = _VSTD::min(__n, __capacity_); + _VSTD::transform(__first, __first + __chunk, _VSTD::addressof(__ptr_[__size_]), __operation); + __size_ = __chunk; + __first += __chunk; + __n -= __chunk; + __flush(); + } while (__n); + } + + /// A \c fill_n wrapper. + _LIBCPP_HIDE_FROM_ABI void __fill(size_t __n, _CharT __value) { + __flush_on_overflow(__n); + if (__n <= __capacity_) { + _VSTD::fill_n(_VSTD::addressof(__ptr_[__size_]), __n, __value); + __size_ += __n; + return; + } + + // The output doesn't fit in the internal buffer. + // Fill the buffer in "__capacity_" sized chunks. + _LIBCPP_ASSERT(__size_ == 0, "the buffer should be flushed by __flush_on_overflow"); + do { + size_t __chunk = _VSTD::min(__n, __capacity_); + _VSTD::fill_n(_VSTD::addressof(__ptr_[__size_]), __chunk, __value); + __size_ = __chunk; + __n -= __chunk; + __flush(); + } while (__n); + } + + _LIBCPP_HIDE_FROM_ABI void __flush() { __flush_(__ptr_, __size_, __obj_); __size_ = 0; } @@ -91,16 +180,54 @@ private: size_t __size_{0}; void (*__flush_)(_CharT*, size_t, void*); void* __obj_; + + /// Flushes the buffer when the output operation would overflow the buffer. + /// + /// A simple approach for the overflow detection would be something along the + /// lines: + /// \code + /// // The internal buffer is large enough. + /// if (__n <= __capacity_) { + /// // Flush when we really would overflow. + /// if (__size_ + __n >= __capacity_) + /// __flush(); + /// ... + /// } + /// \endcode + /// + /// This approach works for all cases but one: + /// A __format_to_n_buffer_base where \ref __enable_direct_output is true. + /// In that case the \ref __capacity_ of the buffer changes during the first + /// \ref __flush. During that operation the output buffer switches from its + /// __writer_ to its __storage_. The \ref __capacity_ of the former depends + /// on the value of n, of the latter is a fixed size. For example: + /// - a format_to_n call with a 10'000 char buffer, + /// - the buffer is filled with 9'500 chars, + /// - adding 1'000 elements would overflow the buffer so the buffer gets + /// changed and the \ref __capacity_ decreases from 10'000 to + /// __buffer_size (256 at the time of writing). + /// + /// This means that the \ref __flush for this class may need to copy a part of + /// the internal buffer to the proper output. In this example there will be + /// 500 characters that need this copy operation. + /// + /// Note it would be more efficient to write 500 chars directly and then swap + /// the buffers. This would make the code more complex and \ref format_to_n is + /// not the most common use case. Therefore the optimization isn't done. + _LIBCPP_HIDE_FROM_ABI void __flush_on_overflow(size_t __n) { + if (__size_ + __n >= __capacity_) + __flush(); + } }; /// A storage using an internal buffer. /// /// This storage is used when writing a single element to the output iterator /// is expensive. -template <__formatter::__char_type _CharT> +template <__fmt_char_type _CharT> class _LIBCPP_TEMPLATE_VIS __internal_storage { public: - _LIBCPP_HIDE_FROM_ABI _CharT* begin() { return __buffer_; } + _LIBCPP_HIDE_FROM_ABI _CharT* __begin() { return __buffer_; } static constexpr size_t __buffer_size = 256 / sizeof(_CharT); @@ -113,11 +240,11 @@ private: /// This requires the storage to be a contiguous buffer of \a _CharT. /// Since the output is directly written to the underlying storage this class /// is just an empty class. -template <__formatter::__char_type _CharT> +template <__fmt_char_type _CharT> class _LIBCPP_TEMPLATE_VIS __direct_storage {}; template -concept __enable_direct_output = __formatter::__char_type<_CharT> && +concept __enable_direct_output = __fmt_char_type<_CharT> && (same_as<_OutIt, _CharT*> #ifndef _LIBCPP_ENABLE_DEBUG_MODE || same_as<_OutIt, __wrap_iter<_CharT*>> @@ -125,18 +252,18 @@ concept __enable_direct_output = __formatter::__char_type<_CharT> && ); /// Write policy for directly writing to the underlying output. -template +template class _LIBCPP_TEMPLATE_VIS __writer_direct { public: _LIBCPP_HIDE_FROM_ABI explicit __writer_direct(_OutIt __out_it) : __out_it_(__out_it) {} - _LIBCPP_HIDE_FROM_ABI auto out() { return __out_it_; } + _LIBCPP_HIDE_FROM_ABI _OutIt __out_it() { return __out_it_; } - _LIBCPP_HIDE_FROM_ABI void flush(_CharT*, size_t __size) { + _LIBCPP_HIDE_FROM_ABI void __flush(_CharT*, size_t __n) { // _OutIt can be a __wrap_iter. Therefore the original iterator // is adjusted. - __out_it_ += __size; + __out_it_ += __n; } private: @@ -144,16 +271,16 @@ private: }; /// Write policy for copying the buffer to the output. -template +template class _LIBCPP_TEMPLATE_VIS __writer_iterator { public: _LIBCPP_HIDE_FROM_ABI explicit __writer_iterator(_OutIt __out_it) : __out_it_{_VSTD::move(__out_it)} {} - _LIBCPP_HIDE_FROM_ABI auto out() { return __out_it_; } + _LIBCPP_HIDE_FROM_ABI _OutIt __out_it() && { return std::move(__out_it_); } - _LIBCPP_HIDE_FROM_ABI void flush(_CharT* __ptr, size_t __size) { - __out_it_ = _VSTD::copy_n(__ptr, __size, _VSTD::move(__out_it_)); + _LIBCPP_HIDE_FROM_ABI void __flush(_CharT* __ptr, size_t __n) { + __out_it_ = std::ranges::copy_n(__ptr, __n, std::move(__out_it_)).out; } private: @@ -169,7 +296,7 @@ private: /// \ref __enable_insertable. template concept __insertable = - __enable_insertable<_Container> && __formatter::__char_type && + __enable_insertable<_Container> && __fmt_char_type && requires(_Container& __t, add_pointer_t __first, add_pointer_t __last) { __t.insert(__t.end(), __first, __last); }; @@ -193,10 +320,10 @@ public: _LIBCPP_HIDE_FROM_ABI explicit __writer_container(back_insert_iterator<_Container> __out_it) : __container_{__out_it.__get_container()} {} - _LIBCPP_HIDE_FROM_ABI auto out() { return back_inserter(*__container_); } + _LIBCPP_HIDE_FROM_ABI auto __out_it() { return std::back_inserter(*__container_); } - _LIBCPP_HIDE_FROM_ABI void flush(_CharT* __ptr, size_t __size) { - __container_->insert(__container_->end(), __ptr, __ptr + __size); + _LIBCPP_HIDE_FROM_ABI void __flush(_CharT* __ptr, size_t __n) { + __container_->insert(__container_->end(), __ptr, __ptr + __n); } private: @@ -215,7 +342,7 @@ public: }; /// The generic formatting buffer. -template +template requires(output_iterator<_OutIt, const _CharT&>) class _LIBCPP_TEMPLATE_VIS __format_buffer { using _Storage = @@ -225,24 +352,20 @@ requires(output_iterator<_OutIt, const _CharT&>) class _LIBCPP_TEMPLATE_VIS public: _LIBCPP_HIDE_FROM_ABI explicit __format_buffer(_OutIt __out_it) requires(same_as<_Storage, __internal_storage<_CharT>>) - : __output_(__storage_.begin(), __storage_.__buffer_size, this), __writer_(_VSTD::move(__out_it)) {} + : __output_(__storage_.__begin(), __storage_.__buffer_size, this), __writer_(_VSTD::move(__out_it)) {} _LIBCPP_HIDE_FROM_ABI explicit __format_buffer(_OutIt __out_it) requires( same_as<_Storage, __direct_storage<_CharT>>) : __output_(_VSTD::__unwrap_iter(__out_it), size_t(-1), this), __writer_(_VSTD::move(__out_it)) {} - _LIBCPP_HIDE_FROM_ABI auto make_output_iterator() { - return __output_.make_output_iterator(); - } + _LIBCPP_HIDE_FROM_ABI auto __make_output_iterator() { return __output_.__make_output_iterator(); } - _LIBCPP_HIDE_FROM_ABI void flush(_CharT* __ptr, size_t __size) { - __writer_.flush(__ptr, __size); - } + _LIBCPP_HIDE_FROM_ABI void __flush(_CharT* __ptr, size_t __n) { __writer_.__flush(__ptr, __n); } - _LIBCPP_HIDE_FROM_ABI _OutIt out() && { - __output_.flush(); - return _VSTD::move(__writer_).out(); + _LIBCPP_HIDE_FROM_ABI _OutIt __out_it() && { + __output_.__flush(); + return _VSTD::move(__writer_).__out_it(); } private: @@ -255,46 +378,46 @@ private: /// /// Since \ref formatted_size only needs to know the size, the output itself is /// discarded. -template <__formatter::__char_type _CharT> +template <__fmt_char_type _CharT> class _LIBCPP_TEMPLATE_VIS __formatted_size_buffer { public: - _LIBCPP_HIDE_FROM_ABI auto make_output_iterator() { return __output_.make_output_iterator(); } + _LIBCPP_HIDE_FROM_ABI auto __make_output_iterator() { return __output_.__make_output_iterator(); } - _LIBCPP_HIDE_FROM_ABI void flush(const _CharT*, size_t __size) { __size_ += __size; } + _LIBCPP_HIDE_FROM_ABI void __flush(const _CharT*, size_t __n) { __size_ += __n; } - _LIBCPP_HIDE_FROM_ABI size_t result() && { - __output_.flush(); + _LIBCPP_HIDE_FROM_ABI size_t __result() && { + __output_.__flush(); return __size_; } private: __internal_storage<_CharT> __storage_; - __output_buffer<_CharT> __output_{__storage_.begin(), __storage_.__buffer_size, this}; + __output_buffer<_CharT> __output_{__storage_.__begin(), __storage_.__buffer_size, this}; size_t __size_{0}; }; /// The base of a buffer that counts and limits the number of insertions. -template +template requires(output_iterator<_OutIt, const _CharT&>) struct _LIBCPP_TEMPLATE_VIS __format_to_n_buffer_base { using _Size = iter_difference_t<_OutIt>; public: - _LIBCPP_HIDE_FROM_ABI explicit __format_to_n_buffer_base(_OutIt __out_it, _Size __n) - : __writer_(_VSTD::move(__out_it)), __n_(_VSTD::max(_Size(0), __n)) {} + _LIBCPP_HIDE_FROM_ABI explicit __format_to_n_buffer_base(_OutIt __out_it, _Size __max_size) + : __writer_(_VSTD::move(__out_it)), __max_size_(_VSTD::max(_Size(0), __max_size)) {} - _LIBCPP_HIDE_FROM_ABI void flush(_CharT* __ptr, size_t __size) { - if (_Size(__size_) <= __n_) - __writer_.flush(__ptr, _VSTD::min(_Size(__size), __n_ - __size_)); - __size_ += __size; + _LIBCPP_HIDE_FROM_ABI void __flush(_CharT* __ptr, size_t __n) { + if (_Size(__size_) <= __max_size_) + __writer_.__flush(__ptr, _VSTD::min(_Size(__n), __max_size_ - __size_)); + __size_ += __n; } protected: __internal_storage<_CharT> __storage_; - __output_buffer<_CharT> __output_{__storage_.begin(), __storage_.__buffer_size, this}; + __output_buffer<_CharT> __output_{__storage_.__begin(), __storage_.__buffer_size, this}; typename __writer_selector<_OutIt, _CharT>::type __writer_; - _Size __n_; + _Size __max_size_; _Size __size_{0}; }; @@ -302,35 +425,46 @@ protected: /// /// This version is used when \c __enable_direct_output<_OutIt, _CharT> == true. /// -/// This class limits the size available the the direct writer so it will not +/// This class limits the size available to the direct writer so it will not /// exceed the maximum number of code units. -template +template requires(output_iterator<_OutIt, const _CharT&>) class _LIBCPP_TEMPLATE_VIS __format_to_n_buffer_base<_OutIt, _CharT, true> { using _Size = iter_difference_t<_OutIt>; public: - _LIBCPP_HIDE_FROM_ABI explicit __format_to_n_buffer_base(_OutIt __out_it, _Size __n) - : __output_(_VSTD::__unwrap_iter(__out_it), __n, this), __writer_(_VSTD::move(__out_it)) { - if (__n <= 0) [[unlikely]] - __output_.reset(__storage_.begin(), __storage_.__buffer_size); + _LIBCPP_HIDE_FROM_ABI explicit __format_to_n_buffer_base(_OutIt __out_it, _Size __max_size) + : __output_(_VSTD::__unwrap_iter(__out_it), __max_size, this), + __writer_(_VSTD::move(__out_it)), + __max_size_(__max_size) { + if (__max_size <= 0) [[unlikely]] + __output_.__reset(__storage_.__begin(), __storage_.__buffer_size); } - _LIBCPP_HIDE_FROM_ABI void flush(_CharT* __ptr, size_t __size) { - // A flush to the direct writer happens in two occasions: + _LIBCPP_HIDE_FROM_ABI void __flush(_CharT* __ptr, size_t __n) { + // A __flush to the direct writer happens in the following occasions: // - The format function has written the maximum number of allowed code // units. At this point it's no longer valid to write to this writer. So // switch to the internal storage. This internal storage doesn't need to - // be written anywhere so the flush for that storage writes no output. + // be written anywhere so the __flush for that storage writes no output. + // - Like above, but the next "mass write" operation would overflow the + // buffer. In that case the buffer is pre-emptively switched. The still + // valid code units will be written separately. // - The format_to_n function is finished. In this case there's no need to // switch the buffer, but for simplicity the buffers are still switched. - // When the __n <= 0 the constructor already switched the buffers. - if (__size_ == 0 && __ptr != __storage_.begin()) { - __writer_.flush(__ptr, __size); - __output_.reset(__storage_.begin(), __storage_.__buffer_size); + // When the __max_size <= 0 the constructor already switched the buffers. + if (__size_ == 0 && __ptr != __storage_.__begin()) { + __writer_.__flush(__ptr, __n); + __output_.__reset(__storage_.__begin(), __storage_.__buffer_size); + } else if (__size_ < __max_size_) { + // Copies a part of the internal buffer to the output up to n characters. + // See __output_buffer<_CharT>::__flush_on_overflow for more information. + _Size __s = _VSTD::min(_Size(__n), __max_size_ - __size_); + std::copy_n(__ptr, __s, __writer_.__out_it()); + __writer_.__flush(__ptr, __s); } - __size_ += __size; + __size_ += __n; } protected: @@ -338,11 +472,12 @@ protected: __output_buffer<_CharT> __output_; __writer_direct<_OutIt, _CharT> __writer_; + _Size __max_size_; _Size __size_{0}; }; /// The buffer that counts and limits the number of insertions. -template +template requires(output_iterator<_OutIt, const _CharT&>) struct _LIBCPP_TEMPLATE_VIS __format_to_n_buffer final : public __format_to_n_buffer_base< _OutIt, _CharT, __enable_direct_output<_OutIt, _CharT>> { @@ -350,14 +485,83 @@ struct _LIBCPP_TEMPLATE_VIS __format_to_n_buffer final using _Size = iter_difference_t<_OutIt>; public: - _LIBCPP_HIDE_FROM_ABI explicit __format_to_n_buffer(_OutIt __out_it, _Size __n) : _Base(_VSTD::move(__out_it), __n) {} - _LIBCPP_HIDE_FROM_ABI auto make_output_iterator() { return this->__output_.make_output_iterator(); } + _LIBCPP_HIDE_FROM_ABI explicit __format_to_n_buffer(_OutIt __out_it, _Size __max_size) + : _Base(_VSTD::move(__out_it), __max_size) {} + _LIBCPP_HIDE_FROM_ABI auto __make_output_iterator() { return this->__output_.__make_output_iterator(); } - _LIBCPP_HIDE_FROM_ABI format_to_n_result<_OutIt> result() && { - this->__output_.flush(); - return {_VSTD::move(this->__writer_).out(), this->__size_}; + _LIBCPP_HIDE_FROM_ABI format_to_n_result<_OutIt> __result() && { + this->__output_.__flush(); + return {_VSTD::move(this->__writer_).__out_it(), this->__size_}; } }; + +// A dynamically growing buffer intended to be used for retargeting a context. +// +// P2286 Formatting ranges adds range formatting support. It allows the user to +// specify the minimum width for the entire formatted range. The width of the +// range is not known until the range is formatted. Formatting is done to an +// output_iterator so there's no guarantee it would be possible to add the fill +// to the front of the output. Instead the range is formatted to a temporary +// buffer and that buffer is formatted as a string. +// +// There is an issue with that approach, the format context used in +// std::formatter::format contains the output iterator used as part of its +// type. So using this output iterator means there needs to be a new format +// context and the format arguments need to be retargeted to the new context. +// This retargeting is done by a basic_format_context specialized for the +// __iterator of this container. +template <__fmt_char_type _CharT> +class _LIBCPP_TEMPLATE_VIS __retarget_buffer { +public: + using value_type = _CharT; + + struct __iterator { + using difference_type = ptrdiff_t; + + _LIBCPP_HIDE_FROM_ABI constexpr explicit __iterator(__retarget_buffer& __buffer) + : __buffer_(std::addressof(__buffer)) {} + _LIBCPP_HIDE_FROM_ABI constexpr __iterator& operator=(const _CharT& __c) { + __buffer_->push_back(__c); + return *this; + } + _LIBCPP_HIDE_FROM_ABI constexpr __iterator& operator=(_CharT&& __c) { + __buffer_->push_back(__c); + return *this; + } + + _LIBCPP_HIDE_FROM_ABI constexpr __iterator& operator*() { return *this; } + _LIBCPP_HIDE_FROM_ABI constexpr __iterator& operator++() { return *this; } + _LIBCPP_HIDE_FROM_ABI constexpr __iterator operator++(int) { return *this; } + __retarget_buffer* __buffer_; + }; + + _LIBCPP_HIDE_FROM_ABI explicit __retarget_buffer(size_t __size_hint) { __buffer_.reserve(__size_hint); } + + _LIBCPP_HIDE_FROM_ABI __iterator __make_output_iterator() { return __iterator{*this}; } + + _LIBCPP_HIDE_FROM_ABI void push_back(_CharT __c) { __buffer_.push_back(__c); } + + template <__fmt_char_type _InCharT> + _LIBCPP_HIDE_FROM_ABI void __copy(basic_string_view<_InCharT> __str) { + __buffer_.insert(__buffer_.end(), __str.begin(), __str.end()); + } + + template <__fmt_char_type _InCharT, class _UnaryOperation> + _LIBCPP_HIDE_FROM_ABI void __transform(const _InCharT* __first, const _InCharT* __last, _UnaryOperation __operation) { + _LIBCPP_ASSERT(__first <= __last, "not a valid range"); + std::transform(__first, __last, std::back_inserter(__buffer_), std::move(__operation)); + } + + _LIBCPP_HIDE_FROM_ABI void __fill(size_t __n, _CharT __value) { __buffer_.insert(__buffer_.end(), __n, __value); } + + _LIBCPP_HIDE_FROM_ABI basic_string_view<_CharT> __view() { return {__buffer_.data(), __buffer_.size()}; } + +private: + // Use vector instead of string to avoid adding zeros after every append + // operation. The buffer is exposed as a string_view and not as a c-string. + vector<_CharT> __buffer_; +}; + } // namespace __format #endif //_LIBCPP_STD_VER > 17 diff --git a/lib/libcxx/include/__format/concepts.h b/lib/libcxx/include/__format/concepts.h index 8df6493b0a..fe4a7b9625 100644 --- a/lib/libcxx/include/__format/concepts.h +++ b/lib/libcxx/include/__format/concepts.h @@ -15,6 +15,9 @@ #include <__config> #include <__format/format_fwd.h> #include <__format/format_parse_context.h> +#include <__type_traits/is_specialization.h> +#include <__utility/pair.h> +#include #include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) @@ -25,6 +28,15 @@ _LIBCPP_BEGIN_NAMESPACE_STD #if _LIBCPP_STD_VER > 17 +/// The character type specializations of \ref formatter. +template +concept __fmt_char_type = + same_as<_CharT, char> +# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS + || same_as<_CharT, wchar_t> +# endif + ; + // The output iterator isn't specified. A formatter should accept any // output_iterator. This iterator is a minimal iterator to test the concept. // (Note testing for (w)format_context would be a valid choice, but requires @@ -32,20 +44,33 @@ _LIBCPP_BEGIN_NAMESPACE_STD template using __fmt_iter_for = _CharT*; -// The concept is based on P2286R6 -// It lacks the const of __cf as required by, the not yet accepted, LWG-3636. -// The current formatters can't be easily adapted, but that is WIP. -// TODO FMT properly implement this concepts once accepted. template -concept __formattable = (semiregular, _CharT>>) && - requires(formatter, _CharT> __f, - formatter, _CharT> __cf, _Tp __t, - basic_format_context<__fmt_iter_for<_CharT>, _CharT> __fc, - basic_format_parse_context<_CharT> __pc) { - { __f.parse(__pc) } -> same_as::iterator>; - { __cf.format(__t, __fc) } -> same_as<__fmt_iter_for<_CharT>>; - }; +concept __formattable = + (semiregular, _CharT>>) && + requires(formatter, _CharT> __f, + const formatter, _CharT> __cf, + _Tp __t, + basic_format_context<__fmt_iter_for<_CharT>, _CharT> __fc, + basic_format_parse_context<_CharT> __pc) { + { __f.parse(__pc) } -> same_as::iterator>; + { __cf.format(__t, __fc) } -> same_as<__fmt_iter_for<_CharT>>; + }; +# if _LIBCPP_STD_VER > 20 +template +concept formattable = __formattable<_Tp, _CharT>; + +// [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. +// +// TODO FMT Add a test to validate we fail when using that concept after P2165 +// has been implemented. +template +concept __fmt_pair_like = __is_specialization_v<_Tp, pair> || + // Use a requires since tuple_size_v may fail to instantiate, + (__is_specialization_v<_Tp, tuple> && requires { tuple_size_v<_Tp> == 2; }); + +# endif //_LIBCPP_STD_VER > 20 #endif //_LIBCPP_STD_VER > 17 _LIBCPP_END_NAMESPACE_STD diff --git a/lib/libcxx/include/__format/container_adaptor.h b/lib/libcxx/include/__format/container_adaptor.h new file mode 100644 index 0000000000..62b698186e --- /dev/null +++ b/lib/libcxx/include/__format/container_adaptor.h @@ -0,0 +1,70 @@ +// -*- 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_CONTAINER_ADAPTOR_H +#define _LIBCPP___FORMAT_CONTAINER_ADAPTOR_H + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +#include <__availability> +#include <__config> +#include <__format/concepts.h> +#include <__format/formatter.h> +#include <__format/range_default_formatter.h> +#include +#include + +_LIBCPP_BEGIN_NAMESPACE_STD + +#if _LIBCPP_STD_VER > 20 + +// [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 +// adding more dependencies like, locale, optinal, string, tuple, etc. to the +// adaptor headers. To use the format functions users already include . + +template +struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT __formatter_container_adaptor { +private: + using __maybe_const_adaptor = __fmt_maybe_const<_Adaptor, _CharT>; + formatter __underlying_; + +public: + template + _LIBCPP_HIDE_FROM_ABI constexpr typename _ParseContext::iterator parse(_ParseContext& __ctx) { + return __underlying_.parse(__ctx); + } + + template + _LIBCPP_HIDE_FROM_ABI typename _FormatContext::iterator + format(__maybe_const_adaptor& __adaptor, _FormatContext& __ctx) const { + return __underlying_.format(__adaptor.__get_container(), __ctx); + } +}; + +template _Container> +struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter, _CharT> + : public __formatter_container_adaptor, _CharT> {}; + +template +struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter, _CharT> + : public __formatter_container_adaptor, _CharT> {}; + +template _Container> +struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter, _CharT> + : public __formatter_container_adaptor, _CharT> {}; + +#endif //_LIBCPP_STD_VER > 20 + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___FORMAT_CONTAINER_ADAPTOR_H diff --git a/lib/libcxx/include/__format/escaped_output_table.h b/lib/libcxx/include/__format/escaped_output_table.h new file mode 100644 index 0000000000..bd2994bdc6 --- /dev/null +++ b/lib/libcxx/include/__format/escaped_output_table.h @@ -0,0 +1,1038 @@ +// -*- 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 +// +//===----------------------------------------------------------------------===// + +// WARNING, this entire header is generated by +// utils/generate_escaped_output_table.py +// DO NOT MODIFY! + +// UNICODE, INC. LICENSE AGREEMENT - DATA FILES AND SOFTWARE +// +// See Terms of Use +// for definitions of Unicode Inc.'s Data Files and Software. +// +// NOTICE TO USER: Carefully read the following legal agreement. +// BY DOWNLOADING, INSTALLING, COPYING OR OTHERWISE USING UNICODE INC.'S +// DATA FILES ("DATA FILES"), AND/OR SOFTWARE ("SOFTWARE"), +// YOU UNEQUIVOCALLY ACCEPT, AND AGREE TO BE BOUND BY, ALL OF THE +// TERMS AND CONDITIONS OF THIS AGREEMENT. +// IF YOU DO NOT AGREE, DO NOT DOWNLOAD, INSTALL, COPY, DISTRIBUTE OR USE +// THE DATA FILES OR SOFTWARE. +// +// COPYRIGHT AND PERMISSION NOTICE +// +// Copyright (c) 1991-2022 Unicode, Inc. All rights reserved. +// Distributed under the Terms of Use in https://www.unicode.org/copyright.html. +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of the Unicode data files and any associated documentation +// (the "Data Files") or Unicode software and any associated documentation +// (the "Software") to deal in the Data Files or Software +// without restriction, including without limitation the rights to use, +// copy, modify, merge, publish, distribute, and/or sell copies of +// the Data Files or Software, and to permit persons to whom the Data Files +// or Software are furnished to do so, provided that either +// (a) this copyright and permission notice appear with all copies +// of the Data Files or Software, or +// (b) this copyright and permission notice appear in associated +// Documentation. +// +// THE DATA FILES AND SOFTWARE ARE PROVIDED "AS IS", WITHOUT WARRANTY OF +// ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE +// WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT OF THIRD PARTY RIGHTS. +// IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS INCLUDED IN THIS +// NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL +// DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, +// DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER +// TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +// PERFORMANCE OF THE DATA FILES OR SOFTWARE. +// +// Except as contained in this notice, the name of a copyright holder +// shall not be used in advertising or otherwise to promote the sale, +// use or other dealings in these Data Files or Software without prior +// written authorization of the copyright holder. + +#ifndef _LIBCPP___FORMAT_ESCAPED_OUTPUT_TABLE_H +#define _LIBCPP___FORMAT_ESCAPED_OUTPUT_TABLE_H + +#include <__algorithm/ranges_upper_bound.h> +#include <__config> +#include +#include + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +#if _LIBCPP_STD_VER > 20 + +namespace __escaped_output_table { + +/// The entries of the characters to escape in format's debug string. +/// +/// Contains the entries for [format.string.escaped]/2.2.1.2.1 +/// CE is a Unicode encoding and C corresponds to either a UCS scalar value +/// whose Unicode property General_Category has a value in the groups +/// Separator (Z) or Other (C) or to a UCS scalar value which has the Unicode +/// property Grapheme_Extend=Yes, as described by table 12 of UAX #44 +/// +/// Separator (Z) consists of General_Category +/// - Space_Separator, +/// - Line_Separator, +/// - Paragraph_Separator. +/// +/// Other (C) consists of General_Category +/// - Control, +/// - Format, +/// - Surrogate, +/// - Private_Use, +/// - Unassigned. +/// +/// The data is generated from +/// - https://www.unicode.org/Public/UCD/latest/ucd/DerivedCoreProperties.txt +/// - https://www.unicode.org/Public/UCD/latest/ucd/extracted/DerivedGeneralCategory.txt +/// +/// The table is similar to the table +/// __extended_grapheme_custer_property_boundary::__entries +/// which explains the details of these classes. The only difference is this +/// table lacks a property, thus having more bits available for the size. +/// +/// The data has 2 values: +/// - bits [0, 10] The size of the range, allowing 2048 elements. +/// - bits [11, 31] The lower bound code point of the range. The upper bound of +/// the range is lower bound + size. +inline constexpr uint32_t __entries[893] = { + 0x00000020, + 0x0003f821, + 0x00056800, + 0x0018006f, + 0x001bc001, + 0x001c0003, + 0x001c5800, + 0x001c6800, + 0x001d1000, + 0x00241806, + 0x00298000, + 0x002ab801, + 0x002c5801, + 0x002c802d, + 0x002df800, + 0x002e0801, + 0x002e2001, + 0x002e3808, + 0x002f5803, + 0x002fa810, + 0x0030800a, + 0x0030e000, + 0x00325814, + 0x00338000, + 0x0036b007, + 0x0036f805, + 0x00373801, + 0x00375003, + 0x00387001, + 0x00388800, + 0x0039801c, + 0x003d300a, + 0x003d900d, + 0x003f5808, + 0x003fd802, + 0x0040b003, + 0x0040d808, + 0x00412802, + 0x00414806, + 0x0041f800, + 0x0042c804, + 0x0042f800, + 0x00435804, + 0x00447810, + 0x00465038, + 0x0049d000, + 0x0049e000, + 0x004a0807, + 0x004a6800, + 0x004a8806, + 0x004b1001, + 0x004c0800, + 0x004c2000, + 0x004c6801, + 0x004c8801, + 0x004d4800, + 0x004d8800, + 0x004d9802, + 0x004dd002, + 0x004df000, + 0x004e0805, + 0x004e4801, + 0x004e6800, + 0x004e780c, + 0x004ef000, + 0x004f1003, + 0x004ff004, + 0x00502000, + 0x00505803, + 0x00508801, + 0x00514800, + 0x00518800, + 0x0051a000, + 0x0051b800, + 0x0051d003, + 0x00520817, + 0x0052e800, + 0x0052f806, + 0x00538001, + 0x0053a800, + 0x0053b80b, + 0x00542000, + 0x00547000, + 0x00549000, + 0x00554800, + 0x00558800, + 0x0055a000, + 0x0055d002, + 0x00560807, + 0x00565000, + 0x00566802, + 0x0056880e, + 0x00571003, + 0x00579006, + 0x0057d007, + 0x00582000, + 0x00586801, + 0x00588801, + 0x00594800, + 0x00598800, + 0x0059a000, + 0x0059d002, + 0x0059f001, + 0x005a0805, + 0x005a4801, + 0x005a680e, + 0x005af000, + 0x005b1003, + 0x005bc00a, + 0x005c2000, + 0x005c5802, + 0x005c8800, + 0x005cb002, + 0x005cd800, + 0x005ce800, + 0x005d0002, + 0x005d2802, + 0x005d5802, + 0x005dd004, + 0x005e0000, + 0x005e1802, + 0x005e4800, + 0x005e6802, + 0x005e8814, + 0x005fd805, + 0x00602000, + 0x00606800, + 0x00608800, + 0x00614800, + 0x0061d002, + 0x0061f002, + 0x00622812, + 0x0062d801, + 0x0062f001, + 0x00631003, + 0x00638006, + 0x00640800, + 0x00646800, + 0x00648800, + 0x00654800, + 0x0065a000, + 0x0065d002, + 0x0065f800, + 0x00661000, + 0x00662801, + 0x00664800, + 0x00666010, + 0x0066f800, + 0x00671003, + 0x00678000, + 0x0067a00d, + 0x00686800, + 0x00688800, + 0x0069d801, + 0x0069f000, + 0x006a0804, + 0x006a4800, + 0x006a6800, + 0x006a8003, + 0x006ab800, + 0x006b1003, + 0x006c0001, + 0x006c2000, + 0x006cb802, + 0x006d9000, + 0x006de000, + 0x006df001, + 0x006e3808, + 0x006e9005, + 0x006ef806, + 0x006f8001, + 0x006fa80b, + 0x00718800, + 0x0071a00a, + 0x00723807, + 0x0072e024, + 0x00741800, + 0x00742800, + 0x00745800, + 0x00752000, + 0x00753000, + 0x00758800, + 0x0075a008, + 0x0075f001, + 0x00762800, + 0x00763808, + 0x0076d001, + 0x0077001f, + 0x0078c001, + 0x0079a800, + 0x0079b800, + 0x0079c800, + 0x007a4000, + 0x007b6811, + 0x007c0004, + 0x007c3001, + 0x007c6830, + 0x007e3000, + 0x007e6800, + 0x007ed824, + 0x00816803, + 0x00819005, + 0x0081c801, + 0x0081e801, + 0x0082c001, + 0x0082f002, + 0x00838803, + 0x00841000, + 0x00842801, + 0x00846800, + 0x0084e800, + 0x00863000, + 0x00864004, + 0x00867001, + 0x00924800, + 0x00927001, + 0x0092b800, + 0x0092c800, + 0x0092f001, + 0x00944800, + 0x00947001, + 0x00958800, + 0x0095b001, + 0x0095f800, + 0x00960800, + 0x00963001, + 0x0096b800, + 0x00988800, + 0x0098b001, + 0x009ad804, + 0x009be802, + 0x009cd005, + 0x009fb001, + 0x009ff001, + 0x00b40000, + 0x00b4e802, + 0x00b7c806, + 0x00b89002, + 0x00b8b008, + 0x00b99001, + 0x00b9b808, + 0x00ba900d, + 0x00bb6800, + 0x00bb880e, + 0x00bda001, + 0x00bdb806, + 0x00be3000, + 0x00be480a, + 0x00bee802, + 0x00bf5005, + 0x00bfd005, + 0x00c05804, + 0x00c0d005, + 0x00c3c806, + 0x00c42801, + 0x00c54800, + 0x00c55804, + 0x00c7b009, + 0x00c8f803, + 0x00c93801, + 0x00c96003, + 0x00c99000, + 0x00c9c806, + 0x00ca0802, + 0x00cb7001, + 0x00cba80a, + 0x00cd6003, + 0x00ce5005, + 0x00ced802, + 0x00d0b801, + 0x00d0d802, + 0x00d2b000, + 0x00d2c008, + 0x00d31000, + 0x00d32807, + 0x00d3980c, + 0x00d45005, + 0x00d4d005, + 0x00d57055, + 0x00d9a006, + 0x00d9e000, + 0x00da1000, + 0x00da6802, + 0x00db5808, + 0x00dbf802, + 0x00dd1003, + 0x00dd4001, + 0x00dd5802, + 0x00df3000, + 0x00df4001, + 0x00df6800, + 0x00df7802, + 0x00dfa007, + 0x00e16007, + 0x00e1b004, + 0x00e25002, + 0x00e44806, + 0x00e5d801, + 0x00e6400a, + 0x00e6a00c, + 0x00e71006, + 0x00e76800, + 0x00e7a000, + 0x00e7c001, + 0x00e7d804, + 0x00ee003f, + 0x00f8b001, + 0x00f8f001, + 0x00fa3001, + 0x00fa7001, + 0x00fac000, + 0x00fad000, + 0x00fae000, + 0x00faf000, + 0x00fbf001, + 0x00fda800, + 0x00fe2800, + 0x00fea001, + 0x00fee000, + 0x00ff8001, + 0x00ffa800, + 0x00fff810, + 0x01014007, + 0x0102f810, + 0x01039001, + 0x01047800, + 0x0104e802, + 0x0106083e, + 0x010c6003, + 0x01213818, + 0x01225814, + 0x015ba001, + 0x015cb000, + 0x01677802, + 0x0167a004, + 0x01693000, + 0x01694004, + 0x01697001, + 0x016b4006, + 0x016b880e, + 0x016cb808, + 0x016d3800, + 0x016d7800, + 0x016db800, + 0x016df800, + 0x016e3800, + 0x016e7800, + 0x016eb800, + 0x016ef820, + 0x0172f021, + 0x0174d000, + 0x0177a00b, + 0x017eb019, + 0x017fe004, + 0x01815005, + 0x01820000, + 0x0184b803, + 0x01880004, + 0x01898000, + 0x018c7800, + 0x018f200b, + 0x0190f800, + 0x05246802, + 0x05263808, + 0x05316013, + 0x05337803, + 0x0533a009, + 0x0534f001, + 0x05378001, + 0x0537c007, + 0x053e5804, + 0x053e9000, + 0x053ea000, + 0x053ed017, + 0x05401000, + 0x05403000, + 0x05405800, + 0x05412801, + 0x05416003, + 0x0541d005, + 0x0543c007, + 0x05462009, + 0x0546d017, + 0x0547f800, + 0x05493007, + 0x054a380a, + 0x054aa00a, + 0x054be805, + 0x054d9800, + 0x054db003, + 0x054de001, + 0x054e7000, + 0x054ed003, + 0x054f2800, + 0x054ff800, + 0x05514805, + 0x05518801, + 0x0551a80a, + 0x05521800, + 0x05526000, + 0x05527001, + 0x0552d001, + 0x0553e000, + 0x05558000, + 0x05559002, + 0x0555b801, + 0x0555f001, + 0x05560800, + 0x05561817, + 0x05576001, + 0x0557b00a, + 0x05583801, + 0x05587801, + 0x0558b808, + 0x05593800, + 0x05597800, + 0x055b6003, + 0x055f2800, + 0x055f4000, + 0x055f6802, + 0x055fd005, + 0x06bd200b, + 0x06be3803, + 0x06bfe7ff, + 0x06ffe7ff, + 0x073fe7ff, + 0x077fe7ff, + 0x07bfe103, + 0x07d37001, + 0x07d6d025, + 0x07d8380b, + 0x07d8c004, + 0x07d8f000, + 0x07d9b800, + 0x07d9e800, + 0x07d9f800, + 0x07da1000, + 0x07da2800, + 0x07de180f, + 0x07ec8001, + 0x07ee4006, + 0x07ee801f, + 0x07f0000f, + 0x07f0d015, + 0x07f29800, + 0x07f33800, + 0x07f36003, + 0x07f3a800, + 0x07f7e803, + 0x07fcf001, + 0x07fdf802, + 0x07fe4001, + 0x07fe8001, + 0x07fec001, + 0x07fee802, + 0x07ff3800, + 0x07ff780c, + 0x07fff001, + 0x08006000, + 0x08013800, + 0x0801d800, + 0x0801f000, + 0x08027001, + 0x0802f021, + 0x0807d804, + 0x08081803, + 0x0809a002, + 0x080c7800, + 0x080ce802, + 0x080d082e, + 0x080fe882, + 0x0814e802, + 0x0816880f, + 0x0817e003, + 0x08192008, + 0x081a5804, + 0x081bb009, + 0x081cf000, + 0x081e2003, + 0x081eb029, + 0x0824f001, + 0x08255005, + 0x0826a003, + 0x0827e003, + 0x08294007, + 0x082b200a, + 0x082bd800, + 0x082c5800, + 0x082c9800, + 0x082cb000, + 0x082d1000, + 0x082d9000, + 0x082dd000, + 0x082de842, + 0x0839b808, + 0x083ab009, + 0x083b4017, + 0x083c3000, + 0x083d8800, + 0x083dd844, + 0x08403001, + 0x08404800, + 0x0841b000, + 0x0841c802, + 0x0841e801, + 0x0842b000, + 0x0844f807, + 0x0845802f, + 0x08479800, + 0x0847b004, + 0x0848e002, + 0x0849d004, + 0x084a003f, + 0x084dc003, + 0x084e8001, + 0x0850080e, + 0x0850a000, + 0x0850c000, + 0x0851b009, + 0x08524806, + 0x0852c806, + 0x0855001f, + 0x08572805, + 0x0857b808, + 0x0859b002, + 0x085ab001, + 0x085b9804, + 0x085c9006, + 0x085ce80b, + 0x085d804f, + 0x08624836, + 0x0865980c, + 0x08679806, + 0x0869200b, + 0x0869d125, + 0x0873f800, + 0x08755002, + 0x08757001, + 0x0875904d, + 0x08794007, + 0x087a300a, + 0x087ad015, + 0x087c1003, + 0x087c5025, + 0x087e6013, + 0x087fb808, + 0x08800800, + 0x0881c00e, + 0x08827003, + 0x08838000, + 0x08839801, + 0x0883b00b, + 0x08859803, + 0x0885c801, + 0x0885e800, + 0x0886100d, + 0x08874806, + 0x0887d008, + 0x08893804, + 0x08896808, + 0x088a4007, + 0x088b9800, + 0x088bb80a, + 0x088db008, + 0x088e4803, + 0x088e7800, + 0x088f0000, + 0x088fa80a, + 0x08909000, + 0x08917802, + 0x0891a000, + 0x0891b001, + 0x0891f000, + 0x0892083e, + 0x08943800, + 0x08944800, + 0x08947000, + 0x0894f000, + 0x08955005, + 0x0896f800, + 0x0897180c, + 0x0897d007, + 0x08982000, + 0x08986801, + 0x08988801, + 0x08994800, + 0x08998800, + 0x0899a000, + 0x0899d002, + 0x0899f000, + 0x089a0000, + 0x089a2801, + 0x089a4801, + 0x089a7001, + 0x089a880b, + 0x089b209b, + 0x08a1c007, + 0x08a21002, + 0x08a23000, + 0x08a2e000, + 0x08a2f000, + 0x08a3101d, + 0x08a58000, + 0x08a59805, + 0x08a5d000, + 0x08a5e800, + 0x08a5f801, + 0x08a61001, + 0x08a64007, + 0x08a6d0a5, + 0x08ad7800, + 0x08ad9005, + 0x08ade001, + 0x08adf801, + 0x08aee023, + 0x08b19807, + 0x08b1e800, + 0x08b1f801, + 0x08b2280a, + 0x08b2d005, + 0x08b36812, + 0x08b55800, + 0x08b56800, + 0x08b58005, + 0x08b5b800, + 0x08b5d005, + 0x08b65035, + 0x08b8d804, + 0x08b91003, + 0x08b93808, + 0x08ba38b8, + 0x08c17808, + 0x08c1c801, + 0x08c1e063, + 0x08c7980b, + 0x08c83801, + 0x08c85001, + 0x08c8a000, + 0x08c8b800, + 0x08c98000, + 0x08c9b000, + 0x08c9c803, + 0x08c9f000, + 0x08ca1800, + 0x08ca3808, + 0x08cad045, + 0x08cd4001, + 0x08cea007, + 0x08cf0000, + 0x08cf281a, + 0x08d00809, + 0x08d19805, + 0x08d1d803, + 0x08d23808, + 0x08d28805, + 0x08d2c802, + 0x08d4500c, + 0x08d4c001, + 0x08d5180c, + 0x08d7c806, + 0x08d850f5, + 0x08e04800, + 0x08e1800d, + 0x08e1f800, + 0x08e23009, + 0x08e36802, + 0x08e48018, + 0x08e55006, + 0x08e59001, + 0x08e5a84a, + 0x08e83800, + 0x08e85000, + 0x08e98814, + 0x08ea3808, + 0x08ead005, + 0x08eb3000, + 0x08eb4800, + 0x08ec7803, + 0x08eca800, + 0x08ecb800, + 0x08ecc806, + 0x08ed5135, + 0x08f79801, + 0x08f7c808, + 0x08f88800, + 0x08f9b007, + 0x08fa0000, + 0x08fa1000, + 0x08fad055, + 0x08fd880e, + 0x08ff900c, + 0x091cd065, + 0x09237800, + 0x0923a80a, + 0x092a27ff, + 0x096a224b, + 0x097f980c, + 0x09a18010, + 0x09a23fff, + 0x09e23fb8, + 0x0a323fff, + 0x0a723fff, + 0x0ab23fff, + 0x0af23fff, + 0x0b3239b8, + 0x0b51c806, + 0x0b52f800, + 0x0b535003, + 0x0b55f800, + 0x0b565005, + 0x0b577006, + 0x0b57b009, + 0x0b598006, + 0x0b5a3009, + 0x0b5ad000, + 0x0b5b1000, + 0x0b5bc004, + 0x0b5c82af, + 0x0b74d864, + 0x0b7a5804, + 0x0b7c400a, + 0x0b7d003f, + 0x0b7f200b, + 0x0b7f900d, + 0x0c3fc007, + 0x0c66b029, + 0x0c684fff, + 0x0ca84fff, + 0x0ce84fff, + 0x0d284fff, + 0x0d684ae6, + 0x0d7fa000, + 0x0d7fe000, + 0x0d7ff800, + 0x0d89180e, + 0x0d89981c, + 0x0d8a9801, + 0x0d8ab00d, + 0x0d8b4007, + 0x0d97e7ff, + 0x0dd7e103, + 0x0de35804, + 0x0de3e802, + 0x0de44806, + 0x0de4d001, + 0x0de4e801, + 0x0de507ff, + 0x0e2507ff, + 0x0e6502af, + 0x0e7e203b, + 0x0e87b009, + 0x0e893801, + 0x0e8b2800, + 0x0e8b3802, + 0x0e8b7014, + 0x0e8c2806, + 0x0e8d5003, + 0x0e8f5814, + 0x0e921002, + 0x0e923079, + 0x0e96a00b, + 0x0e97a00b, + 0x0e9ab808, + 0x0e9bc886, + 0x0ea2a800, + 0x0ea4e800, + 0x0ea50001, + 0x0ea51801, + 0x0ea53801, + 0x0ea56800, + 0x0ea5d000, + 0x0ea5e000, + 0x0ea62000, + 0x0ea83000, + 0x0ea85801, + 0x0ea8a800, + 0x0ea8e800, + 0x0ea9d000, + 0x0ea9f800, + 0x0eaa2800, + 0x0eaa3802, + 0x0eaa8800, + 0x0eb53001, + 0x0ebe6001, + 0x0ed00036, + 0x0ed1d831, + 0x0ed3a800, + 0x0ed42000, + 0x0ed46473, + 0x0ef8f805, + 0x0ef95904, + 0x0f037091, + 0x0f096809, + 0x0f09f001, + 0x0f0a5003, + 0x0f0a813f, + 0x0f157011, + 0x0f176003, + 0x0f17d004, + 0x0f1801cf, + 0x0f276003, + 0x0f27d2e5, + 0x0f3f3800, + 0x0f3f6000, + 0x0f3f7800, + 0x0f3ff800, + 0x0f462801, + 0x0f46802f, + 0x0f4a2006, + 0x0f4a6003, + 0x0f4ad003, + 0x0f4b0310, + 0x0f65a84b, + 0x0f69f0c1, + 0x0f702000, + 0x0f710000, + 0x0f711800, + 0x0f712801, + 0x0f714000, + 0x0f719800, + 0x0f71c000, + 0x0f71d000, + 0x0f71e005, + 0x0f721803, + 0x0f724000, + 0x0f725000, + 0x0f726000, + 0x0f728000, + 0x0f729800, + 0x0f72a801, + 0x0f72c000, + 0x0f72d000, + 0x0f72e000, + 0x0f72f000, + 0x0f730000, + 0x0f731800, + 0x0f732801, + 0x0f735800, + 0x0f739800, + 0x0f73c000, + 0x0f73e800, + 0x0f73f800, + 0x0f745000, + 0x0f74e004, + 0x0f752000, + 0x0f755000, + 0x0f75e033, + 0x0f77910d, + 0x0f816003, + 0x0f84a00b, + 0x0f857801, + 0x0f860000, + 0x0f868000, + 0x0f87b009, + 0x0f8d7037, + 0x0f90180c, + 0x0f91e003, + 0x0f924806, + 0x0f92900d, + 0x0f933099, + 0x0fb6c003, + 0x0fb76802, + 0x0fb7e802, + 0x0fbbb803, + 0x0fbed005, + 0x0fbf6003, + 0x0fbf880e, + 0x0fc06003, + 0x0fc24007, + 0x0fc2d005, + 0x0fc44007, + 0x0fc57001, + 0x0fc5904d, + 0x0fd2a00b, + 0x0fd37001, + 0x0fd3e802, + 0x0fd44806, + 0x0fd5f000, + 0x0fd63007, + 0x0fd6e003, + 0x0fd74806, + 0x0fd7c806, + 0x0fdc9800, + 0x0fde5824, + 0x0fdfd405, + 0x1537001f, + 0x15b9d005, + 0x15c0f001, + 0x1675100d, + 0x175f0fff, + 0x179f0c1e, + 0x17d0f5e1, + 0x189a5804}; + +/// At the end of the valid Unicode code points space a lot of code points are +/// either reserved or a noncharacter. Adding all these entries to the +/// lookup table would add 446 entries to the table (in Unicode 14). +/// Instead the only the start of the region is stored, every code point in +/// this region needs to be escaped. +inline constexpr uint32_t __unallocated_region_lower_bound = 0x000323b0; + +/// Returns whether the code unit needs to be escaped. +/// +/// \pre The code point is a valid Unicode code point. +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool __needs_escape(const char32_t __code_point) noexcept { + // Since __unallocated_region_lower_bound contains the unshifted range do the + // comparison without shifting. + if (__code_point >= __unallocated_region_lower_bound) + return true; + + ptrdiff_t __i = std::ranges::upper_bound(__entries, (__code_point << 11) | 0x7ffu) - __entries; + if (__i == 0) + return false; + + --__i; + uint32_t __upper_bound = (__entries[__i] >> 11) + (__entries[__i] & 0x7ffu); + return __code_point <= __upper_bound; +} + +} // namespace __escaped_output_table + +#endif //_LIBCPP_STD_VER > 20 + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___FORMAT_ESCAPED_OUTPUT_TABLE_H diff --git a/lib/libcxx/include/__format/extended_grapheme_cluster_table.h b/lib/libcxx/include/__format/extended_grapheme_cluster_table.h index 00cd0e91cd..1ffcfeb549 100644 --- a/lib/libcxx/include/__format/extended_grapheme_cluster_table.h +++ b/lib/libcxx/include/__format/extended_grapheme_cluster_table.h @@ -8,7 +8,7 @@ //===----------------------------------------------------------------------===// // WARNING, this entire header is generated by -// utiles/generate_extended_grapheme_cluster_table.py +// utils/generate_extended_grapheme_cluster_table.py // DO NOT MODIFY! // UNICODE, INC. LICENSE AGREEMENT - DATA FILES AND SOFTWARE @@ -61,7 +61,7 @@ #ifndef _LIBCPP___FORMAT_EXTENDED_GRAPHEME_CLUSTER_TABLE_H #define _LIBCPP___FORMAT_EXTENDED_GRAPHEME_CLUSTER_TABLE_H -#include <__algorithm/upper_bound.h> +#include <__algorithm/ranges_upper_bound.h> #include <__config> #include <__iterator/access.h> #include @@ -111,7 +111,7 @@ enum class __property : uint8_t { /// - https://www.unicode.org/Public/UCD/latest/ucd/emoji/emoji-data.txt /// /// The data has 3 values -/// - bits [0, 3] The property. One of the values generated form the datafiles +/// - bits [0, 3] The property. One of the values generated from the datafiles /// of \ref __property /// - bits [4, 10] The size of the range. /// - bits [11, 31] The lower bound code point of the range. The upper bound of @@ -124,177 +124,1506 @@ enum class __property : uint8_t { /// this approach uses less space for the data and is about 4% faster in the /// following benchmark. /// libcxx/benchmarks/std_format_spec_string_unicode.bench.cpp -inline constexpr uint32_t __entries[1480] = { - 0x00000091, 0x00005005, 0x00005811, 0x00006800, 0x00007111, 0x0003fa01, 0x00054803, 0x00056801, 0x00057003, - 0x001806f2, 0x00241862, 0x002c8ac2, 0x002df802, 0x002e0812, 0x002e2012, 0x002e3802, 0x00300058, 0x003080a2, - 0x0030e001, 0x00325942, 0x00338002, 0x0036b062, 0x0036e808, 0x0036f852, 0x00373812, 0x00375032, 0x00387808, - 0x00388802, 0x003981a2, 0x003d30a2, 0x003f5882, 0x003fe802, 0x0040b032, 0x0040d882, 0x00412822, 0x00414842, - 0x0042c822, 0x00448018, 0x0044c072, 0x00465172, 0x00471008, 0x004719f2, 0x0048180a, 0x0049d002, 0x0049d80a, - 0x0049e002, 0x0049f02a, 0x004a0872, 0x004a483a, 0x004a6802, 0x004a701a, 0x004a8862, 0x004b1012, 0x004c0802, - 0x004c101a, 0x004de002, 0x004df002, 0x004df81a, 0x004e0832, 0x004e381a, 0x004e581a, 0x004e6802, 0x004eb802, - 0x004f1012, 0x004ff002, 0x00500812, 0x0050180a, 0x0051e002, 0x0051f02a, 0x00520812, 0x00523812, 0x00525822, - 0x00528802, 0x00538012, 0x0053a802, 0x00540812, 0x0054180a, 0x0055e002, 0x0055f02a, 0x00560842, 0x00563812, - 0x0056480a, 0x0056581a, 0x00566802, 0x00571012, 0x0057d052, 0x00580802, 0x0058101a, 0x0059e002, 0x0059f012, - 0x005a000a, 0x005a0832, 0x005a381a, 0x005a581a, 0x005a6802, 0x005aa822, 0x005b1012, 0x005c1002, 0x005df002, - 0x005df80a, 0x005e0002, 0x005e081a, 0x005e302a, 0x005e502a, 0x005e6802, 0x005eb802, 0x00600002, 0x0060082a, - 0x00602002, 0x0061e002, 0x0061f022, 0x0062083a, 0x00623022, 0x00625032, 0x0062a812, 0x00631012, 0x00640802, - 0x0064101a, 0x0065e002, 0x0065f00a, 0x0065f802, 0x0066001a, 0x00661002, 0x0066181a, 0x00663002, 0x0066381a, - 0x0066501a, 0x00666012, 0x0066a812, 0x00671012, 0x00680012, 0x0068101a, 0x0069d812, 0x0069f002, 0x0069f81a, - 0x006a0832, 0x006a302a, 0x006a502a, 0x006a6802, 0x006a7008, 0x006ab802, 0x006b1012, 0x006c0802, 0x006c101a, - 0x006e5002, 0x006e7802, 0x006e801a, 0x006e9022, 0x006eb002, 0x006ec06a, 0x006ef802, 0x006f901a, 0x00718802, - 0x0071980a, 0x0071a062, 0x00723872, 0x00758802, 0x0075980a, 0x0075a082, 0x00764052, 0x0078c012, 0x0079a802, - 0x0079b802, 0x0079c802, 0x0079f01a, 0x007b88d2, 0x007bf80a, 0x007c0042, 0x007c3012, 0x007c68a2, 0x007cca32, - 0x007e3002, 0x00816832, 0x0081880a, 0x00819052, 0x0081c812, 0x0081d81a, 0x0081e812, 0x0082b01a, 0x0082c012, - 0x0082f022, 0x00838832, 0x00841002, 0x0084200a, 0x00842812, 0x00846802, 0x0084e802, 0x008805f4, 0x008b047c, - 0x008d457b, 0x009ae822, 0x00b89022, 0x00b8a80a, 0x00b99012, 0x00b9a00a, 0x00ba9012, 0x00bb9012, 0x00bda012, - 0x00bdb00a, 0x00bdb862, 0x00bdf07a, 0x00be3002, 0x00be381a, 0x00be48a2, 0x00bee802, 0x00c05822, 0x00c07001, - 0x00c07802, 0x00c42812, 0x00c54802, 0x00c90022, 0x00c9183a, 0x00c93812, 0x00c9482a, 0x00c9801a, 0x00c99002, - 0x00c9985a, 0x00c9c822, 0x00d0b812, 0x00d0c81a, 0x00d0d802, 0x00d2a80a, 0x00d2b002, 0x00d2b80a, 0x00d2c062, - 0x00d30002, 0x00d31002, 0x00d32872, 0x00d3685a, 0x00d39892, 0x00d3f802, 0x00d581e2, 0x00d80032, 0x00d8200a, - 0x00d9a062, 0x00d9d80a, 0x00d9e002, 0x00d9e84a, 0x00da1002, 0x00da181a, 0x00db5882, 0x00dc0012, 0x00dc100a, - 0x00dd080a, 0x00dd1032, 0x00dd301a, 0x00dd4012, 0x00dd500a, 0x00dd5822, 0x00df3002, 0x00df380a, 0x00df4012, - 0x00df502a, 0x00df6802, 0x00df700a, 0x00df7822, 0x00df901a, 0x00e1207a, 0x00e16072, 0x00e1a01a, 0x00e1b012, - 0x00e68022, 0x00e6a0c2, 0x00e7080a, 0x00e71062, 0x00e76802, 0x00e7a002, 0x00e7b80a, 0x00e7c012, 0x00ee03f2, - 0x01005801, 0x01006002, 0x0100680d, 0x01007011, 0x01014061, 0x0101e003, 0x01024803, 0x010300f1, 0x01068202, - 0x01091003, 0x0109c803, 0x010ca053, 0x010d4813, 0x0118d013, 0x01194003, 0x011c4003, 0x011e7803, 0x011f48a3, - 0x011fc023, 0x01261003, 0x012d5013, 0x012db003, 0x012e0003, 0x012fd833, 0x01300053, 0x013038b3, 0x0130a713, - 0x01348753, 0x013840a3, 0x0138a003, 0x0138b003, 0x0138e803, 0x01390803, 0x01394003, 0x01399813, 0x013a2003, - 0x013a3803, 0x013a6003, 0x013a7003, 0x013a9823, 0x013ab803, 0x013b1843, 0x013ca823, 0x013d0803, 0x013d8003, - 0x013df803, 0x0149a013, 0x01582823, 0x0158d813, 0x015a8003, 0x015aa803, 0x01677822, 0x016bf802, 0x016f01f2, - 0x01815052, 0x01818003, 0x0181e803, 0x0184c812, 0x0194b803, 0x0194c803, 0x05337832, 0x0533a092, 0x0534f012, - 0x05378012, 0x05401002, 0x05403002, 0x05405802, 0x0541181a, 0x05412812, 0x0541380a, 0x05416002, 0x0544001a, - 0x0545a0fa, 0x05462012, 0x05470112, 0x0547f802, 0x05493072, 0x054a38a2, 0x054a901a, 0x054b01c4, 0x054c0022, - 0x054c180a, 0x054d9802, 0x054da01a, 0x054db032, 0x054dd01a, 0x054de012, 0x054df02a, 0x054f2802, 0x05514852, - 0x0551781a, 0x05518812, 0x0551981a, 0x0551a812, 0x05521802, 0x05526002, 0x0552680a, 0x0553e002, 0x05558002, - 0x05559022, 0x0555b812, 0x0555f012, 0x05560802, 0x0557580a, 0x05576012, 0x0557701a, 0x0557a80a, 0x0557b002, - 0x055f181a, 0x055f2802, 0x055f301a, 0x055f4002, 0x055f481a, 0x055f600a, 0x055f6802, 0x05600006, 0x056009a7, - 0x0560e006, 0x0560e9a7, 0x0561c006, 0x0561c9a7, 0x0562a006, 0x0562a9a7, 0x05638006, 0x056389a7, 0x05646006, - 0x056469a7, 0x05654006, 0x056549a7, 0x05662006, 0x056629a7, 0x05670006, 0x056709a7, 0x0567e006, 0x0567e9a7, - 0x0568c006, 0x0568c9a7, 0x0569a006, 0x0569a9a7, 0x056a8006, 0x056a89a7, 0x056b6006, 0x056b69a7, 0x056c4006, - 0x056c49a7, 0x056d2006, 0x056d29a7, 0x056e0006, 0x056e09a7, 0x056ee006, 0x056ee9a7, 0x056fc006, 0x056fc9a7, - 0x0570a006, 0x0570a9a7, 0x05718006, 0x057189a7, 0x05726006, 0x057269a7, 0x05734006, 0x057349a7, 0x05742006, - 0x057429a7, 0x05750006, 0x057509a7, 0x0575e006, 0x0575e9a7, 0x0576c006, 0x0576c9a7, 0x0577a006, 0x0577a9a7, - 0x05788006, 0x057889a7, 0x05796006, 0x057969a7, 0x057a4006, 0x057a49a7, 0x057b2006, 0x057b29a7, 0x057c0006, - 0x057c09a7, 0x057ce006, 0x057ce9a7, 0x057dc006, 0x057dc9a7, 0x057ea006, 0x057ea9a7, 0x057f8006, 0x057f89a7, - 0x05806006, 0x058069a7, 0x05814006, 0x058149a7, 0x05822006, 0x058229a7, 0x05830006, 0x058309a7, 0x0583e006, - 0x0583e9a7, 0x0584c006, 0x0584c9a7, 0x0585a006, 0x0585a9a7, 0x05868006, 0x058689a7, 0x05876006, 0x058769a7, - 0x05884006, 0x058849a7, 0x05892006, 0x058929a7, 0x058a0006, 0x058a09a7, 0x058ae006, 0x058ae9a7, 0x058bc006, - 0x058bc9a7, 0x058ca006, 0x058ca9a7, 0x058d8006, 0x058d89a7, 0x058e6006, 0x058e69a7, 0x058f4006, 0x058f49a7, - 0x05902006, 0x059029a7, 0x05910006, 0x059109a7, 0x0591e006, 0x0591e9a7, 0x0592c006, 0x0592c9a7, 0x0593a006, - 0x0593a9a7, 0x05948006, 0x059489a7, 0x05956006, 0x059569a7, 0x05964006, 0x059649a7, 0x05972006, 0x059729a7, - 0x05980006, 0x059809a7, 0x0598e006, 0x0598e9a7, 0x0599c006, 0x0599c9a7, 0x059aa006, 0x059aa9a7, 0x059b8006, - 0x059b89a7, 0x059c6006, 0x059c69a7, 0x059d4006, 0x059d49a7, 0x059e2006, 0x059e29a7, 0x059f0006, 0x059f09a7, - 0x059fe006, 0x059fe9a7, 0x05a0c006, 0x05a0c9a7, 0x05a1a006, 0x05a1a9a7, 0x05a28006, 0x05a289a7, 0x05a36006, - 0x05a369a7, 0x05a44006, 0x05a449a7, 0x05a52006, 0x05a529a7, 0x05a60006, 0x05a609a7, 0x05a6e006, 0x05a6e9a7, - 0x05a7c006, 0x05a7c9a7, 0x05a8a006, 0x05a8a9a7, 0x05a98006, 0x05a989a7, 0x05aa6006, 0x05aa69a7, 0x05ab4006, - 0x05ab49a7, 0x05ac2006, 0x05ac29a7, 0x05ad0006, 0x05ad09a7, 0x05ade006, 0x05ade9a7, 0x05aec006, 0x05aec9a7, - 0x05afa006, 0x05afa9a7, 0x05b08006, 0x05b089a7, 0x05b16006, 0x05b169a7, 0x05b24006, 0x05b249a7, 0x05b32006, - 0x05b329a7, 0x05b40006, 0x05b409a7, 0x05b4e006, 0x05b4e9a7, 0x05b5c006, 0x05b5c9a7, 0x05b6a006, 0x05b6a9a7, - 0x05b78006, 0x05b789a7, 0x05b86006, 0x05b869a7, 0x05b94006, 0x05b949a7, 0x05ba2006, 0x05ba29a7, 0x05bb0006, - 0x05bb09a7, 0x05bbe006, 0x05bbe9a7, 0x05bcc006, 0x05bcc9a7, 0x05bda006, 0x05bda9a7, 0x05be8006, 0x05be89a7, - 0x05bf6006, 0x05bf69a7, 0x05c04006, 0x05c049a7, 0x05c12006, 0x05c129a7, 0x05c20006, 0x05c209a7, 0x05c2e006, - 0x05c2e9a7, 0x05c3c006, 0x05c3c9a7, 0x05c4a006, 0x05c4a9a7, 0x05c58006, 0x05c589a7, 0x05c66006, 0x05c669a7, - 0x05c74006, 0x05c749a7, 0x05c82006, 0x05c829a7, 0x05c90006, 0x05c909a7, 0x05c9e006, 0x05c9e9a7, 0x05cac006, - 0x05cac9a7, 0x05cba006, 0x05cba9a7, 0x05cc8006, 0x05cc89a7, 0x05cd6006, 0x05cd69a7, 0x05ce4006, 0x05ce49a7, - 0x05cf2006, 0x05cf29a7, 0x05d00006, 0x05d009a7, 0x05d0e006, 0x05d0e9a7, 0x05d1c006, 0x05d1c9a7, 0x05d2a006, - 0x05d2a9a7, 0x05d38006, 0x05d389a7, 0x05d46006, 0x05d469a7, 0x05d54006, 0x05d549a7, 0x05d62006, 0x05d629a7, - 0x05d70006, 0x05d709a7, 0x05d7e006, 0x05d7e9a7, 0x05d8c006, 0x05d8c9a7, 0x05d9a006, 0x05d9a9a7, 0x05da8006, - 0x05da89a7, 0x05db6006, 0x05db69a7, 0x05dc4006, 0x05dc49a7, 0x05dd2006, 0x05dd29a7, 0x05de0006, 0x05de09a7, - 0x05dee006, 0x05dee9a7, 0x05dfc006, 0x05dfc9a7, 0x05e0a006, 0x05e0a9a7, 0x05e18006, 0x05e189a7, 0x05e26006, - 0x05e269a7, 0x05e34006, 0x05e349a7, 0x05e42006, 0x05e429a7, 0x05e50006, 0x05e509a7, 0x05e5e006, 0x05e5e9a7, - 0x05e6c006, 0x05e6c9a7, 0x05e7a006, 0x05e7a9a7, 0x05e88006, 0x05e889a7, 0x05e96006, 0x05e969a7, 0x05ea4006, - 0x05ea49a7, 0x05eb2006, 0x05eb29a7, 0x05ec0006, 0x05ec09a7, 0x05ece006, 0x05ece9a7, 0x05edc006, 0x05edc9a7, - 0x05eea006, 0x05eea9a7, 0x05ef8006, 0x05ef89a7, 0x05f06006, 0x05f069a7, 0x05f14006, 0x05f149a7, 0x05f22006, - 0x05f229a7, 0x05f30006, 0x05f309a7, 0x05f3e006, 0x05f3e9a7, 0x05f4c006, 0x05f4c9a7, 0x05f5a006, 0x05f5a9a7, - 0x05f68006, 0x05f689a7, 0x05f76006, 0x05f769a7, 0x05f84006, 0x05f849a7, 0x05f92006, 0x05f929a7, 0x05fa0006, - 0x05fa09a7, 0x05fae006, 0x05fae9a7, 0x05fbc006, 0x05fbc9a7, 0x05fca006, 0x05fca9a7, 0x05fd8006, 0x05fd89a7, - 0x05fe6006, 0x05fe69a7, 0x05ff4006, 0x05ff49a7, 0x06002006, 0x060029a7, 0x06010006, 0x060109a7, 0x0601e006, - 0x0601e9a7, 0x0602c006, 0x0602c9a7, 0x0603a006, 0x0603a9a7, 0x06048006, 0x060489a7, 0x06056006, 0x060569a7, - 0x06064006, 0x060649a7, 0x06072006, 0x060729a7, 0x06080006, 0x060809a7, 0x0608e006, 0x0608e9a7, 0x0609c006, - 0x0609c9a7, 0x060aa006, 0x060aa9a7, 0x060b8006, 0x060b89a7, 0x060c6006, 0x060c69a7, 0x060d4006, 0x060d49a7, - 0x060e2006, 0x060e29a7, 0x060f0006, 0x060f09a7, 0x060fe006, 0x060fe9a7, 0x0610c006, 0x0610c9a7, 0x0611a006, - 0x0611a9a7, 0x06128006, 0x061289a7, 0x06136006, 0x061369a7, 0x06144006, 0x061449a7, 0x06152006, 0x061529a7, - 0x06160006, 0x061609a7, 0x0616e006, 0x0616e9a7, 0x0617c006, 0x0617c9a7, 0x0618a006, 0x0618a9a7, 0x06198006, - 0x061989a7, 0x061a6006, 0x061a69a7, 0x061b4006, 0x061b49a7, 0x061c2006, 0x061c29a7, 0x061d0006, 0x061d09a7, - 0x061de006, 0x061de9a7, 0x061ec006, 0x061ec9a7, 0x061fa006, 0x061fa9a7, 0x06208006, 0x062089a7, 0x06216006, - 0x062169a7, 0x06224006, 0x062249a7, 0x06232006, 0x062329a7, 0x06240006, 0x062409a7, 0x0624e006, 0x0624e9a7, - 0x0625c006, 0x0625c9a7, 0x0626a006, 0x0626a9a7, 0x06278006, 0x062789a7, 0x06286006, 0x062869a7, 0x06294006, - 0x062949a7, 0x062a2006, 0x062a29a7, 0x062b0006, 0x062b09a7, 0x062be006, 0x062be9a7, 0x062cc006, 0x062cc9a7, - 0x062da006, 0x062da9a7, 0x062e8006, 0x062e89a7, 0x062f6006, 0x062f69a7, 0x06304006, 0x063049a7, 0x06312006, - 0x063129a7, 0x06320006, 0x063209a7, 0x0632e006, 0x0632e9a7, 0x0633c006, 0x0633c9a7, 0x0634a006, 0x0634a9a7, - 0x06358006, 0x063589a7, 0x06366006, 0x063669a7, 0x06374006, 0x063749a7, 0x06382006, 0x063829a7, 0x06390006, - 0x063909a7, 0x0639e006, 0x0639e9a7, 0x063ac006, 0x063ac9a7, 0x063ba006, 0x063ba9a7, 0x063c8006, 0x063c89a7, - 0x063d6006, 0x063d69a7, 0x063e4006, 0x063e49a7, 0x063f2006, 0x063f29a7, 0x06400006, 0x064009a7, 0x0640e006, - 0x0640e9a7, 0x0641c006, 0x0641c9a7, 0x0642a006, 0x0642a9a7, 0x06438006, 0x064389a7, 0x06446006, 0x064469a7, - 0x06454006, 0x064549a7, 0x06462006, 0x064629a7, 0x06470006, 0x064709a7, 0x0647e006, 0x0647e9a7, 0x0648c006, - 0x0648c9a7, 0x0649a006, 0x0649a9a7, 0x064a8006, 0x064a89a7, 0x064b6006, 0x064b69a7, 0x064c4006, 0x064c49a7, - 0x064d2006, 0x064d29a7, 0x064e0006, 0x064e09a7, 0x064ee006, 0x064ee9a7, 0x064fc006, 0x064fc9a7, 0x0650a006, - 0x0650a9a7, 0x06518006, 0x065189a7, 0x06526006, 0x065269a7, 0x06534006, 0x065349a7, 0x06542006, 0x065429a7, - 0x06550006, 0x065509a7, 0x0655e006, 0x0655e9a7, 0x0656c006, 0x0656c9a7, 0x0657a006, 0x0657a9a7, 0x06588006, - 0x065889a7, 0x06596006, 0x065969a7, 0x065a4006, 0x065a49a7, 0x065b2006, 0x065b29a7, 0x065c0006, 0x065c09a7, - 0x065ce006, 0x065ce9a7, 0x065dc006, 0x065dc9a7, 0x065ea006, 0x065ea9a7, 0x065f8006, 0x065f89a7, 0x06606006, - 0x066069a7, 0x06614006, 0x066149a7, 0x06622006, 0x066229a7, 0x06630006, 0x066309a7, 0x0663e006, 0x0663e9a7, - 0x0664c006, 0x0664c9a7, 0x0665a006, 0x0665a9a7, 0x06668006, 0x066689a7, 0x06676006, 0x066769a7, 0x06684006, - 0x066849a7, 0x06692006, 0x066929a7, 0x066a0006, 0x066a09a7, 0x066ae006, 0x066ae9a7, 0x066bc006, 0x066bc9a7, - 0x066ca006, 0x066ca9a7, 0x066d8006, 0x066d89a7, 0x066e6006, 0x066e69a7, 0x066f4006, 0x066f49a7, 0x06702006, - 0x067029a7, 0x06710006, 0x067109a7, 0x0671e006, 0x0671e9a7, 0x0672c006, 0x0672c9a7, 0x0673a006, 0x0673a9a7, - 0x06748006, 0x067489a7, 0x06756006, 0x067569a7, 0x06764006, 0x067649a7, 0x06772006, 0x067729a7, 0x06780006, - 0x067809a7, 0x0678e006, 0x0678e9a7, 0x0679c006, 0x0679c9a7, 0x067aa006, 0x067aa9a7, 0x067b8006, 0x067b89a7, - 0x067c6006, 0x067c69a7, 0x067d4006, 0x067d49a7, 0x067e2006, 0x067e29a7, 0x067f0006, 0x067f09a7, 0x067fe006, - 0x067fe9a7, 0x0680c006, 0x0680c9a7, 0x0681a006, 0x0681a9a7, 0x06828006, 0x068289a7, 0x06836006, 0x068369a7, - 0x06844006, 0x068449a7, 0x06852006, 0x068529a7, 0x06860006, 0x068609a7, 0x0686e006, 0x0686e9a7, 0x0687c006, - 0x0687c9a7, 0x0688a006, 0x0688a9a7, 0x06898006, 0x068989a7, 0x068a6006, 0x068a69a7, 0x068b4006, 0x068b49a7, - 0x068c2006, 0x068c29a7, 0x068d0006, 0x068d09a7, 0x068de006, 0x068de9a7, 0x068ec006, 0x068ec9a7, 0x068fa006, - 0x068fa9a7, 0x06908006, 0x069089a7, 0x06916006, 0x069169a7, 0x06924006, 0x069249a7, 0x06932006, 0x069329a7, - 0x06940006, 0x069409a7, 0x0694e006, 0x0694e9a7, 0x0695c006, 0x0695c9a7, 0x0696a006, 0x0696a9a7, 0x06978006, - 0x069789a7, 0x06986006, 0x069869a7, 0x06994006, 0x069949a7, 0x069a2006, 0x069a29a7, 0x069b0006, 0x069b09a7, - 0x069be006, 0x069be9a7, 0x069cc006, 0x069cc9a7, 0x069da006, 0x069da9a7, 0x069e8006, 0x069e89a7, 0x069f6006, - 0x069f69a7, 0x06a04006, 0x06a049a7, 0x06a12006, 0x06a129a7, 0x06a20006, 0x06a209a7, 0x06a2e006, 0x06a2e9a7, - 0x06a3c006, 0x06a3c9a7, 0x06a4a006, 0x06a4a9a7, 0x06a58006, 0x06a589a7, 0x06a66006, 0x06a669a7, 0x06a74006, - 0x06a749a7, 0x06a82006, 0x06a829a7, 0x06a90006, 0x06a909a7, 0x06a9e006, 0x06a9e9a7, 0x06aac006, 0x06aac9a7, - 0x06aba006, 0x06aba9a7, 0x06ac8006, 0x06ac89a7, 0x06ad6006, 0x06ad69a7, 0x06ae4006, 0x06ae49a7, 0x06af2006, - 0x06af29a7, 0x06b00006, 0x06b009a7, 0x06b0e006, 0x06b0e9a7, 0x06b1c006, 0x06b1c9a7, 0x06b2a006, 0x06b2a9a7, - 0x06b38006, 0x06b389a7, 0x06b46006, 0x06b469a7, 0x06b54006, 0x06b549a7, 0x06b62006, 0x06b629a7, 0x06b70006, - 0x06b709a7, 0x06b7e006, 0x06b7e9a7, 0x06b8c006, 0x06b8c9a7, 0x06b9a006, 0x06b9a9a7, 0x06ba8006, 0x06ba89a7, - 0x06bb6006, 0x06bb69a7, 0x06bc4006, 0x06bc49a7, 0x06bd816c, 0x06be5b0b, 0x07d8f002, 0x07f000f2, 0x07f100f2, - 0x07f7f801, 0x07fcf012, 0x07ff80b1, 0x080fe802, 0x08170002, 0x081bb042, 0x08500822, 0x08502812, 0x08506032, - 0x0851c022, 0x0851f802, 0x08572812, 0x08692032, 0x08755812, 0x087a30a2, 0x087c1032, 0x0880000a, 0x08800802, - 0x0880100a, 0x0881c0e2, 0x08838002, 0x08839812, 0x0883f822, 0x0884100a, 0x0885802a, 0x08859832, 0x0885b81a, - 0x0885c812, 0x0885e808, 0x08861002, 0x08866808, 0x08880022, 0x08893842, 0x0889600a, 0x08896872, 0x088a281a, - 0x088b9802, 0x088c0012, 0x088c100a, 0x088d982a, 0x088db082, 0x088df81a, 0x088e1018, 0x088e4832, 0x088e700a, - 0x088e7802, 0x0891602a, 0x08917822, 0x0891901a, 0x0891a002, 0x0891a80a, 0x0891b012, 0x0891f002, 0x0896f802, - 0x0897002a, 0x08971872, 0x08980012, 0x0898101a, 0x0899d812, 0x0899f002, 0x0899f80a, 0x089a0002, 0x089a083a, - 0x089a381a, 0x089a582a, 0x089ab802, 0x089b101a, 0x089b3062, 0x089b8042, 0x08a1a82a, 0x08a1c072, 0x08a2001a, - 0x08a21022, 0x08a2280a, 0x08a23002, 0x08a2f002, 0x08a58002, 0x08a5881a, 0x08a59852, 0x08a5c80a, 0x08a5d002, - 0x08a5d81a, 0x08a5e802, 0x08a5f00a, 0x08a5f812, 0x08a6080a, 0x08a61012, 0x08ad7802, 0x08ad801a, 0x08ad9032, - 0x08adc03a, 0x08ade012, 0x08adf00a, 0x08adf812, 0x08aee012, 0x08b1802a, 0x08b19872, 0x08b1d81a, 0x08b1e802, - 0x08b1f00a, 0x08b1f812, 0x08b55802, 0x08b5600a, 0x08b56802, 0x08b5701a, 0x08b58052, 0x08b5b00a, 0x08b5b802, - 0x08b8e822, 0x08b91032, 0x08b9300a, 0x08b93842, 0x08c1602a, 0x08c17882, 0x08c1c00a, 0x08c1c812, 0x08c98002, - 0x08c9884a, 0x08c9b81a, 0x08c9d812, 0x08c9e80a, 0x08c9f002, 0x08c9f808, 0x08ca000a, 0x08ca0808, 0x08ca100a, - 0x08ca1802, 0x08ce882a, 0x08cea032, 0x08ced012, 0x08cee03a, 0x08cf0002, 0x08cf200a, 0x08d00892, 0x08d19852, - 0x08d1c80a, 0x08d1d008, 0x08d1d832, 0x08d23802, 0x08d28852, 0x08d2b81a, 0x08d2c822, 0x08d42058, 0x08d450c2, - 0x08d4b80a, 0x08d4c012, 0x08e1780a, 0x08e18062, 0x08e1c052, 0x08e1f00a, 0x08e1f802, 0x08e49152, 0x08e5480a, - 0x08e55062, 0x08e5880a, 0x08e59012, 0x08e5a00a, 0x08e5a812, 0x08e98852, 0x08e9d002, 0x08e9e012, 0x08e9f862, - 0x08ea3008, 0x08ea3802, 0x08ec504a, 0x08ec8012, 0x08ec981a, 0x08eca802, 0x08ecb00a, 0x08ecb802, 0x08f79812, - 0x08f7a81a, 0x09a18081, 0x0b578042, 0x0b598062, 0x0b7a7802, 0x0b7a8b6a, 0x0b7c7832, 0x0b7f2002, 0x0b7f801a, - 0x0de4e812, 0x0de50031, 0x0e7802d2, 0x0e798162, 0x0e8b2802, 0x0e8b300a, 0x0e8b3822, 0x0e8b680a, 0x0e8b7042, - 0x0e8b9871, 0x0e8bd872, 0x0e8c2862, 0x0e8d5032, 0x0e921022, 0x0ed00362, 0x0ed1db12, 0x0ed3a802, 0x0ed42002, - 0x0ed4d842, 0x0ed508e2, 0x0f000062, 0x0f004102, 0x0f00d862, 0x0f011812, 0x0f013042, 0x0f098062, 0x0f157002, - 0x0f176032, 0x0f468062, 0x0f4a2062, 0x0f8007f3, 0x0f8407f3, 0x0f886823, 0x0f897803, 0x0f8b6053, 0x0f8bf013, - 0x0f8c7003, 0x0f8c8893, 0x0f8d6b83, 0x0f8f3199, 0x0f9008e3, 0x0f90d003, 0x0f917803, 0x0f919083, 0x0f91e033, - 0x0f924ff3, 0x0f964ff3, 0x0f9a4ff3, 0x0f9e4b13, 0x0f9fd842, 0x0fa007f3, 0x0fa407f3, 0x0fa803d3, 0x0faa37f3, - 0x0fae37f3, 0x0fb23093, 0x0fb407f3, 0x0fbba0b3, 0x0fbeaaa3, 0x0fc06033, 0x0fc24073, 0x0fc2d053, 0x0fc44073, - 0x0fc57513, 0x0fc862e3, 0x0fc9e093, 0x0fca3ff3, 0x0fce3ff3, 0x0fd23ff3, 0x0fd63b83, 0x0fe007f3, 0x0fe407f3, - 0x0fe807f3, 0x0fec07f3, 0x0ff007f3, 0x0ff407f3, 0x0ff807f3, 0x0ffc07d3, 0x700001f1, 0x700105f2, 0x700407f1, - 0x700807f2, 0x700c06f2, 0x700f87f1, 0x701387f1, 0x701787f1, 0x701b87f1, 0x701f87f1, 0x702387f1, 0x702787f1, - 0x702b87f1, 0x702f87f1, 0x703387f1, 0x703787f1, 0x703b87f1, 0x703f87f1, 0x704387f1, 0x704787f1, 0x704b87f1, - 0x704f87f1, 0x705387f1, 0x705787f1, 0x705b87f1, 0x705f87f1, 0x706387f1, 0x706787f1, 0x706b87f1, 0x706f87f1, - 0x707387f1, 0x707787f1, 0x707b87f1, 0x707f80f1}; +inline constexpr uint32_t __entries[1496] = { + 0x00000091, + 0x00005005, + 0x00005811, + 0x00006800, + 0x00007111, + 0x0003fa01, + 0x00054803, + 0x00056801, + 0x00057003, + 0x001806f2, + 0x00241862, + 0x002c8ac2, + 0x002df802, + 0x002e0812, + 0x002e2012, + 0x002e3802, + 0x00300058, + 0x003080a2, + 0x0030e001, + 0x00325942, + 0x00338002, + 0x0036b062, + 0x0036e808, + 0x0036f852, + 0x00373812, + 0x00375032, + 0x00387808, + 0x00388802, + 0x003981a2, + 0x003d30a2, + 0x003f5882, + 0x003fe802, + 0x0040b032, + 0x0040d882, + 0x00412822, + 0x00414842, + 0x0042c822, + 0x00448018, + 0x0044c072, + 0x00465172, + 0x00471008, + 0x004719f2, + 0x0048180a, + 0x0049d002, + 0x0049d80a, + 0x0049e002, + 0x0049f02a, + 0x004a0872, + 0x004a483a, + 0x004a6802, + 0x004a701a, + 0x004a8862, + 0x004b1012, + 0x004c0802, + 0x004c101a, + 0x004de002, + 0x004df002, + 0x004df81a, + 0x004e0832, + 0x004e381a, + 0x004e581a, + 0x004e6802, + 0x004eb802, + 0x004f1012, + 0x004ff002, + 0x00500812, + 0x0050180a, + 0x0051e002, + 0x0051f02a, + 0x00520812, + 0x00523812, + 0x00525822, + 0x00528802, + 0x00538012, + 0x0053a802, + 0x00540812, + 0x0054180a, + 0x0055e002, + 0x0055f02a, + 0x00560842, + 0x00563812, + 0x0056480a, + 0x0056581a, + 0x00566802, + 0x00571012, + 0x0057d052, + 0x00580802, + 0x0058101a, + 0x0059e002, + 0x0059f012, + 0x005a000a, + 0x005a0832, + 0x005a381a, + 0x005a581a, + 0x005a6802, + 0x005aa822, + 0x005b1012, + 0x005c1002, + 0x005df002, + 0x005df80a, + 0x005e0002, + 0x005e081a, + 0x005e302a, + 0x005e502a, + 0x005e6802, + 0x005eb802, + 0x00600002, + 0x0060082a, + 0x00602002, + 0x0061e002, + 0x0061f022, + 0x0062083a, + 0x00623022, + 0x00625032, + 0x0062a812, + 0x00631012, + 0x00640802, + 0x0064101a, + 0x0065e002, + 0x0065f00a, + 0x0065f802, + 0x0066001a, + 0x00661002, + 0x0066181a, + 0x00663002, + 0x0066381a, + 0x0066501a, + 0x00666012, + 0x0066a812, + 0x00671012, + 0x0067980a, + 0x00680012, + 0x0068101a, + 0x0069d812, + 0x0069f002, + 0x0069f81a, + 0x006a0832, + 0x006a302a, + 0x006a502a, + 0x006a6802, + 0x006a7008, + 0x006ab802, + 0x006b1012, + 0x006c0802, + 0x006c101a, + 0x006e5002, + 0x006e7802, + 0x006e801a, + 0x006e9022, + 0x006eb002, + 0x006ec06a, + 0x006ef802, + 0x006f901a, + 0x00718802, + 0x0071980a, + 0x0071a062, + 0x00723872, + 0x00758802, + 0x0075980a, + 0x0075a082, + 0x00764062, + 0x0078c012, + 0x0079a802, + 0x0079b802, + 0x0079c802, + 0x0079f01a, + 0x007b88d2, + 0x007bf80a, + 0x007c0042, + 0x007c3012, + 0x007c68a2, + 0x007cca32, + 0x007e3002, + 0x00816832, + 0x0081880a, + 0x00819052, + 0x0081c812, + 0x0081d81a, + 0x0081e812, + 0x0082b01a, + 0x0082c012, + 0x0082f022, + 0x00838832, + 0x00841002, + 0x0084200a, + 0x00842812, + 0x00846802, + 0x0084e802, + 0x008805f4, + 0x008b047c, + 0x008d457b, + 0x009ae822, + 0x00b89022, + 0x00b8a80a, + 0x00b99012, + 0x00b9a00a, + 0x00ba9012, + 0x00bb9012, + 0x00bda012, + 0x00bdb00a, + 0x00bdb862, + 0x00bdf07a, + 0x00be3002, + 0x00be381a, + 0x00be48a2, + 0x00bee802, + 0x00c05822, + 0x00c07001, + 0x00c07802, + 0x00c42812, + 0x00c54802, + 0x00c90022, + 0x00c9183a, + 0x00c93812, + 0x00c9482a, + 0x00c9801a, + 0x00c99002, + 0x00c9985a, + 0x00c9c822, + 0x00d0b812, + 0x00d0c81a, + 0x00d0d802, + 0x00d2a80a, + 0x00d2b002, + 0x00d2b80a, + 0x00d2c062, + 0x00d30002, + 0x00d31002, + 0x00d32872, + 0x00d3685a, + 0x00d39892, + 0x00d3f802, + 0x00d581e2, + 0x00d80032, + 0x00d8200a, + 0x00d9a062, + 0x00d9d80a, + 0x00d9e002, + 0x00d9e84a, + 0x00da1002, + 0x00da181a, + 0x00db5882, + 0x00dc0012, + 0x00dc100a, + 0x00dd080a, + 0x00dd1032, + 0x00dd301a, + 0x00dd4012, + 0x00dd500a, + 0x00dd5822, + 0x00df3002, + 0x00df380a, + 0x00df4012, + 0x00df502a, + 0x00df6802, + 0x00df700a, + 0x00df7822, + 0x00df901a, + 0x00e1207a, + 0x00e16072, + 0x00e1a01a, + 0x00e1b012, + 0x00e68022, + 0x00e6a0c2, + 0x00e7080a, + 0x00e71062, + 0x00e76802, + 0x00e7a002, + 0x00e7b80a, + 0x00e7c012, + 0x00ee03f2, + 0x01005801, + 0x01006002, + 0x0100680d, + 0x01007011, + 0x01014061, + 0x0101e003, + 0x01024803, + 0x010300f1, + 0x01068202, + 0x01091003, + 0x0109c803, + 0x010ca053, + 0x010d4813, + 0x0118d013, + 0x01194003, + 0x011c4003, + 0x011e7803, + 0x011f48a3, + 0x011fc023, + 0x01261003, + 0x012d5013, + 0x012db003, + 0x012e0003, + 0x012fd833, + 0x01300053, + 0x013038b3, + 0x0130a713, + 0x01348753, + 0x013840a3, + 0x0138a003, + 0x0138b003, + 0x0138e803, + 0x01390803, + 0x01394003, + 0x01399813, + 0x013a2003, + 0x013a3803, + 0x013a6003, + 0x013a7003, + 0x013a9823, + 0x013ab803, + 0x013b1843, + 0x013ca823, + 0x013d0803, + 0x013d8003, + 0x013df803, + 0x0149a013, + 0x01582823, + 0x0158d813, + 0x015a8003, + 0x015aa803, + 0x01677822, + 0x016bf802, + 0x016f01f2, + 0x01815052, + 0x01818003, + 0x0181e803, + 0x0184c812, + 0x0194b803, + 0x0194c803, + 0x05337832, + 0x0533a092, + 0x0534f012, + 0x05378012, + 0x05401002, + 0x05403002, + 0x05405802, + 0x0541181a, + 0x05412812, + 0x0541380a, + 0x05416002, + 0x0544001a, + 0x0545a0fa, + 0x05462012, + 0x05470112, + 0x0547f802, + 0x05493072, + 0x054a38a2, + 0x054a901a, + 0x054b01c4, + 0x054c0022, + 0x054c180a, + 0x054d9802, + 0x054da01a, + 0x054db032, + 0x054dd01a, + 0x054de012, + 0x054df02a, + 0x054f2802, + 0x05514852, + 0x0551781a, + 0x05518812, + 0x0551981a, + 0x0551a812, + 0x05521802, + 0x05526002, + 0x0552680a, + 0x0553e002, + 0x05558002, + 0x05559022, + 0x0555b812, + 0x0555f012, + 0x05560802, + 0x0557580a, + 0x05576012, + 0x0557701a, + 0x0557a80a, + 0x0557b002, + 0x055f181a, + 0x055f2802, + 0x055f301a, + 0x055f4002, + 0x055f481a, + 0x055f600a, + 0x055f6802, + 0x05600006, + 0x056009a7, + 0x0560e006, + 0x0560e9a7, + 0x0561c006, + 0x0561c9a7, + 0x0562a006, + 0x0562a9a7, + 0x05638006, + 0x056389a7, + 0x05646006, + 0x056469a7, + 0x05654006, + 0x056549a7, + 0x05662006, + 0x056629a7, + 0x05670006, + 0x056709a7, + 0x0567e006, + 0x0567e9a7, + 0x0568c006, + 0x0568c9a7, + 0x0569a006, + 0x0569a9a7, + 0x056a8006, + 0x056a89a7, + 0x056b6006, + 0x056b69a7, + 0x056c4006, + 0x056c49a7, + 0x056d2006, + 0x056d29a7, + 0x056e0006, + 0x056e09a7, + 0x056ee006, + 0x056ee9a7, + 0x056fc006, + 0x056fc9a7, + 0x0570a006, + 0x0570a9a7, + 0x05718006, + 0x057189a7, + 0x05726006, + 0x057269a7, + 0x05734006, + 0x057349a7, + 0x05742006, + 0x057429a7, + 0x05750006, + 0x057509a7, + 0x0575e006, + 0x0575e9a7, + 0x0576c006, + 0x0576c9a7, + 0x0577a006, + 0x0577a9a7, + 0x05788006, + 0x057889a7, + 0x05796006, + 0x057969a7, + 0x057a4006, + 0x057a49a7, + 0x057b2006, + 0x057b29a7, + 0x057c0006, + 0x057c09a7, + 0x057ce006, + 0x057ce9a7, + 0x057dc006, + 0x057dc9a7, + 0x057ea006, + 0x057ea9a7, + 0x057f8006, + 0x057f89a7, + 0x05806006, + 0x058069a7, + 0x05814006, + 0x058149a7, + 0x05822006, + 0x058229a7, + 0x05830006, + 0x058309a7, + 0x0583e006, + 0x0583e9a7, + 0x0584c006, + 0x0584c9a7, + 0x0585a006, + 0x0585a9a7, + 0x05868006, + 0x058689a7, + 0x05876006, + 0x058769a7, + 0x05884006, + 0x058849a7, + 0x05892006, + 0x058929a7, + 0x058a0006, + 0x058a09a7, + 0x058ae006, + 0x058ae9a7, + 0x058bc006, + 0x058bc9a7, + 0x058ca006, + 0x058ca9a7, + 0x058d8006, + 0x058d89a7, + 0x058e6006, + 0x058e69a7, + 0x058f4006, + 0x058f49a7, + 0x05902006, + 0x059029a7, + 0x05910006, + 0x059109a7, + 0x0591e006, + 0x0591e9a7, + 0x0592c006, + 0x0592c9a7, + 0x0593a006, + 0x0593a9a7, + 0x05948006, + 0x059489a7, + 0x05956006, + 0x059569a7, + 0x05964006, + 0x059649a7, + 0x05972006, + 0x059729a7, + 0x05980006, + 0x059809a7, + 0x0598e006, + 0x0598e9a7, + 0x0599c006, + 0x0599c9a7, + 0x059aa006, + 0x059aa9a7, + 0x059b8006, + 0x059b89a7, + 0x059c6006, + 0x059c69a7, + 0x059d4006, + 0x059d49a7, + 0x059e2006, + 0x059e29a7, + 0x059f0006, + 0x059f09a7, + 0x059fe006, + 0x059fe9a7, + 0x05a0c006, + 0x05a0c9a7, + 0x05a1a006, + 0x05a1a9a7, + 0x05a28006, + 0x05a289a7, + 0x05a36006, + 0x05a369a7, + 0x05a44006, + 0x05a449a7, + 0x05a52006, + 0x05a529a7, + 0x05a60006, + 0x05a609a7, + 0x05a6e006, + 0x05a6e9a7, + 0x05a7c006, + 0x05a7c9a7, + 0x05a8a006, + 0x05a8a9a7, + 0x05a98006, + 0x05a989a7, + 0x05aa6006, + 0x05aa69a7, + 0x05ab4006, + 0x05ab49a7, + 0x05ac2006, + 0x05ac29a7, + 0x05ad0006, + 0x05ad09a7, + 0x05ade006, + 0x05ade9a7, + 0x05aec006, + 0x05aec9a7, + 0x05afa006, + 0x05afa9a7, + 0x05b08006, + 0x05b089a7, + 0x05b16006, + 0x05b169a7, + 0x05b24006, + 0x05b249a7, + 0x05b32006, + 0x05b329a7, + 0x05b40006, + 0x05b409a7, + 0x05b4e006, + 0x05b4e9a7, + 0x05b5c006, + 0x05b5c9a7, + 0x05b6a006, + 0x05b6a9a7, + 0x05b78006, + 0x05b789a7, + 0x05b86006, + 0x05b869a7, + 0x05b94006, + 0x05b949a7, + 0x05ba2006, + 0x05ba29a7, + 0x05bb0006, + 0x05bb09a7, + 0x05bbe006, + 0x05bbe9a7, + 0x05bcc006, + 0x05bcc9a7, + 0x05bda006, + 0x05bda9a7, + 0x05be8006, + 0x05be89a7, + 0x05bf6006, + 0x05bf69a7, + 0x05c04006, + 0x05c049a7, + 0x05c12006, + 0x05c129a7, + 0x05c20006, + 0x05c209a7, + 0x05c2e006, + 0x05c2e9a7, + 0x05c3c006, + 0x05c3c9a7, + 0x05c4a006, + 0x05c4a9a7, + 0x05c58006, + 0x05c589a7, + 0x05c66006, + 0x05c669a7, + 0x05c74006, + 0x05c749a7, + 0x05c82006, + 0x05c829a7, + 0x05c90006, + 0x05c909a7, + 0x05c9e006, + 0x05c9e9a7, + 0x05cac006, + 0x05cac9a7, + 0x05cba006, + 0x05cba9a7, + 0x05cc8006, + 0x05cc89a7, + 0x05cd6006, + 0x05cd69a7, + 0x05ce4006, + 0x05ce49a7, + 0x05cf2006, + 0x05cf29a7, + 0x05d00006, + 0x05d009a7, + 0x05d0e006, + 0x05d0e9a7, + 0x05d1c006, + 0x05d1c9a7, + 0x05d2a006, + 0x05d2a9a7, + 0x05d38006, + 0x05d389a7, + 0x05d46006, + 0x05d469a7, + 0x05d54006, + 0x05d549a7, + 0x05d62006, + 0x05d629a7, + 0x05d70006, + 0x05d709a7, + 0x05d7e006, + 0x05d7e9a7, + 0x05d8c006, + 0x05d8c9a7, + 0x05d9a006, + 0x05d9a9a7, + 0x05da8006, + 0x05da89a7, + 0x05db6006, + 0x05db69a7, + 0x05dc4006, + 0x05dc49a7, + 0x05dd2006, + 0x05dd29a7, + 0x05de0006, + 0x05de09a7, + 0x05dee006, + 0x05dee9a7, + 0x05dfc006, + 0x05dfc9a7, + 0x05e0a006, + 0x05e0a9a7, + 0x05e18006, + 0x05e189a7, + 0x05e26006, + 0x05e269a7, + 0x05e34006, + 0x05e349a7, + 0x05e42006, + 0x05e429a7, + 0x05e50006, + 0x05e509a7, + 0x05e5e006, + 0x05e5e9a7, + 0x05e6c006, + 0x05e6c9a7, + 0x05e7a006, + 0x05e7a9a7, + 0x05e88006, + 0x05e889a7, + 0x05e96006, + 0x05e969a7, + 0x05ea4006, + 0x05ea49a7, + 0x05eb2006, + 0x05eb29a7, + 0x05ec0006, + 0x05ec09a7, + 0x05ece006, + 0x05ece9a7, + 0x05edc006, + 0x05edc9a7, + 0x05eea006, + 0x05eea9a7, + 0x05ef8006, + 0x05ef89a7, + 0x05f06006, + 0x05f069a7, + 0x05f14006, + 0x05f149a7, + 0x05f22006, + 0x05f229a7, + 0x05f30006, + 0x05f309a7, + 0x05f3e006, + 0x05f3e9a7, + 0x05f4c006, + 0x05f4c9a7, + 0x05f5a006, + 0x05f5a9a7, + 0x05f68006, + 0x05f689a7, + 0x05f76006, + 0x05f769a7, + 0x05f84006, + 0x05f849a7, + 0x05f92006, + 0x05f929a7, + 0x05fa0006, + 0x05fa09a7, + 0x05fae006, + 0x05fae9a7, + 0x05fbc006, + 0x05fbc9a7, + 0x05fca006, + 0x05fca9a7, + 0x05fd8006, + 0x05fd89a7, + 0x05fe6006, + 0x05fe69a7, + 0x05ff4006, + 0x05ff49a7, + 0x06002006, + 0x060029a7, + 0x06010006, + 0x060109a7, + 0x0601e006, + 0x0601e9a7, + 0x0602c006, + 0x0602c9a7, + 0x0603a006, + 0x0603a9a7, + 0x06048006, + 0x060489a7, + 0x06056006, + 0x060569a7, + 0x06064006, + 0x060649a7, + 0x06072006, + 0x060729a7, + 0x06080006, + 0x060809a7, + 0x0608e006, + 0x0608e9a7, + 0x0609c006, + 0x0609c9a7, + 0x060aa006, + 0x060aa9a7, + 0x060b8006, + 0x060b89a7, + 0x060c6006, + 0x060c69a7, + 0x060d4006, + 0x060d49a7, + 0x060e2006, + 0x060e29a7, + 0x060f0006, + 0x060f09a7, + 0x060fe006, + 0x060fe9a7, + 0x0610c006, + 0x0610c9a7, + 0x0611a006, + 0x0611a9a7, + 0x06128006, + 0x061289a7, + 0x06136006, + 0x061369a7, + 0x06144006, + 0x061449a7, + 0x06152006, + 0x061529a7, + 0x06160006, + 0x061609a7, + 0x0616e006, + 0x0616e9a7, + 0x0617c006, + 0x0617c9a7, + 0x0618a006, + 0x0618a9a7, + 0x06198006, + 0x061989a7, + 0x061a6006, + 0x061a69a7, + 0x061b4006, + 0x061b49a7, + 0x061c2006, + 0x061c29a7, + 0x061d0006, + 0x061d09a7, + 0x061de006, + 0x061de9a7, + 0x061ec006, + 0x061ec9a7, + 0x061fa006, + 0x061fa9a7, + 0x06208006, + 0x062089a7, + 0x06216006, + 0x062169a7, + 0x06224006, + 0x062249a7, + 0x06232006, + 0x062329a7, + 0x06240006, + 0x062409a7, + 0x0624e006, + 0x0624e9a7, + 0x0625c006, + 0x0625c9a7, + 0x0626a006, + 0x0626a9a7, + 0x06278006, + 0x062789a7, + 0x06286006, + 0x062869a7, + 0x06294006, + 0x062949a7, + 0x062a2006, + 0x062a29a7, + 0x062b0006, + 0x062b09a7, + 0x062be006, + 0x062be9a7, + 0x062cc006, + 0x062cc9a7, + 0x062da006, + 0x062da9a7, + 0x062e8006, + 0x062e89a7, + 0x062f6006, + 0x062f69a7, + 0x06304006, + 0x063049a7, + 0x06312006, + 0x063129a7, + 0x06320006, + 0x063209a7, + 0x0632e006, + 0x0632e9a7, + 0x0633c006, + 0x0633c9a7, + 0x0634a006, + 0x0634a9a7, + 0x06358006, + 0x063589a7, + 0x06366006, + 0x063669a7, + 0x06374006, + 0x063749a7, + 0x06382006, + 0x063829a7, + 0x06390006, + 0x063909a7, + 0x0639e006, + 0x0639e9a7, + 0x063ac006, + 0x063ac9a7, + 0x063ba006, + 0x063ba9a7, + 0x063c8006, + 0x063c89a7, + 0x063d6006, + 0x063d69a7, + 0x063e4006, + 0x063e49a7, + 0x063f2006, + 0x063f29a7, + 0x06400006, + 0x064009a7, + 0x0640e006, + 0x0640e9a7, + 0x0641c006, + 0x0641c9a7, + 0x0642a006, + 0x0642a9a7, + 0x06438006, + 0x064389a7, + 0x06446006, + 0x064469a7, + 0x06454006, + 0x064549a7, + 0x06462006, + 0x064629a7, + 0x06470006, + 0x064709a7, + 0x0647e006, + 0x0647e9a7, + 0x0648c006, + 0x0648c9a7, + 0x0649a006, + 0x0649a9a7, + 0x064a8006, + 0x064a89a7, + 0x064b6006, + 0x064b69a7, + 0x064c4006, + 0x064c49a7, + 0x064d2006, + 0x064d29a7, + 0x064e0006, + 0x064e09a7, + 0x064ee006, + 0x064ee9a7, + 0x064fc006, + 0x064fc9a7, + 0x0650a006, + 0x0650a9a7, + 0x06518006, + 0x065189a7, + 0x06526006, + 0x065269a7, + 0x06534006, + 0x065349a7, + 0x06542006, + 0x065429a7, + 0x06550006, + 0x065509a7, + 0x0655e006, + 0x0655e9a7, + 0x0656c006, + 0x0656c9a7, + 0x0657a006, + 0x0657a9a7, + 0x06588006, + 0x065889a7, + 0x06596006, + 0x065969a7, + 0x065a4006, + 0x065a49a7, + 0x065b2006, + 0x065b29a7, + 0x065c0006, + 0x065c09a7, + 0x065ce006, + 0x065ce9a7, + 0x065dc006, + 0x065dc9a7, + 0x065ea006, + 0x065ea9a7, + 0x065f8006, + 0x065f89a7, + 0x06606006, + 0x066069a7, + 0x06614006, + 0x066149a7, + 0x06622006, + 0x066229a7, + 0x06630006, + 0x066309a7, + 0x0663e006, + 0x0663e9a7, + 0x0664c006, + 0x0664c9a7, + 0x0665a006, + 0x0665a9a7, + 0x06668006, + 0x066689a7, + 0x06676006, + 0x066769a7, + 0x06684006, + 0x066849a7, + 0x06692006, + 0x066929a7, + 0x066a0006, + 0x066a09a7, + 0x066ae006, + 0x066ae9a7, + 0x066bc006, + 0x066bc9a7, + 0x066ca006, + 0x066ca9a7, + 0x066d8006, + 0x066d89a7, + 0x066e6006, + 0x066e69a7, + 0x066f4006, + 0x066f49a7, + 0x06702006, + 0x067029a7, + 0x06710006, + 0x067109a7, + 0x0671e006, + 0x0671e9a7, + 0x0672c006, + 0x0672c9a7, + 0x0673a006, + 0x0673a9a7, + 0x06748006, + 0x067489a7, + 0x06756006, + 0x067569a7, + 0x06764006, + 0x067649a7, + 0x06772006, + 0x067729a7, + 0x06780006, + 0x067809a7, + 0x0678e006, + 0x0678e9a7, + 0x0679c006, + 0x0679c9a7, + 0x067aa006, + 0x067aa9a7, + 0x067b8006, + 0x067b89a7, + 0x067c6006, + 0x067c69a7, + 0x067d4006, + 0x067d49a7, + 0x067e2006, + 0x067e29a7, + 0x067f0006, + 0x067f09a7, + 0x067fe006, + 0x067fe9a7, + 0x0680c006, + 0x0680c9a7, + 0x0681a006, + 0x0681a9a7, + 0x06828006, + 0x068289a7, + 0x06836006, + 0x068369a7, + 0x06844006, + 0x068449a7, + 0x06852006, + 0x068529a7, + 0x06860006, + 0x068609a7, + 0x0686e006, + 0x0686e9a7, + 0x0687c006, + 0x0687c9a7, + 0x0688a006, + 0x0688a9a7, + 0x06898006, + 0x068989a7, + 0x068a6006, + 0x068a69a7, + 0x068b4006, + 0x068b49a7, + 0x068c2006, + 0x068c29a7, + 0x068d0006, + 0x068d09a7, + 0x068de006, + 0x068de9a7, + 0x068ec006, + 0x068ec9a7, + 0x068fa006, + 0x068fa9a7, + 0x06908006, + 0x069089a7, + 0x06916006, + 0x069169a7, + 0x06924006, + 0x069249a7, + 0x06932006, + 0x069329a7, + 0x06940006, + 0x069409a7, + 0x0694e006, + 0x0694e9a7, + 0x0695c006, + 0x0695c9a7, + 0x0696a006, + 0x0696a9a7, + 0x06978006, + 0x069789a7, + 0x06986006, + 0x069869a7, + 0x06994006, + 0x069949a7, + 0x069a2006, + 0x069a29a7, + 0x069b0006, + 0x069b09a7, + 0x069be006, + 0x069be9a7, + 0x069cc006, + 0x069cc9a7, + 0x069da006, + 0x069da9a7, + 0x069e8006, + 0x069e89a7, + 0x069f6006, + 0x069f69a7, + 0x06a04006, + 0x06a049a7, + 0x06a12006, + 0x06a129a7, + 0x06a20006, + 0x06a209a7, + 0x06a2e006, + 0x06a2e9a7, + 0x06a3c006, + 0x06a3c9a7, + 0x06a4a006, + 0x06a4a9a7, + 0x06a58006, + 0x06a589a7, + 0x06a66006, + 0x06a669a7, + 0x06a74006, + 0x06a749a7, + 0x06a82006, + 0x06a829a7, + 0x06a90006, + 0x06a909a7, + 0x06a9e006, + 0x06a9e9a7, + 0x06aac006, + 0x06aac9a7, + 0x06aba006, + 0x06aba9a7, + 0x06ac8006, + 0x06ac89a7, + 0x06ad6006, + 0x06ad69a7, + 0x06ae4006, + 0x06ae49a7, + 0x06af2006, + 0x06af29a7, + 0x06b00006, + 0x06b009a7, + 0x06b0e006, + 0x06b0e9a7, + 0x06b1c006, + 0x06b1c9a7, + 0x06b2a006, + 0x06b2a9a7, + 0x06b38006, + 0x06b389a7, + 0x06b46006, + 0x06b469a7, + 0x06b54006, + 0x06b549a7, + 0x06b62006, + 0x06b629a7, + 0x06b70006, + 0x06b709a7, + 0x06b7e006, + 0x06b7e9a7, + 0x06b8c006, + 0x06b8c9a7, + 0x06b9a006, + 0x06b9a9a7, + 0x06ba8006, + 0x06ba89a7, + 0x06bb6006, + 0x06bb69a7, + 0x06bc4006, + 0x06bc49a7, + 0x06bd816c, + 0x06be5b0b, + 0x07d8f002, + 0x07f000f2, + 0x07f100f2, + 0x07f7f801, + 0x07fcf012, + 0x07ff80b1, + 0x080fe802, + 0x08170002, + 0x081bb042, + 0x08500822, + 0x08502812, + 0x08506032, + 0x0851c022, + 0x0851f802, + 0x08572812, + 0x08692032, + 0x08755812, + 0x0877e822, + 0x087a30a2, + 0x087c1032, + 0x0880000a, + 0x08800802, + 0x0880100a, + 0x0881c0e2, + 0x08838002, + 0x08839812, + 0x0883f822, + 0x0884100a, + 0x0885802a, + 0x08859832, + 0x0885b81a, + 0x0885c812, + 0x0885e808, + 0x08861002, + 0x08866808, + 0x08880022, + 0x08893842, + 0x0889600a, + 0x08896872, + 0x088a281a, + 0x088b9802, + 0x088c0012, + 0x088c100a, + 0x088d982a, + 0x088db082, + 0x088df81a, + 0x088e1018, + 0x088e4832, + 0x088e700a, + 0x088e7802, + 0x0891602a, + 0x08917822, + 0x0891901a, + 0x0891a002, + 0x0891a80a, + 0x0891b012, + 0x0891f002, + 0x08920802, + 0x0896f802, + 0x0897002a, + 0x08971872, + 0x08980012, + 0x0898101a, + 0x0899d812, + 0x0899f002, + 0x0899f80a, + 0x089a0002, + 0x089a083a, + 0x089a381a, + 0x089a582a, + 0x089ab802, + 0x089b101a, + 0x089b3062, + 0x089b8042, + 0x08a1a82a, + 0x08a1c072, + 0x08a2001a, + 0x08a21022, + 0x08a2280a, + 0x08a23002, + 0x08a2f002, + 0x08a58002, + 0x08a5881a, + 0x08a59852, + 0x08a5c80a, + 0x08a5d002, + 0x08a5d81a, + 0x08a5e802, + 0x08a5f00a, + 0x08a5f812, + 0x08a6080a, + 0x08a61012, + 0x08ad7802, + 0x08ad801a, + 0x08ad9032, + 0x08adc03a, + 0x08ade012, + 0x08adf00a, + 0x08adf812, + 0x08aee012, + 0x08b1802a, + 0x08b19872, + 0x08b1d81a, + 0x08b1e802, + 0x08b1f00a, + 0x08b1f812, + 0x08b55802, + 0x08b5600a, + 0x08b56802, + 0x08b5701a, + 0x08b58052, + 0x08b5b00a, + 0x08b5b802, + 0x08b8e822, + 0x08b91032, + 0x08b9300a, + 0x08b93842, + 0x08c1602a, + 0x08c17882, + 0x08c1c00a, + 0x08c1c812, + 0x08c98002, + 0x08c9884a, + 0x08c9b81a, + 0x08c9d812, + 0x08c9e80a, + 0x08c9f002, + 0x08c9f808, + 0x08ca000a, + 0x08ca0808, + 0x08ca100a, + 0x08ca1802, + 0x08ce882a, + 0x08cea032, + 0x08ced012, + 0x08cee03a, + 0x08cf0002, + 0x08cf200a, + 0x08d00892, + 0x08d19852, + 0x08d1c80a, + 0x08d1d008, + 0x08d1d832, + 0x08d23802, + 0x08d28852, + 0x08d2b81a, + 0x08d2c822, + 0x08d42058, + 0x08d450c2, + 0x08d4b80a, + 0x08d4c012, + 0x08e1780a, + 0x08e18062, + 0x08e1c052, + 0x08e1f00a, + 0x08e1f802, + 0x08e49152, + 0x08e5480a, + 0x08e55062, + 0x08e5880a, + 0x08e59012, + 0x08e5a00a, + 0x08e5a812, + 0x08e98852, + 0x08e9d002, + 0x08e9e012, + 0x08e9f862, + 0x08ea3008, + 0x08ea3802, + 0x08ec504a, + 0x08ec8012, + 0x08ec981a, + 0x08eca802, + 0x08ecb00a, + 0x08ecb802, + 0x08f79812, + 0x08f7a81a, + 0x08f80012, + 0x08f81008, + 0x08f8180a, + 0x08f9a01a, + 0x08f9b042, + 0x08f9f01a, + 0x08fa0002, + 0x08fa080a, + 0x08fa1002, + 0x09a180f1, + 0x09a20002, + 0x09a238e2, + 0x0b578042, + 0x0b598062, + 0x0b7a7802, + 0x0b7a8b6a, + 0x0b7c7832, + 0x0b7f2002, + 0x0b7f801a, + 0x0de4e812, + 0x0de50031, + 0x0e7802d2, + 0x0e798162, + 0x0e8b2802, + 0x0e8b300a, + 0x0e8b3822, + 0x0e8b680a, + 0x0e8b7042, + 0x0e8b9871, + 0x0e8bd872, + 0x0e8c2862, + 0x0e8d5032, + 0x0e921022, + 0x0ed00362, + 0x0ed1db12, + 0x0ed3a802, + 0x0ed42002, + 0x0ed4d842, + 0x0ed508e2, + 0x0f000062, + 0x0f004102, + 0x0f00d862, + 0x0f011812, + 0x0f013042, + 0x0f047802, + 0x0f098062, + 0x0f157002, + 0x0f176032, + 0x0f276032, + 0x0f468062, + 0x0f4a2062, + 0x0f8007f3, + 0x0f8407f3, + 0x0f886823, + 0x0f897803, + 0x0f8b6053, + 0x0f8bf013, + 0x0f8c7003, + 0x0f8c8893, + 0x0f8d6b83, + 0x0f8f3199, + 0x0f9008e3, + 0x0f90d003, + 0x0f917803, + 0x0f919083, + 0x0f91e033, + 0x0f924ff3, + 0x0f964ff3, + 0x0f9a4ff3, + 0x0f9e4b13, + 0x0f9fd842, + 0x0fa007f3, + 0x0fa407f3, + 0x0fa803d3, + 0x0faa37f3, + 0x0fae37f3, + 0x0fb23093, + 0x0fb407f3, + 0x0fbba0b3, + 0x0fbeaaa3, + 0x0fc06033, + 0x0fc24073, + 0x0fc2d053, + 0x0fc44073, + 0x0fc57513, + 0x0fc862e3, + 0x0fc9e093, + 0x0fca3ff3, + 0x0fce3ff3, + 0x0fd23ff3, + 0x0fd63b83, + 0x0fe007f3, + 0x0fe407f3, + 0x0fe807f3, + 0x0fec07f3, + 0x0ff007f3, + 0x0ff407f3, + 0x0ff807f3, + 0x0ffc07d3, + 0x700001f1, + 0x700105f2, + 0x700407f1, + 0x700807f2, + 0x700c06f2, + 0x700f87f1, + 0x701387f1, + 0x701787f1, + 0x701b87f1, + 0x701f87f1, + 0x702387f1, + 0x702787f1, + 0x702b87f1, + 0x702f87f1, + 0x703387f1, + 0x703787f1, + 0x703b87f1, + 0x703f87f1, + 0x704387f1, + 0x704787f1, + 0x704b87f1, + 0x704f87f1, + 0x705387f1, + 0x705787f1, + 0x705b87f1, + 0x705f87f1, + 0x706387f1, + 0x706787f1, + 0x706b87f1, + 0x706f87f1, + 0x707387f1, + 0x707787f1, + 0x707b87f1, + 0x707f80f1}; /// Returns the extended grapheme cluster bondary property of a code point. [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr __property __get_property(const char32_t __code_point) noexcept { - // TODO FMT use std::ranges::upper_bound. - // The algorithm searches for the upper bound of the range and, when found, // steps back one entry. This algorithm is used since the code point can be // anywhere in the range. After a lower bound is found the next step is to @@ -311,7 +1640,7 @@ inline constexpr uint32_t __entries[1480] = { // size. Then the upper bound for code point 3 will return the entry after // 0x1810. After moving to the previous entry the algorithm arrives at the // correct entry. - ptrdiff_t __i = std::upper_bound(__entries, std::end(__entries), (__code_point << 11) | 0x7ffu) - __entries; + ptrdiff_t __i = std::ranges::upper_bound(__entries, (__code_point << 11) | 0x7ffu) - __entries; if (__i == 0) return __property::__none; diff --git a/lib/libcxx/include/__format/format_arg.h b/lib/libcxx/include/__format/format_arg.h index 4f93024b7c..771a03ff2f 100644 --- a/lib/libcxx/include/__format/format_arg.h +++ b/lib/libcxx/include/__format/format_arg.h @@ -45,16 +45,22 @@ namespace __format { /// It could be packed in 4-bits but that means a new type directly becomes an /// ABI break. The packed type is 64-bit so this reduces the maximum number of /// packed elements from 16 to 12. +/// +/// @note Some members of this enum are an extension. These extensions need +/// special behaviour in visit_format_arg. There they need to be wrapped in a +/// handle to satisfy the user observable behaviour. The internal function +/// __visit_format_arg doesn't do this wrapping. So in the format functions +/// this function is used to avoid unneeded overhead. enum class _LIBCPP_ENUM_VIS __arg_t : uint8_t { __none, __boolean, __char_type, __int, __long_long, - __i128, + __i128, // extension __unsigned, __unsigned_long_long, - __u128, + __u128, // extension __float, __double, __long_double, @@ -85,9 +91,11 @@ constexpr __arg_t __get_packed_type(uint64_t __types, size_t __id) { } // namespace __format +// This function is not user obervable, so it can directly use the non-standard +// types of the "variant". See __arg_t for more details. template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT decltype(auto) visit_format_arg(_Visitor&& __vis, - basic_format_arg<_Context> __arg) { +_LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT decltype(auto) +__visit_format_arg(_Visitor&& __vis, basic_format_arg<_Context> __arg) { switch (__arg.__type_) { case __format::__arg_t::__none: return _VSTD::invoke(_VSTD::forward<_Visitor>(__vis), __arg.__value_.__monostate_); @@ -153,7 +161,7 @@ public: using _Dp = remove_cvref_t<_Tp>; using _Formatter = typename _Context::template formatter_type<_Dp>; constexpr bool __const_formattable = - requires { _Formatter().format(declval(), declval<_Context&>()); }; + requires { _Formatter().format(std::declval(), std::declval<_Context&>()); }; using _Qp = conditional_t<__const_formattable, const _Dp, _Dp>; static_assert(__const_formattable || !is_const_v>, "Mandated by [format.arg]/18"); @@ -265,6 +273,28 @@ private: typename __basic_format_arg_value<_Context>::__handle& __handle_; }; +// This function is user facing, so it must wrap the non-standard types of +// the "variant" in a handle to stay conforming. See __arg_t for more details. +template +_LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT decltype(auto) +visit_format_arg(_Visitor&& __vis, basic_format_arg<_Context> __arg) { + switch (__arg.__type_) { +# ifndef _LIBCPP_HAS_NO_INT128 + case __format::__arg_t::__i128: { + typename __basic_format_arg_value<_Context>::__handle __h{__arg.__value_.__i128_}; + return _VSTD::invoke(_VSTD::forward<_Visitor>(__vis), typename basic_format_arg<_Context>::handle{__h}); + } + + case __format::__arg_t::__u128: { + typename __basic_format_arg_value<_Context>::__handle __h{__arg.__value_.__u128_}; + return _VSTD::invoke(_VSTD::forward<_Visitor>(__vis), typename basic_format_arg<_Context>::handle{__h}); + } +# endif + default: + return _VSTD::__visit_format_arg(_VSTD::forward<_Visitor>(__vis), __arg); + } +} + #endif //_LIBCPP_STD_VER > 17 _LIBCPP_END_NAMESPACE_STD diff --git a/lib/libcxx/include/__format/format_arg_store.h b/lib/libcxx/include/__format/format_arg_store.h index 26a5e71b93..6f4f4c3617 100644 --- a/lib/libcxx/include/__format/format_arg_store.h +++ b/lib/libcxx/include/__format/format_arg_store.h @@ -19,6 +19,7 @@ #include <__config> #include <__format/concepts.h> #include <__format/format_arg.h> +#include <__utility/forward.h> #include #include #include @@ -197,7 +198,7 @@ _LIBCPP_HIDE_FROM_ABI void __create_packed_storage(uint64_t& __types, __basic_fo int __shift = 0; ( [&] { - basic_format_arg<_Context> __arg = __create_format_arg<_Context>(__args); + basic_format_arg<_Context> __arg = __format::__create_format_arg<_Context>(__args); if (__shift != 0) __types |= static_cast(__arg.__type_) << __shift; else @@ -211,7 +212,7 @@ _LIBCPP_HIDE_FROM_ABI void __create_packed_storage(uint64_t& __types, __basic_fo template _LIBCPP_HIDE_FROM_ABI void __store_basic_format_arg(basic_format_arg<_Context>* __data, _Args&&... __args) noexcept { - ([&] { *__data++ = __create_format_arg<_Context>(__args); }(), ...); + ([&] { *__data++ = __format::__create_format_arg<_Context>(__args); }(), ...); } template diff --git a/lib/libcxx/include/__format/format_args.h b/lib/libcxx/include/__format/format_args.h index d90dc50acb..8b8fbde92f 100644 --- a/lib/libcxx/include/__format/format_args.h +++ b/lib/libcxx/include/__format/format_args.h @@ -71,6 +71,7 @@ private: const basic_format_arg<_Context>* __args_; }; }; +_LIBCPP_CTAD_SUPPORTED_FOR_TYPE(basic_format_args); #endif //_LIBCPP_STD_VER > 17 diff --git a/lib/libcxx/include/__format/format_context.h b/lib/libcxx/include/__format/format_context.h index b9a41db05d..85e00eb222 100644 --- a/lib/libcxx/include/__format/format_context.h +++ b/lib/libcxx/include/__format/format_context.h @@ -11,14 +11,19 @@ #define _LIBCPP___FORMAT_FORMAT_CONTEXT_H #include <__availability> +#include <__concepts/same_as.h> #include <__config> #include <__format/buffer.h> +#include <__format/format_arg.h> +#include <__format/format_arg_store.h> #include <__format/format_args.h> +#include <__format/format_error.h> #include <__format/format_fwd.h> #include <__iterator/back_insert_iterator.h> #include <__iterator/concepts.h> +#include <__memory/addressof.h> #include <__utility/move.h> -#include +#include <__variant/monostate.h> #include #ifndef _LIBCPP_HAS_NO_LOCALIZATION @@ -50,8 +55,7 @@ __format_context_create( _OutIt __out_it, basic_format_args> __args, optional<_VSTD::locale>&& __loc = nullopt) { - return _VSTD::basic_format_context(_VSTD::move(__out_it), __args, - _VSTD::move(__loc)); + return _VSTD::basic_format_context(_VSTD::move(__out_it), __args, _VSTD::move(__loc)); } #else template @@ -87,9 +91,6 @@ public: template using formatter_type = formatter<_Tp, _CharT>; - basic_format_context(const basic_format_context&) = delete; - basic_format_context& operator=(const basic_format_context&) = delete; - _LIBCPP_HIDE_FROM_ABI basic_format_arg arg(size_t __id) const noexcept { return __args_.get(__id); @@ -101,8 +102,8 @@ public: return *__loc_; } #endif - _LIBCPP_HIDE_FROM_ABI iterator out() { return __out_it_; } - _LIBCPP_HIDE_FROM_ABI void advance_to(iterator __it) { __out_it_ = __it; } + _LIBCPP_HIDE_FROM_ABI iterator out() { return std::move(__out_it_); } + _LIBCPP_HIDE_FROM_ABI void advance_to(iterator __it) { __out_it_ = std::move(__it); } private: iterator __out_it_; @@ -144,6 +145,77 @@ private: #endif }; +// A specialization for __retarget_buffer +// +// See __retarget_buffer for the motivation for this specialization. +// +// This context holds a reference to the instance of the basic_format_context +// that is retargeted. It converts a formatting argument when it is requested +// during formatting. It is expected that the usage of the arguments is rare so +// the lookups are not expected to be used often. An alternative would be to +// convert all elements during construction. +// +// The elements of the retargets context are only used when an underlying +// formatter uses a locale specific formatting or an formatting argument is +// part for the format spec. For example +// format("{:256:{}}", input, 8); +// Here the width of an element in input is determined dynamically. +// Note when the top-level element has no width the retargeting is not needed. +template +class _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT + basic_format_context::__iterator, _CharT> { +public: + using iterator = typename __format::__retarget_buffer<_CharT>::__iterator; + using char_type = _CharT; + template + using formatter_type = formatter<_Tp, _CharT>; + + template + _LIBCPP_HIDE_FROM_ABI explicit basic_format_context(iterator __out_it, _Context& __ctx) + : __out_it_(std::move(__out_it)), +# ifndef _LIBCPP_HAS_NO_LOCALIZATION + __loc_([](void* __c) { return static_cast<_Context*>(__c)->locale(); }), +# endif + __ctx_(std::addressof(__ctx)), + __arg_([](void* __c, size_t __id) { + return std::visit_format_arg( + [&](auto __arg) -> basic_format_arg { + if constexpr (same_as) + return {}; + else if constexpr (same_as::handle>) + // At the moment it's not possible for formatting to use a re-targeted handle. + // TODO FMT add this when support is needed. + std::__throw_format_error("Re-targeting handle not supported"); + else + return basic_format_arg{ + __format::__determine_arg_t(), + __basic_format_arg_value(__arg)}; + }, + static_cast<_Context*>(__c)->arg(__id)); + }) { + } + + _LIBCPP_HIDE_FROM_ABI basic_format_arg arg(size_t __id) const noexcept { + return __arg_(__ctx_, __id); + } +# ifndef _LIBCPP_HAS_NO_LOCALIZATION + _LIBCPP_HIDE_FROM_ABI _VSTD::locale locale() { return __loc_(__ctx_); } +# endif + _LIBCPP_HIDE_FROM_ABI iterator out() { return std::move(__out_it_); } + _LIBCPP_HIDE_FROM_ABI void advance_to(iterator __it) { __out_it_ = std::move(__it); } + +private: + iterator __out_it_; + +# ifndef _LIBCPP_HAS_NO_LOCALIZATION + std::locale (*__loc_)(void* __ctx); +# endif + + void* __ctx_; + basic_format_arg (*__arg_)(void* __ctx, size_t __id); +}; + +_LIBCPP_CTAD_SUPPORTED_FOR_TYPE(basic_format_context); #endif //_LIBCPP_STD_VER > 17 _LIBCPP_END_NAMESPACE_STD diff --git a/lib/libcxx/include/__format/format_error.h b/lib/libcxx/include/__format/format_error.h index 67ff41cbc3..002d1a40a2 100644 --- a/lib/libcxx/include/__format/format_error.h +++ b/lib/libcxx/include/__format/format_error.h @@ -11,11 +11,8 @@ #define _LIBCPP___FORMAT_FORMAT_ERROR_H #include <__config> -#include - -#ifdef _LIBCPP_NO_EXCEPTIONS #include -#endif +#include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header @@ -31,7 +28,14 @@ public: : runtime_error(__s) {} _LIBCPP_HIDE_FROM_ABI explicit format_error(const char* __s) : runtime_error(__s) {} - virtual ~format_error() noexcept; + // TODO FMT Remove when format is no longer experimental. + // Avoids linker errors when building the Clang-cl Windows DLL which doesn't + // support the experimental library. +# ifndef _LIBCPP_INLINE_FORMAT_ERROR_DTOR + ~format_error() noexcept override; +# else + ~format_error() noexcept override {} +# endif }; _LIBCPP_NORETURN inline _LIBCPP_HIDE_FROM_ABI void diff --git a/lib/libcxx/include/__format/format_functions.h b/lib/libcxx/include/__format/format_functions.h new file mode 100644 index 0000000000..185148ccba --- /dev/null +++ b/lib/libcxx/include/__format/format_functions.h @@ -0,0 +1,661 @@ +// -*- 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_FORMAT_FUNCTIONS +#define _LIBCPP___FORMAT_FORMAT_FUNCTIONS + +// TODO FMT This is added to fix Apple back-deployment. +#include +#if !defined(_LIBCPP_HAS_NO_INCOMPLETE_FORMAT) + +#include <__algorithm/clamp.h> +#include <__availability> +#include <__concepts/convertible_to.h> +#include <__concepts/same_as.h> +#include <__config> +#include <__debug> +#include <__format/buffer.h> +#include <__format/format_arg.h> +#include <__format/format_arg_store.h> +#include <__format/format_args.h> +#include <__format/format_context.h> +#include <__format/format_error.h> +#include <__format/format_parse_context.h> +#include <__format/format_string.h> +#include <__format/format_to_n_result.h> +#include <__format/formatter.h> +#include <__format/formatter_bool.h> +#include <__format/formatter_char.h> +#include <__format/formatter_floating_point.h> +#include <__format/formatter_integer.h> +#include <__format/formatter_pointer.h> +#include <__format/formatter_string.h> +#include <__format/parser_std_format_spec.h> +#include <__iterator/back_insert_iterator.h> +#include <__iterator/incrementable_traits.h> +#include <__variant/monostate.h> +#include +#include +#include + +#ifndef _LIBCPP_HAS_NO_LOCALIZATION +#include +#endif + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +#if _LIBCPP_STD_VER > 17 + +// TODO FMT Evaluate which templates should be external templates. This +// improves the efficiency of the header. However since the header is still +// under heavy development and not all classes are stable it makes no sense +// to do this optimization now. + +using format_args = basic_format_args; +#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS +using wformat_args = basic_format_args; +#endif + +template +_LIBCPP_HIDE_FROM_ABI __format_arg_store<_Context, _Args...> make_format_args(_Args&&... __args) { + return _VSTD::__format_arg_store<_Context, _Args...>(__args...); +} + +#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS +template +_LIBCPP_HIDE_FROM_ABI __format_arg_store make_wformat_args(_Args&&... __args) { + return _VSTD::__format_arg_store(__args...); +} +#endif + +namespace __format { + +/// Helper class parse and handle argument. +/// +/// When parsing a handle which is not enabled the code is ill-formed. +/// This helper uses the parser of the appropriate formatter for the stored type. +template +class _LIBCPP_TEMPLATE_VIS __compile_time_handle { +public: + _LIBCPP_HIDE_FROM_ABI + constexpr void __parse(basic_format_parse_context<_CharT>& __parse_ctx) const { __parse_(__parse_ctx); } + + template + _LIBCPP_HIDE_FROM_ABI constexpr void __enable() { + __parse_ = [](basic_format_parse_context<_CharT>& __parse_ctx) { + formatter<_Tp, _CharT> __f; + __parse_ctx.advance_to(__f.parse(__parse_ctx)); + }; + } + + // Before calling __parse the proper handler needs to be set with __enable. + // The default handler isn't a core constant expression. + _LIBCPP_HIDE_FROM_ABI constexpr __compile_time_handle() + : __parse_([](basic_format_parse_context<_CharT>&) { std::__throw_format_error("Not a handle"); }) {} + +private: + void (*__parse_)(basic_format_parse_context<_CharT>&); +}; + +// Dummy format_context only providing the parts used during constant +// validation of the basic_format_string. +template +struct _LIBCPP_TEMPLATE_VIS __compile_time_basic_format_context { +public: + using char_type = _CharT; + + _LIBCPP_HIDE_FROM_ABI constexpr explicit __compile_time_basic_format_context( + const __arg_t* __args, const __compile_time_handle<_CharT>* __handles, size_t __size) + : __args_(__args), __handles_(__handles), __size_(__size) {} + + // During the compile-time validation nothing needs to be written. + // Therefore all operations of this iterator are a NOP. + struct iterator { + _LIBCPP_HIDE_FROM_ABI constexpr iterator& operator=(_CharT) { return *this; } + _LIBCPP_HIDE_FROM_ABI constexpr iterator& operator*() { return *this; } + _LIBCPP_HIDE_FROM_ABI constexpr iterator operator++(int) { return *this; } + }; + + _LIBCPP_HIDE_FROM_ABI constexpr __arg_t arg(size_t __id) const { + if (__id >= __size_) + std::__throw_format_error("Argument index out of bounds"); + return __args_[__id]; + } + + _LIBCPP_HIDE_FROM_ABI constexpr const __compile_time_handle<_CharT>& __handle(size_t __id) const { + if (__id >= __size_) + std::__throw_format_error("Argument index out of bounds"); + return __handles_[__id]; + } + + _LIBCPP_HIDE_FROM_ABI constexpr iterator out() { return {}; } + _LIBCPP_HIDE_FROM_ABI constexpr void advance_to(iterator) {} + +private: + const __arg_t* __args_; + const __compile_time_handle<_CharT>* __handles_; + size_t __size_; +}; + +_LIBCPP_HIDE_FROM_ABI +constexpr void __compile_time_validate_integral(__arg_t __type) { + switch (__type) { + case __arg_t::__int: + case __arg_t::__long_long: + case __arg_t::__i128: + case __arg_t::__unsigned: + case __arg_t::__unsigned_long_long: + case __arg_t::__u128: + return; + + default: + std::__throw_format_error("Argument isn't an integral type"); + } +} + +// _HasPrecision does the formatter have a precision? +template +_LIBCPP_HIDE_FROM_ABI constexpr void +__compile_time_validate_argument(basic_format_parse_context<_CharT>& __parse_ctx, + __compile_time_basic_format_context<_CharT>& __ctx) { + formatter<_Tp, _CharT> __formatter; + __parse_ctx.advance_to(__formatter.parse(__parse_ctx)); + // [format.string.std]/7 + // ... If the corresponding formatting argument is not of integral type, or + // its value is negative for precision or non-positive for width, an + // exception of type format_error is thrown. + // + // Validate whether the arguments are integrals. + if (__formatter.__parser_.__width_as_arg_) + __format::__compile_time_validate_integral(__ctx.arg(__formatter.__parser_.__width_)); + + if constexpr (_HasPrecision) + if (__formatter.__parser_.__precision_as_arg_) + __format::__compile_time_validate_integral(__ctx.arg(__formatter.__parser_.__precision_)); +} + +// This function is not user facing, so it can directly use the non-standard types of the "variant". +template +_LIBCPP_HIDE_FROM_ABI constexpr void __compile_time_visit_format_arg(basic_format_parse_context<_CharT>& __parse_ctx, + __compile_time_basic_format_context<_CharT>& __ctx, + __arg_t __type) { + switch (__type) { + case __arg_t::__none: + std::__throw_format_error("Invalid argument"); + case __arg_t::__boolean: + return __format::__compile_time_validate_argument<_CharT, bool>(__parse_ctx, __ctx); + case __arg_t::__char_type: + return __format::__compile_time_validate_argument<_CharT, _CharT>(__parse_ctx, __ctx); + case __arg_t::__int: + return __format::__compile_time_validate_argument<_CharT, int>(__parse_ctx, __ctx); + case __arg_t::__long_long: + return __format::__compile_time_validate_argument<_CharT, long long>(__parse_ctx, __ctx); + case __arg_t::__i128: +# ifndef _LIBCPP_HAS_NO_INT128 + return __format::__compile_time_validate_argument<_CharT, __int128_t>(__parse_ctx, __ctx); +# else + std::__throw_format_error("Invalid argument"); +# endif + return; + case __arg_t::__unsigned: + return __format::__compile_time_validate_argument<_CharT, unsigned>(__parse_ctx, __ctx); + case __arg_t::__unsigned_long_long: + return __format::__compile_time_validate_argument<_CharT, unsigned long long>(__parse_ctx, __ctx); + case __arg_t::__u128: +# ifndef _LIBCPP_HAS_NO_INT128 + return __format::__compile_time_validate_argument<_CharT, __uint128_t>(__parse_ctx, __ctx); +# else + std::__throw_format_error("Invalid argument"); +# endif + return; + case __arg_t::__float: + return __format::__compile_time_validate_argument<_CharT, float, true>(__parse_ctx, __ctx); + case __arg_t::__double: + return __format::__compile_time_validate_argument<_CharT, double, true>(__parse_ctx, __ctx); + case __arg_t::__long_double: + return __format::__compile_time_validate_argument<_CharT, long double, true>(__parse_ctx, __ctx); + case __arg_t::__const_char_type_ptr: + return __format::__compile_time_validate_argument<_CharT, const _CharT*, true>(__parse_ctx, __ctx); + case __arg_t::__string_view: + return __format::__compile_time_validate_argument<_CharT, basic_string_view<_CharT>, true>(__parse_ctx, __ctx); + case __arg_t::__ptr: + return __format::__compile_time_validate_argument<_CharT, const void*>(__parse_ctx, __ctx); + case __arg_t::__handle: + std::__throw_format_error("Handle should use __compile_time_validate_handle_argument"); + } + std::__throw_format_error("Invalid argument"); +} + +template +_LIBCPP_HIDE_FROM_ABI constexpr const _CharT* +__handle_replacement_field(const _CharT* __begin, const _CharT* __end, + _ParseCtx& __parse_ctx, _Ctx& __ctx) { + __format::__parse_number_result __r = __format::__parse_arg_id(__begin, __end, __parse_ctx); + + bool __parse = *__r.__ptr == _CharT(':'); + switch (*__r.__ptr) { + case _CharT(':'): + // The arg-id has a format-specifier, advance the input to the format-spec. + __parse_ctx.advance_to(__r.__ptr + 1); + break; + case _CharT('}'): + // The arg-id has no format-specifier. + __parse_ctx.advance_to(__r.__ptr); + break; + default: + std::__throw_format_error("The replacement field arg-id should terminate at a ':' or '}'"); + } + + if constexpr (same_as<_Ctx, __compile_time_basic_format_context<_CharT>>) { + __arg_t __type = __ctx.arg(__r.__value); + if (__type == __arg_t::__handle) + __ctx.__handle(__r.__value).__parse(__parse_ctx); + else + __format::__compile_time_visit_format_arg(__parse_ctx, __ctx, __type); + } else + _VSTD::__visit_format_arg( + [&](auto __arg) { + if constexpr (same_as) + std::__throw_format_error("Argument index out of bounds"); + else if constexpr (same_as::handle>) + __arg.format(__parse_ctx, __ctx); + else { + formatter __formatter; + if (__parse) + __parse_ctx.advance_to(__formatter.parse(__parse_ctx)); + __ctx.advance_to(__formatter.format(__arg, __ctx)); + } + }, + __ctx.arg(__r.__value)); + + __begin = __parse_ctx.begin(); + if (__begin == __end || *__begin != _CharT('}')) + std::__throw_format_error("The replacement field misses a terminating '}'"); + + return ++__begin; +} + +template +_LIBCPP_HIDE_FROM_ABI constexpr typename _Ctx::iterator +__vformat_to(_ParseCtx&& __parse_ctx, _Ctx&& __ctx) { + using _CharT = typename _ParseCtx::char_type; + static_assert(same_as); + + const _CharT* __begin = __parse_ctx.begin(); + const _CharT* __end = __parse_ctx.end(); + typename _Ctx::iterator __out_it = __ctx.out(); + while (__begin != __end) { + switch (*__begin) { + case _CharT('{'): + ++__begin; + if (__begin == __end) + std::__throw_format_error("The format string terminates at a '{'"); + + if (*__begin != _CharT('{')) [[likely]] { + __ctx.advance_to(_VSTD::move(__out_it)); + __begin = + __format::__handle_replacement_field(__begin, __end, __parse_ctx, __ctx); + __out_it = __ctx.out(); + + // The output is written and __begin points to the next character. So + // start the next iteration. + continue; + } + // The string is an escape character. + break; + + case _CharT('}'): + ++__begin; + if (__begin == __end || *__begin != _CharT('}')) + std::__throw_format_error("The format string contains an invalid escape sequence"); + + break; + } + + // Copy the character to the output verbatim. + *__out_it++ = *__begin++; + } + return __out_it; +} + +} // namespace __format + +template +struct _LIBCPP_TEMPLATE_VIS basic_format_string { + template + requires convertible_to> + consteval basic_format_string(const _Tp& __str) : __str_{__str} { + __format::__vformat_to(basic_format_parse_context<_CharT>{__str_, sizeof...(_Args)}, + _Context{__types_.data(), __handles_.data(), sizeof...(_Args)}); + } + + _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT constexpr basic_string_view<_CharT> get() const noexcept { + return __str_; + } + +private: + basic_string_view<_CharT> __str_; + + using _Context = __format::__compile_time_basic_format_context<_CharT>; + + static constexpr array<__format::__arg_t, sizeof...(_Args)> __types_{ + __format::__determine_arg_t<_Context, remove_cvref_t<_Args>>()...}; + + // TODO FMT remove this work-around when the AIX ICE has been resolved. +# if defined(_AIX) && defined(_LIBCPP_CLANG_VER) && _LIBCPP_CLANG_VER < 1400 + template + static constexpr __format::__compile_time_handle<_CharT> __get_handle() { + __format::__compile_time_handle<_CharT> __handle; + if (__format::__determine_arg_t<_Context, _Tp>() == __format::__arg_t::__handle) + __handle.template __enable<_Tp>(); + + return __handle; + } + + static constexpr array<__format::__compile_time_handle<_CharT>, sizeof...(_Args)> __handles_{ + __get_handle<_Args>()...}; +# else + static constexpr array<__format::__compile_time_handle<_CharT>, sizeof...(_Args)> __handles_{[] { + using _Tp = remove_cvref_t<_Args>; + __format::__compile_time_handle<_CharT> __handle; + if (__format::__determine_arg_t<_Context, _Tp>() == __format::__arg_t::__handle) + __handle.template __enable<_Tp>(); + + return __handle; + }()...}; +# endif +}; + +template +using format_string = basic_format_string...>; + +#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS +template +using wformat_string = basic_format_string...>; +#endif + +template +requires(output_iterator<_OutIt, const _CharT&>) _LIBCPP_HIDE_FROM_ABI _OutIt + __vformat_to( + _OutIt __out_it, basic_string_view<_CharT> __fmt, + basic_format_args> __args) { + if constexpr (same_as<_OutIt, _FormatOutIt>) + return _VSTD::__format::__vformat_to(basic_format_parse_context{__fmt, __args.__size()}, + _VSTD::__format_context_create(_VSTD::move(__out_it), __args)); + else { + __format::__format_buffer<_OutIt, _CharT> __buffer{_VSTD::move(__out_it)}; + _VSTD::__format::__vformat_to(basic_format_parse_context{__fmt, __args.__size()}, + _VSTD::__format_context_create(__buffer.__make_output_iterator(), __args)); + return _VSTD::move(__buffer).__out_it(); + } +} + +// The function is _LIBCPP_ALWAYS_INLINE since the compiler is bad at inlining +// https://reviews.llvm.org/D110499#inline-1180704 +// TODO FMT Evaluate whether we want to file a Clang bug report regarding this. +template _OutIt> +_LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT _OutIt +vformat_to(_OutIt __out_it, string_view __fmt, format_args __args) { + return _VSTD::__vformat_to(_VSTD::move(__out_it), __fmt, __args); +} + +#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS +template _OutIt> +_LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT _OutIt +vformat_to(_OutIt __out_it, wstring_view __fmt, wformat_args __args) { + return _VSTD::__vformat_to(_VSTD::move(__out_it), __fmt, __args); +} +#endif + +template _OutIt, class... _Args> +_LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT _OutIt +format_to(_OutIt __out_it, format_string<_Args...> __fmt, _Args&&... __args) { + return _VSTD::vformat_to(_VSTD::move(__out_it), __fmt.get(), + _VSTD::make_format_args(__args...)); +} + +#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS +template _OutIt, class... _Args> +_LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT _OutIt +format_to(_OutIt __out_it, wformat_string<_Args...> __fmt, _Args&&... __args) { + return _VSTD::vformat_to(_VSTD::move(__out_it), __fmt.get(), + _VSTD::make_wformat_args(__args...)); +} +#endif + +_LIBCPP_ALWAYS_INLINE inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT string +vformat(string_view __fmt, format_args __args) { + string __res; + _VSTD::vformat_to(_VSTD::back_inserter(__res), __fmt, __args); + return __res; +} + +#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS +_LIBCPP_ALWAYS_INLINE inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT wstring +vformat(wstring_view __fmt, wformat_args __args) { + wstring __res; + _VSTD::vformat_to(_VSTD::back_inserter(__res), __fmt, __args); + return __res; +} +#endif + +template +_LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT string format(format_string<_Args...> __fmt, + _Args&&... __args) { + return _VSTD::vformat(__fmt.get(), _VSTD::make_format_args(__args...)); +} + +#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS +template +_LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT wstring +format(wformat_string<_Args...> __fmt, _Args&&... __args) { + return _VSTD::vformat(__fmt.get(), _VSTD::make_wformat_args(__args...)); +} +#endif + +template +_LIBCPP_HIDE_FROM_ABI format_to_n_result<_OutIt> __vformat_to_n(_OutIt __out_it, iter_difference_t<_OutIt> __n, + basic_string_view<_CharT> __fmt, + basic_format_args<_Context> __args) { + __format::__format_to_n_buffer<_OutIt, _CharT> __buffer{_VSTD::move(__out_it), __n}; + _VSTD::__format::__vformat_to(basic_format_parse_context{__fmt, __args.__size()}, + _VSTD::__format_context_create(__buffer.__make_output_iterator(), __args)); + return _VSTD::move(__buffer).__result(); +} + +template _OutIt, class... _Args> +_LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT format_to_n_result<_OutIt> +format_to_n(_OutIt __out_it, iter_difference_t<_OutIt> __n, format_string<_Args...> __fmt, _Args&&... __args) { + return _VSTD::__vformat_to_n(_VSTD::move(__out_it), __n, __fmt.get(), _VSTD::make_format_args(__args...)); +} + +#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS +template _OutIt, class... _Args> +_LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT format_to_n_result<_OutIt> +format_to_n(_OutIt __out_it, iter_difference_t<_OutIt> __n, wformat_string<_Args...> __fmt, + _Args&&... __args) { + return _VSTD::__vformat_to_n(_VSTD::move(__out_it), __n, __fmt.get(), _VSTD::make_wformat_args(__args...)); +} +#endif + +template +_LIBCPP_HIDE_FROM_ABI size_t __vformatted_size(basic_string_view<_CharT> __fmt, auto __args) { + __format::__formatted_size_buffer<_CharT> __buffer; + _VSTD::__format::__vformat_to(basic_format_parse_context{__fmt, __args.__size()}, + _VSTD::__format_context_create(__buffer.__make_output_iterator(), __args)); + return _VSTD::move(__buffer).__result(); +} + +template +_LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT size_t +formatted_size(format_string<_Args...> __fmt, _Args&&... __args) { + return _VSTD::__vformatted_size(__fmt.get(), basic_format_args{_VSTD::make_format_args(__args...)}); +} + +#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS +template +_LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT size_t +formatted_size(wformat_string<_Args...> __fmt, _Args&&... __args) { + return _VSTD::__vformatted_size(__fmt.get(), basic_format_args{_VSTD::make_wformat_args(__args...)}); +} +#endif + +#ifndef _LIBCPP_HAS_NO_LOCALIZATION + +template +requires(output_iterator<_OutIt, const _CharT&>) _LIBCPP_HIDE_FROM_ABI _OutIt + __vformat_to( + _OutIt __out_it, locale __loc, basic_string_view<_CharT> __fmt, + basic_format_args> __args) { + if constexpr (same_as<_OutIt, _FormatOutIt>) + return _VSTD::__format::__vformat_to( + basic_format_parse_context{__fmt, __args.__size()}, + _VSTD::__format_context_create(_VSTD::move(__out_it), __args, _VSTD::move(__loc))); + else { + __format::__format_buffer<_OutIt, _CharT> __buffer{_VSTD::move(__out_it)}; + _VSTD::__format::__vformat_to( + basic_format_parse_context{__fmt, __args.__size()}, + _VSTD::__format_context_create(__buffer.__make_output_iterator(), __args, _VSTD::move(__loc))); + return _VSTD::move(__buffer).__out_it(); + } +} + +template _OutIt> +_LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT _OutIt vformat_to( + _OutIt __out_it, locale __loc, string_view __fmt, format_args __args) { + return _VSTD::__vformat_to(_VSTD::move(__out_it), _VSTD::move(__loc), __fmt, + __args); +} + +#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS +template _OutIt> +_LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT _OutIt vformat_to( + _OutIt __out_it, locale __loc, wstring_view __fmt, wformat_args __args) { + return _VSTD::__vformat_to(_VSTD::move(__out_it), _VSTD::move(__loc), __fmt, + __args); +} +#endif + +template _OutIt, class... _Args> +_LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT _OutIt +format_to(_OutIt __out_it, locale __loc, format_string<_Args...> __fmt, _Args&&... __args) { + return _VSTD::vformat_to(_VSTD::move(__out_it), _VSTD::move(__loc), __fmt.get(), + _VSTD::make_format_args(__args...)); +} + +#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS +template _OutIt, class... _Args> +_LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT _OutIt +format_to(_OutIt __out_it, locale __loc, wformat_string<_Args...> __fmt, _Args&&... __args) { + return _VSTD::vformat_to(_VSTD::move(__out_it), _VSTD::move(__loc), __fmt.get(), + _VSTD::make_wformat_args(__args...)); +} +#endif + +_LIBCPP_ALWAYS_INLINE inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT string +vformat(locale __loc, string_view __fmt, format_args __args) { + string __res; + _VSTD::vformat_to(_VSTD::back_inserter(__res), _VSTD::move(__loc), __fmt, + __args); + return __res; +} + +#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS +_LIBCPP_ALWAYS_INLINE inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT wstring +vformat(locale __loc, wstring_view __fmt, wformat_args __args) { + wstring __res; + _VSTD::vformat_to(_VSTD::back_inserter(__res), _VSTD::move(__loc), __fmt, + __args); + return __res; +} +#endif + +template +_LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT string format(locale __loc, + format_string<_Args...> __fmt, + _Args&&... __args) { + return _VSTD::vformat(_VSTD::move(__loc), __fmt.get(), + _VSTD::make_format_args(__args...)); +} + +#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS +template +_LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT wstring +format(locale __loc, wformat_string<_Args...> __fmt, _Args&&... __args) { + return _VSTD::vformat(_VSTD::move(__loc), __fmt.get(), + _VSTD::make_wformat_args(__args...)); +} +#endif + +template +_LIBCPP_HIDE_FROM_ABI format_to_n_result<_OutIt> __vformat_to_n(_OutIt __out_it, iter_difference_t<_OutIt> __n, + locale __loc, basic_string_view<_CharT> __fmt, + basic_format_args<_Context> __args) { + __format::__format_to_n_buffer<_OutIt, _CharT> __buffer{_VSTD::move(__out_it), __n}; + _VSTD::__format::__vformat_to( + basic_format_parse_context{__fmt, __args.__size()}, + _VSTD::__format_context_create(__buffer.__make_output_iterator(), __args, _VSTD::move(__loc))); + return _VSTD::move(__buffer).__result(); +} + +template _OutIt, class... _Args> +_LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT format_to_n_result<_OutIt> +format_to_n(_OutIt __out_it, iter_difference_t<_OutIt> __n, locale __loc, format_string<_Args...> __fmt, + _Args&&... __args) { + return _VSTD::__vformat_to_n(_VSTD::move(__out_it), __n, _VSTD::move(__loc), __fmt.get(), + _VSTD::make_format_args(__args...)); +} + +#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS +template _OutIt, class... _Args> +_LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT format_to_n_result<_OutIt> +format_to_n(_OutIt __out_it, iter_difference_t<_OutIt> __n, locale __loc, wformat_string<_Args...> __fmt, + _Args&&... __args) { + return _VSTD::__vformat_to_n(_VSTD::move(__out_it), __n, _VSTD::move(__loc), __fmt.get(), + _VSTD::make_wformat_args(__args...)); +} +#endif + +template +_LIBCPP_HIDE_FROM_ABI size_t __vformatted_size(locale __loc, basic_string_view<_CharT> __fmt, auto __args) { + __format::__formatted_size_buffer<_CharT> __buffer; + _VSTD::__format::__vformat_to( + basic_format_parse_context{__fmt, __args.__size()}, + _VSTD::__format_context_create(__buffer.__make_output_iterator(), __args, _VSTD::move(__loc))); + return _VSTD::move(__buffer).__result(); +} + +template +_LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT size_t +formatted_size(locale __loc, format_string<_Args...> __fmt, _Args&&... __args) { + return _VSTD::__vformatted_size(_VSTD::move(__loc), __fmt.get(), basic_format_args{_VSTD::make_format_args(__args...)}); +} + +#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS +template +_LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT size_t +formatted_size(locale __loc, wformat_string<_Args...> __fmt, _Args&&... __args) { + return _VSTD::__vformatted_size(_VSTD::move(__loc), __fmt.get(), basic_format_args{_VSTD::make_wformat_args(__args...)}); +} +#endif + +#endif // _LIBCPP_HAS_NO_LOCALIZATION + + +#endif //_LIBCPP_STD_VER > 17 + +_LIBCPP_END_NAMESPACE_STD + +#endif // !defined(_LIBCPP_HAS_NO_INCOMPLETE_FORMAT) + +#endif // _LIBCPP___FORMAT_FORMAT_FUNCTIONS diff --git a/lib/libcxx/include/__format/format_parse_context.h b/lib/libcxx/include/__format/format_parse_context.h index 272b615d10..30e3a7dfda 100644 --- a/lib/libcxx/include/__format/format_parse_context.h +++ b/lib/libcxx/include/__format/format_parse_context.h @@ -54,8 +54,7 @@ public: _LIBCPP_HIDE_FROM_ABI constexpr size_t next_arg_id() { if (__indexing_ == __manual) - __throw_format_error("Using automatic argument numbering in manual " - "argument numbering mode"); + std::__throw_format_error("Using automatic argument numbering in manual argument numbering mode"); if (__indexing_ == __unknown) __indexing_ = __automatic; @@ -63,8 +62,7 @@ public: } _LIBCPP_HIDE_FROM_ABI constexpr void check_arg_id(size_t __id) { if (__indexing_ == __automatic) - __throw_format_error("Using manual argument numbering in automatic " - "argument numbering mode"); + std::__throw_format_error("Using manual argument numbering in automatic argument numbering mode"); if (__indexing_ == __unknown) __indexing_ = __manual; @@ -77,7 +75,7 @@ public: // Note: the Throws clause [format.parse.ctx]/10 doesn't specify the // behavior when id >= num_args_. if (is_constant_evaluated() && __id >= __num_args_) - __throw_format_error("Argument index outside the valid range"); + std::__throw_format_error("Argument index outside the valid range"); } private: @@ -88,6 +86,7 @@ private: size_t __next_arg_id_; size_t __num_args_; }; +_LIBCPP_CTAD_SUPPORTED_FOR_TYPE(basic_format_parse_context); using format_parse_context = basic_format_parse_context; #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS diff --git a/lib/libcxx/include/__format/format_string.h b/lib/libcxx/include/__format/format_string.h index 51c3c7a1a6..d9caf866a1 100644 --- a/lib/libcxx/include/__format/format_string.h +++ b/lib/libcxx/include/__format/format_string.h @@ -32,6 +32,9 @@ struct _LIBCPP_TEMPLATE_VIS __parse_number_result { uint32_t __value; }; +template +__parse_number_result(const _CharT*, uint32_t) -> __parse_number_result<_CharT>; + template _LIBCPP_HIDE_FROM_ABI constexpr __parse_number_result<_CharT> __parse_number(const _CharT* __begin, const _CharT* __end); @@ -70,7 +73,7 @@ __parse_automatic(const _CharT* __begin, const _CharT*, auto& __parse_ctx) { template _LIBCPP_HIDE_FROM_ABI constexpr __parse_number_result<_CharT> __parse_manual(const _CharT* __begin, const _CharT* __end, auto& __parse_ctx) { - __parse_number_result<_CharT> __r = __parse_number(__begin, __end); + __parse_number_result<_CharT> __r = __format::__parse_number(__begin, __end); __parse_ctx.check_arg_id(__r.__value); return __r; } @@ -117,7 +120,7 @@ __parse_number(const _CharT* __begin, const _CharT* __end_input) { if (__v > __number_max || (__begin != __end_input && *__begin >= _CharT('0') && *__begin <= _CharT('9'))) - __throw_format_error("The numeric value of the format-spec is too large"); + std::__throw_format_error("The numeric value of the format-spec is too large"); __value = __v; } @@ -146,8 +149,7 @@ __parse_arg_id(const _CharT* __begin, const _CharT* __end, auto& __parse_ctx) { return __detail::__parse_automatic(__begin, __end, __parse_ctx); } if (*__begin < _CharT('0') || *__begin > _CharT('9')) - __throw_format_error( - "The arg-id of the format-spec starts with an invalid character"); + std::__throw_format_error("The arg-id of the format-spec starts with an invalid character"); return __detail::__parse_manual(__begin, __end, __parse_ctx); } diff --git a/lib/libcxx/include/__format/format_to_n_result.h b/lib/libcxx/include/__format/format_to_n_result.h index 25caa1c9e9..f1ed9a0982 100644 --- a/lib/libcxx/include/__format/format_to_n_result.h +++ b/lib/libcxx/include/__format/format_to_n_result.h @@ -26,6 +26,7 @@ struct _LIBCPP_TEMPLATE_VIS format_to_n_result { _OutIt out; iter_difference_t<_OutIt> size; }; +_LIBCPP_CTAD_SUPPORTED_FOR_TYPE(format_to_n_result); #endif //_LIBCPP_STD_VER > 17 diff --git a/lib/libcxx/include/__format/formatter.h b/lib/libcxx/include/__format/formatter.h index 4816f961c4..900a09af4e 100644 --- a/lib/libcxx/include/__format/formatter.h +++ b/lib/libcxx/include/__format/formatter.h @@ -11,7 +11,6 @@ #define _LIBCPP___FORMAT_FORMATTER_H #include <__availability> -#include <__concepts/same_as.h> #include <__config> #include <__format/format_fwd.h> @@ -39,15 +38,16 @@ struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter { formatter& operator=(const formatter&) = delete; }; -namespace __formatter { +# if _LIBCPP_STD_VER > 20 -/** The character types that formatters are specialized for. */ -template -concept __char_type = same_as<_CharT, char> || same_as<_CharT, wchar_t>; +template +_LIBCPP_HIDE_FROM_ABI constexpr void __set_debug_format(_Tp& __formatter) { + if constexpr (requires { __formatter.set_debug_format(); }) + __formatter.set_debug_format(); +} -} // namespace __formatter - -#endif //_LIBCPP_STD_VER > 17 +# endif // _LIBCPP_STD_VER > 20 +#endif // _LIBCPP_STD_VER > 17 _LIBCPP_END_NAMESPACE_STD diff --git a/lib/libcxx/include/__format/formatter_bool.h b/lib/libcxx/include/__format/formatter_bool.h index cdb0631f87..0d005a1bee 100644 --- a/lib/libcxx/include/__format/formatter_bool.h +++ b/lib/libcxx/include/__format/formatter_bool.h @@ -14,8 +14,8 @@ #include <__availability> #include <__config> #include <__debug> +#include <__format/concepts.h> #include <__format/format_error.h> -#include <__format/format_fwd.h> #include <__format/format_parse_context.h> #include <__format/formatter.h> #include <__format/formatter_integral.h> @@ -35,7 +35,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD #if _LIBCPP_STD_VER > 17 -template <__formatter::__char_type _CharT> +template <__fmt_char_type _CharT> struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter { public: _LIBCPP_HIDE_FROM_ABI constexpr auto diff --git a/lib/libcxx/include/__format/formatter_char.h b/lib/libcxx/include/__format/formatter_char.h index a3ca36ec0a..8a92e7445b 100644 --- a/lib/libcxx/include/__format/formatter_char.h +++ b/lib/libcxx/include/__format/formatter_char.h @@ -13,7 +13,7 @@ #include <__availability> #include <__concepts/same_as.h> #include <__config> -#include <__format/format_fwd.h> +#include <__format/concepts.h> #include <__format/format_parse_context.h> #include <__format/formatter.h> #include <__format/formatter_integral.h> @@ -30,7 +30,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD #if _LIBCPP_STD_VER > 17 -template <__formatter::__char_type _CharT> +template <__fmt_char_type _CharT> struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT __formatter_char { public: _LIBCPP_HIDE_FROM_ABI constexpr auto @@ -44,6 +44,11 @@ public: if (__parser_.__type_ == __format_spec::__type::__default || __parser_.__type_ == __format_spec::__type::__char) return __formatter::__format_char(__value, __ctx.out(), __parser_.__get_parsed_std_specifications(__ctx)); +# if _LIBCPP_STD_VER > 20 + if (__parser_.__type_ == __format_spec::__type::__debug) + return __formatter::__format_escaped_char(__value, __ctx.out(), __parser_.__get_parsed_std_specifications(__ctx)); +# endif + if constexpr (sizeof(_CharT) <= sizeof(int)) // Promotes _CharT to an integral type. This reduces the number of // instantiations of __format_integer reducing code size. @@ -61,6 +66,10 @@ public: return format(static_cast(__value), __ctx); } +# if _LIBCPP_STD_VER > 20 + _LIBCPP_HIDE_FROM_ABI constexpr void set_debug_format() { __parser_.__type_ = __format_spec::__type::__debug; } +# endif + __format_spec::__parser<_CharT> __parser_; }; diff --git a/lib/libcxx/include/__format/formatter_floating_point.h b/lib/libcxx/include/__format/formatter_floating_point.h index 90a7619319..a544b53f7e 100644 --- a/lib/libcxx/include/__format/formatter_floating_point.h +++ b/lib/libcxx/include/__format/formatter_floating_point.h @@ -10,17 +10,16 @@ #ifndef _LIBCPP___FORMAT_FORMATTER_FLOATING_POINT_H #define _LIBCPP___FORMAT_FORMATTER_FLOATING_POINT_H -#include <__algorithm/copy.h> #include <__algorithm/copy_n.h> -#include <__algorithm/fill_n.h> #include <__algorithm/find.h> +#include <__algorithm/max.h> #include <__algorithm/min.h> #include <__algorithm/rotate.h> #include <__algorithm/transform.h> #include <__concepts/arithmetic.h> #include <__concepts/same_as.h> #include <__config> -#include <__format/format_fwd.h> +#include <__format/concepts.h> #include <__format/format_parse_context.h> #include <__format/formatter.h> #include <__format/formatter_integral.h> @@ -103,7 +102,7 @@ template struct __traits; template -static constexpr size_t __float_buffer_size(int __precision) { +_LIBCPP_HIDE_FROM_ABI constexpr size_t __float_buffer_size(int __precision) { using _Traits = __traits<_Fp>; return 4 + _Traits::__max_integral + __precision + _Traits::__max_fractional_value; } @@ -183,6 +182,7 @@ public: _LIBCPP_HIDE_FROM_ABI int __precision() const { return __precision_; } _LIBCPP_HIDE_FROM_ABI int __num_trailing_zeros() const { return __num_trailing_zeros_; } _LIBCPP_HIDE_FROM_ABI void __remove_trailing_zeros() { __num_trailing_zeros_ = 0; } + _LIBCPP_HIDE_FROM_ABI void __add_trailing_zeros(int __zeros) { __num_trailing_zeros_ += __zeros; } private: int __precision_; @@ -216,7 +216,7 @@ struct __float_result { /// \returns a pointer to the exponent or __last when not found. constexpr inline _LIBCPP_HIDE_FROM_ABI char* __find_exponent(char* __first, char* __last) { ptrdiff_t __size = __last - __first; - if (__size > 4) { + if (__size >= 4) { __first = __last - _VSTD::min(__size, ptrdiff_t(6)); for (; __first != __last - 3; ++__first) { if (*__first == 'e') @@ -404,6 +404,7 @@ _LIBCPP_HIDE_FROM_ABI __float_result __format_buffer_general_lower_case(__float_ // In fixed mode the algorithm truncates trailing spaces and possibly the // radix point. There's no good guess for the position of the radix point // therefore scan the output after the first digit. + __result.__radix_point = _VSTD::find(__first, __result.__last, '.'); } } @@ -454,7 +455,10 @@ _LIBCPP_HIDE_FROM_ABI __float_result __format_buffer( char* __first = __formatter::__insert_sign(__buffer.begin(), __negative, __sign); switch (__type) { case __format_spec::__type::__default: - return __formatter::__format_buffer_default(__buffer, __value, __first); + if (__has_precision) + return __formatter::__format_buffer_general_lower_case(__buffer, __value, __buffer.__precision(), __first); + else + return __formatter::__format_buffer_default(__buffer, __value, __first); case __format_spec::__type::__hexfloat_lower_case: return __formatter::__format_buffer_hexadecimal_lower_case( @@ -494,7 +498,7 @@ _LIBCPP_HIDE_FROM_ABI _OutIt __format_locale_specific_form( const __float_result& __result, _VSTD::locale __loc, __format_spec::__parsed_specifications<_CharT> __specs) { - const auto& __np = use_facet>(__loc); + const auto& __np = std::use_facet>(__loc); string __grouping = __np.grouping(); char* __first = __result.__integral; // When no radix point or exponent are present __last will be __result.__last. @@ -528,13 +532,13 @@ _LIBCPP_HIDE_FROM_ABI _OutIt __format_locale_specific_form( // sign and (zero padding or alignment) if (__zero_padding && __first != __buffer.begin()) *__out_it++ = *__buffer.begin(); - __out_it = _VSTD::fill_n(_VSTD::move(__out_it), __padding.__before_, __specs.__fill_); + __out_it = __formatter::__fill(_VSTD::move(__out_it), __padding.__before_, __specs.__fill_); if (!__zero_padding && __first != __buffer.begin()) *__out_it++ = *__buffer.begin(); // integral part if (__grouping.empty()) { - __out_it = _VSTD::copy_n(__first, __digits, _VSTD::move(__out_it)); + __out_it = __formatter::__copy(__first, __digits, _VSTD::move(__out_it)); } else { auto __r = __grouping.rbegin(); auto __e = __grouping.rend() - 1; @@ -546,7 +550,7 @@ _LIBCPP_HIDE_FROM_ABI _OutIt __format_locale_specific_form( // This loop achieves that process by testing the termination condition // midway in the loop. while (true) { - __out_it = _VSTD::copy_n(__first, *__r, _VSTD::move(__out_it)); + __out_it = __formatter::__copy(__first, *__r, _VSTD::move(__out_it)); __first += *__r; if (__r == __e) @@ -560,16 +564,16 @@ _LIBCPP_HIDE_FROM_ABI _OutIt __format_locale_specific_form( // fractional part if (__result.__radix_point != __result.__last) { *__out_it++ = __np.decimal_point(); - __out_it = _VSTD::copy(__result.__radix_point + 1, __result.__exponent, _VSTD::move(__out_it)); - __out_it = _VSTD::fill_n(_VSTD::move(__out_it), __buffer.__num_trailing_zeros(), _CharT('0')); + __out_it = __formatter::__copy(__result.__radix_point + 1, __result.__exponent, _VSTD::move(__out_it)); + __out_it = __formatter::__fill(_VSTD::move(__out_it), __buffer.__num_trailing_zeros(), _CharT('0')); } // exponent if (__result.__exponent != __result.__last) - __out_it = _VSTD::copy(__result.__exponent, __result.__last, _VSTD::move(__out_it)); + __out_it = __formatter::__copy(__result.__exponent, __result.__last, _VSTD::move(__out_it)); // alignment - return _VSTD::fill_n(_VSTD::move(__out_it), __padding.__after_, __specs.__fill_); + return __formatter::__fill(_VSTD::move(__out_it), __padding.__after_, __specs.__fill_); } # endif // _LIBCPP_HAS_NO_LOCALIZATION @@ -625,20 +629,51 @@ __format_floating_point(_Tp __value, auto& __ctx, __format_spec::__parsed_specif __float_result __result = __formatter::__format_buffer( __buffer, __value, __negative, (__specs.__has_precision()), __specs.__std_.__sign_, __specs.__std_.__type_); - if (__specs.__std_.__alternate_form_ && __result.__radix_point == __result.__last) { - *__result.__last++ = '.'; + if (__specs.__std_.__alternate_form_) { + if (__result.__radix_point == __result.__last) { + *__result.__last++ = '.'; - // When there is an exponent the point needs to be moved before the - // exponent. When there's no exponent the rotate does nothing. Since - // rotate tests whether the operation is a nop, call it unconditionally. - _VSTD::rotate(__result.__exponent, __result.__last - 1, __result.__last); - __result.__radix_point = __result.__exponent; + // When there is an exponent the point needs to be moved before the + // exponent. When there's no exponent the rotate does nothing. Since + // rotate tests whether the operation is a nop, call it unconditionally. + _VSTD::rotate(__result.__exponent, __result.__last - 1, __result.__last); + __result.__radix_point = __result.__exponent; - // The radix point is always placed before the exponent. - // - No exponent needs to point to the new last. - // - An exponent needs to move one position to the right. - // So it's safe to increment the value unconditionally. - ++__result.__exponent; + // The radix point is always placed before the exponent. + // - No exponent needs to point to the new last. + // - An exponent needs to move one position to the right. + // So it's safe to increment the value unconditionally. + ++__result.__exponent; + } + + // [format.string.std]/6 + // In addition, for g and G conversions, trailing zeros are not removed + // from the result. + // + // If the type option for a floating-point type is none it may use the + // general formatting, but it's not a g or G conversion. So in that case + // the formatting should not append trailing zeros. + bool __is_general = __specs.__std_.__type_ == __format_spec::__type::__general_lower_case || + __specs.__std_.__type_ == __format_spec::__type::__general_upper_case; + + if (__is_general) { + // https://en.cppreference.com/w/c/io/fprintf + // Let P equal the precision if nonzero, 6 if the precision is not + // specified, or 1 if the precision is 0. Then, if a conversion with + // style E would have an exponent of X: + int __p = _VSTD::max(1, (__specs.__has_precision() ? __specs.__precision_ : 6)); + if (__result.__exponent == __result.__last) + // if P > X >= -4, the conversion is with style f or F and precision P - 1 - X. + // By including the radix point it calculates P - (1 + X) + __p -= __result.__radix_point - __buffer.begin(); + else + // otherwise, the conversion is with style e or E and precision P - 1. + --__p; + + ptrdiff_t __precision = (__result.__exponent - __result.__radix_point) - 1; + if (__precision < __p) + __buffer.__add_trailing_zeros(__p - __precision); + } } # ifndef _LIBCPP_HAS_NO_LOCALIZATION @@ -651,14 +686,15 @@ __format_floating_point(_Tp __value, auto& __ctx, __format_spec::__parsed_specif if (__size + __num_trailing_zeros >= __specs.__width_) { if (__num_trailing_zeros && __result.__exponent != __result.__last) // Insert trailing zeros before exponent character. - return _VSTD::copy( + return __formatter::__copy( __result.__exponent, __result.__last, - _VSTD::fill_n( - _VSTD::copy(__buffer.begin(), __result.__exponent, __ctx.out()), __num_trailing_zeros, _CharT('0'))); + __formatter::__fill(__formatter::__copy(__buffer.begin(), __result.__exponent, __ctx.out()), + __num_trailing_zeros, + _CharT('0'))); - return _VSTD::fill_n( - _VSTD::copy(__buffer.begin(), __result.__last, __ctx.out()), __num_trailing_zeros, _CharT('0')); + return __formatter::__fill( + __formatter::__copy(__buffer.begin(), __result.__last, __ctx.out()), __num_trailing_zeros, _CharT('0')); } auto __out_it = __ctx.out(); @@ -684,7 +720,7 @@ __format_floating_point(_Tp __value, auto& __ctx, __format_spec::__parsed_specif } // namespace __formatter -template <__formatter::__char_type _CharT> +template <__fmt_char_type _CharT> struct _LIBCPP_TEMPLATE_VIS __formatter_floating_point { public: _LIBCPP_HIDE_FROM_ABI constexpr auto @@ -702,13 +738,13 @@ public: __format_spec::__parser<_CharT> __parser_; }; -template <__formatter::__char_type _CharT> +template <__fmt_char_type _CharT> struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter : public __formatter_floating_point<_CharT> {}; -template <__formatter::__char_type _CharT> +template <__fmt_char_type _CharT> struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter : public __formatter_floating_point<_CharT> {}; -template <__formatter::__char_type _CharT> +template <__fmt_char_type _CharT> struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter : public __formatter_floating_point<_CharT> {}; diff --git a/lib/libcxx/include/__format/formatter_integer.h b/lib/libcxx/include/__format/formatter_integer.h index 3139c9efdf..b4be9f9a07 100644 --- a/lib/libcxx/include/__format/formatter_integer.h +++ b/lib/libcxx/include/__format/formatter_integer.h @@ -13,7 +13,7 @@ #include <__availability> #include <__concepts/arithmetic.h> #include <__config> -#include <__format/format_fwd.h> +#include <__format/concepts.h> #include <__format/format_parse_context.h> #include <__format/formatter.h> #include <__format/formatter_integral.h> @@ -30,7 +30,7 @@ #if _LIBCPP_STD_VER > 17 - template <__formatter::__char_type _CharT> + template <__fmt_char_type _CharT> struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT __formatter_integer { public: @@ -59,43 +59,43 @@ public: }; // Signed integral types. -template <__formatter::__char_type _CharT> +template <__fmt_char_type _CharT> struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter : public __formatter_integer<_CharT> {}; -template <__formatter::__char_type _CharT> +template <__fmt_char_type _CharT> struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter : public __formatter_integer<_CharT> { }; -template <__formatter::__char_type _CharT> +template <__fmt_char_type _CharT> struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter : public __formatter_integer<_CharT> {}; -template <__formatter::__char_type _CharT> +template <__fmt_char_type _CharT> struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter : public __formatter_integer<_CharT> {}; -template <__formatter::__char_type _CharT> +template <__fmt_char_type _CharT> struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter : public __formatter_integer<_CharT> {}; # ifndef _LIBCPP_HAS_NO_INT128 -template <__formatter::__char_type _CharT> +template <__fmt_char_type _CharT> struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter<__int128_t, _CharT> : public __formatter_integer<_CharT> {}; # endif // Unsigned integral types. -template <__formatter::__char_type _CharT> +template <__fmt_char_type _CharT> struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter : public __formatter_integer<_CharT> {}; -template <__formatter::__char_type _CharT> +template <__fmt_char_type _CharT> struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter : public __formatter_integer<_CharT> {}; -template <__formatter::__char_type _CharT> +template <__fmt_char_type _CharT> struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter : public __formatter_integer<_CharT> {}; -template <__formatter::__char_type _CharT> +template <__fmt_char_type _CharT> struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter : public __formatter_integer<_CharT> {}; -template <__formatter::__char_type _CharT> +template <__fmt_char_type _CharT> struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter : public __formatter_integer<_CharT> {}; # ifndef _LIBCPP_HAS_NO_INT128 -template <__formatter::__char_type _CharT> +template <__fmt_char_type _CharT> struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter<__uint128_t, _CharT> : public __formatter_integer<_CharT> {}; # endif diff --git a/lib/libcxx/include/__format/formatter_integral.h b/lib/libcxx/include/__format/formatter_integral.h index b9ed5fe80f..fe3a06311b 100644 --- a/lib/libcxx/include/__format/formatter_integral.h +++ b/lib/libcxx/include/__format/formatter_integral.h @@ -13,11 +13,12 @@ #include <__concepts/arithmetic.h> #include <__concepts/same_as.h> #include <__config> +#include <__format/concepts.h> #include <__format/format_error.h> -#include <__format/formatter.h> // for __char_type TODO FMT Move the concept? #include <__format/formatter_output.h> #include <__format/parser_std_format_spec.h> #include <__utility/unreachable.h> +#include #include #include #include @@ -112,7 +113,7 @@ _LIBCPP_HIDE_FROM_ABI inline string __determine_grouping(ptrdiff_t __size, const // Char // -template <__formatter::__char_type _CharT> +template <__fmt_char_type _CharT> _LIBCPP_HIDE_FROM_ABI auto __format_char( integral auto __value, output_iterator auto __out_it, @@ -216,7 +217,7 @@ _LIBCPP_HIDE_FROM_ABI auto __format_integer( # ifndef _LIBCPP_HAS_NO_LOCALIZATION if (__specs.__std_.__locale_specific_form_) { - const auto& __np = use_facet>(__ctx.locale()); + const auto& __np = std::use_facet>(__ctx.locale()); string __grouping = __np.grouping(); ptrdiff_t __size = __last - __first; // Writing the grouped form has more overhead than the normal output @@ -243,7 +244,7 @@ _LIBCPP_HIDE_FROM_ABI auto __format_integer( // The zero padding is done like: // - Write [sign][prefix] // - Write data right aligned with '0' as fill character. - __out_it = _VSTD::copy(__begin, __first, _VSTD::move(__out_it)); + __out_it = __formatter::__copy(__begin, __first, _VSTD::move(__out_it)); __specs.__alignment_ = __format_spec::__alignment::__right; __specs.__fill_ = _CharT('0'); int32_t __size = __first - __begin; @@ -309,7 +310,7 @@ __format_integer(_Tp __value, auto& __ctx, __format_spec::__parsed_specification auto __r = std::__to_unsigned_like(__value); bool __negative = __value < 0; if (__negative) - __r = __complement(__r); + __r = std::__complement(__r); return __formatter::__format_integer(__r, __ctx, __specs, __negative); } @@ -341,7 +342,7 @@ __format_bool(bool __value, auto& __ctx, __format_spec::__parsed_specifications< -> decltype(__ctx.out()) { # ifndef _LIBCPP_HAS_NO_LOCALIZATION if (__specs.__std_.__locale_specific_form_) { - const auto& __np = use_facet>(__ctx.locale()); + const auto& __np = std::use_facet>(__ctx.locale()); basic_string<_CharT> __str = __value ? __np.truename() : __np.falsename(); return __formatter::__write_string_no_precision(basic_string_view<_CharT>{__str}, __ctx.out(), __specs); } diff --git a/lib/libcxx/include/__format/formatter_output.h b/lib/libcxx/include/__format/formatter_output.h index e09534c41d..467692559c 100644 --- a/lib/libcxx/include/__format/formatter_output.h +++ b/lib/libcxx/include/__format/formatter_output.h @@ -10,16 +10,23 @@ #ifndef _LIBCPP___FORMAT_FORMATTER_OUTPUT_H #define _LIBCPP___FORMAT_FORMATTER_OUTPUT_H -#include <__algorithm/copy.h> -#include <__algorithm/copy_n.h> -#include <__algorithm/fill_n.h> -#include <__algorithm/transform.h> +#include <__algorithm/ranges_copy.h> +#include <__algorithm/ranges_fill_n.h> +#include <__algorithm/ranges_transform.h> +#include <__chrono/statically_widen.h> +#include <__concepts/same_as.h> #include <__config> +#include <__format/buffer.h> +#include <__format/concepts.h> +#include <__format/escaped_output_table.h> #include <__format/formatter.h> #include <__format/parser_std_format_spec.h> #include <__format/unicode.h> +#include <__iterator/back_insert_iterator.h> +#include <__type_traits/make_unsigned.h> #include <__utility/move.h> #include <__utility/unreachable.h> +#include #include #include #include @@ -86,6 +93,74 @@ __padding_size(size_t __size, size_t __width, __format_spec::__alignment __align __libcpp_unreachable(); } +/// Copy wrapper. +/// +/// This uses a "mass output function" of __format::__output_buffer when possible. +template <__fmt_char_type _CharT, __fmt_char_type _OutCharT = _CharT> +_LIBCPP_HIDE_FROM_ABI auto __copy(basic_string_view<_CharT> __str, output_iterator auto __out_it) + -> decltype(__out_it) { + if constexpr (_VSTD::same_as>>) { + __out_it.__get_container()->__copy(__str); + return __out_it; + } else if constexpr (_VSTD::same_as::__iterator>) { + __out_it.__buffer_->__copy(__str); + return __out_it; + } else { + return std::ranges::copy(__str, _VSTD::move(__out_it)).out; + } +} + +template <__fmt_char_type _CharT, __fmt_char_type _OutCharT = _CharT> +_LIBCPP_HIDE_FROM_ABI auto +__copy(const _CharT* __first, const _CharT* __last, output_iterator auto __out_it) + -> decltype(__out_it) { + return __formatter::__copy(basic_string_view{__first, __last}, _VSTD::move(__out_it)); +} + +template <__fmt_char_type _CharT, __fmt_char_type _OutCharT = _CharT> +_LIBCPP_HIDE_FROM_ABI auto __copy(const _CharT* __first, size_t __n, output_iterator auto __out_it) + -> decltype(__out_it) { + return __formatter::__copy(basic_string_view{__first, __n}, _VSTD::move(__out_it)); +} + +/// Transform wrapper. +/// +/// This uses a "mass output function" of __format::__output_buffer when possible. +template <__fmt_char_type _CharT, __fmt_char_type _OutCharT = _CharT, class _UnaryOperation> +_LIBCPP_HIDE_FROM_ABI auto +__transform(const _CharT* __first, + const _CharT* __last, + output_iterator auto __out_it, + _UnaryOperation __operation) -> decltype(__out_it) { + if constexpr (_VSTD::same_as>>) { + __out_it.__get_container()->__transform(__first, __last, _VSTD::move(__operation)); + return __out_it; + } else if constexpr (_VSTD::same_as::__iterator>) { + __out_it.__buffer_->__transform(__first, __last, _VSTD::move(__operation)); + return __out_it; + } else { + return std::ranges::transform(__first, __last, _VSTD::move(__out_it), __operation).out; + } +} + +/// Fill wrapper. +/// +/// This uses a "mass output function" of __format::__output_buffer when possible. +template <__fmt_char_type _CharT, output_iterator _OutIt> +_LIBCPP_HIDE_FROM_ABI _OutIt __fill(_OutIt __out_it, size_t __n, _CharT __value) { + if constexpr (_VSTD::same_as>>) { + __out_it.__get_container()->__fill(__n, __value); + return __out_it; + } else if constexpr (_VSTD::same_as::__iterator>) { + __out_it.__buffer_->__fill(__n, __value); + return __out_it; + } else { + return std::ranges::fill_n(_VSTD::move(__out_it), __n, __value); + } +} + template _LIBCPP_HIDE_FROM_ABI _OutIt __write_using_decimal_separators(_OutIt __out_it, const char* __begin, const char* __first, const char* __last, string&& __grouping, _CharT __sep, @@ -97,22 +172,22 @@ _LIBCPP_HIDE_FROM_ABI _OutIt __write_using_decimal_separators(_OutIt __out_it, c __padding_size_result __padding = {0, 0}; if (__specs.__alignment_ == __format_spec::__alignment::__zero_padding) { // Write [sign][prefix]. - __out_it = _VSTD::copy(__begin, __first, _VSTD::move(__out_it)); + __out_it = __formatter::__copy(__begin, __first, _VSTD::move(__out_it)); if (__specs.__width_ > __size) { // Write zero padding. __padding.__before_ = __specs.__width_ - __size; - __out_it = _VSTD::fill_n(_VSTD::move(__out_it), __specs.__width_ - __size, _CharT('0')); + __out_it = __formatter::__fill(_VSTD::move(__out_it), __specs.__width_ - __size, _CharT('0')); } } else { if (__specs.__width_ > __size) { // Determine padding and write padding. - __padding = __padding_size(__size, __specs.__width_, __specs.__alignment_); + __padding = __formatter::__padding_size(__size, __specs.__width_, __specs.__alignment_); - __out_it = _VSTD::fill_n(_VSTD::move(__out_it), __padding.__before_, __specs.__fill_); + __out_it = __formatter::__fill(_VSTD::move(__out_it), __padding.__before_, __specs.__fill_); } // Write [sign][prefix]. - __out_it = _VSTD::copy(__begin, __first, _VSTD::move(__out_it)); + __out_it = __formatter::__copy(__begin, __first, _VSTD::move(__out_it)); } auto __r = __grouping.rbegin(); @@ -133,10 +208,10 @@ _LIBCPP_HIDE_FROM_ABI _OutIt __write_using_decimal_separators(_OutIt __out_it, c while (true) { if (__specs.__std_.__type_ == __format_spec::__type::__hexadecimal_upper_case) { __last = __first + *__r; - __out_it = _VSTD::transform(__first, __last, _VSTD::move(__out_it), __hex_to_upper); + __out_it = __formatter::__transform(__first, __last, _VSTD::move(__out_it), __hex_to_upper); __first = __last; } else { - __out_it = _VSTD::copy_n(__first, *__r, _VSTD::move(__out_it)); + __out_it = __formatter::__copy(__first, *__r, _VSTD::move(__out_it)); __first += *__r; } @@ -147,7 +222,7 @@ _LIBCPP_HIDE_FROM_ABI _OutIt __write_using_decimal_separators(_OutIt __out_it, c *__out_it++ = __sep; } - return _VSTD::fill_n(_VSTD::move(__out_it), __padding.__after_, __specs.__fill_); + return __formatter::__fill(_VSTD::move(__out_it), __padding.__after_, __specs.__fill_); } /// Writes the input to the output with the required padding. @@ -155,12 +230,10 @@ _LIBCPP_HIDE_FROM_ABI _OutIt __write_using_decimal_separators(_OutIt __out_it, c /// Since the output column width is specified the function can be used for /// ASCII and Unicode output. /// -/// \pre [\a __first, \a __last) is a valid range. /// \pre \a __size <= \a __width. Using this function when this pre-condition /// doesn't hold incurs an unwanted overhead. /// -/// \param __first Pointer to the first element to write. -/// \param __last Pointer beyond the last element to write. +/// \param __str The string to write. /// \param __out_it The output iterator to write to. /// \param __specs The parsed formatting specifications. /// \param __size The (estimated) output column width. When the elements @@ -174,31 +247,42 @@ _LIBCPP_HIDE_FROM_ABI _OutIt __write_using_decimal_separators(_OutIt __out_it, c /// conversion, which means the [\a __first, \a __last) always contains elements /// of the type \c char. template -_LIBCPP_HIDE_FROM_ABI auto __write( - const _CharT* __first, - const _CharT* __last, - output_iterator auto __out_it, - __format_spec::__parsed_specifications<_ParserCharT> __specs, - ptrdiff_t __size) -> decltype(__out_it) { - _LIBCPP_ASSERT(__first <= __last, "Not a valid range"); - +_LIBCPP_HIDE_FROM_ABI auto +__write(basic_string_view<_CharT> __str, + output_iterator auto __out_it, + __format_spec::__parsed_specifications<_ParserCharT> __specs, + ptrdiff_t __size) -> decltype(__out_it) { if (__size >= __specs.__width_) - return _VSTD::copy(__first, __last, _VSTD::move(__out_it)); + return __formatter::__copy(__str, _VSTD::move(__out_it)); __padding_size_result __padding = __formatter::__padding_size(__size, __specs.__width_, __specs.__std_.__alignment_); - __out_it = _VSTD::fill_n(_VSTD::move(__out_it), __padding.__before_, __specs.__fill_); - __out_it = _VSTD::copy(__first, __last, _VSTD::move(__out_it)); - return _VSTD::fill_n(_VSTD::move(__out_it), __padding.__after_, __specs.__fill_); + __out_it = __formatter::__fill(_VSTD::move(__out_it), __padding.__before_, __specs.__fill_); + __out_it = __formatter::__copy(__str, _VSTD::move(__out_it)); + return __formatter::__fill(_VSTD::move(__out_it), __padding.__after_, __specs.__fill_); +} + +template +_LIBCPP_HIDE_FROM_ABI auto +__write(const _CharT* __first, + const _CharT* __last, + output_iterator auto __out_it, + __format_spec::__parsed_specifications<_ParserCharT> __specs, + ptrdiff_t __size) -> decltype(__out_it) { + _LIBCPP_ASSERT(__first <= __last, "Not a valid range"); + return __formatter::__write(basic_string_view{__first, __last}, _VSTD::move(__out_it), __specs, __size); } /// \overload /// /// Calls the function above where \a __size = \a __last - \a __first. template -_LIBCPP_HIDE_FROM_ABI auto __write(const _CharT* __first, const _CharT* __last, - output_iterator auto __out_it, - __format_spec::__parsed_specifications<_ParserCharT> __specs) -> decltype(__out_it) { - return __write(__first, __last, _VSTD::move(__out_it), __specs, __last - __first); +_LIBCPP_HIDE_FROM_ABI auto +__write(const _CharT* __first, + const _CharT* __last, + output_iterator auto __out_it, + __format_spec::__parsed_specifications<_ParserCharT> __specs) -> decltype(__out_it) { + _LIBCPP_ASSERT(__first <= __last, "Not a valid range"); + return __formatter::__write(__first, __last, _VSTD::move(__out_it), __specs, __last - __first); } template @@ -210,12 +294,12 @@ _LIBCPP_HIDE_FROM_ABI auto __write_transformed(const _CharT* __first, const _Cha ptrdiff_t __size = __last - __first; if (__size >= __specs.__width_) - return _VSTD::transform(__first, __last, _VSTD::move(__out_it), __op); + return __formatter::__transform(__first, __last, _VSTD::move(__out_it), __op); - __padding_size_result __padding = __padding_size(__size, __specs.__width_, __specs.__alignment_); - __out_it = _VSTD::fill_n(_VSTD::move(__out_it), __padding.__before_, __specs.__fill_); - __out_it = _VSTD::transform(__first, __last, _VSTD::move(__out_it), __op); - return _VSTD::fill_n(_VSTD::move(__out_it), __padding.__after_, __specs.__fill_); + __padding_size_result __padding = __formatter::__padding_size(__size, __specs.__width_, __specs.__alignment_); + __out_it = __formatter::__fill(_VSTD::move(__out_it), __padding.__before_, __specs.__fill_); + __out_it = __formatter::__transform(__first, __last, _VSTD::move(__out_it), __op); + return __formatter::__fill(_VSTD::move(__out_it), __padding.__after_, __specs.__fill_); } /// Writes additional zero's for the precision before the exponent. @@ -239,12 +323,12 @@ _LIBCPP_HIDE_FROM_ABI auto __write_using_trailing_zeros( _LIBCPP_ASSERT(__num_trailing_zeros > 0, "The overload not writing trailing zeros should have been used"); __padding_size_result __padding = - __padding_size(__size + __num_trailing_zeros, __specs.__width_, __specs.__alignment_); - __out_it = _VSTD::fill_n(_VSTD::move(__out_it), __padding.__before_, __specs.__fill_); - __out_it = _VSTD::copy(__first, __exponent, _VSTD::move(__out_it)); - __out_it = _VSTD::fill_n(_VSTD::move(__out_it), __num_trailing_zeros, _CharT('0')); - __out_it = _VSTD::copy(__exponent, __last, _VSTD::move(__out_it)); - return _VSTD::fill_n(_VSTD::move(__out_it), __padding.__after_, __specs.__fill_); + __formatter::__padding_size(__size + __num_trailing_zeros, __specs.__width_, __specs.__alignment_); + __out_it = __formatter::__fill(_VSTD::move(__out_it), __padding.__before_, __specs.__fill_); + __out_it = __formatter::__copy(__first, __exponent, _VSTD::move(__out_it)); + __out_it = __formatter::__fill(_VSTD::move(__out_it), __num_trailing_zeros, _CharT('0')); + __out_it = __formatter::__copy(__exponent, __last, _VSTD::move(__out_it)); + return __formatter::__fill(_VSTD::move(__out_it), __padding.__after_, __specs.__fill_); } /// Writes a string using format's width estimation algorithm. @@ -262,7 +346,7 @@ _LIBCPP_HIDE_FROM_ABI auto __write_string_no_precision( // No padding -> copy the string if (!__specs.__has_width()) - return _VSTD::copy(__str.begin(), __str.end(), _VSTD::move(__out_it)); + return __formatter::__copy(__str, _VSTD::move(__out_it)); // Note when the estimated width is larger than size there's no padding. So // there's no reason to get the real size when the estimate is larger than or @@ -270,8 +354,7 @@ _LIBCPP_HIDE_FROM_ABI auto __write_string_no_precision( size_t __size = __format_spec::__estimate_column_width(__str, __specs.__width_, __format_spec::__column_width_rounding::__up) .__width_; - - return __formatter::__write(__str.begin(), __str.end(), _VSTD::move(__out_it), __specs, __size); + return __formatter::__write(__str, _VSTD::move(__out_it), __specs, __size); } template @@ -296,9 +379,188 @@ _LIBCPP_HIDE_FROM_ABI auto __write_string( int __size = __formatter::__truncate(__str, __specs.__precision_); - return __write(__str.begin(), __str.end(), _VSTD::move(__out_it), __specs, __size); + return __formatter::__write(__str.begin(), __str.end(), _VSTD::move(__out_it), __specs, __size); } +# if _LIBCPP_STD_VER > 20 + +struct __nul_terminator {}; + +template +_LIBCPP_HIDE_FROM_ABI bool operator==(const _CharT* __cstr, __nul_terminator) { + return *__cstr == _CharT('\0'); +} + +template +_LIBCPP_HIDE_FROM_ABI void +__write_escaped_code_unit(basic_string<_CharT>& __str, char32_t __value, const _CharT* __prefix) { + back_insert_iterator __out_it{__str}; + std::ranges::copy(__prefix, __nul_terminator{}, __out_it); + + char __buffer[8]; + to_chars_result __r = std::to_chars(std::begin(__buffer), std::end(__buffer), __value, 16); + _LIBCPP_ASSERT(__r.ec == errc(0), "Internal buffer too small"); + std::ranges::copy(std::begin(__buffer), __r.ptr, __out_it); + + __str += _CharT('}'); +} + +// [format.string.escaped]/2.2.1.2 +// ... +// then the sequence \u{hex-digit-sequence} is appended to E, where +// hex-digit-sequence is the shortest hexadecimal representation of C using +// lower-case hexadecimal digits. +template +_LIBCPP_HIDE_FROM_ABI void __write_well_formed_escaped_code_unit(basic_string<_CharT>& __str, char32_t __value) { + __formatter::__write_escaped_code_unit(__str, __value, _LIBCPP_STATICALLY_WIDEN(_CharT, "\\u{")); +} + +// [format.string.escaped]/2.2.3 +// Otherwise (X is a sequence of ill-formed code units), each code unit U is +// appended to E in order as the sequence \x{hex-digit-sequence}, where +// hex-digit-sequence is the shortest hexadecimal representation of U using +// lower-case hexadecimal digits. +template +_LIBCPP_HIDE_FROM_ABI void __write_escape_ill_formed_code_unit(basic_string<_CharT>& __str, char32_t __value) { + __formatter::__write_escaped_code_unit(__str, __value, _LIBCPP_STATICALLY_WIDEN(_CharT, "\\x{")); +} + +template +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI bool __is_escaped_sequence_written(basic_string<_CharT>& __str, char32_t __value) { +# ifdef _LIBCPP_HAS_NO_UNICODE + // For ASCII assume everything above 127 is printable. + if (__value > 127) + return false; +# endif + + if (!__escaped_output_table::__needs_escape(__value)) + return false; + + __formatter::__write_well_formed_escaped_code_unit(__str, __value); + return true; +} + +template +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr char32_t __to_char32(_CharT __value) { + return static_cast>(__value); +} + +enum class _LIBCPP_ENUM_VIS __escape_quotation_mark { __apostrophe, __double_quote }; + +// [format.string.escaped]/2 +template +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI bool +__is_escaped_sequence_written(basic_string<_CharT>& __str, char32_t __value, __escape_quotation_mark __mark) { + // 2.2.1.1 - Mapped character in [tab:format.escape.sequences] + switch (__value) { + case _CharT('\t'): + __str += _LIBCPP_STATICALLY_WIDEN(_CharT, "\\t"); + return true; + case _CharT('\n'): + __str += _LIBCPP_STATICALLY_WIDEN(_CharT, "\\n"); + return true; + case _CharT('\r'): + __str += _LIBCPP_STATICALLY_WIDEN(_CharT, "\\r"); + return true; + case _CharT('\''): + if (__mark == __escape_quotation_mark::__apostrophe) + __str += _LIBCPP_STATICALLY_WIDEN(_CharT, R"(\')"); + else + __str += __value; + return true; + case _CharT('"'): + if (__mark == __escape_quotation_mark::__double_quote) + __str += _LIBCPP_STATICALLY_WIDEN(_CharT, R"(\")"); + else + __str += __value; + return true; + case _CharT('\\'): + __str += _LIBCPP_STATICALLY_WIDEN(_CharT, R"(\\)"); + return true; + + // 2.2.1.2 - Space + case _CharT(' '): + __str += __value; + return true; + } + + // 2.2.2 + // Otherwise, if X is a shift sequence, the effect on E and further + // decoding of S is unspecified. + // For now shift sequences are ignored and treated as Unicode. Other parts + // of the format library do the same. It's unknown how ostream treats them. + // TODO FMT determine what to do with shift sequences. + + // 2.2.1.2.1 and 2.2.1.2.2 - Escape + return __formatter::__is_escaped_sequence_written(__str, __formatter::__to_char32(__value)); +} + +template +_LIBCPP_HIDE_FROM_ABI void +__escape(basic_string<_CharT>& __str, basic_string_view<_CharT> __values, __escape_quotation_mark __mark) { + __unicode::__code_point_view<_CharT> __view{__values.begin(), __values.end()}; + + while (!__view.__at_end()) { + const _CharT* __first = __view.__position(); + typename __unicode::__consume_p2286_result __result = __view.__consume_p2286(); + if (__result.__ill_formed_size == 0) { + if (!__formatter::__is_escaped_sequence_written(__str, __result.__value, __mark)) + // 2.2.1.3 - Add the character + ranges::copy(__first, __view.__position(), std::back_insert_iterator(__str)); + + } else { + // 2.2.3 sequence of ill-formed code units + // The number of code-units in __result.__value depends on the character type being used. + if constexpr (sizeof(_CharT) == 1) { + _LIBCPP_ASSERT(__result.__ill_formed_size == 1 || __result.__ill_formed_size == 4, + "illegal number of invalid code units."); + if (__result.__ill_formed_size == 1) // ill-formed, one code unit + __formatter::__write_escape_ill_formed_code_unit(__str, __result.__value & 0xff); + else { // out of valid range, four code units + // The code point was properly encoded, decode the value. + __formatter::__write_escape_ill_formed_code_unit(__str, __result.__value >> 18 | 0xf0); + __formatter::__write_escape_ill_formed_code_unit(__str, (__result.__value >> 12 & 0x3f) | 0x80); + __formatter::__write_escape_ill_formed_code_unit(__str, (__result.__value >> 6 & 0x3f) | 0x80); + __formatter::__write_escape_ill_formed_code_unit(__str, (__result.__value & 0x3f) | 0x80); + } + } else if constexpr (sizeof(_CharT) == 2) { + _LIBCPP_ASSERT(__result.__ill_formed_size == 1, "for UTF-16 at most one invalid code unit"); + __formatter::__write_escape_ill_formed_code_unit(__str, __result.__value & 0xffff); + } else { + static_assert(sizeof(_CharT) == 4, "unsupported character width"); + _LIBCPP_ASSERT(__result.__ill_formed_size == 1, "for UTF-32 one code unit is one code point"); + __formatter::__write_escape_ill_formed_code_unit(__str, __result.__value); + } + } + } +} + +template +_LIBCPP_HIDE_FROM_ABI auto +__format_escaped_char(_CharT __value, + output_iterator auto __out_it, + __format_spec::__parsed_specifications<_CharT> __specs) -> decltype(__out_it) { + basic_string<_CharT> __str; + __str += _CharT('\''); + __formatter::__escape(__str, basic_string_view{std::addressof(__value), 1}, __escape_quotation_mark::__apostrophe); + __str += _CharT('\''); + return __formatter::__write(__str.data(), __str.data() + __str.size(), _VSTD::move(__out_it), __specs, __str.size()); +} + +template +_LIBCPP_HIDE_FROM_ABI auto +__format_escaped_string(basic_string_view<_CharT> __values, + output_iterator auto __out_it, + __format_spec::__parsed_specifications<_CharT> __specs) -> decltype(__out_it) { + basic_string<_CharT> __str; + __str += _CharT('"'); + __formatter::__escape(__str, __values, __escape_quotation_mark::__double_quote); + __str += _CharT('"'); + return __formatter::__write_string(basic_string_view{__str}, _VSTD::move(__out_it), __specs); +} + +# endif // _LIBCPP_STD_VER > 20 + } // namespace __formatter #endif //_LIBCPP_STD_VER > 17 diff --git a/lib/libcxx/include/__format/formatter_pointer.h b/lib/libcxx/include/__format/formatter_pointer.h index 3cd4c9bba9..31b49e17ab 100644 --- a/lib/libcxx/include/__format/formatter_pointer.h +++ b/lib/libcxx/include/__format/formatter_pointer.h @@ -12,7 +12,7 @@ #include <__availability> #include <__config> -#include <__format/format_fwd.h> +#include <__format/concepts.h> #include <__format/format_parse_context.h> #include <__format/formatter.h> #include <__format/formatter_integral.h> @@ -29,7 +29,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD #if _LIBCPP_STD_VER > 17 -template <__formatter::__char_type _CharT> +template <__fmt_char_type _CharT> struct _LIBCPP_TEMPLATE_VIS __formatter_pointer { public: constexpr __formatter_pointer() { __parser_.__alignment_ = __format_spec::__alignment::__right; } @@ -56,13 +56,13 @@ public: // - struct formatter; // - template<> struct formatter; // - template<> struct formatter; -template <__formatter::__char_type _CharT> +template <__fmt_char_type _CharT> struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter : public __formatter_pointer<_CharT> {}; -template <__formatter::__char_type _CharT> +template <__fmt_char_type _CharT> struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter : public __formatter_pointer<_CharT> { }; -template <__formatter::__char_type _CharT> +template <__fmt_char_type _CharT> struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter : public __formatter_pointer<_CharT> {}; diff --git a/lib/libcxx/include/__format/formatter_string.h b/lib/libcxx/include/__format/formatter_string.h index 71bda4fcde..606fb79249 100644 --- a/lib/libcxx/include/__format/formatter_string.h +++ b/lib/libcxx/include/__format/formatter_string.h @@ -12,7 +12,7 @@ #include <__availability> #include <__config> -#include <__format/format_fwd.h> +#include <__format/concepts.h> #include <__format/format_parse_context.h> #include <__format/formatter.h> #include <__format/formatter_output.h> @@ -29,7 +29,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD #if _LIBCPP_STD_VER > 17 -template <__formatter::__char_type _CharT> +template <__fmt_char_type _CharT> struct _LIBCPP_TEMPLATE_VIS __formatter_string { public: _LIBCPP_HIDE_FROM_ABI constexpr auto parse(basic_format_parse_context<_CharT>& __parse_ctx) @@ -40,14 +40,23 @@ public: } _LIBCPP_HIDE_FROM_ABI auto format(basic_string_view<_CharT> __str, auto& __ctx) const -> decltype(__ctx.out()) { +# if _LIBCPP_STD_VER > 20 + if (__parser_.__type_ == __format_spec::__type::__debug) + return __formatter::__format_escaped_string(__str, __ctx.out(), __parser_.__get_parsed_std_specifications(__ctx)); +# endif + return __formatter::__write_string(__str, __ctx.out(), __parser_.__get_parsed_std_specifications(__ctx)); } - __format_spec::__parser<_CharT> __parser_; +# if _LIBCPP_STD_VER > 20 + _LIBCPP_HIDE_FROM_ABI constexpr void set_debug_format() { __parser_.__type_ = __format_spec::__type::__debug; } +# endif + + __format_spec::__parser<_CharT> __parser_{.__alignment_ = __format_spec::__alignment::__left}; }; // Formatter const char*. -template <__formatter::__char_type _CharT> +template <__fmt_char_type _CharT> struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter : public __formatter_string<_CharT> { using _Base = __formatter_string<_CharT>; @@ -56,6 +65,12 @@ struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter __specs = _Base::__parser_.__get_parsed_std_specifications(__ctx); +# if _LIBCPP_STD_VER > 20 + if (_Base::__parser_.__type_ == __format_spec::__type::__debug) + return __formatter::__format_escaped_string(basic_string_view<_CharT>{__str}, __ctx.out(), __specs); +# endif + // When using a center or right alignment and the width option the length // of __str must be known to add the padding upfront. This case is handled // by the base class by converting the argument to a basic_string_view. @@ -67,7 +82,6 @@ struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter __specs = _Base::__parser_.__get_parsed_std_specifications(__ctx); if (__specs.__has_width() || __specs.__has_precision()) return __formatter::__write_string(basic_string_view<_CharT>{__str}, __ctx.out(), __specs); @@ -80,7 +94,7 @@ struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter +template <__fmt_char_type _CharT> struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter<_CharT*, _CharT> : public formatter { using _Base = formatter; @@ -91,7 +105,7 @@ struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter<_CharT*, _Char }; // Formatter char[]. -template <__formatter::__char_type _CharT, size_t _Size> +template <__fmt_char_type _CharT, size_t _Size> struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter<_CharT[_Size], _CharT> : public __formatter_string<_CharT> { using _Base = __formatter_string<_CharT>; @@ -102,7 +116,7 @@ struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter<_CharT[_Size], }; // Formatter const char[]. -template <__formatter::__char_type _CharT, size_t _Size> +template <__fmt_char_type _CharT, size_t _Size> struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter : public __formatter_string<_CharT> { using _Base = __formatter_string<_CharT>; @@ -113,7 +127,7 @@ struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter +template <__fmt_char_type _CharT, class _Traits, class _Allocator> struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter, _CharT> : public __formatter_string<_CharT> { using _Base = __formatter_string<_CharT>; @@ -126,7 +140,7 @@ struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter +template <__fmt_char_type _CharT, class _Traits> struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter, _CharT> : public __formatter_string<_CharT> { using _Base = __formatter_string<_CharT>; diff --git a/lib/libcxx/include/__format/formatter_tuple.h b/lib/libcxx/include/__format/formatter_tuple.h new file mode 100644 index 0000000000..82f5ada6e0 --- /dev/null +++ b/lib/libcxx/include/__format/formatter_tuple.h @@ -0,0 +1,178 @@ +// -*- 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_TUPLE_H +#define _LIBCPP___FORMAT_FORMATTER_TUPLE_H + +#include <__algorithm/ranges_copy.h> +#include <__availability> +#include <__chrono/statically_widen.h> +#include <__config> +#include <__format/concepts.h> +#include <__format/format_args.h> +#include <__format/format_context.h> +#include <__format/format_error.h> +#include <__format/format_parse_context.h> +#include <__format/formatter.h> +#include <__format/formatter_output.h> +#include <__format/parser_std_format_spec.h> +#include <__iterator/back_insert_iterator.h> +#include <__type_traits/remove_cvref.h> +#include <__utility/integer_sequence.h> +#include <__utility/pair.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 + +template <__fmt_char_type _CharT, class _Tuple, formattable<_CharT>... _Args> +struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT __formatter_tuple { + _LIBCPP_HIDE_FROM_ABI constexpr void set_separator(basic_string_view<_CharT> __separator) { + __separator_ = __separator; + } + _LIBCPP_HIDE_FROM_ABI constexpr void + set_brackets(basic_string_view<_CharT> __opening_bracket, basic_string_view<_CharT> __closing_bracket) { + __opening_bracket_ = __opening_bracket; + __closing_bracket_ = __closing_bracket; + } + + template + _LIBCPP_HIDE_FROM_ABI constexpr typename _ParseContext::iterator parse(_ParseContext& __parse_ctx) { + const _CharT* __begin = __parser_.__parse(__parse_ctx, __format_spec::__fields_tuple); + + // [format.tuple]/7 + // ... For each element e in underlying_, if e.set_debug_format() + // is a valid expression, calls e.set_debug_format(). + // TODO FMT this can be removed when P2733 is accepted. + std::__for_each_index_sequence(make_index_sequence(), [&] { + std::__set_debug_format(std::get<_Index>(__underlying_)); + }); + + const _CharT* __end = __parse_ctx.end(); + if (__begin == __end) + return __begin; + + if (*__begin == _CharT('m')) { + if constexpr (sizeof...(_Args) == 2) { + set_separator(_LIBCPP_STATICALLY_WIDEN(_CharT, ": ")); + set_brackets({}, {}); + ++__begin; + } else + std::__throw_format_error("The format specifier m requires a pair or a two-element tuple"); + } else if (*__begin == _CharT('n')) { + set_brackets({}, {}); + ++__begin; + } + + if (__begin != __end && *__begin != _CharT('}')) + std::__throw_format_error("The format-spec should consume the input or end with a '}'"); + + return __begin; + } + + template + typename _FormatContext::iterator _LIBCPP_HIDE_FROM_ABI + format(conditional_t<(formattable && ...), const _Tuple&, _Tuple&> __tuple, + _FormatContext& __ctx) const { + __format_spec::__parsed_specifications<_CharT> __specs = __parser_.__get_parsed_std_specifications(__ctx); + + if (!__specs.__has_width()) + return __format_tuple(__tuple, __ctx); + + basic_string<_CharT> __str; + + // Since the output is written to a different iterator a new context is + // created. Since the underlying formatter uses the default formatting it + // doesn't need a locale or the formatting arguments. So creating a new + // context works. + // + // This solution works for this formatter, but it will not work for the + // range_formatter. In that patch a generic solution is work in progress. + // Once that is finished it can be used here. (The range_formatter will use + // these features so it's easier to add it there and then port it.) + // + // TODO FMT Use formatting wrapping used in the range_formatter. + basic_format_context __c = std::__format_context_create( + back_insert_iterator{__str}, + basic_format_args>, _CharT>>{}); + + __format_tuple(__tuple, __c); + + return __formatter::__write_string_no_precision(basic_string_view{__str}, __ctx.out(), __specs); + } + + template + _LIBCPP_HIDE_FROM_ABI typename _FormatContext::iterator __format_tuple(auto&& __tuple, _FormatContext& __ctx) const { + __ctx.advance_to(std::ranges::copy(__opening_bracket_, __ctx.out()).out); + + std::__for_each_index_sequence(make_index_sequence(), [&] { + if constexpr (_Index) + __ctx.advance_to(std::ranges::copy(__separator_, __ctx.out()).out); + + // During review Victor suggested to make the exposition only + // __underlying_ member a local variable. Currently the Standard + // requires nested debug-enabled formatter specializations not to + // output escaped output. P2733 fixes that bug, once accepted the + // code below can be used. + // (Note when a paper allows parsing a tuple-underlying-spec the + // exposition only member needs to be a class member. Earlier + // revisions of P2286 proposed that, but this was not pursued, + // due to time constrains and complexity of the matter.) + // TODO FMT This can be updated after P2733 is accepted. +# if 0 + // P2286 uses an exposition only member in the formatter + // tuple, _CharT>...> __underlying_; + // This was used in earlier versions of the paper since + // __underlying_.parse(...) was called. This is no longer the case + // so we can reduce the scope of the formatter. + // + // It does require the underlying's parse effect to be moved here too. + using _Arg = tuple_element<_Index, decltype(__tuple)>; + formatter, _CharT> __underlying; + + // [format.tuple]/7 + // ... For each element e in underlying_, if e.set_debug_format() + // is a valid expression, calls e.set_debug_format(). + std::__set_debug_format(__underlying); +# else + __ctx.advance_to(std::get<_Index>(__underlying_).format(std::get<_Index>(__tuple), __ctx)); +# endif + }); + + return std::ranges::copy(__closing_bracket_, __ctx.out()).out; + } + + __format_spec::__parser<_CharT> __parser_{.__alignment_ = __format_spec::__alignment::__left}; + +private: + tuple, _CharT>...> __underlying_; + basic_string_view<_CharT> __separator_ = _LIBCPP_STATICALLY_WIDEN(_CharT, ", "); + basic_string_view<_CharT> __opening_bracket_ = _LIBCPP_STATICALLY_WIDEN(_CharT, "("); + basic_string_view<_CharT> __closing_bracket_ = _LIBCPP_STATICALLY_WIDEN(_CharT, ")"); +}; + +template <__fmt_char_type _CharT, formattable<_CharT>... _Args> +struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter, _CharT> + : public __formatter_tuple<_CharT, pair<_Args...>, _Args...> {}; + +template <__fmt_char_type _CharT, formattable<_CharT>... _Args> +struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter, _CharT> + : public __formatter_tuple<_CharT, tuple<_Args...>, _Args...> {}; + +#endif //_LIBCPP_STD_VER > 20 + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___FORMAT_FORMATTER_TUPLE_H diff --git a/lib/libcxx/include/__format/parser_std_format_spec.h b/lib/libcxx/include/__format/parser_std_format_spec.h index 1425a953eb..c03cec9796 100644 --- a/lib/libcxx/include/__format/parser_std_format_spec.h +++ b/lib/libcxx/include/__format/parser_std_format_spec.h @@ -19,6 +19,8 @@ #include <__algorithm/find_if.h> #include <__algorithm/min.h> #include <__assert> +#include <__concepts/arithmetic.h> +#include <__concepts/same_as.h> #include <__config> #include <__debug> #include <__format/format_arg.h> @@ -28,7 +30,6 @@ #include <__format/unicode.h> #include <__variant/monostate.h> #include -#include #include #include #include @@ -52,13 +53,12 @@ __parse_arg_id(const _CharT* __begin, const _CharT* __end, auto& __parse_ctx) { // This function is a wrapper to call the real parser. But it does the // validation for the pre-conditions and post-conditions. if (__begin == __end) - __throw_format_error("End of input while parsing format-spec arg-id"); + std::__throw_format_error("End of input while parsing format-spec arg-id"); - __format::__parse_number_result __r = - __format::__parse_arg_id(__begin, __end, __parse_ctx); + __format::__parse_number_result __r = __format::__parse_arg_id(__begin, __end, __parse_ctx); if (__r.__ptr == __end || *__r.__ptr != _CharT('}')) - __throw_format_error("Invalid arg-id"); + std::__throw_format_error("Invalid arg-id"); ++__r.__ptr; return __r; @@ -67,28 +67,33 @@ __parse_arg_id(const _CharT* __begin, const _CharT* __end, auto& __parse_ctx) { template _LIBCPP_HIDE_FROM_ABI constexpr uint32_t __substitute_arg_id(basic_format_arg<_Context> __format_arg) { - return visit_format_arg( + // [format.string.std]/8 + // If the corresponding formatting argument is not of integral type... + // This wording allows char and bool too. LWG-3720 changes the wording to + // If the corresponding formatting argument is not of standard signed or + // unsigned integer type, + // This means the 128-bit will not be valid anymore. + // TODO FMT Verify this resolution is accepted and add a test to verify + // 128-bit integrals fail and switch to visit_format_arg. + return _VSTD::__visit_format_arg( [](auto __arg) -> uint32_t { using _Type = decltype(__arg); if constexpr (integral<_Type>) { if constexpr (signed_integral<_Type>) { if (__arg < 0) - __throw_format_error("A format-spec arg-id replacement shouldn't " - "have a negative value"); + std::__throw_format_error("A format-spec arg-id replacement shouldn't have a negative value"); } using _CT = common_type_t<_Type, decltype(__format::__number_max)>; if (static_cast<_CT>(__arg) > static_cast<_CT>(__format::__number_max)) - __throw_format_error("A format-spec arg-id replacement exceeds " - "the maximum supported value"); + std::__throw_format_error("A format-spec arg-id replacement exceeds the maximum supported value"); return __arg; } else if constexpr (same_as<_Type, monostate>) - __throw_format_error("Argument index out of bounds"); + std::__throw_format_error("Argument index out of bounds"); else - __throw_format_error("A format-spec arg-id replacement argument " - "isn't an integral type"); + std::__throw_format_error("A format-spec arg-id replacement argument isn't an integral type"); }, __format_arg); } @@ -97,6 +102,7 @@ __substitute_arg_id(basic_format_arg<_Context> __format_arg) { /// /// They default to false so when a new field is added it needs to be opted in /// explicitly. +// TODO FMT Use an ABI tag for this struct. struct __fields { uint8_t __sign_ : 1 {false}; uint8_t __alternate_form_ : 1 {false}; @@ -104,6 +110,13 @@ struct __fields { uint8_t __precision_ : 1 {false}; uint8_t __locale_specific_form_ : 1 {false}; uint8_t __type_ : 1 {false}; + // Determines the valid values for fill. + // + // Originally the fill could be any character except { and }. Range-based + // formatters use the colon to mark the beginning of the + // underlying-format-spec. To avoid parsing ambiguities these formatter + // specializations prohibit the use of the colon as a fill character. + uint8_t __allow_colon_in_fill_ : 1 {false}; }; // By not placing this constant in the formatter class it's not duplicated for @@ -124,6 +137,11 @@ inline constexpr __fields __fields_floating_point{ inline constexpr __fields __fields_string{.__precision_ = true, .__type_ = true}; inline constexpr __fields __fields_pointer{.__type_ = true}; +# if _LIBCPP_STD_VER > 20 +inline constexpr __fields __fields_tuple{.__type_ = false, .__allow_colon_in_fill_ = true}; +inline constexpr __fields __fields_range{.__type_ = false, .__allow_colon_in_fill_ = true}; +# endif + enum class _LIBCPP_ENUM_VIS __alignment : uint8_t { /// No alignment is set in the format string. __default, @@ -163,7 +181,8 @@ enum class _LIBCPP_ENUM_VIS __type : uint8_t { __fixed_lower_case, __fixed_upper_case, __general_lower_case, - __general_upper_case + __general_upper_case, + __debug }; struct __std { @@ -176,7 +195,11 @@ struct __std { struct __chrono { __alignment __alignment_ : 3; + bool __locale_specific_form_ : 1; bool __weekday_name_ : 1; + bool __weekday_ : 1; + bool __day_of_year_ : 1; + bool __week_of_year_ : 1; bool __month_name_ : 1; }; @@ -250,7 +273,7 @@ public: if (__begin == __end) return __begin; - if (__parse_fill_align(__begin, __end) && __begin == __end) + if (__parse_fill_align(__begin, __end, __fields.__allow_colon_in_fill_) && __begin == __end) return __begin; if (__fields.__sign_ && __parse_sign(__begin) && __begin == __end) @@ -278,7 +301,7 @@ public: // parsing. In that case that parser should do the end of format string // validation. if (__begin != __end && *__begin != _CharT('}')) - __throw_format_error("The format-spec should consume the input or end with a '}'"); + std::__throw_format_error("The format-spec should consume the input or end with a '}'"); } return __begin; @@ -288,12 +311,26 @@ public: _LIBCPP_HIDE_FROM_ABI __parsed_specifications<_CharT> __get_parsed_std_specifications(auto& __ctx) const { return __parsed_specifications<_CharT>{ - .__std_ = - __std{.__alignment_ = __alignment_, - .__sign_ = __sign_, - .__alternate_form_ = __alternate_form_, - .__locale_specific_form_ = __locale_specific_form_, - .__type_ = __type_}, + .__std_ = __std{.__alignment_ = __alignment_, + .__sign_ = __sign_, + .__alternate_form_ = __alternate_form_, + .__locale_specific_form_ = __locale_specific_form_, + .__type_ = __type_}, + .__width_{__get_width(__ctx)}, + .__precision_{__get_precision(__ctx)}, + .__fill_{__fill_}}; + } + + _LIBCPP_HIDE_FROM_ABI __parsed_specifications<_CharT> __get_parsed_chrono_specifications(auto& __ctx) const { + return __parsed_specifications<_CharT>{ + .__chrono_ = + __chrono{.__alignment_ = __alignment_, + .__locale_specific_form_ = __locale_specific_form_, + .__weekday_name_ = __weekday_name_, + .__weekday_ = __weekday_, + .__day_of_year_ = __day_of_year_, + .__week_of_year_ = __week_of_year_, + .__month_name_ = __month_name_}, .__width_{__get_width(__ctx)}, .__precision_{__get_precision(__ctx)}, .__fill_{__fill_}}; @@ -306,12 +343,17 @@ public: bool __reserved_0_ : 1 {false}; __type __type_{__type::__default}; - // These two flags are used for formatting chrono. Since the struct has + // These flags are only used for formatting chrono. Since the struct has // padding space left it's added to this structure. bool __weekday_name_ : 1 {false}; + bool __weekday_ : 1 {false}; + + bool __day_of_year_ : 1 {false}; + bool __week_of_year_ : 1 {false}; + bool __month_name_ : 1 {false}; - uint8_t __reserved_1_ : 6 {0}; + uint8_t __reserved_1_ : 3 {0}; uint8_t __reserved_2_ : 6 {0}; // These two flags are only used internally and not part of the // __parsed_specifications. Therefore put them at the end. @@ -348,13 +390,17 @@ private: return false; } - _LIBCPP_HIDE_FROM_ABI constexpr bool __parse_fill_align(const _CharT*& __begin, const _CharT* __end) { + // range-fill and tuple-fill are identical + _LIBCPP_HIDE_FROM_ABI constexpr bool + __parse_fill_align(const _CharT*& __begin, const _CharT* __end, bool __use_range_fill) { _LIBCPP_ASSERT(__begin != __end, "when called with an empty input the function will cause " "undefined behavior by evaluating data not in the input"); if (__begin + 1 != __end) { if (__parse_alignment(*(__begin + 1))) { - if (*__begin == _CharT('{') || *__begin == _CharT('}')) - __throw_format_error("The format-spec fill field contains an invalid character"); + if (__use_range_fill && (*__begin == _CharT('{') || *__begin == _CharT('}') || *__begin == _CharT(':'))) + std::__throw_format_error("The format-spec range-fill field contains an invalid character"); + else if (*__begin == _CharT('{') || *__begin == _CharT('}')) + std::__throw_format_error("The format-spec fill field contains an invalid character"); __fill_ = *__begin; __begin += 2; @@ -408,7 +454,7 @@ private: _LIBCPP_HIDE_FROM_ABI constexpr bool __parse_width(const _CharT*& __begin, const _CharT* __end, auto& __parse_ctx) { if (*__begin == _CharT('0')) - __throw_format_error("A format-spec width field shouldn't have a leading zero"); + std::__throw_format_error("A format-spec width field shouldn't have a leading zero"); if (*__begin == _CharT('{')) { __format::__parse_number_result __r = __format_spec::__parse_arg_id(++__begin, __end, __parse_ctx); @@ -436,7 +482,7 @@ private: ++__begin; if (__begin == __end) - __throw_format_error("End of input while parsing format-spec precision"); + std::__throw_format_error("End of input while parsing format-spec precision"); if (*__begin == _CharT('{')) { __format::__parse_number_result __arg_id = __format_spec::__parse_arg_id(++__begin, __end, __parse_ctx); @@ -447,7 +493,7 @@ private: } if (*__begin < _CharT('0') || *__begin > _CharT('9')) - __throw_format_error("The format-spec precision field doesn't contain a value or arg-id"); + std::__throw_format_error("The format-spec precision field doesn't contain a value or arg-id"); __format::__parse_number_result __r = __format::__parse_number(__begin, __end); __precision_ = __r.__value; @@ -523,6 +569,11 @@ private: case 'x': __type_ = __type::__hexadecimal_lower_case; break; +# if _LIBCPP_STD_VER > 20 + case '?': + __type_ = __type::__debug; + break; +# endif default: return; } @@ -534,10 +585,7 @@ private: if (!__width_as_arg_) return __width_; - int32_t __result = __format_spec::__substitute_arg_id(__ctx.arg(__width_)); - if (__result == 0) - __throw_format_error("A format-spec width field replacement should have a positive value"); - return __result; + return __format_spec::__substitute_arg_id(__ctx.arg(__width_)); } _LIBCPP_HIDE_FROM_ABI @@ -559,6 +607,7 @@ _LIBCPP_HIDE_FROM_ABI constexpr void __process_display_type_string(__format_spec switch (__type) { case __format_spec::__type::__default: case __format_spec::__type::__string: + case __format_spec::__type::__debug: break; default: @@ -612,6 +661,7 @@ _LIBCPP_HIDE_FROM_ABI constexpr void __process_parsed_char(__parser<_CharT>& __p switch (__parser.__type_) { case __format_spec::__type::__default: case __format_spec::__type::__char: + case __format_spec::__type::__debug: __format_spec::__process_display_type_char(__parser); break; @@ -653,11 +703,6 @@ template _LIBCPP_HIDE_FROM_ABI constexpr void __process_parsed_floating_point(__parser<_CharT>& __parser) { switch (__parser.__type_) { case __format_spec::__type::__default: - // When no precision specified then it keeps default since that - // formatting differs from the other types. - if (__parser.__precision_as_arg_ || __parser.__precision_ != -1) - __parser.__type_ = __format_spec::__type::__general_lower_case; - break; case __format_spec::__type::__hexfloat_lower_case: case __format_spec::__type::__hexfloat_upper_case: // Precision specific behavior will be handled later. @@ -699,6 +744,9 @@ struct __column_width_result { const _CharT* __last_; }; +template +__column_width_result(size_t, const _CharT*) -> __column_width_result<_CharT>; + /// Since a column width can be two it's possible that the requested column /// width can't be achieved. Depending on the intended usage the policy can be /// selected. @@ -857,7 +905,7 @@ _LIBCPP_HIDE_FROM_ABI constexpr __column_width_result<_CharT> __estimate_column_ // unit is non-ASCII we omit the current code unit and let the Grapheme // clustering algorithm do its work. const _CharT* __it = __str.begin(); - if (__is_ascii(*__it)) { + if (__format_spec::__is_ascii(*__it)) { do { --__maximum; ++__it; @@ -865,12 +913,12 @@ _LIBCPP_HIDE_FROM_ABI constexpr __column_width_result<_CharT> __estimate_column_ return {__str.size(), __str.end()}; if (__maximum == 0) { - if (__is_ascii(*__it)) + if (__format_spec::__is_ascii(*__it)) return {static_cast(__it - __str.begin()), __it}; break; } - } while (__is_ascii(*__it)); + } while (__format_spec::__is_ascii(*__it)); --__it; ++__maximum; } diff --git a/lib/libcxx/include/__format/range_default_formatter.h b/lib/libcxx/include/__format/range_default_formatter.h new file mode 100644 index 0000000000..774887b053 --- /dev/null +++ b/lib/libcxx/include/__format/range_default_formatter.h @@ -0,0 +1,201 @@ +// -*- 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_RANGE_DEFAULT_FORMATTER_H +#define _LIBCPP___FORMAT_RANGE_DEFAULT_FORMATTER_H + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +#include <__availability> +#include <__chrono/statically_widen.h> +#include <__concepts/same_as.h> +#include <__config> +#include <__format/concepts.h> +#include <__format/formatter.h> +#include <__format/range_formatter.h> +#include <__ranges/concepts.h> +#include <__type_traits/remove_cvref.h> +#include <__utility/pair.h> +#include +#include + +_LIBCPP_BEGIN_NAMESPACE_STD + +#if _LIBCPP_STD_VER > 20 + +template +concept __const_formattable_range = + ranges::input_range && formattable, _CharT>; + +template +using __fmt_maybe_const = conditional_t<__const_formattable_range<_Rp, _CharT>, const _Rp, _Rp>; + +_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 + +// There is no definition of this struct, it's purely intended to be used to +// generate diagnostics. +template +struct _LIBCPP_TEMPLATE_VIS __instantiated_the_primary_template_of_format_kind; + +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; +}(); + +template + requires same_as<_Rp, remove_cvref_t<_Rp>> +inline constexpr range_format format_kind<_Rp> = [] { + // [format.range.fmtkind]/2 + + // 2.1 If same_as>, R> is true, + // Otherwise format_kind is range_format::disabled. + if constexpr (same_as>, _Rp>) + return range_format::disabled; + // 2.2 Otherwise, if the qualified-id R::key_type is valid and denotes a type: + else if constexpr (requires { typename _Rp::key_type; }) { + // 2.2.1 If the qualified-id R::mapped_type is valid and denotes a type ... + if constexpr (requires { typename _Rp::mapped_type; } && + // 2.2.1 ... If either U is a specialization of pair or U is a specialization + // of tuple and tuple_size_v == 2 + __fmt_pair_like>>) + return range_format::map; + else + // 2.2.2 Otherwise format_kind is range_format::set. + return range_format::set; + } else + // 2.3 Otherwise, format_kind is range_format::sequence. + return range_format::sequence; +}(); + +// This is a non-standard work-around to fix instantiation of +// formatter +// const _CharT[N] satisfies the ranges::input_range concept. +// remove_cvref_t is _CharT[N] so it does not satisfy the +// requirement of the above specialization. Instead it will instantiate the +// primary template, which is ill-formed. +// +// An alternative solution is to remove the offending formatter. +// +// https://godbolt.org/z/bqjhhaexx +// +// The removal is proposed in LWG3833, but use the work-around until the issue +// has been adopted. +// TODO FMT Implement LWG3833. +template +inline constexpr range_format format_kind = range_format::disabled; + +template +struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT __range_default_formatter; + +// Required specializations + +template +struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT __range_default_formatter { +private: + using __maybe_const_r = __fmt_maybe_const<_Rp, _CharT>; + range_formatter>, _CharT> __underlying_; + +public: + _LIBCPP_HIDE_FROM_ABI constexpr void set_separator(basic_string_view<_CharT> __separator) { + __underlying_.set_separator(__separator); + } + _LIBCPP_HIDE_FROM_ABI constexpr void + set_brackets(basic_string_view<_CharT> __opening_bracket, basic_string_view<_CharT> __closing_bracket) { + __underlying_.set_brackets(__opening_bracket, __closing_bracket); + } + + template + _LIBCPP_HIDE_FROM_ABI constexpr typename _ParseContext::iterator parse(_ParseContext& __ctx) { + return __underlying_.parse(__ctx); + } + + template + _LIBCPP_HIDE_FROM_ABI typename FormatContext::iterator format(__maybe_const_r& __range, FormatContext& __ctx) const { + return __underlying_.format(__range, __ctx); + } +}; + +template +struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT __range_default_formatter { +private: + using __maybe_const_map = __fmt_maybe_const<_Rp, _CharT>; + using __element_type = remove_cvref_t>; + range_formatter<__element_type, _CharT> __underlying_; + +public: + _LIBCPP_HIDE_FROM_ABI constexpr __range_default_formatter() + requires(__fmt_pair_like<__element_type>) + { + __underlying_.set_brackets(_LIBCPP_STATICALLY_WIDEN(_CharT, "{"), _LIBCPP_STATICALLY_WIDEN(_CharT, "}")); + __underlying_.underlying().set_brackets({}, {}); + __underlying_.underlying().set_separator(_LIBCPP_STATICALLY_WIDEN(_CharT, ": ")); + } + + template + _LIBCPP_HIDE_FROM_ABI constexpr typename _ParseContext::iterator parse(_ParseContext& __ctx) { + return __underlying_.parse(__ctx); + } + + template + _LIBCPP_HIDE_FROM_ABI typename _FormatContext::iterator + format(__maybe_const_map& __range, _FormatContext& __ctx) const { + return __underlying_.format(__range, __ctx); + } +}; + +template +struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT __range_default_formatter { +private: + using __maybe_const_set = __fmt_maybe_const<_Rp, _CharT>; + using __element_type = remove_cvref_t>; + range_formatter<__element_type, _CharT> __underlying_; + +public: + _LIBCPP_HIDE_FROM_ABI constexpr __range_default_formatter() { + __underlying_.set_brackets(_LIBCPP_STATICALLY_WIDEN(_CharT, "{"), _LIBCPP_STATICALLY_WIDEN(_CharT, "}")); + } + + template + _LIBCPP_HIDE_FROM_ABI constexpr typename _ParseContext::iterator parse(_ParseContext& __ctx) { + return __underlying_.parse(__ctx); + } + + template + _LIBCPP_HIDE_FROM_ABI typename _FormatContext::iterator + format(__maybe_const_set& __range, _FormatContext& __ctx) const { + return __underlying_.format(__range, __ctx); + } +}; + +template + requires(_Kp == range_format::string || _Kp == range_format::debug_string) +struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT __range_default_formatter<_Kp, _Rp, _CharT> { + __range_default_formatter() = delete; // TODO FMT Implement +}; + +template + requires(format_kind<_Rp> != range_format::disabled && formattable, _CharT>) +struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter<_Rp, _CharT> + : __range_default_formatter, _Rp, _CharT> {}; + +#endif //_LIBCPP_STD_VER > 20 + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___FORMAT_RANGE_DEFAULT_FORMATTER_H diff --git a/lib/libcxx/include/__format/range_formatter.h b/lib/libcxx/include/__format/range_formatter.h new file mode 100644 index 0000000000..9ea61a7035 --- /dev/null +++ b/lib/libcxx/include/__format/range_formatter.h @@ -0,0 +1,255 @@ +// -*- 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_RANGE_FORMATTER_H +#define _LIBCPP___FORMAT_RANGE_FORMATTER_H + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +#include <__algorithm/ranges_copy.h> +#include <__availability> +#include <__chrono/statically_widen.h> +#include <__concepts/same_as.h> +#include <__config> +#include <__format/buffer.h> +#include <__format/concepts.h> +#include <__format/format_args.h> +#include <__format/format_context.h> +#include <__format/format_error.h> +#include <__format/formatter.h> +#include <__format/formatter_output.h> +#include <__format/parser_std_format_spec.h> +#include <__iterator/back_insert_iterator.h> +#include <__ranges/concepts.h> +#include <__ranges/data.h> +#include <__ranges/size.h> +#include <__type_traits/remove_cvref.h> +#include + +_LIBCPP_BEGIN_NAMESPACE_STD + +#if _LIBCPP_STD_VER > 20 + +template + requires same_as, _Tp> && formattable<_Tp, _CharT> +struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT range_formatter { + _LIBCPP_HIDE_FROM_ABI constexpr void set_separator(basic_string_view<_CharT> __separator) { + __separator_ = __separator; + } + _LIBCPP_HIDE_FROM_ABI constexpr void + set_brackets(basic_string_view<_CharT> __opening_bracket, basic_string_view<_CharT> __closing_bracket) { + __opening_bracket_ = __opening_bracket; + __closing_bracket_ = __closing_bracket; + } + + _LIBCPP_HIDE_FROM_ABI constexpr formatter<_Tp, _CharT>& underlying() { return __underlying_; } + _LIBCPP_HIDE_FROM_ABI constexpr const formatter<_Tp, _CharT>& underlying() const { return __underlying_; } + + template + _LIBCPP_HIDE_FROM_ABI constexpr typename _ParseContext::iterator parse(_ParseContext& __parse_ctx) { + const _CharT* __begin = __parser_.__parse(__parse_ctx, __format_spec::__fields_range); + const _CharT* __end = __parse_ctx.end(); + if (__begin == __end) + return __begin; + + // The n field overrides a possible m type, therefore delay applying the + // effect of n until the type has been procesed. + bool __clear_brackets = (*__begin == _CharT('n')); + if (__clear_brackets) { + ++__begin; + if (__begin == __end) { + // Since there is no more data, clear the brackets before returning. + set_brackets({}, {}); + return __begin; + } + } + + __parse_type(__begin, __end); + if (__clear_brackets) + set_brackets({}, {}); + if (__begin == __end) + return __begin; + + bool __has_range_underlying_spec = *__begin == _CharT(':'); + if (__parser_.__type_ != __format_spec::__type::__default) { + // [format.range.formatter]/6 + // If the range-type is s or ?s, then there shall be no n option and no + // range-underlying-spec. + if (__clear_brackets) { + if (__parser_.__type_ == __format_spec::__type::__string) + std::__throw_format_error("The n option and type s can't be used together"); + std::__throw_format_error("The n option and type ?s can't be used together"); + } + if (__has_range_underlying_spec) { + if (__parser_.__type_ == __format_spec::__type::__string) + std::__throw_format_error("Type s and an underlying format specification can't be used together"); + std::__throw_format_error("Type ?s and an underlying format specification can't be used together"); + } + } else if (!__has_range_underlying_spec) + std::__set_debug_format(__underlying_); + + if (__has_range_underlying_spec) { + // range-underlying-spec: + // : format-spec + ++__begin; + if (__begin == __end) + return __begin; + + __parse_ctx.advance_to(__begin); + __begin = __underlying_.parse(__parse_ctx); + } + + if (__begin != __end && *__begin != _CharT('}')) + std::__throw_format_error("The format-spec should consume the input or end with a '}'"); + + return __begin; + } + + template + requires formattable, _CharT> && + same_as>, _Tp> + _LIBCPP_HIDE_FROM_ABI typename _FormatContext::iterator format(_Rp&& __range, _FormatContext& __ctx) const { + __format_spec::__parsed_specifications<_CharT> __specs = __parser_.__get_parsed_std_specifications(__ctx); + + if (!__specs.__has_width()) + return __format_range(__range, __ctx, __specs); + + // The size of the buffer needed is: + // - open bracket characters + // - close bracket character + // - n elements where every element may have a different size + // - (n -1) separators + // The size of the element is hard to predict, knowing the type helps but + // it depends on the format-spec. As an initial estimate we guess 6 + // characters. + // Typically both brackets are 1 character and the separator is 2 + // characters. Which means there will be + // (n - 1) * 2 + 1 + 1 = n * 2 character + // So estimate 8 times the range size as buffer. + std::size_t __capacity_hint = 0; + if constexpr (std::ranges::sized_range<_Rp>) + __capacity_hint = 8 * ranges::size(__range); + __format::__retarget_buffer<_CharT> __buffer{__capacity_hint}; + basic_format_context::__iterator, _CharT> __c{ + __buffer.__make_output_iterator(), __ctx}; + + __format_range(__range, __c, __specs); + + return __formatter::__write_string_no_precision(__buffer.__view(), __ctx.out(), __specs); + } + + template + typename _FormatContext::iterator _LIBCPP_HIDE_FROM_ABI + __format_range(_Rp&& __range, _FormatContext& __ctx, __format_spec::__parsed_specifications<_CharT> __specs) const { + if constexpr (same_as<_Tp, _CharT>) { + switch (__specs.__std_.__type_) { + case __format_spec::__type::__string: + case __format_spec::__type::__debug: + return __format_as_string(__range, __ctx, __specs.__std_.__type_ == __format_spec::__type::__debug); + default: + return __format_as_sequence(__range, __ctx); + } + } else + return __format_as_sequence(__range, __ctx); + } + + template + _LIBCPP_HIDE_FROM_ABI typename _FormatContext::iterator + __format_as_string(_Rp&& __range, _FormatContext& __ctx, bool __debug_format) const { + // When the range is contiguous use a basic_string_view instead to avoid a + // copy of the underlying data. The basic_string_view formatter + // specialization is the "basic" string formatter in libc++. + if constexpr (ranges::contiguous_range<_Rp> && std::ranges::sized_range<_Rp>) { + std::formatter, _CharT> __formatter; + if (__debug_format) + __formatter.set_debug_format(); + return __formatter.format( + basic_string_view<_CharT>{ + ranges::data(__range), + ranges::size(__range), + }, + __ctx); + } else { + std::formatter, _CharT> __formatter; + if (__debug_format) + __formatter.set_debug_format(); + // P2106's from_range has not been implemented yet. Instead use a simple + // copy operation. + // TODO FMT use basic_string's "from_range" constructor. + // return std::formatter, _CharT>{}.format(basic_string<_CharT>{from_range, __range}, __ctx); + basic_string<_CharT> __str; + ranges::copy(__range, back_insert_iterator{__str}); + return __formatter.format(__str, __ctx); + } + } + + template + _LIBCPP_HIDE_FROM_ABI typename _FormatContext::iterator + __format_as_sequence(_Rp&& __range, _FormatContext& __ctx) const { + __ctx.advance_to(ranges::copy(__opening_bracket_, __ctx.out()).out); + bool __use_separator = false; + for (auto&& __e : __range) { + if (__use_separator) + __ctx.advance_to(ranges::copy(__separator_, __ctx.out()).out); + else + __use_separator = true; + + __ctx.advance_to(__underlying_.format(__e, __ctx)); + } + + return ranges::copy(__closing_bracket_, __ctx.out()).out; + } + + __format_spec::__parser<_CharT> __parser_{.__alignment_ = __format_spec::__alignment::__left}; + +private: + _LIBCPP_HIDE_FROM_ABI constexpr void __parse_type(const _CharT*& __begin, const _CharT* __end) { + switch (*__begin) { + case _CharT('m'): + if constexpr (__fmt_pair_like<_Tp>) { + set_brackets(_LIBCPP_STATICALLY_WIDEN(_CharT, "{"), _LIBCPP_STATICALLY_WIDEN(_CharT, "}")); + set_separator(_LIBCPP_STATICALLY_WIDEN(_CharT, ", ")); + ++__begin; + } else + std::__throw_format_error("The range-format-spec type m requires two elements for a pair or tuple"); + break; + + case _CharT('s'): + if constexpr (same_as<_Tp, _CharT>) { + __parser_.__type_ = __format_spec::__type::__string; + ++__begin; + } else + std::__throw_format_error("The range-format-spec type s requires formatting a character type"); + break; + + case _CharT('?'): + ++__begin; + if (__begin == __end || *__begin != _CharT('s')) + std::__throw_format_error("The format-spec should consume the input or end with a '}'"); + if constexpr (same_as<_Tp, _CharT>) { + __parser_.__type_ = __format_spec::__type::__debug; + ++__begin; + } else + std::__throw_format_error("The range-format-spec type ?s requires formatting a character type"); + } + } + + formatter<_Tp, _CharT> __underlying_; + basic_string_view<_CharT> __separator_ = _LIBCPP_STATICALLY_WIDEN(_CharT, ", "); + basic_string_view<_CharT> __opening_bracket_ = _LIBCPP_STATICALLY_WIDEN(_CharT, "["); + basic_string_view<_CharT> __closing_bracket_ = _LIBCPP_STATICALLY_WIDEN(_CharT, "]"); +}; + +#endif //_LIBCPP_STD_VER > 20 + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___FORMAT_RANGE_FORMATTER_H diff --git a/lib/libcxx/include/__format/unicode.h b/lib/libcxx/include/__format/unicode.h index 3316217f4a..4327258760 100644 --- a/lib/libcxx/include/__format/unicode.h +++ b/lib/libcxx/include/__format/unicode.h @@ -13,6 +13,7 @@ #include <__assert> #include <__config> #include <__format/extended_grapheme_cluster_table.h> +#include <__type_traits/make_unsigned.h> #include <__utility/unreachable.h> #include @@ -24,6 +25,26 @@ _LIBCPP_BEGIN_NAMESPACE_STD #if _LIBCPP_STD_VER > 17 +namespace __unicode { + +# if _LIBCPP_STD_VER > 20 + +/// The result of consuming a code point using P2286' semantics +/// +/// TODO FMT Combine __consume and __consume_p2286 in one function. +struct __consume_p2286_result { + // A size of 0 means well formed. This to differenciate between + // a valid code point and a code unit that's invalid like 0b11111xxx. + int __ill_formed_size; + + // If well formed the consumed code point. + // Otherwise the ill-formed code units as unsigned 8-bit values. They are + // stored in reverse order, to make it easier to extract the values. + char32_t __value; +}; + +# endif // _LIBCPP_STD_VER > 20 + # ifndef _LIBCPP_HAS_NO_UNICODE /// Implements the grapheme cluster boundary rules @@ -39,8 +60,6 @@ _LIBCPP_BEGIN_NAMESPACE_STD /// https://www.unicode.org/Public/UCD/latest/ucd/emoji/emoji-data.txt /// https://www.unicode.org/Public/UCD/latest/ucd/auxiliary/GraphemeBreakTest.txt (for testing only) -namespace __unicode { - inline constexpr char32_t __replacement_character = U'\ufffd'; _LIBCPP_HIDE_FROM_ABI constexpr bool __is_continuation(const char* __char, int __count) { @@ -123,18 +142,92 @@ public: return __replacement_character; } +# if _LIBCPP_STD_VER > 20 + _LIBCPP_HIDE_FROM_ABI constexpr __consume_p2286_result __consume_p2286() noexcept { + _LIBCPP_ASSERT(__first_ != __last_, "can't move beyond the end of input"); + + // Based on the number of leading 1 bits the number of code units in the + // code point can be determined. See + // https://en.wikipedia.org/wiki/UTF-8#Encoding + switch (std::countl_one(static_cast(*__first_))) { + case 0: + return {0, static_cast(*__first_++)}; + + case 2: + if (__last_ - __first_ < 2) [[unlikely]] + break; + + if (__unicode::__is_continuation(__first_ + 1, 1)) { + char32_t __value = static_cast(*__first_++) & 0x1f; + __value <<= 6; + __value |= static_cast(*__first_++) & 0x3f; + return {0, __value}; + } + break; + + case 3: + if (__last_ - __first_ < 3) [[unlikely]] + break; + + if (__unicode::__is_continuation(__first_ + 1, 2)) { + char32_t __value = static_cast(*__first_++) & 0x0f; + __value <<= 6; + __value |= static_cast(*__first_++) & 0x3f; + __value <<= 6; + __value |= static_cast(*__first_++) & 0x3f; + return {0, __value}; + } + break; + + case 4: + if (__last_ - __first_ < 4) [[unlikely]] + break; + + if (__unicode::__is_continuation(__first_ + 1, 3)) { + char32_t __value = static_cast(*__first_++) & 0x07; + __value <<= 6; + __value |= static_cast(*__first_++) & 0x3f; + __value <<= 6; + __value |= static_cast(*__first_++) & 0x3f; + __value <<= 6; + __value |= static_cast(*__first_++) & 0x3f; + + if (__value > 0x10FFFF) // Outside the valid Unicode range? + return {4, __value}; + + return {0, __value}; + } + break; + } + // An invalid number of leading ones can be garbage or a code unit in the + // middle of a code point. By consuming one code unit the parser may get + // "in sync" after a few code units. + return {1, static_cast(*__first_++)}; + } +# endif // _LIBCPP_STD_VER > 20 + private: const char* __first_; const char* __last_; }; -# ifndef TEST_HAS_NO_WIDE_CHARACTERS +# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS +_LIBCPP_HIDE_FROM_ABI constexpr bool __is_surrogate_pair_high(wchar_t __value) { + return __value >= 0xd800 && __value <= 0xdbff; +} + +_LIBCPP_HIDE_FROM_ABI constexpr bool __is_surrogate_pair_low(wchar_t __value) { + return __value >= 0xdc00 && __value <= 0xdfff; +} + /// This specialization depends on the size of wchar_t /// - 2 UTF-16 (for example Windows and AIX) /// - 4 UTF-32 (for example Linux) template <> class __code_point_view { public: + static_assert(sizeof(wchar_t) == 2 || sizeof(wchar_t) == 4, "sizeof(wchar_t) has a not implemented value"); + _LIBCPP_HIDE_FROM_ABI constexpr explicit __code_point_view(const wchar_t* __first, const wchar_t* __last) : __first_(__first), __last_(__last) {} @@ -166,17 +259,43 @@ public: return __replacement_character; return __result; } else { - // TODO FMT P2593R0 Use static_assert(false, "sizeof(wchar_t) has a not implemented value"); - _LIBCPP_ASSERT(sizeof(wchar_t) == 0, "sizeof(wchar_t) has a not implemented value"); __libcpp_unreachable(); } } +# if _LIBCPP_STD_VER > 20 + _LIBCPP_HIDE_FROM_ABI constexpr __consume_p2286_result __consume_p2286() noexcept { + _LIBCPP_ASSERT(__first_ != __last_, "can't move beyond the end of input"); + + char32_t __result = *__first_++; + if constexpr (sizeof(wchar_t) == 2) { + // https://en.wikipedia.org/wiki/UTF-16#U+D800_to_U+DFFF + if (__is_surrogate_pair_high(__result)) { + // Malformed Unicode. + if (__first_ == __last_ || !__is_surrogate_pair_low(*(__first_ + 1))) [[unlikely]] + return {1, __result}; + + __result -= 0xd800; + __result <<= 10; + __result += *__first_++ - 0xdc00; + __result += 0x10000; + } else if (__is_surrogate_pair_low(__result)) + // A code point shouldn't start with the low surrogate pair + return {1, __result}; + } else { + if (__result > 0x10FFFF) [[unlikely]] + return {1, __result}; + } + + return {0, __result}; + } +# endif // _LIBCPP_STD_VER > 20 + private: const wchar_t* __first_; const wchar_t* __last_; }; -# endif +# endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS _LIBCPP_HIDE_FROM_ABI constexpr bool __at_extended_grapheme_cluster_break( bool& __ri_break_allowed, @@ -251,10 +370,7 @@ _LIBCPP_HIDE_FROM_ABI constexpr bool __at_extended_grapheme_cluster_break( if (__prev == __property::__Regional_Indicator && __next == __property::__Regional_Indicator) { // GB12 + GB13 __ri_break_allowed = !__ri_break_allowed; - if (__ri_break_allowed) - return true; - - return false; + return __ri_break_allowed; } // *** Otherwise, break everywhere. *** @@ -328,10 +444,44 @@ private: } }; -} // namespace __unicode +template +__extended_grapheme_cluster_view(const _CharT*, const _CharT*) -> __extended_grapheme_cluster_view<_CharT>; + +# else // _LIBCPP_HAS_NO_UNICODE + +// For ASCII every character is a "code point". +// This makes it easier to write code agnostic of the _LIBCPP_HAS_NO_UNICODE define. +template +class __code_point_view { +public: + _LIBCPP_HIDE_FROM_ABI constexpr explicit __code_point_view(const _CharT* __first, const _CharT* __last) + : __first_(__first), __last_(__last) {} + + _LIBCPP_HIDE_FROM_ABI constexpr bool __at_end() const noexcept { return __first_ == __last_; } + _LIBCPP_HIDE_FROM_ABI constexpr const _CharT* __position() const noexcept { return __first_; } + + _LIBCPP_HIDE_FROM_ABI constexpr char32_t __consume() noexcept { + _LIBCPP_ASSERT(__first_ != __last_, "can't move beyond the end of input"); + return *__first_++; + } + +# if _LIBCPP_STD_VER > 20 + _LIBCPP_HIDE_FROM_ABI constexpr __consume_p2286_result __consume_p2286() noexcept { + _LIBCPP_ASSERT(__first_ != __last_, "can't move beyond the end of input"); + + return {0, std::make_unsigned_t<_CharT>(*__first_++)}; + } +# endif // _LIBCPP_STD_VER > 20 + +private: + const _CharT* __first_; + const _CharT* __last_; +}; # endif // _LIBCPP_HAS_NO_UNICODE +} // namespace __unicode + #endif //_LIBCPP_STD_VER > 17 _LIBCPP_END_NAMESPACE_STD diff --git a/lib/libcxx/include/__functional/binary_negate.h b/lib/libcxx/include/__functional/binary_negate.h index c4977f4ebe..73ecea9971 100644 --- a/lib/libcxx/include/__functional/binary_negate.h +++ b/lib/libcxx/include/__functional/binary_negate.h @@ -29,17 +29,17 @@ class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX17 binary_negate { _Predicate __pred_; public: - _LIBCPP_INLINE_VISIBILITY explicit _LIBCPP_CONSTEXPR_AFTER_CXX11 + _LIBCPP_INLINE_VISIBILITY explicit _LIBCPP_CONSTEXPR_SINCE_CXX14 binary_negate(const _Predicate& __pred) : __pred_(__pred) {} - _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY bool operator()(const typename _Predicate::first_argument_type& __x, const typename _Predicate::second_argument_type& __y) const {return !__pred_(__x, __y);} }; template -_LIBCPP_DEPRECATED_IN_CXX17 inline _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY +_LIBCPP_DEPRECATED_IN_CXX17 inline _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY binary_negate<_Predicate> not2(const _Predicate& __pred) {return binary_negate<_Predicate>(__pred);} diff --git a/lib/libcxx/include/__functional/bind.h b/lib/libcxx/include/__functional/bind.h index d1cbbb3d91..297e4e5103 100644 --- a/lib/libcxx/include/__functional/bind.h +++ b/lib/libcxx/include/__functional/bind.h @@ -25,9 +25,9 @@ _LIBCPP_BEGIN_NAMESPACE_STD template struct is_bind_expression : _If< - _IsSame<_Tp, __uncvref_t<_Tp> >::value, + _IsSame<_Tp, __remove_cvref_t<_Tp> >::value, false_type, - is_bind_expression<__uncvref_t<_Tp> > + is_bind_expression<__remove_cvref_t<_Tp> > > {}; #if _LIBCPP_STD_VER > 14 @@ -37,9 +37,9 @@ inline constexpr size_t is_bind_expression_v = is_bind_expression<_Tp>::value; template struct is_placeholder : _If< - _IsSame<_Tp, __uncvref_t<_Tp> >::value, + _IsSame<_Tp, __remove_cvref_t<_Tp> >::value, integral_constant, - is_placeholder<__uncvref_t<_Tp> > + is_placeholder<__remove_cvref_t<_Tp> > > {}; #if _LIBCPP_STD_VER > 14 @@ -279,16 +279,16 @@ public: class = typename enable_if < is_constructible<_Fd, _Gp>::value && - !is_same::type, + !is_same<__libcpp_remove_reference_t<_Gp>, __bind>::value >::type> - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit __bind(_Gp&& __f, _BA&& ...__bound_args) : __f_(_VSTD::forward<_Gp>(__f)), __bound_args_(_VSTD::forward<_BA>(__bound_args)...) {} template - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 typename __bind_return<_Fd, _Td, tuple<_Args&&...> >::type operator()(_Args&& ...__args) { @@ -297,7 +297,7 @@ public: } template - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 typename __bind_return >::type operator()(_Args&& ...__args) const { @@ -324,16 +324,16 @@ public: class = typename enable_if < is_constructible<_Fd, _Gp>::value && - !is_same::type, + !is_same<__libcpp_remove_reference_t<_Gp>, __bind_r>::value >::type> - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit __bind_r(_Gp&& __f, _BA&& ...__bound_args) : base(_VSTD::forward<_Gp>(__f), _VSTD::forward<_BA>(__bound_args)...) {} template - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 typename enable_if < is_convertible >::type, @@ -347,7 +347,7 @@ public: } template - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 typename enable_if < is_convertible >::type, @@ -365,7 +365,7 @@ template struct is_bind_expression<__bind_r<_Rp, _Fp, _BoundArgs...> > : public true_type {}; template -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 __bind<_Fp, _BoundArgs...> bind(_Fp&& __f, _BoundArgs&&... __bound_args) { @@ -374,7 +374,7 @@ bind(_Fp&& __f, _BoundArgs&&... __bound_args) } template -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 __bind_r<_Rp, _Fp, _BoundArgs...> bind(_Fp&& __f, _BoundArgs&&... __bound_args) { diff --git a/lib/libcxx/include/__functional/boyer_moore_searcher.h b/lib/libcxx/include/__functional/boyer_moore_searcher.h index 20e554408f..a6750893ee 100644 --- a/lib/libcxx/include/__functional/boyer_moore_searcher.h +++ b/lib/libcxx/include/__functional/boyer_moore_searcher.h @@ -223,6 +223,7 @@ private: } } }; +_LIBCPP_CTAD_SUPPORTED_FOR_TYPE(boyer_moore_searcher); template ::value_type>, @@ -303,6 +304,7 @@ private: return std::make_pair(__l, __l); } }; +_LIBCPP_CTAD_SUPPORTED_FOR_TYPE(boyer_moore_horspool_searcher); _LIBCPP_END_NAMESPACE_STD diff --git a/lib/libcxx/include/__functional/default_searcher.h b/lib/libcxx/include/__functional/default_searcher.h index 8e37082b6b..e4151e589f 100644 --- a/lib/libcxx/include/__functional/default_searcher.h +++ b/lib/libcxx/include/__functional/default_searcher.h @@ -29,13 +29,13 @@ _LIBCPP_BEGIN_NAMESPACE_STD template> class _LIBCPP_TEMPLATE_VIS default_searcher { public: - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 default_searcher(_ForwardIterator __f, _ForwardIterator __l, _BinaryPredicate __p = _BinaryPredicate()) : __first_(__f), __last_(__l), __pred_(__p) {} template - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_ForwardIterator2, _ForwardIterator2> operator () (_ForwardIterator2 __f, _ForwardIterator2 __l) const { @@ -48,6 +48,7 @@ private: _ForwardIterator __last_; _BinaryPredicate __pred_; }; +_LIBCPP_CTAD_SUPPORTED_FOR_TYPE(default_searcher); #endif // _LIBCPP_STD_VER > 14 diff --git a/lib/libcxx/include/__functional/function.h b/lib/libcxx/include/__functional/function.h index 55b607f3f8..ca79d334a0 100644 --- a/lib/libcxx/include/__functional/function.h +++ b/lib/libcxx/include/__functional/function.h @@ -17,20 +17,29 @@ #include <__functional/unary_function.h> #include <__iterator/iterator_traits.h> #include <__memory/addressof.h> +#include <__memory/allocator.h> +#include <__memory/allocator_destructor.h> #include <__memory/allocator_traits.h> +#include <__memory/builtin_new_allocator.h> #include <__memory/compressed_pair.h> -#include <__memory/shared_ptr.h> +#include <__memory/unique_ptr.h> +#include <__type_traits/strip_signature.h> #include <__utility/forward.h> #include <__utility/move.h> +#include <__utility/piecewise_construct.h> #include <__utility/swap.h> #include -#include // TODO: replace with <__memory/__builtin_new_allocator.h> +#include +#include #include +#include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header #endif +#ifndef _LIBCPP_CXX03_LANG + _LIBCPP_BEGIN_NAMESPACE_STD // bad_function_call @@ -45,13 +54,13 @@ public: // bad_function_call will end up containing a weak definition of the vtable and // typeinfo. #ifdef _LIBCPP_ABI_BAD_FUNCTION_CALL_KEY_FUNCTION - virtual ~bad_function_call() _NOEXCEPT; + ~bad_function_call() _NOEXCEPT override; #else - virtual ~bad_function_call() _NOEXCEPT {} + ~bad_function_call() _NOEXCEPT override {} #endif #ifdef _LIBCPP_ABI_BAD_FUNCTION_CALL_GOOD_WHAT_MESSAGE - virtual const char* what() const _NOEXCEPT; + const char* what() const _NOEXCEPT override; #endif }; _LIBCPP_DIAGNOSTIC_POP @@ -66,14 +75,7 @@ void __throw_bad_function_call() #endif } -#if defined(_LIBCPP_CXX03_LANG) && !defined(_LIBCPP_DISABLE_DEPRECATION_WARNINGS) && __has_attribute(deprecated) -# define _LIBCPP_DEPRECATED_CXX03_FUNCTION \ - __attribute__((deprecated("Using std::function in C++03 is not supported anymore. Please upgrade to C++11 or later, or use a different type"))) -#else -# define _LIBCPP_DEPRECATED_CXX03_FUNCTION /* nothing */ -#endif - -template class _LIBCPP_DEPRECATED_CXX03_FUNCTION _LIBCPP_TEMPLATE_VIS function; // undefined +template class _LIBCPP_TEMPLATE_VIS function; // undefined namespace __function { @@ -124,8 +126,6 @@ bool __not_null(_Rp (^__p)(_Args...)) { return __p; } } // namespace __function -#ifndef _LIBCPP_CXX03_LANG - namespace __function { // __alloc_func holds a functor and an allocator. @@ -190,9 +190,7 @@ class __alloc_func<_Fp, _Ap, _Rp(_ArgTypes...)> __alloc_func* __clone() const { typedef allocator_traits<_Alloc> __alloc_traits; - typedef - typename __rebind_alloc_helper<__alloc_traits, __alloc_func>::type - _AA; + typedef __rebind_alloc<__alloc_traits, __alloc_func> _AA; _AA __a(__f_.second()); typedef __allocator_destructor<_AA> _Dp; unique_ptr<__alloc_func, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); @@ -205,8 +203,7 @@ class __alloc_func<_Fp, _Ap, _Rp(_ArgTypes...)> static void __destroy_and_delete(__alloc_func* __f) { typedef allocator_traits<_Alloc> __alloc_traits; - typedef typename __rebind_alloc_helper<__alloc_traits, __alloc_func>::type - _FunAlloc; + typedef __rebind_alloc<__alloc_traits, __alloc_func> _FunAlloc; _FunAlloc __a(__f->__get_allocator()); __f->destroy(); __a.deallocate(__f, 1); @@ -265,7 +262,7 @@ class __base<_Rp(_ArgTypes...)> __base& operator=(const __base&); public: _LIBCPP_INLINE_VISIBILITY __base() {} - _LIBCPP_INLINE_VISIBILITY virtual ~__base() {} + _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual ~__base() {} virtual __base* __clone() const = 0; virtual void __clone(__base*) const = 0; virtual void destroy() _NOEXCEPT = 0; @@ -319,7 +316,7 @@ __base<_Rp(_ArgTypes...)>* __func<_Fp, _Alloc, _Rp(_ArgTypes...)>::__clone() const { typedef allocator_traits<_Alloc> __alloc_traits; - typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap; + typedef __rebind_alloc<__alloc_traits, __func> _Ap; _Ap __a(__f_.__get_allocator()); typedef __allocator_destructor<_Ap> _Dp; unique_ptr<__func, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); @@ -346,7 +343,7 @@ void __func<_Fp, _Alloc, _Rp(_ArgTypes...)>::destroy_deallocate() _NOEXCEPT { typedef allocator_traits<_Alloc> __alloc_traits; - typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap; + typedef __rebind_alloc<__alloc_traits, __func> _Ap; _Ap __a(__f_.__get_allocator()); __f_.destroy(); __a.deallocate(this, 1); @@ -385,7 +382,9 @@ template class __value_func; template class __value_func<_Rp(_ArgTypes...)> { + _LIBCPP_SUPPRESS_DEPRECATED_PUSH typename aligned_storage<3 * sizeof(void*)>::type __buf_; + _LIBCPP_SUPPRESS_DEPRECATED_POP typedef __base<_Rp(_ArgTypes...)> __func; __func* __f_; @@ -405,8 +404,7 @@ template class __value_func<_Rp(_ArgTypes...)> { typedef allocator_traits<_Alloc> __alloc_traits; typedef __function::__func<_Fp, _Alloc, _Rp(_ArgTypes...)> _Fun; - typedef typename __rebind_alloc_helper<__alloc_traits, _Fun>::type - _FunAlloc; + typedef __rebind_alloc<__alloc_traits, _Fun> _FunAlloc; if (__function::__not_null(__f)) { @@ -519,7 +517,9 @@ template class __value_func<_Rp(_ArgTypes...)> return; if ((void*)__f_ == &__buf_ && (void*)__f.__f_ == &__f.__buf_) { + _LIBCPP_SUPPRESS_DEPRECATED_PUSH typename aligned_storage::type __tempbuf; + _LIBCPP_SUPPRESS_DEPRECATED_POP __func* __t = __as_base(&__tempbuf); __f_->__clone(__t); __f_->destroy(); @@ -670,8 +670,7 @@ struct __policy // Used to choose between perfect forwarding or pass-by-value. Pass-by-value is // faster for types that can be passed in registers. template -using __fast_forward = - typename conditional::value, _Tp, _Tp&&>::type; +using __fast_forward = __conditional_t::value, _Tp, _Tp&&>; // __policy_invoker calls an instance of __alloc_func held in __policy_storage. @@ -747,8 +746,7 @@ template class __policy_func<_Rp(_ArgTypes...)> { typedef __alloc_func<_Fp, _Alloc, _Rp(_ArgTypes...)> _Fun; typedef allocator_traits<_Alloc> __alloc_traits; - typedef typename __rebind_alloc_helper<__alloc_traits, _Fun>::type - _FunAlloc; + typedef __rebind_alloc<__alloc_traits, _Fun> _FunAlloc; if (__function::__not_null(__f)) { @@ -978,7 +976,7 @@ class _LIBCPP_TEMPLATE_VIS function<_Rp(_ArgTypes...)> __func __f_; template , function>, + _IsNotSame<__remove_cvref_t<_Fp>, function>, __invokable<_Fp, _ArgTypes...> >::value> struct __callable; @@ -1070,45 +1068,6 @@ public: template function(_Rp(*)(_Ap...)) -> function<_Rp(_Ap...)>; -template -struct __strip_signature; - -template -struct __strip_signature<_Rp (_Gp::*) (_Ap...)> { using type = _Rp(_Ap...); }; -template -struct __strip_signature<_Rp (_Gp::*) (_Ap...) const> { using type = _Rp(_Ap...); }; -template -struct __strip_signature<_Rp (_Gp::*) (_Ap...) volatile> { using type = _Rp(_Ap...); }; -template -struct __strip_signature<_Rp (_Gp::*) (_Ap...) const volatile> { using type = _Rp(_Ap...); }; - -template -struct __strip_signature<_Rp (_Gp::*) (_Ap...) &> { using type = _Rp(_Ap...); }; -template -struct __strip_signature<_Rp (_Gp::*) (_Ap...) const &> { using type = _Rp(_Ap...); }; -template -struct __strip_signature<_Rp (_Gp::*) (_Ap...) volatile &> { using type = _Rp(_Ap...); }; -template -struct __strip_signature<_Rp (_Gp::*) (_Ap...) const volatile &> { using type = _Rp(_Ap...); }; - -template -struct __strip_signature<_Rp (_Gp::*) (_Ap...) noexcept> { using type = _Rp(_Ap...); }; -template -struct __strip_signature<_Rp (_Gp::*) (_Ap...) const noexcept> { using type = _Rp(_Ap...); }; -template -struct __strip_signature<_Rp (_Gp::*) (_Ap...) volatile noexcept> { using type = _Rp(_Ap...); }; -template -struct __strip_signature<_Rp (_Gp::*) (_Ap...) const volatile noexcept> { using type = _Rp(_Ap...); }; - -template -struct __strip_signature<_Rp (_Gp::*) (_Ap...) & noexcept> { using type = _Rp(_Ap...); }; -template -struct __strip_signature<_Rp (_Gp::*) (_Ap...) const & noexcept> { using type = _Rp(_Ap...); }; -template -struct __strip_signature<_Rp (_Gp::*) (_Ap...) volatile & noexcept> { using type = _Rp(_Ap...); }; -template -struct __strip_signature<_Rp (_Gp::*) (_Ap...) const volatile & noexcept> { using type = _Rp(_Ap...); }; - template::type> function(_Fp) -> function<_Stripped>; #endif // _LIBCPP_STD_VER >= 17 @@ -1250,1574 +1209,8 @@ void swap(function<_Rp(_ArgTypes...)>& __x, function<_Rp(_ArgTypes...)>& __y) _NOEXCEPT {return __x.swap(__y);} -#elif defined(_LIBCPP_ENABLE_CXX03_FUNCTION) - -namespace __function { - -template class __base; - -template -class __base<_Rp()> -{ - __base(const __base&); - __base& operator=(const __base&); -public: - __base() {} - virtual ~__base() {} - virtual __base* __clone() const = 0; - virtual void __clone(__base*) const = 0; - virtual void destroy() = 0; - virtual void destroy_deallocate() = 0; - virtual _Rp operator()() = 0; -#ifndef _LIBCPP_NO_RTTI - virtual const void* target(const type_info&) const = 0; - virtual const std::type_info& target_type() const = 0; -#endif // _LIBCPP_NO_RTTI -}; - -template -class __base<_Rp(_A0)> -{ - __base(const __base&); - __base& operator=(const __base&); -public: - __base() {} - virtual ~__base() {} - virtual __base* __clone() const = 0; - virtual void __clone(__base*) const = 0; - virtual void destroy() = 0; - virtual void destroy_deallocate() = 0; - virtual _Rp operator()(_A0) = 0; -#ifndef _LIBCPP_NO_RTTI - virtual const void* target(const type_info&) const = 0; - virtual const std::type_info& target_type() const = 0; -#endif // _LIBCPP_NO_RTTI -}; - -template -class __base<_Rp(_A0, _A1)> -{ - __base(const __base&); - __base& operator=(const __base&); -public: - __base() {} - virtual ~__base() {} - virtual __base* __clone() const = 0; - virtual void __clone(__base*) const = 0; - virtual void destroy() = 0; - virtual void destroy_deallocate() = 0; - virtual _Rp operator()(_A0, _A1) = 0; -#ifndef _LIBCPP_NO_RTTI - virtual const void* target(const type_info&) const = 0; - virtual const std::type_info& target_type() const = 0; -#endif // _LIBCPP_NO_RTTI -}; - -template -class __base<_Rp(_A0, _A1, _A2)> -{ - __base(const __base&); - __base& operator=(const __base&); -public: - __base() {} - virtual ~__base() {} - virtual __base* __clone() const = 0; - virtual void __clone(__base*) const = 0; - virtual void destroy() = 0; - virtual void destroy_deallocate() = 0; - virtual _Rp operator()(_A0, _A1, _A2) = 0; -#ifndef _LIBCPP_NO_RTTI - virtual const void* target(const type_info&) const = 0; - virtual const std::type_info& target_type() const = 0; -#endif // _LIBCPP_NO_RTTI -}; - -template class __func; - -template -class __func<_Fp, _Alloc, _Rp()> - : public __base<_Rp()> -{ - __compressed_pair<_Fp, _Alloc> __f_; -public: - explicit __func(_Fp __f) : __f_(_VSTD::move(__f), __default_init_tag()) {} - explicit __func(_Fp __f, _Alloc __a) : __f_(_VSTD::move(__f), _VSTD::move(__a)) {} - virtual __base<_Rp()>* __clone() const; - virtual void __clone(__base<_Rp()>*) const; - virtual void destroy(); - virtual void destroy_deallocate(); - virtual _Rp operator()(); -#ifndef _LIBCPP_NO_RTTI - virtual const void* target(const type_info&) const; - virtual const std::type_info& target_type() const; -#endif // _LIBCPP_NO_RTTI -}; - -template -__base<_Rp()>* -__func<_Fp, _Alloc, _Rp()>::__clone() const -{ - typedef allocator_traits<_Alloc> __alloc_traits; - typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap; - _Ap __a(__f_.second()); - typedef __allocator_destructor<_Ap> _Dp; - unique_ptr<__func, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); - ::new ((void*)__hold.get()) __func(__f_.first(), _Alloc(__a)); - return __hold.release(); -} - -template -void -__func<_Fp, _Alloc, _Rp()>::__clone(__base<_Rp()>* __p) const -{ - ::new ((void*)__p) __func(__f_.first(), __f_.second()); -} - -template -void -__func<_Fp, _Alloc, _Rp()>::destroy() -{ - __f_.~__compressed_pair<_Fp, _Alloc>(); -} - -template -void -__func<_Fp, _Alloc, _Rp()>::destroy_deallocate() -{ - typedef allocator_traits<_Alloc> __alloc_traits; - typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap; - _Ap __a(__f_.second()); - __f_.~__compressed_pair<_Fp, _Alloc>(); - __a.deallocate(this, 1); -} - -template -_Rp -__func<_Fp, _Alloc, _Rp()>::operator()() -{ - typedef __invoke_void_return_wrapper<_Rp> _Invoker; - return _Invoker::__call(__f_.first()); -} - -#ifndef _LIBCPP_NO_RTTI - -template -const void* -__func<_Fp, _Alloc, _Rp()>::target(const type_info& __ti) const -{ - if (__ti == typeid(_Fp)) - return _VSTD::addressof(__f_.first()); - return (const void*)0; -} - -template -const std::type_info& -__func<_Fp, _Alloc, _Rp()>::target_type() const -{ - return typeid(_Fp); -} - -#endif // _LIBCPP_NO_RTTI - -template -class __func<_Fp, _Alloc, _Rp(_A0)> - : public __base<_Rp(_A0)> -{ - __compressed_pair<_Fp, _Alloc> __f_; -public: - _LIBCPP_INLINE_VISIBILITY explicit __func(_Fp __f) : __f_(_VSTD::move(__f), __default_init_tag()) {} - _LIBCPP_INLINE_VISIBILITY explicit __func(_Fp __f, _Alloc __a) - : __f_(_VSTD::move(__f), _VSTD::move(__a)) {} - virtual __base<_Rp(_A0)>* __clone() const; - virtual void __clone(__base<_Rp(_A0)>*) const; - virtual void destroy(); - virtual void destroy_deallocate(); - virtual _Rp operator()(_A0); -#ifndef _LIBCPP_NO_RTTI - virtual const void* target(const type_info&) const; - virtual const std::type_info& target_type() const; -#endif // _LIBCPP_NO_RTTI -}; - -template -__base<_Rp(_A0)>* -__func<_Fp, _Alloc, _Rp(_A0)>::__clone() const -{ - typedef allocator_traits<_Alloc> __alloc_traits; - typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap; - _Ap __a(__f_.second()); - typedef __allocator_destructor<_Ap> _Dp; - unique_ptr<__func, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); - ::new ((void*)__hold.get()) __func(__f_.first(), _Alloc(__a)); - return __hold.release(); -} - -template -void -__func<_Fp, _Alloc, _Rp(_A0)>::__clone(__base<_Rp(_A0)>* __p) const -{ - ::new ((void*)__p) __func(__f_.first(), __f_.second()); -} - -template -void -__func<_Fp, _Alloc, _Rp(_A0)>::destroy() -{ - __f_.~__compressed_pair<_Fp, _Alloc>(); -} - -template -void -__func<_Fp, _Alloc, _Rp(_A0)>::destroy_deallocate() -{ - typedef allocator_traits<_Alloc> __alloc_traits; - typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap; - _Ap __a(__f_.second()); - __f_.~__compressed_pair<_Fp, _Alloc>(); - __a.deallocate(this, 1); -} - -template -_Rp -__func<_Fp, _Alloc, _Rp(_A0)>::operator()(_A0 __a0) -{ - typedef __invoke_void_return_wrapper<_Rp> _Invoker; - return _Invoker::__call(__f_.first(), __a0); -} - -#ifndef _LIBCPP_NO_RTTI - -template -const void* -__func<_Fp, _Alloc, _Rp(_A0)>::target(const type_info& __ti) const -{ - if (__ti == typeid(_Fp)) - return &__f_.first(); - return (const void*)0; -} - -template -const std::type_info& -__func<_Fp, _Alloc, _Rp(_A0)>::target_type() const -{ - return typeid(_Fp); -} - -#endif // _LIBCPP_NO_RTTI - -template -class __func<_Fp, _Alloc, _Rp(_A0, _A1)> - : public __base<_Rp(_A0, _A1)> -{ - __compressed_pair<_Fp, _Alloc> __f_; -public: - _LIBCPP_INLINE_VISIBILITY explicit __func(_Fp __f) : __f_(_VSTD::move(__f), __default_init_tag()) {} - _LIBCPP_INLINE_VISIBILITY explicit __func(_Fp __f, _Alloc __a) - : __f_(_VSTD::move(__f), _VSTD::move(__a)) {} - virtual __base<_Rp(_A0, _A1)>* __clone() const; - virtual void __clone(__base<_Rp(_A0, _A1)>*) const; - virtual void destroy(); - virtual void destroy_deallocate(); - virtual _Rp operator()(_A0, _A1); -#ifndef _LIBCPP_NO_RTTI - virtual const void* target(const type_info&) const; - virtual const std::type_info& target_type() const; -#endif // _LIBCPP_NO_RTTI -}; - -template -__base<_Rp(_A0, _A1)>* -__func<_Fp, _Alloc, _Rp(_A0, _A1)>::__clone() const -{ - typedef allocator_traits<_Alloc> __alloc_traits; - typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap; - _Ap __a(__f_.second()); - typedef __allocator_destructor<_Ap> _Dp; - unique_ptr<__func, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); - ::new ((void*)__hold.get()) __func(__f_.first(), _Alloc(__a)); - return __hold.release(); -} - -template -void -__func<_Fp, _Alloc, _Rp(_A0, _A1)>::__clone(__base<_Rp(_A0, _A1)>* __p) const -{ - ::new ((void*)__p) __func(__f_.first(), __f_.second()); -} - -template -void -__func<_Fp, _Alloc, _Rp(_A0, _A1)>::destroy() -{ - __f_.~__compressed_pair<_Fp, _Alloc>(); -} - -template -void -__func<_Fp, _Alloc, _Rp(_A0, _A1)>::destroy_deallocate() -{ - typedef allocator_traits<_Alloc> __alloc_traits; - typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap; - _Ap __a(__f_.second()); - __f_.~__compressed_pair<_Fp, _Alloc>(); - __a.deallocate(this, 1); -} - -template -_Rp -__func<_Fp, _Alloc, _Rp(_A0, _A1)>::operator()(_A0 __a0, _A1 __a1) -{ - typedef __invoke_void_return_wrapper<_Rp> _Invoker; - return _Invoker::__call(__f_.first(), __a0, __a1); -} - -#ifndef _LIBCPP_NO_RTTI - -template -const void* -__func<_Fp, _Alloc, _Rp(_A0, _A1)>::target(const type_info& __ti) const -{ - if (__ti == typeid(_Fp)) - return &__f_.first(); - return (const void*)0; -} - -template -const std::type_info& -__func<_Fp, _Alloc, _Rp(_A0, _A1)>::target_type() const -{ - return typeid(_Fp); -} - -#endif // _LIBCPP_NO_RTTI - -template -class __func<_Fp, _Alloc, _Rp(_A0, _A1, _A2)> - : public __base<_Rp(_A0, _A1, _A2)> -{ - __compressed_pair<_Fp, _Alloc> __f_; -public: - _LIBCPP_INLINE_VISIBILITY explicit __func(_Fp __f) : __f_(_VSTD::move(__f), __default_init_tag()) {} - _LIBCPP_INLINE_VISIBILITY explicit __func(_Fp __f, _Alloc __a) - : __f_(_VSTD::move(__f), _VSTD::move(__a)) {} - virtual __base<_Rp(_A0, _A1, _A2)>* __clone() const; - virtual void __clone(__base<_Rp(_A0, _A1, _A2)>*) const; - virtual void destroy(); - virtual void destroy_deallocate(); - virtual _Rp operator()(_A0, _A1, _A2); -#ifndef _LIBCPP_NO_RTTI - virtual const void* target(const type_info&) const; - virtual const std::type_info& target_type() const; -#endif // _LIBCPP_NO_RTTI -}; - -template -__base<_Rp(_A0, _A1, _A2)>* -__func<_Fp, _Alloc, _Rp(_A0, _A1, _A2)>::__clone() const -{ - typedef allocator_traits<_Alloc> __alloc_traits; - typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap; - _Ap __a(__f_.second()); - typedef __allocator_destructor<_Ap> _Dp; - unique_ptr<__func, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); - ::new ((void*)__hold.get()) __func(__f_.first(), _Alloc(__a)); - return __hold.release(); -} - -template -void -__func<_Fp, _Alloc, _Rp(_A0, _A1, _A2)>::__clone(__base<_Rp(_A0, _A1, _A2)>* __p) const -{ - ::new ((void*)__p) __func(__f_.first(), __f_.second()); -} - -template -void -__func<_Fp, _Alloc, _Rp(_A0, _A1, _A2)>::destroy() -{ - __f_.~__compressed_pair<_Fp, _Alloc>(); -} - -template -void -__func<_Fp, _Alloc, _Rp(_A0, _A1, _A2)>::destroy_deallocate() -{ - typedef allocator_traits<_Alloc> __alloc_traits; - typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap; - _Ap __a(__f_.second()); - __f_.~__compressed_pair<_Fp, _Alloc>(); - __a.deallocate(this, 1); -} - -template -_Rp -__func<_Fp, _Alloc, _Rp(_A0, _A1, _A2)>::operator()(_A0 __a0, _A1 __a1, _A2 __a2) -{ - typedef __invoke_void_return_wrapper<_Rp> _Invoker; - return _Invoker::__call(__f_.first(), __a0, __a1, __a2); -} - -#ifndef _LIBCPP_NO_RTTI - -template -const void* -__func<_Fp, _Alloc, _Rp(_A0, _A1, _A2)>::target(const type_info& __ti) const -{ - if (__ti == typeid(_Fp)) - return &__f_.first(); - return (const void*)0; -} - -template -const std::type_info& -__func<_Fp, _Alloc, _Rp(_A0, _A1, _A2)>::target_type() const -{ - return typeid(_Fp); -} - -#endif // _LIBCPP_NO_RTTI - -} // namespace __function - -template -class _LIBCPP_TEMPLATE_VIS function<_Rp()> -{ - typedef __function::__base<_Rp()> __base; - aligned_storage<3*sizeof(void*)>::type __buf_; - __base* __f_; - -public: - typedef _Rp result_type; - - // 20.7.16.2.1, construct/copy/destroy: - _LIBCPP_INLINE_VISIBILITY explicit function() : __f_(0) {} - _LIBCPP_INLINE_VISIBILITY function(nullptr_t) : __f_(0) {} - function(const function&); - template - function(_Fp, - typename enable_if::value>::type* = 0); - - template - _LIBCPP_INLINE_VISIBILITY - function(allocator_arg_t, const _Alloc&) : __f_(0) {} - template - _LIBCPP_INLINE_VISIBILITY - function(allocator_arg_t, const _Alloc&, nullptr_t) : __f_(0) {} - template - function(allocator_arg_t, const _Alloc&, const function&); - template - function(allocator_arg_t, const _Alloc& __a, _Fp __f, - typename enable_if::value>::type* = 0); - - function& operator=(const function&); - function& operator=(nullptr_t); - template - typename enable_if - < - !is_integral<_Fp>::value, - function& - >::type - operator=(_Fp); - - ~function(); - - // 20.7.16.2.2, function modifiers: - void swap(function&); - template - _LIBCPP_INLINE_VISIBILITY - void assign(_Fp __f, const _Alloc& __a) - {function(allocator_arg, __a, __f).swap(*this);} - - // 20.7.16.2.3, function capacity: - _LIBCPP_INLINE_VISIBILITY explicit operator bool() const {return __f_;} - - template - bool operator==(const function<_R2()>&) const = delete; - template - bool operator!=(const function<_R2()>&) const = delete; - - // 20.7.16.2.4, function invocation: - _Rp operator()() const; - -#ifndef _LIBCPP_NO_RTTI - // 20.7.16.2.5, function target access: - const std::type_info& target_type() const; - template _Tp* target(); - template const _Tp* target() const; -#endif // _LIBCPP_NO_RTTI -}; - -template -function<_Rp()>::function(const function& __f) -{ - if (__f.__f_ == 0) - __f_ = 0; - else if (__f.__f_ == (const __base*)&__f.__buf_) - { - __f_ = (__base*)&__buf_; - __f.__f_->__clone(__f_); - } - else - __f_ = __f.__f_->__clone(); -} - -template -template -function<_Rp()>::function(allocator_arg_t, const _Alloc&, const function& __f) -{ - if (__f.__f_ == 0) - __f_ = 0; - else if (__f.__f_ == (const __base*)&__f.__buf_) - { - __f_ = (__base*)&__buf_; - __f.__f_->__clone(__f_); - } - else - __f_ = __f.__f_->__clone(); -} - -template -template -function<_Rp()>::function(_Fp __f, - typename enable_if::value>::type*) - : __f_(0) -{ - if (__function::__not_null(__f)) - { - typedef __function::__func<_Fp, allocator<_Fp>, _Rp()> _FF; - if (sizeof(_FF) <= sizeof(__buf_)) - { - __f_ = (__base*)&__buf_; - ::new ((void*)__f_) _FF(__f); - } - else - { - typedef allocator<_FF> _Ap; - _Ap __a; - typedef __allocator_destructor<_Ap> _Dp; - unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); - ::new ((void*)__hold.get()) _FF(__f, allocator<_Fp>(__a)); - __f_ = __hold.release(); - } - } -} - -template -template -function<_Rp()>::function(allocator_arg_t, const _Alloc& __a0, _Fp __f, - typename enable_if::value>::type*) - : __f_(0) -{ - typedef allocator_traits<_Alloc> __alloc_traits; - if (__function::__not_null(__f)) - { - typedef __function::__func<_Fp, _Alloc, _Rp()> _FF; - if (sizeof(_FF) <= sizeof(__buf_)) - { - __f_ = (__base*)&__buf_; - ::new ((void*)__f_) _FF(__f, __a0); - } - else - { - typedef typename __rebind_alloc_helper<__alloc_traits, _FF>::type _Ap; - _Ap __a(__a0); - typedef __allocator_destructor<_Ap> _Dp; - unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); - ::new ((void*)__hold.get()) _FF(__f, _Alloc(__a)); - __f_ = __hold.release(); - } - } -} - -template -function<_Rp()>& -function<_Rp()>::operator=(const function& __f) -{ - if (__f) - function(__f).swap(*this); - else - *this = nullptr; - return *this; -} - -template -function<_Rp()>& -function<_Rp()>::operator=(nullptr_t) -{ - __base* __t = __f_; - __f_ = 0; - if (__t == (__base*)&__buf_) - __t->destroy(); - else if (__t) - __t->destroy_deallocate(); - return *this; -} - -template -template -typename enable_if -< - !is_integral<_Fp>::value, - function<_Rp()>& ->::type -function<_Rp()>::operator=(_Fp __f) -{ - function(_VSTD::move(__f)).swap(*this); - return *this; -} - -template -function<_Rp()>::~function() -{ - if (__f_ == (__base*)&__buf_) - __f_->destroy(); - else if (__f_) - __f_->destroy_deallocate(); -} - -template -void -function<_Rp()>::swap(function& __f) -{ - if (_VSTD::addressof(__f) == this) - return; - if (__f_ == (__base*)&__buf_ && __f.__f_ == (__base*)&__f.__buf_) - { - typename aligned_storage::type __tempbuf; - __base* __t = (__base*)&__tempbuf; - __f_->__clone(__t); - __f_->destroy(); - __f_ = 0; - __f.__f_->__clone((__base*)&__buf_); - __f.__f_->destroy(); - __f.__f_ = 0; - __f_ = (__base*)&__buf_; - __t->__clone((__base*)&__f.__buf_); - __t->destroy(); - __f.__f_ = (__base*)&__f.__buf_; - } - else if (__f_ == (__base*)&__buf_) - { - __f_->__clone((__base*)&__f.__buf_); - __f_->destroy(); - __f_ = __f.__f_; - __f.__f_ = (__base*)&__f.__buf_; - } - else if (__f.__f_ == (__base*)&__f.__buf_) - { - __f.__f_->__clone((__base*)&__buf_); - __f.__f_->destroy(); - __f.__f_ = __f_; - __f_ = (__base*)&__buf_; - } - else - _VSTD::swap(__f_, __f.__f_); -} - -template -_Rp -function<_Rp()>::operator()() const -{ - if (__f_ == 0) - __throw_bad_function_call(); - return (*__f_)(); -} - -#ifndef _LIBCPP_NO_RTTI - -template -const std::type_info& -function<_Rp()>::target_type() const -{ - if (__f_ == 0) - return typeid(void); - return __f_->target_type(); -} - -template -template -_Tp* -function<_Rp()>::target() -{ - if (__f_ == 0) - return (_Tp*)0; - return (_Tp*) const_cast(__f_->target(typeid(_Tp))); -} - -template -template -const _Tp* -function<_Rp()>::target() const -{ - if (__f_ == 0) - return (const _Tp*)0; - return (const _Tp*)__f_->target(typeid(_Tp)); -} - -#endif // _LIBCPP_NO_RTTI - -template -class _LIBCPP_TEMPLATE_VIS function<_Rp(_A0)> - : public unary_function<_A0, _Rp> -{ - typedef __function::__base<_Rp(_A0)> __base; - aligned_storage<3*sizeof(void*)>::type __buf_; - __base* __f_; - -public: - typedef _Rp result_type; - - // 20.7.16.2.1, construct/copy/destroy: - _LIBCPP_INLINE_VISIBILITY explicit function() : __f_(0) {} - _LIBCPP_INLINE_VISIBILITY function(nullptr_t) : __f_(0) {} - function(const function&); - template - function(_Fp, - typename enable_if::value>::type* = 0); - - template - _LIBCPP_INLINE_VISIBILITY - function(allocator_arg_t, const _Alloc&) : __f_(0) {} - template - _LIBCPP_INLINE_VISIBILITY - function(allocator_arg_t, const _Alloc&, nullptr_t) : __f_(0) {} - template - function(allocator_arg_t, const _Alloc&, const function&); - template - function(allocator_arg_t, const _Alloc& __a, _Fp __f, - typename enable_if::value>::type* = 0); - - function& operator=(const function&); - function& operator=(nullptr_t); - template - typename enable_if - < - !is_integral<_Fp>::value, - function& - >::type - operator=(_Fp); - - ~function(); - - // 20.7.16.2.2, function modifiers: - void swap(function&); - template - _LIBCPP_INLINE_VISIBILITY - void assign(_Fp __f, const _Alloc& __a) - {function(allocator_arg, __a, __f).swap(*this);} - - // 20.7.16.2.3, function capacity: - _LIBCPP_INLINE_VISIBILITY explicit operator bool() const {return __f_;} - - template - bool operator==(const function<_R2(_B0)>&) const = delete; - template - bool operator!=(const function<_R2(_B0)>&) const = delete; - - // 20.7.16.2.4, function invocation: - _Rp operator()(_A0) const; - -#ifndef _LIBCPP_NO_RTTI - // 20.7.16.2.5, function target access: - const std::type_info& target_type() const; - template _Tp* target(); - template const _Tp* target() const; -#endif // _LIBCPP_NO_RTTI -}; - -template -function<_Rp(_A0)>::function(const function& __f) -{ - if (__f.__f_ == 0) - __f_ = 0; - else if (__f.__f_ == (const __base*)&__f.__buf_) - { - __f_ = (__base*)&__buf_; - __f.__f_->__clone(__f_); - } - else - __f_ = __f.__f_->__clone(); -} - -template -template -function<_Rp(_A0)>::function(allocator_arg_t, const _Alloc&, const function& __f) -{ - if (__f.__f_ == 0) - __f_ = 0; - else if (__f.__f_ == (const __base*)&__f.__buf_) - { - __f_ = (__base*)&__buf_; - __f.__f_->__clone(__f_); - } - else - __f_ = __f.__f_->__clone(); -} - -template -template -function<_Rp(_A0)>::function(_Fp __f, - typename enable_if::value>::type*) - : __f_(0) -{ - if (__function::__not_null(__f)) - { - typedef __function::__func<_Fp, allocator<_Fp>, _Rp(_A0)> _FF; - if (sizeof(_FF) <= sizeof(__buf_)) - { - __f_ = (__base*)&__buf_; - ::new ((void*)__f_) _FF(__f); - } - else - { - typedef allocator<_FF> _Ap; - _Ap __a; - typedef __allocator_destructor<_Ap> _Dp; - unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); - ::new ((void*)__hold.get()) _FF(__f, allocator<_Fp>(__a)); - __f_ = __hold.release(); - } - } -} - -template -template -function<_Rp(_A0)>::function(allocator_arg_t, const _Alloc& __a0, _Fp __f, - typename enable_if::value>::type*) - : __f_(0) -{ - typedef allocator_traits<_Alloc> __alloc_traits; - if (__function::__not_null(__f)) - { - typedef __function::__func<_Fp, _Alloc, _Rp(_A0)> _FF; - if (sizeof(_FF) <= sizeof(__buf_)) - { - __f_ = (__base*)&__buf_; - ::new ((void*)__f_) _FF(__f, __a0); - } - else - { - typedef typename __rebind_alloc_helper<__alloc_traits, _FF>::type _Ap; - _Ap __a(__a0); - typedef __allocator_destructor<_Ap> _Dp; - unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); - ::new ((void*)__hold.get()) _FF(__f, _Alloc(__a)); - __f_ = __hold.release(); - } - } -} - -template -function<_Rp(_A0)>& -function<_Rp(_A0)>::operator=(const function& __f) -{ - if (__f) - function(__f).swap(*this); - else - *this = nullptr; - return *this; -} - -template -function<_Rp(_A0)>& -function<_Rp(_A0)>::operator=(nullptr_t) -{ - __base* __t = __f_; - __f_ = 0; - if (__t == (__base*)&__buf_) - __t->destroy(); - else if (__t) - __t->destroy_deallocate(); - return *this; -} - -template -template -typename enable_if -< - !is_integral<_Fp>::value, - function<_Rp(_A0)>& ->::type -function<_Rp(_A0)>::operator=(_Fp __f) -{ - function(_VSTD::move(__f)).swap(*this); - return *this; -} - -template -function<_Rp(_A0)>::~function() -{ - if (__f_ == (__base*)&__buf_) - __f_->destroy(); - else if (__f_) - __f_->destroy_deallocate(); -} - -template -void -function<_Rp(_A0)>::swap(function& __f) -{ - if (_VSTD::addressof(__f) == this) - return; - if (__f_ == (__base*)&__buf_ && __f.__f_ == (__base*)&__f.__buf_) - { - typename aligned_storage::type __tempbuf; - __base* __t = (__base*)&__tempbuf; - __f_->__clone(__t); - __f_->destroy(); - __f_ = 0; - __f.__f_->__clone((__base*)&__buf_); - __f.__f_->destroy(); - __f.__f_ = 0; - __f_ = (__base*)&__buf_; - __t->__clone((__base*)&__f.__buf_); - __t->destroy(); - __f.__f_ = (__base*)&__f.__buf_; - } - else if (__f_ == (__base*)&__buf_) - { - __f_->__clone((__base*)&__f.__buf_); - __f_->destroy(); - __f_ = __f.__f_; - __f.__f_ = (__base*)&__f.__buf_; - } - else if (__f.__f_ == (__base*)&__f.__buf_) - { - __f.__f_->__clone((__base*)&__buf_); - __f.__f_->destroy(); - __f.__f_ = __f_; - __f_ = (__base*)&__buf_; - } - else - _VSTD::swap(__f_, __f.__f_); -} - -template -_Rp -function<_Rp(_A0)>::operator()(_A0 __a0) const -{ - if (__f_ == 0) - __throw_bad_function_call(); - return (*__f_)(__a0); -} - -#ifndef _LIBCPP_NO_RTTI - -template -const std::type_info& -function<_Rp(_A0)>::target_type() const -{ - if (__f_ == 0) - return typeid(void); - return __f_->target_type(); -} - -template -template -_Tp* -function<_Rp(_A0)>::target() -{ - if (__f_ == 0) - return (_Tp*)0; - return (_Tp*) const_cast(__f_->target(typeid(_Tp))); -} - -template -template -const _Tp* -function<_Rp(_A0)>::target() const -{ - if (__f_ == 0) - return (const _Tp*)0; - return (const _Tp*)__f_->target(typeid(_Tp)); -} - -#endif // _LIBCPP_NO_RTTI - -template -class _LIBCPP_TEMPLATE_VIS function<_Rp(_A0, _A1)> - : public binary_function<_A0, _A1, _Rp> -{ - typedef __function::__base<_Rp(_A0, _A1)> __base; - aligned_storage<3*sizeof(void*)>::type __buf_; - __base* __f_; - -public: - typedef _Rp result_type; - - // 20.7.16.2.1, construct/copy/destroy: - _LIBCPP_INLINE_VISIBILITY explicit function() : __f_(0) {} - _LIBCPP_INLINE_VISIBILITY function(nullptr_t) : __f_(0) {} - function(const function&); - template - function(_Fp, - typename enable_if::value>::type* = 0); - - template - _LIBCPP_INLINE_VISIBILITY - function(allocator_arg_t, const _Alloc&) : __f_(0) {} - template - _LIBCPP_INLINE_VISIBILITY - function(allocator_arg_t, const _Alloc&, nullptr_t) : __f_(0) {} - template - function(allocator_arg_t, const _Alloc&, const function&); - template - function(allocator_arg_t, const _Alloc& __a, _Fp __f, - typename enable_if::value>::type* = 0); - - function& operator=(const function&); - function& operator=(nullptr_t); - template - typename enable_if - < - !is_integral<_Fp>::value, - function& - >::type - operator=(_Fp); - - ~function(); - - // 20.7.16.2.2, function modifiers: - void swap(function&); - template - _LIBCPP_INLINE_VISIBILITY - void assign(_Fp __f, const _Alloc& __a) - {function(allocator_arg, __a, __f).swap(*this);} - - // 20.7.16.2.3, function capacity: - _LIBCPP_INLINE_VISIBILITY explicit operator bool() const {return __f_;} - - template - bool operator==(const function<_R2(_B0, _B1)>&) const = delete; - template - bool operator!=(const function<_R2(_B0, _B1)>&) const = delete; - - // 20.7.16.2.4, function invocation: - _Rp operator()(_A0, _A1) const; - -#ifndef _LIBCPP_NO_RTTI - // 20.7.16.2.5, function target access: - const std::type_info& target_type() const; - template _Tp* target(); - template const _Tp* target() const; -#endif // _LIBCPP_NO_RTTI -}; - -template -function<_Rp(_A0, _A1)>::function(const function& __f) -{ - if (__f.__f_ == 0) - __f_ = 0; - else if (__f.__f_ == (const __base*)&__f.__buf_) - { - __f_ = (__base*)&__buf_; - __f.__f_->__clone(__f_); - } - else - __f_ = __f.__f_->__clone(); -} - -template -template -function<_Rp(_A0, _A1)>::function(allocator_arg_t, const _Alloc&, const function& __f) -{ - if (__f.__f_ == 0) - __f_ = 0; - else if (__f.__f_ == (const __base*)&__f.__buf_) - { - __f_ = (__base*)&__buf_; - __f.__f_->__clone(__f_); - } - else - __f_ = __f.__f_->__clone(); -} - -template -template -function<_Rp(_A0, _A1)>::function(_Fp __f, - typename enable_if::value>::type*) - : __f_(0) -{ - if (__function::__not_null(__f)) - { - typedef __function::__func<_Fp, allocator<_Fp>, _Rp(_A0, _A1)> _FF; - if (sizeof(_FF) <= sizeof(__buf_)) - { - __f_ = (__base*)&__buf_; - ::new ((void*)__f_) _FF(__f); - } - else - { - typedef allocator<_FF> _Ap; - _Ap __a; - typedef __allocator_destructor<_Ap> _Dp; - unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); - ::new ((void*)__hold.get()) _FF(__f, allocator<_Fp>(__a)); - __f_ = __hold.release(); - } - } -} - -template -template -function<_Rp(_A0, _A1)>::function(allocator_arg_t, const _Alloc& __a0, _Fp __f, - typename enable_if::value>::type*) - : __f_(0) -{ - typedef allocator_traits<_Alloc> __alloc_traits; - if (__function::__not_null(__f)) - { - typedef __function::__func<_Fp, _Alloc, _Rp(_A0, _A1)> _FF; - if (sizeof(_FF) <= sizeof(__buf_)) - { - __f_ = (__base*)&__buf_; - ::new ((void*)__f_) _FF(__f, __a0); - } - else - { - typedef typename __rebind_alloc_helper<__alloc_traits, _FF>::type _Ap; - _Ap __a(__a0); - typedef __allocator_destructor<_Ap> _Dp; - unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); - ::new ((void*)__hold.get()) _FF(__f, _Alloc(__a)); - __f_ = __hold.release(); - } - } -} - -template -function<_Rp(_A0, _A1)>& -function<_Rp(_A0, _A1)>::operator=(const function& __f) -{ - if (__f) - function(__f).swap(*this); - else - *this = nullptr; - return *this; -} - -template -function<_Rp(_A0, _A1)>& -function<_Rp(_A0, _A1)>::operator=(nullptr_t) -{ - __base* __t = __f_; - __f_ = 0; - if (__t == (__base*)&__buf_) - __t->destroy(); - else if (__t) - __t->destroy_deallocate(); - return *this; -} - -template -template -typename enable_if -< - !is_integral<_Fp>::value, - function<_Rp(_A0, _A1)>& ->::type -function<_Rp(_A0, _A1)>::operator=(_Fp __f) -{ - function(_VSTD::move(__f)).swap(*this); - return *this; -} - -template -function<_Rp(_A0, _A1)>::~function() -{ - if (__f_ == (__base*)&__buf_) - __f_->destroy(); - else if (__f_) - __f_->destroy_deallocate(); -} - -template -void -function<_Rp(_A0, _A1)>::swap(function& __f) -{ - if (_VSTD::addressof(__f) == this) - return; - if (__f_ == (__base*)&__buf_ && __f.__f_ == (__base*)&__f.__buf_) - { - typename aligned_storage::type __tempbuf; - __base* __t = (__base*)&__tempbuf; - __f_->__clone(__t); - __f_->destroy(); - __f_ = 0; - __f.__f_->__clone((__base*)&__buf_); - __f.__f_->destroy(); - __f.__f_ = 0; - __f_ = (__base*)&__buf_; - __t->__clone((__base*)&__f.__buf_); - __t->destroy(); - __f.__f_ = (__base*)&__f.__buf_; - } - else if (__f_ == (__base*)&__buf_) - { - __f_->__clone((__base*)&__f.__buf_); - __f_->destroy(); - __f_ = __f.__f_; - __f.__f_ = (__base*)&__f.__buf_; - } - else if (__f.__f_ == (__base*)&__f.__buf_) - { - __f.__f_->__clone((__base*)&__buf_); - __f.__f_->destroy(); - __f.__f_ = __f_; - __f_ = (__base*)&__buf_; - } - else - _VSTD::swap(__f_, __f.__f_); -} - -template -_Rp -function<_Rp(_A0, _A1)>::operator()(_A0 __a0, _A1 __a1) const -{ - if (__f_ == 0) - __throw_bad_function_call(); - return (*__f_)(__a0, __a1); -} - -#ifndef _LIBCPP_NO_RTTI - -template -const std::type_info& -function<_Rp(_A0, _A1)>::target_type() const -{ - if (__f_ == 0) - return typeid(void); - return __f_->target_type(); -} - -template -template -_Tp* -function<_Rp(_A0, _A1)>::target() -{ - if (__f_ == 0) - return (_Tp*)0; - return (_Tp*) const_cast(__f_->target(typeid(_Tp))); -} - -template -template -const _Tp* -function<_Rp(_A0, _A1)>::target() const -{ - if (__f_ == 0) - return (const _Tp*)0; - return (const _Tp*)__f_->target(typeid(_Tp)); -} - -#endif // _LIBCPP_NO_RTTI - -template -class _LIBCPP_TEMPLATE_VIS function<_Rp(_A0, _A1, _A2)> -{ - typedef __function::__base<_Rp(_A0, _A1, _A2)> __base; - aligned_storage<3*sizeof(void*)>::type __buf_; - __base* __f_; - -public: - typedef _Rp result_type; - - // 20.7.16.2.1, construct/copy/destroy: - _LIBCPP_INLINE_VISIBILITY explicit function() : __f_(0) {} - _LIBCPP_INLINE_VISIBILITY function(nullptr_t) : __f_(0) {} - function(const function&); - template - function(_Fp, - typename enable_if::value>::type* = 0); - - template - _LIBCPP_INLINE_VISIBILITY - function(allocator_arg_t, const _Alloc&) : __f_(0) {} - template - _LIBCPP_INLINE_VISIBILITY - function(allocator_arg_t, const _Alloc&, nullptr_t) : __f_(0) {} - template - function(allocator_arg_t, const _Alloc&, const function&); - template - function(allocator_arg_t, const _Alloc& __a, _Fp __f, - typename enable_if::value>::type* = 0); - - function& operator=(const function&); - function& operator=(nullptr_t); - template - typename enable_if - < - !is_integral<_Fp>::value, - function& - >::type - operator=(_Fp); - - ~function(); - - // 20.7.16.2.2, function modifiers: - void swap(function&); - template - _LIBCPP_INLINE_VISIBILITY - void assign(_Fp __f, const _Alloc& __a) - {function(allocator_arg, __a, __f).swap(*this);} - - // 20.7.16.2.3, function capacity: - _LIBCPP_INLINE_VISIBILITY explicit operator bool() const {return __f_;} - - template - bool operator==(const function<_R2(_B0, _B1, _B2)>&) const = delete; - template - bool operator!=(const function<_R2(_B0, _B1, _B2)>&) const = delete; - - // 20.7.16.2.4, function invocation: - _Rp operator()(_A0, _A1, _A2) const; - -#ifndef _LIBCPP_NO_RTTI - // 20.7.16.2.5, function target access: - const std::type_info& target_type() const; - template _Tp* target(); - template const _Tp* target() const; -#endif // _LIBCPP_NO_RTTI -}; - -template -function<_Rp(_A0, _A1, _A2)>::function(const function& __f) -{ - if (__f.__f_ == 0) - __f_ = 0; - else if (__f.__f_ == (const __base*)&__f.__buf_) - { - __f_ = (__base*)&__buf_; - __f.__f_->__clone(__f_); - } - else - __f_ = __f.__f_->__clone(); -} - -template -template -function<_Rp(_A0, _A1, _A2)>::function(allocator_arg_t, const _Alloc&, - const function& __f) -{ - if (__f.__f_ == 0) - __f_ = 0; - else if (__f.__f_ == (const __base*)&__f.__buf_) - { - __f_ = (__base*)&__buf_; - __f.__f_->__clone(__f_); - } - else - __f_ = __f.__f_->__clone(); -} - -template -template -function<_Rp(_A0, _A1, _A2)>::function(_Fp __f, - typename enable_if::value>::type*) - : __f_(0) -{ - if (__function::__not_null(__f)) - { - typedef __function::__func<_Fp, allocator<_Fp>, _Rp(_A0, _A1, _A2)> _FF; - if (sizeof(_FF) <= sizeof(__buf_)) - { - __f_ = (__base*)&__buf_; - ::new ((void*)__f_) _FF(__f); - } - else - { - typedef allocator<_FF> _Ap; - _Ap __a; - typedef __allocator_destructor<_Ap> _Dp; - unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); - ::new ((void*)__hold.get()) _FF(__f, allocator<_Fp>(__a)); - __f_ = __hold.release(); - } - } -} - -template -template -function<_Rp(_A0, _A1, _A2)>::function(allocator_arg_t, const _Alloc& __a0, _Fp __f, - typename enable_if::value>::type*) - : __f_(0) -{ - typedef allocator_traits<_Alloc> __alloc_traits; - if (__function::__not_null(__f)) - { - typedef __function::__func<_Fp, _Alloc, _Rp(_A0, _A1, _A2)> _FF; - if (sizeof(_FF) <= sizeof(__buf_)) - { - __f_ = (__base*)&__buf_; - ::new ((void*)__f_) _FF(__f, __a0); - } - else - { - typedef typename __rebind_alloc_helper<__alloc_traits, _FF>::type _Ap; - _Ap __a(__a0); - typedef __allocator_destructor<_Ap> _Dp; - unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); - ::new ((void*)__hold.get()) _FF(__f, _Alloc(__a)); - __f_ = __hold.release(); - } - } -} - -template -function<_Rp(_A0, _A1, _A2)>& -function<_Rp(_A0, _A1, _A2)>::operator=(const function& __f) -{ - if (__f) - function(__f).swap(*this); - else - *this = nullptr; - return *this; -} - -template -function<_Rp(_A0, _A1, _A2)>& -function<_Rp(_A0, _A1, _A2)>::operator=(nullptr_t) -{ - __base* __t = __f_; - __f_ = 0; - if (__t == (__base*)&__buf_) - __t->destroy(); - else if (__t) - __t->destroy_deallocate(); - return *this; -} - -template -template -typename enable_if -< - !is_integral<_Fp>::value, - function<_Rp(_A0, _A1, _A2)>& ->::type -function<_Rp(_A0, _A1, _A2)>::operator=(_Fp __f) -{ - function(_VSTD::move(__f)).swap(*this); - return *this; -} - -template -function<_Rp(_A0, _A1, _A2)>::~function() -{ - if (__f_ == (__base*)&__buf_) - __f_->destroy(); - else if (__f_) - __f_->destroy_deallocate(); -} - -template -void -function<_Rp(_A0, _A1, _A2)>::swap(function& __f) -{ - if (_VSTD::addressof(__f) == this) - return; - if (__f_ == (__base*)&__buf_ && __f.__f_ == (__base*)&__f.__buf_) - { - typename aligned_storage::type __tempbuf; - __base* __t = (__base*)&__tempbuf; - __f_->__clone(__t); - __f_->destroy(); - __f_ = 0; - __f.__f_->__clone((__base*)&__buf_); - __f.__f_->destroy(); - __f.__f_ = 0; - __f_ = (__base*)&__buf_; - __t->__clone((__base*)&__f.__buf_); - __t->destroy(); - __f.__f_ = (__base*)&__f.__buf_; - } - else if (__f_ == (__base*)&__buf_) - { - __f_->__clone((__base*)&__f.__buf_); - __f_->destroy(); - __f_ = __f.__f_; - __f.__f_ = (__base*)&__f.__buf_; - } - else if (__f.__f_ == (__base*)&__f.__buf_) - { - __f.__f_->__clone((__base*)&__buf_); - __f.__f_->destroy(); - __f.__f_ = __f_; - __f_ = (__base*)&__buf_; - } - else - _VSTD::swap(__f_, __f.__f_); -} - -template -_Rp -function<_Rp(_A0, _A1, _A2)>::operator()(_A0 __a0, _A1 __a1, _A2 __a2) const -{ - if (__f_ == 0) - __throw_bad_function_call(); - return (*__f_)(__a0, __a1, __a2); -} - -#ifndef _LIBCPP_NO_RTTI - -template -const std::type_info& -function<_Rp(_A0, _A1, _A2)>::target_type() const -{ - if (__f_ == 0) - return typeid(void); - return __f_->target_type(); -} - -template -template -_Tp* -function<_Rp(_A0, _A1, _A2)>::target() -{ - if (__f_ == 0) - return (_Tp*)0; - return (_Tp*) const_cast(__f_->target(typeid(_Tp))); -} - -template -template -const _Tp* -function<_Rp(_A0, _A1, _A2)>::target() const -{ - if (__f_ == 0) - return (const _Tp*)0; - return (const _Tp*)__f_->target(typeid(_Tp)); -} - -#endif // _LIBCPP_NO_RTTI - -template -inline _LIBCPP_INLINE_VISIBILITY -bool -operator==(const function<_Fp>& __f, nullptr_t) {return !__f;} - -template -inline _LIBCPP_INLINE_VISIBILITY -bool -operator==(nullptr_t, const function<_Fp>& __f) {return !__f;} - -template -inline _LIBCPP_INLINE_VISIBILITY -bool -operator!=(const function<_Fp>& __f, nullptr_t) {return (bool)__f;} - -template -inline _LIBCPP_INLINE_VISIBILITY -bool -operator!=(nullptr_t, const function<_Fp>& __f) {return (bool)__f;} - -template -inline _LIBCPP_INLINE_VISIBILITY -void -swap(function<_Fp>& __x, function<_Fp>& __y) -{return __x.swap(__y);} +_LIBCPP_END_NAMESPACE_STD #endif // _LIBCPP_CXX03_LANG -_LIBCPP_END_NAMESPACE_STD - #endif // _LIBCPP___FUNCTIONAL_FUNCTION_H diff --git a/lib/libcxx/include/__functional/hash.h b/lib/libcxx/include/__functional/hash.h index 8a11931288..dfd8ea2553 100644 --- a/lib/libcxx/include/__functional/hash.h +++ b/lib/libcxx/include/__functional/hash.h @@ -10,8 +10,15 @@ #define _LIBCPP___FUNCTIONAL_HASH_H #include <__config> +#include <__functional/invoke.h> #include <__functional/unary_function.h> -#include <__tuple> +#include <__fwd/hash.h> +#include <__tuple_dir/sfinae_helpers.h> +#include <__type_traits/is_copy_constructible.h> +#include <__type_traits/is_default_constructible.h> +#include <__type_traits/is_enum.h> +#include <__type_traits/is_move_constructible.h> +#include <__type_traits/underlying_type.h> #include <__utility/forward.h> #include <__utility/move.h> #include <__utility/pair.h> @@ -20,7 +27,6 @@ #include #include #include -#include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header @@ -62,7 +68,7 @@ __murmur2_or_cityhash<_Size, 32>::operator()(const void* __key, _Size __len) const unsigned char* __data = static_cast(__key); for (; __len >= 4; __data += 4, __len -= 4) { - _Size __k = __loadword<_Size>(__data); + _Size __k = std::__loadword<_Size>(__data); __k *= __m; __k ^= __k >> __r; __k *= __m; @@ -127,14 +133,14 @@ struct __murmur2_or_cityhash<_Size, 64> _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK { if (__len > 8) { - const _Size __a = __loadword<_Size>(__s); - const _Size __b = __loadword<_Size>(__s + __len - 8); + const _Size __a = std::__loadword<_Size>(__s); + const _Size __b = std::__loadword<_Size>(__s + __len - 8); return __hash_len_16(__a, __rotate_by_at_least_1(__b + __len, __len)) ^ __b; } if (__len >= 4) { - const uint32_t __a = __loadword(__s); - const uint32_t __b = __loadword(__s + __len - 4); - return __hash_len_16(__len + (__a << 3), __b); + const uint32_t __a = std::__loadword(__s); + const uint32_t __b = std::__loadword(__s + __len - 4); + return __hash_len_16(__len + (static_cast<_Size>(__a) << 3), __b); } if (__len > 0) { const unsigned char __a = static_cast(__s[0]); @@ -151,10 +157,10 @@ struct __murmur2_or_cityhash<_Size, 64> static _Size __hash_len_17_to_32(const char *__s, _Size __len) _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK { - const _Size __a = __loadword<_Size>(__s) * __k1; - const _Size __b = __loadword<_Size>(__s + 8); - const _Size __c = __loadword<_Size>(__s + __len - 8) * __k2; - const _Size __d = __loadword<_Size>(__s + __len - 16) * __k0; + const _Size __a = std::__loadword<_Size>(__s) * __k1; + const _Size __b = std::__loadword<_Size>(__s + 8); + const _Size __c = std::__loadword<_Size>(__s + __len - 8) * __k2; + const _Size __d = std::__loadword<_Size>(__s + __len - 16) * __k0; return __hash_len_16(__rotate(__a - __b, 43) + __rotate(__c, 30) + __d, __a + __rotate(__b ^ __k3, 20) - __c + __len); } @@ -179,10 +185,10 @@ struct __murmur2_or_cityhash<_Size, 64> const char* __s, _Size __a, _Size __b) _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK { - return __weak_hash_len_32_with_seeds(__loadword<_Size>(__s), - __loadword<_Size>(__s + 8), - __loadword<_Size>(__s + 16), - __loadword<_Size>(__s + 24), + return __weak_hash_len_32_with_seeds(std::__loadword<_Size>(__s), + std::__loadword<_Size>(__s + 8), + std::__loadword<_Size>(__s + 16), + std::__loadword<_Size>(__s + 24), __a, __b); } @@ -191,23 +197,23 @@ struct __murmur2_or_cityhash<_Size, 64> static _Size __hash_len_33_to_64(const char *__s, size_t __len) _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK { - _Size __z = __loadword<_Size>(__s + 24); - _Size __a = __loadword<_Size>(__s) + - (__len + __loadword<_Size>(__s + __len - 16)) * __k0; + _Size __z = std::__loadword<_Size>(__s + 24); + _Size __a = std::__loadword<_Size>(__s) + + (__len + std::__loadword<_Size>(__s + __len - 16)) * __k0; _Size __b = __rotate(__a + __z, 52); _Size __c = __rotate(__a, 37); - __a += __loadword<_Size>(__s + 8); + __a += std::__loadword<_Size>(__s + 8); __c += __rotate(__a, 7); - __a += __loadword<_Size>(__s + 16); + __a += std::__loadword<_Size>(__s + 16); _Size __vf = __a + __z; _Size __vs = __b + __rotate(__a, 31) + __c; - __a = __loadword<_Size>(__s + 16) + __loadword<_Size>(__s + __len - 32); - __z += __loadword<_Size>(__s + __len - 8); + __a = std::__loadword<_Size>(__s + 16) + std::__loadword<_Size>(__s + __len - 32); + __z += std::__loadword<_Size>(__s + __len - 8); __b = __rotate(__a + __z, 52); __c = __rotate(__a, 37); - __a += __loadword<_Size>(__s + __len - 24); + __a += std::__loadword<_Size>(__s + __len - 24); __c += __rotate(__a, 7); - __a += __loadword<_Size>(__s + __len - 16); + __a += std::__loadword<_Size>(__s + __len - 16); _Size __wf = __a + __z; _Size __ws = __b + __rotate(__a, 31) + __c; _Size __r = __shift_mix((__vf + __ws) * __k2 + (__wf + __vs) * __k0); @@ -233,26 +239,26 @@ __murmur2_or_cityhash<_Size, 64>::operator()(const void* __key, _Size __len) // For strings over 64 bytes we hash the end first, and then as we // loop we keep 56 bytes of state: v, w, x, y, and z. - _Size __x = __loadword<_Size>(__s + __len - 40); - _Size __y = __loadword<_Size>(__s + __len - 16) + - __loadword<_Size>(__s + __len - 56); - _Size __z = __hash_len_16(__loadword<_Size>(__s + __len - 48) + __len, - __loadword<_Size>(__s + __len - 24)); + _Size __x = std::__loadword<_Size>(__s + __len - 40); + _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 + __loadword<_Size>(__s); + __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); do { - __x = __rotate(__x + __y + __v.first + __loadword<_Size>(__s + 8), 37) * __k1; - __y = __rotate(__y + __v.second + __loadword<_Size>(__s + 48), 42) * __k1; + __x = __rotate(__x + __y + __v.first + std::__loadword<_Size>(__s + 8), 37) * __k1; + __y = __rotate(__y + __v.second + std::__loadword<_Size>(__s + 48), 42) * __k1; __x ^= __w.second; - __y += __v.first + __loadword<_Size>(__s + 40); + __y += __v.first + std::__loadword<_Size>(__s + 40); __z = __rotate(__z + __w.first, 33) * __k1; __v = __weak_hash_len_32_with_seeds(__s, __v.second * __k1, __x + __w.first); __w = __weak_hash_len_32_with_seeds(__s + 32, __z + __w.second, - __y + __loadword<_Size>(__s + 16)); + __y + std::__loadword<_Size>(__s + 16)); _VSTD::swap(__z, __x); __s += 64; __len -= 64; diff --git a/lib/libcxx/include/__functional/invoke.h b/lib/libcxx/include/__functional/invoke.h index d56a0accdb..48e6eac3ce 100644 --- a/lib/libcxx/include/__functional/invoke.h +++ b/lib/libcxx/include/__functional/invoke.h @@ -248,7 +248,7 @@ struct __member_pointer_traits_imp<_Rp _Class::*, false, true> template struct __member_pointer_traits - : public __member_pointer_traits_imp::type, + : public __member_pointer_traits_imp<__remove_cv_t<_MP>, is_member_function_pointer<_MP>::value, is_member_object_pointer<_MP>::value> { @@ -398,7 +398,7 @@ template struct __invokable_r { template - static decltype(std::__invoke(declval<_XFp>(), declval<_XArgs>()...)) __try_call(int); + static decltype(std::__invoke(std::declval<_XFp>(), std::declval<_XArgs>()...)) __try_call(int); template static __nat __try_call(...); @@ -406,10 +406,10 @@ struct __invokable_r // or incomplete array types as required by the standard. using _Result = decltype(__try_call<_Fp, _Args...>(0)); - using type = typename conditional< + using type = __conditional_t< _IsNotSame<_Result, __nat>::value, - typename conditional< is_void<_Ret>::value, true_type, __is_core_convertible<_Result, _Ret> >::type, - false_type >::type; + __conditional_t::value, true_type, __is_core_convertible<_Result, _Ret> >, + false_type>; static const bool value = type::value; }; template @@ -428,15 +428,23 @@ struct __nothrow_invokable_r_imp template static void __test_noexcept(_Tp) _NOEXCEPT; +#ifdef _LIBCPP_CXX03_LANG + static const bool value = false; +#else static const bool value = noexcept(_ThisT::__test_noexcept<_Ret>( - _VSTD::__invoke(declval<_Fp>(), declval<_Args>()...))); + _VSTD::__invoke(std::declval<_Fp>(), std::declval<_Args>()...))); +#endif }; template struct __nothrow_invokable_r_imp { +#ifdef _LIBCPP_CXX03_LANG + static const bool value = false; +#else static const bool value = noexcept( - _VSTD::__invoke(declval<_Fp>(), declval<_Args>()...)); + _VSTD::__invoke(std::declval<_Fp>(), std::declval<_Args>()...)); +#endif }; template @@ -524,7 +532,7 @@ template using invoke_result_t = typename invoke_result<_Fn, _Args...>::type; template -_LIBCPP_CONSTEXPR_AFTER_CXX17 invoke_result_t<_Fn, _Args...> +_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...>) { diff --git a/lib/libcxx/include/__functional/is_transparent.h b/lib/libcxx/include/__functional/is_transparent.h index 74326c76c1..c7a0ee9ee7 100644 --- a/lib/libcxx/include/__functional/is_transparent.h +++ b/lib/libcxx/include/__functional/is_transparent.h @@ -25,8 +25,7 @@ template struct __is_transparent : false_type {}; template -struct __is_transparent<_Tp, _Up, - typename __void_t::type> +struct __is_transparent<_Tp, _Up, __void_t > : true_type {}; #endif diff --git a/lib/libcxx/include/__functional/mem_fn.h b/lib/libcxx/include/__functional/mem_fn.h index a5818b3f01..8b51627079 100644 --- a/lib/libcxx/include/__functional/mem_fn.h +++ b/lib/libcxx/include/__functional/mem_fn.h @@ -33,12 +33,12 @@ private: type __f_; public: - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 __mem_fn(type __f) _NOEXCEPT : __f_(__f) {} // invoke template - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 typename __invoke_return::type operator() (_ArgTypes&&... __args) const { @@ -47,7 +47,7 @@ public: }; template -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 __mem_fn<_Rp _Tp::*> mem_fn(_Rp _Tp::* __pm) _NOEXCEPT { diff --git a/lib/libcxx/include/__functional/not_fn.h b/lib/libcxx/include/__functional/not_fn.h index b5c415c25c..79d9a8710b 100644 --- a/lib/libcxx/include/__functional/not_fn.h +++ b/lib/libcxx/include/__functional/not_fn.h @@ -27,7 +27,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD struct __not_fn_op { template _LIBCPP_HIDE_FROM_ABI - _LIBCPP_CONSTEXPR_AFTER_CXX17 auto operator()(_Args&&... __args) const + _LIBCPP_CONSTEXPR_SINCE_CXX20 auto operator()(_Args&&... __args) const noexcept(noexcept(!_VSTD::invoke(_VSTD::forward<_Args>(__args)...))) -> decltype( !_VSTD::invoke(_VSTD::forward<_Args>(__args)...)) { return !_VSTD::invoke(_VSTD::forward<_Args>(__args)...); } @@ -43,7 +43,7 @@ template > >> _LIBCPP_HIDE_FROM_ABI -_LIBCPP_CONSTEXPR_AFTER_CXX17 auto not_fn(_Fn&& __f) { +_LIBCPP_CONSTEXPR_SINCE_CXX20 auto not_fn(_Fn&& __f) { return __not_fn_t>(_VSTD::forward<_Fn>(__f)); } diff --git a/lib/libcxx/include/__functional/operations.h b/lib/libcxx/include/__functional/operations.h index 1c73c999db..8a781efbdb 100644 --- a/lib/libcxx/include/__functional/operations.h +++ b/lib/libcxx/include/__functional/operations.h @@ -32,17 +32,18 @@ struct _LIBCPP_TEMPLATE_VIS plus : __binary_function<_Tp, _Tp, _Tp> { typedef _Tp __result_type; // used by valarray - _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const {return __x + __y;} }; +_LIBCPP_CTAD_SUPPORTED_FOR_TYPE(plus); #if _LIBCPP_STD_VER > 11 template <> struct _LIBCPP_TEMPLATE_VIS plus { template - _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY auto operator()(_T1&& __t, _T2&& __u) const noexcept(noexcept(_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u))) -> decltype( _VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u)) @@ -60,17 +61,18 @@ struct _LIBCPP_TEMPLATE_VIS minus : __binary_function<_Tp, _Tp, _Tp> { typedef _Tp __result_type; // used by valarray - _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const {return __x - __y;} }; +_LIBCPP_CTAD_SUPPORTED_FOR_TYPE(minus); #if _LIBCPP_STD_VER > 11 template <> struct _LIBCPP_TEMPLATE_VIS minus { template - _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY auto operator()(_T1&& __t, _T2&& __u) const noexcept(noexcept(_VSTD::forward<_T1>(__t) - _VSTD::forward<_T2>(__u))) -> decltype( _VSTD::forward<_T1>(__t) - _VSTD::forward<_T2>(__u)) @@ -88,17 +90,18 @@ struct _LIBCPP_TEMPLATE_VIS multiplies : __binary_function<_Tp, _Tp, _Tp> { typedef _Tp __result_type; // used by valarray - _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const {return __x * __y;} }; +_LIBCPP_CTAD_SUPPORTED_FOR_TYPE(multiplies); #if _LIBCPP_STD_VER > 11 template <> struct _LIBCPP_TEMPLATE_VIS multiplies { template - _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY auto operator()(_T1&& __t, _T2&& __u) const noexcept(noexcept(_VSTD::forward<_T1>(__t) * _VSTD::forward<_T2>(__u))) -> decltype( _VSTD::forward<_T1>(__t) * _VSTD::forward<_T2>(__u)) @@ -116,17 +119,18 @@ struct _LIBCPP_TEMPLATE_VIS divides : __binary_function<_Tp, _Tp, _Tp> { typedef _Tp __result_type; // used by valarray - _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const {return __x / __y;} }; +_LIBCPP_CTAD_SUPPORTED_FOR_TYPE(divides); #if _LIBCPP_STD_VER > 11 template <> struct _LIBCPP_TEMPLATE_VIS divides { template - _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY auto operator()(_T1&& __t, _T2&& __u) const noexcept(noexcept(_VSTD::forward<_T1>(__t) / _VSTD::forward<_T2>(__u))) -> decltype( _VSTD::forward<_T1>(__t) / _VSTD::forward<_T2>(__u)) @@ -144,17 +148,18 @@ struct _LIBCPP_TEMPLATE_VIS modulus : __binary_function<_Tp, _Tp, _Tp> { typedef _Tp __result_type; // used by valarray - _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const {return __x % __y;} }; +_LIBCPP_CTAD_SUPPORTED_FOR_TYPE(modulus); #if _LIBCPP_STD_VER > 11 template <> struct _LIBCPP_TEMPLATE_VIS modulus { template - _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY auto operator()(_T1&& __t, _T2&& __u) const noexcept(noexcept(_VSTD::forward<_T1>(__t) % _VSTD::forward<_T2>(__u))) -> decltype( _VSTD::forward<_T1>(__t) % _VSTD::forward<_T2>(__u)) @@ -172,17 +177,18 @@ struct _LIBCPP_TEMPLATE_VIS negate : __unary_function<_Tp, _Tp> { typedef _Tp __result_type; // used by valarray - _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x) const {return -__x;} }; +_LIBCPP_CTAD_SUPPORTED_FOR_TYPE(negate); #if _LIBCPP_STD_VER > 11 template <> struct _LIBCPP_TEMPLATE_VIS negate { template - _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY auto operator()(_Tp&& __x) const noexcept(noexcept(- _VSTD::forward<_Tp>(__x))) -> decltype( - _VSTD::forward<_Tp>(__x)) @@ -202,17 +208,18 @@ struct _LIBCPP_TEMPLATE_VIS bit_and : __binary_function<_Tp, _Tp, _Tp> { typedef _Tp __result_type; // used by valarray - _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const {return __x & __y;} }; +_LIBCPP_CTAD_SUPPORTED_FOR_TYPE(bit_and); #if _LIBCPP_STD_VER > 11 template <> struct _LIBCPP_TEMPLATE_VIS bit_and { template - _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY auto operator()(_T1&& __t, _T2&& __u) const noexcept(noexcept(_VSTD::forward<_T1>(__t) & _VSTD::forward<_T2>(__u))) -> decltype( _VSTD::forward<_T1>(__t) & _VSTD::forward<_T2>(__u)) @@ -226,16 +233,17 @@ template struct _LIBCPP_TEMPLATE_VIS bit_not : __unary_function<_Tp, _Tp> { - _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x) const {return ~__x;} }; +_LIBCPP_CTAD_SUPPORTED_FOR_TYPE(bit_not); template <> struct _LIBCPP_TEMPLATE_VIS bit_not { template - _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY auto operator()(_Tp&& __x) const noexcept(noexcept(~_VSTD::forward<_Tp>(__x))) -> decltype( ~_VSTD::forward<_Tp>(__x)) @@ -253,17 +261,18 @@ struct _LIBCPP_TEMPLATE_VIS bit_or : __binary_function<_Tp, _Tp, _Tp> { typedef _Tp __result_type; // used by valarray - _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const {return __x | __y;} }; +_LIBCPP_CTAD_SUPPORTED_FOR_TYPE(bit_or); #if _LIBCPP_STD_VER > 11 template <> struct _LIBCPP_TEMPLATE_VIS bit_or { template - _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY auto operator()(_T1&& __t, _T2&& __u) const noexcept(noexcept(_VSTD::forward<_T1>(__t) | _VSTD::forward<_T2>(__u))) -> decltype( _VSTD::forward<_T1>(__t) | _VSTD::forward<_T2>(__u)) @@ -281,17 +290,18 @@ struct _LIBCPP_TEMPLATE_VIS bit_xor : __binary_function<_Tp, _Tp, _Tp> { typedef _Tp __result_type; // used by valarray - _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const {return __x ^ __y;} }; +_LIBCPP_CTAD_SUPPORTED_FOR_TYPE(bit_xor); #if _LIBCPP_STD_VER > 11 template <> struct _LIBCPP_TEMPLATE_VIS bit_xor { template - _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY auto operator()(_T1&& __t, _T2&& __u) const noexcept(noexcept(_VSTD::forward<_T1>(__t) ^ _VSTD::forward<_T2>(__u))) -> decltype( _VSTD::forward<_T1>(__t) ^ _VSTD::forward<_T2>(__u)) @@ -311,17 +321,18 @@ struct _LIBCPP_TEMPLATE_VIS equal_to : __binary_function<_Tp, _Tp, bool> { typedef bool __result_type; // used by valarray - _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const {return __x == __y;} }; +_LIBCPP_CTAD_SUPPORTED_FOR_TYPE(equal_to); #if _LIBCPP_STD_VER > 11 template <> struct _LIBCPP_TEMPLATE_VIS equal_to { template - _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY auto operator()(_T1&& __t, _T2&& __u) const noexcept(noexcept(_VSTD::forward<_T1>(__t) == _VSTD::forward<_T2>(__u))) -> decltype( _VSTD::forward<_T1>(__t) == _VSTD::forward<_T2>(__u)) @@ -339,17 +350,18 @@ struct _LIBCPP_TEMPLATE_VIS not_equal_to : __binary_function<_Tp, _Tp, bool> { typedef bool __result_type; // used by valarray - _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const {return __x != __y;} }; +_LIBCPP_CTAD_SUPPORTED_FOR_TYPE(not_equal_to); #if _LIBCPP_STD_VER > 11 template <> struct _LIBCPP_TEMPLATE_VIS not_equal_to { template - _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY auto operator()(_T1&& __t, _T2&& __u) const noexcept(noexcept(_VSTD::forward<_T1>(__t) != _VSTD::forward<_T2>(__u))) -> decltype( _VSTD::forward<_T1>(__t) != _VSTD::forward<_T2>(__u)) @@ -367,17 +379,18 @@ struct _LIBCPP_TEMPLATE_VIS less : __binary_function<_Tp, _Tp, bool> { typedef bool __result_type; // used by valarray - _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const {return __x < __y;} }; +_LIBCPP_CTAD_SUPPORTED_FOR_TYPE(less); #if _LIBCPP_STD_VER > 11 template <> struct _LIBCPP_TEMPLATE_VIS less { template - _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY auto operator()(_T1&& __t, _T2&& __u) const noexcept(noexcept(_VSTD::forward<_T1>(__t) < _VSTD::forward<_T2>(__u))) -> decltype( _VSTD::forward<_T1>(__t) < _VSTD::forward<_T2>(__u)) @@ -395,17 +408,18 @@ struct _LIBCPP_TEMPLATE_VIS less_equal : __binary_function<_Tp, _Tp, bool> { typedef bool __result_type; // used by valarray - _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const {return __x <= __y;} }; +_LIBCPP_CTAD_SUPPORTED_FOR_TYPE(less_equal); #if _LIBCPP_STD_VER > 11 template <> struct _LIBCPP_TEMPLATE_VIS less_equal { template - _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY auto operator()(_T1&& __t, _T2&& __u) const noexcept(noexcept(_VSTD::forward<_T1>(__t) <= _VSTD::forward<_T2>(__u))) -> decltype( _VSTD::forward<_T1>(__t) <= _VSTD::forward<_T2>(__u)) @@ -423,17 +437,18 @@ struct _LIBCPP_TEMPLATE_VIS greater_equal : __binary_function<_Tp, _Tp, bool> { typedef bool __result_type; // used by valarray - _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const {return __x >= __y;} }; +_LIBCPP_CTAD_SUPPORTED_FOR_TYPE(greater_equal); #if _LIBCPP_STD_VER > 11 template <> struct _LIBCPP_TEMPLATE_VIS greater_equal { template - _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY auto operator()(_T1&& __t, _T2&& __u) const noexcept(noexcept(_VSTD::forward<_T1>(__t) >= _VSTD::forward<_T2>(__u))) -> decltype( _VSTD::forward<_T1>(__t) >= _VSTD::forward<_T2>(__u)) @@ -451,17 +466,18 @@ struct _LIBCPP_TEMPLATE_VIS greater : __binary_function<_Tp, _Tp, bool> { typedef bool __result_type; // used by valarray - _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const {return __x > __y;} }; +_LIBCPP_CTAD_SUPPORTED_FOR_TYPE(greater); #if _LIBCPP_STD_VER > 11 template <> struct _LIBCPP_TEMPLATE_VIS greater { template - _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY auto operator()(_T1&& __t, _T2&& __u) const noexcept(noexcept(_VSTD::forward<_T1>(__t) > _VSTD::forward<_T2>(__u))) -> decltype( _VSTD::forward<_T1>(__t) > _VSTD::forward<_T2>(__u)) @@ -481,17 +497,18 @@ struct _LIBCPP_TEMPLATE_VIS logical_and : __binary_function<_Tp, _Tp, bool> { typedef bool __result_type; // used by valarray - _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const {return __x && __y;} }; +_LIBCPP_CTAD_SUPPORTED_FOR_TYPE(logical_and); #if _LIBCPP_STD_VER > 11 template <> struct _LIBCPP_TEMPLATE_VIS logical_and { template - _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY auto operator()(_T1&& __t, _T2&& __u) const noexcept(noexcept(_VSTD::forward<_T1>(__t) && _VSTD::forward<_T2>(__u))) -> decltype( _VSTD::forward<_T1>(__t) && _VSTD::forward<_T2>(__u)) @@ -509,17 +526,18 @@ struct _LIBCPP_TEMPLATE_VIS logical_not : __unary_function<_Tp, bool> { typedef bool __result_type; // used by valarray - _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x) const {return !__x;} }; +_LIBCPP_CTAD_SUPPORTED_FOR_TYPE(logical_not); #if _LIBCPP_STD_VER > 11 template <> struct _LIBCPP_TEMPLATE_VIS logical_not { template - _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY auto operator()(_Tp&& __x) const noexcept(noexcept(!_VSTD::forward<_Tp>(__x))) -> decltype( !_VSTD::forward<_Tp>(__x)) @@ -537,17 +555,18 @@ struct _LIBCPP_TEMPLATE_VIS logical_or : __binary_function<_Tp, _Tp, bool> { typedef bool __result_type; // used by valarray - _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const {return __x || __y;} }; +_LIBCPP_CTAD_SUPPORTED_FOR_TYPE(logical_or); #if _LIBCPP_STD_VER > 11 template <> struct _LIBCPP_TEMPLATE_VIS logical_or { template - _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY auto operator()(_T1&& __t, _T2&& __u) const noexcept(noexcept(_VSTD::forward<_T1>(__t) || _VSTD::forward<_T2>(__u))) -> decltype( _VSTD::forward<_T1>(__t) || _VSTD::forward<_T2>(__u)) diff --git a/lib/libcxx/include/__functional/ranges_operations.h b/lib/libcxx/include/__functional/ranges_operations.h index 3f63a86731..87081dd56a 100644 --- a/lib/libcxx/include/__functional/ranges_operations.h +++ b/lib/libcxx/include/__functional/ranges_operations.h @@ -10,9 +10,10 @@ #ifndef _LIBCPP___FUNCTIONAL_RANGES_OPERATIONS_H #define _LIBCPP___FUNCTIONAL_RANGES_OPERATIONS_H +#include <__concepts/equality_comparable.h> +#include <__concepts/totally_ordered.h> #include <__config> #include <__utility/forward.h> -#include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header diff --git a/lib/libcxx/include/__functional/reference_wrapper.h b/lib/libcxx/include/__functional/reference_wrapper.h index 8245e3a047..c377b64377 100644 --- a/lib/libcxx/include/__functional/reference_wrapper.h +++ b/lib/libcxx/include/__functional/reference_wrapper.h @@ -11,10 +11,13 @@ #define _LIBCPP___FUNCTIONAL_REFERENCE_WRAPPER_H #include <__config> +#include <__functional/invoke.h> #include <__functional/weak_result_type.h> #include <__memory/addressof.h> +#include <__type_traits/enable_if.h> +#include <__type_traits/remove_cvref.h> +#include <__utility/declval.h> #include <__utility/forward.h> -#include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header @@ -35,22 +38,22 @@ private: static void __fun(_Tp&&) = delete; public: - template ::value, decltype(__fun(declval<_Up>())) > > - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 - reference_wrapper(_Up&& __u) _NOEXCEPT_(noexcept(__fun(declval<_Up>()))) { + template ::value, decltype(__fun(std::declval<_Up>())) > > + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 + reference_wrapper(_Up&& __u) _NOEXCEPT_(noexcept(__fun(std::declval<_Up>()))) { type& __f = static_cast<_Up&&>(__u); __f_ = _VSTD::addressof(__f); } // access - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 operator type&() const _NOEXCEPT {return *__f_;} - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 type& get() const _NOEXCEPT {return *__f_;} // invoke template - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 typename __invoke_of::type operator() (_ArgTypes&&... __args) const { return std::__invoke(get(), std::forward<_ArgTypes>(__args)...); @@ -63,7 +66,7 @@ reference_wrapper(_Tp&) -> reference_wrapper<_Tp>; #endif template -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 reference_wrapper<_Tp> ref(_Tp& __t) _NOEXCEPT { @@ -71,7 +74,7 @@ ref(_Tp& __t) _NOEXCEPT } template -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 reference_wrapper<_Tp> ref(reference_wrapper<_Tp> __t) _NOEXCEPT { @@ -79,7 +82,7 @@ ref(reference_wrapper<_Tp> __t) _NOEXCEPT } template -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 reference_wrapper cref(const _Tp& __t) _NOEXCEPT { @@ -87,7 +90,7 @@ cref(const _Tp& __t) _NOEXCEPT } template -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 reference_wrapper cref(reference_wrapper<_Tp> __t) _NOEXCEPT { diff --git a/lib/libcxx/include/__functional/unary_negate.h b/lib/libcxx/include/__functional/unary_negate.h index 7f081903fe..ab87e86d18 100644 --- a/lib/libcxx/include/__functional/unary_negate.h +++ b/lib/libcxx/include/__functional/unary_negate.h @@ -27,16 +27,16 @@ class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX17 unary_negate { _Predicate __pred_; public: - _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY explicit unary_negate(const _Predicate& __pred) : __pred_(__pred) {} - _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY bool operator()(const typename _Predicate::argument_type& __x) const {return !__pred_(__x);} }; template -_LIBCPP_DEPRECATED_IN_CXX17 inline _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY +_LIBCPP_DEPRECATED_IN_CXX17 inline _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY unary_negate<_Predicate> not1(const _Predicate& __pred) {return unary_negate<_Predicate>(__pred);} diff --git a/lib/libcxx/include/__functional/unwrap_ref.h b/lib/libcxx/include/__functional/unwrap_ref.h index f7207934e1..da000d80b8 100644 --- a/lib/libcxx/include/__functional/unwrap_ref.h +++ b/lib/libcxx/include/__functional/unwrap_ref.h @@ -10,6 +10,7 @@ #define _LIBCPP___FUNCTIONAL_UNWRAP_REF_H #include <__config> +#include <__type_traits/decay.h> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header diff --git a/lib/libcxx/include/__functional/weak_result_type.h b/lib/libcxx/include/__functional/weak_result_type.h index 96d8cf7146..18d1bf718c 100644 --- a/lib/libcxx/include/__functional/weak_result_type.h +++ b/lib/libcxx/include/__functional/weak_result_type.h @@ -12,8 +12,11 @@ #include <__config> #include <__functional/binary_function.h> +#include <__functional/invoke.h> #include <__functional/unary_function.h> -#include +#include <__type_traits/integral_constant.h> +#include <__type_traits/is_same.h> +#include <__utility/declval.h> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header @@ -283,7 +286,7 @@ struct __weak_result_type<_Rp (_Cp::*)(_A1, _A2, _A3...) const volatile> template struct __invoke_return { - typedef decltype(_VSTD::__invoke(declval<_Tp>(), declval<_Args>()...)) type; + typedef decltype(_VSTD::__invoke(std::declval<_Tp>(), std::declval<_Args>()...)) type; }; _LIBCPP_END_NAMESPACE_STD diff --git a/lib/libcxx/include/__fwd/array.h b/lib/libcxx/include/__fwd/array.h new file mode 100644 index 0000000000..9a79effb61 --- /dev/null +++ b/lib/libcxx/include/__fwd/array.h @@ -0,0 +1,26 @@ +//===---------------------------------------------------------------------===// +// +// 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_ARRAY_H +#define _LIBCPP___FWD_ARRAY_H + +#include <__config> +#include + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +template +struct _LIBCPP_TEMPLATE_VIS array; + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___FWD_ARRAY_H diff --git a/lib/libcxx/include/__fwd/get.h b/lib/libcxx/include/__fwd/get.h new file mode 100644 index 0000000000..ec1fab4602 --- /dev/null +++ b/lib/libcxx/include/__fwd/get.h @@ -0,0 +1,115 @@ +//===----------------------------------------------------------------------===// +// +// 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_GET_H +#define _LIBCPP___FWD_GET_H + +#include <__concepts/copyable.h> +#include <__config> +#include <__fwd/array.h> +#include <__fwd/pair.h> +#include <__fwd/subrange.h> +#include <__fwd/tuple.h> +#include <__tuple_dir/tuple_element.h> +#include + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +#ifndef _LIBCPP_CXX03_LANG + +template +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14 +typename tuple_element<_Ip, tuple<_Tp...> >::type& +get(tuple<_Tp...>&) _NOEXCEPT; + +template +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14 +const typename tuple_element<_Ip, tuple<_Tp...> >::type& +get(const tuple<_Tp...>&) _NOEXCEPT; + +template +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14 +typename tuple_element<_Ip, tuple<_Tp...> >::type&& +get(tuple<_Tp...>&&) _NOEXCEPT; + +template +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14 +const typename tuple_element<_Ip, tuple<_Tp...> >::type&& +get(const tuple<_Tp...>&&) _NOEXCEPT; + +#endif //_LIBCPP_CXX03_LANG + +template +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14 +typename tuple_element<_Ip, pair<_T1, _T2> >::type& +get(pair<_T1, _T2>&) _NOEXCEPT; + +template +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14 +const typename tuple_element<_Ip, pair<_T1, _T2> >::type& +get(const pair<_T1, _T2>&) _NOEXCEPT; + +#ifndef _LIBCPP_CXX03_LANG +template +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14 +typename tuple_element<_Ip, pair<_T1, _T2> >::type&& +get(pair<_T1, _T2>&&) _NOEXCEPT; + +template +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14 +const typename tuple_element<_Ip, pair<_T1, _T2> >::type&& +get(const pair<_T1, _T2>&&) _NOEXCEPT; +#endif + +template +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14 +_Tp& +get(array<_Tp, _Size>&) _NOEXCEPT; + +template +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14 +const _Tp& +get(const array<_Tp, _Size>&) _NOEXCEPT; + +#ifndef _LIBCPP_CXX03_LANG +template +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14 +_Tp&& +get(array<_Tp, _Size>&&) _NOEXCEPT; + +template +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14 +const _Tp&& +get(const array<_Tp, _Size>&&) _NOEXCEPT; +#endif + +#if _LIBCPP_STD_VER >= 20 + +namespace ranges { + +template + requires((_Index == 0 && copyable<_Iter>) || _Index == 1) +_LIBCPP_HIDE_FROM_ABI constexpr auto get(const subrange<_Iter, _Sent, _Kind>& __subrange); + +template + requires(_Index < 2) +_LIBCPP_HIDE_FROM_ABI constexpr auto get(subrange<_Iter, _Sent, _Kind>&& __subrange); + +} // namespace ranges + +using ranges::get; + +#endif // _LIBCPP_STD_VER >= 20 + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___FWD_GET_H diff --git a/lib/libcxx/include/__fwd/hash.h b/lib/libcxx/include/__fwd/hash.h new file mode 100644 index 0000000000..af9eca876a --- /dev/null +++ b/lib/libcxx/include/__fwd/hash.h @@ -0,0 +1,25 @@ +//===---------------------------------------------------------------------===// +// +// 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_HASH_H +#define _LIBCPP___FWD_HASH_H + +#include <__config> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +template +struct _LIBCPP_TEMPLATE_VIS hash; + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___FWD_HASH_H diff --git a/lib/libcxx/include/__fwd/memory_resource.h b/lib/libcxx/include/__fwd/memory_resource.h new file mode 100644 index 0000000000..718a9078d3 --- /dev/null +++ b/lib/libcxx/include/__fwd/memory_resource.h @@ -0,0 +1,27 @@ +//===----------------------------------------------------------------------===// +// +// 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_MEMORY_RESOURCE_H +#define _LIBCPP___FWD_MEMORY_RESOURCE_H + +#include <__config> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +namespace pmr { +template +class _LIBCPP_TEMPLATE_VIS polymorphic_allocator; +} // namespace pmr + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___FWD_MEMORY_RESOURCE_H diff --git a/lib/libcxx/include/__fwd/pair.h b/lib/libcxx/include/__fwd/pair.h new file mode 100644 index 0000000000..3844014de3 --- /dev/null +++ b/lib/libcxx/include/__fwd/pair.h @@ -0,0 +1,25 @@ +//===---------------------------------------------------------------------===// +// +// 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_PAIR_H +#define _LIBCPP___FWD_PAIR_H + +#include <__config> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +template +struct _LIBCPP_TEMPLATE_VIS pair; + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___FWD_PAIR_H diff --git a/lib/libcxx/include/__fwd/span.h b/lib/libcxx/include/__fwd/span.h index f38b8cfa05..943cb13fa1 100644 --- a/lib/libcxx/include/__fwd/span.h +++ b/lib/libcxx/include/__fwd/span.h @@ -7,8 +7,8 @@ // //===---------------------------------------------------------------------===// -#ifndef _LIBCPP_FWD_SPAN_H -#define _LIBCPP_FWD_SPAN_H +#ifndef _LIBCPP___FWD_SPAN_H +#define _LIBCPP___FWD_SPAN_H #include <__config> #include @@ -34,4 +34,4 @@ _LIBCPP_END_NAMESPACE_STD _LIBCPP_POP_MACROS -#endif // _LIBCPP_FWD_SPAN_H +#endif // _LIBCPP___FWD_SPAN_H diff --git a/lib/libcxx/include/__fwd/string.h b/lib/libcxx/include/__fwd/string.h new file mode 100644 index 0000000000..7ab5561b75 --- /dev/null +++ b/lib/libcxx/include/__fwd/string.h @@ -0,0 +1,110 @@ +//===----------------------------------------------------------------------===// +// +// 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_STRING_H +#define _LIBCPP___FWD_STRING_H + +#include <__config> +#include <__fwd/memory_resource.h> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +template +struct _LIBCPP_TEMPLATE_VIS char_traits; +template <> +struct char_traits; + +#ifndef _LIBCPP_HAS_NO_CHAR8_T +template <> +struct char_traits; +#endif + +template <> +struct char_traits; +template <> +struct char_traits; + +#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS +template <> +struct char_traits; +#endif + +template +class _LIBCPP_TEMPLATE_VIS allocator; + +template , class _Allocator = allocator<_CharT> > +class _LIBCPP_TEMPLATE_VIS basic_string; + +using string = basic_string; + +#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS +using wstring = basic_string; +#endif + +#ifndef _LIBCPP_HAS_NO_CHAR8_T +using u8string = basic_string; +#endif + +using u16string = basic_string; +using u32string = basic_string; + +#if _LIBCPP_STD_VER >= 17 + +namespace pmr { +template > +using basic_string = std::basic_string<_CharT, _Traits, polymorphic_allocator<_CharT>>; + +using string = basic_string; + +# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS +using wstring = basic_string; +# endif + +# ifndef _LIBCPP_HAS_NO_CHAR8_T +using u8string = basic_string; +# endif + +using u16string = basic_string; +using u32string = basic_string; + +} // namespace pmr + +#endif // _LIBCPP_STD_VER >= 17 + +// clang-format off +template +class _LIBCPP_PREFERRED_NAME(string) +#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS + _LIBCPP_PREFERRED_NAME(wstring) +#endif +#ifndef _LIBCPP_HAS_NO_CHAR8_T + _LIBCPP_PREFERRED_NAME(u8string) +#endif + _LIBCPP_PREFERRED_NAME(u16string) + _LIBCPP_PREFERRED_NAME(u32string) +#if _LIBCPP_STD_VER >= 17 + _LIBCPP_PREFERRED_NAME(pmr::string) +# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS + _LIBCPP_PREFERRED_NAME(pmr::wstring) +# endif +# ifndef _LIBCPP_HAS_NO_CHAR8_T + _LIBCPP_PREFERRED_NAME(pmr::u8string) +# endif + _LIBCPP_PREFERRED_NAME(pmr::u16string) + _LIBCPP_PREFERRED_NAME(pmr::u32string) +#endif + basic_string; +// clang-format on + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___FWD_STRING_H diff --git a/lib/libcxx/include/__fwd/string_view.h b/lib/libcxx/include/__fwd/string_view.h index e5e77b292a..4818990248 100644 --- a/lib/libcxx/include/__fwd/string_view.h +++ b/lib/libcxx/include/__fwd/string_view.h @@ -7,8 +7,8 @@ // //===---------------------------------------------------------------------===// -#ifndef _LIBCPP_FWD_STRING_VIEW_H -#define _LIBCPP_FWD_STRING_VIEW_H +#ifndef _LIBCPP___FWD_STRING_VIEW_H +#define _LIBCPP___FWD_STRING_VIEW_H #include <__config> #include // char_traits @@ -32,6 +32,19 @@ typedef basic_string_view u32string_view; typedef basic_string_view wstring_view; #endif +// clang-format off +template +class _LIBCPP_PREFERRED_NAME(string_view) +#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS + _LIBCPP_PREFERRED_NAME(wstring_view) +#endif +#ifndef _LIBCPP_HAS_NO_CHAR8_T + _LIBCPP_PREFERRED_NAME(u8string_view) +#endif + _LIBCPP_PREFERRED_NAME(u16string_view) + _LIBCPP_PREFERRED_NAME(u32string_view) + basic_string_view; +// clang-format on _LIBCPP_END_NAMESPACE_STD -#endif // _LIBCPP_FWD_STRING_VIEW_H +#endif // _LIBCPP___FWD_STRING_VIEW_H diff --git a/lib/libcxx/include/__fwd/subrange.h b/lib/libcxx/include/__fwd/subrange.h new file mode 100644 index 0000000000..8f7239247e --- /dev/null +++ b/lib/libcxx/include/__fwd/subrange.h @@ -0,0 +1,38 @@ +//===---------------------------------------------------------------------===// +// +// 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_SUBRANGE_H +#define _LIBCPP___FWD_SUBRANGE_H + +#include <__config> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +#if _LIBCPP_STD_VER >= 20 + +#include <__iterator/concepts.h> + +_LIBCPP_BEGIN_NAMESPACE_STD + +namespace ranges { + +enum class _LIBCPP_ENUM_VIS subrange_kind : bool { unsized, sized }; + +template _Sent, subrange_kind _Kind> + requires(_Kind == subrange_kind::sized || !sized_sentinel_for<_Sent, _Iter>) +class _LIBCPP_TEMPLATE_VIS subrange; + +} // namespace ranges + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_STD_VER >= 20 + +#endif // _LIBCPP___FWD_SUBRANGE_H diff --git a/lib/libcxx/include/__fwd/tuple.h b/lib/libcxx/include/__fwd/tuple.h new file mode 100644 index 0000000000..16b3fabbb9 --- /dev/null +++ b/lib/libcxx/include/__fwd/tuple.h @@ -0,0 +1,29 @@ +//===---------------------------------------------------------------------===// +// +// 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_TUPLE_H +#define _LIBCPP___FWD_TUPLE_H + +#include <__config> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +#ifndef _LIBCPP_CXX03_LANG + +template +class _LIBCPP_TEMPLATE_VIS tuple; + +#endif // _LIBCPP_CXX03_LANG + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___FWD_TUPLE_H diff --git a/lib/libcxx/include/__hash_table b/lib/libcxx/include/__hash_table index 959ef7fe7d..f8896c8664 100644 --- a/lib/libcxx/include/__hash_table +++ b/lib/libcxx/include/__hash_table @@ -13,16 +13,25 @@ #include <__algorithm/max.h> #include <__algorithm/min.h> #include <__assert> -#include <__bits> // __libcpp_clz +#include <__bit/countl.h> #include <__config> #include <__debug> #include <__functional/hash.h> #include <__iterator/iterator_traits.h> +#include <__memory/addressof.h> +#include <__memory/allocator_traits.h> +#include <__memory/compressed_pair.h> +#include <__memory/pointer_traits.h> #include <__memory/swap_allocator.h> +#include <__memory/unique_ptr.h> +#include <__type_traits/can_extract_key.h> +#include <__utility/forward.h> +#include <__utility/move.h> +#include <__utility/pair.h> #include <__utility/swap.h> #include +#include #include -#include #include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) @@ -48,7 +57,7 @@ template struct __is_hash_value_type : false_type {}; template -struct __is_hash_value_type<_One> : __is_hash_value_type_imp<__uncvref_t<_One> > {}; +struct __is_hash_value_type<_One> : __is_hash_value_type_imp<__remove_cvref_t<_One> > {}; _LIBCPP_FUNC_VIS size_t __next_prime(size_t __n); @@ -58,16 +67,13 @@ struct __hash_node_base { typedef typename pointer_traits<_NodePtr>::element_type __node_type; typedef __hash_node_base __first_node; - typedef typename __rebind_pointer<_NodePtr, __first_node>::type __node_base_pointer; + typedef __rebind_pointer_t<_NodePtr, __first_node> __node_base_pointer; typedef _NodePtr __node_pointer; #if defined(_LIBCPP_ABI_FIX_UNORDERED_NODE_POINTER_UB) typedef __node_base_pointer __next_pointer; #else - typedef typename conditional< - is_pointer<__node_pointer>::value, - __node_base_pointer, - __node_pointer>::type __next_pointer; + typedef __conditional_t::value, __node_base_pointer, __node_pointer> __next_pointer; #endif __next_pointer __next_; @@ -96,7 +102,7 @@ template struct _LIBCPP_STANDALONE_DEBUG __hash_node : public __hash_node_base < - typename __rebind_pointer<_VoidPtr, __hash_node<_Tp, _VoidPtr> >::type + __rebind_pointer_t<_VoidPtr, __hash_node<_Tp, _VoidPtr> > > { typedef _Tp __node_value_type; @@ -208,9 +214,9 @@ struct __hash_map_pointer_types {}; template struct __hash_map_pointer_types<_Tp, _AllocPtr, _KVTypes, true> { typedef typename _KVTypes::__map_value_type _Mv; - typedef typename __rebind_pointer<_AllocPtr, _Mv>::type + typedef __rebind_pointer_t<_AllocPtr, _Mv> __map_value_type_pointer; - typedef typename __rebind_pointer<_AllocPtr, const _Mv>::type + typedef __rebind_pointer_t<_AllocPtr, const _Mv> __const_map_value_type_pointer; }; @@ -228,21 +234,21 @@ public: typedef ptrdiff_t difference_type; typedef size_t size_type; - typedef typename __rebind_pointer<_NodePtr, void>::type __void_pointer; + typedef __rebind_pointer_t<_NodePtr, void> __void_pointer; typedef typename pointer_traits<_NodePtr>::element_type __node_type; typedef _NodePtr __node_pointer; typedef __hash_node_base<__node_pointer> __node_base_type; - typedef typename __rebind_pointer<_NodePtr, __node_base_type>::type + typedef __rebind_pointer_t<_NodePtr, __node_base_type> __node_base_pointer; typedef typename __node_base_type::__next_pointer __next_pointer; typedef _Tp __node_value_type; - typedef typename __rebind_pointer<_VoidPtr, __node_value_type>::type + typedef __rebind_pointer_t<_VoidPtr, __node_value_type> __node_value_type_pointer; - typedef typename __rebind_pointer<_VoidPtr, const __node_value_type>::type + typedef __rebind_pointer_t<_VoidPtr, const __node_value_type> __const_node_value_type_pointer; private: @@ -250,7 +256,7 @@ private: "_NodePtr should never be a pointer to const"); static_assert((is_same::element_type, void>::value), "_VoidPtr does not point to unqualified void type"); - static_assert((is_same::type, + static_assert((is_same<__rebind_pointer_t<_VoidPtr, __node_type>, _NodePtr>::value), "_VoidPtr does not rebind to _NodePtr."); }; @@ -269,7 +275,7 @@ struct __hash_node_types_from_iterator<__hash_const_local_iterator<_NodePtr> > : template struct __make_hash_node_types { typedef __hash_node<_NodeValueTp, _VoidPtr> _NodeTp; - typedef typename __rebind_pointer<_VoidPtr, _NodeTp>::type _NodePtr; + typedef __rebind_pointer_t<_VoidPtr, _NodeTp> _NodePtr; typedef __hash_node_types<_NodePtr> type; }; @@ -559,7 +565,7 @@ public: _LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this), "Attempted to increment a non-incrementable unordered container local_iterator"); __node_ = __node_->__next_; - if (__node_ != nullptr && __constrain_hash(__node_->__hash(), __bucket_count_) != __bucket_) + if (__node_ != nullptr && std::__constrain_hash(__node_->__hash(), __bucket_count_) != __bucket_) __node_ = nullptr; return *this; } @@ -614,8 +620,8 @@ class _LIBCPP_TEMPLATE_VIS __hash_const_local_iterator typedef pointer_traits<__node_pointer> __pointer_traits; typedef typename __pointer_traits::element_type __node; - typedef typename remove_const<__node>::type __non_const_node; - typedef typename __rebind_pointer<__node_pointer, __non_const_node>::type + typedef __remove_const_t<__node> __non_const_node; + typedef __rebind_pointer_t<__node_pointer, __non_const_node> __non_const_node_pointer; public: typedef __hash_local_iterator<__non_const_node_pointer> @@ -692,7 +698,7 @@ public: _LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this), "Attempted to increment a non-incrementable unordered container const_local_iterator"); __node_ = __node_->__next_; - if (__node_ != nullptr && __constrain_hash(__node_->__hash(), __bucket_count_) != __bucket_) + if (__node_ != nullptr && std::__constrain_hash(__node_->__hash(), __bucket_count_) != __bucket_) __node_ = nullptr; return *this; } @@ -892,7 +898,7 @@ public: // Create __node typedef typename _NodeTypes::__node_type __node; - typedef typename __rebind_alloc_helper<__alloc_traits, __node>::type __node_allocator; + typedef __rebind_alloc<__alloc_traits, __node> __node_allocator; typedef allocator_traits<__node_allocator> __node_traits; typedef typename _NodeTypes::__void_pointer __void_pointer; typedef typename _NodeTypes::__node_pointer __node_pointer; @@ -907,15 +913,14 @@ private: // the pointer using 'pointer_traits'. static_assert((is_same<__node_pointer, typename __node_traits::pointer>::value), "Allocator does not rebind pointers in a sane manner."); - typedef typename __rebind_alloc_helper<__node_traits, __first_node>::type - __node_base_allocator; + typedef __rebind_alloc<__node_traits, __first_node> __node_base_allocator; typedef allocator_traits<__node_base_allocator> __node_base_traits; static_assert((is_same<__node_base_pointer, typename __node_base_traits::pointer>::value), "Allocator does not rebind pointers in a sane manner."); private: - typedef typename __rebind_alloc_helper<__node_traits, __next_pointer>::type __pointer_allocator; + typedef __rebind_alloc<__node_traits, __next_pointer> __pointer_allocator; typedef __bucket_list_deallocator<__pointer_allocator> __bucket_list_deleter; typedef unique_ptr<__next_pointer[], __bucket_list_deleter> __bucket_list; typedef allocator_traits<__pointer_allocator> __pointer_alloc_traits; @@ -1151,11 +1156,11 @@ public: _LIBCPP_INLINE_VISIBILITY void __rehash_multi(size_type __n) { __rehash(__n); } _LIBCPP_INLINE_VISIBILITY void __reserve_unique(size_type __n) { - __rehash_unique(static_cast(ceil(__n / max_load_factor()))); + __rehash_unique(static_cast(std::ceil(__n / max_load_factor()))); } _LIBCPP_INLINE_VISIBILITY void __reserve_multi(size_type __n) { - __rehash_multi(static_cast(ceil(__n / max_load_factor()))); + __rehash_multi(static_cast(std::ceil(__n / max_load_factor()))); } _LIBCPP_INLINE_VISIBILITY @@ -1179,7 +1184,7 @@ public: { _LIBCPP_ASSERT(bucket_count() > 0, "unordered container::bucket(key) called when bucket_count() == 0"); - return __constrain_hash(hash_function()(__k), bucket_count()); + return std::__constrain_hash(hash_function()(__k), bucket_count()); } template @@ -1428,7 +1433,7 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(__hash_table&& __u) { if (size() > 0) { - __bucket_list_[__constrain_hash(__p1_.first().__next_->__hash(), bucket_count())] = + __bucket_list_[std::__constrain_hash(__p1_.first().__next_->__hash(), bucket_count())] = __p1_.first().__ptr(); __u.__p1_.first().__next_ = nullptr; __u.size() = 0; @@ -1452,7 +1457,7 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(__hash_table&& __u, { __p1_.first().__next_ = __u.__p1_.first().__next_; __u.__p1_.first().__next_ = nullptr; - __bucket_list_[__constrain_hash(__p1_.first().__next_->__hash(), bucket_count())] = + __bucket_list_[std::__constrain_hash(__p1_.first().__next_->__hash(), bucket_count())] = __p1_.first().__ptr(); size() = __u.size(); __u.size() = 0; @@ -1569,7 +1574,7 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::__move_assign( __p1_.first().__next_ = __u.__p1_.first().__next_; if (size() > 0) { - __bucket_list_[__constrain_hash(__p1_.first().__next_->__hash(), bucket_count())] = + __bucket_list_[std::__constrain_hash(__p1_.first().__next_->__hash(), bucket_count())] = __p1_.first().__ptr(); __u.__p1_.first().__next_ = nullptr; __u.size() = 0; @@ -1784,12 +1789,12 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_unique_prepare( if (__bc != 0) { - size_t __chash = __constrain_hash(__hash, __bc); + size_t __chash = std::__constrain_hash(__hash, __bc); __next_pointer __ndptr = __bucket_list_[__chash]; if (__ndptr != nullptr) { for (__ndptr = __ndptr->__next_; __ndptr != nullptr && - __constrain_hash(__ndptr->__hash(), __bc) == __chash; + std::__constrain_hash(__ndptr->__hash(), __bc) == __chash; __ndptr = __ndptr->__next_) { if (key_eq()(__ndptr->__upcast()->__value_, __value)) @@ -1799,8 +1804,8 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_unique_prepare( } if (size()+1 > __bc * max_load_factor() || __bc == 0) { - __rehash_unique(_VSTD::max(2 * __bc + !__is_hash_power2(__bc), - size_type(ceil(float(size() + 1) / max_load_factor())))); + __rehash_unique(_VSTD::max(2 * __bc + !std::__is_hash_power2(__bc), + size_type(std::ceil(float(size() + 1) / max_load_factor())))); } return nullptr; } @@ -1816,7 +1821,7 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_unique_perform( __node_pointer __nd) _NOEXCEPT { size_type __bc = bucket_count(); - size_t __chash = __constrain_hash(__nd->__hash(), __bc); + size_t __chash = std::__constrain_hash(__nd->__hash(), __bc); // insert_after __bucket_list_[__chash], or __first_node if bucket is null __next_pointer __pn = __bucket_list_[__chash]; if (__pn == nullptr) @@ -1827,7 +1832,7 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_unique_perform( // fix up __bucket_list_ __bucket_list_[__chash] = __pn; if (__nd->__next_ != nullptr) - __bucket_list_[__constrain_hash(__nd->__next_->__hash(), __bc)] = __nd->__ptr(); + __bucket_list_[std::__constrain_hash(__nd->__next_->__hash(), __bc)] = __nd->__ptr(); } else { @@ -1871,16 +1876,16 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_multi_prepare( size_type __bc = bucket_count(); if (size()+1 > __bc * max_load_factor() || __bc == 0) { - __rehash_multi(_VSTD::max(2 * __bc + !__is_hash_power2(__bc), - size_type(ceil(float(size() + 1) / max_load_factor())))); + __rehash_multi(_VSTD::max(2 * __bc + !std::__is_hash_power2(__bc), + size_type(std::ceil(float(size() + 1) / max_load_factor())))); __bc = bucket_count(); } - size_t __chash = __constrain_hash(__cp_hash, __bc); + size_t __chash = std::__constrain_hash(__cp_hash, __bc); __next_pointer __pn = __bucket_list_[__chash]; if (__pn != nullptr) { for (bool __found = false; __pn->__next_ != nullptr && - __constrain_hash(__pn->__next_->__hash(), __bc) == __chash; + std::__constrain_hash(__pn->__next_->__hash(), __bc) == __chash; __pn = __pn->__next_) { // __found key_eq() action @@ -1912,7 +1917,7 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_multi_perform( __node_pointer __cp, __next_pointer __pn) _NOEXCEPT { size_type __bc = bucket_count(); - size_t __chash = __constrain_hash(__cp->__hash_, __bc); + size_t __chash = std::__constrain_hash(__cp->__hash_, __bc); if (__pn == nullptr) { __pn =__p1_.first().__ptr(); @@ -1921,7 +1926,7 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_multi_perform( // fix up __bucket_list_ __bucket_list_[__chash] = __pn; if (__cp->__next_ != nullptr) - __bucket_list_[__constrain_hash(__cp->__next_->__hash(), __bc)] + __bucket_list_[std::__constrain_hash(__cp->__next_->__hash(), __bc)] = __cp->__ptr(); } else @@ -1930,7 +1935,7 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_multi_perform( __pn->__next_ = __cp->__ptr(); if (__cp->__next_ != nullptr) { - size_t __nhash = __constrain_hash(__cp->__next_->__hash(), __bc); + size_t __nhash = std::__constrain_hash(__cp->__next_->__hash(), __bc); if (__nhash != __chash) __bucket_list_[__nhash] = __cp->__ptr(); } @@ -1965,11 +1970,11 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_multi( size_type __bc = bucket_count(); if (size()+1 > __bc * max_load_factor() || __bc == 0) { - __rehash_multi(_VSTD::max(2 * __bc + !__is_hash_power2(__bc), - size_type(ceil(float(size() + 1) / max_load_factor())))); + __rehash_multi(_VSTD::max(2 * __bc + !std::__is_hash_power2(__bc), + size_type(std::ceil(float(size() + 1) / max_load_factor())))); __bc = bucket_count(); } - size_t __chash = __constrain_hash(__cp->__hash_, __bc); + size_t __chash = std::__constrain_hash(__cp->__hash_, __bc); __next_pointer __pp = __bucket_list_[__chash]; while (__pp->__next_ != __np) __pp = __pp->__next_; @@ -1996,12 +2001,12 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::__emplace_unique_key_args(_Key const& size_t __chash; if (__bc != 0) { - __chash = __constrain_hash(__hash, __bc); + __chash = std::__constrain_hash(__hash, __bc); __nd = __bucket_list_[__chash]; if (__nd != nullptr) { for (__nd = __nd->__next_; __nd != nullptr && - (__nd->__hash() == __hash || __constrain_hash(__nd->__hash(), __bc) == __chash); + (__nd->__hash() == __hash || std::__constrain_hash(__nd->__hash(), __bc) == __chash); __nd = __nd->__next_) { if (key_eq()(__nd->__upcast()->__value_, __k)) @@ -2013,10 +2018,10 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::__emplace_unique_key_args(_Key const& __node_holder __h = __construct_node_hash(__hash, _VSTD::forward<_Args>(__args)...); if (size()+1 > __bc * max_load_factor() || __bc == 0) { - __rehash_unique(_VSTD::max(2 * __bc + !__is_hash_power2(__bc), - size_type(ceil(float(size() + 1) / max_load_factor())))); + __rehash_unique(_VSTD::max(2 * __bc + !std::__is_hash_power2(__bc), + size_type(std::ceil(float(size() + 1) / max_load_factor())))); __bc = bucket_count(); - __chash = __constrain_hash(__hash, __bc); + __chash = std::__constrain_hash(__hash, __bc); } // insert_after __bucket_list_[__chash], or __first_node if bucket is null __next_pointer __pn = __bucket_list_[__chash]; @@ -2028,7 +2033,7 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::__emplace_unique_key_args(_Key const& // fix up __bucket_list_ __bucket_list_[__chash] = __pn; if (__h->__next_ != nullptr) - __bucket_list_[__constrain_hash(__h->__next_->__hash(), __bc)] + __bucket_list_[std::__constrain_hash(__h->__next_->__hash(), __bc)] = __h.get()->__ptr(); } else @@ -2224,7 +2229,7 @@ _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK if (__n == 1) __n = 2; else if (__n & (__n - 1)) - __n = __next_prime(__n); + __n = std::__next_prime(__n); size_type __bc = bucket_count(); if (__n > __bc) __do_rehash<_UniqueKeys>(__n); @@ -2233,8 +2238,8 @@ _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK __n = _VSTD::max ( __n, - __is_hash_power2(__bc) ? __next_hash_pow2(size_t(ceil(float(size()) / max_load_factor()))) : - __next_prime(size_t(ceil(float(size()) / max_load_factor()))) + std::__is_hash_power2(__bc) ? std::__next_hash_pow2(size_t(std::ceil(float(size()) / max_load_factor()))) : + std::__next_prime(size_t(std::ceil(float(size()) / max_load_factor()))) ); if (__n < __bc) __do_rehash<_UniqueKeys>(__n); @@ -2259,13 +2264,13 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::__do_rehash(size_type __nbc) __next_pointer __cp = __pp->__next_; if (__cp != nullptr) { - size_type __chash = __constrain_hash(__cp->__hash(), __nbc); + size_type __chash = std::__constrain_hash(__cp->__hash(), __nbc); __bucket_list_[__chash] = __pp; size_type __phash = __chash; for (__pp = __cp, void(), __cp = __cp->__next_; __cp != nullptr; __cp = __pp->__next_) { - __chash = __constrain_hash(__cp->__hash(), __nbc); + __chash = std::__constrain_hash(__cp->__hash(), __nbc); if (__chash == __phash) __pp = __cp; else @@ -2279,7 +2284,7 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::__do_rehash(size_type __nbc) else { __next_pointer __np = __cp; - if _LIBCPP_CONSTEXPR_AFTER_CXX14 (!_UniqueKeys) + if _LIBCPP_CONSTEXPR_SINCE_CXX17 (!_UniqueKeys) { for (; __np->__next_ != nullptr && key_eq()(__cp->__upcast()->__value_, @@ -2307,13 +2312,13 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::find(const _Key& __k) size_type __bc = bucket_count(); if (__bc != 0) { - size_t __chash = __constrain_hash(__hash, __bc); + size_t __chash = std::__constrain_hash(__hash, __bc); __next_pointer __nd = __bucket_list_[__chash]; if (__nd != nullptr) { for (__nd = __nd->__next_; __nd != nullptr && (__nd->__hash() == __hash - || __constrain_hash(__nd->__hash(), __bc) == __chash); + || std::__constrain_hash(__nd->__hash(), __bc) == __chash); __nd = __nd->__next_) { if ((__nd->__hash() == __hash) @@ -2334,13 +2339,13 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::find(const _Key& __k) const size_type __bc = bucket_count(); if (__bc != 0) { - size_t __chash = __constrain_hash(__hash, __bc); + size_t __chash = std::__constrain_hash(__hash, __bc); __next_pointer __nd = __bucket_list_[__chash]; if (__nd != nullptr) { for (__nd = __nd->__next_; __nd != nullptr && (__hash == __nd->__hash() - || __constrain_hash(__nd->__hash(), __bc) == __chash); + || std::__constrain_hash(__nd->__hash(), __bc) == __chash); __nd = __nd->__next_) { if ((__nd->__hash() == __hash) @@ -2462,7 +2467,7 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::remove(const_iterator __p) _NOEXCEPT // current node __next_pointer __cn = __p.__node_; size_type __bc = bucket_count(); - size_t __chash = __constrain_hash(__cn->__hash(), __bc); + size_t __chash = std::__constrain_hash(__cn->__hash(), __bc); // find previous node __next_pointer __pn = __bucket_list_[__chash]; for (; __pn->__next_ != __cn; __pn = __pn->__next_) @@ -2471,16 +2476,16 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::remove(const_iterator __p) _NOEXCEPT // if __pn is not in same bucket (before begin is not in same bucket) && // if __cn->__next_ is not in same bucket (nullptr is not in same bucket) if (__pn == __p1_.first().__ptr() - || __constrain_hash(__pn->__hash(), __bc) != __chash) + || std::__constrain_hash(__pn->__hash(), __bc) != __chash) { if (__cn->__next_ == nullptr - || __constrain_hash(__cn->__next_->__hash(), __bc) != __chash) + || std::__constrain_hash(__cn->__next_->__hash(), __bc) != __chash) __bucket_list_[__chash] = nullptr; } // if __cn->__next_ is not in same bucket (nullptr is in same bucket) if (__cn->__next_ != nullptr) { - size_t __nhash = __constrain_hash(__cn->__next_->__hash(), __bc); + size_t __nhash = std::__constrain_hash(__cn->__next_->__hash(), __bc); if (__nhash != __chash) __bucket_list_[__nhash] = __pn; } @@ -2634,10 +2639,10 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::swap(__hash_table& __u) __p2_.swap(__u.__p2_); __p3_.swap(__u.__p3_); if (size() > 0) - __bucket_list_[__constrain_hash(__p1_.first().__next_->__hash(), bucket_count())] = + __bucket_list_[std::__constrain_hash(__p1_.first().__next_->__hash(), bucket_count())] = __p1_.first().__ptr(); if (__u.size() > 0) - __u.__bucket_list_[__constrain_hash(__u.__p1_.first().__next_->__hash(), __u.bucket_count())] = + __u.__bucket_list_[std::__constrain_hash(__u.__p1_.first().__next_->__hash(), __u.bucket_count())] = __u.__p1_.first().__ptr(); std::__debug_db_swap(this, std::addressof(__u)); } @@ -2654,8 +2659,8 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::bucket_size(size_type __n) const if (__np != nullptr) { for (__np = __np->__next_; __np != nullptr && - __constrain_hash(__np->__hash(), __bc) == __n; - __np = __np->__next_, (void) ++__r) + std::__constrain_hash(__np->__hash(), __bc) == __n; + __np = __np->__next_, (void) ++__r) ; } return __r; diff --git a/lib/libcxx/include/__iterator/access.h b/lib/libcxx/include/__iterator/access.h index 7abd4c5573..0b8d523017 100644 --- a/lib/libcxx/include/__iterator/access.h +++ b/lib/libcxx/include/__iterator/access.h @@ -20,7 +20,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD template -_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14 _Tp* begin(_Tp (&__array)[_Np]) { @@ -28,7 +28,7 @@ begin(_Tp (&__array)[_Np]) } template -_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14 _Tp* end(_Tp (&__array)[_Np]) { @@ -38,7 +38,7 @@ end(_Tp (&__array)[_Np]) #if !defined(_LIBCPP_CXX03_LANG) template -_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17 auto begin(_Cp& __c) -> decltype(__c.begin()) { @@ -46,7 +46,7 @@ begin(_Cp& __c) -> decltype(__c.begin()) } template -_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17 auto begin(const _Cp& __c) -> decltype(__c.begin()) { @@ -54,7 +54,7 @@ begin(const _Cp& __c) -> decltype(__c.begin()) } template -_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17 auto end(_Cp& __c) -> decltype(__c.end()) { @@ -62,7 +62,7 @@ end(_Cp& __c) -> decltype(__c.end()) } template -_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17 auto end(const _Cp& __c) -> decltype(__c.end()) { @@ -72,14 +72,14 @@ end(const _Cp& __c) -> decltype(__c.end()) #if _LIBCPP_STD_VER > 11 template -_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14 auto cbegin(const _Cp& __c) -> decltype(_VSTD::begin(__c)) { return _VSTD::begin(__c); } template -_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14 auto cend(const _Cp& __c) -> decltype(_VSTD::end(__c)) { return _VSTD::end(__c); diff --git a/lib/libcxx/include/__iterator/advance.h b/lib/libcxx/include/__iterator/advance.h index 4b8b0dc970..154c2736f3 100644 --- a/lib/libcxx/include/__iterator/advance.h +++ b/lib/libcxx/include/__iterator/advance.h @@ -11,16 +11,20 @@ #define _LIBCPP___ITERATOR_ADVANCE_H #include <__assert> +#include <__concepts/assignable.h> +#include <__concepts/same_as.h> #include <__config> #include <__iterator/concepts.h> #include <__iterator/incrementable_traits.h> #include <__iterator/iterator_traits.h> +#include <__type_traits/enable_if.h> +#include <__type_traits/is_integral.h> +#include <__utility/convert_to_integral.h> +#include <__utility/declval.h> #include <__utility/move.h> #include <__utility/unreachable.h> -#include #include #include -#include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header @@ -29,14 +33,14 @@ _LIBCPP_BEGIN_NAMESPACE_STD template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX14 +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 void __advance(_InputIter& __i, typename iterator_traits<_InputIter>::difference_type __n, input_iterator_tag) { for (; __n > 0; --__n) ++__i; } template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX14 +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 void __advance(_BiDirIter& __i, typename iterator_traits<_BiDirIter>::difference_type __n, bidirectional_iterator_tag) { if (__n >= 0) for (; __n > 0; --__n) @@ -47,16 +51,16 @@ void __advance(_BiDirIter& __i, typename iterator_traits<_BiDirIter>::difference } template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX14 +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 void __advance(_RandIter& __i, typename iterator_traits<_RandIter>::difference_type __n, random_access_iterator_tag) { __i += __n; } template < class _InputIter, class _Distance, - class _IntegralDistance = decltype(_VSTD::__convert_to_integral(declval<_Distance>())), + class _IntegralDistance = decltype(_VSTD::__convert_to_integral(std::declval<_Distance>())), class = __enable_if_t::value> > -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX14 +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 void advance(_InputIter& __i, _Distance __orig_n) { typedef typename iterator_traits<_InputIter>::difference_type _Difference; _Difference __n = static_cast<_Difference>(_VSTD::__convert_to_integral(__orig_n)); @@ -65,7 +69,7 @@ void advance(_InputIter& __i, _Distance __orig_n) { _VSTD::__advance(__i, __n, typename iterator_traits<_InputIter>::iterator_category()); } -#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#if _LIBCPP_STD_VER > 17 // [range.iter.op.advance] @@ -192,7 +196,7 @@ inline namespace __cpo { } // namespace __cpo } // namespace ranges -#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#endif // _LIBCPP_STD_VER > 17 _LIBCPP_END_NAMESPACE_STD diff --git a/lib/libcxx/include/__iterator/back_insert_iterator.h b/lib/libcxx/include/__iterator/back_insert_iterator.h index e9f9f2abec..4c00a7e397 100644 --- a/lib/libcxx/include/__iterator/back_insert_iterator.h +++ b/lib/libcxx/include/__iterator/back_insert_iterator.h @@ -45,22 +45,23 @@ public: typedef void reference; typedef _Container container_type; - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 explicit back_insert_iterator(_Container& __x) : container(_VSTD::addressof(__x)) {} - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator& operator=(const typename _Container::value_type& __value) + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit back_insert_iterator(_Container& __x) : container(_VSTD::addressof(__x)) {} + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 back_insert_iterator& operator=(const typename _Container::value_type& __value) {container->push_back(__value); return *this;} #ifndef _LIBCPP_CXX03_LANG - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator& operator=(typename _Container::value_type&& __value) + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 back_insert_iterator& operator=(typename _Container::value_type&& __value) {container->push_back(_VSTD::move(__value)); return *this;} #endif // _LIBCPP_CXX03_LANG - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator& operator*() {return *this;} - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator& operator++() {return *this;} - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator operator++(int) {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++() {return *this;} + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 back_insert_iterator operator++(int) {return *this;} - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 _Container* __get_container() const { return container; } + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Container* __get_container() const { return container; } }; +_LIBCPP_CTAD_SUPPORTED_FOR_TYPE(back_insert_iterator); template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 back_insert_iterator<_Container> back_inserter(_Container& __x) { diff --git a/lib/libcxx/include/__iterator/bounded_iter.h b/lib/libcxx/include/__iterator/bounded_iter.h index a395e2b638..2682f2a68a 100644 --- a/lib/libcxx/include/__iterator/bounded_iter.h +++ b/lib/libcxx/include/__iterator/bounded_iter.h @@ -14,8 +14,10 @@ #include <__config> #include <__iterator/iterator_traits.h> #include <__memory/pointer_traits.h> +#include <__type_traits/enable_if.h> +#include <__type_traits/integral_constant.h> +#include <__type_traits/is_convertible.h> #include <__utility/move.h> -#include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header @@ -73,7 +75,7 @@ private: // // Since it is non-standard for iterators to have this constructor, __bounded_iter must // be created via `std::__make_bounded_iter`. - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 explicit __bounded_iter( + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit __bounded_iter( _Iterator __current, _Iterator __begin, _Iterator __end) : __current_(__current), __begin_(__begin), __end_(__end) { _LIBCPP_ASSERT(__begin <= __end, "__bounded_iter(current, begin, end): [begin, end) is not a valid range"); @@ -86,19 +88,19 @@ public: // Dereference and indexing operations. // // These operations check that the iterator is dereferenceable, that is within [begin, end). - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 reference operator*() const _NOEXCEPT { + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 reference operator*() const _NOEXCEPT { _LIBCPP_ASSERT( __in_bounds(__current_), "__bounded_iter::operator*: Attempt to dereference an out-of-range iterator"); return *__current_; } - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 pointer operator->() const _NOEXCEPT { + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pointer operator->() const _NOEXCEPT { _LIBCPP_ASSERT( __in_bounds(__current_), "__bounded_iter::operator->: Attempt to dereference an out-of-range iterator"); return std::__to_address(__current_); } - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 reference operator[](difference_type __n) const _NOEXCEPT { + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 reference operator[](difference_type __n) const _NOEXCEPT { _LIBCPP_ASSERT( __in_bounds(__current_ + __n), "__bounded_iter::operator[]: Attempt to index an iterator out-of-range"); return __current_[__n]; @@ -108,54 +110,54 @@ public: // // These operations do not check that the resulting iterator is within the bounds, since that // would make it impossible to create a past-the-end iterator. - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 __bounded_iter& operator++() _NOEXCEPT { + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 __bounded_iter& operator++() _NOEXCEPT { ++__current_; return *this; } - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 __bounded_iter operator++(int) _NOEXCEPT { + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 __bounded_iter operator++(int) _NOEXCEPT { __bounded_iter __tmp(*this); ++*this; return __tmp; } - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 __bounded_iter& operator--() _NOEXCEPT { + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 __bounded_iter& operator--() _NOEXCEPT { --__current_; return *this; } - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 __bounded_iter operator--(int) _NOEXCEPT { + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 __bounded_iter operator--(int) _NOEXCEPT { __bounded_iter __tmp(*this); --*this; return __tmp; } - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 __bounded_iter& operator+=(difference_type __n) _NOEXCEPT { + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 __bounded_iter& operator+=(difference_type __n) _NOEXCEPT { __current_ += __n; return *this; } - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 friend __bounded_iter + _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_AFTER_CXX11 friend __bounded_iter + _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; return __tmp; } - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 __bounded_iter& operator-=(difference_type __n) _NOEXCEPT { + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 __bounded_iter& operator-=(difference_type __n) _NOEXCEPT { __current_ -= __n; return *this; } - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 friend __bounded_iter + _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_AFTER_CXX11 friend difference_type + _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/common_iterator.h b/lib/libcxx/include/__iterator/common_iterator.h index abcc0b675e..f7883e2c37 100644 --- a/lib/libcxx/include/__iterator/common_iterator.h +++ b/lib/libcxx/include/__iterator/common_iterator.h @@ -11,6 +11,13 @@ #define _LIBCPP___ITERATOR_COMMON_ITERATOR_H #include <__assert> +#include <__concepts/assignable.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/same_as.h> #include <__config> #include <__iterator/concepts.h> #include <__iterator/incrementable_traits.h> @@ -18,7 +25,8 @@ #include <__iterator/iter_swap.h> #include <__iterator/iterator_traits.h> #include <__iterator/readable_traits.h> -#include +#include <__type_traits/is_pointer.h> +#include <__utility/declval.h> #include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) @@ -95,14 +103,14 @@ public: constexpr decltype(auto) operator*() { - _LIBCPP_ASSERT(holds_alternative<_Iter>(__hold_), "Attempted to dereference a non-dereferenceable common_iterator"); + _LIBCPP_ASSERT(std::holds_alternative<_Iter>(__hold_), "Attempted to dereference a non-dereferenceable common_iterator"); return *_VSTD::__unchecked_get<_Iter>(__hold_); } constexpr decltype(auto) operator*() const requires __dereferenceable { - _LIBCPP_ASSERT(holds_alternative<_Iter>(__hold_), "Attempted to dereference a non-dereferenceable common_iterator"); + _LIBCPP_ASSERT(std::holds_alternative<_Iter>(__hold_), "Attempted to dereference a non-dereferenceable common_iterator"); return *_VSTD::__unchecked_get<_Iter>(__hold_); } @@ -113,7 +121,7 @@ public: is_reference_v> || constructible_from, iter_reference_t<_I2>>) { - _LIBCPP_ASSERT(holds_alternative<_Iter>(__hold_), "Attempted to dereference a non-dereferenceable common_iterator"); + _LIBCPP_ASSERT(std::holds_alternative<_Iter>(__hold_), "Attempted to dereference a non-dereferenceable common_iterator"); if constexpr (is_pointer_v<_Iter> || requires(const _Iter& __i) { __i.operator->(); }) { return _VSTD::__unchecked_get<_Iter>(__hold_); } else if constexpr (is_reference_v>) { @@ -125,12 +133,12 @@ public: } common_iterator& operator++() { - _LIBCPP_ASSERT(holds_alternative<_Iter>(__hold_), "Attempted to increment a non-dereferenceable common_iterator"); + _LIBCPP_ASSERT(std::holds_alternative<_Iter>(__hold_), "Attempted to increment a non-dereferenceable common_iterator"); ++_VSTD::__unchecked_get<_Iter>(__hold_); return *this; } decltype(auto) operator++(int) { - _LIBCPP_ASSERT(holds_alternative<_Iter>(__hold_), "Attempted to increment a non-dereferenceable common_iterator"); + _LIBCPP_ASSERT(std::holds_alternative<_Iter>(__hold_), "Attempted to increment a non-dereferenceable common_iterator"); if constexpr (forward_iterator<_Iter>) { auto __tmp = *this; ++*this; @@ -147,6 +155,7 @@ public: template _S2> requires sentinel_for<_Sent, _I2> + _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(const common_iterator& __x, const common_iterator<_I2, _S2>& __y) { _LIBCPP_ASSERT(!__x.__hold_.valueless_by_exception(), "Attempted to compare a valueless common_iterator"); _LIBCPP_ASSERT(!__y.__hold_.valueless_by_exception(), "Attempted to compare a valueless common_iterator"); @@ -165,6 +174,7 @@ public: template _S2> requires sentinel_for<_Sent, _I2> && equality_comparable_with<_Iter, _I2> + _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(const common_iterator& __x, const common_iterator<_I2, _S2>& __y) { _LIBCPP_ASSERT(!__x.__hold_.valueless_by_exception(), "Attempted to compare a valueless common_iterator"); _LIBCPP_ASSERT(!__y.__hold_.valueless_by_exception(), "Attempted to compare a valueless common_iterator"); @@ -186,6 +196,7 @@ public: template _I2, sized_sentinel_for<_Iter> _S2> requires sized_sentinel_for<_Sent, _I2> + _LIBCPP_HIDE_FROM_ABI friend constexpr iter_difference_t<_I2> operator-(const common_iterator& __x, const common_iterator<_I2, _S2>& __y) { _LIBCPP_ASSERT(!__x.__hold_.valueless_by_exception(), "Attempted to subtract from a valueless common_iterator"); _LIBCPP_ASSERT(!__y.__hold_.valueless_by_exception(), "Attempted to subtract a valueless common_iterator"); @@ -205,20 +216,20 @@ public: return _VSTD::__unchecked_get<_Sent>(__x.__hold_) - _VSTD::__unchecked_get<_I2>(__y.__hold_); } - friend constexpr iter_rvalue_reference_t<_Iter> iter_move(const common_iterator& __i) - noexcept(noexcept(ranges::iter_move(declval()))) + _LIBCPP_HIDE_FROM_ABI friend constexpr iter_rvalue_reference_t<_Iter> iter_move(const common_iterator& __i) + noexcept(noexcept(ranges::iter_move(std::declval()))) requires input_iterator<_Iter> { - _LIBCPP_ASSERT(holds_alternative<_Iter>(__i.__hold_), "Attempted to iter_move a non-dereferenceable common_iterator"); + _LIBCPP_ASSERT(std::holds_alternative<_Iter>(__i.__hold_), "Attempted to iter_move a non-dereferenceable common_iterator"); return ranges::iter_move( _VSTD::__unchecked_get<_Iter>(__i.__hold_)); } template _I2, class _S2> - friend constexpr void iter_swap(const common_iterator& __x, const common_iterator<_I2, _S2>& __y) - noexcept(noexcept(ranges::iter_swap(declval(), declval()))) + _LIBCPP_HIDE_FROM_ABI friend constexpr void iter_swap(const common_iterator& __x, const common_iterator<_I2, _S2>& __y) + noexcept(noexcept(ranges::iter_swap(std::declval(), std::declval()))) { - _LIBCPP_ASSERT(holds_alternative<_Iter>(__x.__hold_), "Attempted to iter_swap a non-dereferenceable common_iterator"); - _LIBCPP_ASSERT(holds_alternative<_I2>(__y.__hold_), "Attempted to iter_swap a non-dereferenceable common_iterator"); + _LIBCPP_ASSERT(std::holds_alternative<_Iter>(__x.__hold_), "Attempted to iter_swap a non-dereferenceable common_iterator"); + _LIBCPP_ASSERT(std::holds_alternative<_I2>(__y.__hold_), "Attempted to iter_swap a non-dereferenceable common_iterator"); return ranges::iter_swap(_VSTD::__unchecked_get<_Iter>(__x.__hold_), _VSTD::__unchecked_get<_I2>(__y.__hold_)); } }; @@ -246,7 +257,7 @@ struct __arrow_type_or_void { template requires __common_iter_has_ptr_op<_Iter, _Sent> struct __arrow_type_or_void<_Iter, _Sent> { - using type = decltype(declval&>().operator->()); + using type = decltype(std::declval&>().operator->()); }; template diff --git a/lib/libcxx/include/__iterator/concepts.h b/lib/libcxx/include/__iterator/concepts.h index bd68889333..d9d40a4249 100644 --- a/lib/libcxx/include/__iterator/concepts.h +++ b/lib/libcxx/include/__iterator/concepts.h @@ -10,15 +10,35 @@ #ifndef _LIBCPP___ITERATOR_CONCEPTS_H #define _LIBCPP___ITERATOR_CONCEPTS_H +#include <__concepts/arithmetic.h> +#include <__concepts/assignable.h> +#include <__concepts/common_reference_with.h> +#include <__concepts/constructible.h> +#include <__concepts/copyable.h> +#include <__concepts/derived_from.h> +#include <__concepts/equality_comparable.h> +#include <__concepts/invocable.h> +#include <__concepts/movable.h> +#include <__concepts/predicate.h> +#include <__concepts/regular.h> +#include <__concepts/relation.h> +#include <__concepts/same_as.h> +#include <__concepts/semiregular.h> +#include <__concepts/totally_ordered.h> #include <__config> +#include <__functional/invoke.h> #include <__iterator/incrementable_traits.h> #include <__iterator/iter_move.h> #include <__iterator/iterator_traits.h> #include <__iterator/readable_traits.h> #include <__memory/pointer_traits.h> +#include <__type_traits/add_pointer.h> +#include <__type_traits/common_reference.h> +#include <__type_traits/is_pointer.h> +#include <__type_traits/is_reference.h> +#include <__type_traits/remove_cv.h> +#include <__type_traits/remove_cvref.h> #include <__utility/forward.h> -#include -#include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header diff --git a/lib/libcxx/include/__iterator/counted_iterator.h b/lib/libcxx/include/__iterator/counted_iterator.h index b0f5c66ecf..5fdbff4b48 100644 --- a/lib/libcxx/include/__iterator/counted_iterator.h +++ b/lib/libcxx/include/__iterator/counted_iterator.h @@ -6,10 +6,16 @@ // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// + #ifndef _LIBCPP___ITERATOR_COUNTED_ITERATOR_H #define _LIBCPP___ITERATOR_COUNTED_ITERATOR_H #include <__assert> +#include <__concepts/assignable.h> +#include <__concepts/common_with.h> +#include <__concepts/constructible.h> +#include <__concepts/convertible_to.h> +#include <__concepts/same_as.h> #include <__config> #include <__iterator/concepts.h> #include <__iterator/default_sentinel.h> @@ -19,10 +25,10 @@ #include <__iterator/iterator_traits.h> #include <__iterator/readable_traits.h> #include <__memory/pointer_traits.h> +#include <__type_traits/add_pointer.h> +#include <__type_traits/conditional.h> #include <__utility/move.h> #include -#include -#include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header @@ -263,7 +269,7 @@ public: } template _I2> - friend constexpr strong_ordering operator<=>( + _LIBCPP_HIDE_FROM_ABI friend constexpr strong_ordering operator<=>( const counted_iterator& __lhs, const counted_iterator<_I2>& __rhs) { return __rhs.__count_ <=> __lhs.__count_; @@ -288,6 +294,7 @@ public: return ranges::iter_swap(__x.__current_, __y.__current_); } }; +_LIBCPP_CTAD_SUPPORTED_FOR_TYPE(counted_iterator); template requires same_as<_ITER_TRAITS<_Iter>, iterator_traits<_Iter>> diff --git a/lib/libcxx/include/__iterator/distance.h b/lib/libcxx/include/__iterator/distance.h index 8819078958..681e20d045 100644 --- a/lib/libcxx/include/__iterator/distance.h +++ b/lib/libcxx/include/__iterator/distance.h @@ -17,7 +17,8 @@ #include <__ranges/access.h> #include <__ranges/concepts.h> #include <__ranges/size.h> -#include +#include <__type_traits/decay.h> +#include <__type_traits/remove_cvref.h> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header @@ -26,7 +27,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD template -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17 typename iterator_traits<_InputIter>::difference_type __distance(_InputIter __first, _InputIter __last, input_iterator_tag) { @@ -37,7 +38,7 @@ __distance(_InputIter __first, _InputIter __last, input_iterator_tag) } template -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17 typename iterator_traits<_RandIter>::difference_type __distance(_RandIter __first, _RandIter __last, random_access_iterator_tag) { @@ -45,14 +46,14 @@ __distance(_RandIter __first, _RandIter __last, random_access_iterator_tag) } template -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17 typename iterator_traits<_InputIter>::difference_type distance(_InputIter __first, _InputIter __last) { return _VSTD::__distance(__first, __last, typename iterator_traits<_InputIter>::iterator_category()); } -#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#if _LIBCPP_STD_VER > 17 // [range.iter.op.distance] @@ -75,7 +76,7 @@ struct __fn { template> _Sp> _LIBCPP_HIDE_FROM_ABI constexpr iter_difference_t<_Ip> operator()(_Ip&& __first, _Sp __last) const { - if constexpr (sized_sentinel_for<_Sp, __uncvref_t<_Ip>>) { + if constexpr (sized_sentinel_for<_Sp, __remove_cvref_t<_Ip>>) { return __last - __first; } else { return __last - decay_t<_Ip>(__first); @@ -100,7 +101,7 @@ inline namespace __cpo { } // namespace __cpo } // namespace ranges -#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#endif // _LIBCPP_STD_VER > 17 _LIBCPP_END_NAMESPACE_STD diff --git a/lib/libcxx/include/__iterator/front_insert_iterator.h b/lib/libcxx/include/__iterator/front_insert_iterator.h index 9c8ec00282..e278359d87 100644 --- a/lib/libcxx/include/__iterator/front_insert_iterator.h +++ b/lib/libcxx/include/__iterator/front_insert_iterator.h @@ -45,20 +45,21 @@ public: typedef void reference; typedef _Container container_type; - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 explicit front_insert_iterator(_Container& __x) : container(_VSTD::addressof(__x)) {} - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 front_insert_iterator& operator=(const typename _Container::value_type& __value) + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit front_insert_iterator(_Container& __x) : container(_VSTD::addressof(__x)) {} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 front_insert_iterator& operator=(const typename _Container::value_type& __value) {container->push_front(__value); return *this;} #ifndef _LIBCPP_CXX03_LANG - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 front_insert_iterator& operator=(typename _Container::value_type&& __value) + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 front_insert_iterator& operator=(typename _Container::value_type&& __value) {container->push_front(_VSTD::move(__value)); return *this;} #endif // _LIBCPP_CXX03_LANG - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 front_insert_iterator& operator*() {return *this;} - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 front_insert_iterator& operator++() {return *this;} - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 front_insert_iterator operator++(int) {return *this;} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 front_insert_iterator& operator*() {return *this;} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 front_insert_iterator& operator++() {return *this;} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 front_insert_iterator operator++(int) {return *this;} }; +_LIBCPP_CTAD_SUPPORTED_FOR_TYPE(front_insert_iterator); template -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 front_insert_iterator<_Container> front_inserter(_Container& __x) { diff --git a/lib/libcxx/include/__iterator/incrementable_traits.h b/lib/libcxx/include/__iterator/incrementable_traits.h index e6a5ed720f..3d06dc0535 100644 --- a/lib/libcxx/include/__iterator/incrementable_traits.h +++ b/lib/libcxx/include/__iterator/incrementable_traits.h @@ -10,11 +10,15 @@ #ifndef _LIBCPP___ITERATOR_INCREMENTABLE_TRAITS_H #define _LIBCPP___ITERATOR_INCREMENTABLE_TRAITS_H +#include <__concepts/arithmetic.h> #include <__config> +#include <__type_traits/conditional.h> +#include <__type_traits/is_object.h> #include <__type_traits/is_primary_template.h> -#include +#include <__type_traits/make_signed.h> +#include <__type_traits/remove_cvref.h> +#include <__utility/declval.h> #include -#include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header @@ -53,7 +57,7 @@ concept __has_integral_minus = template<__has_integral_minus _Tp> requires (!__has_member_difference_type<_Tp>) struct incrementable_traits<_Tp> { - using difference_type = make_signed_t() - declval<_Tp>())>; + using difference_type = make_signed_t() - std::declval<_Tp>())>; }; template diff --git a/lib/libcxx/include/__iterator/insert_iterator.h b/lib/libcxx/include/__iterator/insert_iterator.h index b35d8bf16a..ecaea61c61 100644 --- a/lib/libcxx/include/__iterator/insert_iterator.h +++ b/lib/libcxx/include/__iterator/insert_iterator.h @@ -24,7 +24,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD -#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#if _LIBCPP_STD_VER > 17 template using __insert_iterator_iter_t = ranges::iterator_t<_Container>; #else @@ -55,21 +55,21 @@ public: typedef void reference; typedef _Container container_type; - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator(_Container& __x, __insert_iterator_iter_t<_Container> __i) + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 insert_iterator(_Container& __x, __insert_iterator_iter_t<_Container> __i) : container(_VSTD::addressof(__x)), iter(__i) {} - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator& operator=(const typename _Container::value_type& __value) + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 insert_iterator& operator=(const typename _Container::value_type& __value) {iter = container->insert(iter, __value); ++iter; return *this;} #ifndef _LIBCPP_CXX03_LANG - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator& operator=(typename _Container::value_type&& __value) + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 insert_iterator& operator=(typename _Container::value_type&& __value) {iter = container->insert(iter, _VSTD::move(__value)); ++iter; return *this;} #endif // _LIBCPP_CXX03_LANG - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator& operator*() {return *this;} - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator& operator++() {return *this;} - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator& operator++(int) {return *this;} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 insert_iterator& operator*() {return *this;} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 insert_iterator& operator++() {return *this;} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 insert_iterator& operator++(int) {return *this;} }; template -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 insert_iterator<_Container> inserter(_Container& __x, __insert_iterator_iter_t<_Container> __i) { diff --git a/lib/libcxx/include/__iterator/iter_move.h b/lib/libcxx/include/__iterator/iter_move.h index d8240ab9c2..a7d9413fb8 100644 --- a/lib/libcxx/include/__iterator/iter_move.h +++ b/lib/libcxx/include/__iterator/iter_move.h @@ -13,9 +13,11 @@ #include <__concepts/class_or_enum.h> #include <__config> #include <__iterator/iterator_traits.h> +#include <__type_traits/is_reference.h> +#include <__type_traits/remove_cvref.h> +#include <__utility/declval.h> #include <__utility/forward.h> #include <__utility/move.h> -#include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header @@ -36,6 +38,7 @@ template concept __unqualified_iter_move = __class_or_enum> && requires (_Tp&& __t) { + // NOLINTNEXTLINE(libcpp-robust-against-adl) iter_swap ADL calls should only be made through ranges::iter_swap iter_move(std::forward<_Tp>(__t)); }; @@ -59,6 +62,7 @@ concept __just_deref = // [iterator.cust.move] struct __fn { + // NOLINTBEGIN(libcpp-robust-against-adl) iter_move ADL calls should only be made through ranges::iter_move template requires __unqualified_iter_move<_Ip> [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr decltype(auto) operator()(_Ip&& __i) const @@ -66,6 +70,7 @@ struct __fn { { return iter_move(std::forward<_Ip>(__i)); } + // NOLINTEND(libcpp-robust-against-adl) template requires __move_deref<_Ip> @@ -90,7 +95,7 @@ inline namespace __cpo { template<__dereferenceable _Tp> requires requires(_Tp& __t) { { ranges::iter_move(__t) } -> __can_reference; } -using iter_rvalue_reference_t = decltype(ranges::iter_move(declval<_Tp&>())); +using iter_rvalue_reference_t = decltype(ranges::iter_move(std::declval<_Tp&>())); #endif // _LIBCPP_STD_VER > 17 diff --git a/lib/libcxx/include/__iterator/iter_swap.h b/lib/libcxx/include/__iterator/iter_swap.h index 9e06464c36..d4c0dca1f6 100644 --- a/lib/libcxx/include/__iterator/iter_swap.h +++ b/lib/libcxx/include/__iterator/iter_swap.h @@ -6,18 +6,21 @@ // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// + #ifndef _LIBCPP___ITERATOR_ITER_SWAP_H #define _LIBCPP___ITERATOR_ITER_SWAP_H +#include <__concepts/class_or_enum.h> +#include <__concepts/swappable.h> #include <__config> #include <__iterator/concepts.h> #include <__iterator/iter_move.h> #include <__iterator/iterator_traits.h> #include <__iterator/readable_traits.h> +#include <__type_traits/remove_cvref.h> +#include <__utility/declval.h> #include <__utility/forward.h> #include <__utility/move.h> -#include -#include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header @@ -38,6 +41,7 @@ namespace __iter_swap { concept __unqualified_iter_swap = (__class_or_enum> || __class_or_enum>) && requires (_T1&& __x, _T2&& __y) { + // NOLINTNEXTLINE(libcpp-robust-against-adl) iter_swap ADL calls should only be made through ranges::iter_swap iter_swap(_VSTD::forward<_T1>(__x), _VSTD::forward<_T2>(__y)); }; @@ -46,7 +50,9 @@ namespace __iter_swap { indirectly_readable<_T1> && indirectly_readable<_T2> && swappable_with, iter_reference_t<_T2>>; + struct __fn { + // NOLINTBEGIN(libcpp-robust-against-adl) iter_swap ADL calls should only be made through ranges::iter_swap template requires __unqualified_iter_swap<_T1, _T2> _LIBCPP_HIDE_FROM_ABI @@ -55,6 +61,7 @@ namespace __iter_swap { { (void)iter_swap(_VSTD::forward<_T1>(__x), _VSTD::forward<_T2>(__y)); } + // NOLINTEND(libcpp-robust-against-adl) template requires (!__unqualified_iter_swap<_T1, _T2>) && @@ -75,7 +82,7 @@ namespace __iter_swap { constexpr void operator()(_T1&& __x, _T2&& __y) const noexcept(noexcept(iter_value_t<_T2>(ranges::iter_move(__y))) && noexcept(*__y = ranges::iter_move(__x)) && - noexcept(*_VSTD::forward<_T1>(__x) = declval>())) + noexcept(*_VSTD::forward<_T1>(__x) = std::declval>())) { iter_value_t<_T2> __old(ranges::iter_move(__y)); *__y = ranges::iter_move(__x); diff --git a/lib/libcxx/include/__iterator/iterator_traits.h b/lib/libcxx/include/__iterator/iterator_traits.h index 0cc64adc0d..c9d8944bfe 100644 --- a/lib/libcxx/include/__iterator/iterator_traits.h +++ b/lib/libcxx/include/__iterator/iterator_traits.h @@ -10,12 +10,32 @@ #ifndef _LIBCPP___ITERATOR_ITERATOR_TRAITS_H #define _LIBCPP___ITERATOR_ITERATOR_TRAITS_H +#include <__concepts/arithmetic.h> +#include <__concepts/constructible.h> +#include <__concepts/convertible_to.h> +#include <__concepts/copyable.h> +#include <__concepts/equality_comparable.h> +#include <__concepts/same_as.h> +#include <__concepts/totally_ordered.h> #include <__config> +#include <__fwd/pair.h> #include <__iterator/incrementable_traits.h> #include <__iterator/readable_traits.h> -#include +#include <__type_traits/add_const.h> +#include <__type_traits/common_reference.h> +#include <__type_traits/conditional.h> +#include <__type_traits/disjunction.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_valid_expansion.h> +#include <__type_traits/remove_const.h> +#include <__type_traits/remove_cv.h> +#include <__type_traits/remove_cvref.h> +#include <__type_traits/void_t.h> +#include <__utility/declval.h> #include -#include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header @@ -40,7 +60,7 @@ concept __dereferenceable = requires(_Tp& __t) { // [iterator.traits] template<__dereferenceable _Tp> -using iter_reference_t = decltype(*declval<_Tp&>()); +using iter_reference_t = decltype(*std::declval<_Tp&>()); #endif // _LIBCPP_STD_VER > 17 @@ -107,11 +127,11 @@ struct __has_iterator_typedefs { private: template static false_type __test(...); - template static true_type __test(typename __void_t::type* = 0, - typename __void_t::type* = 0, - typename __void_t::type* = 0, - typename __void_t::type* = 0, - typename __void_t::type* = 0); + template static true_type __test(__void_t* = nullptr, + __void_t* = nullptr, + __void_t* = nullptr, + __void_t* = nullptr, + __void_t* = nullptr); public: static const bool value = decltype(__test<_Tp>(0,0,0,0,0))::value; }; @@ -253,7 +273,7 @@ struct __iterator_traits_member_pointer_or_arrow_or_void<_Ip> { using type = typ template requires requires(_Ip& __i) { __i.operator->(); } && (!__has_member_pointer<_Ip>) struct __iterator_traits_member_pointer_or_arrow_or_void<_Ip> { - using type = decltype(declval<_Ip&>().operator->()); + using type = decltype(std::declval<_Ip&>().operator->()); }; // Otherwise, `reference` names `iter-reference-t`. @@ -407,7 +427,7 @@ requires is_object_v<_Tp> struct _LIBCPP_TEMPLATE_VIS iterator_traits<_Tp*> { typedef ptrdiff_t difference_type; - typedef typename remove_cv<_Tp>::type value_type; + typedef __remove_cv_t<_Tp> value_type; typedef _Tp* pointer; typedef _Tp& reference; typedef random_access_iterator_tag iterator_category; @@ -492,7 +512,7 @@ template using __iter_value_type = typename iterator_traits<_InputIterator>::value_type; template -using __iter_key_type = typename remove_const::value_type::first_type>::type; +using __iter_key_type = __remove_const_t::value_type::first_type>; template using __iter_mapped_type = typename iterator_traits<_InputIterator>::value_type::second_type; diff --git a/lib/libcxx/include/__iterator/iterator_with_data.h b/lib/libcxx/include/__iterator/iterator_with_data.h new file mode 100644 index 0000000000..06c2fa699c --- /dev/null +++ b/lib/libcxx/include/__iterator/iterator_with_data.h @@ -0,0 +1,100 @@ +//===----------------------------------------------------------------------===// +// +// 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___ITERATOR_ITERATOR_WITH_DATA_H +#define _LIBCPP___ITERATOR_ITERATOR_WITH_DATA_H + +#include <__compare/compare_three_way_result.h> +#include <__compare/three_way_comparable.h> +#include <__config> +#include <__iterator/concepts.h> +#include <__iterator/incrementable_traits.h> +#include <__iterator/iter_move.h> +#include <__iterator/iter_swap.h> +#include <__iterator/iterator_traits.h> +#include <__iterator/readable_traits.h> +#include <__utility/move.h> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +#if _LIBCPP_STD_VER >= 20 + +_LIBCPP_BEGIN_NAMESPACE_STD + +template +class __iterator_with_data { + _Iterator __iter_{}; + _Data __data_{}; + +public: + using value_type = iter_value_t<_Iterator>; + using difference_type = iter_difference_t<_Iterator>; + + _LIBCPP_HIDE_FROM_ABI __iterator_with_data() = default; + + constexpr _LIBCPP_HIDE_FROM_ABI __iterator_with_data(_Iterator __iter, _Data __data) + : __iter_(std::move(__iter)), __data_(std::move(__data)) {} + + constexpr _LIBCPP_HIDE_FROM_ABI _Iterator __get_iter() const { return __iter_; } + + constexpr _LIBCPP_HIDE_FROM_ABI _Data __get_data() && { return std::move(__data_); } + + friend constexpr _LIBCPP_HIDE_FROM_ABI bool + operator==(const __iterator_with_data& __lhs, const __iterator_with_data& __rhs) { + return __lhs.__iter_ == __rhs.__iter_; + } + + constexpr _LIBCPP_HIDE_FROM_ABI __iterator_with_data& operator++() { + ++__iter_; + return *this; + } + + constexpr _LIBCPP_HIDE_FROM_ABI __iterator_with_data operator++(int) { + auto __tmp = *this; + __iter_++; + return __tmp; + } + + constexpr _LIBCPP_HIDE_FROM_ABI __iterator_with_data& operator--() + requires bidirectional_iterator<_Iterator> + { + --__iter_; + return *this; + } + + constexpr _LIBCPP_HIDE_FROM_ABI __iterator_with_data operator--(int) + requires bidirectional_iterator<_Iterator> + { + auto __tmp = *this; + --__iter_; + return __tmp; + } + + constexpr _LIBCPP_HIDE_FROM_ABI iter_reference_t<_Iterator> operator*() const { return *__iter_; } + + _LIBCPP_HIDE_FROM_ABI friend constexpr iter_rvalue_reference_t<_Iterator> + iter_move(const __iterator_with_data& __iter) noexcept(noexcept(ranges::iter_move(__iter.__iter_))) { + return ranges::iter_move(__iter.__iter_); + } + + _LIBCPP_HIDE_FROM_ABI friend constexpr void + iter_swap(const __iterator_with_data& __lhs, + const __iterator_with_data& __rhs) noexcept(noexcept(ranges::iter_swap(__lhs.__iter_, __rhs.__iter_))) + requires indirectly_swappable<_Iterator> + { + return ranges::iter_swap(__lhs.__data_, __rhs.__iter_); + } +}; + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_STD_VER >= 20 + +#endif // _LIBCPP___ITERATOR_ITERATOR_WITH_DATA_H diff --git a/lib/libcxx/include/__iterator/move_iterator.h b/lib/libcxx/include/__iterator/move_iterator.h index 6be9f216db..fa806dbaf7 100644 --- a/lib/libcxx/include/__iterator/move_iterator.h +++ b/lib/libcxx/include/__iterator/move_iterator.h @@ -24,8 +24,16 @@ #include <__iterator/iterator_traits.h> #include <__iterator/move_sentinel.h> #include <__iterator/readable_traits.h> +#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> +#include <__type_traits/remove_reference.h> +#include <__utility/declval.h> #include <__utility/move.h> -#include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header @@ -49,7 +57,7 @@ struct __move_iter_category_base<_Iter> { template concept __move_iter_comparable = requires { - { declval() == declval<_Sent>() } -> convertible_to; + { std::declval() == std::declval<_Sent>() } -> convertible_to; }; #endif // _LIBCPP_STD_VER > 17 @@ -82,18 +90,18 @@ public: typedef typename iterator_traits::reference __reference; typedef typename conditional< is_reference<__reference>::value, - typename remove_reference<__reference>::type&&, + __libcpp_remove_reference_t<__reference>&&, __reference >::type reference; #endif // _LIBCPP_STD_VER > 17 - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX14 + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 explicit move_iterator(_Iter __i) : __current_(std::move(__i)) {} - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX14 + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 move_iterator& operator++() { ++__current_; return *this; } - _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX14 + _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 pointer operator->() const { return __current_; } #if _LIBCPP_STD_VER > 17 @@ -133,13 +141,13 @@ public: _LIBCPP_HIDE_FROM_ABI constexpr void operator++(int) { ++__current_; } #else - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX14 + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 move_iterator() : __current_() {} template ::value && is_convertible::value > > - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX14 + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 move_iterator(const move_iterator<_Up>& __u) : __current_(__u.base()) {} template ::value && is_assignable<_Iter&, const _Up&>::value > > - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX14 + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 move_iterator& operator=(const move_iterator<_Up>& __u) { __current_ = __u.base(); return *this; } - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX14 + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 _Iter base() const { return __current_; } - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX14 + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 reference operator*() const { return static_cast(*__current_); } - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX14 + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 reference operator[](difference_type __n) const { return static_cast(__current_[__n]); } - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX14 + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 move_iterator operator++(int) { move_iterator __tmp(*this); ++__current_; return __tmp; } #endif // _LIBCPP_STD_VER > 17 - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX14 + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 move_iterator& operator--() { --__current_; return *this; } - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX14 + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 move_iterator operator--(int) { move_iterator __tmp(*this); --__current_; return __tmp; } - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX14 + _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_AFTER_CXX14 + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 move_iterator& operator+=(difference_type __n) { __current_ += __n; return *this; } - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX14 + _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_AFTER_CXX14 + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 move_iterator& operator-=(difference_type __n) { __current_ -= __n; return *this; } #if _LIBCPP_STD_VER > 17 @@ -222,9 +230,10 @@ private: _Iter __current_; }; +_LIBCPP_CTAD_SUPPORTED_FOR_TYPE(move_iterator); template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX14 +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 bool operator==(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y) { return __x.base() == __y.base(); @@ -232,7 +241,7 @@ bool operator==(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& _ #if _LIBCPP_STD_VER <= 17 template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX14 +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 bool operator!=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y) { return __x.base() != __y.base(); @@ -240,28 +249,28 @@ bool operator!=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& _ #endif // _LIBCPP_STD_VER <= 17 template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX14 +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 bool operator<(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y) { return __x.base() < __y.base(); } template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX14 +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 bool operator>(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y) { return __x.base() > __y.base(); } template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX14 +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 bool operator<=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y) { return __x.base() <= __y.base(); } template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX14 +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 bool operator>=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y) { return __x.base() >= __y.base(); @@ -279,7 +288,7 @@ auto operator<=>(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& #ifndef _LIBCPP_CXX03_LANG template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX14 +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()) { @@ -305,7 +314,7 @@ move_iterator<_Iter> operator+(iter_difference_t<_Iter> __n, const move_iterator } #else template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX14 +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) { @@ -314,7 +323,7 @@ operator+(typename move_iterator<_Iter>::difference_type __n, const move_iterato #endif // _LIBCPP_STD_VER > 17 template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX14 +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 move_iterator<_Iter> make_move_iterator(_Iter __i) { diff --git a/lib/libcxx/include/__iterator/move_sentinel.h b/lib/libcxx/include/__iterator/move_sentinel.h index 5adf877b34..0d7336a1dc 100644 --- a/lib/libcxx/include/__iterator/move_sentinel.h +++ b/lib/libcxx/include/__iterator/move_sentinel.h @@ -50,6 +50,8 @@ private: _Sent __last_ = _Sent(); }; +_LIBCPP_CTAD_SUPPORTED_FOR_TYPE(move_sentinel); + #endif // _LIBCPP_STD_VER > 17 _LIBCPP_END_NAMESPACE_STD diff --git a/lib/libcxx/include/__iterator/next.h b/lib/libcxx/include/__iterator/next.h index 5363d6d58e..49970ae248 100644 --- a/lib/libcxx/include/__iterator/next.h +++ b/lib/libcxx/include/__iterator/next.h @@ -16,7 +16,7 @@ #include <__iterator/concepts.h> #include <__iterator/incrementable_traits.h> #include <__iterator/iterator_traits.h> -#include +#include <__type_traits/enable_if.h> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header @@ -25,7 +25,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD template -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17 typename enable_if<__is_cpp17_input_iterator<_InputIter>::value, _InputIter>::type next(_InputIter __x, typename iterator_traits<_InputIter>::difference_type __n = 1) { _LIBCPP_ASSERT(__n >= 0 || __is_cpp17_bidirectional_iterator<_InputIter>::value, @@ -35,7 +35,7 @@ inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 return __x; } -#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#if _LIBCPP_STD_VER > 17 // [range.iter.op.next] @@ -77,7 +77,7 @@ inline namespace __cpo { } // namespace __cpo } // namespace ranges -#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#endif // _LIBCPP_STD_VER > 17 _LIBCPP_END_NAMESPACE_STD diff --git a/lib/libcxx/include/__iterator/ostreambuf_iterator.h b/lib/libcxx/include/__iterator/ostreambuf_iterator.h index 6da7598ed2..b75f7b6e84 100644 --- a/lib/libcxx/include/__iterator/ostreambuf_iterator.h +++ b/lib/libcxx/include/__iterator/ostreambuf_iterator.h @@ -65,7 +65,7 @@ public: template friend - _LIBCPP_HIDDEN + _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, diff --git a/lib/libcxx/include/__iterator/prev.h b/lib/libcxx/include/__iterator/prev.h index eb997b91ba..af1e1bab11 100644 --- a/lib/libcxx/include/__iterator/prev.h +++ b/lib/libcxx/include/__iterator/prev.h @@ -16,7 +16,7 @@ #include <__iterator/concepts.h> #include <__iterator/incrementable_traits.h> #include <__iterator/iterator_traits.h> -#include +#include <__type_traits/enable_if.h> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header @@ -25,7 +25,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD template -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17 typename enable_if<__is_cpp17_input_iterator<_InputIter>::value, _InputIter>::type prev(_InputIter __x, typename iterator_traits<_InputIter>::difference_type __n = 1) { _LIBCPP_ASSERT(__n <= 0 || __is_cpp17_bidirectional_iterator<_InputIter>::value, @@ -34,7 +34,7 @@ inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 return __x; } -#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#if _LIBCPP_STD_VER > 17 // [range.iter.op.prev] @@ -70,7 +70,7 @@ inline namespace __cpo { } // namespace __cpo } // namespace ranges -#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) +#endif // _LIBCPP_STD_VER > 17 _LIBCPP_END_NAMESPACE_STD diff --git a/lib/libcxx/include/__iterator/projected.h b/lib/libcxx/include/__iterator/projected.h index 53526bd8e7..19c076b2e5 100644 --- a/lib/libcxx/include/__iterator/projected.h +++ b/lib/libcxx/include/__iterator/projected.h @@ -6,13 +6,14 @@ // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// + #ifndef _LIBCPP___ITERATOR_PROJECTED_H #define _LIBCPP___ITERATOR_PROJECTED_H #include <__config> #include <__iterator/concepts.h> #include <__iterator/incrementable_traits.h> -#include +#include <__type_traits/remove_cvref.h> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header diff --git a/lib/libcxx/include/__iterator/readable_traits.h b/lib/libcxx/include/__iterator/readable_traits.h index 500b46ac14..8f17757c5a 100644 --- a/lib/libcxx/include/__iterator/readable_traits.h +++ b/lib/libcxx/include/__iterator/readable_traits.h @@ -10,9 +10,15 @@ #ifndef _LIBCPP___ITERATOR_READABLE_TRAITS_H #define _LIBCPP___ITERATOR_READABLE_TRAITS_H +#include <__concepts/same_as.h> #include <__config> -#include -#include +#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> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header diff --git a/lib/libcxx/include/__iterator/reverse_access.h b/lib/libcxx/include/__iterator/reverse_access.h index 40c266378d..79b599c47c 100644 --- a/lib/libcxx/include/__iterator/reverse_access.h +++ b/lib/libcxx/include/__iterator/reverse_access.h @@ -24,70 +24,70 @@ _LIBCPP_BEGIN_NAMESPACE_STD #if _LIBCPP_STD_VER > 11 template -_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17 reverse_iterator<_Tp*> rbegin(_Tp (&__array)[_Np]) { return reverse_iterator<_Tp*>(__array + _Np); } template -_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17 reverse_iterator<_Tp*> rend(_Tp (&__array)[_Np]) { return reverse_iterator<_Tp*>(__array); } template -_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17 reverse_iterator rbegin(initializer_list<_Ep> __il) { return reverse_iterator(__il.end()); } template -_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17 reverse_iterator rend(initializer_list<_Ep> __il) { return reverse_iterator(__il.begin()); } template -_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17 auto rbegin(_Cp& __c) -> decltype(__c.rbegin()) { return __c.rbegin(); } template -_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17 auto rbegin(const _Cp& __c) -> decltype(__c.rbegin()) { return __c.rbegin(); } template -_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17 auto rend(_Cp& __c) -> decltype(__c.rend()) { return __c.rend(); } template -_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17 auto rend(const _Cp& __c) -> decltype(__c.rend()) { return __c.rend(); } template -_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17 auto crbegin(const _Cp& __c) -> decltype(_VSTD::rbegin(__c)) { return _VSTD::rbegin(__c); } template -_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17 auto crend(const _Cp& __c) -> decltype(_VSTD::rend(__c)) { return _VSTD::rend(__c); diff --git a/lib/libcxx/include/__iterator/reverse_iterator.h b/lib/libcxx/include/__iterator/reverse_iterator.h index 7b002205f3..f272e03c17 100644 --- a/lib/libcxx/include/__iterator/reverse_iterator.h +++ b/lib/libcxx/include/__iterator/reverse_iterator.h @@ -25,12 +25,20 @@ #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> +#include <__type_traits/is_convertible.h> +#include <__type_traits/is_nothrow_copy_constructible.h> +#include <__type_traits/is_pointer.h> +#include <__type_traits/is_same.h> +#include <__utility/declval.h> #include <__utility/move.h> -#include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header @@ -52,7 +60,7 @@ class _LIBCPP_TEMPLATE_VIS reverse_iterator _LIBCPP_SUPPRESS_DEPRECATED_POP private: #ifndef _LIBCPP_ABI_NO_ITERATOR_BASES - _Iter __t; // no longer used as of LWG #2360, not removed due to ABI break + _Iter __t_; // no longer used as of LWG #2360, not removed due to ABI break #endif #if _LIBCPP_STD_VER > 17 @@ -81,18 +89,18 @@ public: #endif #ifndef _LIBCPP_ABI_NO_ITERATOR_BASES - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 - reverse_iterator() : __t(), current() {} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17 + reverse_iterator() : __t_(), current() {} - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 - explicit reverse_iterator(_Iter __x) : __t(__x), current(__x) {} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17 + explicit reverse_iterator(_Iter __x) : __t_(__x), current(__x) {} template ::value && is_convertible<_Up const&, _Iter>::value > > - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17 reverse_iterator(const reverse_iterator<_Up>& __u) - : __t(__u.base()), current(__u.base()) + : __t_(__u.base()), current(__u.base()) { } template ::value && is_assignable<_Iter&, _Up const&>::value > > - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17 reverse_iterator& operator=(const reverse_iterator<_Up>& __u) { - __t = current = __u.base(); + __t_ = current = __u.base(); return *this; } #else - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17 reverse_iterator() : current() {} - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17 explicit reverse_iterator(_Iter __x) : current(__x) {} template ::value && is_convertible<_Up const&, _Iter>::value > > - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17 reverse_iterator(const reverse_iterator<_Up>& __u) : current(__u.base()) { } @@ -125,15 +133,15 @@ public: is_convertible<_Up const&, _Iter>::value && is_assignable<_Iter&, _Up const&>::value > > - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17 reverse_iterator& operator=(const reverse_iterator<_Up>& __u) { current = __u.base(); return *this; } #endif - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17 _Iter base() const {return current;} - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17 reference operator*() const {_Iter __tmp = current; return *--__tmp;} #if _LIBCPP_STD_VER > 17 @@ -148,36 +156,36 @@ public: } } #else - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17 pointer operator->() const { return std::addressof(operator*()); } #endif // _LIBCPP_STD_VER > 17 - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17 reverse_iterator& operator++() {--current; return *this;} - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17 reverse_iterator operator++(int) {reverse_iterator __tmp(*this); --current; return __tmp;} - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17 reverse_iterator& operator--() {++current; return *this;} - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17 reverse_iterator operator--(int) {reverse_iterator __tmp(*this); ++current; return __tmp;} - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17 reverse_iterator operator+(difference_type __n) const {return reverse_iterator(current - __n);} - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17 reverse_iterator& operator+=(difference_type __n) {current -= __n; return *this;} - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17 reverse_iterator operator-(difference_type __n) const {return reverse_iterator(current + __n);} - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17 reverse_iterator& operator-=(difference_type __n) {current += __n; return *this;} - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17 reference operator[](difference_type __n) const {return *(*this + __n);} #if _LIBCPP_STD_VER > 17 _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(--declval<_Iter&>()))) { + noexcept(ranges::iter_move(--std::declval<_Iter&>()))) { auto __tmp = __i.base(); return ranges::iter_move(--__tmp); } @@ -187,7 +195,7 @@ public: void iter_swap(const reverse_iterator& __x, const reverse_iterator<_Iter2>& __y) noexcept(is_nothrow_copy_constructible_v<_Iter> && is_nothrow_copy_constructible_v<_Iter2> && - noexcept(ranges::iter_swap(--declval<_Iter&>(), --declval<_Iter2&>()))) { + noexcept(ranges::iter_swap(--std::declval<_Iter&>(), --std::declval<_Iter2&>()))) { auto __xtmp = __x.base(); auto __ytmp = __y.base(); ranges::iter_swap(--__xtmp, --__ytmp); @@ -195,14 +203,8 @@ public: #endif // _LIBCPP_STD_VER > 17 }; -template -struct __is_reverse_iterator : false_type {}; - -template -struct __is_reverse_iterator > : true_type {}; - template -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17 bool operator==(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y) #if _LIBCPP_STD_VER > 17 @@ -215,7 +217,7 @@ operator==(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& } template -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17 bool operator<(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y) #if _LIBCPP_STD_VER > 17 @@ -228,7 +230,7 @@ operator<(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& _ } template -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17 bool operator!=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y) #if _LIBCPP_STD_VER > 17 @@ -241,7 +243,7 @@ operator!=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& } template -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17 bool operator>(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y) #if _LIBCPP_STD_VER > 17 @@ -254,7 +256,7 @@ operator>(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& _ } template -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17 bool operator>=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y) #if _LIBCPP_STD_VER > 17 @@ -267,7 +269,7 @@ operator>=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& } template -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17 bool operator<=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y) #if _LIBCPP_STD_VER > 17 @@ -291,7 +293,7 @@ operator<=>(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& #ifndef _LIBCPP_CXX03_LANG template -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17 auto operator-(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y) -> decltype(__y.base() - __x.base()) @@ -309,7 +311,7 @@ operator-(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& _ #endif template -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17 reverse_iterator<_Iter> operator+(typename reverse_iterator<_Iter>::difference_type __n, const reverse_iterator<_Iter>& __x) { @@ -324,7 +326,7 @@ inline constexpr bool disable_sized_sentinel_for, rever #if _LIBCPP_STD_VER > 11 template -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17 reverse_iterator<_Iter> make_reverse_iterator(_Iter __i) { return reverse_iterator<_Iter>(__i); @@ -394,7 +396,7 @@ public: _LIBCPP_HIDE_FROM_ABI friend constexpr iter_rvalue_reference_t<_Iter> iter_move(const __unconstrained_reverse_iterator& __i) noexcept(is_nothrow_copy_constructible_v<_Iter> && - noexcept(ranges::iter_move(--declval<_Iter&>()))) { + noexcept(ranges::iter_move(--std::declval<_Iter&>()))) { auto __tmp = __i.base(); return ranges::iter_move(--__tmp); } @@ -478,9 +480,6 @@ public: } }; -template -struct __is_reverse_iterator<__unconstrained_reverse_iterator<_Iter>> : true_type {}; - #endif // _LIBCPP_STD_VER <= 17 template