/// \file // Range v3 library // // Copyright Eric Niebler 2013-present // // Use, modification and distribution is subject to the // Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // // Project home: https://github.com/ericniebler/range-v3 // #ifndef RANGES_V3_FUNCTIONAL_ON_HPP #define RANGES_V3_FUNCTIONAL_ON_HPP #include #include #include namespace ranges { /// \addtogroup group-functional /// @{ template struct transformed { private: RANGES_NO_UNIQUE_ADDRESS Fn1 first_; RANGES_NO_UNIQUE_ADDRESS Fn2 second_; public: transformed() = default; constexpr transformed(Fn1 fn1, Fn2 fn2) : first_(static_cast(fn1)) , second_(static_cast(fn2)) {} // clang-format off template auto CPP_auto_fun(operator())(Args &&... args) ( return invoke(first_, invoke(second_, static_cast(args)...)) ) template auto CPP_auto_fun(operator())(Args &&... args)(const) ( return invoke((Fn1 const &)first_, invoke((Fn2 const &)second_, static_cast(args)...)) ) // clang-format on }; struct on_fn { template constexpr transformed operator()(Fn1 fn1, Fn2 fn2) const { return transformed{detail::move(fn1), detail::move(fn2)}; } }; /// \ingroup group-functional /// \sa `on_fn` RANGES_INLINE_VARIABLE(on_fn, on) /// @} } // namespace ranges #endif