refactor: use perfect forwarding for make functions

Addresses https://github.com/mpusz/units/pull/261#discussion_r597131272.
This commit is contained in:
Johel Ernesto Guerrero Peña
2021-03-18 17:06:17 -04:00
committed by Mateusz Pusz
parent c61b8643d7
commit 234337d310
2 changed files with 6 additions and 6 deletions

View File

@@ -37,9 +37,9 @@ namespace units {
namespace detail {
template<Reference auto R> // TODO: Replace with `v * R{}` pending https://github.com/BobSteagall/wg21/issues/58.
inline constexpr auto make_quantity = [](auto v) {
using Rep = decltype(v);
return quantity<typename decltype(R)::dimension, typename decltype(R)::unit, Rep>(std::move(v));
inline constexpr auto make_quantity = [](auto&& v) {
using Rep = std::remove_cvref_t<decltype(v)>;
return quantity<typename decltype(R)::dimension, typename decltype(R)::unit, Rep>(std::forward<decltype(v)>(v));
};
} // namespace detail

View File

@@ -34,9 +34,9 @@ namespace units {
namespace detail {
template<Kind K>
inline constexpr auto make_quantity_kind_fn = [](auto q) {
using Q = decltype(q);
return quantity_kind<K, typename Q::unit, typename Q::rep>(std::move(q));
inline constexpr auto make_quantity_kind_fn = [](auto&& q) {
using Q = std::remove_reference_t<decltype(q)>;
return quantity_kind<K, typename Q::unit, typename Q::rep>(std::forward<decltype(q)>(q));
};
template<QuantityKind QK>