SeqAn3 3.2.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
24
25namespace seqan3::detail
26{
27
28// ============================================================================
29// view_persist
30// ============================================================================
31
43template <std::ranges::input_range urng_t>
44class view_persist : public std::ranges::view_interface<view_persist<urng_t>>
45{
46private:
49
50public:
54 view_persist() noexcept = default;
55 constexpr view_persist(view_persist const & rhs) noexcept = default;
56 constexpr view_persist(view_persist && rhs) noexcept = default;
57 constexpr view_persist & operator=(view_persist const & rhs) noexcept = default;
58 constexpr view_persist & operator=(view_persist && rhs) noexcept = default;
59 ~view_persist() noexcept = default;
60
64 view_persist(urng_t && _urange) :
65 urange{new urng_t{std::move(_urange)}}
66 {}
68
85 auto begin() noexcept
86 {
87 return std::ranges::begin(*urange);
88 }
89
91 auto begin() const noexcept
93 requires const_iterable_range<urng_t>
95 {
96 return std::ranges::cbegin(*urange);
97 }
98
112 auto end() noexcept
113 {
114 return std::ranges::end(*urange);
115 }
116
118 auto end() const noexcept
120 requires const_iterable_range<urng_t>
122 {
123 return std::ranges::cend(*urange);
124 }
126};
127
130template <typename urng_t>
132
133// ============================================================================
134// persist_fn (adaptor definition)
135// ============================================================================
136
138
141class persist_fn : public adaptor_base<persist_fn>
142{
143private:
146
147public:
149 using base_t::base_t;
150
151private:
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
223inline auto constexpr persist = persist_fn{};
224
225} // namespace seqan3::detail
Provides seqan3::detail::adaptor_base and seqan3::detail::combined_adaptor.
The <algorithm> header from C++20's standard library.
CRTP-base to simplify the definition of range adaptor closure objects and similar types.
Definition: adaptor_base.hpp:77
[adaptor_def]
Definition: persist_view.hpp:142
friend base_t
Befriend the base class so it can call impl().
Definition: persist_view.hpp:153
static auto impl(urng_t &&urange)
For ranges that are viewable, delegate to std::views::all.
Definition: persist_view.hpp:159
The type returned by seqan3::detail::persist.
Definition: persist_view.hpp:45
auto end() noexcept
Returns an iterator to the element following the last element of the range.
Definition: persist_view.hpp:112
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_view.hpp:118
auto begin() const noexcept
Returns an iterator to the first element of the container.
Definition: persist_view.hpp:91
std::shared_ptr< urng_t > urange
Shared storage of the underlying range.
Definition: persist_view.hpp:48
auto begin() noexcept
Returns an iterator to the first element of the container.
Definition: persist_view.hpp:85
view_persist() noexcept=default
Defaulted.
The <concepts> header from C++20's standard library.
Provides various transformation traits used by the range module.
auto constexpr persist
[adaptor_def]
Definition: persist_view.hpp:223
Specifies requirements of an input range type for which the const version of that type satisfies the ...
Provides various transformation traits for use on iterators.
The internal SeqAn3 namespace.
Definition: aligned_sequence_concept.hpp:29
The <ranges> header from C++20's standard library.
Provides seqan3::detail::transformation_trait_or.
Additional non-standard concepts for ranges.