Add an rvalue-qualified overload of closure::operator(). This makes

forwarding work properly in cases such as r | foo(std::string("foo")), where
foo is an adaptor.  Without this, the std::string temporary dangles.
This commit is contained in:
Zach Laine
2024-01-21 15:26:41 -06:00
parent 510eb431fb
commit 1c050d2df5

View File

@@ -242,11 +242,24 @@ namespace boost { namespace stl_interfaces {
typename Enable =
std::enable_if_t<detail::is_invocable_v<F const &, T>>>
#endif
constexpr decltype(auto) operator()(T && t) const
constexpr decltype(auto) operator()(T && t) const &
{
return f_((T &&) t);
}
#if BOOST_STL_INTERFACES_USE_CONCEPTS
template<typename T>
requires std::invocable<F &&, T>
#else
template<
typename T,
typename Enable = std::enable_if_t<detail::is_invocable_v<F &&, T>>>
#endif
constexpr decltype(auto) operator()(T && t) &&
{
return std::move(f_)((T &&) t);
}
private:
F f_;
};