More perfect forwarding in field visitors

This commit is contained in:
Alexander Kuzmenkov 2020-07-09 19:15:46 +03:00
parent 8095a4e2bb
commit 0001a08081

View File

@ -40,21 +40,24 @@ struct StaticVisitor
template <typename Visitor, typename F>
auto applyVisitor(Visitor && visitor, F && field)
{
return Field::dispatch(visitor, field);
return Field::dispatch(std::forward<Visitor>(visitor),
std::forward<F>(field));
}
template <typename Visitor, typename F1, typename F2>
auto applyVisitor(Visitor && visitor, F1 && field1, F2 && field2)
{
return Field::dispatch([&](auto & field1_value)
return Field::dispatch(
[&field1, &field2, &visitor](auto & field1_value)
{
return Field::dispatch([&](auto & field2_value)
return Field::dispatch(
[&field1_value, &visitor](auto & field2_value)
{
return visitor(field1_value, field2_value);
},
field2);
std::forward<F2>(field2));
},
field1);
std::forward<F1>(field1));
}