mirror of
https://codeberg.org/DawnMagnet/reflect-cpp
synced 2026-12-06 10:46:18 +08:00
Fix bugging disallowing optionals to hold items without copy constructors (#390)
This commit is contained in:
@@ -38,7 +38,7 @@ struct Parser<R, W, std::optional<T>, ProcessorsType> {
|
||||
if (_r.is_empty(_var)) {
|
||||
return std::optional<T>();
|
||||
}
|
||||
const auto to_opt = [](auto&& _t) { return std::make_optional<T>(_t); };
|
||||
const auto to_opt = [](auto&& _t) { return std::make_optional<T>(std::forward<decltype(_t)>(_t)); };
|
||||
return Parser<R, W, std::remove_cvref_t<T>, ProcessorsType>::read(_r,
|
||||
_var)
|
||||
.transform(to_opt);
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
#include <rfl.hpp>
|
||||
#include <string>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
namespace test_optional {
|
||||
|
||||
struct Person {
|
||||
std::string name;
|
||||
std::optional<rfl::Box<Person>> spouse;
|
||||
};
|
||||
|
||||
TEST(generic, test_optional) {
|
||||
rfl::Generic generic;
|
||||
// This failed to compile due to optional copying rather than moving
|
||||
rfl::from_generic<Person>(generic);
|
||||
}
|
||||
} // namespace test_map
|
||||
Reference in New Issue
Block a user