Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/range/v3/functional/indirect.hpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 
0002 /// \file
0003 // Range v3 library
0004 //
0005 //  Copyright Eric Niebler 2013-present
0006 //
0007 //  Use, modification and distribution is subject to the
0008 //  Boost Software License, Version 1.0. (See accompanying
0009 //  file LICENSE_1_0.txt or copy at
0010 //  http://www.boost.org/LICENSE_1_0.txt)
0011 //
0012 // Project home: https://github.com/ericniebler/range-v3
0013 //
0014 #ifndef RANGES_V3_FUNCTIONAL_INDIRECT_HPP
0015 #define RANGES_V3_FUNCTIONAL_INDIRECT_HPP
0016 
0017 #include <utility>
0018 
0019 #include <concepts/concepts.hpp>
0020 
0021 #include <range/v3/functional/invoke.hpp>
0022 #include <range/v3/iterator/traits.hpp>
0023 #include <range/v3/utility/move.hpp>
0024 #include <range/v3/utility/static_const.hpp>
0025 
0026 #include <range/v3/detail/prologue.hpp>
0027 
0028 namespace ranges
0029 {
0030     /// \addtogroup group-functional
0031     /// @{
0032     template<typename Fn>
0033     struct indirected
0034     {
0035     private:
0036         RANGES_NO_UNIQUE_ADDRESS
0037         Fn fn_;
0038 
0039     public:
0040         indirected() = default;
0041         indirected(Fn fn)
0042           : fn_(std::move(fn))
0043         {}
0044         // value_type (needs no impl)
0045         template<typename... Its>
0046         [[noreturn]] invoke_result_t<Fn &, iter_reference_t<Its>...> //
0047         operator()(copy_tag, Its...) const
0048         {
0049             RANGES_EXPECT(false);
0050         }
0051 
0052         // Reference
0053         // clang-format off
0054         template<typename... Its>
0055         auto CPP_auto_fun(operator())(Its... its)
0056         (
0057             return invoke(fn_, *its...)
0058         )
0059         template<typename... Its>
0060         auto CPP_auto_fun(operator())(Its... its)(const)
0061         (
0062             return invoke((Fn const &)fn_, *its...)
0063         )
0064 
0065         // Rvalue reference
0066         template<typename... Its>
0067         auto CPP_auto_fun(operator())(move_tag, Its... its)
0068         (
0069             return static_cast<
0070                 aux::move_t<invoke_result_t<Fn &, iter_reference_t<Its>...>>>(
0071                 aux::move(invoke(fn_, *its...)))
0072         )
0073         template<typename... Its>
0074         auto CPP_auto_fun(operator())(move_tag, Its... its)(const)
0075         (
0076             return static_cast<
0077                 aux::move_t<invoke_result_t<Fn const &, iter_reference_t<Its>...>>>(
0078                 aux::move(invoke((Fn const &)fn_, *its...)))
0079         )
0080         // clang-format on
0081     };
0082 
0083     struct indirect_fn
0084     {
0085         template<typename Fn>
0086         constexpr indirected<Fn> operator()(Fn fn) const
0087         {
0088             return indirected<Fn>{detail::move(fn)};
0089         }
0090     };
0091 
0092     /// \ingroup group-functional
0093     /// \sa `indirect_fn`
0094     RANGES_INLINE_VARIABLE(indirect_fn, indirect)
0095     /// @}
0096 } // namespace ranges
0097 
0098 #include <range/v3/detail/epilogue.hpp>
0099 
0100 #endif