SeqAn3
The Modern C++ library for sequence analysis.
view_all.hpp
Go to the documentation of this file.
1 // -----------------------------------------------------------------------------------------------------
2 // Copyright (c) 2006-2019, Knut Reinert & Freie Universität Berlin
3 // Copyright (c) 2016-2019, 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 <string_view>
16 
18 #include <seqan3/range/concept.hpp>
20 #include <seqan3/std/concepts>
21 #include <seqan3/std/ranges>
22 #include <seqan3/std/span>
23 
24 namespace seqan3::detail
25 {
26 
27 // ============================================================================
28 // all_fn (adaptor definition)
29 // ============================================================================
30 
33 class all_fn : public adaptor_base<all_fn>
34 {
35 private:
37  using base_t = adaptor_base<all_fn>;
38 
39 public:
41  using base_t::base_t;
42 
43 private:
45  friend base_t;
46 
50  template <std::ranges::Range urng_t>
51  static constexpr auto impl(urng_t && urange)
52  {
54  "The view::all adaptor can only be passed ViewableRanges, i.e. Views or &-to-non-View.");
55 
56  // views are always passed as-is
57  if constexpr (std::ranges::View<remove_cvref_t<urng_t>>)
58  {
59  return std::view::all(std::forward<urng_t>(urange));
60  }
61  // string const &
62  else if constexpr (is_type_specialisation_of_v<remove_cvref_t<urng_t>, std::basic_string> &&
64  {
66  }
67  // contiguous
68  else if constexpr (ForwardingRange<urng_t> &&
71  {
72  return std::span{std::ranges::data(urange), std::ranges::size(urange)};
73  }
74  // random_access
75  else if constexpr (ForwardingRange<urng_t> &&
78  {
80  {
81  std::ranges::begin(urange),
82  std::ranges::begin(urange) + std::ranges::size(urange),
83  std::ranges::size(urange)
84  };
85  }
86  // pass to std::view::all (will return ref-view)
87  else
88  {
89  return std::view::all(std::forward<urng_t>(urange));
90  }
91  }
92 };
93 
94 } // namespace seqan3::detail
95 
96 // ============================================================================
97 // view::all (adaptor instance definition)
98 // ============================================================================
99 
100 namespace seqan3::view
101 {
102 
160 inline constexpr auto all = detail::all_fn{};
161 
163 
164 } // namespace seqan3::view
165 
166 namespace seqan3
167 {
169 template <typename t>
170 using all_view = decltype(view::all(std::declval<t>()));
171 }
Specifies requirements of a Range type whose elements occupy adjacent locations in memory...
::ranges::subrange< it_t, sen_t, k > subrange
Create a view from a pair of iterator and sentinel.
Definition: ranges:339
Specifies the requirements of a Range type that has constant time copy, move and assignment operators...
decltype(view::all(std::declval< t >())) all_view
Deduces the return value of seqan3::view::all.
Definition: view_all.hpp:170
Provides seqan3::type_list and auxiliary type traits.
constexpr auto all
A view adaptor that behaves like std::view:all, but type erases contiguous ranges.
Definition: view_all.hpp:160
::ranges::size size
Alias for ranges::size. Obtains the size of a range whose size can be calculated in constant time...
Definition: ranges:189
The main SeqAn3 namespace.
::ranges::data data
Alias for ranges::data. Returns a pointer the block of data of a ContiguousRange. ...
Definition: ranges:184
Additional non-standard concepts for ranges.
The Concepts library.
Auxiliary header for the view submodule .
::ranges::iterator_t iterator_t
Alias for ranges::iterator_t. Obtains the iterator type of a range.
Definition: ranges:204
Adaptations of concepts from the Ranges TS.
::ranges::begin begin
Alias for ranges::begin. Returns an iterator to the beginning of a range.
Definition: ranges:174
The SeqAn3 namespace for views.
Provides std::span from the C++20 standard library.
Specifies requirements of a Range type for which begin returns a type that models std::RandomAccessIt...
Specifies the requirements of a Range type that is either a std::ranges::View or an lvalue-reference...
T is_const_v
Definition: aligned_sequence_concept.hpp:35
Specifies the requirements of a Range type that knows its size in constant time with the size functio...