Skip to content

Commit a9d896c

Browse files
authored
chore: migrate common libraries to std::optional (googleapis#16254)
1 parent ccd5fbc commit a9d896c

98 files changed

Lines changed: 362 additions & 363 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

google/cloud/BUILD.bazel

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ cc_library(
7777
"@abseil-cpp//absl/strings",
7878
"@abseil-cpp//absl/strings:str_format",
7979
"@abseil-cpp//absl/time",
80-
"@abseil-cpp//absl/types:optional",
8180
"@abseil-cpp//absl/types:span",
8281
"@abseil-cpp//absl/types:variant",
8382
"@opentelemetry-cpp//api",

google/cloud/async_streaming_read_write_rpc.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
#include "google/cloud/rpc_metadata.h"
2020
#include "google/cloud/status.h"
2121
#include "google/cloud/version.h"
22-
#include "absl/types/optional.h"
2322
#include <grpcpp/support/async_stream.h>
23+
#include <optional>
2424

2525
namespace google {
2626
namespace cloud {
@@ -77,7 +77,7 @@ class AsyncStreamingReadWriteRpc {
7777
* other `Write()` calls) complete and then call `Finish()` to find the status
7878
* of the streaming RPC.
7979
*/
80-
virtual future<absl::optional<Response>> Read() = 0;
80+
virtual future<std::optional<Response>> Read() = 0;
8181

8282
/**
8383
* Write one request to the streaming RPC.

google/cloud/credentials.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,13 @@ std::shared_ptr<Credentials> MakeImpersonateServiceAccountCredentials(
4848
std::shared_ptr<Credentials> MakeServiceAccountCredentials(
4949
std::string json_object, Options opts) {
5050
return std::make_shared<internal::ServiceAccountConfig>(
51-
std::move(json_object), absl::nullopt, std::move(opts));
51+
std::move(json_object), std::nullopt, std::move(opts));
5252
}
5353

5454
std::shared_ptr<Credentials> MakeServiceAccountCredentialsFromFile(
5555
std::string const& file_path, Options opts) {
5656
return std::make_shared<internal::ServiceAccountConfig>(
57-
absl::nullopt, file_path, std::move(opts));
57+
std::nullopt, file_path, std::move(opts));
5858
}
5959

6060
std::shared_ptr<Credentials> MakeExternalAccountCredentials(

google/cloud/grpc_error_delegate.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414

1515
#include "google/cloud/grpc_error_delegate.h"
1616
#include "google/cloud/internal/status_payload_keys.h"
17-
#include "absl/types/optional.h"
1817
#include "google/protobuf/any.pb.h"
1918
#include "google/rpc/error_details.pb.h"
2019
#include <google/protobuf/text_format.h>
20+
#include <optional>
2121

2222
namespace google {
2323
namespace cloud {
@@ -67,7 +67,7 @@ google::cloud::StatusCode MapStatusCode(grpc::StatusCode const& code) {
6767
}
6868

6969
// Unpacks the ErrorInfo from the Status proto, if one exists.
70-
absl::optional<google::rpc::ErrorInfo> GetErrorInfoProto(
70+
std::optional<google::rpc::ErrorInfo> GetErrorInfoProto(
7171
google::rpc::Status const& proto) {
7272
// While in theory there _could_ be multiple ErrorInfo protos in this
7373
// repeated field, we're told that there will be at most one, and our
@@ -76,7 +76,7 @@ absl::optional<google::rpc::ErrorInfo> GetErrorInfoProto(
7676
for (google::protobuf::Any const& any : proto.details()) {
7777
if (any.UnpackTo(&error_info)) return error_info;
7878
}
79-
return absl::nullopt;
79+
return std::nullopt;
8080
}
8181

8282
ErrorInfo GetErrorInfo(google::rpc::Status const& status) {
@@ -88,7 +88,7 @@ ErrorInfo GetErrorInfo(google::rpc::Status const& status) {
8888
}
8989

9090
// Unpacks the RetryInfo from the Status proto, if one exists.
91-
absl::optional<internal::RetryInfo> GetRetryInfo(
91+
std::optional<internal::RetryInfo> GetRetryInfo(
9292
google::rpc::Status const& proto) {
9393
// While in theory there _could_ be multiple RetryInfo protos in this
9494
// repeated field, we're told that there will be at most one, and our
@@ -101,7 +101,7 @@ absl::optional<internal::RetryInfo> GetRetryInfo(
101101
return internal::RetryInfo(d);
102102
}
103103
}
104-
return absl::nullopt;
104+
return std::nullopt;
105105
}
106106

107107
} // namespace

google/cloud/grpc_error_delegate_test.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ TEST(MakeStatusFromRpcError, AllCodesWithPayload) {
133133
EXPECT_EQ(expected, actual);
134134
EXPECT_EQ(message, actual.message());
135135
EXPECT_EQ(ErrorInfo{}, actual.error_info());
136-
EXPECT_EQ(absl::nullopt, internal::GetRetryInfo(actual));
136+
EXPECT_EQ(std::nullopt, internal::GetRetryInfo(actual));
137137

138138
// Make sure the actual payload is what we expect.
139139
auto actual_payload = google::cloud::internal::GetPayload(

google/cloud/grpc_options.cc

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -118,30 +118,30 @@ grpc::ChannelArguments MakeChannelArguments(Options const& opts) {
118118
return channel_arguments;
119119
}
120120

121-
absl::optional<int> GetIntChannelArgument(grpc::ChannelArguments const& args,
122-
std::string const& key) {
121+
std::optional<int> GetIntChannelArgument(grpc::ChannelArguments const& args,
122+
std::string const& key) {
123123
auto c_args = args.c_channel_args();
124124
// Just do a linear search for the key; the data structure is not organized
125125
// in any other useful way.
126126
for (auto const* a = c_args.args; a != c_args.args + c_args.num_args; ++a) {
127127
if (key != a->key) continue;
128-
if (a->type != GRPC_ARG_INTEGER) return absl::nullopt;
128+
if (a->type != GRPC_ARG_INTEGER) return std::nullopt;
129129
return a->value.integer;
130130
}
131-
return absl::nullopt;
131+
return std::nullopt;
132132
}
133133

134-
absl::optional<std::string> GetStringChannelArgument(
134+
std::optional<std::string> GetStringChannelArgument(
135135
grpc::ChannelArguments const& args, std::string const& key) {
136136
auto c_args = args.c_channel_args();
137137
// Just do a linear search for the key; the data structure is not organized
138138
// in any other useful way.
139139
for (auto const* a = c_args.args; a != c_args.args + c_args.num_args; ++a) {
140140
if (key != a->key) continue;
141-
if (a->type != GRPC_ARG_STRING) return absl::nullopt;
141+
if (a->type != GRPC_ARG_STRING) return std::nullopt;
142142
return a->value.string;
143143
}
144-
return absl::nullopt;
144+
return std::nullopt;
145145
}
146146

147147
BackgroundThreadsFactory MakeBackgroundThreadsFactory(Options const& opts) {

google/cloud/grpc_options.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -258,11 +258,11 @@ std::string MakeGrpcHttpProxy(ProxyConfig const& config);
258258
grpc::ChannelArguments MakeChannelArguments(Options const& opts);
259259

260260
/// Helper function to extract the first instance of an integer channel argument
261-
absl::optional<int> GetIntChannelArgument(grpc::ChannelArguments const& args,
262-
std::string const& key);
261+
std::optional<int> GetIntChannelArgument(grpc::ChannelArguments const& args,
262+
std::string const& key);
263263

264264
/// Helper function to extract the first instance of a string channel argument
265-
absl::optional<std::string> GetStringChannelArgument(
265+
std::optional<std::string> GetStringChannelArgument(
266266
grpc::ChannelArguments const& args, std::string const& key);
267267

268268
/**

google/cloud/iam_updater.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_IAM_UPDATER_H
1717

1818
#include "google/cloud/version.h"
19-
#include "absl/types/optional.h"
2019
#include "google/iam/v1/policy.pb.h"
2120
#include <functional>
21+
#include <optional>
2222

2323
namespace google {
2424
namespace cloud {
@@ -38,7 +38,7 @@ GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
3838
* has been an intermediate update), this update is dropped and a new cycle is
3939
* initiated. In case (2) the existing policy is overwritten blindly.
4040
*/
41-
using IamUpdater = std::function<absl::optional<google::iam::v1::Policy>(
41+
using IamUpdater = std::function<std::optional<google::iam::v1::Policy>(
4242
google::iam::v1::Policy)>;
4343

4444
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END

google/cloud/internal/async_read_write_stream_auth.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class AsyncStreamingReadWriteRpcAuth
5555
});
5656
}
5757

58-
future<absl::optional<Response>> Read() override {
58+
future<std::optional<Response>> Read() override {
5959
std::lock_guard<std::mutex> g{state_->mu};
6060
return state_->stream->Read();
6161
}

google/cloud/internal/async_read_write_stream_auth_test.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ TEST(AsyncStreamReadWriteAuth, Start) {
5757
return make_ready_future(true);
5858
});
5959
EXPECT_CALL(*mock, Read).WillOnce([] {
60-
return make_ready_future(absl::make_optional(FakeResponse{"k0", "v0"}));
60+
return make_ready_future(std::make_optional(FakeResponse{"k0", "v0"}));
6161
});
6262
EXPECT_CALL(*mock, WritesDone).WillOnce([] {
6363
return make_ready_future(true);

0 commit comments

Comments
 (0)