Skip to content

Commit b492f0e

Browse files
authored
impl(common): modifiers for ErrorInfoBuilder lvalues (#10286)
1 parent e368c12 commit b492f0e

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

google/cloud/internal/make_status.h

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,21 +79,31 @@ class ErrorInfoBuilder {
7979
ErrorInfoBuilder(std::string file, int line, std::string function);
8080

8181
/// Adds the metadata from an error context, existing values are not replaced.
82-
ErrorInfoBuilder&& WithContext(ErrorContext const& ec) && {
82+
ErrorInfoBuilder& WithContext(ErrorContext const& ec) & {
8383
metadata_.insert(ec.begin(), ec.end());
84-
return std::move(*this);
84+
return *this;
85+
}
86+
ErrorInfoBuilder&& WithContext(ErrorContext const& ec) && {
87+
return std::move(WithContext(ec));
8588
}
8689

8790
/// Add a metadata pair, existing values are not replaced.
91+
ErrorInfoBuilder& WithMetadata(absl::string_view key,
92+
absl::string_view value) & {
93+
metadata_.emplace(key, value);
94+
return *this;
95+
}
8896
ErrorInfoBuilder&& WithMetadata(absl::string_view key,
8997
absl::string_view value) && {
90-
metadata_.emplace(key, value);
91-
return std::move(*this);
98+
return std::move(WithMetadata(std::move(key), std::move(value)));
9299
}
93100

94-
ErrorInfoBuilder&& WithReason(std::string reason) && {
101+
ErrorInfoBuilder& WithReason(std::string reason) & {
95102
reason_ = std::move(reason);
96-
return std::move(*this);
103+
return *this;
104+
}
105+
ErrorInfoBuilder&& WithReason(std::string reason) && {
106+
return std::move(WithReason(std::move(reason)));
97107
}
98108

99109
ErrorInfo Build(StatusCode code) &&;

0 commit comments

Comments
 (0)