Skip to content

Commit

Permalink
Add an rvalue-qualified overload of closure::operator(). This makes
Browse files Browse the repository at this point in the history
forwarding work properly in cases such as r | foo(std::string("foo")), where
foo is an adaptor.  Without this, the std::string temporary dangles.
  • Loading branch information
tzlaine committed Jan 21, 2024
1 parent 510eb43 commit 1c050d2
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion include/boost/stl_interfaces/view_adaptor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_;
};
Expand Down

0 comments on commit 1c050d2

Please sign in to comment.