Parser_default: Move temporary variable instead of copying (#362)

This commit is contained in:
Heiko Lewin
2025-02-25 21:01:39 +01:00
committed by GitHub
parent c3764e83ce
commit e825b236ee
2 changed files with 29 additions and 1 deletions
+1 -1
View File
@@ -69,7 +69,7 @@ struct Parser {
using ReflectionType = std::remove_cvref_t<typename T::ReflectionType>;
const auto wrap_in_t = [](auto _named_tuple) -> Result<T> {
try {
return T{_named_tuple};
return T{std::move(_named_tuple)};
} catch (std::exception& e) {
return error(e.what());
}
+28
View File
@@ -0,0 +1,28 @@
#include <cassert>
#include <iostream>
#include <rfl.hpp>
#include <rfl/json.hpp>
#include <string>
#include <vector>
#include "write_and_read.hpp"
struct MoveableType {
int x;
MoveableType(MoveableType&&) = default;
MoveableType(const MoveableType&) = delete;
using ReflectionType = int;
MoveableType(int&& x) : x(x) {}
int reflection() const { return x; }
};
TEST(json, test_moveable) {
MoveableType moveable = {2};
write_and_read(
moveable, R"(2)");
}