Horizon
Loading...
Searching...
No Matches
indirect.hpp
Go to the documentation of this file.
1
3// Range v3 library
4//
5// Copyright Eric Niebler 2013-present
6//
7// Use, modification and distribution is subject to the
8// Boost Software License, Version 1.0. (See accompanying
9// file LICENSE_1_0.txt or copy at
10// http://www.boost.org/LICENSE_1_0.txt)
11//
12// Project home: https://github.com/ericniebler/range-v3
13//
14#ifndef RANGES_V3_FUNCTIONAL_INDIRECT_HPP
15#define RANGES_V3_FUNCTIONAL_INDIRECT_HPP
16
17#include <utility>
18
19#include <concepts/concepts.hpp>
20
24#include <range/v3/utility/static_const.hpp>
25
26#include <range/v3/detail/prologue.hpp>
27
28namespace ranges
29{
32 template<typename Fn>
34 {
35 private:
36 RANGES_NO_UNIQUE_ADDRESS
37 Fn fn_;
38
39 public:
40 indirected() = default;
41 indirected(Fn fn)
42 : fn_(std::move(fn))
43 {}
44 // value_type (needs no impl)
45 template<typename... Its>
46 [[noreturn]] invoke_result_t<Fn &, iter_reference_t<Its>...> //
47 operator()(copy_tag, Its...) const
48 {
49 RANGES_EXPECT(false);
50 }
51
52 // Reference
53 // clang-format off
54 template<typename... Its>
55 auto CPP_auto_fun(operator())(Its... its)
56 (
57 return invoke(fn_, *its...)
58 )
59 template<typename... Its>
60 auto CPP_auto_fun(operator())(Its... its)(const)
61 (
62 return invoke((Fn const &)fn_, *its...)
63 )
64
65 // Rvalue reference
66 template<typename... Its>
67 auto CPP_auto_fun(operator())(move_tag, Its... its)
68 (
69 return static_cast<
71 aux::move(invoke(fn_, *its...)))
72 )
73 template<typename... Its>
74 auto CPP_auto_fun(operator())(move_tag, Its... its)(const)
75 (
76 return static_cast<
78 aux::move(invoke((Fn const &)fn_, *its...)))
79 )
80 // clang-format on
81 };
82
84 {
85 template<typename Fn>
86 constexpr indirected<Fn> operator()(Fn fn) const
87 {
88 return indirected<Fn>{detail::move(fn)};
89 }
90 };
91
94 RANGES_INLINE_VARIABLE(indirect_fn, indirect)
96} // namespace ranges
97
98#include <range/v3/detail/epilogue.hpp>
99
100#endif
meta::if_c< std::is_reference< R >::value, meta::_t< std::remove_reference< R > > &&, detail::decay_t< R > > move_t
Definition move.hpp:59
Definition range_fwd.hpp:492
Definition indirect.hpp:84
Definition indirect.hpp:34
Definition range_fwd.hpp:494