Skip to content

Commit 6ee01e1

Browse files
committed
fix: RVO in legacy result
1 parent 6d439c0 commit 6ee01e1

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

include/ext/util/result.hpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ struct result {
6464
return *this;
6565
}
6666

67-
auto get_message() const -> std::string {
67+
auto get_message() const & -> std::string {
6868
if (message.empty()) {
6969
if (code != EXT_OK) {
7070
message = error_code_vo_string(code);
@@ -73,6 +73,15 @@ struct result {
7373
return message;
7474
}
7575

76+
auto get_message() && -> std::string {
77+
if (message.empty()) {
78+
if (code != EXT_OK) {
79+
return error_code_vo_string(code);
80+
}
81+
}
82+
return std::move(message);
83+
}
84+
7685
auto get_code() const -> int {
7786
return code;
7887
}
@@ -222,13 +231,13 @@ struct typed_result {
222231
return _result.get_message();
223232
}
224233
std::string message() && {
225-
return std::move(std::move(_result).get_message());
234+
return std::move(_result).get_message();
226235
}
227236
std::string get_message() const& {
228237
return _result.get_message();
229238
}
230239
std::string get_message() && {
231-
return std::move(std::move(_result).get_message());
240+
return std::move(_result).get_message();
232241
}
233242

234243
bool ok() const {

0 commit comments

Comments
 (0)