BioC++ core-0.7.0
The Modern C++ libraries for Bioinformatics.
 
Loading...
Searching...
No Matches
persist.hpp
Go to the documentation of this file.
1// -----------------------------------------------------------------------------------------------------
2// Copyright (c) 2022 deCODE Genetics
3// Copyright (c) 2006-2020, Knut Reinert & Freie Universität Berlin
4// Copyright (c) 2016-2020, Knut Reinert & MPI für molekulare Genetik
5// This file may be used, modified and/or redistributed under the terms of the 3-clause BSD-License
6// shipped with this file and also available at: https://github.com/biocpp/biocpp-core/blob/main/LICENSE.md
7// -----------------------------------------------------------------------------------------------------
8
14#pragma once
15
16#include <algorithm>
17#include <concepts>
18#include <ranges>
19
25
26namespace bio::ranges::detail
27{
28
29// ============================================================================
30// view_persist
31// ============================================================================
32
44template <std::ranges::input_range urng_t>
45class view_persist : public std::ranges::view_interface<view_persist<urng_t>>
46{
47private:
50
51public:
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) : urange{new urng_t{std::move(_urange)}} {}
67
84 auto begin() noexcept { return std::ranges::begin(*urange); }
85
87 auto begin() const noexcept
88 requires const_iterable_range<urng_t>
89 {
90 return std::ranges::cbegin(*urange);
91 }
92
106 auto end() noexcept { return std::ranges::end(*urange); }
107
109 auto end() const noexcept
110 requires const_iterable_range<urng_t>
111 {
112 return std::ranges::cend(*urange);
113 }
115};
116
119template <typename urng_t>
120view_persist(urng_t &&) -> view_persist<std::remove_reference_t<urng_t>>;
121
122// ============================================================================
123// persist_fn (adaptor definition)
124// ============================================================================
125
127
129class persist_fn : public adaptor_base<persist_fn>
130{
131private:
133 using base_t = adaptor_base<persist_fn>;
134
135public:
137 using base_t::base_t;
138
139private:
141 friend base_t;
142
146 template <std::ranges::viewable_range urng_t>
147 static auto impl(urng_t && urange)
148 {
149 return std::views::all(std::forward<urng_t>(urange));
150 }
151
155 template <std::ranges::range urng_t>
156 static auto impl(urng_t && urange)
157 {
158 static_assert(!std::is_lvalue_reference_v<urng_t>, "BUG: lvalue-reference in persist_fn::impl().");
159 return view_persist{std::forward<urng_t>(urange)};
160 }
161};
163
164} // namespace bio::ranges::detail
165
166// ============================================================================
167// views::persist (adaptor instance definition)
168// ============================================================================
169
170namespace bio::ranges::views
171{
172
220inline constexpr auto persist = detail::persist_fn{};
221
223
224} // namespace bio::ranges::views
T begin(T... args)
T end(T... args)
constexpr auto persist
A view adaptor that wraps rvalue references of non-views.
Definition: persist.hpp:220
The BioC++ namespace for views.
Additional non-standard concepts for ranges.
Adaptations of concepts from the standard library.
Auxiliary header for the views submodule .
Provides bio::meta::transformation_trait_or.
Provides various transformation traits used by the range module.