mirror of
https://codeberg.org/DawnMagnet/reflect-cpp
synced 2026-12-04 01:06:19 +08:00
Parser_default: Move temporary variable instead of copying (#362)
This commit is contained in:
@@ -69,7 +69,7 @@ struct Parser {
|
|||||||
using ReflectionType = std::remove_cvref_t<typename T::ReflectionType>;
|
using ReflectionType = std::remove_cvref_t<typename T::ReflectionType>;
|
||||||
const auto wrap_in_t = [](auto _named_tuple) -> Result<T> {
|
const auto wrap_in_t = [](auto _named_tuple) -> Result<T> {
|
||||||
try {
|
try {
|
||||||
return T{_named_tuple};
|
return T{std::move(_named_tuple)};
|
||||||
} catch (std::exception& e) {
|
} catch (std::exception& e) {
|
||||||
return error(e.what());
|
return error(e.what());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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)");
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user