SeqAn3  3.0.3
The Modern C++ library for sequence analysis.
persist_view.hpp
Go to the documentation of this file.
1 // -----------------------------------------------------------------------------------------------------
2 // Copyright (c) 2006-2021, Knut Reinert & Freie Universität Berlin
3 // Copyright (c) 2016-2021, 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 
15 #include <seqan3/std/algorithm>
16 #include <seqan3/std/concepts>
17 #include <seqan3/std/ranges>
18 
22 #include <seqan3/io/exception.hpp>
25 
26 namespace seqan3::detail
27 {
28 
29 // ============================================================================
30 // view_persist
31 // ============================================================================
32 
44 template <std::ranges::input_range urng_t>
45 class view_persist : public std::ranges::view_interface<view_persist<urng_t>>
46 {
47 private:
50 
51 public:
55  view_persist() noexcept = default;
56  constexpr view_persist(view_persist const & rhs) noexcept = default;
57  constexpr view_persist(view_persist && rhs) noexcept = default;
58  constexpr view_persist & operator=(view_persist const & rhs) noexcept = default;
59  constexpr view_persist & operator=(view_persist && rhs) noexcept = default;
60  ~view_persist() noexcept = default;
61 
65  view_persist(urng_t && _urange) :
66  urange{new urng_t{std::move(_urange)}}
67  {}
69 
86  auto begin() noexcept
87  {
88  return std::ranges::begin(*urange);
89  }
90 
92  auto begin() const noexcept
94  requires const_iterable_range<urng_t>
96  {
97  return std::ranges::cbegin(*urange);
98  }
99 
113  auto end() noexcept
114  {
115  return std::ranges::end(*urange);
116  }
117 
119  auto end() const noexcept
121  requires const_iterable_range<urng_t>
123  {
124  return std::ranges::cend(*urange);
125  }
127 };
128 
131 template <typename urng_t>
132 view_persist(urng_t &&) -> view_persist<std::remove_reference_t<urng_t>>;
133 
134 // ============================================================================
135 // persist_fn (adaptor definition)
136 // ============================================================================
137 
139 
141 class persist_fn : public adaptor_base<persist_fn>
142 {
143 private:
145  using base_t = adaptor_base<persist_fn>;
146 
147 public:
149  using base_t::base_t;
150 
151 private:
153  friend base_t;
154 
158  template <std::ranges::viewable_range urng_t>
159  static auto impl(urng_t && urange)
160  {
161  return std::views::all(std::forward<urng_t>(urange));
162  }
163 
167  template <std::ranges::range urng_t>
168  static auto impl(urng_t && urange)
169  {
170  static_assert(!std::is_lvalue_reference_v<urng_t>, "BUG: lvalue-reference in persist_fn::impl().");
171  return view_persist{std::move(urange)};
172  }
173 };
175 
176 // ============================================================================
177 // detail::persist (adaptor instance definition)
178 // ============================================================================
179 
227 inline auto constexpr persist = persist_fn{};
228 
230 
231 } // namespace seqan3::detail
232 
233 #ifdef SEQAN3_DEPRECATED_310
234 namespace seqan3::views
235 {
236 
241 SEQAN3_DEPRECATED_310 inline auto constexpr persist = detail::persist_fn{};
242 
243 } // namespace seqan3::views
244 #endif // SEQAN3_DEPRECATED_310
Provides seqan3::detail::adaptor_base and seqan3::detail::combined_adaptor.
Adaptations of algorithms from the Ranges TS.
T begin(T... args)
The Concepts library.
Provides various transformation traits used by the range module.
T end(T... args)
constexpr auto persist
A view adaptor that wraps rvalue references of non-views.
Definition: persist_view.hpp:241
auto const move
A view that turns lvalue-references into rvalue-references.
Definition: move.hpp:74
Specifies requirements of an input range type for which the const version of that type satisfies the ...
Provides exceptions used in the I/O module.
Provides various transformation traits for use on iterators.
The SeqAn namespace for views.
Definition: char_to.hpp:22
#define SEQAN3_DEPRECATED_310
Deprecation message for SeqAn 3.1.0 release.
Definition: platform.hpp:203
Adaptations of concepts from the Ranges TS.
Additional non-standard concepts for ranges.
Provides seqan3::detail::transformation_trait_or.