diff options
Diffstat (limited to 'absl')
-rw-r--r-- | absl/CMakeLists.txt | 1 | ||||
-rw-r--r-- | absl/base/BUILD.bazel | 3 | ||||
-rw-r--r-- | absl/base/CMakeLists.txt | 2 | ||||
-rw-r--r-- | absl/base/internal/invoke.h | 37 | ||||
-rw-r--r-- | absl/base/invoke_test.cc | 21 | ||||
-rw-r--r-- | absl/copts/AbseilConfigureCopts.cmake | 5 | ||||
-rw-r--r-- | absl/meta/type_traits.h | 17 | ||||
-rw-r--r-- | absl/meta/type_traits_test.cc | 16 | ||||
-rw-r--r-- | absl/random/CMakeLists.txt | 1034 | ||||
-rw-r--r-- | absl/random/internal/salted_seed_seq.h | 8 | ||||
-rw-r--r-- | absl/strings/str_split_benchmark.cc | 23 | ||||
-rw-r--r-- | absl/types/optional.h | 4 |
12 files changed, 1145 insertions, 26 deletions
diff --git a/absl/CMakeLists.txt b/absl/CMakeLists.txt index bd13eef4..3e78397c 100644 --- a/absl/CMakeLists.txt +++ b/absl/CMakeLists.txt @@ -25,6 +25,7 @@ add_subdirectory(hash) add_subdirectory(memory) add_subdirectory(meta) add_subdirectory(numeric) +add_subdirectory(random) add_subdirectory(strings) add_subdirectory(synchronization) add_subdirectory(time) diff --git a/absl/base/BUILD.bazel b/absl/base/BUILD.bazel index e825de0c..a512272a 100644 --- a/absl/base/BUILD.bazel +++ b/absl/base/BUILD.bazel @@ -155,6 +155,9 @@ cc_library( visibility = [ "//absl:__subpackages__", ], + deps = [ + "//absl/meta:type_traits", + ], ) cc_library( diff --git a/absl/base/CMakeLists.txt b/absl/base/CMakeLists.txt index 9ff80738..cc7960e3 100644 --- a/absl/base/CMakeLists.txt +++ b/absl/base/CMakeLists.txt @@ -133,6 +133,8 @@ absl_cc_library( "internal/invoke.h" COPTS ${ABSL_DEFAULT_COPTS} + DEPS + absl::type_traits ) absl_cc_library( diff --git a/absl/base/internal/invoke.h b/absl/base/internal/invoke.h index 8da2869a..44f13302 100644 --- a/absl/base/internal/invoke.h +++ b/absl/base/internal/invoke.h @@ -39,6 +39,8 @@ #include <type_traits> #include <utility> +#include "absl/meta/type_traits.h" + // The following code is internal implementation detail. See the comment at the // top of this file for the API documentation. @@ -67,15 +69,11 @@ struct MemFunAndRef : StrippedAccept<MemFunAndRef> { template <typename... Args> struct AcceptImpl : std::false_type {}; - template <typename R, typename C, typename... Params, typename Obj, - typename... Args> - struct AcceptImpl<R (C::*)(Params...), Obj, Args...> - : std::is_base_of<C, Obj> {}; - - template <typename R, typename C, typename... Params, typename Obj, - typename... Args> - struct AcceptImpl<R (C::*)(Params...) const, Obj, Args...> - : std::is_base_of<C, Obj> {}; + template <typename MemFunType, typename C, typename Obj, typename... Args> + struct AcceptImpl<MemFunType C::*, Obj, Args...> + : std::integral_constant<bool, std::is_base_of<C, Obj>::value && + absl::is_function<MemFunType>::value> { + }; template <typename MemFun, typename Obj, typename... Args> static decltype((std::declval<Obj>().* @@ -92,15 +90,11 @@ struct MemFunAndPtr : StrippedAccept<MemFunAndPtr> { template <typename... Args> struct AcceptImpl : std::false_type {}; - template <typename R, typename C, typename... Params, typename Ptr, - typename... Args> - struct AcceptImpl<R (C::*)(Params...), Ptr, Args...> - : std::integral_constant<bool, !std::is_base_of<C, Ptr>::value> {}; - - template <typename R, typename C, typename... Params, typename Ptr, - typename... Args> - struct AcceptImpl<R (C::*)(Params...) const, Ptr, Args...> - : std::integral_constant<bool, !std::is_base_of<C, Ptr>::value> {}; + template <typename MemFunType, typename C, typename Ptr, typename... Args> + struct AcceptImpl<MemFunType C::*, Ptr, Args...> + : std::integral_constant<bool, !std::is_base_of<C, Ptr>::value && + absl::is_function<MemFunType>::value> { + }; template <typename MemFun, typename Ptr, typename... Args> static decltype(((*std::declval<Ptr>()).* @@ -119,7 +113,9 @@ struct DataMemAndRef : StrippedAccept<DataMemAndRef> { struct AcceptImpl : std::false_type {}; template <typename R, typename C, typename Obj> - struct AcceptImpl<R C::*, Obj> : std::is_base_of<C, Obj> {}; + struct AcceptImpl<R C::*, Obj> + : std::integral_constant<bool, std::is_base_of<C, Obj>::value && + !absl::is_function<R>::value> {}; template <typename DataMem, typename Ref> static decltype(std::declval<Ref>().*std::declval<DataMem>()) Invoke( @@ -136,7 +132,8 @@ struct DataMemAndPtr : StrippedAccept<DataMemAndPtr> { template <typename R, typename C, typename Ptr> struct AcceptImpl<R C::*, Ptr> - : std::integral_constant<bool, !std::is_base_of<C, Ptr>::value> {}; + : std::integral_constant<bool, !std::is_base_of<C, Ptr>::value && + !absl::is_function<R>::value> {}; template <typename DataMem, typename Ptr> static decltype((*std::declval<Ptr>()).*std::declval<DataMem>()) Invoke( diff --git a/absl/base/invoke_test.cc b/absl/base/invoke_test.cc index 691f5537..9074443b 100644 --- a/absl/base/invoke_test.cc +++ b/absl/base/invoke_test.cc @@ -70,6 +70,10 @@ struct OverloadedFunctor { struct Class { int Method(int a, int b) { return a - b; } int ConstMethod(int a, int b) const { return a - b; } + int RefMethod(int a, int b) & { return a - b; } + int RefRefMethod(int a, int b) && { return a - b; } + int NoExceptMethod(int a, int b) noexcept { return a - b; } + int VolatileMethod(int a, int b) volatile { return a - b; } int member; }; @@ -151,8 +155,18 @@ TEST(InvokeTest, ReferenceWrapper) { TEST(InvokeTest, MemberFunction) { std::unique_ptr<Class> p(new Class); std::unique_ptr<const Class> cp(new Class); + std::unique_ptr<volatile Class> vp(new Class); + EXPECT_EQ(1, Invoke(&Class::Method, p, 3, 2)); EXPECT_EQ(1, Invoke(&Class::Method, p.get(), 3, 2)); + EXPECT_EQ(1, Invoke(&Class::Method, *p, 3, 2)); + EXPECT_EQ(1, Invoke(&Class::RefMethod, p, 3, 2)); + EXPECT_EQ(1, Invoke(&Class::RefMethod, p.get(), 3, 2)); + EXPECT_EQ(1, Invoke(&Class::RefMethod, *p, 3, 2)); + EXPECT_EQ(1, Invoke(&Class::RefRefMethod, std::move(*p), 3, 2)); // NOLINT + EXPECT_EQ(1, Invoke(&Class::NoExceptMethod, p, 3, 2)); + EXPECT_EQ(1, Invoke(&Class::NoExceptMethod, p.get(), 3, 2)); + EXPECT_EQ(1, Invoke(&Class::NoExceptMethod, *p, 3, 2)); EXPECT_EQ(1, Invoke(&Class::ConstMethod, p, 3, 2)); EXPECT_EQ(1, Invoke(&Class::ConstMethod, p.get(), 3, 2)); @@ -162,6 +176,13 @@ TEST(InvokeTest, MemberFunction) { EXPECT_EQ(1, Invoke(&Class::ConstMethod, cp.get(), 3, 2)); EXPECT_EQ(1, Invoke(&Class::ConstMethod, *cp, 3, 2)); + EXPECT_EQ(1, Invoke(&Class::VolatileMethod, p, 3, 2)); + EXPECT_EQ(1, Invoke(&Class::VolatileMethod, p.get(), 3, 2)); + EXPECT_EQ(1, Invoke(&Class::VolatileMethod, *p, 3, 2)); + EXPECT_EQ(1, Invoke(&Class::VolatileMethod, vp, 3, 2)); + EXPECT_EQ(1, Invoke(&Class::VolatileMethod, vp.get(), 3, 2)); + EXPECT_EQ(1, Invoke(&Class::VolatileMethod, *vp, 3, 2)); + EXPECT_EQ(1, Invoke(&Class::Method, make_unique<Class>(), 3, 2)); EXPECT_EQ(1, Invoke(&Class::ConstMethod, make_unique<Class>(), 3, 2)); EXPECT_EQ(1, Invoke(&Class::ConstMethod, make_unique<const Class>(), 3, 2)); diff --git a/absl/copts/AbseilConfigureCopts.cmake b/absl/copts/AbseilConfigureCopts.cmake index 6394c15b..4ece4c6f 100644 --- a/absl/copts/AbseilConfigureCopts.cmake +++ b/absl/copts/AbseilConfigureCopts.cmake @@ -9,6 +9,7 @@ if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") set(ABSL_DEFAULT_COPTS "${ABSL_GCC_FLAGS}") set(ABSL_TEST_COPTS "${ABSL_GCC_FLAGS};${ABSL_GCC_TEST_FLAGS}") set(ABSL_EXCEPTIONS_FLAG "${ABSL_GCC_EXCEPTIONS_FLAGS}") + set(ABSL_RANDOM_RANDEN_COPTS "${ABSL_RANDOM_HWAES_X64_FLAGS}") elseif("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") # MATCHES so we get both Clang and AppleClang if(MSVC) @@ -17,10 +18,12 @@ elseif("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") set(ABSL_TEST_COPTS "${ABSL_CLANG_CL_FLAGS};${ABSL_CLANG_CL_TEST_FLAGS}") set(ABSL_EXCEPTIONS_FLAG "${ABSL_CLANG_CL_EXCEPTIONS_FLAGS}") set(ABSL_DEFAULT_LINKOPTS "${ABSL_MSVC_LINKOPTS}") + set(ABSL_RANDOM_RANDEN_COPTS "${ABSL_RANDOM_HWAES_MSVC_X64_FLAGS}") else() set(ABSL_DEFAULT_COPTS "${ABSL_LLVM_FLAGS}") set(ABSL_TEST_COPTS "${ABSL_LLVM_FLAGS};${ABSL_LLVM_TEST_FLAGS}") set(ABSL_EXCEPTIONS_FLAG "${ABSL_LLVM_EXCEPTIONS_FLAGS}") + set(ABSL_RANDOM_RANDEN_COPTS "${ABSL_RANDOM_HWAES_X64_FLAGS}") if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") # AppleClang doesn't have lsan # https://developer.apple.com/documentation/code_diagnostics @@ -35,11 +38,13 @@ elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") set(ABSL_TEST_COPTS "${ABSL_MSVC_FLAGS};${ABSL_MSVC_TEST_FLAGS}") set(ABSL_EXCEPTIONS_FLAG "${ABSL_MSVC_EXCEPTIONS_FLAGS}") set(ABSL_DEFAULT_LINKOPTS "${ABSL_MSVC_LINKOPTS}") + set(ABSL_RANDOM_RANDEN_COPTS "${ABSL_RANDOM_HWAES_MSVC_X64_FLAGS}") else() message(WARNING "Unknown compiler: ${CMAKE_CXX_COMPILER}. Building with no default flags") set(ABSL_DEFAULT_COPTS "") set(ABSL_TEST_COPTS "") set(ABSL_EXCEPTIONS_FLAG "") + set(ABSL_RANDOM_RANDEN_COPTS "") endif() # This flag is used internally for Bazel builds and is kept here for consistency diff --git a/absl/meta/type_traits.h b/absl/meta/type_traits.h index c08e3754..927244e0 100644 --- a/absl/meta/type_traits.h +++ b/absl/meta/type_traits.h @@ -224,6 +224,23 @@ struct disjunction<> : std::false_type {}; template <typename T> struct negation : std::integral_constant<bool, !T::value> {}; +// is_function() +// +// Determines whether the passed type `T` is a function type. +// +// This metafunction is designed to be a drop-in replacement for the C++11 +// `std::is_function()` metafunction for platforms that have incomplete C++11 +// support (such as libstdc++ 4.x). +// +// This metafunction works because appending `const` to a type does nothing to +// function types and reference types (and forms a const-qualified type +// otherwise). +template <typename T> +struct is_function + : std::integral_constant< + bool, !(std::is_reference<T>::value || + std::is_const<typename std::add_const<T>::type>::value)> {}; + // is_trivially_destructible() // // Determines whether the passed type `T` is trivially destructable. diff --git a/absl/meta/type_traits_test.cc b/absl/meta/type_traits_test.cc index 82b1be51..a7a9c5c9 100644 --- a/absl/meta/type_traits_test.cc +++ b/absl/meta/type_traits_test.cc @@ -385,6 +385,22 @@ class Base { #define ABSL_GCC_BUG_TRIVIALLY_CONSTRUCTIBLE_ON_ARRAY_OF_NONTRIVIAL 1 #endif +TEST(TypeTraitsTest, TestIsFunction) { + struct Callable { + void operator()() {} + }; + EXPECT_TRUE(absl::is_function<void()>::value); + EXPECT_TRUE(absl::is_function<void()&>::value); + EXPECT_TRUE(absl::is_function<void() const>::value); + EXPECT_TRUE(absl::is_function<void() noexcept>::value); + EXPECT_TRUE(absl::is_function<void(...) noexcept>::value); + + EXPECT_FALSE(absl::is_function<void(*)()>::value); + EXPECT_FALSE(absl::is_function<void(&)()>::value); + EXPECT_FALSE(absl::is_function<int>::value); + EXPECT_FALSE(absl::is_function<Callable>::value); +} + TEST(TypeTraitsTest, TestTrivialDestructor) { // Verify that arithmetic types and pointers have trivial destructors. EXPECT_TRUE(absl::is_trivially_destructible<bool>::value); diff --git a/absl/random/CMakeLists.txt b/absl/random/CMakeLists.txt new file mode 100644 index 00000000..2d5c0658 --- /dev/null +++ b/absl/random/CMakeLists.txt @@ -0,0 +1,1034 @@ +# +# Copyright 2019 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. +# + +absl_cc_library( + NAME + random_random + HDRS + "random.h" + COPTS + ${ABSL_DEFAULT_COPTS} + LINKOPTS + ${ABSL_DEFAULT_LINKOPTS} + DEPS + absl::random_distributions + absl::random_internal_nonsecure_base + absl::random_internal_pcg_engine + absl::random_internal_pool_urbg + absl::random_internal_randen_engine + absl::random_seed_sequences +) + +absl_cc_library( + NAME + random_distributions + SRCS + "discrete_distribution.cc" + "gaussian_distribution.cc" + HDRS + "bernoulli_distribution.h" + "beta_distribution.h" + "discrete_distribution.h" + "distribution_format_traits.h" + "distributions.h" + "exponential_distribution.h" + "gaussian_distribution.h" + "log_uniform_int_distribution.h" + "poisson_distribution.h" + "uniform_int_distribution.h" + "uniform_real_distribution.h" + "zipf_distribution.h" + COPTS + ${ABSL_DEFAULT_COPTS} + LINKOPTS + ${ABSL_DEFAULT_LINKOPTS} + DEPS + absl::base_internal + absl::core_headers + absl::random_internal_distribution_impl + absl::random_internal_distributions + absl::random_internal_fast_uniform_bits + absl::random_internal_fastmath + absl::random_internal_iostream_state_saver + absl::random_internal_traits + absl::random_internal_uniform_helper + absl::strings + absl::span + absl::type_traits +) + +absl_cc_library( + NAME + random_seed_gen_exception + SRCS + "seed_gen_exception.cc" + HDRS + "seed_gen_exception.h" + COPTS + ${ABSL_DEFAULT_COPTS} + ${ABSL_EXCEPTIONS_FLAG} + LINKOPTS + ${ABSL_EXCEPTIONS_FLAG_LINKOPTS} + ${ABSL_DEFAULT_LINKOPTS} + DEPS + absl::config +) + +absl_cc_library( + NAME + random_seed_sequences + SRCS + "seed_sequences.cc" + HDRS + "seed_sequences.h" + COPTS + ${ABSL_DEFAULT_COPTS} + LINKOPTS + ${ABSL_DEFAULT_LINKOPTS} + DEPS + absl::inlined_vector + absl::random_internal_nonsecure_base + absl::random_internal_pool_urbg + absl::random_internal_salted_seed_seq + absl::random_internal_seed_material + absl::random_seed_gen_exception + absl::span +) + +absl_cc_test( + NAME + random_bernoulli_distribution_test + SRCS + "bernoulli_distribution_test.cc" + COPTS + ${ABSL_TEST_COPTS} + LINKOPTS + ${ABSL_DEFAULT_LINKOPTS} + DEPS + absl::random_distributions + absl::random_random + absl::random_internal_sequence_urbg + gmock + gtest_main +) + +absl_cc_test( + NAME + random_beta_distribution_test + SRCS + "beta_distribution_test.cc" + COPTS + ${ABSL_TEST_COPTS} + LINKOPTS + ${ABSL_DEFAULT_LINKOPTS} + DEPS + absl::random_distributions + absl::random_random + absl::base + absl::random_internal_distribution_test_util + absl::random_internal_sequence_urbg + absl::strings + absl::str_format + gmock + gtest_main +) + +absl_cc_test( + NAME + random_distributions_test + SRCS + "distributions_test.cc" + COPTS + ${ABSL_TEST_COPTS} + LINKOPTS + ${ABSL_DEFAULT_LINKOPTS} + DEPS + absl::random_distributions + absl::random_random + absl::random_internal_distribution_test_util + gmock + gtest_main +) + +absl_cc_test( + NAME + random_generators_test + SRCS + "generators_test.cc" + COPTS + ${ABSL_TEST_COPTS} + LINKOPTS + ${ABSL_DEFAULT_LINKOPTS} + absl::random_distributions + absl::random_random + gmock + gtest_main +) + +absl_cc_test( + NAME + random_log_uniform_int_distribution_test + SRCS + "log_uniform_int_distribution_test.cc" + COPTS + ${ABSL_TEST_COPTS} + LINKOPTS + ${ABSL_DEFAULT_LINKOPTS} + absl::base + absl::core_headers + absl::random_distributions + absl::random_internal_distribution_test_util + absl::random_internal_sequence_urbg + absl::random_random + absl::strings + absl::str_format + gmock + gtest_main +) + +absl_cc_test( + NAME + random_discrete_distribution_test + SRCS + "discrete_distribution_test.cc" + COPTS + ${ABSL_TEST_COPTS} + LINKOPTS + ${ABSL_DEFAULT_LINKOPTS} + DEPS + absl::base + absl::random_distributions + absl::random_internal_distribution_test_util + absl::random_internal_sequence_urbg + absl::random_random + absl::strings + gmock + gtest_main +) + +absl_cc_test( + NAME + random_poisson_distribution_test + SRCS + "poisson_distribution_test.cc" + COPTS + ${ABSL_TEST_COPTS} + LINKOPTS + ${ABSL_DEFAULT_LINKOPTS} + DEPS + absl::random_distributions + absl::random_random + absl::base + absl::core_headers + absl::flat_hash_map + absl::random_internal_distribution_test_util + absl::random_internal_sequence_urbg + absl::strings + absl::str_format + gmock + gtest_main +) + +absl_cc_test( + NAME + random_exponential_distribution_test + SRCS + "exponential_distribution_test.cc" + COPTS + ${ABSL_TEST_COPTS} + LINKOPTS + ${ABSL_DEFAULT_LINKOPTS} + DEPS + absl::base + absl::core_headers + absl::random_distributions + absl::random_internal_distribution_test_util + absl::random_internal_sequence_urbg + absl::random_random + absl::strings + absl::str_format + gmock + gtest_main +) + +absl_cc_test( + NAME + random_gaussian_distribution_test + SRCS + "gaussian_distribution_test.cc" + COPTS + ${ABSL_TEST_COPTS} + LINKOPTS + ${ABSL_DEFAULT_LINKOPTS} + DEPS + absl::base + absl::core_headers + absl::random_distributions + absl::random_internal_distribution_test_util + absl::random_internal_sequence_urbg + absl::random_random + absl::strings + absl::str_format + gmock + gtest_main +) + +absl_cc_test( + NAME + random_uniform_int_distribution_test + SRCS + "uniform_int_distribution_test.cc" + COPTS + ${ABSL_TEST_COPTS} + LINKOPTS + ${ABSL_DEFAULT_LINKOPTS} + DEPS + absl::base + absl::random_distributions + absl::random_internal_distribution_test_util + absl::random_internal_sequence_urbg + absl::random_random + absl::strings + gmock + gtest_main +) + +absl_cc_test( + NAME + random_uniform_real_distribution_test + SRCS + "uniform_real_distribution_test.cc" + COPTS + ${ABSL_TEST_COPTS} + LINKOPTS + ${ABSL_DEFAULT_LINKOPTS} + DEPS + absl::base + absl::random_distributions + absl::random_internal_distribution_test_util + absl::random_internal_sequence_urbg + absl::random_random + absl::strings + gmock + gtest_main +) + +absl_cc_test( + NAME + random_zipf_distribution_test + SRCS + "zipf_distribution_test.cc" + COPTS + ${ABSL_TEST_COPTS} + LINKOPTS + ${ABSL_DEFAULT_LINKOPTS} + DEPS + absl::base + absl::random_distributions + absl::random_internal_distribution_test_util + absl::random_internal_sequence_urbg + absl::random_random + absl::strings + gmock + gtest_main +) + +absl_cc_test( + NAME + random_examples_test + SRCS + "examples_test.cc" + COPTS + ${ABSL_TEST_COPTS} + LINKOPTS + ${ABSL_DEFAULT_LINKOPTS} + DEPS + absl::random_random + gtest_main +) + +absl_cc_test( + NAME + random_seed_sequences_test + SRCS + "seed_sequences_test.cc" + COPTS + ${ABSL_TEST_COPTS} + LINKOPTS + ${ABSL_DEFAULT_LINKOPTS} + DEPS + absl::random_seed_sequences + absl::random_internal_nonsecure_base + absl::random_random + gmock + gtest_main +) + +# Internal-only target, do not depend on directly. +absl_cc_library( + NAME + random_internal_traits + HDRS + "internal/traits.h" + COPTS + ${ABSL_DEFAULT_COPTS} + LINKOPTS + ${ABSL_DEFAULT_LINKOPTS} + DEPS + absl::config +) + +# Internal-only target, do not depend on directly. +absl_cc_library( + NAME + random_internal_distribution_caller + HDRS + "internal/distribution_caller.h" + COPTS + ${ABSL_DEFAULT_COPTS} + LINKOPTS + ${ABSL_DEFAULT_LINKOPTS} +) + +# Internal-only target, do not depend on directly. +absl_cc_library( + NAME + random_internal_distributions + HDRS + "internal/distributions.h" + COPTS + ${ABSL_DEFAULT_COPTS} + LINKOPTS + ${ABSL_DEFAULT_LINKOPTS} + DEPS + absl::random_internal_distribution_caller + absl::random_internal_fast_uniform_bits + absl::random_internal_fastmath + absl::random_internal_traits + absl::random_internal_uniform_helper + absl::span + absl::strings + absl::type_traits +) + +# Internal-only target, do not depend on directly. +absl_cc_library( + NAME + random_internal_fast_uniform_bits + HDRS + "internal/fast_uniform_bits.h" + COPTS + ${ABSL_DEFAULT_COPTS} + LINKOPTS + ${ABSL_DEFAULT_LINKOPTS} +) + +# Internal-only target, do not depend on directly. +absl_cc_library( + NAME + random_internal_seed_material + SRCS + "internal/seed_material.cc" + HDRS + "internal/seed_material.h" + COPTS + ${ABSL_DEFAULT_COPTS} + LINKOPTS + ${ABSL_DEFAULT_LINKOPTS} + DEPS + absl::base + absl::core_headers + absl::optional + absl::random_internal_fast_uniform_bits + absl::span + absl::strings +) + +# Internal-only target, do not depend on directly. +absl_cc_library( + NAME + random_internal_pool_urbg + SRCS + "internal/pool_urbg.cc" + HDRS + "internal/pool_urbg.h" + COPTS + ${ABSL_DEFAULT_COPTS} + LINKOPTS + ${ABSL_DEFAULT_LINKOPTS} + DEPS + absl::base + absl::config + absl::core_headers + absl::endian + absl::random_internal_randen + absl::random_internal_seed_material + absl::random_internal_traits + absl::random_seed_gen_exception + absl::span +) + +# Internal-only target, do not depend on directly. +absl_cc_library( + NAME + random_internal_explicit_seed_seq + HDRS + "internal/random_internal_explicit_seed_seq.h" + COPTS + ${ABSL_DEFAULT_COPTS} + LINKOPTS + ${ABSL_DEFAULT_LINKOPTS} + TESTONLY +) + +# Internal-only target, do not depend on directly. +absl_cc_library( + NAME + random_internal_sequence_urbg + HDRS + "internal/sequence_urbg.h" + COPTS + ${ABSL_DEFAULT_COPTS} + LINKOPTS + ${ABSL_DEFAULT_LINKOPTS} + TESTONLY +) + +# Internal-only target, do not depend on directly. +absl_cc_library( + NAME + random_internal_salted_seed_seq + HDRS + "internal/salted_seed_seq.h" + COPTS + ${ABSL_DEFAULT_COPTS} + LINKOPTS + ${ABSL_DEFAULT_LINKOPTS} + DEPS + absl::inlined_vector + absl::optional + absl::span + absl::random_internal_seed_material + absl::type_traits +) + +# Internal-only target, do not depend on directly. +absl_cc_library( + NAME + random_internal_iostream_state_saver + HDRS + "internal/iostream_state_saver.h" + COPTS + ${ABSL_DEFAULT_COPTS} + LINKOPTS + ${ABSL_DEFAULT_LINKOPTS} + DEPS + absl::int128 + absl::type_traits +) + +# Internal-only target, do not depend on directly. +absl_cc_library( + NAME + random_internal_distribution_impl + HDRS + "internal/distribution_impl.h" + COPTS + ${ABSL_DEFAULT_COPTS} + LINKOPTS + ${ABSL_DEFAULT_LINKOPTS} + DEPS + absl::bits + absl::config + absl::int128 + absl::random_internal_fastmath + absl::random_internal_traits +) + +# Internal-only target, do not depend on directly. +absl_cc_library( + NAME + random_internal_fastmath + HDRS + "internal/fastmath.h" + COPTS + ${ABSL_DEFAULT_COPTS} + LINKOPTS + ${ABSL_DEFAULT_LINKOPTS} + DEPS + absl::bits +) + +# Internal-only target, do not depend on directly. +absl_cc_library( + NAME + random_internal_nonsecure_base + HDRS + "internal/nonsecure_base.h" + COPTS + ${ABSL_DEFAULT_COPTS} + LINKOPTS + ${ABSL_DEFAULT_LINKOPTS} + DEPS + absl::core_headers + absl::optional + absl::random_internal_pool_urbg + absl::random_internal_salted_seed_seq + absl::random_internal_seed_material + absl::span + absl::strings + absl::type_traits +) + +# Internal-only target, do not depend on directly. +absl_cc_library( + NAME + random_internal_pcg_engine + HDRS + "internal/pcg_engine.h" + COPTS + ${ABSL_DEFAULT_COPTS} + LINKOPTS + ${ABSL_DEFAULT_LINKOPTS} + DEPS + absl::config + absl::int128 + absl::random_internal_fastmath + absl::random_internal_iostream_state_saver + absl::type_traits +) + +# Internal-only target, do not depend on directly. +absl_cc_library( + NAME + random_internal_randen_engine + HDRS + "internal/randen_engine.h" + COPTS + ${ABSL_DEFAULT_COPTS} + LINKOPTS + ${ABSL_DEFAULT_LINKOPTS} + DEPS + absl::random_internal_iostream_state_saver + absl::random_internal_randen + absl::type_traits +) + +# Internal-only target, do not depend on directly. +absl_cc_library( + NAME + random_internal_platform + HDRS + "internal/randen_traits.h" + "internal/randen-keys.inc" + "internal/platform.h" + COPTS + ${ABSL_DEFAULT_COPTS} + LINKOPTS + ${ABSL_DEFAULT_LINKOPTS} +) + +# Internal-only target, do not depend on directly. +absl_cc_library( + NAME + random_internal_randen + SRCS + "internal/randen.cc" + HDRS + "internal/randen.h" + COPTS + ${ABSL_DEFAULT_COPTS} + LINKOPTS + ${ABSL_DEFAULT_LINKOPTS} + DEPS + absl::base + absl::random_internal_platform + absl::random_internal_randen_hwaes + absl::random_internal_randen_slow +) + +# Internal-only target, do not depend on directly. +absl_cc_library( + NAME + random_internal_randen_slow + SRCS + "internal/randen_slow.cc" + HDRS + "internal/randen_slow.h" + COPTS + ${ABSL_DEFAULT_COPTS} + LINKOPTS + ${ABSL_DEFAULT_LINKOPTS} + DEPS + absl::random_internal_platform +) + +# Internal-only target, do not depend on directly. +absl_cc_library( + NAME + random_internal_randen_hwaes + SRCS + "internal/randen_detect.cc" + HDRS + "internal/randen_detect.h" + "internal/randen_hwaes.h" + COPTS + ${ABSL_DEFAULT_COPTS} + ${ABSL_RANDOM_RANDEN_COPTS} + LINKOPTS + ${ABSL_DEFAULT_LINKOPTS} + DEPS + absl::random_internal_platform + absl::random_internal_randen_hwaes_impl +) + +# Internal-only target, do not depend on directly. +absl_cc_library( + NAME + random_internal_randen_hwaes_impl + SRCS + "internal/randen_hwaes.cc" + "internal/randen_hwaes.h" + COPTS + ${ABSL_DEFAULT_COPTS} + ${ABSL_RANDOM_RANDEN_COPTS} + LINKOPTS + ${ABSL_DEFAULT_LINKOPTS} + DEPS + absl::random_internal_platform +) + +# Internal-only target, do not depend on directly. +absl_cc_library( + NAME + random_internal_distribution_test_util + SRCS + "internal/chi_square.cc" + "internal/distribution_test_util.cc" + HDRS + "internal/chi_square.h" + "internal/distribution_test_util.h" + COPTS + ${ABSL_DEFAULT_COPTS} + LINKOPTS + ${ABSL_DEFAULT_LINKOPTS} + DEPS + absl::base + absl::core_headers + absl::strings + absl::str_format + absl::span +) + +# Internal-only target, do not depend on directly. +absl_cc_test( + NAME + random_internal_traits_test + SRCS + "internal/traits_test.cc" + COPTS + ${ABSL_TEST_COPTS} + LINKOPTS + ${ABSL_DEFAULT_LINKOPTS} + DEPS + absl::random_internal_traits + gtest_main +) + +# Internal-only target, do not depend on directly. +absl_cc_test( + NAME + random_internal_distribution_impl_test + SRCS + "internal/distribution_impl_test.cc" + COPTS + ${ABSL_TEST_COPTS} + LINKOPTS + ${ABSL_DEFAULT_LINKOPTS} + DEPS + absl::bits + absl::flags + absl::int128 + absl::random_internal_distribution_impl + gtest_main +) + +# Internal-only target, do not depend on directly. +absl_cc_test( + NAME + random_internal_distribution_test_util_test + SRCS + "internal/distribution_test_util_test.cc" + COPTS + ${ABSL_TEST_COPTS} + LINKOPTS + ${ABSL_DEFAULT_LINKOPTS} + DEPS + absl::random_internal_distribution_test_util + gtest_main +) + +# Internal-only target, do not depend on directly. +absl_cc_test( + NAME + random_internal_fastmath_test + SRCS + "internal/fastmath_test.cc" + COPTS + ${ABSL_TEST_COPTS} + LINKOPTS + ${ABSL_DEFAULT_LINKOPTS} + DEPS + absl::random_internal_fastmath + gtest_main +) + +# Internal-only target, do not depend on directly. +absl_cc_test( + NAME + random_internal_explicit_seed_seq_test + SRCS + "internal/explicit_seed_seq_test.cc" + COPTS + ${ABSL_TEST_COPTS} + LINKOPTS + ${ABSL_DEFAULT_LINKOPTS} + DEPS + absl::random_internal_explicit_seed_seq + absl::random_seed_sequences + gmock + gtest_main +) + +# Internal-only target, do not depend on directly. +absl_cc_test( + NAME + random_internal_salted_seed_seq_test + SRCS + "internal/salted_seed_seq_test.cc" + COPTS + ${ABSL_TEST_COPTS} + LINKOPTS + ${ABSL_DEFAULT_LINKOPTS} + DEPS + absl::random_internal_salted_seed_seq + gmock + gtest_main +) + +# Internal-only target, do not depend on directly. +absl_cc_test( + NAME + random_internal_chi_square_test + SRCS + "internal/chi_square_test.cc" + COPTS + ${ABSL_TEST_COPTS} + LINKOPTS + ${ABSL_DEFAULT_LINKOPTS} + DEPS + absl::core_headers + absl::random_internal_distribution_test_util + gtest_main +) + +# Internal-only target, do not depend on directly. +absl_cc_test( + NAME + random_internal_fast_uniform_bits_test + SRCS + "internal/fast_uniform_bits_test.cc" + COPTS + ${ABSL_TEST_COPTS} + LINKOPTS + ${ABSL_DEFAULT_LINKOPTS} + DEPS + absl::random_internal_fast_uniform_bits + gtest_main +) + +# Internal-only target, do not depend on directly. +absl_cc_test( + NAME + random_internal_nonsecure_base_test + SRCS + "internal/nonsecure_base_test.cc" + COPTS + ${ABSL_TEST_COPTS} + LINKOPTS + ${ABSL_DEFAULT_LINKOPTS} + DEPS + absl::random_internal_nonsecure_base + absl::random_random + absl::random_distributions + absl::random_seed_sequences + absl::strings + gtest_main +) + +# Internal-only target, do not depend on directly. +absl_cc_test( + NAME + random_internal_seed_material_test + SRCS + "internal/seed_material_test.cc" + COPTS + ${ABSL_TEST_COPTS} + LINKOPTS + ${ABSL_DEFAULT_LINKOPTS} + DEPS + absl::random_internal_seed_material + gmock + gtest_main +) + +# Internal-only target, do not depend on directly. +absl_cc_test( + NAME + random_internal_pool_urbg_test + SRCS + "internal/pool_urbg_test.cc" + COPTS + ${ABSL_TEST_COPTS} + LINKOPTS + ${ABSL_DEFAULT_LINKOPTS} + DEPS + absl::random_internal_pool_urbg + absl::span + absl::type_traits + gtest_main +) + +# Internal-only target, do not depend on directly. +absl_cc_test( + NAME + random_internal_pcg_engine_test + SRCS + "internal/pcg_engine_test.cc" + COPTS + ${ABSL_TEST_COPTS} + LINKOPTS + ${ABSL_DEFAULT_LINKOPTS} + DEPS + absl::random_internal_explicit_seed_seq + absl::random_internal_pcg_engine + absl::time + gmock + gtest_main +) + +# Internal-only target, do not depend on directly. +absl_cc_test( + NAME + random_internal_randen_engine_test + SRCS + "internal/randen_engine_test.cc" + COPTS + ${ABSL_TEST_COPTS} + LINKOPTS + ${ABSL_DEFAULT_LINKOPTS} + DEPS + absl::base + absl::random_internal_explicit_seed_seq + absl::random_internal_randen_engine + absl::strings + absl::time + gmock + gtest_main +) + +# Internal-only target, do not depend on directly. +absl_cc_test( + NAME + random_internal_randen_test + SRCS + "internal/randen_test.cc" + COPTS + ${ABSL_TEST_COPTS} + LINKOPTS + ${ABSL_DEFAULT_LINKOPTS} + DEPS + absl::random_internal_randen + absl::type_traits + gtest_main +) + +# Internal-only target, do not depend on directly. +absl_cc_test( + NAME + random_internal_randen_slow_test + SRCS + "internal/randen_slow_test.cc" + COPTS + ${ABSL_TEST_COPTS} + LINKOPTS + ${ABSL_DEFAULT_LINKOPTS} + DEPS + absl::random_internal_randen_slow + gtest_main +) + +# Internal-only target, do not depend on directly. +absl_cc_test( + NAME + random_internal_randen_hwaes_test + SRCS + "internal/randen_hwaes_test.cc" + COPTS + ${ABSL_TEST_COPTS} + LINKOPTS + ${ABSL_DEFAULT_LINKOPTS} + DEPS + absl::random_internal_platform + absl::random_internal_randen_hwaes + absl::random_internal_randen_hwaes_impl + absl::base + absl::str_format + gmock + gtest +) + +# Internal-only target, do not depend on directly. +absl_cc_library( + NAME + random_internal_uniform_helper + HDRS + "internal/uniform_helper.h" + COPTS + ${ABSL_DEFAULT_COPTS} + LINKOPTS + ${ABSL_DEFAULT_LINKOPTS} + DEPS + absl::core_headers + absl::random_internal_distribution_impl + absl::random_internal_fast_uniform_bits + absl::random_internal_iostream_state_saver + absl::random_internal_traits + absl::type_traits +) + +# Internal-only target, do not depend on directly. +absl_cc_test( + NAME + random_internal_iostream_state_saver_test + SRCS + "internal/iostream_state_saver_test.cc" + LINKOPTS + ${ABSL_DEFAULT_LINKOPTS} + DEPS + absl::random_internal_iostream_state_saver + gtest_main +) diff --git a/absl/random/internal/salted_seed_seq.h b/absl/random/internal/salted_seed_seq.h index e160f79e..86487006 100644 --- a/absl/random/internal/salted_seed_seq.h +++ b/absl/random/internal/salted_seed_seq.h @@ -56,11 +56,11 @@ class SaltedSeedSeq { SaltedSeedSeq(std::initializer_list<T> il) : SaltedSeedSeq(il.begin(), il.end()) {} - SaltedSeedSeq(const SaltedSeedSeq& other) = delete; - SaltedSeedSeq& operator=(const SaltedSeedSeq& other) = delete; + SaltedSeedSeq(const SaltedSeedSeq&) = delete; + SaltedSeedSeq& operator=(const SaltedSeedSeq&) = delete; - SaltedSeedSeq(SaltedSeedSeq&& other) = default; - SaltedSeedSeq& operator=(SaltedSeedSeq&& other) = default; + SaltedSeedSeq(SaltedSeedSeq&&) = default; + SaltedSeedSeq& operator=(SaltedSeedSeq&&) = default; template <typename RandomAccessIterator> void generate(RandomAccessIterator begin, RandomAccessIterator end) { diff --git a/absl/strings/str_split_benchmark.cc b/absl/strings/str_split_benchmark.cc index 28c25e8d..f38dfcfe 100644 --- a/absl/strings/str_split_benchmark.cc +++ b/absl/strings/str_split_benchmark.cc @@ -44,6 +44,29 @@ void BM_Split2StringView(benchmark::State& state) { } BENCHMARK_RANGE(BM_Split2StringView, 0, 1 << 20); +static const absl::string_view kDelimiters = ";:,."; + +std::string MakeMultiDelimiterTestString(int desired_length) { + static const int kAverageValueLen = 25; + std::string test(desired_length * kAverageValueLen, 'x'); + for (int i = 0; i * kAverageValueLen < test.size(); ++i) { + // Cycle through a variety of delimiters. + test[i * kAverageValueLen] = kDelimiters[i % kDelimiters.size()]; + } + return test; +} + +// Measure StrSplit with ByAnyChar with four delimiters to choose from. +void BM_Split2StringViewByAnyChar(benchmark::State& state) { + std::string test = MakeMultiDelimiterTestString(state.range(0)); + for (auto _ : state) { + std::vector<absl::string_view> result = + absl::StrSplit(test, absl::ByAnyChar(kDelimiters)); + benchmark::DoNotOptimize(result); + } +} +BENCHMARK_RANGE(BM_Split2StringViewByAnyChar, 0, 1 << 20); + void BM_Split2StringViewLifted(benchmark::State& state) { std::string test = MakeTestString(state.range(0)); std::vector<absl::string_view> result; diff --git a/absl/types/optional.h b/absl/types/optional.h index 142dc83a..ed8faf97 100644 --- a/absl/types/optional.h +++ b/absl/types/optional.h @@ -499,7 +499,7 @@ class optional : private optional_internal::optional_data<T>, template <typename U> constexpr T value_or(U&& v) const& { static_assert(std::is_copy_constructible<value_type>::value, - "optional<T>::value_or: T must by copy constructible"); + "optional<T>::value_or: T must be copy constructible"); static_assert(std::is_convertible<U&&, value_type>::value, "optional<T>::value_or: U must be convertible to T"); return static_cast<bool>(*this) @@ -509,7 +509,7 @@ class optional : private optional_internal::optional_data<T>, template <typename U> T value_or(U&& v) && { // NOLINT(build/c++11) static_assert(std::is_move_constructible<value_type>::value, - "optional<T>::value_or: T must by move constructible"); + "optional<T>::value_or: T must be move constructible"); static_assert(std::is_convertible<U&&, value_type>::value, "optional<T>::value_or: U must be convertible to T"); return static_cast<bool>(*this) ? std::move(**this) |