Skip to content
Merged
Show file tree
Hide file tree
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/Parser_optional.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
17 changes: 17 additions & 0 deletions tests/generic/test_optional.cpp
Original file line number Diff line number Diff line change
@@ -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
Loading