Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-16 10:27:57

0001 /// \file
0002 // Range v3 library
0003 //
0004 //  Copyright Eric Niebler 2013-present
0005 //
0006 //  Use, modification and distribution is subject to the
0007 //  Boost Software License, Version 1.0. (See accompanying
0008 //  file LICENSE_1_0.txt or copy at
0009 //  http://www.boost.org/LICENSE_1_0.txt)
0010 //
0011 // Project home: https://github.com/ericniebler/range-v3
0012 //
0013 #ifndef RANGES_V3_FUNCTIONAL_ON_HPP
0014 #define RANGES_V3_FUNCTIONAL_ON_HPP
0015 
0016 #include <concepts/concepts.hpp>
0017 
0018 #include <range/v3/detail/config.hpp>
0019 #include <range/v3/functional/invoke.hpp>
0020 
0021 #include <range/v3/detail/prologue.hpp>
0022 
0023 namespace ranges
0024 {
0025     /// \addtogroup group-functional
0026     /// @{
0027     template<typename Fn1, typename Fn2>
0028     struct transformed
0029     {
0030     private:
0031         RANGES_NO_UNIQUE_ADDRESS
0032         Fn1 first_;
0033         RANGES_NO_UNIQUE_ADDRESS
0034         Fn2 second_;
0035 
0036     public:
0037         transformed() = default;
0038         constexpr transformed(Fn1 fn1, Fn2 fn2)
0039           : first_(static_cast<Fn1 &&>(fn1))
0040           , second_(static_cast<Fn2 &&>(fn2))
0041         {}
0042         // clang-format off
0043         template<typename... Args>
0044         auto CPP_auto_fun(operator())(Args &&... args)
0045         (
0046             return invoke(first_, invoke(second_, static_cast<Args &&>(args)...))
0047         )
0048         template<typename... Args>
0049         auto CPP_auto_fun(operator())(Args &&... args)(const)
0050         (
0051             return invoke((Fn1 const &)first_,
0052                           invoke((Fn2 const &)second_, static_cast<Args &&>(args))...)
0053         )
0054         // clang-format on
0055     };
0056 
0057     struct on_fn
0058     {
0059         template<typename Fn1, typename Fn2>
0060         constexpr transformed<Fn1, Fn2> operator()(Fn1 fn1, Fn2 fn2) const
0061         {
0062             return transformed<Fn1, Fn2>{detail::move(fn1), detail::move(fn2)};
0063         }
0064     };
0065 
0066     /// \ingroup group-functional
0067     /// \sa `on_fn`
0068     RANGES_INLINE_VARIABLE(on_fn, on)
0069     /// @}
0070 } // namespace ranges
0071 
0072 #include <range/v3/detail/epilogue.hpp>
0073 
0074 #endif