Horizon
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 
28 namespace ranges
29 {
32  template<typename Fn>
33  struct indirected
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 
83  struct indirect_fn
84  {
85  template<typename Fn>
86  constexpr indirected<Fn> operator()(Fn fn) const
87  {
88  return indirected<Fn>{detail::move(fn)};
89  }
90  };
91 
96 } // namespace ranges
97 
98 #include <range/v3/detail/epilogue.hpp>
99 
100 #endif
RANGES_INLINE_VARIABLE(detail::to_container_fn< detail::from_range< std::vector >>, to_vector) template< template< typename... > class ContT > auto to(RANGES_HIDDEN_DETAIL(detail
For initializing a container of the specified type with the elements of an Range.
Definition: conversion.hpp:399
meta::if_c< std::is_reference< R >::value, meta::_t< std::remove_reference< R > > &&, detail::decay_t< R > > move_t
Definition: move.hpp:59
typename Fn::template invoke< Args... > invoke
Evaluate the invocable Fn with the arguments Args.
Definition: meta.hpp:541
Definition: range_fwd.hpp:492
Definition: indirect.hpp:84
Definition: indirect.hpp:34
Definition: range_fwd.hpp:494