From f5228db89f62b5559e6f2129509a2b08400c987f Mon Sep 17 00:00:00 2001 From: Hannah Shi Date: Thu, 31 Oct 2024 22:27:57 -0700 Subject: [PATCH 1/6] sync abseil-cpp 20240722.0 code --- BUILD.bazel | 12 +- CMake/AbseilDll.cmake | 103 +- CMake/AbseilHelpers.cmake | 19 +- CMake/Googletest/CMakeLists.txt.in | 2 +- CMake/README.md | 4 +- CMake/install_test_project/CMakeLists.txt | 2 +- CMake/install_test_project/test.sh | 9 +- CMakeLists.txt | 65 +- MODULE.bazel | 9 +- PrivacyInfo.xcprivacy | 16 +- WORKSPACE | 32 +- WORKSPACE.bzlmod | 19 + absl/BUILD.bazel | 11 - absl/CMakeLists.txt | 4 +- absl/abseil.podspec.gen.py | 13 +- absl/algorithm/BUILD.bazel | 2 + absl/algorithm/CMakeLists.txt | 2 + absl/algorithm/algorithm_test.cc | 50 + absl/algorithm/container.h | 75 +- absl/algorithm/container_test.cc | 1210 ++++++ absl/base/BUILD.bazel | 71 +- absl/base/CMakeLists.txt | 32 + absl/base/attributes.h | 84 + absl/base/bit_cast_test.cc | 109 + absl/base/c_header_test.c | 30 + absl/base/call_once_test.cc | 107 + absl/base/config.h | 85 +- absl/base/config_test.cc | 60 + absl/base/dynamic_annotations.h | 16 - absl/base/exception_safety_testing_test.cc | 962 +++++ absl/base/inline_variable_test.cc | 64 + absl/base/internal/atomic_hook_test.cc | 97 + absl/base/internal/cmake_thread_test.cc | 22 + absl/base/internal/endian_test.cc | 263 ++ absl/base/internal/errno_saver_test.cc | 45 + absl/base/internal/fast_type_id_test.cc | 123 + absl/base/internal/low_level_alloc_test.cc | 180 + absl/base/internal/nullability_impl.h | 4 +- absl/base/internal/poison.cc | 84 + absl/base/internal/poison.h | 59 + absl/base/internal/poison_test.cc | 41 + absl/base/internal/scoped_set_env_test.cc | 99 + absl/base/internal/spinlock.h | 16 +- absl/base/internal/spinlock_benchmark.cc | 80 + absl/base/internal/strerror_benchmark.cc | 29 + absl/base/internal/strerror_test.cc | 88 + absl/base/internal/sysinfo_test.cc | 88 + .../internal/thread_identity_benchmark.cc | 38 + absl/base/internal/thread_identity_test.cc | 129 + absl/base/internal/unique_small_name_test.cc | 77 + absl/base/internal/unscaledcycleclock.cc | 12 - .../base/internal/unscaledcycleclock_config.h | 8 +- absl/base/invoke_test.cc | 331 ++ absl/base/log_severity_test.cc | 251 ++ absl/base/macros.h | 48 + absl/base/no_destructor.h | 75 +- absl/base/no_destructor_benchmark.cc | 165 + absl/base/no_destructor_test.cc | 209 + absl/base/nullability.h | 40 +- absl/base/nullability_test.cc | 129 + absl/base/optimization.h | 11 + absl/base/optimization_test.cc | 129 + absl/base/options.h | 2 +- absl/base/prefetch.h | 2 +- absl/base/prefetch_test.cc | 64 + absl/base/raw_logging_test.cc | 79 + absl/base/throw_delegate_test.cc | 175 + absl/cleanup/cleanup_test.cc | 311 ++ absl/container/BUILD.bazel | 92 +- absl/container/CMakeLists.txt | 54 +- absl/container/btree_benchmark.cc | 764 ++++ absl/container/btree_map.h | 6 +- absl/container/btree_set.h | 7 +- absl/container/btree_test.cc | 3461 ++++++++++++++++ absl/container/fixed_array_benchmark.cc | 67 + .../fixed_array_exception_safety_test.cc | 201 + absl/container/fixed_array_test.cc | 853 ++++ absl/container/flat_hash_map.h | 80 +- absl/container/flat_hash_map_test.cc | 458 +++ absl/container/flat_hash_set.h | 66 +- absl/container/flat_hash_set_test.cc | 297 ++ absl/container/hash_container_defaults.h | 45 + absl/container/inlined_vector.h | 13 + absl/container/inlined_vector_benchmark.cc | 829 ++++ .../inlined_vector_exception_safety_test.cc | 508 +++ absl/container/inlined_vector_test.cc | 2208 ++++++++++ absl/container/internal/btree.h | 51 +- .../container/internal/common_policy_traits.h | 31 +- .../internal/common_policy_traits_test.cc | 157 + absl/container/internal/compressed_tuple.h | 31 +- .../internal/compressed_tuple_test.cc | 482 +++ absl/container/internal/container_memory.h | 35 +- .../internal/container_memory_test.cc | 318 ++ .../internal/hash_function_defaults.h | 69 +- .../internal/hash_function_defaults_test.cc | 684 ++++ absl/container/internal/hash_policy_testing.h | 3 +- .../internal/hash_policy_testing_test.cc | 45 + absl/container/internal/hash_policy_traits.h | 50 + .../internal/hash_policy_traits_test.cc | 144 + absl/container/internal/hashtablez_sampler.cc | 29 +- absl/container/internal/hashtablez_sampler.h | 34 +- .../internal/hashtablez_sampler_test.cc | 518 +++ absl/container/internal/inlined_vector.h | 74 +- absl/container/internal/layout.h | 264 +- absl/container/internal/layout_benchmark.cc | 295 ++ absl/container/internal/layout_test.cc | 2034 ++++++++++ .../internal/node_slot_policy_test.cc | 71 + absl/container/internal/raw_hash_map.h | 14 +- absl/container/internal/raw_hash_set.cc | 405 +- absl/container/internal/raw_hash_set.h | 1757 +++++--- .../internal/raw_hash_set_allocator_test.cc | 520 +++ .../internal/raw_hash_set_benchmark.cc | 687 ++++ .../internal/raw_hash_set_probe_benchmark.cc | 597 +++ absl/container/internal/raw_hash_set_test.cc | 3600 +++++++++++++++++ .../internal/test_instance_tracker_test.cc | 184 + absl/container/internal/unordered_map_test.cc | 50 + absl/container/internal/unordered_set_test.cc | 41 + absl/container/node_hash_map.h | 71 +- absl/container/node_hash_map_test.cc | 351 ++ absl/container/node_hash_set.h | 64 +- absl/container/node_hash_set_test.cc | 189 + absl/container/sample_element_size_test.cc | 123 + absl/copts/AbseilConfigureCopts.cmake | 4 +- absl/copts/GENERATED_AbseilCopts.cmake | 6 + absl/copts/GENERATED_copts.bzl | 6 + absl/copts/copts.py | 3 + absl/crc/BUILD.bazel | 12 +- absl/crc/CMakeLists.txt | 1 + absl/crc/crc32c_benchmark.cc | 183 + absl/crc/crc32c_test.cc | 227 ++ .../internal/crc32_x86_arm_combined_simd.h | 36 +- absl/crc/internal/crc_cord_state.cc | 7 +- absl/crc/internal/crc_cord_state_test.cc | 124 + absl/crc/internal/crc_memcpy_fallback.cc | 3 +- absl/crc/internal/crc_memcpy_test.cc | 177 + .../internal/crc_memcpy_x86_arm_combined.cc | 20 +- absl/crc/internal/crc_non_temporal_memcpy.cc | 2 +- absl/crc/internal/crc_x86_arm_combined.cc | 18 +- absl/crc/internal/non_temporal_memcpy.h | 35 +- absl/crc/internal/non_temporal_memcpy_test.cc | 88 + absl/debugging/BUILD.bazel | 103 + absl/debugging/CMakeLists.txt | 116 +- absl/debugging/failure_signal_handler.h | 2 +- absl/debugging/failure_signal_handler_test.cc | 166 + .../internal/bounded_utf8_length_sequence.h | 126 + .../bounded_utf8_length_sequence_test.cc | 126 + .../internal/decode_rust_punycode.cc | 258 ++ .../debugging/internal/decode_rust_punycode.h | 55 + .../internal/decode_rust_punycode_test.cc | 606 +++ absl/debugging/internal/demangle.cc | 1143 +++++- absl/debugging/internal/demangle.h | 3 + absl/debugging/internal/demangle_rust.cc | 925 +++++ absl/debugging/internal/demangle_rust.h | 42 + absl/debugging/internal/demangle_rust_test.cc | 584 +++ absl/debugging/internal/demangle_test.cc | 2042 ++++++++++ absl/debugging/internal/elf_mem_image.cc | 59 +- absl/debugging/internal/elf_mem_image.h | 15 +- .../internal/stack_consumption_test.cc | 50 + .../internal/stacktrace_aarch64-inl.inc | 17 +- .../debugging/internal/utf8_for_code_point.cc | 70 + absl/debugging/internal/utf8_for_code_point.h | 47 + .../internal/utf8_for_code_point_test.cc | 175 + absl/debugging/leak_check_fail_test.cc | 41 + absl/debugging/leak_check_test.cc | 41 + absl/debugging/stacktrace_benchmark.cc | 55 + absl/debugging/stacktrace_test.cc | 47 + absl/debugging/symbolize_test.cc | 638 +++ absl/flags/BUILD.bazel | 13 +- absl/flags/CMakeLists.txt | 8 +- absl/flags/commandlineflag.h | 11 + absl/flags/commandlineflag_test.cc | 236 ++ absl/flags/config_test.cc | 61 + absl/flags/flag.h | 2 + absl/flags/flag_benchmark.cc | 251 ++ absl/flags/flag_test.cc | 1381 +++++++ absl/flags/internal/flag.cc | 147 +- absl/flags/internal/flag.h | 222 +- absl/flags/internal/path_util_test.cc | 46 + absl/flags/internal/program_name_test.cc | 61 + absl/flags/internal/sequence_lock_test.cc | 169 + absl/flags/internal/usage_test.cc | 550 +++ absl/flags/marshalling_test.cc | 1220 ++++++ absl/flags/parse_test.cc | 1094 +++++ absl/flags/reflection.cc | 10 + absl/flags/reflection_test.cc | 268 ++ absl/flags/usage_config_test.cc | 205 + absl/functional/CMakeLists.txt | 4 + absl/functional/any_invocable.h | 16 +- absl/functional/any_invocable_test.cc | 1719 ++++++++ absl/functional/bind_front.h | 5 +- absl/functional/bind_front_test.cc | 231 ++ absl/functional/function_ref_test.cc | 293 ++ absl/functional/function_type_benchmark.cc | 176 + absl/functional/internal/any_invocable.h | 14 +- absl/functional/internal/front_binder.h | 18 +- absl/functional/overload.h | 61 +- absl/functional/overload_test.cc | 213 + absl/hash/BUILD.bazel | 6 +- absl/hash/hash_benchmark.cc | 323 ++ absl/hash/hash_instantiated_test.cc | 224 + absl/hash/hash_test.cc | 1148 ++++++ absl/hash/internal/city_test.cc | 597 +++ absl/hash/internal/hash.cc | 2 +- absl/hash/internal/hash.h | 16 +- absl/hash/internal/low_level_hash.cc | 88 +- absl/hash/internal/low_level_hash.h | 4 + absl/hash/internal/low_level_hash_test.cc | 532 +++ absl/hash/internal/spy_hash_state.h | 24 +- absl/log/BUILD.bazel | 12 +- absl/log/CMakeLists.txt | 6 + absl/log/absl_check_test.cc | 58 + absl/log/absl_log_basic_test.cc | 22 + absl/log/absl_vlog_is_on.h | 6 +- absl/log/check_test.cc | 58 + absl/log/check_test_impl.inc | 158 + absl/log/die_if_null.h | 2 +- absl/log/die_if_null_test.cc | 107 + absl/log/flags_test.cc | 188 + absl/log/globals.h | 43 +- absl/log/globals_test.cc | 147 + absl/log/internal/BUILD.bazel | 7 +- absl/log/internal/check_op.cc | 20 + absl/log/internal/check_op.h | 84 +- absl/log/internal/conditions.h | 4 +- absl/log/internal/fnmatch_benchmark.cc | 29 + absl/log/internal/fnmatch_test.cc | 59 + absl/log/internal/log_impl.h | 46 +- absl/log/internal/log_message.cc | 151 +- absl/log/internal/log_message.h | 27 +- absl/log/internal/nullstream.h | 11 +- absl/log/internal/stderr_log_sink_test.cc | 105 + absl/log/internal/strip.h | 36 + absl/log/internal/test_matchers.cc | 9 +- absl/log/internal/test_matchers.h | 2 +- absl/log/internal/vlog_config_benchmark.cc | 187 + absl/log/log.h | 6 +- absl/log/log_basic_test.cc | 22 + absl/log/log_basic_test_impl.inc | 233 +- absl/log/log_benchmark.cc | 164 + absl/log/log_entry_test.cc | 468 +++ absl/log/log_format_test.cc | 1854 +++++++++ absl/log/log_macro_hygiene_test.cc | 187 + absl/log/log_modifier_methods_test.cc | 225 ++ absl/log/log_sink.h | 15 +- absl/log/log_sink_test.cc | 418 ++ absl/log/log_streamer_test.cc | 441 ++ absl/log/scoped_mock_log_test.cc | 295 ++ absl/log/stripping_test.cc | 502 +++ absl/log/structured_test.cc | 64 + absl/log/vlog_is_on.h | 6 +- absl/log/vlog_is_on_test.cc | 176 + absl/memory/memory_test.cc | 222 + absl/meta/type_traits.h | 180 +- absl/meta/type_traits_test.cc | 819 ++++ absl/numeric/BUILD.bazel | 4 +- absl/numeric/CMakeLists.txt | 2 + absl/numeric/bits_benchmark.cc | 73 + absl/numeric/bits_test.cc | 641 +++ absl/numeric/int128.cc | 3 - absl/numeric/int128.h | 43 +- absl/numeric/int128_benchmark.cc | 282 ++ absl/numeric/int128_have_intrinsic.inc | 14 + absl/numeric/int128_no_intrinsic.inc | 18 + absl/numeric/int128_stream_test.cc | 1400 +++++++ absl/numeric/int128_test.cc | 1285 ++++++ absl/numeric/internal/bits.h | 8 +- absl/profiling/BUILD.bazel | 2 +- .../internal/exponential_biased_test.cc | 203 + absl/profiling/internal/periodic_sampler.h | 2 +- .../internal/periodic_sampler_benchmark.cc | 79 + .../internal/periodic_sampler_test.cc | 177 + .../internal/sample_recorder_test.cc | 184 + absl/random/BUILD.bazel | 24 +- absl/random/CMakeLists.txt | 38 +- absl/random/benchmarks.cc | 4 +- absl/random/bernoulli_distribution_test.cc | 217 + absl/random/beta_distribution.h | 16 +- absl/random/beta_distribution_test.cc | 615 +++ absl/random/bit_gen_ref.h | 16 +- absl/random/bit_gen_ref_test.cc | 102 + absl/random/discrete_distribution_test.cc | 251 ++ absl/random/distributions.h | 22 +- absl/random/distributions_test.cc | 510 +++ absl/random/examples_test.cc | 99 + absl/random/exponential_distribution_test.cc | 426 ++ absl/random/gaussian_distribution_test.cc | 561 +++ absl/random/generators_test.cc | 186 + absl/random/internal/BUILD.bazel | 24 +- absl/random/internal/chi_square_test.cc | 365 ++ .../internal/distribution_test_util_test.cc | 193 + .../random/internal/explicit_seed_seq_test.cc | 237 ++ .../random/internal/fast_uniform_bits_test.cc | 336 ++ absl/random/internal/fastmath_test.cc | 97 + absl/random/internal/generate_real_test.cc | 496 +++ .../internal/iostream_state_saver_test.cc | 373 ++ absl/random/internal/mock_helpers.h | 40 +- absl/random/internal/mock_overload_set.h | 82 +- absl/random/internal/mock_validators.h | 98 + absl/random/internal/nanobenchmark_test.cc | 79 + absl/random/internal/nonsecure_base_test.cc | 227 ++ absl/random/internal/pcg_engine_test.cc | 638 +++ absl/random/internal/pool_urbg_test.cc | 182 + absl/random/internal/randen_engine_test.cc | 655 +++ absl/random/internal/randen_hwaes_test.cc | 99 + absl/random/internal/randen_slow_test.cc | 61 + absl/random/internal/randen_test.cc | 75 + absl/random/internal/salted_seed_seq_test.cc | 168 + absl/random/internal/seed_material_test.cc | 202 + absl/random/internal/traits_test.cc | 126 + absl/random/internal/uniform_helper_test.cc | 279 ++ absl/random/internal/wide_multiply_test.cc | 119 + .../log_uniform_int_distribution_test.cc | 277 ++ absl/random/mock_distributions.h | 19 +- absl/random/mock_distributions_test.cc | 287 ++ absl/random/mocking_bit_gen.h | 158 +- absl/random/mocking_bit_gen_test.cc | 403 ++ absl/random/poisson_distribution_test.cc | 570 +++ absl/random/seed_sequences.h | 2 + absl/random/seed_sequences_test.cc | 126 + absl/random/uniform_int_distribution_test.cc | 259 ++ absl/random/uniform_real_distribution_test.cc | 394 ++ absl/random/zipf_distribution_test.cc | 423 ++ absl/status/BUILD.bazel | 36 + absl/status/CMakeLists.txt | 38 + absl/status/internal/status_matchers.cc | 68 + absl/status/internal/status_matchers.h | 246 ++ absl/status/internal/statusor_internal.h | 63 +- absl/status/status.cc | 4 - absl/status/status.h | 8 +- absl/status/status_matchers.h | 118 + absl/status/status_matchers_test.cc | 119 + absl/status/status_test.cc | 579 +++ absl/status/statusor.h | 250 +- absl/status/statusor_test.cc | 1802 +++++++++ absl/strings/BUILD.bazel | 18 +- absl/strings/CMakeLists.txt | 10 +- absl/strings/ascii.cc | 103 +- absl/strings/ascii_benchmark.cc | 132 + absl/strings/ascii_test.cc | 362 ++ absl/strings/atod_manual_test.cc | 193 + absl/strings/char_formatting_test.cc | 169 + absl/strings/charconv_benchmark.cc | 204 + absl/strings/charconv_test.cc | 787 ++++ absl/strings/charset_benchmark.cc | 57 + absl/strings/charset_test.cc | 181 + absl/strings/cord.cc | 35 +- absl/strings/cord.h | 75 +- absl/strings/cord_buffer_test.cc | 322 ++ absl/strings/cord_test.cc | 3376 ++++++++++++++++ absl/strings/cordz_test.cc | 468 +++ absl/strings/escaping.cc | 117 +- absl/strings/escaping.h | 33 +- absl/strings/escaping_benchmark.cc | 98 + absl/strings/escaping_test.cc | 750 ++++ absl/strings/has_absl_stringify.h | 1 + absl/strings/has_absl_stringify_test.cc | 40 + absl/strings/has_ostream_operator_test.cc | 41 + absl/strings/internal/charconv_bigint.h | 10 + absl/strings/internal/charconv_bigint_test.cc | 260 ++ absl/strings/internal/charconv_parse_test.cc | 357 ++ absl/strings/internal/cord_data_edge_test.cc | 130 + absl/strings/internal/cord_internal.h | 38 +- absl/strings/internal/cord_rep_btree.h | 4 +- .../internal/cord_rep_btree_navigator_test.cc | 346 ++ .../internal/cord_rep_btree_reader_test.cc | 293 ++ absl/strings/internal/cord_rep_btree_test.cc | 1568 +++++++ absl/strings/internal/cord_rep_crc_test.cc | 130 + absl/strings/internal/cordz_functions.cc | 32 +- absl/strings/internal/cordz_functions.h | 36 +- absl/strings/internal/cordz_functions_test.cc | 147 + absl/strings/internal/cordz_handle.cc | 48 +- absl/strings/internal/cordz_handle_test.cc | 265 ++ absl/strings/internal/cordz_info.cc | 19 +- absl/strings/internal/cordz_info.h | 13 +- .../internal/cordz_info_statistics_test.cc | 510 +++ absl/strings/internal/cordz_info_test.cc | 342 ++ .../internal/cordz_sample_token_test.cc | 208 + .../internal/cordz_update_scope_test.cc | 49 + .../internal/cordz_update_tracker_test.cc | 147 + .../damerau_levenshtein_distance_test.cc | 99 + absl/strings/internal/escaping.cc | 7 +- absl/strings/internal/memutil_benchmark.cc | 128 + absl/strings/internal/memutil_test.cc | 41 + .../internal/ostringstream_benchmark.cc | 106 + absl/strings/internal/ostringstream_test.cc | 131 + absl/strings/internal/pow10_helper_test.cc | 122 + .../internal/resize_uninitialized_test.cc | 133 + absl/strings/internal/str_format/arg_test.cc | 162 + absl/strings/internal/str_format/bind_test.cc | 157 + .../internal/str_format/checker_test.cc | 176 + .../internal/str_format/convert_test.cc | 1462 +++++++ .../internal/str_format/extension_test.cc | 109 + .../internal/str_format/output_test.cc | 79 + .../internal/str_format/parser_test.cc | 446 ++ absl/strings/internal/str_join_internal.h | 25 +- absl/strings/internal/str_split_internal.h | 6 +- absl/strings/internal/string_constant_test.cc | 60 + absl/strings/internal/utf8_test.cc | 66 + absl/strings/match_test.cc | 291 ++ absl/strings/numbers.cc | 440 +- absl/strings/numbers.h | 163 +- absl/strings/numbers_benchmark.cc | 288 ++ absl/strings/numbers_test.cc | 1740 ++++++++ absl/strings/str_cat.cc | 191 +- absl/strings/str_cat.h | 155 +- absl/strings/str_cat_benchmark.cc | 265 ++ absl/strings/str_cat_test.cc | 684 ++++ absl/strings/str_format.h | 2 +- absl/strings/str_format_test.cc | 1224 ++++++ absl/strings/str_join.h | 24 +- absl/strings/str_join_benchmark.cc | 107 + absl/strings/str_join_test.cc | 645 +++ absl/strings/str_replace_benchmark.cc | 122 + absl/strings/str_replace_test.cc | 345 ++ absl/strings/str_split.h | 4 +- absl/strings/str_split_benchmark.cc | 181 + absl/strings/str_split_test.cc | 1023 +++++ absl/strings/string_view.h | 5 +- absl/strings/string_view_benchmark.cc | 382 ++ absl/strings/string_view_test.cc | 1386 +++++++ absl/strings/strip_test.cc | 198 + absl/strings/substitute.cc | 4 + absl/strings/substitute_test.cc | 288 ++ absl/synchronization/BUILD.bazel | 14 +- absl/synchronization/barrier_test.cc | 75 + .../blocking_counter_benchmark.cc | 84 + absl/synchronization/blocking_counter_test.cc | 80 + absl/synchronization/internal/graphcycles.cc | 13 +- absl/synchronization/internal/graphcycles.h | 5 + .../internal/graphcycles_benchmark.cc | 44 + .../internal/graphcycles_test.cc | 482 +++ .../internal/kernel_timeout_test.cc | 396 ++ .../internal/per_thread_sem_test.cc | 194 + absl/synchronization/internal/waiter_test.cc | 180 + absl/synchronization/lifetime_test.cc | 180 + absl/synchronization/mutex.h | 9 +- absl/synchronization/mutex_benchmark.cc | 339 ++ .../mutex_method_pointer_test.cc | 138 + absl/synchronization/mutex_test.cc | 2037 ++++++++++ absl/synchronization/notification_test.cc | 133 + absl/time/BUILD.bazel | 2 +- absl/time/CMakeLists.txt | 2 +- absl/time/civil_time.h | 4 +- absl/time/civil_time_benchmark.cc | 130 + absl/time/civil_time_test.cc | 1262 ++++++ absl/time/clock.cc | 16 +- absl/time/clock_benchmark.cc | 74 + absl/time/clock_test.cc | 122 + absl/time/duration.cc | 111 +- absl/time/duration_benchmark.cc | 464 +++ absl/time/duration_test.cc | 1898 +++++++++ absl/time/flag_test.cc | 147 + absl/time/format.cc | 3 +- absl/time/format_benchmark.cc | 64 + absl/time/format_test.cc | 441 ++ absl/time/internal/cctz/src/cctz_benchmark.cc | 922 +++++ .../time/internal/cctz/src/civil_time_test.cc | 1066 +++++ .../cctz/src/time_zone_format_test.cc | 1774 ++++++++ absl/time/internal/cctz/src/time_zone_libc.cc | 2 +- .../internal/cctz/src/time_zone_lookup.cc | 29 - .../cctz/src/time_zone_lookup_test.cc | 1416 +++++++ absl/time/internal/cctz/src/tzfile.h | 6 +- absl/time/internal/cctz/testdata/version | 2 +- .../cctz/testdata/zoneinfo/America/Miquelon | Bin 550 -> 550 bytes .../cctz/testdata/zoneinfo/America/Montreal | Bin 1717 -> 1717 bytes .../cctz/testdata/zoneinfo/America/Nipigon | Bin 1717 -> 1717 bytes .../testdata/zoneinfo/America/Thunder_Bay | Bin 1717 -> 1717 bytes .../cctz/testdata/zoneinfo/America/Toronto | Bin 1717 -> 1717 bytes .../cctz/testdata/zoneinfo/Asia/Almaty | Bin 609 -> 618 bytes .../internal/cctz/testdata/zoneinfo/Asia/Gaza | Bin 2968 -> 2950 bytes .../cctz/testdata/zoneinfo/Asia/Hebron | Bin 2986 -> 2968 bytes .../cctz/testdata/zoneinfo/Asia/Ho_Chi_Minh | Bin 236 -> 236 bytes .../cctz/testdata/zoneinfo/Asia/Qostanay | Bin 615 -> 624 bytes .../cctz/testdata/zoneinfo/Asia/Saigon | Bin 236 -> 236 bytes .../cctz/testdata/zoneinfo/Canada/Eastern | Bin 1717 -> 1717 bytes .../cctz/testdata/zoneinfo/zonenow.tab | 4 +- absl/time/time.h | 102 +- absl/time/time_benchmark.cc | 321 ++ absl/time/time_test.cc | 1332 ++++++ absl/time/time_zone_test.cc | 97 + absl/types/BUILD.bazel | 1 + absl/types/CMakeLists.txt | 1 + absl/types/any_exception_safety_test.cc | 173 + absl/types/any_test.cc | 778 ++++ absl/types/compare_test.cc | 300 ++ absl/types/internal/optional.h | 4 +- absl/types/internal/variant.h | 122 +- absl/types/optional.h | 33 +- absl/types/optional_exception_safety_test.cc | 292 ++ absl/types/optional_test.cc | 1615 ++++++++ absl/types/span.h | 5 +- absl/types/span_test.cc | 853 ++++ absl/types/variant.h | 43 +- absl/types/variant_benchmark.cc | 222 + absl/types/variant_exception_safety_test.cc | 532 +++ absl/types/variant_test.cc | 2718 +++++++++++++ absl/utility/internal/if_constexpr_test.cc | 79 + absl/utility/utility.h | 44 +- absl/utility/utility_test.cc | 239 ++ ci/cmake_common.sh | 14 +- ci/cmake_install_test.sh | 2 +- ci/linux_docker_containers.sh | 6 +- ci/linux_gcc-floor_libstdcxx_bazel.sh | 4 +- ci/linux_gcc-latest_libstdcxx_cmake.sh | 55 +- ci/linux_gcc_alpine_cmake.sh | 54 +- ci/macos_xcode_cmake.sh | 48 +- ci/windows_clangcl_bazel.bat | 4 +- ci/windows_msvc_cmake.bat | 18 +- create_lts.py | 27 +- 509 files changed, 125394 insertions(+), 3328 deletions(-) create mode 100644 WORKSPACE.bzlmod create mode 100644 absl/algorithm/algorithm_test.cc create mode 100644 absl/algorithm/container_test.cc create mode 100644 absl/base/bit_cast_test.cc create mode 100644 absl/base/c_header_test.c create mode 100644 absl/base/call_once_test.cc create mode 100644 absl/base/config_test.cc create mode 100644 absl/base/exception_safety_testing_test.cc create mode 100644 absl/base/inline_variable_test.cc create mode 100644 absl/base/internal/atomic_hook_test.cc create mode 100644 absl/base/internal/cmake_thread_test.cc create mode 100644 absl/base/internal/endian_test.cc create mode 100644 absl/base/internal/errno_saver_test.cc create mode 100644 absl/base/internal/fast_type_id_test.cc create mode 100644 absl/base/internal/low_level_alloc_test.cc create mode 100644 absl/base/internal/poison.cc create mode 100644 absl/base/internal/poison.h create mode 100644 absl/base/internal/poison_test.cc create mode 100644 absl/base/internal/scoped_set_env_test.cc create mode 100644 absl/base/internal/spinlock_benchmark.cc create mode 100644 absl/base/internal/strerror_benchmark.cc create mode 100644 absl/base/internal/strerror_test.cc create mode 100644 absl/base/internal/sysinfo_test.cc create mode 100644 absl/base/internal/thread_identity_benchmark.cc create mode 100644 absl/base/internal/thread_identity_test.cc create mode 100644 absl/base/internal/unique_small_name_test.cc create mode 100644 absl/base/invoke_test.cc create mode 100644 absl/base/log_severity_test.cc create mode 100644 absl/base/no_destructor_benchmark.cc create mode 100644 absl/base/no_destructor_test.cc create mode 100644 absl/base/nullability_test.cc create mode 100644 absl/base/optimization_test.cc create mode 100644 absl/base/prefetch_test.cc create mode 100644 absl/base/raw_logging_test.cc create mode 100644 absl/base/throw_delegate_test.cc create mode 100644 absl/cleanup/cleanup_test.cc create mode 100644 absl/container/btree_benchmark.cc create mode 100644 absl/container/btree_test.cc create mode 100644 absl/container/fixed_array_benchmark.cc create mode 100644 absl/container/fixed_array_exception_safety_test.cc create mode 100644 absl/container/fixed_array_test.cc create mode 100644 absl/container/flat_hash_map_test.cc create mode 100644 absl/container/flat_hash_set_test.cc create mode 100644 absl/container/hash_container_defaults.h create mode 100644 absl/container/inlined_vector_benchmark.cc create mode 100644 absl/container/inlined_vector_exception_safety_test.cc create mode 100644 absl/container/inlined_vector_test.cc create mode 100644 absl/container/internal/common_policy_traits_test.cc create mode 100644 absl/container/internal/compressed_tuple_test.cc create mode 100644 absl/container/internal/container_memory_test.cc create mode 100644 absl/container/internal/hash_function_defaults_test.cc create mode 100644 absl/container/internal/hash_policy_testing_test.cc create mode 100644 absl/container/internal/hash_policy_traits_test.cc create mode 100644 absl/container/internal/hashtablez_sampler_test.cc create mode 100644 absl/container/internal/layout_benchmark.cc create mode 100644 absl/container/internal/layout_test.cc create mode 100644 absl/container/internal/node_slot_policy_test.cc create mode 100644 absl/container/internal/raw_hash_set_allocator_test.cc create mode 100644 absl/container/internal/raw_hash_set_benchmark.cc create mode 100644 absl/container/internal/raw_hash_set_probe_benchmark.cc create mode 100644 absl/container/internal/raw_hash_set_test.cc create mode 100644 absl/container/internal/test_instance_tracker_test.cc create mode 100644 absl/container/internal/unordered_map_test.cc create mode 100644 absl/container/internal/unordered_set_test.cc create mode 100644 absl/container/node_hash_map_test.cc create mode 100644 absl/container/node_hash_set_test.cc create mode 100644 absl/container/sample_element_size_test.cc create mode 100644 absl/crc/crc32c_benchmark.cc create mode 100644 absl/crc/crc32c_test.cc create mode 100644 absl/crc/internal/crc_cord_state_test.cc create mode 100644 absl/crc/internal/crc_memcpy_test.cc create mode 100644 absl/crc/internal/non_temporal_memcpy_test.cc create mode 100644 absl/debugging/failure_signal_handler_test.cc create mode 100644 absl/debugging/internal/bounded_utf8_length_sequence.h create mode 100644 absl/debugging/internal/bounded_utf8_length_sequence_test.cc create mode 100644 absl/debugging/internal/decode_rust_punycode.cc create mode 100644 absl/debugging/internal/decode_rust_punycode.h create mode 100644 absl/debugging/internal/decode_rust_punycode_test.cc create mode 100644 absl/debugging/internal/demangle_rust.cc create mode 100644 absl/debugging/internal/demangle_rust.h create mode 100644 absl/debugging/internal/demangle_rust_test.cc create mode 100644 absl/debugging/internal/demangle_test.cc create mode 100644 absl/debugging/internal/stack_consumption_test.cc create mode 100644 absl/debugging/internal/utf8_for_code_point.cc create mode 100644 absl/debugging/internal/utf8_for_code_point.h create mode 100644 absl/debugging/internal/utf8_for_code_point_test.cc create mode 100644 absl/debugging/leak_check_fail_test.cc create mode 100644 absl/debugging/leak_check_test.cc create mode 100644 absl/debugging/stacktrace_benchmark.cc create mode 100644 absl/debugging/stacktrace_test.cc create mode 100644 absl/debugging/symbolize_test.cc create mode 100644 absl/flags/commandlineflag_test.cc create mode 100644 absl/flags/config_test.cc create mode 100644 absl/flags/flag_benchmark.cc create mode 100644 absl/flags/flag_test.cc create mode 100644 absl/flags/internal/path_util_test.cc create mode 100644 absl/flags/internal/program_name_test.cc create mode 100644 absl/flags/internal/sequence_lock_test.cc create mode 100644 absl/flags/internal/usage_test.cc create mode 100644 absl/flags/marshalling_test.cc create mode 100644 absl/flags/parse_test.cc create mode 100644 absl/flags/reflection_test.cc create mode 100644 absl/flags/usage_config_test.cc create mode 100644 absl/functional/any_invocable_test.cc create mode 100644 absl/functional/bind_front_test.cc create mode 100644 absl/functional/function_ref_test.cc create mode 100644 absl/functional/function_type_benchmark.cc create mode 100644 absl/functional/overload_test.cc create mode 100644 absl/hash/hash_benchmark.cc create mode 100644 absl/hash/hash_instantiated_test.cc create mode 100644 absl/hash/hash_test.cc create mode 100644 absl/hash/internal/city_test.cc create mode 100644 absl/hash/internal/low_level_hash_test.cc create mode 100644 absl/log/absl_check_test.cc create mode 100644 absl/log/absl_log_basic_test.cc create mode 100644 absl/log/check_test.cc create mode 100644 absl/log/die_if_null_test.cc create mode 100644 absl/log/flags_test.cc create mode 100644 absl/log/globals_test.cc create mode 100644 absl/log/internal/fnmatch_benchmark.cc create mode 100644 absl/log/internal/fnmatch_test.cc create mode 100644 absl/log/internal/stderr_log_sink_test.cc create mode 100644 absl/log/internal/vlog_config_benchmark.cc create mode 100644 absl/log/log_basic_test.cc create mode 100644 absl/log/log_benchmark.cc create mode 100644 absl/log/log_entry_test.cc create mode 100644 absl/log/log_format_test.cc create mode 100644 absl/log/log_macro_hygiene_test.cc create mode 100644 absl/log/log_modifier_methods_test.cc create mode 100644 absl/log/log_sink_test.cc create mode 100644 absl/log/log_streamer_test.cc create mode 100644 absl/log/scoped_mock_log_test.cc create mode 100644 absl/log/stripping_test.cc create mode 100644 absl/log/structured_test.cc create mode 100644 absl/log/vlog_is_on_test.cc create mode 100644 absl/memory/memory_test.cc create mode 100644 absl/meta/type_traits_test.cc create mode 100644 absl/numeric/bits_benchmark.cc create mode 100644 absl/numeric/bits_test.cc create mode 100644 absl/numeric/int128_benchmark.cc create mode 100644 absl/numeric/int128_stream_test.cc create mode 100644 absl/numeric/int128_test.cc create mode 100644 absl/profiling/internal/exponential_biased_test.cc create mode 100644 absl/profiling/internal/periodic_sampler_benchmark.cc create mode 100644 absl/profiling/internal/periodic_sampler_test.cc create mode 100644 absl/profiling/internal/sample_recorder_test.cc create mode 100644 absl/random/bernoulli_distribution_test.cc create mode 100644 absl/random/beta_distribution_test.cc create mode 100644 absl/random/bit_gen_ref_test.cc create mode 100644 absl/random/discrete_distribution_test.cc create mode 100644 absl/random/distributions_test.cc create mode 100644 absl/random/examples_test.cc create mode 100644 absl/random/exponential_distribution_test.cc create mode 100644 absl/random/gaussian_distribution_test.cc create mode 100644 absl/random/generators_test.cc create mode 100644 absl/random/internal/chi_square_test.cc create mode 100644 absl/random/internal/distribution_test_util_test.cc create mode 100644 absl/random/internal/explicit_seed_seq_test.cc create mode 100644 absl/random/internal/fast_uniform_bits_test.cc create mode 100644 absl/random/internal/fastmath_test.cc create mode 100644 absl/random/internal/generate_real_test.cc create mode 100644 absl/random/internal/iostream_state_saver_test.cc create mode 100644 absl/random/internal/mock_validators.h create mode 100644 absl/random/internal/nanobenchmark_test.cc create mode 100644 absl/random/internal/nonsecure_base_test.cc create mode 100644 absl/random/internal/pcg_engine_test.cc create mode 100644 absl/random/internal/pool_urbg_test.cc create mode 100644 absl/random/internal/randen_engine_test.cc create mode 100644 absl/random/internal/randen_hwaes_test.cc create mode 100644 absl/random/internal/randen_slow_test.cc create mode 100644 absl/random/internal/randen_test.cc create mode 100644 absl/random/internal/salted_seed_seq_test.cc create mode 100644 absl/random/internal/seed_material_test.cc create mode 100644 absl/random/internal/traits_test.cc create mode 100644 absl/random/internal/uniform_helper_test.cc create mode 100644 absl/random/internal/wide_multiply_test.cc create mode 100644 absl/random/log_uniform_int_distribution_test.cc create mode 100644 absl/random/mock_distributions_test.cc create mode 100644 absl/random/mocking_bit_gen_test.cc create mode 100644 absl/random/poisson_distribution_test.cc create mode 100644 absl/random/seed_sequences_test.cc create mode 100644 absl/random/uniform_int_distribution_test.cc create mode 100644 absl/random/uniform_real_distribution_test.cc create mode 100644 absl/random/zipf_distribution_test.cc create mode 100644 absl/status/internal/status_matchers.cc create mode 100644 absl/status/internal/status_matchers.h create mode 100644 absl/status/status_matchers.h create mode 100644 absl/status/status_matchers_test.cc create mode 100644 absl/status/status_test.cc create mode 100644 absl/status/statusor_test.cc create mode 100644 absl/strings/ascii_benchmark.cc create mode 100644 absl/strings/ascii_test.cc create mode 100644 absl/strings/atod_manual_test.cc create mode 100644 absl/strings/char_formatting_test.cc create mode 100644 absl/strings/charconv_benchmark.cc create mode 100644 absl/strings/charconv_test.cc create mode 100644 absl/strings/charset_benchmark.cc create mode 100644 absl/strings/charset_test.cc create mode 100644 absl/strings/cord_buffer_test.cc create mode 100644 absl/strings/cord_test.cc create mode 100644 absl/strings/cordz_test.cc create mode 100644 absl/strings/escaping_benchmark.cc create mode 100644 absl/strings/escaping_test.cc create mode 100644 absl/strings/has_absl_stringify_test.cc create mode 100644 absl/strings/has_ostream_operator_test.cc create mode 100644 absl/strings/internal/charconv_bigint_test.cc create mode 100644 absl/strings/internal/charconv_parse_test.cc create mode 100644 absl/strings/internal/cord_data_edge_test.cc create mode 100644 absl/strings/internal/cord_rep_btree_navigator_test.cc create mode 100644 absl/strings/internal/cord_rep_btree_reader_test.cc create mode 100644 absl/strings/internal/cord_rep_btree_test.cc create mode 100644 absl/strings/internal/cord_rep_crc_test.cc create mode 100644 absl/strings/internal/cordz_functions_test.cc create mode 100644 absl/strings/internal/cordz_handle_test.cc create mode 100644 absl/strings/internal/cordz_info_statistics_test.cc create mode 100644 absl/strings/internal/cordz_info_test.cc create mode 100644 absl/strings/internal/cordz_sample_token_test.cc create mode 100644 absl/strings/internal/cordz_update_scope_test.cc create mode 100644 absl/strings/internal/cordz_update_tracker_test.cc create mode 100644 absl/strings/internal/damerau_levenshtein_distance_test.cc create mode 100644 absl/strings/internal/memutil_benchmark.cc create mode 100644 absl/strings/internal/memutil_test.cc create mode 100644 absl/strings/internal/ostringstream_benchmark.cc create mode 100644 absl/strings/internal/ostringstream_test.cc create mode 100644 absl/strings/internal/pow10_helper_test.cc create mode 100644 absl/strings/internal/resize_uninitialized_test.cc create mode 100644 absl/strings/internal/str_format/arg_test.cc create mode 100644 absl/strings/internal/str_format/bind_test.cc create mode 100644 absl/strings/internal/str_format/checker_test.cc create mode 100644 absl/strings/internal/str_format/convert_test.cc create mode 100644 absl/strings/internal/str_format/extension_test.cc create mode 100644 absl/strings/internal/str_format/output_test.cc create mode 100644 absl/strings/internal/str_format/parser_test.cc create mode 100644 absl/strings/internal/string_constant_test.cc create mode 100644 absl/strings/internal/utf8_test.cc create mode 100644 absl/strings/match_test.cc create mode 100644 absl/strings/numbers_benchmark.cc create mode 100644 absl/strings/numbers_test.cc create mode 100644 absl/strings/str_cat_benchmark.cc create mode 100644 absl/strings/str_cat_test.cc create mode 100644 absl/strings/str_format_test.cc create mode 100644 absl/strings/str_join_benchmark.cc create mode 100644 absl/strings/str_join_test.cc create mode 100644 absl/strings/str_replace_benchmark.cc create mode 100644 absl/strings/str_replace_test.cc create mode 100644 absl/strings/str_split_benchmark.cc create mode 100644 absl/strings/str_split_test.cc create mode 100644 absl/strings/string_view_benchmark.cc create mode 100644 absl/strings/string_view_test.cc create mode 100644 absl/strings/strip_test.cc create mode 100644 absl/strings/substitute_test.cc create mode 100644 absl/synchronization/barrier_test.cc create mode 100644 absl/synchronization/blocking_counter_benchmark.cc create mode 100644 absl/synchronization/blocking_counter_test.cc create mode 100644 absl/synchronization/internal/graphcycles_benchmark.cc create mode 100644 absl/synchronization/internal/graphcycles_test.cc create mode 100644 absl/synchronization/internal/kernel_timeout_test.cc create mode 100644 absl/synchronization/internal/per_thread_sem_test.cc create mode 100644 absl/synchronization/internal/waiter_test.cc create mode 100644 absl/synchronization/lifetime_test.cc create mode 100644 absl/synchronization/mutex_benchmark.cc create mode 100644 absl/synchronization/mutex_method_pointer_test.cc create mode 100644 absl/synchronization/mutex_test.cc create mode 100644 absl/synchronization/notification_test.cc create mode 100644 absl/time/civil_time_benchmark.cc create mode 100644 absl/time/civil_time_test.cc create mode 100644 absl/time/clock_benchmark.cc create mode 100644 absl/time/clock_test.cc create mode 100644 absl/time/duration_benchmark.cc create mode 100644 absl/time/duration_test.cc create mode 100644 absl/time/flag_test.cc create mode 100644 absl/time/format_benchmark.cc create mode 100644 absl/time/format_test.cc create mode 100644 absl/time/internal/cctz/src/cctz_benchmark.cc create mode 100644 absl/time/internal/cctz/src/civil_time_test.cc create mode 100644 absl/time/internal/cctz/src/time_zone_format_test.cc create mode 100644 absl/time/internal/cctz/src/time_zone_lookup_test.cc create mode 100644 absl/time/time_benchmark.cc create mode 100644 absl/time/time_test.cc create mode 100644 absl/time/time_zone_test.cc create mode 100644 absl/types/any_exception_safety_test.cc create mode 100644 absl/types/any_test.cc create mode 100644 absl/types/compare_test.cc create mode 100644 absl/types/optional_exception_safety_test.cc create mode 100644 absl/types/optional_test.cc create mode 100644 absl/types/span_test.cc create mode 100644 absl/types/variant_benchmark.cc create mode 100644 absl/types/variant_exception_safety_test.cc create mode 100644 absl/types/variant_test.cc create mode 100644 absl/utility/internal/if_constexpr_test.cc create mode 100644 absl/utility/utility_test.cc diff --git a/BUILD.bazel b/BUILD.bazel index 79fb0ec..03122a9 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -1,4 +1,3 @@ -# # Copyright 2020 The Abseil Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -23,3 +22,14 @@ exports_files([ "AUTHORS", "LICENSE", ]) + +# For building with clang-cl. +# https://bazel.build/configure/windows#clang +platform( + name = "x64_windows-clang-cl", + constraint_values = [ + "@platforms//cpu:x86_64", + "@platforms//os:windows", + "@bazel_tools//tools/cpp:clang-cl", + ], +) diff --git a/CMake/AbseilDll.cmake b/CMake/AbseilDll.cmake index 47f3bee..32cc28f 100644 --- a/CMake/AbseilDll.cmake +++ b/CMake/AbseilDll.cmake @@ -28,6 +28,8 @@ set(ABSL_INTERNAL_DLL_FILES "base/internal/low_level_scheduling.h" "base/internal/nullability_impl.h" "base/internal/per_thread_tls.h" + "base/internal/poison.cc" + "base/internal/poison.h" "base/prefetch.h" "base/internal/pretty_function.h" "base/internal/raw_logging.cc" @@ -66,6 +68,7 @@ set(ABSL_INTERNAL_DLL_FILES "cleanup/internal/cleanup.h" "container/btree_map.h" "container/btree_set.h" + "container/hash_container_defaults.h" "container/fixed_array.h" "container/flat_hash_map.h" "container/flat_hash_set.h" @@ -121,8 +124,13 @@ set(ABSL_INTERNAL_DLL_FILES "debugging/symbolize.h" "debugging/internal/address_is_readable.cc" "debugging/internal/address_is_readable.h" + "debugging/internal/bounded_utf8_length_sequence.h" + "debugging/internal/decode_rust_punycode.cc" + "debugging/internal/decode_rust_punycode.h" "debugging/internal/demangle.cc" "debugging/internal/demangle.h" + "debugging/internal/demangle_rust.cc" + "debugging/internal/demangle_rust.h" "debugging/internal/elf_mem_image.cc" "debugging/internal/elf_mem_image.h" "debugging/internal/examine_stack.cc" @@ -131,6 +139,8 @@ set(ABSL_INTERNAL_DLL_FILES "debugging/internal/stack_consumption.h" "debugging/internal/stacktrace_config.h" "debugging/internal/symbolize.h" + "debugging/internal/utf8_for_code_point.cc" + "debugging/internal/utf8_for_code_point.h" "debugging/internal/vdso_support.cc" "debugging/internal/vdso_support.h" "functional/any_invocable.h" @@ -311,7 +321,6 @@ set(ABSL_INTERNAL_DLL_FILES "strings/internal/string_constant.h" "strings/internal/stringify_sink.h" "strings/internal/stringify_sink.cc" - "strings/internal/has_absl_stringify.h" "strings/has_absl_stringify.h" "strings/has_ostream_operator.h" "strings/match.cc" @@ -437,9 +446,47 @@ set(ABSL_INTERNAL_DLL_FILES "debugging/leak_check.cc" ) +if(NOT MSVC) + list(APPEND ABSL_INTERNAL_DLL_FILES + "flags/commandlineflag.cc" + "flags/commandlineflag.h" + "flags/config.h" + "flags/declare.h" + "flags/flag.h" + "flags/internal/commandlineflag.cc" + "flags/internal/commandlineflag.h" + "flags/internal/flag.cc" + "flags/internal/flag.h" + "flags/internal/parse.h" + "flags/internal/path_util.h" + "flags/internal/private_handle_accessor.cc" + "flags/internal/private_handle_accessor.h" + "flags/internal/program_name.cc" + "flags/internal/program_name.h" + "flags/internal/registry.h" + "flags/internal/sequence_lock.h" + "flags/internal/usage.cc" + "flags/internal/usage.h" + "flags/marshalling.cc" + "flags/marshalling.h" + "flags/parse.cc" + "flags/parse.h" + "flags/reflection.cc" + "flags/reflection.h" + "flags/usage.cc" + "flags/usage.h" + "flags/usage_config.cc" + "flags/usage_config.h" + "log/flags.cc" + "log/flags.h" + "log/internal/flags.h" + ) +endif() + set(ABSL_INTERNAL_DLL_TARGETS "absl_check" "absl_log" + "absl_vlog_is_on" "algorithm" "algorithm_container" "any" @@ -505,6 +552,7 @@ set(ABSL_INTERNAL_DLL_TARGETS "log_internal_check_op" "log_internal_conditions" "log_internal_config" + "log_internal_fnmatch" "log_internal_format" "log_internal_globals" "log_internal_log_impl" @@ -584,6 +632,7 @@ set(ABSL_INTERNAL_DLL_TARGETS "strerror" "strings" "strings_internal" + "string_view" "symbolize" "synchronization" "thread_pool" @@ -594,8 +643,30 @@ set(ABSL_INTERNAL_DLL_TARGETS "type_traits" "utility" "variant" + "vlog_config_internal" + "vlog_is_on" ) +if(NOT MSVC) + list(APPEND ABSL_INTERNAL_DLL_TARGETS + "flags" + "flags_commandlineflag" + "flags_commandlineflag_internal" + "flags_config" + "flags_internal" + "flags_marshalling" + "flags_parse" + "flags_path_util" + "flags_private_handle_accessor" + "flags_program_name" + "flags_reflection" + "flags_usage" + "flags_usage_internal" + "log_internal_flags" + "log_flags" + ) +endif() + set(ABSL_INTERNAL_TEST_DLL_FILES "hash/hash_testing.h" "log/scoped_mock_log.cc" @@ -608,6 +679,9 @@ set(ABSL_INTERNAL_TEST_DLL_FILES "random/internal/mock_overload_set.h" "random/mocking_bit_gen.h" "random/mock_distributions.h" + "status/status_matchers.h" + "status/internal/status_matchers.cc" + "status/internal/status_matchers.h" "strings/cordz_test_helpers.h" "strings/cord_test_helpers.h" ) @@ -620,6 +694,7 @@ set(ABSL_INTERNAL_TEST_DLL_TARGETS "random_internal_distribution_test_util" "random_internal_mock_overload_set" "scoped_mock_log" + "status_matchers" ) include(CheckCXXSourceCompiles) @@ -668,12 +743,7 @@ function(absl_internal_dll_contains) STRING(REGEX REPLACE "^absl::" "" _target ${ABSL_INTERNAL_DLL_TARGET}) - list(FIND - ABSL_INTERNAL_DLL_TARGETS - "${_target}" - _index) - - if (${_index} GREATER -1) + if (_target IN_LIST ABSL_INTERNAL_DLL_TARGETS) set(${ABSL_INTERNAL_DLL_OUTPUT} 1 PARENT_SCOPE) else() set(${ABSL_INTERNAL_DLL_OUTPUT} 0 PARENT_SCOPE) @@ -690,12 +760,7 @@ function(absl_internal_test_dll_contains) STRING(REGEX REPLACE "^absl::" "" _target ${ABSL_INTERNAL_TEST_DLL_TARGET}) - list(FIND - ABSL_INTERNAL_TEST_DLL_TARGETS - "${_target}" - _index) - - if (${_index} GREATER -1) + if (_target IN_LIST ABSL_INTERNAL_TEST_DLL_TARGETS) set(${ABSL_INTERNAL_TEST_DLL_OUTPUT} 1 PARENT_SCOPE) else() set(${ABSL_INTERNAL_TEST_DLL_OUTPUT} 0 PARENT_SCOPE) @@ -747,7 +812,12 @@ function(absl_make_dll) else() set(_dll "abseil_dll") set(_dll_files ${ABSL_INTERNAL_DLL_FILES}) - set(_dll_libs "") + set(_dll_libs + Threads::Threads + # TODO(#1495): Use $ once our + # minimum CMake version >= 3.24 + $<$:-Wl,-framework,CoreFoundation> + ) set(_dll_compile_definitions "") set(_dll_includes "") set(_dll_consume "ABSL_CONSUME_DLL") @@ -765,7 +835,10 @@ function(absl_make_dll) ${_dll_libs} ${ABSL_DEFAULT_LINKOPTS} ) - set_property(TARGET ${_dll} PROPERTY LINKER_LANGUAGE "CXX") + set_target_properties(${_dll} PROPERTIES + LINKER_LANGUAGE "CXX" + SOVERSION ${ABSL_SOVERSION} + ) target_include_directories( ${_dll} PUBLIC diff --git a/CMake/AbseilHelpers.cmake b/CMake/AbseilHelpers.cmake index c53b358..b177e59 100644 --- a/CMake/AbseilHelpers.cmake +++ b/CMake/AbseilHelpers.cmake @@ -186,8 +186,16 @@ function(absl_cc_library) endif() endif() endforeach() + set(skip_next_cflag OFF) foreach(cflag ${ABSL_CC_LIB_COPTS}) - if(${cflag} MATCHES "^(-Wno|/wd)") + if(skip_next_cflag) + set(skip_next_cflag OFF) + elseif(${cflag} MATCHES "^-Xarch_") + # An -Xarch_ flag implies that its successor only applies to the + # specified platform. Filter both of them out before the successor + # reaches the "^-m" filter. + set(skip_next_cflag ON) + elseif(${cflag} MATCHES "^(-Wno|/wd)") # These flags are needed to suppress warnings that might fire in our headers. set(PC_CFLAGS "${PC_CFLAGS} ${cflag}") elseif(${cflag} MATCHES "^(-W|/w[1234eo])") @@ -250,6 +258,13 @@ Cflags: -I\${includedir}${PC_CFLAGS}\n") elseif(_build_type STREQUAL "static" OR _build_type STREQUAL "shared") add_library(${_NAME} "") target_sources(${_NAME} PRIVATE ${ABSL_CC_LIB_SRCS} ${ABSL_CC_LIB_HDRS}) + if(APPLE) + set_target_properties(${_NAME} PROPERTIES + INSTALL_RPATH "@loader_path") + elseif(UNIX) + set_target_properties(${_NAME} PROPERTIES + INSTALL_RPATH "$ORIGIN") + endif() target_link_libraries(${_NAME} PUBLIC ${ABSL_CC_LIB_DEPS} PRIVATE @@ -298,7 +313,7 @@ Cflags: -I\${includedir}${PC_CFLAGS}\n") if(ABSL_ENABLE_INSTALL) set_target_properties(${_NAME} PROPERTIES OUTPUT_NAME "absl_${_NAME}" - SOVERSION "2401.0.0" + SOVERSION "${ABSL_SOVERSION}" ) endif() else() diff --git a/CMake/Googletest/CMakeLists.txt.in b/CMake/Googletest/CMakeLists.txt.in index 75691b1..3db4834 100644 --- a/CMake/Googletest/CMakeLists.txt.in +++ b/CMake/Googletest/CMakeLists.txt.in @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.10) +cmake_minimum_required(VERSION 3.16) project(googletest-external NONE) diff --git a/CMake/README.md b/CMake/README.md index c7ddee6..808edfe 100644 --- a/CMake/README.md +++ b/CMake/README.md @@ -39,7 +39,7 @@ section of your executable or of your library.
Here is a short CMakeLists.txt example of an application project using Abseil. ```cmake -cmake_minimum_required(VERSION 3.10) +cmake_minimum_required(VERSION 3.16) project(my_app_project) # Pick the C++ standard to compile with. @@ -62,7 +62,7 @@ will control Abseil library targets) is set to at least that minimum. For example: ```cmake -cmake_minimum_required(VERSION 3.10) +cmake_minimum_required(VERSION 3.16) project(my_lib_project) # Leave C++ standard up to the root application, so set it only if this is the diff --git a/CMake/install_test_project/CMakeLists.txt b/CMake/install_test_project/CMakeLists.txt index 30c23b2..3229887 100644 --- a/CMake/install_test_project/CMakeLists.txt +++ b/CMake/install_test_project/CMakeLists.txt @@ -15,7 +15,7 @@ # A simple CMakeLists.txt for testing cmake installation -cmake_minimum_required(VERSION 3.10) +cmake_minimum_required(VERSION 3.16) project(absl_cmake_testing CXX) add_executable(simple simple.cc) diff --git a/CMake/install_test_project/test.sh b/CMake/install_test_project/test.sh index cc028ba..962bc8d 100755 --- a/CMake/install_test_project/test.sh +++ b/CMake/install_test_project/test.sh @@ -22,7 +22,8 @@ set -euox pipefail absl_dir=/abseil-cpp absl_build_dir=/buildfs googletest_builddir=/googletest_builddir -project_dir="${absl_dir}"/CMake/install_test_project +googletest_archive="googletest-${ABSL_GOOGLETEST_VERSION}.tar.gz" +project_dir="${absl_dir}/CMake/install_test_project" project_build_dir=/buildfs/project-build build_shared_libs="OFF" @@ -33,9 +34,9 @@ fi # Build and install GoogleTest mkdir "${googletest_builddir}" pushd "${googletest_builddir}" -curl -L "${ABSL_GOOGLETEST_DOWNLOAD_URL}" --output "${ABSL_GOOGLETEST_COMMIT}".zip -unzip "${ABSL_GOOGLETEST_COMMIT}".zip -pushd "googletest-${ABSL_GOOGLETEST_COMMIT}" +curl -L "${ABSL_GOOGLETEST_DOWNLOAD_URL}" --output "${googletest_archive}" +tar -xz -f "${googletest_archive}" +pushd "googletest-${ABSL_GOOGLETEST_VERSION}" mkdir build pushd build cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS="${build_shared_libs}" .. diff --git a/CMakeLists.txt b/CMakeLists.txt index 194f870..7c82b3a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,50 +15,16 @@ # # https://github.com/google/oss-policies-info/blob/main/foundational-cxx-support-matrix.md -# As of 2022-09-06, CMake 3.10 is the minimum supported version. -cmake_minimum_required(VERSION 3.10) - -# Compiler id for Apple Clang is now AppleClang. -if (POLICY CMP0025) - cmake_policy(SET CMP0025 NEW) -endif (POLICY CMP0025) - -# if command can use IN_LIST -if (POLICY CMP0057) - cmake_policy(SET CMP0057 NEW) -endif (POLICY CMP0057) - -# Project version variables are the empty string if version is unspecified -if (POLICY CMP0048) - cmake_policy(SET CMP0048 NEW) -endif (POLICY CMP0048) - -# Honor the GTest_ROOT variable if specified -if (POLICY CMP0074) - cmake_policy(SET CMP0074 NEW) -endif (POLICY CMP0074) - -# option() honor variables -if (POLICY CMP0077) - cmake_policy(SET CMP0077 NEW) -endif (POLICY CMP0077) - -# Allow the user to specify the MSVC runtime -if (POLICY CMP0091) - cmake_policy(SET CMP0091 NEW) -endif (POLICY CMP0091) - -# try_compile() honors the CMAKE_CXX_STANDARD value -if (POLICY CMP0067) - cmake_policy(SET CMP0067 NEW) -endif (POLICY CMP0067) +# As of 2024-07-01, CMake 3.16 is the minimum supported version. +cmake_minimum_required(VERSION 3.16) # Allow the user to specify the CMAKE_MSVC_DEBUG_INFORMATION_FORMAT if (POLICY CMP0141) cmake_policy(SET CMP0141 NEW) endif (POLICY CMP0141) -project(absl LANGUAGES CXX VERSION 20240116) +project(absl LANGUAGES CXX VERSION 20240722) +set(ABSL_SOVERSION "2407.0.0") include(CTest) # Output directory is correct by default for most build setups. However, when @@ -75,6 +41,10 @@ else() option(ABSL_ENABLE_INSTALL "Enable install rule" ON) endif() +set(CMAKE_INSTALL_RPATH "$ORIGIN") +set(CMAKE_INSTALL_RPATH_USE_LINK_PATH ON) +set(CMAKE_BUILD_RPATH_USE_ORIGIN ON) + option(ABSL_PROPAGATE_CXX_STD "Use CMake C++ standard meta features (e.g. cxx_std_14) that propagate to targets that link to Abseil" OFF) # TODO: Default to ON for CMake 3.8 and greater. @@ -91,6 +61,15 @@ list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/absl/copts ) +option(ABSL_MSVC_STATIC_RUNTIME + "Link static runtime libraries" + OFF) +if(ABSL_MSVC_STATIC_RUNTIME) + set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") +else() + set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>DLL") +endif() + include(CMakePackageConfigHelpers) include(GNUInstallDirs) include(AbseilDll) @@ -149,6 +128,14 @@ set(ABSL_LOCAL_GOOGLETEST_DIR "/usr/src/googletest" CACHE PATH "If ABSL_USE_GOOGLETEST_HEAD is OFF and ABSL_GOOGLETEST_URL is not set, specifies the directory of a local GoogleTest checkout." ) +option(ABSL_BUILD_MONOLITHIC_SHARED_LIBS + "Build Abseil as a single shared library (always enabled for Windows)" + OFF +) +if(NOT BUILD_SHARED_LIBS AND ABSL_BUILD_MONOLITHIC_SHARED_LIBS) + message(WARNING "Not building a shared library because BUILD_SHARED_LIBS is not set. Ignoring ABSL_BUILD_MONOLITHIC_SHARED_LIBS.") +endif() + if((BUILD_TESTING AND ABSL_BUILD_TESTING) OR ABSL_BUILD_TEST_HELPERS) if (ABSL_USE_EXTERNAL_GOOGLETEST) if (ABSL_FIND_GOOGLETEST) @@ -261,7 +248,7 @@ if(ABSL_ENABLE_INSTALL) ABSL_INTERNAL_OPTIONS_H_PINNED "${ABSL_INTERNAL_OPTIONS_H_CONTENTS}") - file(WRITE "${CMAKE_BINARY_DIR}/options-pinned.h" "${ABSL_INTERNAL_OPTIONS_H_PINNED}") + file(GENERATE OUTPUT "${CMAKE_BINARY_DIR}/options-pinned.h" CONTENT "${ABSL_INTERNAL_OPTIONS_H_PINNED}") install(FILES "${CMAKE_BINARY_DIR}/options-pinned.h" DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/absl/base diff --git a/MODULE.bazel b/MODULE.bazel index efbc88b..75285b6 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -16,10 +16,13 @@ module( name = "abseil-cpp", - version = "20240116.0", + version = "20240722.0", compatibility_level = 1, ) +cc_configure = use_extension("@bazel_tools//tools/cpp:cc_configure.bzl", "cc_configure_extension") +use_repo(cc_configure, "local_config_cc") + # Only direct dependencies need to be listed below. # Please keep the versions in sync with the versions in the WORKSPACE file. @@ -32,8 +35,8 @@ bazel_dep(name = "google_benchmark", dev_dependency = True) bazel_dep(name = "googletest", - version = "1.14.0.bcr.1", + version = "1.15.2", repo_name = "com_google_googletest") bazel_dep(name = "platforms", - version = "0.0.8") + version = "0.0.10") diff --git a/PrivacyInfo.xcprivacy b/PrivacyInfo.xcprivacy index 6af1641..3ff4a9d 100644 --- a/PrivacyInfo.xcprivacy +++ b/PrivacyInfo.xcprivacy @@ -2,13 +2,13 @@ - NSPrivacyTracking - - NSPrivacyCollectedDataTypes - - NSPrivacyTrackingDomains - - NSPrivacyAccessedAPITypes - + NSPrivacyTracking + + NSPrivacyCollectedDataTypes + + NSPrivacyTrackingDomains + + NSPrivacyAccessedAPITypes + diff --git a/WORKSPACE b/WORKSPACE index 0d88609..dee6d05 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -20,20 +20,21 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") # GoogleTest/GoogleMock framework. Used by most unit-tests. http_archive( - name = "com_google_googletest", - sha256 = "8ad598c73ad796e0d8280b082cebd82a630d73e73cd3c70057938a6501bba5d7", - strip_prefix = "googletest-1.14.0", - # Keep this URL in sync with ABSL_GOOGLETEST_COMMIT in ci/cmake_common.sh and - # ci/windows_msvc_cmake.bat. - urls = ["https://github.com/google/googletest/archive/refs/tags/v1.14.0.tar.gz"], + name = "com_google_googletest", + sha256 = "7b42b4d6ed48810c5362c265a17faebe90dc2373c885e5216439d37927f02926", + strip_prefix = "googletest-1.15.2", + # Keep this URL in sync with the version in ci/cmake_common.sh and + # ci/windows_msvc_cmake.bat. + urls = ["https://github.com/google/googletest/releases/download/v1.15.2/googletest-1.15.2.tar.gz"], ) # RE2 (the regular expression library used by GoogleTest) http_archive( name = "com_googlesource_code_re2", - sha256 = "828341ad08524618a626167bd320b0c2acc97bd1c28eff693a9ea33a7ed2a85f", - strip_prefix = "re2-2023-11-01", - urls = ["https://github.com/google/re2/releases/download/2023-11-01/re2-2023-11-01.zip"], + sha256 = "eb2df807c781601c14a260a507a5bb4509be1ee626024cb45acbd57cb9d4032b", + strip_prefix = "re2-2024-07-02", + urls = ["https://github.com/google/re2/releases/download/2024-07-02/re2-2024-07-02.tar.gz"], + repo_mapping = {"@abseil-cpp": "@com_google_absl"}, ) # Google benchmark. @@ -46,14 +47,17 @@ http_archive( # Bazel Skylib. http_archive( - name = "bazel_skylib", - sha256 = "cd55a062e763b9349921f0f5db8c3933288dc8ba4f76dd9416aac68acee3cb94", - urls = ["https://github.com/bazelbuild/bazel-skylib/releases/download/1.5.0/bazel-skylib-1.5.0.tar.gz"], + name = "bazel_skylib", + sha256 = "cd55a062e763b9349921f0f5db8c3933288dc8ba4f76dd9416aac68acee3cb94", + urls = ["https://github.com/bazelbuild/bazel-skylib/releases/download/1.5.0/bazel-skylib-1.5.0.tar.gz"], ) # Bazel platform rules. http_archive( name = "platforms", - sha256 = "8150406605389ececb6da07cbcb509d5637a3ab9a24bc69b1101531367d89d74", - urls = ["https://github.com/bazelbuild/platforms/releases/download/0.0.8/platforms-0.0.8.tar.gz"], + urls = [ + "https://mirror.bazel.build/github.com/bazelbuild/platforms/releases/download/0.0.10/platforms-0.0.10.tar.gz", + "https://github.com/bazelbuild/platforms/releases/download/0.0.10/platforms-0.0.10.tar.gz", + ], + sha256 = "218efe8ee736d26a3572663b374a253c012b716d8af0c07e842e82f238a0a7ee", ) diff --git a/WORKSPACE.bzlmod b/WORKSPACE.bzlmod new file mode 100644 index 0000000..83e67ba --- /dev/null +++ b/WORKSPACE.bzlmod @@ -0,0 +1,19 @@ +# Copyright 2024 The Abseil Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# https://bazel.build/external/migration#workspace.bzlmod +# +# This file is intentionally empty. When bzlmod is enabled and this +# file exists, the contents of WORKSPACE is ignored. This prevents +# bzlmod builds from unintentionally depending on the WORKSPACE file. diff --git a/absl/BUILD.bazel b/absl/BUILD.bazel index 14c30b3..253c0ae 100644 --- a/absl/BUILD.bazel +++ b/absl/BUILD.bazel @@ -68,17 +68,6 @@ config_setting( visibility = [":__subpackages__"], ) -# x64_windows-clang-cl - used for selecting clang-cl for CI builds -platform( - name = "x64_windows-clang-cl", - constraint_values = [ - "@platforms//cpu:x86_64", - "@platforms//os:windows", - "@bazel_tools//tools/cpp:clang-cl", - ], - visibility = [":__subpackages__"], -) - config_setting( name = "osx", constraint_values = [ diff --git a/absl/CMakeLists.txt b/absl/CMakeLists.txt index 3a7c12f..810d7f3 100644 --- a/absl/CMakeLists.txt +++ b/absl/CMakeLists.txt @@ -36,9 +36,9 @@ add_subdirectory(time) add_subdirectory(types) add_subdirectory(utility) -if (${ABSL_BUILD_DLL}) +if (ABSL_BUILD_DLL) absl_make_dll() - if (${ABSL_BUILD_TEST_HELPERS}) + if ((BUILD_TESTING AND ABSL_BUILD_TESTING) OR ABSL_BUILD_TEST_HELPERS) absl_make_dll(TEST ON) endif() endif() diff --git a/absl/abseil.podspec.gen.py b/absl/abseil.podspec.gen.py index c83edbf..cbf7cb4 100755 --- a/absl/abseil.podspec.gen.py +++ b/absl/abseil.podspec.gen.py @@ -44,9 +44,14 @@ 'ALWAYS_SEARCH_USER_PATHS' => 'NO', } s.ios.deployment_target = '9.0' - s.osx.deployment_target = '10.10' + s.osx.deployment_target = '10.11' s.tvos.deployment_target = '9.0' s.watchos.deployment_target = '2.0' + s.subspec 'xcprivacy' do |ss| + ss.resource_bundles = { + ss.module_name => 'PrivacyInfo.xcprivacy', + } + end """ # Rule object representing the rule of Bazel BUILD. @@ -191,6 +196,12 @@ def write_podspec_rule(f, rule, depth): name = get_spec_name(dep.replace(":", "/")) f.write("{indent}{var}.dependency '{dep}'\n".format( indent=indent, var=spec_var, dep=name)) + # Writes dependency to xcprivacy + f.write( + "{indent}{var}.dependency '{dep}'\n".format( + indent=indent, var=spec_var, dep="abseil/xcprivacy" + ) + ) def write_indented_list(f, leading, values): diff --git a/absl/algorithm/BUILD.bazel b/absl/algorithm/BUILD.bazel index ddf9e11..f20e729 100644 --- a/absl/algorithm/BUILD.bazel +++ b/absl/algorithm/BUILD.bazel @@ -65,6 +65,7 @@ cc_library( linkopts = ABSL_DEFAULT_LINKOPTS, deps = [ ":algorithm", + "//absl/base:config", "//absl/base:core_headers", "//absl/base:nullability", "//absl/meta:type_traits", @@ -79,6 +80,7 @@ cc_test( deps = [ ":container", "//absl/base", + "//absl/base:config", "//absl/base:core_headers", "//absl/memory", "//absl/types:span", diff --git a/absl/algorithm/CMakeLists.txt b/absl/algorithm/CMakeLists.txt index 5577164..252b6b2 100644 --- a/absl/algorithm/CMakeLists.txt +++ b/absl/algorithm/CMakeLists.txt @@ -48,6 +48,7 @@ absl_cc_library( ${ABSL_DEFAULT_COPTS} DEPS absl::algorithm + absl::config absl::core_headers absl::meta absl::nullability @@ -64,6 +65,7 @@ absl_cc_test( DEPS absl::algorithm_container absl::base + absl::config absl::core_headers absl::memory absl::span diff --git a/absl/algorithm/algorithm_test.cc b/absl/algorithm/algorithm_test.cc new file mode 100644 index 0000000..e6ee469 --- /dev/null +++ b/absl/algorithm/algorithm_test.cc @@ -0,0 +1,50 @@ +// Copyright 2017 The Abseil Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "absl/algorithm/algorithm.h" + +#include +#include +#include + +#include "gmock/gmock.h" +#include "gtest/gtest.h" +#include "absl/base/config.h" + +namespace { + +class LinearSearchTest : public testing::Test { + protected: + LinearSearchTest() : container_{1, 2, 3} {} + + static bool Is3(int n) { return n == 3; } + static bool Is4(int n) { return n == 4; } + + std::vector container_; +}; + +TEST_F(LinearSearchTest, linear_search) { + EXPECT_TRUE(absl::linear_search(container_.begin(), container_.end(), 3)); + EXPECT_FALSE(absl::linear_search(container_.begin(), container_.end(), 4)); +} + +TEST_F(LinearSearchTest, linear_searchConst) { + const std::vector *const const_container = &container_; + EXPECT_TRUE( + absl::linear_search(const_container->begin(), const_container->end(), 3)); + EXPECT_FALSE( + absl::linear_search(const_container->begin(), const_container->end(), 4)); +} + +} // namespace diff --git a/absl/algorithm/container.h b/absl/algorithm/container.h index c7bafae..6bbe3b5 100644 --- a/absl/algorithm/container.h +++ b/absl/algorithm/container.h @@ -44,6 +44,7 @@ #include #include #include +#include #include #include #include @@ -51,6 +52,7 @@ #include #include "absl/algorithm/algorithm.h" +#include "absl/base/config.h" #include "absl/base/macros.h" #include "absl/base/nullability.h" #include "absl/meta/type_traits.h" @@ -92,17 +94,17 @@ using ContainerPointerType = // using std::end; // std::foo(begin(c), end(c)); // becomes -// std::foo(container_algorithm_internal::begin(c), -// container_algorithm_internal::end(c)); +// std::foo(container_algorithm_internal::c_begin(c), +// container_algorithm_internal::c_end(c)); // These are meant for internal use only. template -ContainerIter c_begin(C& c) { +ABSL_INTERNAL_CONSTEXPR_SINCE_CXX17 ContainerIter c_begin(C& c) { return begin(c); } template -ContainerIter c_end(C& c) { +ABSL_INTERNAL_CONSTEXPR_SINCE_CXX17 ContainerIter c_end(C& c) { return end(c); } @@ -145,8 +147,9 @@ bool c_linear_search(const C& c, EqualityComparable&& value) { // Container-based version of the `std::distance()` function to // return the number of elements within a container. template -container_algorithm_internal::ContainerDifferenceType c_distance( - const C& c) { +ABSL_INTERNAL_CONSTEXPR_SINCE_CXX17 + container_algorithm_internal::ContainerDifferenceType + c_distance(const C& c) { return std::distance(container_algorithm_internal::c_begin(c), container_algorithm_internal::c_end(c)); } @@ -210,6 +213,16 @@ container_algorithm_internal::ContainerIter c_find(C& c, T&& value) { std::forward(value)); } +// c_contains() +// +// Container-based version of the `std::ranges::contains()` C++23 +// function to search a container for a value. +template +bool c_contains(const Sequence& sequence, T&& value) { + return absl::c_find(sequence, std::forward(value)) != + container_algorithm_internal::c_end(sequence); +} + // c_find_if() // // Container-based version of the `std::find_if()` function to find @@ -426,6 +439,26 @@ container_algorithm_internal::ContainerIter c_search( std::forward(pred)); } +// c_contains_subrange() +// +// Container-based version of the `std::ranges::contains_subrange()` +// C++23 function to search a container for a subsequence. +template +bool c_contains_subrange(Sequence1& sequence, Sequence2& subsequence) { + return absl::c_search(sequence, subsequence) != + container_algorithm_internal::c_end(sequence); +} + +// Overload of c_contains_subrange() for using a predicate evaluation other than +// `==` as the function's test condition. +template +bool c_contains_subrange(Sequence1& sequence, Sequence2& subsequence, + BinaryPredicate&& pred) { + return absl::c_search(sequence, subsequence, + std::forward(pred)) != + container_algorithm_internal::c_end(sequence); +} + // c_search_n() // // Container-based version of the `std::search_n()` function to @@ -1500,8 +1533,9 @@ c_is_heap_until(RandomAccessContainer& sequence, LessThan&& comp) { // to return an iterator pointing to the element with the smallest value, using // `operator<` to make the comparisons. template -container_algorithm_internal::ContainerIter c_min_element( - Sequence& sequence) { +ABSL_INTERNAL_CONSTEXPR_SINCE_CXX17 + container_algorithm_internal::ContainerIter + c_min_element(Sequence& sequence) { return std::min_element(container_algorithm_internal::c_begin(sequence), container_algorithm_internal::c_end(sequence)); } @@ -1509,8 +1543,9 @@ container_algorithm_internal::ContainerIter c_min_element( // Overload of c_min_element() for performing a `comp` comparison other than // `operator<`. template -container_algorithm_internal::ContainerIter c_min_element( - Sequence& sequence, LessThan&& comp) { +ABSL_INTERNAL_CONSTEXPR_SINCE_CXX17 + container_algorithm_internal::ContainerIter + c_min_element(Sequence& sequence, LessThan&& comp) { return std::min_element(container_algorithm_internal::c_begin(sequence), container_algorithm_internal::c_end(sequence), std::forward(comp)); @@ -1522,8 +1557,9 @@ container_algorithm_internal::ContainerIter c_min_element( // to return an iterator pointing to the element with the largest value, using // `operator<` to make the comparisons. template -container_algorithm_internal::ContainerIter c_max_element( - Sequence& sequence) { +ABSL_INTERNAL_CONSTEXPR_SINCE_CXX17 + container_algorithm_internal::ContainerIter + c_max_element(Sequence& sequence) { return std::max_element(container_algorithm_internal::c_begin(sequence), container_algorithm_internal::c_end(sequence)); } @@ -1531,8 +1567,9 @@ container_algorithm_internal::ContainerIter c_max_element( // Overload of c_max_element() for performing a `comp` comparison other than // `operator<`. template -container_algorithm_internal::ContainerIter c_max_element( - Sequence& sequence, LessThan&& comp) { +ABSL_INTERNAL_CONSTEXPR_SINCE_CXX17 + container_algorithm_internal::ContainerIter + c_max_element(Sequence& sequence, LessThan&& comp) { return std::max_element(container_algorithm_internal::c_begin(sequence), container_algorithm_internal::c_end(sequence), std::forward(comp)); @@ -1545,8 +1582,9 @@ container_algorithm_internal::ContainerIter c_max_element( // smallest and largest values, respectively, using `operator<` to make the // comparisons. template -container_algorithm_internal::ContainerIterPairType c_minmax_element( - C& c) { +ABSL_INTERNAL_CONSTEXPR_SINCE_CXX17 + container_algorithm_internal::ContainerIterPairType + c_minmax_element(C& c) { return std::minmax_element(container_algorithm_internal::c_begin(c), container_algorithm_internal::c_end(c)); } @@ -1554,8 +1592,9 @@ container_algorithm_internal::ContainerIterPairType c_minmax_element( // Overload of c_minmax_element() for performing `comp` comparisons other than // `operator<`. template -container_algorithm_internal::ContainerIterPairType c_minmax_element( - C& c, LessThan&& comp) { +ABSL_INTERNAL_CONSTEXPR_SINCE_CXX17 + container_algorithm_internal::ContainerIterPairType + c_minmax_element(C& c, LessThan&& comp) { return std::minmax_element(container_algorithm_internal::c_begin(c), container_algorithm_internal::c_end(c), std::forward(comp)); diff --git a/absl/algorithm/container_test.cc b/absl/algorithm/container_test.cc new file mode 100644 index 0000000..5012224 --- /dev/null +++ b/absl/algorithm/container_test.cc @@ -0,0 +1,1210 @@ +// Copyright 2017 The Abseil Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "absl/algorithm/container.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "gmock/gmock.h" +#include "gtest/gtest.h" +#include "absl/base/casts.h" +#include "absl/base/config.h" +#include "absl/base/macros.h" +#include "absl/memory/memory.h" +#include "absl/types/span.h" + +namespace { + +using ::testing::Each; +using ::testing::ElementsAre; +using ::testing::Gt; +using ::testing::IsNull; +using ::testing::IsSubsetOf; +using ::testing::Lt; +using ::testing::Pointee; +using ::testing::SizeIs; +using ::testing::Truly; +using ::testing::UnorderedElementsAre; + +// Most of these tests just check that the code compiles, not that it +// does the right thing. That's fine since the functions just forward +// to the STL implementation. +class NonMutatingTest : public testing::Test { + protected: + std::unordered_set container_ = {1, 2, 3}; + std::list sequence_ = {1, 2, 3}; + std::vector vector_ = {1, 2, 3}; + int array_[3] = {1, 2, 3}; +}; + +struct AccumulateCalls { + void operator()(int value) { calls.push_back(value); } + std::vector calls; +}; + +bool Predicate(int value) { return value < 3; } +bool BinPredicate(int v1, int v2) { return v1 < v2; } +bool Equals(int v1, int v2) { return v1 == v2; } +bool IsOdd(int x) { return x % 2 != 0; } + +TEST_F(NonMutatingTest, Distance) { + EXPECT_EQ(container_.size(), + static_cast(absl::c_distance(container_))); + EXPECT_EQ(sequence_.size(), static_cast(absl::c_distance(sequence_))); + EXPECT_EQ(vector_.size(), static_cast(absl::c_distance(vector_))); + EXPECT_EQ(ABSL_ARRAYSIZE(array_), + static_cast(absl::c_distance(array_))); + + // Works with a temporary argument. + EXPECT_EQ(vector_.size(), + static_cast(absl::c_distance(std::vector(vector_)))); +} + +TEST_F(NonMutatingTest, Distance_OverloadedBeginEnd) { + // Works with classes which have custom ADL-selected overloads of std::begin + // and std::end. + std::initializer_list a = {1, 2, 3}; + std::valarray b = {1, 2, 3}; + EXPECT_EQ(3, absl::c_distance(a)); + EXPECT_EQ(3, absl::c_distance(b)); + + // It is assumed that other c_* functions use the same mechanism for + // ADL-selecting begin/end overloads. +} + +TEST_F(NonMutatingTest, ForEach) { + AccumulateCalls c = absl::c_for_each(container_, AccumulateCalls()); + // Don't rely on the unordered_set's order. + std::sort(c.calls.begin(), c.calls.end()); + EXPECT_EQ(vector_, c.calls); + + // Works with temporary container, too. + AccumulateCalls c2 = + absl::c_for_each(std::unordered_set(container_), AccumulateCalls()); + std::sort(c2.calls.begin(), c2.calls.end()); + EXPECT_EQ(vector_, c2.calls); +} + +TEST_F(NonMutatingTest, FindReturnsCorrectType) { + auto it = absl::c_find(container_, 3); + EXPECT_EQ(3, *it); + absl::c_find(absl::implicit_cast&>(sequence_), 3); +} + +TEST_F(NonMutatingTest, Contains) { + EXPECT_TRUE(absl::c_contains(container_, 3)); + EXPECT_FALSE(absl::c_contains(container_, 4)); +} + +TEST_F(NonMutatingTest, FindIf) { absl::c_find_if(container_, Predicate); } + +TEST_F(NonMutatingTest, FindIfNot) { + absl::c_find_if_not(container_, Predicate); +} + +TEST_F(NonMutatingTest, FindEnd) { + absl::c_find_end(sequence_, vector_); + absl::c_find_end(vector_, sequence_); +} + +TEST_F(NonMutatingTest, FindEndWithPredicate) { + absl::c_find_end(sequence_, vector_, BinPredicate); + absl::c_find_end(vector_, sequence_, BinPredicate); +} + +TEST_F(NonMutatingTest, FindFirstOf) { + absl::c_find_first_of(container_, sequence_); + absl::c_find_first_of(sequence_, container_); +} + +TEST_F(NonMutatingTest, FindFirstOfWithPredicate) { + absl::c_find_first_of(container_, sequence_, BinPredicate); + absl::c_find_first_of(sequence_, container_, BinPredicate); +} + +TEST_F(NonMutatingTest, AdjacentFind) { absl::c_adjacent_find(sequence_); } + +TEST_F(NonMutatingTest, AdjacentFindWithPredicate) { + absl::c_adjacent_find(sequence_, BinPredicate); +} + +TEST_F(NonMutatingTest, Count) { EXPECT_EQ(1, absl::c_count(container_, 3)); } + +TEST_F(NonMutatingTest, CountIf) { + EXPECT_EQ(2, absl::c_count_if(container_, Predicate)); + const std::unordered_set& const_container = container_; + EXPECT_EQ(2, absl::c_count_if(const_container, Predicate)); +} + +TEST_F(NonMutatingTest, Mismatch) { + // Testing necessary as absl::c_mismatch executes logic. + { + auto result = absl::c_mismatch(vector_, sequence_); + EXPECT_EQ(result.first, vector_.end()); + EXPECT_EQ(result.second, sequence_.end()); + } + { + auto result = absl::c_mismatch(sequence_, vector_); + EXPECT_EQ(result.first, sequence_.end()); + EXPECT_EQ(result.second, vector_.end()); + } + + sequence_.back() = 5; + { + auto result = absl::c_mismatch(vector_, sequence_); + EXPECT_EQ(result.first, std::prev(vector_.end())); + EXPECT_EQ(result.second, std::prev(sequence_.end())); + } + { + auto result = absl::c_mismatch(sequence_, vector_); + EXPECT_EQ(result.first, std::prev(sequence_.end())); + EXPECT_EQ(result.second, std::prev(vector_.end())); + } + + sequence_.pop_back(); + { + auto result = absl::c_mismatch(vector_, sequence_); + EXPECT_EQ(result.first, std::prev(vector_.end())); + EXPECT_EQ(result.second, sequence_.end()); + } + { + auto result = absl::c_mismatch(sequence_, vector_); + EXPECT_EQ(result.first, sequence_.end()); + EXPECT_EQ(result.second, std::prev(vector_.end())); + } + { + struct NoNotEquals { + constexpr bool operator==(NoNotEquals) const { return true; } + constexpr bool operator!=(NoNotEquals) const = delete; + }; + std::vector first; + std::list second; + + // Check this still compiles. + absl::c_mismatch(first, second); + } +} + +TEST_F(NonMutatingTest, MismatchWithPredicate) { + // Testing necessary as absl::c_mismatch executes logic. + { + auto result = absl::c_mismatch(vector_, sequence_, BinPredicate); + EXPECT_EQ(result.first, vector_.begin()); + EXPECT_EQ(result.second, sequence_.begin()); + } + { + auto result = absl::c_mismatch(sequence_, vector_, BinPredicate); + EXPECT_EQ(result.first, sequence_.begin()); + EXPECT_EQ(result.second, vector_.begin()); + } + + sequence_.front() = 0; + { + auto result = absl::c_mismatch(vector_, sequence_, BinPredicate); + EXPECT_EQ(result.first, vector_.begin()); + EXPECT_EQ(result.second, sequence_.begin()); + } + { + auto result = absl::c_mismatch(sequence_, vector_, BinPredicate); + EXPECT_EQ(result.first, std::next(sequence_.begin())); + EXPECT_EQ(result.second, std::next(vector_.begin())); + } + + sequence_.clear(); + { + auto result = absl::c_mismatch(vector_, sequence_, BinPredicate); + EXPECT_EQ(result.first, vector_.begin()); + EXPECT_EQ(result.second, sequence_.end()); + } + { + auto result = absl::c_mismatch(sequence_, vector_, BinPredicate); + EXPECT_EQ(result.first, sequence_.end()); + EXPECT_EQ(result.second, vector_.begin()); + } +} + +TEST_F(NonMutatingTest, Equal) { + EXPECT_TRUE(absl::c_equal(vector_, sequence_)); + EXPECT_TRUE(absl::c_equal(sequence_, vector_)); + EXPECT_TRUE(absl::c_equal(sequence_, array_)); + EXPECT_TRUE(absl::c_equal(array_, vector_)); + + // Test that behavior appropriately differs from that of equal(). + std::vector vector_plus = {1, 2, 3}; + vector_plus.push_back(4); + EXPECT_FALSE(absl::c_equal(vector_plus, sequence_)); + EXPECT_FALSE(absl::c_equal(sequence_, vector_plus)); + EXPECT_FALSE(absl::c_equal(array_, vector_plus)); +} + +TEST_F(NonMutatingTest, EqualWithPredicate) { + EXPECT_TRUE(absl::c_equal(vector_, sequence_, Equals)); + EXPECT_TRUE(absl::c_equal(sequence_, vector_, Equals)); + EXPECT_TRUE(absl::c_equal(array_, sequence_, Equals)); + EXPECT_TRUE(absl::c_equal(vector_, array_, Equals)); + + // Test that behavior appropriately differs from that of equal(). + std::vector vector_plus = {1, 2, 3}; + vector_plus.push_back(4); + EXPECT_FALSE(absl::c_equal(vector_plus, sequence_, Equals)); + EXPECT_FALSE(absl::c_equal(sequence_, vector_plus, Equals)); + EXPECT_FALSE(absl::c_equal(vector_plus, array_, Equals)); +} + +TEST_F(NonMutatingTest, IsPermutation) { + auto vector_permut_ = vector_; + std::next_permutation(vector_permut_.begin(), vector_permut_.end()); + EXPECT_TRUE(absl::c_is_permutation(vector_permut_, sequence_)); + EXPECT_TRUE(absl::c_is_permutation(sequence_, vector_permut_)); + + // Test that behavior appropriately differs from that of is_permutation(). + std::vector vector_plus = {1, 2, 3}; + vector_plus.push_back(4); + EXPECT_FALSE(absl::c_is_permutation(vector_plus, sequence_)); + EXPECT_FALSE(absl::c_is_permutation(sequence_, vector_plus)); +} + +TEST_F(NonMutatingTest, IsPermutationWithPredicate) { + auto vector_permut_ = vector_; + std::next_permutation(vector_permut_.begin(), vector_permut_.end()); + EXPECT_TRUE(absl::c_is_permutation(vector_permut_, sequence_, Equals)); + EXPECT_TRUE(absl::c_is_permutation(sequence_, vector_permut_, Equals)); + + // Test that behavior appropriately differs from that of is_permutation(). + std::vector vector_plus = {1, 2, 3}; + vector_plus.push_back(4); + EXPECT_FALSE(absl::c_is_permutation(vector_plus, sequence_, Equals)); + EXPECT_FALSE(absl::c_is_permutation(sequence_, vector_plus, Equals)); +} + +TEST_F(NonMutatingTest, Search) { + absl::c_search(sequence_, vector_); + absl::c_search(vector_, sequence_); + absl::c_search(array_, sequence_); +} + +TEST_F(NonMutatingTest, SearchWithPredicate) { + absl::c_search(sequence_, vector_, BinPredicate); + absl::c_search(vector_, sequence_, BinPredicate); +} + +TEST_F(NonMutatingTest, ContainsSubrange) { + EXPECT_TRUE(absl::c_contains_subrange(sequence_, vector_)); + EXPECT_TRUE(absl::c_contains_subrange(vector_, sequence_)); + EXPECT_TRUE(absl::c_contains_subrange(array_, sequence_)); +} + +TEST_F(NonMutatingTest, ContainsSubrangeWithPredicate) { + EXPECT_TRUE(absl::c_contains_subrange(sequence_, vector_, Equals)); + EXPECT_TRUE(absl::c_contains_subrange(vector_, sequence_, Equals)); +} + +TEST_F(NonMutatingTest, SearchN) { absl::c_search_n(sequence_, 3, 1); } + +TEST_F(NonMutatingTest, SearchNWithPredicate) { + absl::c_search_n(sequence_, 3, 1, BinPredicate); +} + +TEST_F(NonMutatingTest, LowerBound) { + std::list::iterator i = absl::c_lower_bound(sequence_, 3); + ASSERT_TRUE(i != sequence_.end()); + EXPECT_EQ(2, std::distance(sequence_.begin(), i)); + EXPECT_EQ(3, *i); +} + +TEST_F(NonMutatingTest, LowerBoundWithPredicate) { + std::vector v(vector_); + std::sort(v.begin(), v.end(), std::greater()); + std::vector::iterator i = absl::c_lower_bound(v, 3, std::greater()); + EXPECT_TRUE(i == v.begin()); + EXPECT_EQ(3, *i); +} + +TEST_F(NonMutatingTest, UpperBound) { + std::list::iterator i = absl::c_upper_bound(sequence_, 1); + ASSERT_TRUE(i != sequence_.end()); + EXPECT_EQ(1, std::distance(sequence_.begin(), i)); + EXPECT_EQ(2, *i); +} + +TEST_F(NonMutatingTest, UpperBoundWithPredicate) { + std::vector v(vector_); + std::sort(v.begin(), v.end(), std::greater()); + std::vector::iterator i = absl::c_upper_bound(v, 1, std::greater()); + EXPECT_EQ(3, i - v.begin()); + EXPECT_TRUE(i == v.end()); +} + +TEST_F(NonMutatingTest, EqualRange) { + std::pair::iterator, std::list::iterator> p = + absl::c_equal_range(sequence_, 2); + EXPECT_EQ(1, std::distance(sequence_.begin(), p.first)); + EXPECT_EQ(2, std::distance(sequence_.begin(), p.second)); +} + +TEST_F(NonMutatingTest, EqualRangeArray) { + auto p = absl::c_equal_range(array_, 2); + EXPECT_EQ(1, std::distance(std::begin(array_), p.first)); + EXPECT_EQ(2, std::distance(std::begin(array_), p.second)); +} + +TEST_F(NonMutatingTest, EqualRangeWithPredicate) { + std::vector v(vector_); + std::sort(v.begin(), v.end(), std::greater()); + std::pair::iterator, std::vector::iterator> p = + absl::c_equal_range(v, 2, std::greater()); + EXPECT_EQ(1, std::distance(v.begin(), p.first)); + EXPECT_EQ(2, std::distance(v.begin(), p.second)); +} + +TEST_F(NonMutatingTest, BinarySearch) { + EXPECT_TRUE(absl::c_binary_search(vector_, 2)); + EXPECT_TRUE(absl::c_binary_search(std::vector(vector_), 2)); +} + +TEST_F(NonMutatingTest, BinarySearchWithPredicate) { + std::vector v(vector_); + std::sort(v.begin(), v.end(), std::greater()); + EXPECT_TRUE(absl::c_binary_search(v, 2, std::greater())); + EXPECT_TRUE( + absl::c_binary_search(std::vector(v), 2, std::greater())); +} + +TEST_F(NonMutatingTest, MinElement) { + std::list::iterator i = absl::c_min_element(sequence_); + ASSERT_TRUE(i != sequence_.end()); + EXPECT_EQ(*i, 1); +} + +TEST_F(NonMutatingTest, MinElementWithPredicate) { + std::list::iterator i = + absl::c_min_element(sequence_, std::greater()); + ASSERT_TRUE(i != sequence_.end()); + EXPECT_EQ(*i, 3); +} + +TEST_F(NonMutatingTest, MaxElement) { + std::list::iterator i = absl::c_max_element(sequence_); + ASSERT_TRUE(i != sequence_.end()); + EXPECT_EQ(*i, 3); +} + +TEST_F(NonMutatingTest, MaxElementWithPredicate) { + std::list::iterator i = + absl::c_max_element(sequence_, std::greater()); + ASSERT_TRUE(i != sequence_.end()); + EXPECT_EQ(*i, 1); +} + +TEST_F(NonMutatingTest, LexicographicalCompare) { + EXPECT_FALSE(absl::c_lexicographical_compare(sequence_, sequence_)); + + std::vector v; + v.push_back(1); + v.push_back(2); + v.push_back(4); + + EXPECT_TRUE(absl::c_lexicographical_compare(sequence_, v)); + EXPECT_TRUE(absl::c_lexicographical_compare(std::list(sequence_), v)); +} + +TEST_F(NonMutatingTest, LexicographicalCopmareWithPredicate) { + EXPECT_FALSE(absl::c_lexicographical_compare(sequence_, sequence_, + std::greater())); + + std::vector v; + v.push_back(1); + v.push_back(2); + v.push_back(4); + + EXPECT_TRUE( + absl::c_lexicographical_compare(v, sequence_, std::greater())); + EXPECT_TRUE(absl::c_lexicographical_compare( + std::vector(v), std::list(sequence_), std::greater())); +} + +TEST_F(NonMutatingTest, Includes) { + std::set s(vector_.begin(), vector_.end()); + s.insert(4); + EXPECT_TRUE(absl::c_includes(s, vector_)); +} + +TEST_F(NonMutatingTest, IncludesWithPredicate) { + std::vector v = {3, 2, 1}; + std::set> s(v.begin(), v.end()); + s.insert(4); + EXPECT_TRUE(absl::c_includes(s, v, std::greater())); +} + +class NumericMutatingTest : public testing::Test { + protected: + std::list list_ = {1, 2, 3}; + std::vector output_; +}; + +TEST_F(NumericMutatingTest, Iota) { + absl::c_iota(list_, 5); + std::list expected{5, 6, 7}; + EXPECT_EQ(list_, expected); +} + +TEST_F(NonMutatingTest, Accumulate) { + EXPECT_EQ(absl::c_accumulate(sequence_, 4), 1 + 2 + 3 + 4); +} + +TEST_F(NonMutatingTest, AccumulateWithBinaryOp) { + EXPECT_EQ(absl::c_accumulate(sequence_, 4, std::multiplies()), + 1 * 2 * 3 * 4); +} + +TEST_F(NonMutatingTest, AccumulateLvalueInit) { + int lvalue = 4; + EXPECT_EQ(absl::c_accumulate(sequence_, lvalue), 1 + 2 + 3 + 4); +} + +TEST_F(NonMutatingTest, AccumulateWithBinaryOpLvalueInit) { + int lvalue = 4; + EXPECT_EQ(absl::c_accumulate(sequence_, lvalue, std::multiplies()), + 1 * 2 * 3 * 4); +} + +TEST_F(NonMutatingTest, InnerProduct) { + EXPECT_EQ(absl::c_inner_product(sequence_, vector_, 1000), + 1000 + 1 * 1 + 2 * 2 + 3 * 3); +} + +TEST_F(NonMutatingTest, InnerProductWithBinaryOps) { + EXPECT_EQ(absl::c_inner_product(sequence_, vector_, 10, + std::multiplies(), std::plus()), + 10 * (1 + 1) * (2 + 2) * (3 + 3)); +} + +TEST_F(NonMutatingTest, InnerProductLvalueInit) { + int lvalue = 1000; + EXPECT_EQ(absl::c_inner_product(sequence_, vector_, lvalue), + 1000 + 1 * 1 + 2 * 2 + 3 * 3); +} + +TEST_F(NonMutatingTest, InnerProductWithBinaryOpsLvalueInit) { + int lvalue = 10; + EXPECT_EQ(absl::c_inner_product(sequence_, vector_, lvalue, + std::multiplies(), std::plus()), + 10 * (1 + 1) * (2 + 2) * (3 + 3)); +} + +TEST_F(NumericMutatingTest, AdjacentDifference) { + auto last = absl::c_adjacent_difference(list_, std::back_inserter(output_)); + *last = 1000; + std::vector expected{1, 2 - 1, 3 - 2, 1000}; + EXPECT_EQ(output_, expected); +} + +TEST_F(NumericMutatingTest, AdjacentDifferenceWithBinaryOp) { + auto last = absl::c_adjacent_difference(list_, std::back_inserter(output_), + std::multiplies()); + *last = 1000; + std::vector expected{1, 2 * 1, 3 * 2, 1000}; + EXPECT_EQ(output_, expected); +} + +TEST_F(NumericMutatingTest, PartialSum) { + auto last = absl::c_partial_sum(list_, std::back_inserter(output_)); + *last = 1000; + std::vector expected{1, 1 + 2, 1 + 2 + 3, 1000}; + EXPECT_EQ(output_, expected); +} + +TEST_F(NumericMutatingTest, PartialSumWithBinaryOp) { + auto last = absl::c_partial_sum(list_, std::back_inserter(output_), + std::multiplies()); + *last = 1000; + std::vector expected{1, 1 * 2, 1 * 2 * 3, 1000}; + EXPECT_EQ(output_, expected); +} + +TEST_F(NonMutatingTest, LinearSearch) { + EXPECT_TRUE(absl::c_linear_search(container_, 3)); + EXPECT_FALSE(absl::c_linear_search(container_, 4)); +} + +TEST_F(NonMutatingTest, AllOf) { + const std::vector& v = vector_; + EXPECT_FALSE(absl::c_all_of(v, [](int x) { return x > 1; })); + EXPECT_TRUE(absl::c_all_of(v, [](int x) { return x > 0; })); +} + +TEST_F(NonMutatingTest, AnyOf) { + const std::vector& v = vector_; + EXPECT_TRUE(absl::c_any_of(v, [](int x) { return x > 2; })); + EXPECT_FALSE(absl::c_any_of(v, [](int x) { return x > 5; })); +} + +TEST_F(NonMutatingTest, NoneOf) { + const std::vector& v = vector_; + EXPECT_FALSE(absl::c_none_of(v, [](int x) { return x > 2; })); + EXPECT_TRUE(absl::c_none_of(v, [](int x) { return x > 5; })); +} + +TEST_F(NonMutatingTest, MinMaxElementLess) { + std::pair::const_iterator, std::vector::const_iterator> + p = absl::c_minmax_element(vector_, std::less()); + EXPECT_TRUE(p.first == vector_.begin()); + EXPECT_TRUE(p.second == vector_.begin() + 2); +} + +TEST_F(NonMutatingTest, MinMaxElementGreater) { + std::pair::const_iterator, std::vector::const_iterator> + p = absl::c_minmax_element(vector_, std::greater()); + EXPECT_TRUE(p.first == vector_.begin() + 2); + EXPECT_TRUE(p.second == vector_.begin()); +} + +TEST_F(NonMutatingTest, MinMaxElementNoPredicate) { + std::pair::const_iterator, std::vector::const_iterator> + p = absl::c_minmax_element(vector_); + EXPECT_TRUE(p.first == vector_.begin()); + EXPECT_TRUE(p.second == vector_.begin() + 2); +} + +class SortingTest : public testing::Test { + protected: + std::list sorted_ = {1, 2, 3, 4}; + std::list unsorted_ = {2, 4, 1, 3}; + std::list reversed_ = {4, 3, 2, 1}; +}; + +TEST_F(SortingTest, IsSorted) { + EXPECT_TRUE(absl::c_is_sorted(sorted_)); + EXPECT_FALSE(absl::c_is_sorted(unsorted_)); + EXPECT_FALSE(absl::c_is_sorted(reversed_)); +} + +TEST_F(SortingTest, IsSortedWithPredicate) { + EXPECT_FALSE(absl::c_is_sorted(sorted_, std::greater())); + EXPECT_FALSE(absl::c_is_sorted(unsorted_, std::greater())); + EXPECT_TRUE(absl::c_is_sorted(reversed_, std::greater())); +} + +TEST_F(SortingTest, IsSortedUntil) { + EXPECT_EQ(1, *absl::c_is_sorted_until(unsorted_)); + EXPECT_EQ(4, *absl::c_is_sorted_until(unsorted_, std::greater())); +} + +TEST_F(SortingTest, NthElement) { + std::vector unsorted = {2, 4, 1, 3}; + absl::c_nth_element(unsorted, unsorted.begin() + 2); + EXPECT_THAT(unsorted, ElementsAre(Lt(3), Lt(3), 3, Gt(3))); + absl::c_nth_element(unsorted, unsorted.begin() + 2, std::greater()); + EXPECT_THAT(unsorted, ElementsAre(Gt(2), Gt(2), 2, Lt(2))); +} + +TEST(MutatingTest, IsPartitioned) { + EXPECT_TRUE( + absl::c_is_partitioned(std::vector{1, 3, 5, 2, 4, 6}, IsOdd)); + EXPECT_FALSE( + absl::c_is_partitioned(std::vector{1, 2, 3, 4, 5, 6}, IsOdd)); + EXPECT_FALSE( + absl::c_is_partitioned(std::vector{2, 4, 6, 1, 3, 5}, IsOdd)); +} + +TEST(MutatingTest, Partition) { + std::vector actual = {1, 2, 3, 4, 5}; + absl::c_partition(actual, IsOdd); + EXPECT_THAT(actual, Truly([](const std::vector& c) { + return absl::c_is_partitioned(c, IsOdd); + })); +} + +TEST(MutatingTest, StablePartition) { + std::vector actual = {1, 2, 3, 4, 5}; + absl::c_stable_partition(actual, IsOdd); + EXPECT_THAT(actual, ElementsAre(1, 3, 5, 2, 4)); +} + +TEST(MutatingTest, PartitionCopy) { + const std::vector initial = {1, 2, 3, 4, 5}; + std::vector odds, evens; + auto ends = absl::c_partition_copy(initial, back_inserter(odds), + back_inserter(evens), IsOdd); + *ends.first = 7; + *ends.second = 6; + EXPECT_THAT(odds, ElementsAre(1, 3, 5, 7)); + EXPECT_THAT(evens, ElementsAre(2, 4, 6)); +} + +TEST(MutatingTest, PartitionPoint) { + const std::vector initial = {1, 3, 5, 2, 4}; + auto middle = absl::c_partition_point(initial, IsOdd); + EXPECT_EQ(2, *middle); +} + +TEST(MutatingTest, CopyMiddle) { + const std::vector initial = {4, -1, -2, -3, 5}; + const std::list input = {1, 2, 3}; + const std::vector expected = {4, 1, 2, 3, 5}; + + std::list test_list(initial.begin(), initial.end()); + absl::c_copy(input, ++test_list.begin()); + EXPECT_EQ(std::list(expected.begin(), expected.end()), test_list); + + std::vector test_vector = initial; + absl::c_copy(input, test_vector.begin() + 1); + EXPECT_EQ(expected, test_vector); +} + +TEST(MutatingTest, CopyFrontInserter) { + const std::list initial = {4, 5}; + const std::list input = {1, 2, 3}; + const std::list expected = {3, 2, 1, 4, 5}; + + std::list test_list = initial; + absl::c_copy(input, std::front_inserter(test_list)); + EXPECT_EQ(expected, test_list); +} + +TEST(MutatingTest, CopyBackInserter) { + const std::vector initial = {4, 5}; + const std::list input = {1, 2, 3}; + const std::vector expected = {4, 5, 1, 2, 3}; + + std::list test_list(initial.begin(), initial.end()); + absl::c_copy(input, std::back_inserter(test_list)); + EXPECT_EQ(std::list(expected.begin(), expected.end()), test_list); + + std::vector test_vector = initial; + absl::c_copy(input, std::back_inserter(test_vector)); + EXPECT_EQ(expected, test_vector); +} + +TEST(MutatingTest, CopyN) { + const std::vector initial = {1, 2, 3, 4, 5}; + const std::vector expected = {1, 2}; + std::vector actual; + absl::c_copy_n(initial, 2, back_inserter(actual)); + EXPECT_EQ(expected, actual); +} + +TEST(MutatingTest, CopyIf) { + const std::list input = {1, 2, 3}; + std::vector output; + absl::c_copy_if(input, std::back_inserter(output), + [](int i) { return i != 2; }); + EXPECT_THAT(output, ElementsAre(1, 3)); +} + +TEST(MutatingTest, CopyBackward) { + std::vector actual = {1, 2, 3, 4, 5}; + std::vector expected = {1, 2, 1, 2, 3}; + absl::c_copy_backward(absl::MakeSpan(actual.data(), 3), actual.end()); + EXPECT_EQ(expected, actual); +} + +TEST(MutatingTest, Move) { + std::vector> src; + src.emplace_back(absl::make_unique(1)); + src.emplace_back(absl::make_unique(2)); + src.emplace_back(absl::make_unique(3)); + src.emplace_back(absl::make_unique(4)); + src.emplace_back(absl::make_unique(5)); + + std::vector> dest = {}; + absl::c_move(src, std::back_inserter(dest)); + EXPECT_THAT(src, Each(IsNull())); + EXPECT_THAT(dest, ElementsAre(Pointee(1), Pointee(2), Pointee(3), Pointee(4), + Pointee(5))); +} + +TEST(MutatingTest, MoveBackward) { + std::vector> actual; + actual.emplace_back(absl::make_unique(1)); + actual.emplace_back(absl::make_unique(2)); + actual.emplace_back(absl::make_unique(3)); + actual.emplace_back(absl::make_unique(4)); + actual.emplace_back(absl::make_unique(5)); + auto subrange = absl::MakeSpan(actual.data(), 3); + absl::c_move_backward(subrange, actual.end()); + EXPECT_THAT(actual, ElementsAre(IsNull(), IsNull(), Pointee(1), Pointee(2), + Pointee(3))); +} + +TEST(MutatingTest, MoveWithRvalue) { + auto MakeRValueSrc = [] { + std::vector> src; + src.emplace_back(absl::make_unique(1)); + src.emplace_back(absl::make_unique(2)); + src.emplace_back(absl::make_unique(3)); + return src; + }; + + std::vector> dest = MakeRValueSrc(); + absl::c_move(MakeRValueSrc(), std::back_inserter(dest)); + EXPECT_THAT(dest, ElementsAre(Pointee(1), Pointee(2), Pointee(3), Pointee(1), + Pointee(2), Pointee(3))); +} + +TEST(MutatingTest, SwapRanges) { + std::vector odds = {2, 4, 6}; + std::vector evens = {1, 3, 5}; + absl::c_swap_ranges(odds, evens); + EXPECT_THAT(odds, ElementsAre(1, 3, 5)); + EXPECT_THAT(evens, ElementsAre(2, 4, 6)); + + odds.pop_back(); + absl::c_swap_ranges(odds, evens); + EXPECT_THAT(odds, ElementsAre(2, 4)); + EXPECT_THAT(evens, ElementsAre(1, 3, 6)); + + absl::c_swap_ranges(evens, odds); + EXPECT_THAT(odds, ElementsAre(1, 3)); + EXPECT_THAT(evens, ElementsAre(2, 4, 6)); +} + +TEST_F(NonMutatingTest, Transform) { + std::vector x{0, 2, 4}, y, z; + auto end = absl::c_transform(x, back_inserter(y), std::negate()); + EXPECT_EQ(std::vector({0, -2, -4}), y); + *end = 7; + EXPECT_EQ(std::vector({0, -2, -4, 7}), y); + + y = {1, 3, 0}; + end = absl::c_transform(x, y, back_inserter(z), std::plus()); + EXPECT_EQ(std::vector({1, 5, 4}), z); + *end = 7; + EXPECT_EQ(std::vector({1, 5, 4, 7}), z); + + z.clear(); + y.pop_back(); + end = absl::c_transform(x, y, std::back_inserter(z), std::plus()); + EXPECT_EQ(std::vector({1, 5}), z); + *end = 7; + EXPECT_EQ(std::vector({1, 5, 7}), z); + + z.clear(); + std::swap(x, y); + end = absl::c_transform(x, y, std::back_inserter(z), std::plus()); + EXPECT_EQ(std::vector({1, 5}), z); + *end = 7; + EXPECT_EQ(std::vector({1, 5, 7}), z); +} + +TEST(MutatingTest, Replace) { + const std::vector initial = {1, 2, 3, 1, 4, 5}; + const std::vector expected = {4, 2, 3, 4, 4, 5}; + + std::vector test_vector = initial; + absl::c_replace(test_vector, 1, 4); + EXPECT_EQ(expected, test_vector); + + std::list test_list(initial.begin(), initial.end()); + absl::c_replace(test_list, 1, 4); + EXPECT_EQ(std::list(expected.begin(), expected.end()), test_list); +} + +TEST(MutatingTest, ReplaceIf) { + std::vector actual = {1, 2, 3, 4, 5}; + const std::vector expected = {0, 2, 0, 4, 0}; + + absl::c_replace_if(actual, IsOdd, 0); + EXPECT_EQ(expected, actual); +} + +TEST(MutatingTest, ReplaceCopy) { + const std::vector initial = {1, 2, 3, 1, 4, 5}; + const std::vector expected = {4, 2, 3, 4, 4, 5}; + + std::vector actual; + absl::c_replace_copy(initial, back_inserter(actual), 1, 4); + EXPECT_EQ(expected, actual); +} + +TEST(MutatingTest, Sort) { + std::vector test_vector = {2, 3, 1, 4}; + absl::c_sort(test_vector); + EXPECT_THAT(test_vector, ElementsAre(1, 2, 3, 4)); +} + +TEST(MutatingTest, SortWithPredicate) { + std::vector test_vector = {2, 3, 1, 4}; + absl::c_sort(test_vector, std::greater()); + EXPECT_THAT(test_vector, ElementsAre(4, 3, 2, 1)); +} + +// For absl::c_stable_sort tests. Needs an operator< that does not cover all +// fields so that the test can check the sort preserves order of equal elements. +struct Element { + int key; + int value; + friend bool operator<(const Element& e1, const Element& e2) { + return e1.key < e2.key; + } + // Make gmock print useful diagnostics. + friend std::ostream& operator<<(std::ostream& o, const Element& e) { + return o << "{" << e.key << ", " << e.value << "}"; + } +}; + +MATCHER_P2(IsElement, key, value, "") { + return arg.key == key && arg.value == value; +} + +TEST(MutatingTest, StableSort) { + std::vector test_vector = {{1, 1}, {2, 1}, {2, 0}, {1, 0}, {2, 2}}; + absl::c_stable_sort(test_vector); + EXPECT_THAT(test_vector, + ElementsAre(IsElement(1, 1), IsElement(1, 0), IsElement(2, 1), + IsElement(2, 0), IsElement(2, 2))); +} + +TEST(MutatingTest, StableSortWithPredicate) { + std::vector test_vector = {{1, 1}, {2, 1}, {2, 0}, {1, 0}, {2, 2}}; + absl::c_stable_sort(test_vector, [](const Element& e1, const Element& e2) { + return e2 < e1; + }); + EXPECT_THAT(test_vector, + ElementsAre(IsElement(2, 1), IsElement(2, 0), IsElement(2, 2), + IsElement(1, 1), IsElement(1, 0))); +} + +TEST(MutatingTest, ReplaceCopyIf) { + const std::vector initial = {1, 2, 3, 4, 5}; + const std::vector expected = {0, 2, 0, 4, 0}; + + std::vector actual; + absl::c_replace_copy_if(initial, back_inserter(actual), IsOdd, 0); + EXPECT_EQ(expected, actual); +} + +TEST(MutatingTest, Fill) { + std::vector actual(5); + absl::c_fill(actual, 1); + EXPECT_THAT(actual, ElementsAre(1, 1, 1, 1, 1)); +} + +TEST(MutatingTest, FillN) { + std::vector actual(5, 0); + absl::c_fill_n(actual, 2, 1); + EXPECT_THAT(actual, ElementsAre(1, 1, 0, 0, 0)); +} + +TEST(MutatingTest, Generate) { + std::vector actual(5); + int x = 0; + absl::c_generate(actual, [&x]() { return ++x; }); + EXPECT_THAT(actual, ElementsAre(1, 2, 3, 4, 5)); +} + +TEST(MutatingTest, GenerateN) { + std::vector actual(5, 0); + int x = 0; + absl::c_generate_n(actual, 3, [&x]() { return ++x; }); + EXPECT_THAT(actual, ElementsAre(1, 2, 3, 0, 0)); +} + +TEST(MutatingTest, RemoveCopy) { + std::vector actual; + absl::c_remove_copy(std::vector{1, 2, 3}, back_inserter(actual), 2); + EXPECT_THAT(actual, ElementsAre(1, 3)); +} + +TEST(MutatingTest, RemoveCopyIf) { + std::vector actual; + absl::c_remove_copy_if(std::vector{1, 2, 3}, back_inserter(actual), + IsOdd); + EXPECT_THAT(actual, ElementsAre(2)); +} + +TEST(MutatingTest, UniqueCopy) { + std::vector actual; + absl::c_unique_copy(std::vector{1, 2, 2, 2, 3, 3, 2}, + back_inserter(actual)); + EXPECT_THAT(actual, ElementsAre(1, 2, 3, 2)); +} + +TEST(MutatingTest, UniqueCopyWithPredicate) { + std::vector actual; + absl::c_unique_copy(std::vector{1, 2, 3, -1, -2, -3, 1}, + back_inserter(actual), + [](int x, int y) { return (x < 0) == (y < 0); }); + EXPECT_THAT(actual, ElementsAre(1, -1, 1)); +} + +TEST(MutatingTest, Reverse) { + std::vector test_vector = {1, 2, 3, 4}; + absl::c_reverse(test_vector); + EXPECT_THAT(test_vector, ElementsAre(4, 3, 2, 1)); + + std::list test_list = {1, 2, 3, 4}; + absl::c_reverse(test_list); + EXPECT_THAT(test_list, ElementsAre(4, 3, 2, 1)); +} + +TEST(MutatingTest, ReverseCopy) { + std::vector actual; + absl::c_reverse_copy(std::vector{1, 2, 3, 4}, back_inserter(actual)); + EXPECT_THAT(actual, ElementsAre(4, 3, 2, 1)); +} + +TEST(MutatingTest, Rotate) { + std::vector actual = {1, 2, 3, 4}; + auto it = absl::c_rotate(actual, actual.begin() + 2); + EXPECT_THAT(actual, testing::ElementsAreArray({3, 4, 1, 2})); + EXPECT_EQ(*it, 1); +} + +TEST(MutatingTest, RotateCopy) { + std::vector initial = {1, 2, 3, 4}; + std::vector actual; + auto end = + absl::c_rotate_copy(initial, initial.begin() + 2, back_inserter(actual)); + *end = 5; + EXPECT_THAT(actual, ElementsAre(3, 4, 1, 2, 5)); +} + +template +T RandomlySeededPrng() { + std::random_device rdev; + std::seed_seq::result_type data[T::state_size]; + std::generate_n(data, T::state_size, std::ref(rdev)); + std::seed_seq prng_seed(data, data + T::state_size); + return T(prng_seed); +} + +TEST(MutatingTest, Shuffle) { + std::vector actual = {1, 2, 3, 4, 5}; + absl::c_shuffle(actual, RandomlySeededPrng()); + EXPECT_THAT(actual, UnorderedElementsAre(1, 2, 3, 4, 5)); +} + +TEST(MutatingTest, Sample) { + std::vector actual; + absl::c_sample(std::vector{1, 2, 3, 4, 5}, std::back_inserter(actual), 3, + RandomlySeededPrng()); + EXPECT_THAT(actual, IsSubsetOf({1, 2, 3, 4, 5})); + EXPECT_THAT(actual, SizeIs(3)); +} + +TEST(MutatingTest, PartialSort) { + std::vector sequence{5, 3, 42, 0}; + absl::c_partial_sort(sequence, sequence.begin() + 2); + EXPECT_THAT(absl::MakeSpan(sequence.data(), 2), ElementsAre(0, 3)); + absl::c_partial_sort(sequence, sequence.begin() + 2, std::greater()); + EXPECT_THAT(absl::MakeSpan(sequence.data(), 2), ElementsAre(42, 5)); +} + +TEST(MutatingTest, PartialSortCopy) { + const std::vector initial = {5, 3, 42, 0}; + std::vector actual(2); + absl::c_partial_sort_copy(initial, actual); + EXPECT_THAT(actual, ElementsAre(0, 3)); + absl::c_partial_sort_copy(initial, actual, std::greater()); + EXPECT_THAT(actual, ElementsAre(42, 5)); +} + +TEST(MutatingTest, Merge) { + std::vector actual; + absl::c_merge(std::vector{1, 3, 5}, std::vector{2, 4}, + back_inserter(actual)); + EXPECT_THAT(actual, ElementsAre(1, 2, 3, 4, 5)); +} + +TEST(MutatingTest, MergeWithComparator) { + std::vector actual; + absl::c_merge(std::vector{5, 3, 1}, std::vector{4, 2}, + back_inserter(actual), std::greater()); + EXPECT_THAT(actual, ElementsAre(5, 4, 3, 2, 1)); +} + +TEST(MutatingTest, InplaceMerge) { + std::vector actual = {1, 3, 5, 2, 4}; + absl::c_inplace_merge(actual, actual.begin() + 3); + EXPECT_THAT(actual, ElementsAre(1, 2, 3, 4, 5)); +} + +TEST(MutatingTest, InplaceMergeWithComparator) { + std::vector actual = {5, 3, 1, 4, 2}; + absl::c_inplace_merge(actual, actual.begin() + 3, std::greater()); + EXPECT_THAT(actual, ElementsAre(5, 4, 3, 2, 1)); +} + +class SetOperationsTest : public testing::Test { + protected: + std::vector a_ = {1, 2, 3}; + std::vector b_ = {1, 3, 5}; + + std::vector a_reversed_ = {3, 2, 1}; + std::vector b_reversed_ = {5, 3, 1}; +}; + +TEST_F(SetOperationsTest, SetUnion) { + std::vector actual; + absl::c_set_union(a_, b_, back_inserter(actual)); + EXPECT_THAT(actual, ElementsAre(1, 2, 3, 5)); +} + +TEST_F(SetOperationsTest, SetUnionWithComparator) { + std::vector actual; + absl::c_set_union(a_reversed_, b_reversed_, back_inserter(actual), + std::greater()); + EXPECT_THAT(actual, ElementsAre(5, 3, 2, 1)); +} + +TEST_F(SetOperationsTest, SetIntersection) { + std::vector actual; + absl::c_set_intersection(a_, b_, back_inserter(actual)); + EXPECT_THAT(actual, ElementsAre(1, 3)); +} + +TEST_F(SetOperationsTest, SetIntersectionWithComparator) { + std::vector actual; + absl::c_set_intersection(a_reversed_, b_reversed_, back_inserter(actual), + std::greater()); + EXPECT_THAT(actual, ElementsAre(3, 1)); +} + +TEST_F(SetOperationsTest, SetDifference) { + std::vector actual; + absl::c_set_difference(a_, b_, back_inserter(actual)); + EXPECT_THAT(actual, ElementsAre(2)); +} + +TEST_F(SetOperationsTest, SetDifferenceWithComparator) { + std::vector actual; + absl::c_set_difference(a_reversed_, b_reversed_, back_inserter(actual), + std::greater()); + EXPECT_THAT(actual, ElementsAre(2)); +} + +TEST_F(SetOperationsTest, SetSymmetricDifference) { + std::vector actual; + absl::c_set_symmetric_difference(a_, b_, back_inserter(actual)); + EXPECT_THAT(actual, ElementsAre(2, 5)); +} + +TEST_F(SetOperationsTest, SetSymmetricDifferenceWithComparator) { + std::vector actual; + absl::c_set_symmetric_difference(a_reversed_, b_reversed_, + back_inserter(actual), std::greater()); + EXPECT_THAT(actual, ElementsAre(5, 2)); +} + +TEST(HeapOperationsTest, WithoutComparator) { + std::vector heap = {1, 2, 3}; + EXPECT_FALSE(absl::c_is_heap(heap)); + absl::c_make_heap(heap); + EXPECT_TRUE(absl::c_is_heap(heap)); + heap.push_back(4); + EXPECT_EQ(3, absl::c_is_heap_until(heap) - heap.begin()); + absl::c_push_heap(heap); + EXPECT_EQ(4, heap[0]); + absl::c_pop_heap(heap); + EXPECT_EQ(4, heap[3]); + absl::c_make_heap(heap); + absl::c_sort_heap(heap); + EXPECT_THAT(heap, ElementsAre(1, 2, 3, 4)); + EXPECT_FALSE(absl::c_is_heap(heap)); +} + +TEST(HeapOperationsTest, WithComparator) { + using greater = std::greater; + std::vector heap = {3, 2, 1}; + EXPECT_FALSE(absl::c_is_heap(heap, greater())); + absl::c_make_heap(heap, greater()); + EXPECT_TRUE(absl::c_is_heap(heap, greater())); + heap.push_back(0); + EXPECT_EQ(3, absl::c_is_heap_until(heap, greater()) - heap.begin()); + absl::c_push_heap(heap, greater()); + EXPECT_EQ(0, heap[0]); + absl::c_pop_heap(heap, greater()); + EXPECT_EQ(0, heap[3]); + absl::c_make_heap(heap, greater()); + absl::c_sort_heap(heap, greater()); + EXPECT_THAT(heap, ElementsAre(3, 2, 1, 0)); + EXPECT_FALSE(absl::c_is_heap(heap, greater())); +} + +TEST(MutatingTest, PermutationOperations) { + std::vector initial = {1, 2, 3, 4}; + std::vector permuted = initial; + + absl::c_next_permutation(permuted); + EXPECT_TRUE(absl::c_is_permutation(initial, permuted)); + EXPECT_TRUE(absl::c_is_permutation(initial, permuted, std::equal_to())); + + std::vector permuted2 = initial; + absl::c_prev_permutation(permuted2, std::greater()); + EXPECT_EQ(permuted, permuted2); + + absl::c_prev_permutation(permuted); + EXPECT_EQ(initial, permuted); +} + +#if defined(ABSL_INTERNAL_CPLUSPLUS_LANG) && \ + ABSL_INTERNAL_CPLUSPLUS_LANG >= 201703L +TEST(ConstexprTest, Distance) { + // Works at compile time with constexpr containers. + static_assert(absl::c_distance(std::array()) == 3); +} + +TEST(ConstexprTest, MinElement) { + constexpr std::array kArray = {1, 2, 3}; + static_assert(*absl::c_min_element(kArray) == 1); +} + +TEST(ConstexprTest, MinElementWithPredicate) { + constexpr std::array kArray = {1, 2, 3}; + static_assert(*absl::c_min_element(kArray, std::greater()) == 3); +} + +TEST(ConstexprTest, MaxElement) { + constexpr std::array kArray = {1, 2, 3}; + static_assert(*absl::c_max_element(kArray) == 3); +} + +TEST(ConstexprTest, MaxElementWithPredicate) { + constexpr std::array kArray = {1, 2, 3}; + static_assert(*absl::c_max_element(kArray, std::greater()) == 1); +} + +TEST(ConstexprTest, MinMaxElement) { + static constexpr std::array kArray = {1, 2, 3}; + constexpr auto kMinMaxPair = absl::c_minmax_element(kArray); + static_assert(*kMinMaxPair.first == 1); + static_assert(*kMinMaxPair.second == 3); +} + +TEST(ConstexprTest, MinMaxElementWithPredicate) { + static constexpr std::array kArray = {1, 2, 3}; + constexpr auto kMinMaxPair = + absl::c_minmax_element(kArray, std::greater()); + static_assert(*kMinMaxPair.first == 3); + static_assert(*kMinMaxPair.second == 1); +} + +#endif // defined(ABSL_INTERNAL_CPLUSPLUS_LANG) && + // ABSL_INTERNAL_CPLUSPLUS_LANG >= 201703L + +} // namespace diff --git a/absl/base/BUILD.bazel b/absl/base/BUILD.bazel index 0eb735d..96503c9 100644 --- a/absl/base/BUILD.bazel +++ b/absl/base/BUILD.bazel @@ -74,7 +74,10 @@ cc_library( hdrs = ["no_destructor.h"], copts = ABSL_DEFAULT_COPTS, linkopts = ABSL_DEFAULT_LINKOPTS, - deps = [":config"], + deps = [ + ":config", + ":nullability", + ], ) cc_library( @@ -84,6 +87,7 @@ cc_library( copts = ABSL_DEFAULT_COPTS, linkopts = ABSL_DEFAULT_LINKOPTS, deps = [ + ":config", ":core_headers", "//absl/meta:type_traits", ], @@ -294,7 +298,7 @@ cc_library( cc_library( name = "atomic_hook_test_helper", - testonly = 1, + testonly = True, srcs = ["internal/atomic_hook_test_helper.cc"], hdrs = ["internal/atomic_hook_test_helper.h"], copts = ABSL_DEFAULT_COPTS, @@ -336,6 +340,18 @@ cc_test( ], ) +cc_test( + name = "c_header_test", + srcs = ["c_header_test.c"], + tags = [ + "no_test_wasm", + ], + deps = [ + ":config", + ":core_headers", + ], +) + cc_library( name = "throw_delegate", srcs = ["internal/throw_delegate.cc"], @@ -380,7 +396,7 @@ cc_test( cc_library( name = "exception_testing", - testonly = 1, + testonly = True, hdrs = ["internal/exception_testing.h"], copts = ABSL_TEST_COPTS, linkopts = ABSL_DEFAULT_LINKOPTS, @@ -404,7 +420,7 @@ cc_library( cc_library( name = "exception_safety_testing", - testonly = 1, + testonly = True, srcs = ["internal/exception_safety_testing.cc"], hdrs = ["internal/exception_safety_testing.h"], copts = ABSL_TEST_COPTS, @@ -470,7 +486,7 @@ cc_test( # AbslInternalSpinLockDelay and AbslInternalSpinLockWake. cc_library( name = "spinlock_test_common", - testonly = 1, + testonly = True, srcs = ["spinlock_test_common.cc"], copts = ABSL_TEST_COPTS, linkopts = ABSL_DEFAULT_LINKOPTS, @@ -507,7 +523,7 @@ cc_test( cc_library( name = "spinlock_benchmark_common", - testonly = 1, + testonly = True, srcs = ["internal/spinlock_benchmark.cc"], copts = ABSL_TEST_COPTS, linkopts = ABSL_DEFAULT_LINKOPTS, @@ -527,7 +543,7 @@ cc_library( cc_binary( name = "spinlock_benchmark", - testonly = 1, + testonly = True, copts = ABSL_DEFAULT_COPTS, linkopts = ABSL_DEFAULT_LINKOPTS, tags = ["benchmark"], @@ -608,7 +624,7 @@ cc_test( cc_binary( name = "no_destructor_benchmark", - testonly = 1, + testonly = True, srcs = ["no_destructor_benchmark.cc"], copts = ABSL_TEST_COPTS, linkopts = ABSL_DEFAULT_LINKOPTS, @@ -710,7 +726,7 @@ cc_test( cc_library( name = "scoped_set_env", - testonly = 1, + testonly = True, srcs = ["internal/scoped_set_env.cc"], hdrs = ["internal/scoped_set_env.h"], linkopts = ABSL_DEFAULT_LINKOPTS, @@ -784,7 +800,7 @@ cc_test( cc_binary( name = "strerror_benchmark", - testonly = 1, + testonly = True, srcs = ["internal/strerror_benchmark.cc"], copts = ABSL_TEST_COPTS, linkopts = ABSL_DEFAULT_LINKOPTS, @@ -850,6 +866,41 @@ cc_test( ], ) +cc_library( + name = "poison", + srcs = [ + "internal/poison.cc", + ], + hdrs = ["internal/poison.h"], + copts = ABSL_DEFAULT_COPTS, + linkopts = ABSL_DEFAULT_LINKOPTS, + visibility = [ + "//absl:__subpackages__", + ], + deps = [ + ":config", + ":core_headers", + ":malloc_internal", + ], +) + +cc_test( + name = "poison_test", + size = "small", + timeout = "short", + srcs = [ + "internal/poison_test.cc", + ], + copts = ABSL_TEST_COPTS, + linkopts = ABSL_DEFAULT_LINKOPTS, + deps = [ + ":config", + ":poison", + "@com_google_googletest//:gtest", + "@com_google_googletest//:gtest_main", + ], +) + cc_test( name = "unique_small_name_test", size = "small", diff --git a/absl/base/CMakeLists.txt b/absl/base/CMakeLists.txt index 4cfc228..97994fc 100644 --- a/absl/base/CMakeLists.txt +++ b/absl/base/CMakeLists.txt @@ -62,6 +62,7 @@ absl_cc_library( "no_destructor.h" DEPS absl::config + absl::nullability COPTS ${ABSL_DEFAULT_COPTS} ) @@ -74,6 +75,7 @@ absl_cc_library( SRCS "internal/nullability_impl.h" DEPS + absl::config absl::core_headers absl::type_traits COPTS @@ -737,3 +739,33 @@ absl_cc_test( absl::optional GTest::gtest_main ) + +absl_cc_library( + NAME + poison + SRCS + "internal/poison.cc" + HDRS + "internal/poison.h" + COPTS + ${ABSL_DEFAULT_COPTS} + LINKOPTS + ${ABSL_DEFAULT_LINKOPTS} + DEPS + absl::config + absl::core_headers + absl::malloc_internal +) + +absl_cc_test( + NAME + poison_test + SRCS + "internal/poison_test.cc" + COPTS + ${ABSL_TEST_COPTS} + DEPS + absl::config + absl::poison + GTest::gtest_main +) diff --git a/absl/base/attributes.h b/absl/base/attributes.h index d4f67a1..5ea5ee3 100644 --- a/absl/base/attributes.h +++ b/absl/base/attributes.h @@ -195,6 +195,9 @@ // ABSL_ATTRIBUTE_NORETURN // // Tells the compiler that a given function never returns. +// +// Deprecated: Prefer the `[[noreturn]]` attribute standardized by C++11 over +// this macro. #if ABSL_HAVE_ATTRIBUTE(noreturn) || (defined(__GNUC__) && !defined(__clang__)) #define ABSL_ATTRIBUTE_NORETURN __attribute__((noreturn)) #elif defined(_MSC_VER) @@ -702,6 +705,11 @@ _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"") #define ABSL_INTERNAL_RESTORE_DEPRECATED_DECLARATION_WARNING \ _Pragma("GCC diagnostic pop") +#elif defined(_MSC_VER) +#define ABSL_INTERNAL_DISABLE_DEPRECATED_DECLARATION_WARNING \ + _Pragma("warning(push)") _Pragma("warning(disable: 4996)") +#define ABSL_INTERNAL_RESTORE_DEPRECATED_DECLARATION_WARNING \ + _Pragma("warning(pop)") #else #define ABSL_INTERNAL_DISABLE_DEPRECATED_DECLARATION_WARNING #define ABSL_INTERNAL_RESTORE_DEPRECATED_DECLARATION_WARNING @@ -808,14 +816,43 @@ // // See also the upstream documentation: // https://clang.llvm.org/docs/AttributeReference.html#lifetimebound +// https://learn.microsoft.com/en-us/cpp/code-quality/c26816?view=msvc-170 #if ABSL_HAVE_CPP_ATTRIBUTE(clang::lifetimebound) #define ABSL_ATTRIBUTE_LIFETIME_BOUND [[clang::lifetimebound]] +#elif ABSL_HAVE_CPP_ATTRIBUTE(msvc::lifetimebound) +#define ABSL_ATTRIBUTE_LIFETIME_BOUND [[msvc::lifetimebound]] #elif ABSL_HAVE_ATTRIBUTE(lifetimebound) #define ABSL_ATTRIBUTE_LIFETIME_BOUND __attribute__((lifetimebound)) #else #define ABSL_ATTRIBUTE_LIFETIME_BOUND #endif +// ABSL_INTERNAL_ATTRIBUTE_VIEW indicates that a type acts like a view i.e. a +// raw (non-owning) pointer. This enables diagnoses similar to those enabled by +// ABSL_ATTRIBUTE_LIFETIME_BOUND. +// +// See the following links for details: +// https://reviews.llvm.org/D64448 +// https://lists.llvm.org/pipermail/cfe-dev/2018-November/060355.html +#if ABSL_HAVE_CPP_ATTRIBUTE(gsl::Pointer) +#define ABSL_INTERNAL_ATTRIBUTE_VIEW [[gsl::Pointer]] +#else +#define ABSL_INTERNAL_ATTRIBUTE_VIEW +#endif + +// ABSL_INTERNAL_ATTRIBUTE_OWNER indicates that a type acts like a smart +// (owning) pointer. This enables diagnoses similar to those enabled by +// ABSL_ATTRIBUTE_LIFETIME_BOUND. +// +// See the following links for details: +// https://reviews.llvm.org/D64448 +// https://lists.llvm.org/pipermail/cfe-dev/2018-November/060355.html +#if ABSL_HAVE_CPP_ATTRIBUTE(gsl::Owner) +#define ABSL_INTERNAL_ATTRIBUTE_OWNER [[gsl::Owner]] +#else +#define ABSL_INTERNAL_ATTRIBUTE_OWNER +#endif + // ABSL_ATTRIBUTE_TRIVIAL_ABI // Indicates that a type is "trivially relocatable" -- meaning it can be // relocated without invoking the constructor/destructor, using a form of move @@ -871,4 +908,51 @@ #define ABSL_ATTRIBUTE_NO_UNIQUE_ADDRESS #endif +// ABSL_ATTRIBUTE_UNINITIALIZED +// +// GCC and Clang support a flag `-ftrivial-auto-var-init=