Cleanup the uses of the polyfills absl::any, absl::optional, absl::variant, and related types The corresponding headers are removed from cc files, but kept in headers to prevent breakages from transitive dependencies. PiperOrigin-RevId: 872421685 Change-Id: I867d4c3f7c9e422289c63816d44719b0530fb0a6
diff --git a/absl/base/BUILD.bazel b/absl/base/BUILD.bazel index f95e187..4ce7f8c 100644 --- a/absl/base/BUILD.bazel +++ b/absl/base/BUILD.bazel
@@ -953,7 +953,6 @@ linkopts = ABSL_DEFAULT_LINKOPTS, deps = [ ":core_headers", - "//absl/types:optional", "@googletest//:gtest", "@googletest//:gtest_main", ],
diff --git a/absl/base/CMakeLists.txt b/absl/base/CMakeLists.txt index 91a8a58..62f9345 100644 --- a/absl/base/CMakeLists.txt +++ b/absl/base/CMakeLists.txt
@@ -765,7 +765,6 @@ ${ABSL_TEST_COPTS} DEPS absl::core_headers - absl::optional GTest::gtest_main )
diff --git a/absl/base/attributes.h b/absl/base/attributes.h index cced170..91e552f 100644 --- a/absl/base/attributes.h +++ b/absl/base/attributes.h
@@ -933,7 +933,7 @@ // We disable this on Clang versions < 13 because of the following // false-positive: // -// absl::string_view f(absl::optional<absl::string_view> sv) { return *sv; } +// absl::string_view f(std::optional<absl::string_view> sv) { return *sv; } // // See the following links for details: // https://reviews.llvm.org/D64448 @@ -964,7 +964,7 @@ // We disable this on Clang versions < 13 because of the following // false-positive: // -// absl::string_view f(absl::optional<absl::string_view> sv) { return *sv; } +// absl::string_view f(std::optional<absl::string_view> sv) { return *sv; } // // See the following links for details: // https://reviews.llvm.org/D64448
diff --git a/absl/base/optimization_test.cc b/absl/base/optimization_test.cc index b47b11a..11d22fe 100644 --- a/absl/base/optimization_test.cc +++ b/absl/base/optimization_test.cc
@@ -14,8 +14,9 @@ #include "absl/base/optimization.h" +#include <optional> + #include "gtest/gtest.h" -#include "absl/types/optional.h" namespace { @@ -80,8 +81,8 @@ TEST(PredictTest, Optional) { // Note: An optional's truth value is the value's existence, not its truth. - absl::optional<bool> has_value(false); - absl::optional<bool> no_value; + std::optional<bool> has_value(false); + std::optional<bool> no_value; EXPECT_TRUE(ABSL_PREDICT_TRUE(has_value)); EXPECT_FALSE(ABSL_PREDICT_TRUE(no_value)); EXPECT_TRUE(ABSL_PREDICT_FALSE(has_value));
diff --git a/absl/cleanup/internal/cleanup.h b/absl/cleanup/internal/cleanup.h index 4dd6f91..2022fa7 100644 --- a/absl/cleanup/internal/cleanup.h +++ b/absl/cleanup/internal/cleanup.h
@@ -49,7 +49,7 @@ explicit Storage(Callback callback) { // Placement-new into a character buffer is used for eager destruction when // the cleanup is invoked or cancelled. To ensure this optimizes well, the - // behavior is implemented locally instead of using an absl::optional. + // behavior is implemented locally instead of using a std::optional. ::new (GetCallbackBuffer()) Callback(std::move(callback)); is_callback_engaged_ = true; }
diff --git a/absl/container/BUILD.bazel b/absl/container/BUILD.bazel index e90aaec..efcdc51 100644 --- a/absl/container/BUILD.bazel +++ b/absl/container/BUILD.bazel
@@ -54,8 +54,6 @@ ":compressed_tuple", ":test_instance_tracker", "//absl/memory", - "//absl/types:any", - "//absl/types:optional", "//absl/utility", "@googletest//:gtest", "@googletest//:gtest_main", @@ -283,7 +281,6 @@ "//absl/base:config", "//absl/log:check", "//absl/meta:type_traits", - "//absl/types:any", "@googletest//:gtest", "@googletest//:gtest_main", ], @@ -810,7 +807,6 @@ "//absl/numeric:int128", "//absl/random", "//absl/strings", - "//absl/types:optional", "@googletest//:gtest", "@googletest//:gtest_main", ], @@ -855,7 +851,6 @@ "//absl/random:distributions", "//absl/strings", "//absl/strings:str_format", - "//absl/types:optional", ], ) @@ -1193,7 +1188,6 @@ "//absl/random", "//absl/strings", "//absl/types:compare", - "//absl/types:optional", "@googletest//:gtest", "@googletest//:gtest_main", ],
diff --git a/absl/container/CMakeLists.txt b/absl/container/CMakeLists.txt index d12e585..589a3a4 100644 --- a/absl/container/CMakeLists.txt +++ b/absl/container/CMakeLists.txt
@@ -80,7 +80,6 @@ absl::core_headers absl::flags absl::hash_testing - absl::optional absl::random_random absl::raw_logging_internal absl::strings @@ -110,10 +109,8 @@ COPTS ${ABSL_TEST_COPTS} DEPS - absl::any absl::compressed_tuple absl::memory - absl::optional absl::test_instance_tracker absl::utility GTest::gmock_main @@ -309,7 +306,6 @@ COPTS ${ABSL_TEST_COPTS} DEPS - absl::any absl::check absl::config absl::flat_hash_map @@ -840,7 +836,6 @@ absl::log absl::memory absl::node_hash_set - absl::optional absl::prefetch absl::random_random absl::raw_hash_set
diff --git a/absl/container/btree_test.cc b/absl/container/btree_test.cc index 0cf3ed3..dc880a8 100644 --- a/absl/container/btree_test.cc +++ b/absl/container/btree_test.cc
@@ -24,6 +24,7 @@ #include <map> #include <memory> #include <numeric> +#include <optional> #include <stdexcept> #include <string> #include <type_traits> @@ -47,7 +48,6 @@ #include "absl/strings/str_split.h" #include "absl/strings/string_view.h" #include "absl/types/compare.h" -#include "absl/types/optional.h" ABSL_FLAG(int, test_values, 10000, "The number of values to use for tests"); @@ -3007,11 +3007,11 @@ // compare differently with each other from how they compare with instances // that don't have the optional field. struct ClockTime { - absl::optional<int> hour; + std::optional<int> hour; int minute; }; // `comp(a,b) && comp(b,c) && !comp(a,c)` violates transitivity. - ClockTime a = {absl::nullopt, 1}; + ClockTime a = {std::nullopt, 1}; ClockTime b = {2, 5}; ClockTime c = {6, 0}; {
diff --git a/absl/container/flat_hash_map_test.cc b/absl/container/flat_hash_map_test.cc index a4efb7d..0839b00 100644 --- a/absl/container/flat_hash_map_test.cc +++ b/absl/container/flat_hash_map_test.cc
@@ -33,7 +33,6 @@ #include "absl/container/internal/unordered_map_modifiers_test.h" #include "absl/log/check.h" #include "absl/meta/type_traits.h" -#include "absl/types/any.h" #if ABSL_INTERNAL_CPLUSPLUS_LANG >= 202002L #include <ranges> // NOLINT(build/c++20)
diff --git a/absl/container/internal/common.h b/absl/container/internal/common.h index 3e263a3..62517af 100644 --- a/absl/container/internal/common.h +++ b/absl/container/internal/common.h
@@ -18,6 +18,7 @@ #include <algorithm> #include <cassert> #include <cstddef> +#include <optional> #include <tuple> #include <type_traits> @@ -146,7 +147,7 @@ void reset() { assert(alloc_.has_value()); - alloc_ = absl::nullopt; + alloc_ = std::nullopt; } slot_type* slot() const { @@ -156,7 +157,7 @@ allocator_type* alloc() { return std::addressof(*alloc_); } private: - absl::optional<allocator_type> alloc_ = {}; + std::optional<allocator_type> alloc_ = {}; alignas(slot_type) mutable unsigned char slot_space_[sizeof(slot_type)] = {}; };
diff --git a/absl/container/internal/compressed_tuple_test.cc b/absl/container/internal/compressed_tuple_test.cc index 662f944..47648c9 100644 --- a/absl/container/internal/compressed_tuple_test.cc +++ b/absl/container/internal/compressed_tuple_test.cc
@@ -14,7 +14,9 @@ #include "absl/container/internal/compressed_tuple.h" +#include <any> #include <memory> +#include <optional> #include <set> #include <string> #include <type_traits> @@ -25,8 +27,6 @@ #include "gtest/gtest.h" #include "absl/container/internal/test_instance_tracker.h" #include "absl/memory/memory.h" -#include "absl/types/any.h" -#include "absl/types/optional.h" #include "absl/utility/utility.h" // These are declared at global scope purely so that error messages @@ -363,13 +363,13 @@ } TEST(CompressedTupleTest, AnyElements) { - any a(std::string("str")); - CompressedTuple<any, any&> x(any(5), a); - EXPECT_EQ(absl::any_cast<int>(x.get<0>()), 5); - EXPECT_EQ(absl::any_cast<std::string>(x.get<1>()), "str"); + std::any a(std::string("str")); + CompressedTuple<std::any, std::any&> x(std::any(5), a); + EXPECT_EQ(std::any_cast<int>(x.get<0>()), 5); + EXPECT_EQ(std::any_cast<std::string>(x.get<1>()), "str"); a = 0.5f; - EXPECT_EQ(absl::any_cast<float>(x.get<1>()), 0.5); + EXPECT_EQ(std::any_cast<float>(x.get<1>()), 0.5); } TEST(CompressedTupleTest, Constexpr) { @@ -418,15 +418,15 @@ EXPECT_EQ(trivial1, 0); EXPECT_EQ(trivial2, 0); - constexpr CompressedTuple<Empty<0>, NonTrivialStruct, absl::optional<int>> + constexpr CompressedTuple<Empty<0>, NonTrivialStruct, std::optional<int>> non_trivial = {}; constexpr CallType non_trivial0 = non_trivial.get<0>().value(); constexpr int non_trivial1 = non_trivial.get<1>().value(); - constexpr absl::optional<int> non_trivial2 = non_trivial.get<2>(); + constexpr std::optional<int> non_trivial2 = non_trivial.get<2>(); EXPECT_EQ(non_trivial0, CallType::kConstRef); EXPECT_EQ(non_trivial1, 5); - EXPECT_EQ(non_trivial2, absl::nullopt); + EXPECT_EQ(non_trivial2, std::nullopt); static constexpr char data[] = "DEF"; constexpr CompressedTuple<const char*> z(data);
diff --git a/absl/container/internal/raw_hash_set_probe_benchmark.cc b/absl/container/internal/raw_hash_set_probe_benchmark.cc index 7165558..dcd1596 100644 --- a/absl/container/internal/raw_hash_set_probe_benchmark.cc +++ b/absl/container/internal/raw_hash_set_probe_benchmark.cc
@@ -20,6 +20,7 @@ #include <cstdint> #include <limits> #include <memory> +#include <optional> #include <regex> // NOLINT #include <string> #include <utility> @@ -36,7 +37,6 @@ #include "absl/strings/str_format.h" #include "absl/strings/string_view.h" #include "absl/strings/strip.h" -#include "absl/types/optional.h" namespace { @@ -450,10 +450,10 @@ constexpr int kDistWidth = 16; bool CanRunBenchmark(absl::string_view name) { - static const absl::NoDestructor<absl::optional<std::regex>> filter([] { + static const absl::NoDestructor<std::optional<std::regex>> filter([] { return benchmarks.empty() || benchmarks == "all" - ? absl::nullopt - : absl::make_optional(std::regex(std::string(benchmarks))); + ? std::nullopt + : std::make_optional(std::regex(std::string(benchmarks))); }()); return !filter->has_value() || std::regex_search(std::string(name), **filter); }
diff --git a/absl/container/internal/raw_hash_set_test.cc b/absl/container/internal/raw_hash_set_test.cc index 5b3cd0e..54a7cae 100644 --- a/absl/container/internal/raw_hash_set_test.cc +++ b/absl/container/internal/raw_hash_set_test.cc
@@ -31,6 +31,7 @@ #include <map> #include <memory> #include <numeric> +#include <optional> #include <ostream> #include <random> #include <set> @@ -53,7 +54,6 @@ #include "absl/container/internal/container_memory.h" #include "absl/container/internal/hash_function_defaults.h" #include "absl/container/internal/hash_policy_testing.h" -#include "absl/random/random.h" #include "absl/container/internal/hashtable_control_bytes.h" #include "absl/container/internal/hashtable_debug.h" #include "absl/container/internal/hashtablez_sampler.h" @@ -68,9 +68,9 @@ #include "absl/memory/memory.h" #include "absl/meta/type_traits.h" #include "absl/numeric/int128.h" +#include "absl/random/random.h" #include "absl/strings/str_cat.h" #include "absl/strings/string_view.h" -#include "absl/types/optional.h" namespace absl { ABSL_NAMESPACE_BEGIN @@ -3840,7 +3840,7 @@ ~DestroyCaller() { if (destroy_func) (*destroy_func)(); } - void Deactivate() { destroy_func = absl::nullopt; } + void Deactivate() { destroy_func = std::nullopt; } template <typename H> friend H AbslHashValue(H h, const DestroyCaller& d) { @@ -3849,7 +3849,7 @@ bool operator==(const DestroyCaller& d) const { return val == d.val; } int val; - absl::optional<absl::FunctionRef<void()>> destroy_func; + std::optional<absl::FunctionRef<void()>> destroy_func; }; TEST(Table, ReentrantCallsFail) { @@ -3897,7 +3897,7 @@ #if !defined(__clang__) && defined(__GNUC__) GTEST_SKIP() << "Flaky on GCC."; #endif - absl::optional<IntTable> t; + std::optional<IntTable> t; t.emplace({1}); IntTable* t_ptr = &*t; EXPECT_TRUE(t_ptr->contains(1)); @@ -3925,7 +3925,7 @@ bool do_lookup = false; using Table = absl::flat_hash_map<int, std::shared_ptr<int>>; - absl::optional<Table> t = Table(); + std::optional<Table> t = Table(); Table* t_ptr = &*t; auto destroy = [&](int* ptr) { if (do_lookup) {
diff --git a/absl/crc/BUILD.bazel b/absl/crc/BUILD.bazel index 22c3cbf..49e916c 100644 --- a/absl/crc/BUILD.bazel +++ b/absl/crc/BUILD.bazel
@@ -45,7 +45,6 @@ deps = [ "//absl/base", "//absl/base:config", - "//absl/types:optional", ], )
diff --git a/absl/crc/CMakeLists.txt b/absl/crc/CMakeLists.txt index 09d3485..034d0d0 100644 --- a/absl/crc/CMakeLists.txt +++ b/absl/crc/CMakeLists.txt
@@ -25,7 +25,6 @@ DEPS absl::base absl::config - absl::optional ) # Internal-only target, do not depend on directly.
diff --git a/absl/crc/internal/cpu_detect.cc b/absl/crc/internal/cpu_detect.cc index a697601..86f55d0 100644 --- a/absl/crc/internal/cpu_detect.cc +++ b/absl/crc/internal/cpu_detect.cc
@@ -15,10 +15,10 @@ #include "absl/crc/internal/cpu_detect.h" #include <cstdint> +#include <optional> // IWYU pragma: keep #include <string> #include "absl/base/config.h" -#include "absl/types/optional.h" // IWYU pragma: keep #if defined(__aarch64__) && defined(__linux__) #include <asm/hwcap.h> @@ -308,12 +308,12 @@ CpuType GetCpuType() { return CpuType::kUnknown; } template <typename T> -static absl::optional<T> ReadSysctlByName(const char* name) { +static std::optional<T> ReadSysctlByName(const char* name) { T val; size_t val_size = sizeof(T); int ret = sysctlbyname(name, &val, &val_size, nullptr, 0); if (ret == -1) { - return absl::nullopt; + return std::nullopt; } return val; } @@ -322,7 +322,7 @@ // Newer XNU kernels support querying all capabilities in a single // sysctlbyname. #if defined(CAP_BIT_CRC32) && defined(CAP_BIT_FEAT_PMULL) - static const absl::optional<uint64_t> caps = + static const std::optional<uint64_t> caps = ReadSysctlByName<uint64_t>("hw.optional.arm.caps"); if (caps.has_value()) { constexpr uint64_t kCrc32AndPmullCaps = @@ -332,13 +332,13 @@ #endif // https://developer.apple.com/documentation/kernel/1387446-sysctlbyname/determining_instruction_set_characteristics#3915619 - static const absl::optional<int> armv8_crc32 = + static const std::optional<int> armv8_crc32 = ReadSysctlByName<int>("hw.optional.armv8_crc32"); if (armv8_crc32.value_or(0) == 0) { return false; } // https://developer.apple.com/documentation/kernel/1387446-sysctlbyname/determining_instruction_set_characteristics#3918855 - static const absl::optional<int> feat_pmull = + static const std::optional<int> feat_pmull = ReadSysctlByName<int>("hw.optional.arm.FEAT_PMULL"); if (feat_pmull.value_or(0) == 0) { return false;
diff --git a/absl/flags/BUILD.bazel b/absl/flags/BUILD.bazel index a5ee2c7..9835648 100644 --- a/absl/flags/BUILD.bazel +++ b/absl/flags/BUILD.bazel
@@ -411,7 +411,6 @@ "//absl/numeric:int128", "//absl/strings", "//absl/time", - "//absl/types:optional", "@googletest//:gtest", "@googletest//:gtest_main", ], @@ -437,7 +436,6 @@ ":reflection", "//absl/strings", "//absl/time", - "//absl/types:optional", "@google_benchmark//:benchmark_main", ], )
diff --git a/absl/flags/CMakeLists.txt b/absl/flags/CMakeLists.txt index 3ec254a..0c75c93 100644 --- a/absl/flags/CMakeLists.txt +++ b/absl/flags/CMakeLists.txt
@@ -352,7 +352,6 @@ absl::flags_parse absl::flags_reflection absl::int128 - absl::optional absl::raw_logging_internal absl::strings absl::time
diff --git a/absl/flags/commandlineflag.h b/absl/flags/commandlineflag.h index 1a9743c..9336d6d 100644 --- a/absl/flags/commandlineflag.h +++ b/absl/flags/commandlineflag.h
@@ -27,6 +27,7 @@ #define ABSL_FLAGS_COMMANDLINEFLAG_H_ #include <memory> +#include <optional> #include <string> #include "absl/base/config.h" @@ -87,11 +88,11 @@ // absl::CommandLineFlag::TryGet() // // Attempts to retrieve the flag value. Returns value on success, - // absl::nullopt otherwise. + // std::nullopt otherwise. template <typename T> - absl::optional<T> TryGet() const { + std::optional<T> TryGet() const { if (IsRetired() || !IsOfType<T>()) { - return absl::nullopt; + return std::nullopt; } // Implementation notes: @@ -119,7 +120,7 @@ Read(&u.value); // allow retired flags to be "read", so we can report invalid access. if (IsRetired()) { - return absl::nullopt; + return std::nullopt; } return std::move(u.value); }
diff --git a/absl/flags/flag_benchmark.cc b/absl/flags/flag_benchmark.cc index 88cc0c5..bbe9cba 100644 --- a/absl/flags/flag_benchmark.cc +++ b/absl/flags/flag_benchmark.cc
@@ -15,6 +15,7 @@ #include <stdint.h> +#include <optional> #include <string> #include <vector> @@ -24,7 +25,6 @@ #include "absl/flags/reflection.h" #include "absl/strings/string_view.h" #include "absl/time/time.h" -#include "absl/types/optional.h" #include "benchmark/benchmark.h" namespace { @@ -32,10 +32,10 @@ using VectorOfStrings = std::vector<std::string>; using AbslDuration = absl::Duration; -// We do not want to take over marshalling for the types absl::optional<int>, -// absl::optional<std::string> which we do not own. Instead we introduce unique +// We do not want to take over marshalling for the types std::optional<int>, +// std::optional<std::string> which we do not own. Instead we introduce unique // "aliases" to these types, which we do. -using AbslOptionalInt = absl::optional<int>; +using AbslOptionalInt = std::optional<int>; struct OptionalInt : AbslOptionalInt { using AbslOptionalInt::AbslOptionalInt; }; @@ -54,7 +54,7 @@ return !flag ? "" : absl::UnparseFlag(*flag); } -using AbslOptionalString = absl::optional<std::string>; +using AbslOptionalString = std::optional<std::string>; struct OptionalString : AbslOptionalString { using AbslOptionalString::AbslOptionalString; };
diff --git a/absl/flags/flag_test.cc b/absl/flags/flag_test.cc index e3ab24c..d303c8d 100644 --- a/absl/flags/flag_test.cc +++ b/absl/flags/flag_test.cc
@@ -19,6 +19,7 @@ #include <stdint.h> #include <atomic> +#include <optional> #include <string> #include <thread> // NOLINT #include <vector> @@ -42,7 +43,6 @@ #include "absl/strings/string_view.h" #include "absl/time/clock.h" #include "absl/time/time.h" -#include "absl/types/optional.h" ABSL_DECLARE_FLAG(int64_t, mistyped_int_flag); ABSL_DECLARE_FLAG(std::vector<std::string>, mistyped_string_flag); @@ -1038,7 +1038,7 @@ template <int id, typename F> void TestExpectedLeaks( F&& f, uint64_t num_leaks, - absl::optional<uint64_t> num_new_instances = absl::nullopt) { + std::optional<uint64_t> num_new_instances = std::nullopt) { if (!num_new_instances.has_value()) num_new_instances = num_leaks; auto num_leaked_before = flags::NumLeakedFlagValues(); @@ -1216,14 +1216,14 @@ // -------------------------------------------------------------------- -ABSL_FLAG(absl::optional<bool>, optional_bool, absl::nullopt, "help"); -ABSL_FLAG(absl::optional<int>, optional_int, {}, "help"); -ABSL_FLAG(absl::optional<double>, optional_double, 9.3, "help"); -ABSL_FLAG(absl::optional<std::string>, optional_string, absl::nullopt, "help"); -ABSL_FLAG(absl::optional<absl::Duration>, optional_duration, absl::nullopt, +ABSL_FLAG(std::optional<bool>, optional_bool, std::nullopt, "help"); +ABSL_FLAG(std::optional<int>, optional_int, {}, "help"); +ABSL_FLAG(std::optional<double>, optional_double, 9.3, "help"); +ABSL_FLAG(std::optional<std::string>, optional_string, std::nullopt, "help"); +ABSL_FLAG(std::optional<absl::Duration>, optional_duration, std::nullopt, "help"); -ABSL_FLAG(absl::optional<absl::optional<int>>, optional_optional_int, - absl::nullopt, "help"); +ABSL_FLAG(std::optional<std::optional<int>>, optional_optional_int, + std::nullopt, "help"); #if defined(ABSL_HAVE_STD_OPTIONAL) && !defined(ABSL_USES_STD_OPTIONAL) ABSL_FLAG(std::optional<int64_t>, std_optional_int64, std::nullopt, "help"); #endif @@ -1232,7 +1232,7 @@ TEST_F(FlagTest, TestOptionalBool) { EXPECT_FALSE(absl::GetFlag(FLAGS_optional_bool).has_value()); - EXPECT_EQ(absl::GetFlag(FLAGS_optional_bool), absl::nullopt); + EXPECT_EQ(absl::GetFlag(FLAGS_optional_bool), std::nullopt); absl::SetFlag(&FLAGS_optional_bool, false); EXPECT_TRUE(absl::GetFlag(FLAGS_optional_bool).has_value()); @@ -1242,16 +1242,16 @@ EXPECT_TRUE(absl::GetFlag(FLAGS_optional_bool).has_value()); EXPECT_EQ(absl::GetFlag(FLAGS_optional_bool), true); - absl::SetFlag(&FLAGS_optional_bool, absl::nullopt); + absl::SetFlag(&FLAGS_optional_bool, std::nullopt); EXPECT_FALSE(absl::GetFlag(FLAGS_optional_bool).has_value()); - EXPECT_EQ(absl::GetFlag(FLAGS_optional_bool), absl::nullopt); + EXPECT_EQ(absl::GetFlag(FLAGS_optional_bool), std::nullopt); } // -------------------------------------------------------------------- TEST_F(FlagTest, TestOptionalInt) { EXPECT_FALSE(absl::GetFlag(FLAGS_optional_int).has_value()); - EXPECT_EQ(absl::GetFlag(FLAGS_optional_int), absl::nullopt); + EXPECT_EQ(absl::GetFlag(FLAGS_optional_int), std::nullopt); absl::SetFlag(&FLAGS_optional_int, 0); EXPECT_TRUE(absl::GetFlag(FLAGS_optional_int).has_value()); @@ -1261,9 +1261,9 @@ EXPECT_TRUE(absl::GetFlag(FLAGS_optional_int).has_value()); EXPECT_EQ(absl::GetFlag(FLAGS_optional_int), 10); - absl::SetFlag(&FLAGS_optional_int, absl::nullopt); + absl::SetFlag(&FLAGS_optional_int, std::nullopt); EXPECT_FALSE(absl::GetFlag(FLAGS_optional_int).has_value()); - EXPECT_EQ(absl::GetFlag(FLAGS_optional_int), absl::nullopt); + EXPECT_EQ(absl::GetFlag(FLAGS_optional_int), std::nullopt); } // -------------------------------------------------------------------- @@ -1280,16 +1280,16 @@ EXPECT_TRUE(absl::GetFlag(FLAGS_optional_double).has_value()); EXPECT_DOUBLE_EQ(*absl::GetFlag(FLAGS_optional_double), 1.234); - absl::SetFlag(&FLAGS_optional_double, absl::nullopt); + absl::SetFlag(&FLAGS_optional_double, std::nullopt); EXPECT_FALSE(absl::GetFlag(FLAGS_optional_double).has_value()); - EXPECT_EQ(absl::GetFlag(FLAGS_optional_double), absl::nullopt); + EXPECT_EQ(absl::GetFlag(FLAGS_optional_double), std::nullopt); } // -------------------------------------------------------------------- TEST_F(FlagTest, TestOptionalString) { EXPECT_FALSE(absl::GetFlag(FLAGS_optional_string).has_value()); - EXPECT_EQ(absl::GetFlag(FLAGS_optional_string), absl::nullopt); + EXPECT_EQ(absl::GetFlag(FLAGS_optional_string), std::nullopt); // Setting optional string to "" leads to undefined behavior. @@ -1301,16 +1301,16 @@ EXPECT_TRUE(absl::GetFlag(FLAGS_optional_string).has_value()); EXPECT_EQ(absl::GetFlag(FLAGS_optional_string), "QWERTY"); - absl::SetFlag(&FLAGS_optional_string, absl::nullopt); + absl::SetFlag(&FLAGS_optional_string, std::nullopt); EXPECT_FALSE(absl::GetFlag(FLAGS_optional_string).has_value()); - EXPECT_EQ(absl::GetFlag(FLAGS_optional_string), absl::nullopt); + EXPECT_EQ(absl::GetFlag(FLAGS_optional_string), std::nullopt); } // -------------------------------------------------------------------- TEST_F(FlagTest, TestOptionalDuration) { EXPECT_FALSE(absl::GetFlag(FLAGS_optional_duration).has_value()); - EXPECT_EQ(absl::GetFlag(FLAGS_optional_duration), absl::nullopt); + EXPECT_EQ(absl::GetFlag(FLAGS_optional_duration), std::nullopt); absl::SetFlag(&FLAGS_optional_duration, absl::ZeroDuration()); EXPECT_TRUE(absl::GetFlag(FLAGS_optional_duration).has_value()); @@ -1320,37 +1320,37 @@ EXPECT_TRUE(absl::GetFlag(FLAGS_optional_duration).has_value()); EXPECT_EQ(absl::GetFlag(FLAGS_optional_duration), absl::Hours(3)); - absl::SetFlag(&FLAGS_optional_duration, absl::nullopt); + absl::SetFlag(&FLAGS_optional_duration, std::nullopt); EXPECT_FALSE(absl::GetFlag(FLAGS_optional_duration).has_value()); - EXPECT_EQ(absl::GetFlag(FLAGS_optional_duration), absl::nullopt); + EXPECT_EQ(absl::GetFlag(FLAGS_optional_duration), std::nullopt); } // -------------------------------------------------------------------- TEST_F(FlagTest, TestOptionalOptional) { EXPECT_FALSE(absl::GetFlag(FLAGS_optional_optional_int).has_value()); - EXPECT_EQ(absl::GetFlag(FLAGS_optional_optional_int), absl::nullopt); + EXPECT_EQ(absl::GetFlag(FLAGS_optional_optional_int), std::nullopt); - absl::optional<int> nullint{absl::nullopt}; + std::optional<int> nullint{std::nullopt}; absl::SetFlag(&FLAGS_optional_optional_int, nullint); EXPECT_TRUE(absl::GetFlag(FLAGS_optional_optional_int).has_value()); EXPECT_NE(absl::GetFlag(FLAGS_optional_optional_int), nullint); EXPECT_EQ(absl::GetFlag(FLAGS_optional_optional_int), - absl::optional<absl::optional<int>>{nullint}); + std::optional<std::optional<int>>{nullint}); absl::SetFlag(&FLAGS_optional_optional_int, 0); EXPECT_TRUE(absl::GetFlag(FLAGS_optional_optional_int).has_value()); EXPECT_EQ(absl::GetFlag(FLAGS_optional_optional_int), 0); - absl::SetFlag(&FLAGS_optional_optional_int, absl::optional<int>{0}); + absl::SetFlag(&FLAGS_optional_optional_int, std::optional<int>{0}); EXPECT_TRUE(absl::GetFlag(FLAGS_optional_optional_int).has_value()); EXPECT_EQ(absl::GetFlag(FLAGS_optional_optional_int), 0); - EXPECT_EQ(absl::GetFlag(FLAGS_optional_optional_int), absl::optional<int>{0}); + EXPECT_EQ(absl::GetFlag(FLAGS_optional_optional_int), std::optional<int>{0}); - absl::SetFlag(&FLAGS_optional_optional_int, absl::nullopt); + absl::SetFlag(&FLAGS_optional_optional_int, std::nullopt); EXPECT_FALSE(absl::GetFlag(FLAGS_optional_optional_int).has_value()); - EXPECT_EQ(absl::GetFlag(FLAGS_optional_optional_int), absl::nullopt); + EXPECT_EQ(absl::GetFlag(FLAGS_optional_optional_int), std::nullopt); } // --------------------------------------------------------------------
diff --git a/absl/flags/marshalling.h b/absl/flags/marshalling.h index 301213a..5e04d6a 100644 --- a/absl/flags/marshalling.h +++ b/absl/flags/marshalling.h
@@ -199,15 +199,12 @@ #ifndef ABSL_FLAGS_MARSHALLING_H_ #define ABSL_FLAGS_MARSHALLING_H_ -#include "absl/base/config.h" -#include "absl/numeric/int128.h" - -#if defined(ABSL_HAVE_STD_OPTIONAL) && !defined(ABSL_USES_STD_OPTIONAL) #include <optional> -#endif #include <string> #include <vector> +#include "absl/base/config.h" +#include "absl/numeric/int128.h" #include "absl/strings/string_view.h" #include "absl/types/optional.h" @@ -242,21 +239,6 @@ bool AbslParseFlag(absl::string_view, std::vector<std::string>*, std::string*); template <typename T> -bool AbslParseFlag(absl::string_view text, absl::optional<T>* f, - std::string* err) { - if (text.empty()) { - *f = absl::nullopt; - return true; - } - T value; - if (!absl::ParseFlag(text, &value, err)) return false; - - *f = std::move(value); - return true; -} - -#if defined(ABSL_HAVE_STD_OPTIONAL) && !defined(ABSL_USES_STD_OPTIONAL) -template <typename T> bool AbslParseFlag(absl::string_view text, std::optional<T>* f, std::string* err) { if (text.empty()) { @@ -269,7 +251,6 @@ *f = std::move(value); return true; } -#endif template <typename T> bool InvokeParseFlag(absl::string_view input, T* dst, std::string* err) { @@ -285,16 +266,9 @@ std::string AbslUnparseFlag(const std::vector<std::string>&); template <typename T> -std::string AbslUnparseFlag(const absl::optional<T>& f) { - return f.has_value() ? absl::UnparseFlag(*f) : ""; -} - -#if defined(ABSL_HAVE_STD_OPTIONAL) && !defined(ABSL_USES_STD_OPTIONAL) -template <typename T> std::string AbslUnparseFlag(const std::optional<T>& f) { return f.has_value() ? absl::UnparseFlag(*f) : ""; } -#endif template <typename T> std::string Unparse(const T& v) {
diff --git a/absl/flags/marshalling_test.cc b/absl/flags/marshalling_test.cc index b0e055f..a5faabc 100644 --- a/absl/flags/marshalling_test.cc +++ b/absl/flags/marshalling_test.cc
@@ -19,6 +19,7 @@ #include <cmath> #include <limits> +#include <optional> #include <string> #include <vector> @@ -777,7 +778,7 @@ TEST(MarshallingTest, TestOptionalBoolParsing) { std::string err; - absl::optional<bool> value; + std::optional<bool> value; EXPECT_TRUE(absl::ParseFlag("", &value, &err)); EXPECT_FALSE(value.has_value()); @@ -797,7 +798,7 @@ TEST(MarshallingTest, TestOptionalIntParsing) { std::string err; - absl::optional<int> value; + std::optional<int> value; EXPECT_TRUE(absl::ParseFlag("", &value, &err)); EXPECT_FALSE(value.has_value()); @@ -817,7 +818,7 @@ TEST(MarshallingTest, TestOptionalDoubleParsing) { std::string err; - absl::optional<double> value; + std::optional<double> value; EXPECT_TRUE(absl::ParseFlag("", &value, &err)); EXPECT_FALSE(value.has_value()); @@ -837,7 +838,7 @@ TEST(MarshallingTest, TestOptionalStringParsing) { std::string err; - absl::optional<std::string> value; + std::optional<std::string> value; EXPECT_TRUE(absl::ParseFlag("", &value, &err)); EXPECT_FALSE(value.has_value()); @@ -1041,49 +1042,49 @@ // -------------------------------------------------------------------- TEST(MarshallingTest, TestOptionalBoolUnparsing) { - absl::optional<bool> value; + std::optional<bool> value; EXPECT_EQ(absl::UnparseFlag(value), ""); value = true; EXPECT_EQ(absl::UnparseFlag(value), "true"); value = false; EXPECT_EQ(absl::UnparseFlag(value), "false"); - value = absl::nullopt; + value = std::nullopt; EXPECT_EQ(absl::UnparseFlag(value), ""); } // -------------------------------------------------------------------- TEST(MarshallingTest, TestOptionalIntUnparsing) { - absl::optional<int> value; + std::optional<int> value; EXPECT_EQ(absl::UnparseFlag(value), ""); value = 0; EXPECT_EQ(absl::UnparseFlag(value), "0"); value = -12; EXPECT_EQ(absl::UnparseFlag(value), "-12"); - value = absl::nullopt; + value = std::nullopt; EXPECT_EQ(absl::UnparseFlag(value), ""); } // -------------------------------------------------------------------- TEST(MarshallingTest, TestOptionalDoubleUnparsing) { - absl::optional<double> value; + std::optional<double> value; EXPECT_EQ(absl::UnparseFlag(value), ""); value = 1.; EXPECT_EQ(absl::UnparseFlag(value), "1"); value = -1.23; EXPECT_EQ(absl::UnparseFlag(value), "-1.23"); - value = absl::nullopt; + value = std::nullopt; EXPECT_EQ(absl::UnparseFlag(value), ""); } // -------------------------------------------------------------------- TEST(MarshallingTest, TestOptionalStringUnparsing) { - absl::optional<std::string> strvalue; + std::optional<std::string> strvalue; EXPECT_EQ(absl::UnparseFlag(strvalue), ""); strvalue = "asdfg";
diff --git a/absl/functional/BUILD.bazel b/absl/functional/BUILD.bazel index b7aa31f..dcf808b 100644 --- a/absl/functional/BUILD.bazel +++ b/absl/functional/BUILD.bazel
@@ -149,7 +149,6 @@ "//absl/base:config", "//absl/strings", "//absl/strings:string_view", - "//absl/types:variant", "@googletest//:gtest", "@googletest//:gtest_main", ],
diff --git a/absl/functional/CMakeLists.txt b/absl/functional/CMakeLists.txt index 07f3dc0..4ffb513 100644 --- a/absl/functional/CMakeLists.txt +++ b/absl/functional/CMakeLists.txt
@@ -135,6 +135,5 @@ absl::overload absl::string_view absl::strings - absl::variant GTest::gmock_main )
diff --git a/absl/functional/overload_test.cc b/absl/functional/overload_test.cc index 802e11f..bb51020 100644 --- a/absl/functional/overload_test.cc +++ b/absl/functional/overload_test.cc
@@ -17,12 +17,12 @@ #include <cstdint> #include <string> #include <type_traits> +#include <variant> #include "gtest/gtest.h" #include "absl/base/config.h" #include "absl/strings/str_cat.h" #include "absl/strings/string_view.h" -#include "absl/types/variant.h" namespace { @@ -145,32 +145,32 @@ } TEST(OverloadTest, VariantVisitDispatchesCorrectly) { - absl::variant<int, double, std::string> v(1); + std::variant<int, double, std::string> v(1); auto overloaded = absl::Overload{ [](int) -> absl::string_view { return "int"; }, [](double) -> absl::string_view { return "double"; }, [](const std::string&) -> absl::string_view { return "string"; }, }; - EXPECT_EQ("int", absl::visit(overloaded, v)); + EXPECT_EQ("int", std::visit(overloaded, v)); v = 1.1; - EXPECT_EQ("double", absl::visit(overloaded, v)); + EXPECT_EQ("double", std::visit(overloaded, v)); v = "hello"; - EXPECT_EQ("string", absl::visit(overloaded, v)); + EXPECT_EQ("string", std::visit(overloaded, v)); } TEST(OverloadTest, VariantVisitWithAutoFallbackDispatchesCorrectly) { - absl::variant<std::string, int32_t, int64_t> v(int32_t{1}); + std::variant<std::string, int32_t, int64_t> v(int32_t{1}); auto overloaded = absl::Overload{ [](const std::string& s) { return s.size(); }, [](const auto& s) { return sizeof(s); }, }; - EXPECT_EQ(4, absl::visit(overloaded, v)); + EXPECT_EQ(4, std::visit(overloaded, v)); v = int64_t{1}; - EXPECT_EQ(8, absl::visit(overloaded, v)); + EXPECT_EQ(8, std::visit(overloaded, v)); v = std::string("hello"); - EXPECT_EQ(5, absl::visit(overloaded, v)); + EXPECT_EQ(5, std::visit(overloaded, v)); } // This API used to be exported as a function, so it should also work fine to @@ -180,14 +180,14 @@ absl::Overload([](const std::string& s) { return s.size(); }, [](const auto& s) { return sizeof(s); }); - absl::variant<std::string, int32_t, int64_t> v(int32_t{1}); - EXPECT_EQ(4, absl::visit(overloaded, v)); + std::variant<std::string, int32_t, int64_t> v(int32_t{1}); + EXPECT_EQ(4, std::visit(overloaded, v)); v = int64_t{1}; - EXPECT_EQ(8, absl::visit(overloaded, v)); + EXPECT_EQ(8, std::visit(overloaded, v)); v = std::string("hello"); - EXPECT_EQ(5, absl::visit(overloaded, v)); + EXPECT_EQ(5, std::visit(overloaded, v)); } TEST(OverloadTest, HasConstexprConstructor) {
diff --git a/absl/hash/BUILD.bazel b/absl/hash/BUILD.bazel index 76dd606..a2d3a02 100644 --- a/absl/hash/BUILD.bazel +++ b/absl/hash/BUILD.bazel
@@ -98,8 +98,6 @@ "//absl/numeric:bits", "//absl/strings:cord_test_helpers", "//absl/strings:string_view", - "//absl/types:optional", - "//absl/types:variant", "@googletest//:gtest", "@googletest//:gtest_main", ],
diff --git a/absl/hash/CMakeLists.txt b/absl/hash/CMakeLists.txt index c8797ff..c593a5b 100644 --- a/absl/hash/CMakeLists.txt +++ b/absl/hash/CMakeLists.txt
@@ -76,10 +76,8 @@ absl::hash_testing absl::memory absl::meta - absl::optional absl::spy_hash_state absl::string_view - absl::variant GTest::gmock_main )
diff --git a/absl/hash/hash_test.cc b/absl/hash/hash_test.cc index 7395ab7..039515a 100644 --- a/absl/hash/hash_test.cc +++ b/absl/hash/hash_test.cc
@@ -26,6 +26,7 @@ #include <ios> #include <limits> #include <memory> +#include <optional> #include <ostream> #include <set> #include <string> @@ -34,6 +35,7 @@ #include <type_traits> #include <unordered_map> #include <utility> +#include <variant> #include <vector> #include "gmock/gmock.h" @@ -49,8 +51,6 @@ #include "absl/numeric/bits.h" #include "absl/strings/cord_test_helpers.h" #include "absl/strings/string_view.h" -#include "absl/types/optional.h" -#include "absl/types/variant.h" #ifdef ABSL_INTERNAL_STD_FILESYSTEM_PATH_HASH_AVAILABLE #include <filesystem> // NOLINT @@ -748,22 +748,22 @@ } TEST(HashValueTest, Optional) { - EXPECT_TRUE(is_hashable<absl::optional<Private>>::value); + EXPECT_TRUE(is_hashable<std::optional<Private>>::value); - using O = absl::optional<Private>; + using O = std::optional<Private>; EXPECT_TRUE(absl::VerifyTypeImplementsAbslHashCorrectly( std::make_tuple(O{}, O{{1}}, O{{-1}}, O{{10}}))); } TEST(HashValueTest, Variant) { - using V = absl::variant<Private, std::string>; + using V = std::variant<Private, std::string>; EXPECT_TRUE(is_hashable<V>::value); EXPECT_TRUE(absl::VerifyTypeImplementsAbslHashCorrectly(std::make_tuple( V(Private{1}), V(Private{-1}), V(Private{2}), V("ABC"), V("BCD")))); struct S {}; - EXPECT_FALSE(is_hashable<absl::variant<S>>::value); + EXPECT_FALSE(is_hashable<std::variant<S>>::value); } TEST(HashValueTest, ReferenceWrapper) {
diff --git a/absl/hash/hash_testing.h b/absl/hash/hash_testing.h index 817a40d..509df07 100644 --- a/absl/hash/hash_testing.h +++ b/absl/hash/hash_testing.h
@@ -20,6 +20,7 @@ #include <string> #include <tuple> #include <type_traits> +#include <variant> #include <vector> #include "gmock/gmock.h" @@ -193,9 +194,9 @@ const V& value; size_t index; std::string ToString() const { - return absl::visit(PrintVisitor{index}, value); + return std::visit(PrintVisitor{index}, value); } - SpyHashState expand() const { return absl::visit(ExpandVisitor{}, value); } + SpyHashState expand() const { return std::visit(ExpandVisitor{}, value); } }; using EqClass = std::vector<Info>; @@ -206,7 +207,7 @@ for (const auto& value : values) { EqClass* c = nullptr; for (auto& eqclass : classes) { - if (absl::visit(EqVisitor<Eq>{equals}, value, eqclass[0].value)) { + if (std::visit(EqVisitor<Eq>{equals}, value, eqclass[0].value)) { c = &eqclass; break; } @@ -300,11 +301,11 @@ template <typename... T> using VariantForTypes = typename MakeTypeSet< - const typename std::decay<T>::type*...>::template apply<absl::variant>; + const typename std::decay<T>::type*...>::template apply<std::variant>; template <typename Container> struct ContainerAsVector { - using V = absl::variant<const typename Container::value_type*>; + using V = std::variant<const typename Container::value_type*>; using Out = std::vector<V>; static Out Do(const Container& values) {
diff --git a/absl/hash/internal/hash.h b/absl/hash/internal/hash.h index 4fe474e..8fe07c7 100644 --- a/absl/hash/internal/hash.h +++ b/absl/hash/internal/hash.h
@@ -63,6 +63,7 @@ #include <list> #include <map> #include <memory> +#include <optional> #include <set> #include <string> #include <string_view> @@ -71,6 +72,7 @@ #include <unordered_map> #include <unordered_set> #include <utility> +#include <variant> #include <vector> #include "absl/base/attributes.h" @@ -898,10 +900,10 @@ return H::combine(std::move(hash_state), opt.get()); } -// AbslHashValue for hashing absl::optional +// AbslHashValue for hashing std::optional template <typename H, typename T> typename std::enable_if<is_hashable<T>::value, H>::type AbslHashValue( - H hash_state, const absl::optional<T>& opt) { + H hash_state, const std::optional<T>& opt) { if (opt) hash_state = H::combine(std::move(hash_state), *opt); return H::combine(std::move(hash_state), opt.has_value()); } @@ -915,12 +917,12 @@ } }; -// AbslHashValue for hashing absl::variant +// AbslHashValue for hashing std::variant template <typename H, typename... T> typename std::enable_if<conjunction<is_hashable<T>...>::value, H>::type -AbslHashValue(H hash_state, const absl::variant<T...>& v) { +AbslHashValue(H hash_state, const std::variant<T...>& v) { if (!v.valueless_by_exception()) { - hash_state = absl::visit(VariantVisitor<H>{std::move(hash_state)}, v); + hash_state = std::visit(VariantVisitor<H>{std::move(hash_state)}, v); } return H::combine(std::move(hash_state), v.index()); }
diff --git a/absl/hash/internal/spy_hash_state.h b/absl/hash/internal/spy_hash_state.h index 823e1e9..80c9767 100644 --- a/absl/hash/internal/spy_hash_state.h +++ b/absl/hash/internal/spy_hash_state.h
@@ -18,6 +18,8 @@ #include <algorithm> #include <cstddef> #include <cstdint> +#include <memory> +#include <optional> #include <ostream> #include <string> #include <vector> @@ -44,7 +46,7 @@ template <typename T> class SpyHashStateImpl : public HashStateBase<SpyHashStateImpl<T>> { public: - SpyHashStateImpl() : error_(std::make_shared<absl::optional<std::string>>()) { + SpyHashStateImpl() : error_(std::make_shared<std::optional<std::string>>()) { static_assert(std::is_void<T>::value, ""); } @@ -198,7 +200,7 @@ return state; } - absl::optional<std::string> error() const { + std::optional<std::string> error() const { if (moved_from_) { return "Returned a moved-from instance of the hash state object."; } @@ -212,7 +214,7 @@ struct UnorderedCombinerCallback { std::vector<std::string> element_hash_representations; - std::shared_ptr<absl::optional<std::string>> error; + std::shared_ptr<std::optional<std::string>> error; // The inner spy can have a different type. template <typename U> @@ -242,7 +244,7 @@ // This is a shared_ptr because we want all instances of the particular // SpyHashState run to share the field. This way we can set the error for // use-after-move and all the copies will see it. - std::shared_ptr<absl::optional<std::string>> error_; + std::shared_ptr<std::optional<std::string>> error_; bool moved_from_ = false; };
diff --git a/absl/log/BUILD.bazel b/absl/log/BUILD.bazel index 5bc7150..ec2fde9 100644 --- a/absl/log/BUILD.bazel +++ b/absl/log/BUILD.bazel
@@ -285,7 +285,6 @@ ":vlog_is_on", "//absl/base:log_severity", "//absl/flags:flag", - "//absl/types:optional", "@googletest//:gtest", "@googletest//:gtest_main", ], @@ -501,7 +500,6 @@ "//absl/log/internal:test_matchers", "//absl/strings", "//absl/strings:str_format", - "//absl/types:optional", "@googletest//:gtest", "@googletest//:gtest_main", ],
diff --git a/absl/log/CMakeLists.txt b/absl/log/CMakeLists.txt index 9d097ab..609f432 100644 --- a/absl/log/CMakeLists.txt +++ b/absl/log/CMakeLists.txt
@@ -757,7 +757,6 @@ absl::nullability absl::strings absl::synchronization - absl::optional ) absl_cc_library( @@ -806,7 +805,6 @@ absl::vlog_is_on absl::log_severity absl::flags - absl::optional GTest::gmock_main ) @@ -1016,7 +1014,6 @@ absl::config absl::log absl::log_internal_test_matchers - absl::optional absl::scoped_mock_log absl::str_format absl::strings
diff --git a/absl/log/internal/BUILD.bazel b/absl/log/internal/BUILD.bazel index 32ae277..833a5f9 100644 --- a/absl/log/internal/BUILD.bazel +++ b/absl/log/internal/BUILD.bazel
@@ -470,7 +470,6 @@ "//absl/memory", "//absl/strings", "//absl/synchronization", - "//absl/types:optional", ], )
diff --git a/absl/log/internal/structured_proto.cc b/absl/log/internal/structured_proto.cc index e3829e4..eed2e88 100644 --- a/absl/log/internal/structured_proto.cc +++ b/absl/log/internal/structured_proto.cc
@@ -16,11 +16,11 @@ #include "absl/log/internal/structured_proto.h" #include <cstdint> +#include <variant> #include "absl/base/config.h" #include "absl/log/internal/proto.h" #include "absl/types/span.h" -#include "absl/types/variant.h" namespace absl { ABSL_NAMESPACE_BEGIN @@ -81,11 +81,11 @@ // Handles protobuf-encoding a type contained inside `StructuredProtoField`. struct EncoderVisitor final { bool operator()(StructuredProtoField::Varint varint) { - return absl::visit(VarintEncoderVisitor{field_number, buf}, varint); + return std::visit(VarintEncoderVisitor{field_number, buf}, varint); } bool operator()(StructuredProtoField::I64 i64) { - return absl::visit(I64EncoderVisitor{field_number, buf}, i64); + return std::visit(I64EncoderVisitor{field_number, buf}, i64); } bool operator()(StructuredProtoField::LengthDelimited length_delimited) { @@ -95,7 +95,7 @@ } bool operator()(StructuredProtoField::I32 i32) { - return absl::visit(I32EncoderVisitor{field_number, buf}, i32); + return std::visit(I32EncoderVisitor{field_number, buf}, i32); } uint64_t field_number; @@ -106,7 +106,7 @@ bool EncodeStructuredProtoField(StructuredProtoField field, absl::Span<char>& buf) { - return absl::visit(EncoderVisitor{field.field_number, buf}, field.value); + return std::visit(EncoderVisitor{field.field_number, buf}, field.value); } } // namespace log_internal
diff --git a/absl/log/internal/structured_proto.h b/absl/log/internal/structured_proto.h index 3ebc4be..04ec499 100644 --- a/absl/log/internal/structured_proto.h +++ b/absl/log/internal/structured_proto.h
@@ -21,6 +21,7 @@ #include <cstddef> #include <cstdint> +#include <variant> #include "absl/base/config.h" #include "absl/log/internal/proto.h" @@ -35,11 +36,11 @@ struct StructuredProtoField final { // Numeric type encoded with varint encoding: // https://protobuf.dev/programming-guides/encoding/#varints - using Varint = absl::variant<uint64_t, int64_t, uint32_t, int32_t, bool>; + using Varint = std::variant<uint64_t, int64_t, uint32_t, int32_t, bool>; // Fixed-length 64-bit integer encoding: // https://protobuf.dev/programming-guides/encoding/#non-varints - using I64 = absl::variant<uint64_t, int64_t, double>; + using I64 = std::variant<uint64_t, int64_t, double>; // Length-delimited record type (string, sub-message): // https://protobuf.dev/programming-guides/encoding/#length-types @@ -47,11 +48,11 @@ // Fixed-length 32-bit integer encoding: // https://protobuf.dev/programming-guides/encoding/#non-varints - using I32 = absl::variant<uint32_t, int32_t, float>; + using I32 = std::variant<uint32_t, int32_t, float>; // Valid record type: // https://protobuf.dev/programming-guides/encoding/#structure - using Value = absl::variant<Varint, I64, LengthDelimited, I32>; + using Value = std::variant<Varint, I64, LengthDelimited, I32>; // Field number for the protobuf value. uint64_t field_number; @@ -88,7 +89,7 @@ uint64_t field_number; }; - return absl::visit(BufferSizeVisitor{field.field_number}, field.value); + return std::visit(BufferSizeVisitor{field.field_number}, field.value); } // Encodes `field` into `buf` using protobuf encoding.
diff --git a/absl/log/internal/vlog_config.cc b/absl/log/internal/vlog_config.cc index e9b4827..51f003c 100644 --- a/absl/log/internal/vlog_config.cc +++ b/absl/log/internal/vlog_config.cc
@@ -20,6 +20,7 @@ #include <atomic> #include <functional> #include <memory> +#include <optional> #include <string> #include <utility> #include <vector> @@ -38,7 +39,6 @@ #include "absl/strings/string_view.h" #include "absl/strings/strip.h" #include "absl/synchronization/mutex.h" -#include "absl/types/optional.h" namespace absl { ABSL_NAMESPACE_BEGIN @@ -189,7 +189,7 @@ // Allocates memory. int PrependVModuleLocked(absl::string_view module_pattern, int log_level) ABSL_EXCLUSIVE_LOCKS_REQUIRED(mutex) { - absl::optional<int> old_log_level; + std::optional<int> old_log_level; for (const auto& info : get_vmodule_info()) { if (FNMatch(info.module_pattern, module_pattern)) { old_log_level = info.vlog_level;
diff --git a/absl/log/log_format_test.cc b/absl/log/log_format_test.cc index 9f1cc6b..b23d90f 100644 --- a/absl/log/log_format_test.cc +++ b/absl/log/log_format_test.cc
@@ -19,6 +19,7 @@ #include <iomanip> #include <ios> #include <limits> +#include <optional> #include <ostream> #include <sstream> #include <string> @@ -28,6 +29,7 @@ #ifdef __ANDROID__ #include <android/api-level.h> #endif + #include "gmock/gmock.h" #include "gtest/gtest.h" #include "absl/base/config.h" @@ -39,7 +41,6 @@ #include "absl/strings/str_cat.h" #include "absl/strings/str_format.h" #include "absl/strings/string_view.h" -#include "absl/types/optional.h" namespace { using ::absl::log_internal::AsString; @@ -2096,7 +2097,7 @@ } private: - absl::optional<size_t> size_; + std::optional<size_t> size_; } extractor_sink; LOG(INFO).NoPrefix().ToSinkOnly(&extractor_sink) << std::string(2 * absl::log_internal::kLogMessageBufferSize, 'x');
diff --git a/absl/log/log_streamer.h b/absl/log/log_streamer.h index 4ed2435..32c3402 100644 --- a/absl/log/log_streamer.h +++ b/absl/log/log_streamer.h
@@ -24,6 +24,7 @@ #include <ios> #include <memory> +#include <optional> #include <ostream> #include <string> #include <utility> @@ -131,7 +132,7 @@ std::string buf_; // A disengaged `stream_` indicates a moved-from `LogStreamer` that should not // `LOG` upon destruction. - absl::optional<absl::strings_internal::OStringStream> stream_; + std::optional<absl::strings_internal::OStringStream> stream_; }; // LogInfoStreamer()
diff --git a/absl/log/vlog_is_on_test.cc b/absl/log/vlog_is_on_test.cc index f612283..d523781 100644 --- a/absl/log/vlog_is_on_test.cc +++ b/absl/log/vlog_is_on_test.cc
@@ -14,6 +14,8 @@ #include "absl/log/vlog_is_on.h" +#include <optional> + #include "gmock/gmock.h" #include "gtest/gtest.h" #include "absl/base/log_severity.h" @@ -22,25 +24,24 @@ #include "absl/log/globals.h" #include "absl/log/log.h" #include "absl/log/scoped_mock_log.h" -#include "absl/types/optional.h" namespace { using ::testing::_; -absl::optional<int> MaxLogVerbosity() { +std::optional<int> MaxLogVerbosity() { #ifdef ABSL_MAX_VLOG_VERBOSITY return ABSL_MAX_VLOG_VERBOSITY; #else - return absl::nullopt; + return std::nullopt; #endif } -absl::optional<int> MinLogLevel() { +std::optional<int> MinLogLevel() { #ifdef ABSL_MIN_LOG_LEVEL return static_cast<int>(ABSL_MIN_LOG_LEVEL); #else - return absl::nullopt; + return std::nullopt; #endif }
diff --git a/absl/random/CMakeLists.txt b/absl/random/CMakeLists.txt index e0294a1..7382b0d 100644 --- a/absl/random/CMakeLists.txt +++ b/absl/random/CMakeLists.txt
@@ -852,7 +852,6 @@ absl::random_internal_platform absl::random_internal_randen_hwaes_impl absl::config - absl::optional ) # Internal-only target, do not depend on directly.
diff --git a/absl/random/internal/BUILD.bazel b/absl/random/internal/BUILD.bazel index 1a3fef8..d292d34 100644 --- a/absl/random/internal/BUILD.bazel +++ b/absl/random/internal/BUILD.bazel
@@ -399,7 +399,6 @@ ":platform", ":randen_hwaes_impl", "//absl/base:config", - "//absl/types:optional", ], )
diff --git a/absl/random/internal/mock_helpers.h b/absl/random/internal/mock_helpers.h index 85f7387..2d66a3b 100644 --- a/absl/random/internal/mock_helpers.h +++ b/absl/random/internal/mock_helpers.h
@@ -16,6 +16,7 @@ #ifndef ABSL_RANDOM_INTERNAL_MOCK_HELPERS_H_ #define ABSL_RANDOM_INTERNAL_MOCK_HELPERS_H_ +#include <optional> #include <utility> #include "absl/base/config.h" @@ -71,21 +72,21 @@ // Empty implementation of InvokeMock. template <typename KeyT, typename ReturnT, typename ArgTupleT, typename URBG, typename... Args> - static absl::optional<ReturnT> InvokeMockImpl(char, URBG*, Args&&...) { - return absl::nullopt; + static std::optional<ReturnT> InvokeMockImpl(char, URBG*, Args&&...) { + return std::nullopt; } // Non-empty implementation of InvokeMock. template <typename KeyT, typename ReturnT, typename ArgTupleT, typename URBG, typename = invoke_mock_t<URBG>, typename... Args> - static absl::optional<ReturnT> InvokeMockImpl(int, URBG* urbg, - Args&&... args) { + static std::optional<ReturnT> InvokeMockImpl(int, URBG* urbg, + Args&&... args) { ArgTupleT arg_tuple(std::forward<Args>(args)...); ReturnT result; if (urbg->InvokeMock(FastTypeId<KeyT>(), &arg_tuple, &result)) { return result; } - return absl::nullopt; + return std::nullopt; } public: @@ -108,7 +109,7 @@ // the underlying mechanism requires a pointer to an argument tuple. template <typename KeyT, typename URBG, typename... Args> static auto MaybeInvokeMock(URBG* urbg, Args&&... args) - -> absl::optional<typename KeySignature<KeyT>::result_type> { + -> std::optional<typename KeySignature<KeyT>::result_type> { // Use function overloading to dispatch to the implementation since // more modern patterns (e.g. require + constexpr) are not supported in all // compiler configurations.
diff --git a/absl/random/internal/randen_detect.cc b/absl/random/internal/randen_detect.cc index 63e8379..fc8c673 100644 --- a/absl/random/internal/randen_detect.cc +++ b/absl/random/internal/randen_detect.cc
@@ -31,9 +31,9 @@ #include <cstdint> #include <cstring> +#include <optional> // IWYU pragma: keep #include "absl/random/internal/platform.h" -#include "absl/types/optional.h" // IWYU pragma: keep #if !defined(__UCLIBC__) && defined(__GLIBC__) && \ (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 16)) @@ -115,12 +115,12 @@ #if defined(__APPLE__) && defined(ABSL_ARCH_AARCH64) template <typename T> -static absl::optional<T> ReadSysctlByName(const char* name) { +static std::optional<T> ReadSysctlByName(const char* name) { T val; size_t val_size = sizeof(T); int ret = sysctlbyname(name, &val, &val_size, nullptr, 0); if (ret == -1) { - return absl::nullopt; + return std::nullopt; } return val; } @@ -210,7 +210,7 @@ // Newer XNU kernels support querying all capabilities in a single // sysctlbyname. #if defined(CAP_BIT_AdvSIMD) && defined(CAP_BIT_FEAT_AES) - static const absl::optional<uint64_t> caps = + static const std::optional<uint64_t> caps = ReadSysctlByName<uint64_t>("hw.optional.arm.caps"); if (caps.has_value()) { constexpr uint64_t kNeonAndAesCaps = @@ -220,13 +220,13 @@ #endif // https://developer.apple.com/documentation/kernel/1387446-sysctlbyname/determining_instruction_set_characteristics#overview - static const absl::optional<int> adv_simd = + static const std::optional<int> adv_simd = ReadSysctlByName<int>("hw.optional.AdvSIMD"); if (adv_simd.value_or(0) == 0) { return false; } // https://developer.apple.com/documentation/kernel/1387446-sysctlbyname/determining_instruction_set_characteristics#3918855 - static const absl::optional<int> feat_aes = + static const std::optional<int> feat_aes = ReadSysctlByName<int>("hw.optional.arm.FEAT_AES"); if (feat_aes.value_or(0) == 0) { return false;
diff --git a/absl/random/internal/salted_seed_seq.h b/absl/random/internal/salted_seed_seq.h index 0629186..c374d93 100644 --- a/absl/random/internal/salted_seed_seq.h +++ b/absl/random/internal/salted_seed_seq.h
@@ -20,6 +20,7 @@ #include <initializer_list> #include <iterator> #include <memory> +#include <optional> #include <type_traits> #include <utility> #include <vector>
diff --git a/absl/random/internal/seed_material.cc b/absl/random/internal/seed_material.cc index b6380c8..f509926 100644 --- a/absl/random/internal/seed_material.cc +++ b/absl/random/internal/seed_material.cc
@@ -28,6 +28,7 @@ #include <cstdint> #include <cstdlib> #include <cstring> +#include <optional> #include <string> #include <vector> @@ -38,7 +39,6 @@ #include "absl/strings/escaping.h" #include "absl/strings/string_view.h" #include "absl/strings/strip.h" -#include "absl/types/optional.h" #include "absl/types/span.h" #if defined(_WIN32) @@ -228,17 +228,17 @@ } } -absl::optional<uint32_t> GetSaltMaterial() { +std::optional<uint32_t> GetSaltMaterial() { // Salt must be common for all generators within the same process so read it // only once and store in static variable. - static const auto salt_material = []() -> absl::optional<uint32_t> { + static const auto salt_material = []() -> std::optional<uint32_t> { uint32_t salt_value = 0; if (ReadSeedMaterialFromOSEntropy(absl::MakeSpan(&salt_value, 1))) { return salt_value; } - return absl::nullopt; + return std::nullopt; }(); return salt_material;
diff --git a/absl/random/internal/seed_material.h b/absl/random/internal/seed_material.h index b671a8c..23bf4fa 100644 --- a/absl/random/internal/seed_material.h +++ b/absl/random/internal/seed_material.h
@@ -18,6 +18,7 @@ #include <cassert> #include <cstdint> #include <cstdlib> +#include <optional> #include <string> #include <vector> @@ -95,7 +96,7 @@ // Salt is obtained only once and stored in static variable. // // May return empty value if obtaining the salt was not possible. -absl::optional<uint32_t> GetSaltMaterial(); +std::optional<uint32_t> GetSaltMaterial(); } // namespace random_internal ABSL_NAMESPACE_END
diff --git a/absl/status/internal/status_internal.cc b/absl/status/internal/status_internal.cc index 9884189..74bece4 100644 --- a/absl/status/internal/status_internal.cc +++ b/absl/status/internal/status_internal.cc
@@ -21,6 +21,7 @@ #include <cstdio> #include <cstring> #include <memory> +#include <optional> #include <string> #include <utility> @@ -40,7 +41,6 @@ #include "absl/strings/str_format.h" #include "absl/strings/str_split.h" #include "absl/strings/string_view.h" -#include "absl/types/optional.h" namespace absl { ABSL_NAMESPACE_BEGIN @@ -56,24 +56,24 @@ } } -static absl::optional<size_t> FindPayloadIndexByUrl( - const Payloads* payloads, absl::string_view type_url) { - if (payloads == nullptr) return absl::nullopt; +static std::optional<size_t> FindPayloadIndexByUrl(const Payloads* payloads, + absl::string_view type_url) { + if (payloads == nullptr) return std::nullopt; for (size_t i = 0; i < payloads->size(); ++i) { if ((*payloads)[i].type_url == type_url) return i; } - return absl::nullopt; + return std::nullopt; } -absl::optional<absl::Cord> StatusRep::GetPayload( +std::optional<absl::Cord> StatusRep::GetPayload( absl::string_view type_url) const { - absl::optional<size_t> index = + std::optional<size_t> index = status_internal::FindPayloadIndexByUrl(payloads_.get(), type_url); if (index.has_value()) return (*payloads_)[index.value()].payload; - return absl::nullopt; + return std::nullopt; } void StatusRep::SetPayload(absl::string_view type_url, absl::Cord payload) { @@ -81,7 +81,7 @@ payloads_ = absl::make_unique<status_internal::Payloads>(); } - absl::optional<size_t> index = + std::optional<size_t> index = status_internal::FindPayloadIndexByUrl(payloads_.get(), type_url); if (index.has_value()) { (*payloads_)[index.value()].payload = std::move(payload); @@ -92,7 +92,7 @@ } StatusRep::EraseResult StatusRep::ErasePayload(absl::string_view type_url) { - absl::optional<size_t> index = + std::optional<size_t> index = status_internal::FindPayloadIndexByUrl(payloads_.get(), type_url); if (!index.has_value()) return {false, Status::PointerToRep(this)}; payloads_->erase(payloads_->begin() + index.value()); @@ -142,7 +142,7 @@ status_internal::GetStatusPayloadPrinter(); this->ForEachPayload([&](absl::string_view type_url, const absl::Cord& payload) { - absl::optional<std::string> result; + std::optional<std::string> result; if (printer) result = printer(type_url, payload); absl::StrAppend( &text, " [", type_url, "='",
diff --git a/absl/status/internal/status_internal.h b/absl/status/internal/status_internal.h index 35a9f9b..f2bd83a 100644 --- a/absl/status/internal/status_internal.h +++ b/absl/status/internal/status_internal.h
@@ -20,6 +20,8 @@ #include <string> #include <utility> +#include <optional> + #include "absl/base/attributes.h" #include "absl/base/config.h" #include "absl/base/nullability.h" @@ -83,7 +85,7 @@ void Unref() const; // Payload methods correspond to the same methods in absl::Status. - absl::optional<absl::Cord> GetPayload(absl::string_view type_url) const; + std::optional<absl::Cord> GetPayload(absl::string_view type_url) const; void SetPayload(absl::string_view type_url, absl::Cord payload); struct EraseResult { bool erased;
diff --git a/absl/status/status.cc b/absl/status/status.cc index f219933..479c39f 100644 --- a/absl/status/status.cc +++ b/absl/status/status.cc
@@ -37,7 +37,6 @@ #include "absl/strings/str_format.h" #include "absl/strings/str_split.h" #include "absl/strings/string_view.h" -#include "absl/types/optional.h" namespace absl { ABSL_NAMESPACE_BEGIN
diff --git a/absl/status/status.h b/absl/status/status.h index b26d072..ab4a489 100644 --- a/absl/status/status.h +++ b/absl/status/status.h
@@ -53,6 +53,7 @@ #include <cassert> #include <cstdint> +#include <optional> #include <ostream> #include <string> #include <utility> @@ -583,32 +584,32 @@ // Status::GetPayload() // // Gets the payload of a status given its unique `type_url` key, if present. - absl::optional<absl::Cord> GetPayload(absl::string_view type_url) const; +std::optional<absl::Cord> GetPayload(absl::string_view type_url) const; - // Status::SetPayload() - // - // Sets the payload for a non-ok status using a `type_url` key, overwriting - // any existing payload for that `type_url`. - // - // NOTE: This function does nothing if the Status is ok. - void SetPayload(absl::string_view type_url, absl::Cord payload); +// Status::SetPayload() +// +// Sets the payload for a non-ok status using a `type_url` key, overwriting +// any existing payload for that `type_url`. +// +// NOTE: This function does nothing if the Status is ok. +void SetPayload(absl::string_view type_url, absl::Cord payload); - // Status::ErasePayload() - // - // Erases the payload corresponding to the `type_url` key. Returns `true` if - // the payload was present. - bool ErasePayload(absl::string_view type_url); +// Status::ErasePayload() +// +// Erases the payload corresponding to the `type_url` key. Returns `true` if +// the payload was present. +bool ErasePayload(absl::string_view type_url); - // Status::ForEachPayload() - // - // Iterates over the stored payloads and calls the - // `visitor(type_key, payload)` callable for each one. - // - // NOTE: The order of calls to `visitor()` is not specified and may change at - // any time. - // - // NOTE: Any mutation on the same 'absl::Status' object during visitation is - // forbidden and could result in undefined behavior. +// Status::ForEachPayload() +// +// Iterates over the stored payloads and calls the +// `visitor(type_key, payload)` callable for each one. +// +// NOTE: The order of calls to `visitor()` is not specified and may change at +// any time. +// +// NOTE: Any mutation on the same 'absl::Status' object during visitation is +// forbidden and could result in undefined behavior. void ForEachPayload( absl::FunctionRef<void(absl::string_view, const absl::Cord&)> visitor) const; @@ -862,9 +863,9 @@ swap(a.rep_, b.rep_); } -inline absl::optional<absl::Cord> Status::GetPayload( +inline std::optional<absl::Cord> Status::GetPayload( absl::string_view type_url) const { - if (IsInlined(rep_)) return absl::nullopt; + if (IsInlined(rep_)) return std::nullopt; return RepToPointer(rep_)->GetPayload(type_url); }
diff --git a/absl/status/status_payload_printer.h b/absl/status/status_payload_printer.h index fc55515..7e2c8c8 100644 --- a/absl/status/status_payload_printer.h +++ b/absl/status/status_payload_printer.h
@@ -14,6 +14,7 @@ #ifndef ABSL_STATUS_STATUS_PAYLOAD_PRINTER_H_ #define ABSL_STATUS_STATUS_PAYLOAD_PRINTER_H_ +#include <optional> #include <string> #include "absl/base/nullability.h" @@ -30,12 +31,12 @@ // extension point, which is a global printer function that can be set by users // to specify how to print payloads. The function takes the type URL and the // payload as input, and should return a valid human-readable string on success -// or `absl::nullopt` on failure (in which case it falls back to the default +// or `std::nullopt` on failure (in which case it falls back to the default // approach of printing the raw bytes). // NOTE: This is an internal API and the design is subject to change in the // future in a non-backward-compatible way. Since it's only meant for debugging // purpose, you should not rely on it in any critical logic. -using StatusPayloadPrinter = absl::optional<std::string> (*absl_nullable)( +using StatusPayloadPrinter = std::optional<std::string> (*absl_nullable)( absl::string_view, const absl::Cord&); // Sets the global payload printer. Only one printer should be set per process.
diff --git a/absl/status/statusor.h b/absl/status/statusor.h index 52294ee..2427d24 100644 --- a/absl/status/statusor.h +++ b/absl/status/statusor.h
@@ -43,6 +43,7 @@ #include <string> #include <type_traits> #include <utility> +#include <variant> #include "absl/base/attributes.h" #include "absl/base/call_once.h"
diff --git a/absl/status/statusor_test.cc b/absl/status/statusor_test.cc index 26d4235..82cb930 100644 --- a/absl/status/statusor_test.cc +++ b/absl/status/statusor_test.cc
@@ -14,6 +14,7 @@ #include "absl/status/statusor.h" +#include <any> #include <array> #include <cstddef> #include <cstdint> @@ -25,6 +26,7 @@ #include <string> #include <type_traits> #include <utility> +#include <variant> #include <vector> #include "gmock/gmock.h" @@ -35,8 +37,6 @@ #include "absl/status/status_matchers.h" #include "absl/strings/str_cat.h" #include "absl/strings/string_view.h" -#include "absl/types/any.h" -#include "absl/types/variant.h" #include "absl/utility/utility.h" namespace { @@ -696,13 +696,13 @@ TEST(StatusOr, ImplicitConstruction) { // Check implicit casting works. auto status_or = - absl::implicit_cast<absl::StatusOr<absl::variant<int, std::string>>>(10); + absl::implicit_cast<absl::StatusOr<std::variant<int, std::string>>>(10); EXPECT_THAT(status_or, IsOkAndHolds(VariantWith<int>(10))); } TEST(StatusOr, ImplicitConstructionFromInitliazerList) { // Note: dropping the explicit std::initializer_list<int> is not supported - // by absl::StatusOr or absl::optional. + // by absl::StatusOr or std::optional. auto status_or = absl::implicit_cast<absl::StatusOr<std::vector<int>>>({{10, 20, 30}}); EXPECT_THAT(status_or, IsOkAndHolds(ElementsAre(10, 20, 30))); @@ -796,49 +796,49 @@ } TEST(StatusOr, StatusOrAnyCopyAndMoveConstructorTests) { - absl::StatusOr<absl::any> status_or = CopyDetector(10); - absl::StatusOr<absl::any> status_error = absl::InvalidArgumentError("foo"); + absl::StatusOr<std::any> status_or = CopyDetector(10); + absl::StatusOr<std::any> status_error = absl::InvalidArgumentError("foo"); EXPECT_THAT( status_or, IsOkAndHolds(AnyWith<CopyDetector>(CopyDetectorHas(10, true, false)))); - absl::StatusOr<absl::any> a = status_or; + absl::StatusOr<std::any> a = status_or; EXPECT_THAT( a, IsOkAndHolds(AnyWith<CopyDetector>(CopyDetectorHas(10, false, true)))); - absl::StatusOr<absl::any> a_err = status_error; + absl::StatusOr<std::any> a_err = status_error; EXPECT_THAT(a_err, Not(IsOk())); - const absl::StatusOr<absl::any>& cref = status_or; + const absl::StatusOr<std::any>& cref = status_or; // No lint for no-change copy. - absl::StatusOr<absl::any> b = cref; // NOLINT + absl::StatusOr<std::any> b = cref; // NOLINT EXPECT_THAT( b, IsOkAndHolds(AnyWith<CopyDetector>(CopyDetectorHas(10, false, true)))); - const absl::StatusOr<absl::any>& cref_err = status_error; + const absl::StatusOr<std::any>& cref_err = status_error; // No lint for no-change copy. - absl::StatusOr<absl::any> b_err = cref_err; // NOLINT + absl::StatusOr<std::any> b_err = cref_err; // NOLINT EXPECT_THAT(b_err, Not(IsOk())); - absl::StatusOr<absl::any> c = std::move(status_or); + absl::StatusOr<std::any> c = std::move(status_or); EXPECT_THAT( c, IsOkAndHolds(AnyWith<CopyDetector>(CopyDetectorHas(10, true, false)))); - absl::StatusOr<absl::any> c_err = std::move(status_error); + absl::StatusOr<std::any> c_err = std::move(status_error); EXPECT_THAT(c_err, Not(IsOk())); } TEST(StatusOr, StatusOrAnyCopyAndMoveAssignment) { - absl::StatusOr<absl::any> status_or = CopyDetector(10); - absl::StatusOr<absl::any> status_error = absl::InvalidArgumentError("foo"); - absl::StatusOr<absl::any> a; + absl::StatusOr<std::any> status_or = CopyDetector(10); + absl::StatusOr<std::any> status_error = absl::InvalidArgumentError("foo"); + absl::StatusOr<std::any> a; a = status_or; EXPECT_THAT( a, IsOkAndHolds(AnyWith<CopyDetector>(CopyDetectorHas(10, false, true)))); a = status_error; EXPECT_THAT(a, Not(IsOk())); - const absl::StatusOr<absl::any>& cref = status_or; + const absl::StatusOr<std::any>& cref = status_or; a = cref; EXPECT_THAT( a, IsOkAndHolds(AnyWith<CopyDetector>(CopyDetectorHas(10, false, true)))); - const absl::StatusOr<absl::any>& cref_err = status_error; + const absl::StatusOr<std::any>& cref_err = status_error; a = cref_err; EXPECT_THAT(a, Not(IsOk())); a = std::move(status_or); @@ -876,15 +876,15 @@ } TEST(StatusOr, AbslAnyAssignment) { - EXPECT_FALSE((std::is_assignable<absl::StatusOr<absl::any>, + EXPECT_FALSE((std::is_assignable<absl::StatusOr<std::any>, absl::StatusOr<int>>::value)); - absl::StatusOr<absl::any> status_or; + absl::StatusOr<std::any> status_or; status_or = absl::InvalidArgumentError("foo"); EXPECT_THAT(status_or, Not(IsOk())); } TEST(StatusOr, ImplicitAssignment) { - absl::StatusOr<absl::variant<int, std::string>> status_or; + absl::StatusOr<std::variant<int, std::string>> status_or; status_or = 10; EXPECT_THAT(status_or, IsOkAndHolds(VariantWith<int>(10))); }
diff --git a/absl/strings/BUILD.bazel b/absl/strings/BUILD.bazel index a1e5021..64e207b 100644 --- a/absl/strings/BUILD.bazel +++ b/absl/strings/BUILD.bazel
@@ -254,7 +254,6 @@ visibility = ["//visibility:private"], deps = [ ":strings", - "//absl/types:optional", "@googletest//:gtest", "@googletest//:gtest_main", ], @@ -278,7 +277,6 @@ visibility = ["//visibility:private"], deps = [ ":has_ostream_operator", - "//absl/types:optional", "@googletest//:gtest", "@googletest//:gtest_main", ], @@ -978,7 +976,6 @@ "//absl/log:check", "//absl/random", "//absl/types:compare", - "//absl/types:optional", "@googletest//:gtest", "@googletest//:gtest_main", ], @@ -1371,7 +1368,6 @@ "//absl/numeric:bits", "//absl/numeric:int128", "//absl/numeric:representation", - "//absl/types:optional", "//absl/types:span", "//absl/utility", ], @@ -1465,7 +1461,6 @@ "//absl/base:raw_logging_internal", "//absl/log", "//absl/numeric:int128", - "//absl/types:optional", "//absl/types:span", "@googletest//:gtest", "@googletest//:gtest_main", @@ -1535,7 +1530,6 @@ ":str_format", ":strings", "//absl/base", - "//absl/types:optional", ], )
diff --git a/absl/strings/CMakeLists.txt b/absl/strings/CMakeLists.txt index a03943d..0e0adfa 100644 --- a/absl/strings/CMakeLists.txt +++ b/absl/strings/CMakeLists.txt
@@ -231,7 +231,6 @@ COPTS ${ABSL_TEST_COPTS} DEPS - absl::optional absl::strings GTest::gmock_main ) @@ -245,7 +244,6 @@ ${ABSL_TEST_COPTS} DEPS absl::has_ostream_operator - absl::optional GTest::gmock_main ) @@ -1138,7 +1136,6 @@ absl::hash_testing absl::no_destructor absl::log - absl::optional absl::random_random absl::str_format absl::strings
diff --git a/absl/strings/atod_manual_test.cc b/absl/strings/atod_manual_test.cc index 6cf28b0..b22657a 100644 --- a/absl/strings/atod_manual_test.cc +++ b/absl/strings/atod_manual_test.cc
@@ -39,13 +39,13 @@ #include <cstdint> #include <cstdio> +#include <optional> #include <string> #include "absl/base/casts.h" #include "absl/strings/numbers.h" #include "absl/strings/str_format.h" #include "absl/strings/string_view.h" -#include "absl/types/optional.h" static constexpr uint8_t kUnhex[256] = { 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, // @@ -85,10 +85,10 @@ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, // }; -static absl::optional<std::string> ReadFileToString(const char* filename) { +static std::optional<std::string> ReadFileToString(const char* filename) { FILE* f = fopen(filename, "rb"); if (!f) { - return absl::nullopt; + return std::nullopt; } fseek(f, 0, SEEK_END); size_t size = ftell(f); @@ -97,13 +97,13 @@ size_t n = fread(&s[0], 1, size, f); fclose(f); if (n != size) { - return absl::nullopt; + return std::nullopt; } return s; } static bool ProcessOneTestFile(const char* filename) { - absl::optional<std::string> contents = ReadFileToString(filename); + std::optional<std::string> contents = ReadFileToString(filename); if (!contents) { absl::FPrintF(stderr, "Invalid file: %s\n", filename); return false;
diff --git a/absl/strings/cord.cc b/absl/strings/cord.cc index d3014f3..aa450d3 100644 --- a/absl/strings/cord.cc +++ b/absl/strings/cord.cc
@@ -26,6 +26,7 @@ #include <iostream> #include <limits> #include <memory> +#include <optional> #include <ostream> #include <sstream> #include <string> @@ -36,8 +37,8 @@ #include "absl/base/internal/endian.h" #include "absl/base/internal/raw_logging.h" #include "absl/base/macros.h" -#include "absl/base/optimization.h" #include "absl/base/nullability.h" +#include "absl/base/optimization.h" #include "absl/container/inlined_vector.h" #include "absl/crc/crc32c.h" #include "absl/crc/internal/crc_cord_state.h" @@ -56,7 +57,6 @@ #include "absl/strings/str_cat.h" #include "absl/strings/string_view.h" #include "absl/strings/strip.h" -#include "absl/types/optional.h" #include "absl/types/span.h" namespace absl { @@ -886,9 +886,9 @@ return &contents_.tree()->crc()->crc_cord_state; } -absl::optional<uint32_t> Cord::ExpectedChecksum() const { +std::optional<uint32_t> Cord::ExpectedChecksum() const { if (!contents_.is_tree() || !contents_.tree()->IsCrc()) { - return absl::nullopt; + return std::nullopt; } return static_cast<uint32_t>( contents_.tree()->crc()->crc_cord_state.Checksum());
diff --git a/absl/strings/cord.h b/absl/strings/cord.h index 965361c..3278296 100644 --- a/absl/strings/cord.h +++ b/absl/strings/cord.h
@@ -67,6 +67,7 @@ #include <cstring> #include <iosfwd> #include <iterator> +#include <optional> #include <string> #include <type_traits> #include <utility> @@ -763,7 +764,7 @@ // // If this cord's representation is a single flat array, returns a // string_view referencing that array. Otherwise returns nullopt. - absl::optional<absl::string_view> TryFlat() const + std::optional<absl::string_view> TryFlat() const ABSL_ATTRIBUTE_LIFETIME_BOUND; // Cord::Flatten() @@ -816,11 +817,11 @@ // Returns this cord's expected checksum, if it has one. Otherwise, returns // nullopt. - absl::optional<uint32_t> ExpectedChecksum() const; + std::optional<uint32_t> ExpectedChecksum() const; template <typename H> friend H AbslHashValue(H hash_state, const absl::Cord& c) { - absl::optional<absl::string_view> maybe_flat = c.TryFlat(); + std::optional<absl::string_view> maybe_flat = c.TryFlat(); if (maybe_flat.has_value()) { return H::combine(std::move(hash_state), *maybe_flat); } @@ -1396,7 +1397,7 @@ return result; } -inline absl::optional<absl::string_view> Cord::TryFlat() const +inline std::optional<absl::string_view> Cord::TryFlat() const ABSL_ATTRIBUTE_LIFETIME_BOUND { absl::cord_internal::CordRep* rep = contents_.tree(); if (rep == nullptr) { @@ -1406,7 +1407,7 @@ if (GetFlatAux(rep, &fragment)) { return fragment; } - return absl::nullopt; + return std::nullopt; } inline absl::string_view Cord::Flatten() ABSL_ATTRIBUTE_LIFETIME_BOUND {
diff --git a/absl/strings/cord_test.cc b/absl/strings/cord_test.cc index f6ade9e..0be2aa4 100644 --- a/absl/strings/cord_test.cc +++ b/absl/strings/cord_test.cc
@@ -24,6 +24,7 @@ #include <iostream> #include <iterator> #include <limits> +#include <optional> #include <random> #include <set> #include <sstream> @@ -61,7 +62,6 @@ #include "absl/strings/str_format.h" #include "absl/strings/string_view.h" #include "absl/types/compare.h" -#include "absl/types/optional.h" // convenience local constants static constexpr auto FLAT = absl::cord_internal::FLAT; @@ -416,7 +416,7 @@ absl::Cord x(absl::string_view("hi there")); absl::Cord y(x); MaybeHarden(y); - ASSERT_EQ(x.ExpectedChecksum(), absl::nullopt); + ASSERT_EQ(x.ExpectedChecksum(), std::nullopt); ASSERT_EQ(std::string(x), "hi there"); ASSERT_EQ(std::string(y), "hi there"); ASSERT_TRUE(x == y); @@ -618,7 +618,7 @@ std::string(sa)) << a; if (pos != 0 || end_pos != a.size()) { - ASSERT_EQ(sa.ExpectedChecksum(), absl::nullopt); + ASSERT_EQ(sa.ExpectedChecksum(), std::nullopt); } } } @@ -662,7 +662,7 @@ MaybeHarden(x); swap(x, y); if (UseCrc()) { - ASSERT_EQ(x.ExpectedChecksum(), absl::nullopt); + ASSERT_EQ(x.ExpectedChecksum(), std::nullopt); ASSERT_EQ(y.ExpectedChecksum(), 1); } ASSERT_EQ(x, absl::Cord(b)); @@ -670,7 +670,7 @@ x.swap(y); if (UseCrc()) { ASSERT_EQ(x.ExpectedChecksum(), 1); - ASSERT_EQ(y.ExpectedChecksum(), absl::nullopt); + ASSERT_EQ(y.ExpectedChecksum(), std::nullopt); } ASSERT_EQ(x, absl::Cord(a)); ASSERT_EQ(y, absl::Cord(b)); @@ -1072,7 +1072,7 @@ TEST_P(CordTest, TryFlatConcat) { absl::Cord c = absl::MakeFragmentedCord({"hel", "lo"}); MaybeHarden(c); - EXPECT_EQ(c.TryFlat(), absl::nullopt); + EXPECT_EQ(c.TryFlat(), std::nullopt); } TEST_P(CordTest, TryFlatExternal) { @@ -3166,13 +3166,13 @@ continue; } - EXPECT_EQ(c2.ExpectedChecksum(), absl::nullopt); + EXPECT_EQ(c2.ExpectedChecksum(), std::nullopt); if (mutator.CanUndo()) { // Undoing an operation should not restore the checksum mutator.Undo(c2); EXPECT_EQ(c2, base_value); - EXPECT_EQ(c2.ExpectedChecksum(), absl::nullopt); + EXPECT_EQ(c2.ExpectedChecksum(), std::nullopt); } } @@ -3282,7 +3282,7 @@ // Not a mutation continue; } - EXPECT_EQ(c2.ExpectedChecksum(), absl::nullopt); + EXPECT_EQ(c2.ExpectedChecksum(), std::nullopt); if (mutator.CanUndo()) { mutator.Undo(c2);
diff --git a/absl/strings/has_absl_stringify_test.cc b/absl/strings/has_absl_stringify_test.cc index 59e7e1d..1aee904 100644 --- a/absl/strings/has_absl_stringify_test.cc +++ b/absl/strings/has_absl_stringify_test.cc
@@ -14,10 +14,10 @@ #include "absl/strings/has_absl_stringify.h" +#include <optional> #include <string> #include "gtest/gtest.h" -#include "absl/types/optional.h" namespace { @@ -34,7 +34,7 @@ EXPECT_FALSE(absl::HasAbslStringify<TypeWithoutAbslStringify>::value); EXPECT_TRUE(absl::HasAbslStringify<TypeWithAbslStringify>::value); EXPECT_FALSE( - absl::HasAbslStringify<absl::optional<TypeWithAbslStringify>>::value); + absl::HasAbslStringify<std::optional<TypeWithAbslStringify>>::value); } } // namespace
diff --git a/absl/strings/has_ostream_operator_test.cc b/absl/strings/has_ostream_operator_test.cc index 9ef4136..720ebd5 100644 --- a/absl/strings/has_ostream_operator_test.cc +++ b/absl/strings/has_ostream_operator_test.cc
@@ -14,11 +14,11 @@ #include "absl/strings/has_ostream_operator.h" +#include <optional> #include <ostream> #include <string> #include "gtest/gtest.h" -#include "absl/types/optional.h" namespace { @@ -33,7 +33,7 @@ TEST(HasOstreamOperatorTest, Works) { EXPECT_TRUE(absl::HasOstreamOperator<int>::value); EXPECT_TRUE(absl::HasOstreamOperator<std::string>::value); - EXPECT_FALSE(absl::HasOstreamOperator<absl::optional<int>>::value); + EXPECT_FALSE(absl::HasOstreamOperator<std::optional<int>>::value); EXPECT_FALSE(absl::HasOstreamOperator<TypeWithoutOstreamOp>::value); EXPECT_TRUE(absl::HasOstreamOperator<TypeWithOstreamOp>::value); }
diff --git a/absl/strings/internal/str_format/convert_test.cc b/absl/strings/internal/str_format/convert_test.cc index f340df4..fb9b5ba 100644 --- a/absl/strings/internal/str_format/convert_test.cc +++ b/absl/strings/internal/str_format/convert_test.cc
@@ -24,6 +24,7 @@ #include <cstring> #include <cwctype> #include <limits> +#include <optional> #include <set> #include <sstream> #include <string> @@ -44,7 +45,6 @@ #include "absl/strings/match.h" #include "absl/strings/str_format.h" #include "absl/strings/string_view.h" -#include "absl/types/optional.h" #include "absl/types/span.h" namespace absl { @@ -593,11 +593,11 @@ } template <typename T> -absl::optional<std::string> StrPrintChar(T c) { +std::optional<std::string> StrPrintChar(T c) { return StrPrint("%c", static_cast<int>(c)); } template <> -absl::optional<std::string> StrPrintChar(wchar_t c) { +std::optional<std::string> StrPrintChar(wchar_t c) { // musl libc has a bug where ("%lc", 0) writes no characters, and Android // doesn't support forcing UTF-8 via setlocale(). Hardcode the expected // answers for ASCII inputs to maximize test coverage on these platforms. @@ -611,7 +611,7 @@ // call. std::string old_locale = setlocale(LC_CTYPE, nullptr); if (!setlocale(LC_CTYPE, "en_US.UTF-8")) { - return absl::nullopt; + return std::nullopt; } const std::string output = StrPrint("%lc", static_cast<wint_t>(c)); setlocale(LC_CTYPE, old_locale.c_str()); @@ -666,7 +666,7 @@ SCOPED_TRACE(Esc(c)); const FormatArgImpl args[] = {FormatArgImpl(c)}; UntypedFormatSpecImpl format("%c"); - absl::optional<std::string> result = StrPrintChar(c); + std::optional<std::string> result = StrPrintChar(c); if (result.has_value()) { EXPECT_EQ(result.value(), FormatPack(format, absl::MakeSpan(args))); }
diff --git a/absl/strings/internal/str_format/float_conversion.cc b/absl/strings/internal/str_format/float_conversion.cc index bcef275..89275d4 100644 --- a/absl/strings/internal/str_format/float_conversion.cc +++ b/absl/strings/internal/str_format/float_conversion.cc
@@ -37,7 +37,6 @@ #include "absl/strings/internal/str_format/extension.h" #include "absl/strings/numbers.h" #include "absl/strings/string_view.h" -#include "absl/types/optional.h" #include "absl/types/span.h" namespace absl {