diff --git a/include/visit_struct/visit_struct.hpp b/include/visit_struct/visit_struct.hpp index 9c8cbfa..e9af296 100644 --- a/include/visit_struct/visit_struct.hpp +++ b/include/visit_struct/visit_struct.hpp @@ -89,10 +89,10 @@ VISIT_STRUCT_CONSTEXPR auto apply_visitor(V && v, S && s) -> */ #define VISIT_STRUCT_MEMBER_HELPER(MEMBER_NAME) \ - visitor(#MEMBER_NAME, struct_instance.MEMBER_NAME); + std::forward(visitor)(#MEMBER_NAME, struct_instance.MEMBER_NAME); #define VISIT_STRUCT_MEMBER_HELPER_MOVE(MEMBER_NAME) \ - visitor(#MEMBER_NAME, std::move(struct_instance.MEMBER_NAME)); + std::forward(visitor)(#MEMBER_NAME, std::move(struct_instance.MEMBER_NAME)); // This macro specializes the trait, provides "apply" method which does the work. diff --git a/include/visit_struct/visit_struct_boost_fusion.hpp b/include/visit_struct/visit_struct_boost_fusion.hpp index fa50da9..89c6ed6 100644 --- a/include/visit_struct/visit_struct_boost_fusion.hpp +++ b/include/visit_struct/visit_struct_boost_fusion.hpp @@ -37,11 +37,11 @@ struct visitable(v)), struct_instance(t) {} template void operator()(Index) const { - visitor(boost::fusion::extension::struct_member_name::call(), boost::fusion::at(struct_instance)); + std::forward(visitor)(boost::fusion::extension::struct_member_name::call(), boost::fusion::at(struct_instance)); } }; @@ -50,11 +50,11 @@ struct visitable(v)), struct_instance(std::move(t)) {} template void operator()(Index) const { - visitor(boost::fusion::extension::struct_member_name::call(), std::move(boost::fusion::at(struct_instance))); + std::forward(visitor)(boost::fusion::extension::struct_member_name::call(), std::move(boost::fusion::at(struct_instance))); } }; @@ -62,21 +62,21 @@ struct visitable static void apply(V && v, const S & s) { typedef boost::mpl::range_c::value > Indices; - helper h{v, s}; + helper(v)), const S &> h{std::forward(v), s}; boost::fusion::for_each(Indices(), h); } template static void apply(V && v, S & s) { typedef boost::mpl::range_c::value > Indices; - helper h{v, s}; + helper(v)), S &> h{std::forward(v), s}; boost::fusion::for_each(Indices(), h); } template static void apply(V && v, S && s) { typedef boost::mpl::range_c::value > Indices; - helper_rvalue_ref h{v, std::move(s)}; + helper_rvalue_ref(v)), S &&> h{std::forward(v), std::move(s)}; boost::fusion::for_each(Indices(), h); } diff --git a/include/visit_struct/visit_struct_intrusive.hpp b/include/visit_struct/visit_struct_intrusive.hpp index ef911ab..ce9a5e1 100644 --- a/include/visit_struct/visit_struct_intrusive.hpp +++ b/include/visit_struct/visit_struct_intrusive.hpp @@ -132,7 +132,7 @@ template struct member_helper { template VISIT_STRUCT_CONSTEXPR static void apply_visitor(V && visitor, S && structure_instance) { - visitor(M::member_name, M::apply(std::forward(structure_instance))); + std::forward(visitor)(M::member_name, M::apply(std::forward(structure_instance))); } }; diff --git a/test_visit_struct.cpp b/test_visit_struct.cpp index b7581d6..b777009 100644 --- a/test_visit_struct.cpp +++ b/test_visit_struct.cpp @@ -82,6 +82,11 @@ struct test_visitor_three { void operator()(const char *, int &&) { result = 3; } + + // Make it non-copyable and non-moveable, apply visitor should still work. + test_visitor_three() = default; + test_visitor_three(const test_visitor_three &) = delete; + test_visitor_three(test_visitor_three &&) = delete; }; diff --git a/test_visit_struct_boost_fusion.cpp b/test_visit_struct_boost_fusion.cpp index 650ce09..cbbbf16 100644 --- a/test_visit_struct_boost_fusion.cpp +++ b/test_visit_struct_boost_fusion.cpp @@ -88,6 +88,11 @@ struct test_visitor_three { void operator()(const char *, int &&) { result = 3; } + + // Make it non-copyable and non-moveable, apply visitor should still work. + test_visitor_three() = default; + test_visitor_three(const test_visitor_three &) = delete; + test_visitor_three(test_visitor_three &&) = delete; }; diff --git a/test_visit_struct_intrusive.cpp b/test_visit_struct_intrusive.cpp index 4346028..5b0c6ef 100644 --- a/test_visit_struct_intrusive.cpp +++ b/test_visit_struct_intrusive.cpp @@ -44,6 +44,11 @@ struct test_visitor_three { void operator()(const char *, int &&) { result = 3; } + + // Make it non-copyable and non-moveable, apply visitor should still work. + test_visitor_three() = default; + test_visitor_three(const test_visitor_three &) = delete; + test_visitor_three(test_visitor_three &&) = delete; }; // debug_print