Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/rfl/parsing/to_single_error_message.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ inline std::string to_single_error_message(
std::optional<std::string> _msg_prefix = std::nullopt,
size_t _err_limit = 10) {
if (_errors.size() == 1) {
return std::move(_errors[0].what());
return _errors[0].what();
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

You are correct that std::move was unnecessary on the result of what(), as _errors[0].what() resolves to the const & overload, returning a const std::string&. Moving from a const reference results in a copy.

However, since _errors is passed by value, we can move from its elements. By moving from the Error object itself, you can invoke the &&-qualified overload of what(), which moves the string instead of copying it. This is more efficient.

Suggested change
return _errors[0].what();
return std::move(_errors[0]).what();

} else {
std::stringstream stream;
stream << (_msg_prefix
Expand Down
Loading