SeqAn3  3.1.0-rc.1
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:
49  std::shared_ptr<urng_t> urange;
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 
142 class persist_fn : public adaptor_base<persist_fn>
143 {
144 private:
146  using base_t = adaptor_base<persist_fn>;
147 
148 public:
150  using base_t::base_t;
151 
152 private:
154  friend base_t;
155 
159  template <std::ranges::viewable_range urng_t>
160  static auto impl(urng_t && urange)
161  {
162  return std::views::all(std::forward<urng_t>(urange));
163  }
164 
168  template <std::ranges::range urng_t>
169  static auto impl(urng_t && urange)
170  {
171  static_assert(!std::is_lvalue_reference_v<urng_t>, "BUG: lvalue-reference in persist_fn::impl().");
172  return view_persist{std::move(urange)};
173  }
174 };
176 
177 // ============================================================================
178 // detail::persist (adaptor instance definition)
179 // ============================================================================
180 
224 inline auto constexpr persist = persist_fn{};
225 
226 } // namespace seqan3::detail
Provides seqan3::detail::adaptor_base and seqan3::detail::combined_adaptor.
Adaptations of algorithms from the Ranges TS.
The Concepts library.
Provides various transformation traits used by the range module.
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.
Adaptations of concepts from the Ranges TS.
Provides seqan3::detail::transformation_trait_or.
Additional non-standard concepts for ranges.