SeqAn3  3.0.0
The Modern C++ library for sequence analysis.
deep.hpp
Go to the documentation of this file.
1 // -----------------------------------------------------------------------------------------------------
2 // Copyright (c) 2006-2019, Knut Reinert & Freie Universität Berlin
3 // Copyright (c) 2016-2019, Knut Reinert & MPI für molekulare Genetik
4 // This file may be used, modified and/or redistributed under the terms of the 3-clause BSD-License
5 // shipped with this file and also available at: https://github.com/seqan/seqan3/blob/master/LICENSE.md
6 // -----------------------------------------------------------------------------------------------------
7 
13 #pragma once
14 
16 #include <seqan3/std/ranges>
17 
18 namespace seqan3::view
19 {
20 
100 template <typename underlying_adaptor_t>
101 class deep : public detail::adaptor_base<deep<underlying_adaptor_t>, underlying_adaptor_t>
102 {
103 private:
105  using base_type = detail::adaptor_base<deep<underlying_adaptor_t>, underlying_adaptor_t>;
106 
108  friend base_type;
109 
110 public:
114  using base_type::base_type;
116 
118 
120  using base_type::operator();
121 
129  template <std::ranges::InputRange urng_t, typename underlying_adaptor_t_>
130  static constexpr auto impl(urng_t && urange, underlying_adaptor_t_ && adap)
131  {
132  return std::forward<urng_t>(urange) | std::forward<underlying_adaptor_t_>(adap);
133  }
134 
145  template <std::ranges::InputRange urng_t>
149  constexpr auto operator()(urng_t && urange) const &
150  {
151  return std::forward<urng_t>(urange) | std::view::transform([me = *this] (auto && e)
152  {
153  return std::forward<decltype(e)>(e) | me;
154  });
155  }
156 
158  template <std::ranges::InputRange urng_t>
162  constexpr auto operator()(urng_t && urange) &&
163  {
164  return std::forward<urng_t>(urange) | std::view::transform([me = std::move(*this)] (auto && e)
165  {
166  return std::forward<decltype(e)>(e) | me;
167  });
168  }
169 
178  template <typename first_arg_t, typename ... stored_arg_types>
182  constexpr auto operator()(first_arg_t && first, stored_arg_types && ...args) const
183  {
184  // The adaptor currently wrapped is a proto-adaptor and this function has the arguments to "complete" it.
185  // We extract the adaptor that is stored and invoke it with the given arguments.
186  // This returns an adaptor closure object.
187  auto adaptor_closure = std::get<0>(this->arguments)(std::forward<first_arg_t>(first),
188  std::forward<stored_arg_types>(args)...);
189  // Now we wrap this closure object back into a view::deep to get the deep behaviour.
190  return deep<decltype(adaptor_closure)>{std::move(adaptor_closure)};
191  }
192 
194  constexpr auto operator()() const
195  {
196  // Proto-adaptors require arguments by definition, but some support defaulting those (e.g. view::translate).
197  // This extracts the proto adaptor and invokes it without args which yields a different object, the closure
198  // with defaulted arguments.
199  auto adaptor_closure = std::get<0>(this->arguments)();
200  // Now we wrap this closure object back into a view::deep to get the deep behaviour.
201  return deep<decltype(adaptor_closure)>{std::move(adaptor_closure)};
202  }
203 
216  template <std::ranges::InputRange urng_t, typename ... stored_arg_types>
218  requires sizeof...(stored_arg_types) > 0
220  constexpr auto operator()(urng_t && urange, stored_arg_types && ...args) const
221  {
222  auto adaptor_closure = std::get<0>(this->arguments)(std::forward<stored_arg_types>(args)...);
223  return std::forward<urng_t>(urange) | std::move(adaptor_closure);
224  }
225 };
226 
230 template <typename underlying_adaptor_t>
233 deep(underlying_adaptor_t && inner) -> deep<underlying_adaptor_t>;
234 
236 
237 } // namespace seqan3::view
Auxiliary header for the view submodule .
Adaptations of concepts from the Ranges TS.
The SeqAn3 namespace for views.
Specifies requirements of a Range type for which begin returns a type that models std::InputIterator...
A wrapper type around an existing view adaptor that enables "deep view" behaviour for that view...
Definition: deep.hpp:101
constexpr auto transform
A range adaptor that takes a invocable and returns a view of the elements with the invocable applied...
Definition: ranges:911