perfetto: switch base::Optional to std::optional
Now that base::Optional is simply a shim for std::optional and it's
stuck without being reverted, migrate everything over to use
std::optional directly.
Change-Id: Ic2595fc1cfae8f3b62350f8bf206675c709894a1
diff --git a/src/base/base64.cc b/src/base/base64.cc
index bb2e3c4..6b2236b 100644
--- a/src/base/base64.cc
+++ b/src/base/base64.cc
@@ -136,17 +136,17 @@
return static_cast<ssize_t>(wr_size);
}
-Optional<std::string> Base64Decode(const char* src, size_t src_size) {
+std::optional<std::string> Base64Decode(const char* src, size_t src_size) {
std::string dst;
dst.resize(Base64DecSize(src_size));
auto res = Base64Decode(src, src_size, reinterpret_cast<uint8_t*>(&dst[0]),
dst.size());
if (res < 0)
- return nullopt; // Decoding error.
+ return std::nullopt; // Decoding error.
PERFETTO_CHECK(res <= static_cast<ssize_t>(dst.size()));
dst.resize(static_cast<size_t>(res));
- return base::make_optional(dst);
+ return std::make_optional(dst);
}
} // namespace base
diff --git a/src/base/base64_unittest.cc b/src/base/base64_unittest.cc
index fb131d9..f01b13c 100644
--- a/src/base/base64_unittest.cc
+++ b/src/base/base64_unittest.cc
@@ -341,14 +341,14 @@
for (size_t i = 0; i < ArraySize(kPatterns); ++i) {
const auto& p = kPatterns[i];
- Optional<std::string> dec = Base64Decode(StringView(p.encoded));
+ std::optional<std::string> dec = Base64Decode(StringView(p.encoded));
EXPECT_TRUE(dec.has_value());
EXPECT_EQ(dec.value(), StringView(p.decoded, p.decoded_len).ToStdString());
}
// Error cases:
- EXPECT_EQ(Base64Decode("Z"), nullopt);
- EXPECT_EQ(Base64Decode("Zm9vY"), nullopt);
+ EXPECT_EQ(Base64Decode("Z"), std::nullopt);
+ EXPECT_EQ(Base64Decode("Zm9vY"), std::nullopt);
uint8_t buf[4];
EXPECT_EQ(Base64Decode("", 0, buf, 2), 0); // Valid, 0 len.
diff --git a/src/base/file_utils.cc b/src/base/file_utils.cc
index 9f70ad7..e7d4c94 100644
--- a/src/base/file_utils.cc
+++ b/src/base/file_utils.cc
@@ -21,6 +21,7 @@
#include <algorithm>
#include <deque>
+#include <optional>
#include <string>
#include <vector>
@@ -28,7 +29,6 @@
#include "perfetto/base/logging.h"
#include "perfetto/base/platform_handle.h"
#include "perfetto/base/status.h"
-#include "perfetto/ext/base/optional.h"
#include "perfetto/ext/base/platform.h"
#include "perfetto/ext/base/scoped_file.h"
#include "perfetto/ext/base/utils.h"
@@ -54,11 +54,11 @@
return FindClose(h) ? 0 : -1;
}
-Optional<std::wstring> ToUtf16(const std::string str) {
+std::optional<std::wstring> ToUtf16(const std::string str) {
int len = MultiByteToWideChar(CP_UTF8, 0, str.data(),
static_cast<int>(str.size()), nullptr, 0);
if (len < 0) {
- return base::nullopt;
+ return std::nullopt;
}
std::vector<wchar_t> tmp;
tmp.resize(static_cast<std::vector<wchar_t>::size_type>(len));
@@ -66,7 +66,7 @@
MultiByteToWideChar(CP_UTF8, 0, str.data(), static_cast<int>(str.size()),
tmp.data(), static_cast<int>(tmp.size()));
if (len < 0) {
- return base::nullopt;
+ return std::nullopt;
}
PERFETTO_CHECK(static_cast<std::vector<wchar_t>::size_type>(len) ==
tmp.size());
diff --git a/src/base/http/http_server.cc b/src/base/http/http_server.cc
index 3db6ae2..2efe9f7 100644
--- a/src/base/http/http_server.cc
+++ b/src/base/http/http_server.cc
@@ -565,12 +565,12 @@
HttpServerConnection::~HttpServerConnection() = default;
-Optional<StringView> HttpRequest::GetHeader(StringView name) const {
+std::optional<StringView> HttpRequest::GetHeader(StringView name) const {
for (size_t i = 0; i < num_headers; i++) {
if (headers[i].name.CaseInsensitiveEq(name))
return headers[i].value;
}
- return nullopt;
+ return std::nullopt;
}
HttpRequestHandler::~HttpRequestHandler() = default;
diff --git a/src/base/string_utils.cc b/src/base/string_utils.cc
index 851b60c..ba6e52b 100644
--- a/src/base/string_utils.cc
+++ b/src/base/string_utils.cc
@@ -245,8 +245,8 @@
return res;
}
-base::Optional<LineWithOffset> FindLineWithOffset(base::StringView str,
- uint32_t offset) {
+std::optional<LineWithOffset> FindLineWithOffset(base::StringView str,
+ uint32_t offset) {
static constexpr char kNewLine = '\n';
uint32_t line_offset = 0;
uint32_t line_count = 1;
@@ -265,7 +265,7 @@
return LineWithOffset{line, offset - line_offset, line_count};
}
}
- return base::nullopt;
+ return std::nullopt;
}
} // namespace base
diff --git a/src/base/string_utils_unittest.cc b/src/base/string_utils_unittest.cc
index 2cc4b06..f65da9f 100644
--- a/src/base/string_utils_unittest.cc
+++ b/src/base/string_utils_unittest.cc
@@ -16,10 +16,9 @@
#include "perfetto/ext/base/string_utils.h"
+#include <optional>
#include "test/gtest_and_gmock.h"
-#include "perfetto/ext/base/optional.h"
-
namespace perfetto {
namespace base {
namespace {
@@ -50,23 +49,23 @@
}
TEST(StringUtilsTest, CStringToUInt32) {
- EXPECT_EQ(CStringToUInt32("0"), make_optional<uint32_t>(0U));
- EXPECT_EQ(CStringToUInt32("1"), make_optional<uint32_t>(1U));
- EXPECT_EQ(CStringToUInt32("42"), make_optional<uint32_t>(42U));
- EXPECT_EQ(CStringToUInt32(""), nullopt);
- EXPECT_EQ(CStringToUInt32("!?"), nullopt);
- EXPECT_EQ(CStringToUInt32("abc"), nullopt);
- EXPECT_EQ(CStringToUInt32("123 abc"), nullopt);
+ EXPECT_EQ(CStringToUInt32("0"), std::make_optional<uint32_t>(0U));
+ EXPECT_EQ(CStringToUInt32("1"), std::make_optional<uint32_t>(1U));
+ EXPECT_EQ(CStringToUInt32("42"), std::make_optional<uint32_t>(42U));
+ EXPECT_EQ(CStringToUInt32(""), std::nullopt);
+ EXPECT_EQ(CStringToUInt32("!?"), std::nullopt);
+ EXPECT_EQ(CStringToUInt32("abc"), std::nullopt);
+ EXPECT_EQ(CStringToUInt32("123 abc"), std::nullopt);
}
TEST(StringUtilsTest, CStringToInt32) {
- EXPECT_EQ(CStringToInt32("0"), make_optional<int32_t>(0));
- EXPECT_EQ(CStringToInt32("1"), make_optional<int32_t>(1));
- EXPECT_EQ(CStringToInt32("-42"), make_optional<int32_t>(-42));
- EXPECT_EQ(CStringToInt32(""), nullopt);
- EXPECT_EQ(CStringToInt32("!?"), nullopt);
- EXPECT_EQ(CStringToInt32("abc"), nullopt);
- EXPECT_EQ(CStringToInt32("123 abc"), nullopt);
+ EXPECT_EQ(CStringToInt32("0"), std::make_optional<int32_t>(0));
+ EXPECT_EQ(CStringToInt32("1"), std::make_optional<int32_t>(1));
+ EXPECT_EQ(CStringToInt32("-42"), std::make_optional<int32_t>(-42));
+ EXPECT_EQ(CStringToInt32(""), std::nullopt);
+ EXPECT_EQ(CStringToInt32("!?"), std::nullopt);
+ EXPECT_EQ(CStringToInt32("abc"), std::nullopt);
+ EXPECT_EQ(CStringToInt32("123 abc"), std::nullopt);
}
TEST(StringUtilsTest, CStringToDouble) {
@@ -74,66 +73,68 @@
EXPECT_DOUBLE_EQ(CStringToDouble("1").value(), 1l);
EXPECT_DOUBLE_EQ(CStringToDouble("-42").value(), -42l);
EXPECT_DOUBLE_EQ(CStringToDouble("-42.5").value(), -42.5l);
- EXPECT_EQ(CStringToDouble(""), nullopt);
- EXPECT_EQ(CStringToDouble("!?"), nullopt);
- EXPECT_EQ(CStringToDouble("abc"), nullopt);
- EXPECT_EQ(CStringToDouble("123 abc"), nullopt);
+ EXPECT_EQ(CStringToDouble(""), std::nullopt);
+ EXPECT_EQ(CStringToDouble("!?"), std::nullopt);
+ EXPECT_EQ(CStringToDouble("abc"), std::nullopt);
+ EXPECT_EQ(CStringToDouble("123 abc"), std::nullopt);
}
TEST(StringUtilsTest, StringToUInt32) {
- EXPECT_EQ(StringToUInt32("0"), make_optional<uint32_t>(0U));
- EXPECT_EQ(StringToUInt32("1"), make_optional<uint32_t>(1U));
- EXPECT_EQ(StringToUInt32("42"), make_optional<uint32_t>(42U));
- EXPECT_EQ(StringToUInt32("a", 16), make_optional<uint32_t>(10U));
+ EXPECT_EQ(StringToUInt32("0"), std::make_optional<uint32_t>(0U));
+ EXPECT_EQ(StringToUInt32("1"), std::make_optional<uint32_t>(1U));
+ EXPECT_EQ(StringToUInt32("42"), std::make_optional<uint32_t>(42U));
+ EXPECT_EQ(StringToUInt32("a", 16), std::make_optional<uint32_t>(10U));
EXPECT_EQ(StringToUInt32("fffffff0", 16),
- make_optional<uint32_t>(0xfffffff0));
- EXPECT_EQ(StringToUInt32(""), nullopt);
- EXPECT_EQ(StringToUInt32("!?"), nullopt);
- EXPECT_EQ(StringToUInt32("abc"), nullopt);
- EXPECT_EQ(StringToUInt32("123 abc"), nullopt);
- EXPECT_EQ(StringToUInt32("beefz", 16), nullopt);
+ std::make_optional<uint32_t>(0xfffffff0));
+ EXPECT_EQ(StringToUInt32(""), std::nullopt);
+ EXPECT_EQ(StringToUInt32("!?"), std::nullopt);
+ EXPECT_EQ(StringToUInt32("abc"), std::nullopt);
+ EXPECT_EQ(StringToUInt32("123 abc"), std::nullopt);
+ EXPECT_EQ(StringToUInt32("beefz", 16), std::nullopt);
}
TEST(StringUtilsTest, StringToInt32) {
- EXPECT_EQ(StringToInt32("0"), make_optional<int32_t>(0));
- EXPECT_EQ(StringToInt32("1"), make_optional<int32_t>(1));
- EXPECT_EQ(StringToInt32("-42"), make_optional<int32_t>(-42));
- EXPECT_EQ(StringToInt32("42", 16), make_optional<int32_t>(0x42));
- EXPECT_EQ(StringToInt32("7ffffffe", 16), make_optional<int32_t>(0x7ffffffe));
- EXPECT_EQ(StringToInt32(""), nullopt);
- EXPECT_EQ(StringToInt32("!?"), nullopt);
- EXPECT_EQ(StringToInt32("abc"), nullopt);
- EXPECT_EQ(StringToInt32("123 abc"), nullopt);
- EXPECT_EQ(StringToInt32("beefz", 16), nullopt);
+ EXPECT_EQ(StringToInt32("0"), std::make_optional<int32_t>(0));
+ EXPECT_EQ(StringToInt32("1"), std::make_optional<int32_t>(1));
+ EXPECT_EQ(StringToInt32("-42"), std::make_optional<int32_t>(-42));
+ EXPECT_EQ(StringToInt32("42", 16), std::make_optional<int32_t>(0x42));
+ EXPECT_EQ(StringToInt32("7ffffffe", 16),
+ std::make_optional<int32_t>(0x7ffffffe));
+ EXPECT_EQ(StringToInt32(""), std::nullopt);
+ EXPECT_EQ(StringToInt32("!?"), std::nullopt);
+ EXPECT_EQ(StringToInt32("abc"), std::nullopt);
+ EXPECT_EQ(StringToInt32("123 abc"), std::nullopt);
+ EXPECT_EQ(StringToInt32("beefz", 16), std::nullopt);
}
TEST(StringUtilsTest, StringToUInt64) {
- EXPECT_EQ(StringToUInt64("0"), make_optional<uint64_t>(0u));
- EXPECT_EQ(StringToUInt64("1"), make_optional<uint64_t>(1u));
+ EXPECT_EQ(StringToUInt64("0"), std::make_optional<uint64_t>(0u));
+ EXPECT_EQ(StringToUInt64("1"), std::make_optional<uint64_t>(1u));
EXPECT_EQ(StringToUInt64("5000000000"),
- make_optional<uint64_t>(5000000000ULL));
+ std::make_optional<uint64_t>(5000000000ULL));
EXPECT_EQ(StringToUInt64("7ffffffffffffffe", 16),
- make_optional<uint64_t>(0x7ffffffffffffffeULL));
+ std::make_optional<uint64_t>(0x7ffffffffffffffeULL));
EXPECT_EQ(StringToUInt64("9ffffffffffffffe", 16),
- make_optional<uint64_t>(0x9ffffffffffffffeULL));
- EXPECT_EQ(StringToUInt64(""), nullopt);
- EXPECT_EQ(StringToUInt64("abc"), nullopt);
- EXPECT_EQ(StringToUInt64("beefz", 16), nullopt);
+ std::make_optional<uint64_t>(0x9ffffffffffffffeULL));
+ EXPECT_EQ(StringToUInt64(""), std::nullopt);
+ EXPECT_EQ(StringToUInt64("abc"), std::nullopt);
+ EXPECT_EQ(StringToUInt64("beefz", 16), std::nullopt);
}
TEST(StringUtilsTest, StringToInt64) {
- EXPECT_EQ(StringToInt64("0"), make_optional<int64_t>(0));
- EXPECT_EQ(StringToInt64("1"), make_optional<int64_t>(1));
+ EXPECT_EQ(StringToInt64("0"), std::make_optional<int64_t>(0));
+ EXPECT_EQ(StringToInt64("1"), std::make_optional<int64_t>(1));
EXPECT_EQ(StringToInt64("-5000000000"),
- make_optional<int64_t>(-5000000000LL));
- EXPECT_EQ(StringToInt64("5000000000"), make_optional<int64_t>(5000000000LL));
+ std::make_optional<int64_t>(-5000000000LL));
+ EXPECT_EQ(StringToInt64("5000000000"),
+ std::make_optional<int64_t>(5000000000LL));
EXPECT_EQ(StringToInt64("7ffffffffffffffe", 16),
- make_optional<int64_t>(0x7ffffffffffffffeLL));
+ std::make_optional<int64_t>(0x7ffffffffffffffeLL));
EXPECT_EQ(StringToInt64("9ffffffe", 16),
- make_optional<int64_t>(0x9ffffffeLL));
- EXPECT_EQ(StringToInt64(""), nullopt);
- EXPECT_EQ(StringToInt64("abc"), nullopt);
- EXPECT_EQ(StringToInt64("beefz", 16), nullopt);
+ std::make_optional<int64_t>(0x9ffffffeLL));
+ EXPECT_EQ(StringToInt64(""), std::nullopt);
+ EXPECT_EQ(StringToInt64("abc"), std::nullopt);
+ EXPECT_EQ(StringToInt64("beefz", 16), std::nullopt);
}
TEST(StringUtilsTest, StringToDouble) {
@@ -143,13 +144,13 @@
EXPECT_DOUBLE_EQ(StringToDouble("-42.5").value(), -42.5l);
EXPECT_DOUBLE_EQ(StringToDouble("0.5").value(), .5l);
EXPECT_DOUBLE_EQ(StringToDouble(".5").value(), .5l);
- EXPECT_EQ(StringToDouble(""), nullopt);
- EXPECT_EQ(StringToDouble("!?"), nullopt);
- EXPECT_EQ(StringToDouble("abc"), nullopt);
- EXPECT_EQ(StringToDouble("123 abc"), nullopt);
- EXPECT_EQ(StringToDouble("124,456"), nullopt);
- EXPECT_EQ(StringToDouble("4 2"), nullopt);
- EXPECT_EQ(StringToDouble(" - 42"), nullopt);
+ EXPECT_EQ(StringToDouble(""), std::nullopt);
+ EXPECT_EQ(StringToDouble("!?"), std::nullopt);
+ EXPECT_EQ(StringToDouble("abc"), std::nullopt);
+ EXPECT_EQ(StringToDouble("123 abc"), std::nullopt);
+ EXPECT_EQ(StringToDouble("124,456"), std::nullopt);
+ EXPECT_EQ(StringToDouble("4 2"), std::nullopt);
+ EXPECT_EQ(StringToDouble(" - 42"), std::nullopt);
}
TEST(StringUtilsTest, StartsWith) {
diff --git a/src/base/threading/channel_unittest.cc b/src/base/threading/channel_unittest.cc
index 7acb355..2c5e45e 100644
--- a/src/base/threading/channel_unittest.cc
+++ b/src/base/threading/channel_unittest.cc
@@ -15,12 +15,13 @@
*/
#include "perfetto/ext/base/threading/channel.h"
+
#include <array>
#include <memory>
+#include <optional>
#include "perfetto/base/platform_handle.h"
#include "perfetto/ext/base/file_utils.h"
-#include "perfetto/ext/base/optional.h"
#include "perfetto/ext/base/utils.h"
#include "test/gtest_and_gmock.h"
@@ -71,7 +72,7 @@
ASSERT_TRUE(IsReady(channel.read_fd()));
ASSERT_EQ(channel.ReadNonBlocking(), ReadResult(100, false));
- ASSERT_EQ(channel.ReadNonBlocking(), ReadResult(base::nullopt, false));
+ ASSERT_EQ(channel.ReadNonBlocking(), ReadResult(std::nullopt, false));
ASSERT_TRUE(IsReady(channel.write_fd()));
ASSERT_FALSE(IsReady(channel.read_fd()));
@@ -98,7 +99,7 @@
ASSERT_TRUE(IsReady(channel.write_fd()));
ASSERT_FALSE(IsReady(channel.read_fd()));
- ASSERT_EQ(channel.ReadNonBlocking(), ReadResult(base::nullopt, false));
+ ASSERT_EQ(channel.ReadNonBlocking(), ReadResult(std::nullopt, false));
ASSERT_TRUE(IsReady(channel.write_fd()));
ASSERT_FALSE(IsReady(channel.read_fd()));
}
@@ -106,13 +107,13 @@
TEST(ChannelUnittest, CloseEmptyChannel) {
Channel<int> channel(1);
- ASSERT_EQ(channel.ReadNonBlocking(), ReadResult(base::nullopt, false));
+ ASSERT_EQ(channel.ReadNonBlocking(), ReadResult(std::nullopt, false));
ASSERT_FALSE(IsReady(channel.read_fd()));
channel.Close();
- ASSERT_EQ(channel.ReadNonBlocking(), ReadResult(base::nullopt, true));
- ASSERT_EQ(channel.ReadNonBlocking(), ReadResult(base::nullopt, true));
+ ASSERT_EQ(channel.ReadNonBlocking(), ReadResult(std::nullopt, true));
+ ASSERT_EQ(channel.ReadNonBlocking(), ReadResult(std::nullopt, true));
ASSERT_TRUE(IsReady(channel.read_fd()));
ASSERT_TRUE(IsReady(channel.read_fd()));
@@ -139,12 +140,12 @@
TEST(ChannelUnittest, ReadAfterClose) {
Channel<int> channel(1);
- ASSERT_EQ(channel.ReadNonBlocking(), ReadResult(base::nullopt, false));
+ ASSERT_EQ(channel.ReadNonBlocking(), ReadResult(std::nullopt, false));
ASSERT_EQ(channel.WriteNonBlocking(100), WriteResult(true, false));
channel.Close();
ASSERT_EQ(channel.ReadNonBlocking(), ReadResult(100, true));
- ASSERT_EQ(channel.ReadNonBlocking(), ReadResult(base::nullopt, true));
+ ASSERT_EQ(channel.ReadNonBlocking(), ReadResult(std::nullopt, true));
}
TEST(ChannelUnittest, WriteAfterClose) {
@@ -164,7 +165,7 @@
channel.Close();
ASSERT_TRUE(IsReady(channel.write_fd()));
ASSERT_TRUE(IsReady(channel.write_fd()));
- ASSERT_EQ(channel.ReadNonBlocking(), ReadResult(base::nullopt, true));
+ ASSERT_EQ(channel.ReadNonBlocking(), ReadResult(std::nullopt, true));
ASSERT_TRUE(IsReady(channel.write_fd()));
ASSERT_TRUE(IsReady(channel.read_fd()));
}
diff --git a/src/base/threading/spawn.cc b/src/base/threading/spawn.cc
index 4fd246a..e727f84 100644
--- a/src/base/threading/spawn.cc
+++ b/src/base/threading/spawn.cc
@@ -16,8 +16,9 @@
#include "perfetto/ext/base/threading/spawn.h"
+#include <optional>
+
#include "perfetto/base/task_runner.h"
-#include "perfetto/ext/base/optional.h"
#include "perfetto/ext/base/thread_checker.h"
#include "perfetto/ext/base/threading/future.h"
#include "perfetto/ext/base/threading/poll.h"
@@ -74,7 +75,7 @@
}
void ClearFutureAndWatches(FlatSet<PlatformHandle> interested) {
- future_ = nullopt;
+ future_ = std::nullopt;
for (PlatformHandle fd : interested) {
task_runner_->RemoveFileDescriptorWatch(fd);
}
@@ -94,7 +95,7 @@
TaskRunner* const task_runner_ = nullptr;
- Optional<Future<FVoid>> future_;
+ std::optional<Future<FVoid>> future_;
FlatSet<PlatformHandle> interested_;
FlatSet<PlatformHandle> ready_;
PollContext context_{&interested_, &ready_};
diff --git a/src/base/threading/spawn_unittest.cc b/src/base/threading/spawn_unittest.cc
index 1324b18..a62ae83 100644
--- a/src/base/threading/spawn_unittest.cc
+++ b/src/base/threading/spawn_unittest.cc
@@ -16,8 +16,9 @@
#include "perfetto/ext/base/threading/spawn.h"
+#include <optional>
+
#include "perfetto/ext/base/event_fd.h"
-#include "perfetto/ext/base/optional.h"
#include "perfetto/ext/base/thread_task_runner.h"
#include "perfetto/ext/base/threading/future.h"
#include "perfetto/ext/base/threading/poll.h"
@@ -65,10 +66,10 @@
});
task_runner.RunUntilIdle();
- ASSERT_EQ(res.channel()->ReadNonBlocking().item, base::nullopt);
+ ASSERT_EQ(res.channel()->ReadNonBlocking().item, std::nullopt);
task_runner.RunUntilIdle();
- ASSERT_EQ(res.channel()->ReadNonBlocking().item, base::nullopt);
+ ASSERT_EQ(res.channel()->ReadNonBlocking().item, std::nullopt);
fd.Notify();
task_runner.RunUntilIdle();
@@ -108,7 +109,7 @@
});
task_runner.RunUntilIdle();
- ASSERT_EQ(res.channel()->ReadNonBlocking().item, base::nullopt);
+ ASSERT_EQ(res.channel()->ReadNonBlocking().item, std::nullopt);
fd.Notify();
task_runner.RunUntilIdle();
@@ -118,7 +119,7 @@
ASSERT_FALSE(read.is_closed);
task_runner.RunUntilIdle();
- ASSERT_EQ(res.channel()->ReadNonBlocking().item, base::nullopt);
+ ASSERT_EQ(res.channel()->ReadNonBlocking().item, std::nullopt);
fd.Notify();
task_runner.RunUntilIdle();
diff --git a/src/base/threading/util_unittest.cc b/src/base/threading/util_unittest.cc
index 887802c..504435b 100644
--- a/src/base/threading/util_unittest.cc
+++ b/src/base/threading/util_unittest.cc
@@ -16,11 +16,12 @@
#include "perfetto/ext/base/threading/util.h"
+#include <optional>
+
#include "perfetto/base/flat_set.h"
#include "perfetto/base/platform_handle.h"
#include "perfetto/base/time.h"
#include "perfetto/ext/base/event_fd.h"
-#include "perfetto/ext/base/optional.h"
#include "perfetto/ext/base/threading/channel.h"
#include "perfetto/ext/base/threading/poll.h"
#include "perfetto/ext/base/threading/stream.h"
@@ -45,7 +46,7 @@
return res.item();
}
-base::Optional<int> WaitForStreamReady(
+std::optional<int> WaitForStreamReady(
base::Stream<int>& stream,
base::FlatSet<base::PlatformHandle>& interested,
PollContext& ctx) {
@@ -55,7 +56,7 @@
base::BlockUntilReadableFd(*interested.begin());
interested = {};
}
- return res.IsDone() ? base::nullopt : base::make_optional(res.item());
+ return res.IsDone() ? std::nullopt : std::make_optional(res.item());
}
TEST(UtilUnittest, BlockUntilReadableFd) {
@@ -113,7 +114,7 @@
interested = {};
ASSERT_EQ(channel.ReadNonBlocking().item, 1);
- ASSERT_EQ(channel.ReadNonBlocking().item, base::nullopt);
+ ASSERT_EQ(channel.ReadNonBlocking().item, std::nullopt);
ASSERT_FALSE(future.Poll(&ctx).IsPending());
ASSERT_EQ(channel.ReadNonBlocking().item, 3);
@@ -127,11 +128,11 @@
base::ThreadPool pool(1);
base::Stream<int> stream =
base::RunOnThreadPool<int>(&pool, [counter = 0]() mutable {
- return counter == 2 ? base::nullopt : base::make_optional(counter++);
+ return counter == 2 ? std::nullopt : std::make_optional(counter++);
});
ASSERT_EQ(WaitForStreamReady(stream, interested, ctx), 0);
ASSERT_EQ(WaitForStreamReady(stream, interested, ctx), 1);
- ASSERT_EQ(WaitForStreamReady(stream, interested, ctx), base::nullopt);
+ ASSERT_EQ(WaitForStreamReady(stream, interested, ctx), std::nullopt);
}
TEST(UtilUnittest, RunOnceOnThreadPool) {
diff --git a/src/base/uuid_unittest.cc b/src/base/uuid_unittest.cc
index 9f5e52f..6cd22c9 100644
--- a/src/base/uuid_unittest.cc
+++ b/src/base/uuid_unittest.cc
@@ -16,9 +16,9 @@
#include "perfetto/ext/base/uuid.h"
-#include "test/gtest_and_gmock.h"
+#include <optional>
-#include "perfetto/ext/base/optional.h"
+#include "test/gtest_and_gmock.h"
namespace perfetto {
namespace base {