SeqAn3  3.0.1
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 <range/v3/algorithm/copy.hpp>
16 
20 #include <seqan3/io/exception.hpp>
21 #include <seqan3/range/concept.hpp>
25 #include <seqan3/std/algorithm>
26 #include <seqan3/std/concepts>
27 #include <seqan3/std/ranges>
28 
29 namespace seqan3::detail
30 {
31 
32 // ============================================================================
33 // view_persist
34 // ============================================================================
35 
47 template <std::ranges::input_range urng_t>
48 class view_persist : public std::ranges::view_interface<view_persist<urng_t>>
49 {
50 private:
53 
54 public:
58  using reference = reference_t<urng_t>;
61  using const_reference = reference;
63  using value_type = value_type_t<urng_t>;
65  using size_type = detail::transformation_trait_or_t<seqan3::size_type<urng_t>, void>;
67  using difference_type = difference_type_t<urng_t>;
69  using iterator = std::ranges::iterator_t<urng_t>;
71  using const_iterator = iterator;
73 
77  view_persist() noexcept = default;
78  constexpr view_persist(view_persist const & rhs) noexcept = default;
79  constexpr view_persist(view_persist && rhs) noexcept = default;
80  constexpr view_persist & operator=(view_persist const & rhs) noexcept = default;
81  constexpr view_persist & operator=(view_persist && rhs) noexcept = default;
82  ~view_persist() noexcept = default;
83 
87  view_persist(urng_t && _urange) :
88  urange{new urng_t{std::move(_urange)}}
89  {}
91 
108  const_iterator begin() const noexcept
109  {
110  return seqan3::begin(*urange);
111  }
112 
114  const_iterator cbegin() const noexcept
115  {
116  return begin();
117  }
118 
132  auto end() const noexcept
133  {
134  return seqan3::end(*urange);
135  }
136 
138  auto cend() const noexcept
139  {
140  return end();
141  }
143 };
144 
147 template <typename urng_t>
148 view_persist(urng_t &&) -> view_persist<std::remove_reference_t<urng_t>>;
149 
150 // ============================================================================
151 // persist_fn (adaptor definition)
152 // ============================================================================
153 
155 
157 class persist_fn : public adaptor_base<persist_fn>
158 {
159 private:
161  using base_t = adaptor_base<persist_fn>;
162 
163 public:
165  using base_t::base_t;
166 
167 private:
169  friend base_t;
170 
174  template <std::ranges::viewable_range urng_t>
175  static auto impl(urng_t && urange)
176  {
177  return std::views::all(std::forward<urng_t>(urange));
178  }
179 
183  template <std::ranges::range urng_t>
184  static auto impl(urng_t && urange)
185  {
186  static_assert(!std::is_lvalue_reference_v<urng_t>, "BUG: lvalue-reference in persist_fn::impl().");
187  return view_persist{std::move(urange)};
188  }
189 };
191 
192 } // namespace seqan3::detail
193 
194 // ============================================================================
195 // views::persist (adaptor instance definition)
196 // ============================================================================
197 
198 namespace seqan3::views
199 {
200 
248 inline auto constexpr persist = detail::persist_fn{};
249 
251 
252 } // namespace seqan3::views
shortcuts.hpp
Provides various shortcuts for common std::ranges functions.
seqan3::views
The SeqAn namespace for views.
Definition: view_to_simd.hpp:672
std::shared_ptr
seqan3::views::move
const auto move
A view that turns lvalue-references into rvalue-references.
Definition: move.hpp:68
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:248
concept.hpp
Additional non-standard concepts for ranges.
range.hpp
Provides various transformation traits used by the range module.
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.
seqan3::search_cfg::all
constexpr detail::search_mode_all all
Configuration element to receive all hits within the error bounds.
Definition: mode.hpp:43
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 .