SeqAn3  3.0.2
The Modern C++ library for sequence analysis.
persist.hpp
Go to the documentation of this file.
1 // -----------------------------------------------------------------------------------------------------
2 // Copyright (c) 2006-2020, Knut Reinert & Freie Universität Berlin
3 // Copyright (c) 2016-2020, 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>
23 #include <seqan3/range/concept.hpp>
26 
27 namespace seqan3::detail
28 {
29 
30 // ============================================================================
31 // view_persist
32 // ============================================================================
33 
45 template <std::ranges::input_range urng_t>
46 class view_persist : public std::ranges::view_interface<view_persist<urng_t>>
47 {
48 private:
51 
52 public:
56  view_persist() noexcept = default;
57  constexpr view_persist(view_persist const & rhs) noexcept = default;
58  constexpr view_persist(view_persist && rhs) noexcept = default;
59  constexpr view_persist & operator=(view_persist const & rhs) noexcept = default;
60  constexpr view_persist & operator=(view_persist && rhs) noexcept = default;
61  ~view_persist() noexcept = default;
62 
66  view_persist(urng_t && _urange) :
67  urange{new urng_t{std::move(_urange)}}
68  {}
70 
87  auto begin() noexcept
88  {
89  return std::ranges::begin(*urange);
90  }
91 
93  auto begin() const noexcept
95  requires const_iterable_range<urng_t>
97  {
98  return std::ranges::cbegin(*urange);
99  }
100 
114  auto end() noexcept
115  {
116  return std::ranges::end(*urange);
117  }
118 
120  auto end() const noexcept
122  requires const_iterable_range<urng_t>
124  {
125  return std::ranges::cend(*urange);
126  }
128 };
129 
132 template <typename urng_t>
133 view_persist(urng_t &&) -> view_persist<std::remove_reference_t<urng_t>>;
134 
135 // ============================================================================
136 // persist_fn (adaptor definition)
137 // ============================================================================
138 
140 
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 } // namespace seqan3::detail
178 
179 // ============================================================================
180 // views::persist (adaptor instance definition)
181 // ============================================================================
182 
183 namespace seqan3::views
184 {
185 
233 inline auto constexpr persist = detail::persist_fn{};
234 
236 
237 } // namespace seqan3::views
seqan3::views
The SeqAn namespace for views.
Definition: view_iota_simd.hpp:218
std::shared_ptr
concept.hpp
Adaptations of concepts from the standard library.
algorithm
Adaptations of algorithms from the Ranges TS.
concepts
The Concepts library.
seqan3::views::persist
constexpr auto persist
A view adaptor that wraps rvalue references of non-views.
Definition: persist.hpp:233
concept.hpp
Additional non-standard concepts for ranges.
seqan3::views::move
auto const move
A view that turns lvalue-references into rvalue-references.
Definition: move.hpp:68
range.hpp
Provides various transformation traits used by the range module.
const_iterable_range
Specifies requirements of an input range type for which the const version of that type satisfies the ...
transformation_trait_or.hpp
Provides seqan3::detail::transformation_trait_or.
exception.hpp
Provides exceptions used in the I/O module.
iterator.hpp
Provides various transformation traits for use on iterators.
ranges
Adaptations of concepts from the Ranges TS.
std::begin
T begin(T... args)
std::end
T end(T... args)
detail.hpp
Auxiliary header for the views submodule .