SeqAn3  3.0.3
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 
21 #include <seqan3/io/exception.hpp>
22 #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>
134 
135 // ============================================================================
136 // persist_fn (adaptor definition)
137 // ============================================================================
138 
140 
142 class persist_fn : public adaptor_base<persist_fn>
143 {
144 private:
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
Adaptations of algorithms from the Ranges TS.
CRTP-base to simplify the definition of range adaptor closure objects and similar types.
Definition: detail.hpp:79
[adaptor_def]
Definition: persist.hpp:143
friend base_t
Befriend the base class so it can call impl().
Definition: persist.hpp:154
static auto impl(urng_t &&urange)
For ranges that are viewable, delegate to std::views::all.
Definition: persist.hpp:160
The type returned by seqan3::views::persist.
Definition: persist.hpp:47
auto end() noexcept
Returns an iterator to the element following the last element of the range.
Definition: persist.hpp:114
view_persist(urng_t &&) -> view_persist< std::remove_reference_t< urng_t >>
Template argument type deduction guide that strips references.
auto end() const noexcept
Returns an iterator to the element following the last element of the range.
Definition: persist.hpp:120
auto begin() const noexcept
Returns an iterator to the first element of the container.
Definition: persist.hpp:93
std::shared_ptr< urng_t > urange
Shared storage of the underlying range.
Definition: persist.hpp:50
auto begin() noexcept
Returns an iterator to the first element of the container.
Definition: persist.hpp:87
view_persist() noexcept=default
Defaulted.
The Concepts library.
Provides various transformation traits used by the range module.
constexpr auto persist
A view adaptor that wraps rvalue references of non-views.
Definition: persist.hpp:233
auto const move
A view that turns lvalue-references into rvalue-references.
Definition: move.hpp:70
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 internal SeqAn3 namespace.
Definition: aligned_sequence_concept.hpp:29
The SeqAn namespace for views.
Definition: async_input_buffer.hpp:343
Additional non-standard concepts for ranges.
Adaptations of concepts from the standard library.
Auxiliary header for the views submodule .
Adaptations of concepts from the Ranges TS.
Provides seqan3::detail::transformation_trait_or.