SeqAn3 3.4.0-rc.1
The Modern C++ library for sequence analysis.
Loading...
Searching...
No Matches
Views

Views are "lazy range combinators" that offer modified views onto other ranges. More...

+ Collaboration diagram for Views:

Classes

class  seqan3::views::deep< underlying_adaptor_t >
 A wrapper type around an existing view adaptor that enables "deep view" behaviour for that view. More...
 

Typedefs

using seqan3::views::chunk = seqan::stl::views::chunk
 A view adaptor that divides a range into chunks.
This entity is not part of the SeqAn API. Do not rely on it in your applications. This is a implementation of the C++23 chunk_view. It will be replaced with std::views::chunk.
.
 
using seqan3::views::join_with = seqan::stl::views::join_with
 A view adaptor that represents view consisting of the sequence obtained from flattening a view of ranges, with every element of the delimiter inserted in between elements of the view. The delimiter can be a single element or a view of elements.
This entity is not part of the SeqAn API. Do not rely on it in your applications. This is a implementation of the C++23 join_with_view. It will be replaced with ::std::views::join_with.
.
 
using seqan3::views::zip = seqan::stl::views::zip
 A view adaptor that takes several views and returns tuple-like values from every i-th element of each view.
This entity is not part of the SeqAn API. Do not rely on it in your applications. This is a implementation of the C++23 zip_view. It will be replaced with std::views::zip.
.
 

Variables

template<typename out_t >
constexpr auto seqan3::views::convert
 A view that converts each element in the input range (implicitly or via static_cast).
 
template<auto index>
constexpr auto seqan3::views::elements
 A view calling get on each element in a range.
 
constexpr auto seqan3::views::interleave
 A view that interleaves a given range into another range at regular intervals.
 
constexpr detail::repeat_fn seqan3::views::repeat
 A view factory that repeats a given value infinitely.
 
constexpr auto seqan3::views::repeat_n
 A view factory that repeats a given value n times.
 
constexpr auto seqan3::views::slice
 A view adaptor that returns a half-open interval on the underlying range.
 

Detailed Description

Views are "lazy range combinators" that offer modified views onto other ranges.

SeqAn makes heavy use of views as defined in the Ranges Technical Specification. From the original documentation: "A view is a lightweight wrapper that presents a view of an underlying sequence of elements in some custom way without mutating or copying it. Views are cheap to create and copy, and have non-owning reference semantics. [...] The big advantage of ranges over iterators is their composability. They permit a functional style of programming where data is manipulated by passing it through a series of combinators. In addition, the combinators can be lazy, only doing work when the answer is requested, and purely functional, without mutating the original data. This makes it easier to reason about your code, especially when writing concurrent programs."

See the range module for how views relate to containers and decorators.

Most views provided by SeqAn are specific to biological operations, like seqan3::views::trim_quality which trims sequences based on the quality or seqan3::views::complement which generates the complement of a nucleotide sequence. But SeqAn also provides some general purpose views.

Namespaces

Example

Functional and pipe notations:

// SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin
// SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik
// SPDX-License-Identifier: CC0-1.0
#include <algorithm>
int main()
{
using namespace seqan3::literals;
seqan3::dna4_vector vec{"ACGGTC"_dna4};
// these are synonymous:
// both views "behave" like a collection of the elements 'T', 'G', 'C', 'C', 'A', 'G'
// but can be copied cheaply et cetera
}
T boolalpha(T... args)
A "pretty printer" for most SeqAn data structures and related types.
Definition debug_stream_type.hpp:79
Provides seqan3::views::complement.
Provides seqan3::dna4, container aliases and string literals.
T equal(T... args)
auto const complement
A view that converts a range of nucleotides to their complement.
Definition complement.hpp:64
The SeqAn namespace for literals.

Re-transform into a distinct container:

// SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin
// SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik
// SPDX-License-Identifier: CC0-1.0
#include <ranges>
int main()
{
using namespace seqan3::literals;
seqan3::dna4_vector vec{"ACGGTC"_dna4};
// re-convert to container
assert(complemented == "TGCCAG"_dna4);
// also possible in one step
seqan3::dna4_vector reversed = vec | std::views::reverse | seqan3::ranges::to<seqan3::dna4_vector>();
assert(reversed == "CTGGCA"_dna4);
}
seqan::stl::ranges::to to
Converts a range to a container. <dl class="no-api">This entity is not part of the SeqAn API....
Definition to.hpp:23
Provides seqan3::ranges::to.

Composability:

// SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin
// SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik
// SPDX-License-Identifier: CC0-1.0
#include <ranges>
int main()
{
using namespace seqan3::literals;
seqan3::dna4_vector vec{"ACGGTC"_dna4};
// views can be composed iteratively
auto vec_view3 = vec | std::views::reverse;
// or in one line similar to the unix command line
auto vec_view5 = vec | seqan3::views::complement | std::views::reverse;
// vec_view4 and vec_view5 are the reverse complement of "ACGGTC": "GACCGT"
seqan3::debug_stream << vec_view4 << '\n'; // GACCGT
seqan3::debug_stream << vec_view5 << '\n'; // GACCGT
}
Provides seqan3::debug_stream and related types.
debug_stream_type debug_stream
A global instance of seqan3::debug_stream_type.
Definition debug_stream.hpp:37

Views vs view adaptors

When talking about views, two different entities are often conflated:

  1. the view (this is the type that is a range and meets std::ranges::view; it is what we refer to with auto vec_view above)
  2. the view adaptor (this is the functor that returns the actual view based on it's parameters, including the underlying range; in the above example std::views::reverse and seqan3::views::complement are view adaptors)

The view adaptor also facilitates the piping behaviour. It is the only entity that is publicly documented and the actual view type (the range type returned by the adaptor) is considered implementation defined. The properties of the returned range are however specified and documented as part of the adaptor, see below.

An exception to this rule are views that don't work on an underlying range and can only be placed at the beginning of a pipe of operations; they do not need an adaptor, because their constructor is sufficient. This is not relevant for the documentation, though, we always document views::foo, independent of whether views::foo is the adaptor that returns the "foo type" or whether views::foo is the "foo type".

View properties

There are three view properties that are documented for a view, only if that view fulfils them:

Source-only views: Most views operate on an underlying range and return a (modified) range, i.e. they can be placed at the beginning, middle or end of a "pipe" of view operations. However, some views are limited to being at the front ("source"), e.g. std::views::empty, std::view::single and std::views::iota. These views are marked as "source-only" and have no urng_t column in the second table. The C++ standard calls these Range factories, which are utilities to create a view.

Sink-only views: The opposite of a source-only view. It can only be placed at the end of a pipe, i.e. it operates on views, but does not actually return a range (has no rrng_t column in the second table). The C++20 standard doesn't have this concept.

Deep views: Some views are declared as "deeps views". This means, that in case they are given a range-of-range as input (as opposed to just a range), they will apply their transformation on the innermost range (instead of the outermost range which would be default). Most alphabet-based transformations are defined as deep, but you can use seqan3::views::deep to make any view (adaptor) deep. See seqan3::views::deep for more details. The C++20 standard doesn't have this concept.

For all views the following are documented:

Concepts and traits urng_t (underlying range type) rrng_t (returned range type)
std::ranges::input_range [required] (usually) [preserved|lost|guaranteed] (usually preserved)
std::ranges::forward_range [required] (or not) [preserved|lost|guaranteed]
std::ranges::bidirectional_range [required] (or not) [preserved|lost|guaranteed]
std::ranges::random_access_range [required] (or not) [preserved|lost|guaranteed]
std::ranges::contiguous_range [required] (or not) [preserved|lost|guaranteed] (usually lost)
std::ranges::viewable_range [required] (usually) [preserved|lost|guaranteed] (usually guaranteed)
std::ranges::view [required] (or not) [preserved|lost|guaranteed] (usually guaranteed)
std::ranges::sized_range [required] (or not) [preserved|lost|guaranteed]
std::ranges::common_range [required] (or not) [preserved|lost|guaranteed]
std::ranges::output_range [required] (or not) [preserved|lost|guaranteed]
seqan3::const_iterable_range [required] (or not) [preserved|lost]
std::ranges::range_reference_t optionally a type or concept optionally a type or concept

Underlying range requirements: All view adaptors that are not source-only make certain assumptions about their underlying range. The most basic assumption is that the range satisfies std::ranges::input_range, but many have stronger requirements, e.g. std::ranges::random_access_range. The concepts in the first block all build up on each other, i.e. requiring one implies requiring those above; the other concepts are mostly independent of each other. Most views also require that the underlying range satisfy std::ranges::viewable_range which means they don't accept temporary range objects other than views (because they are cheap to copy). Note that these being requirements means that they are the minimal set of properties assumed. Views may very well make use of stronger properties if available.

Return range guarantees: All view adaptors that are not sink-only return a range that meets at least std::ranges::input_range and also std::ranges::view (and conversely also std::ranges::viewable_range, because all views are viewable). Most views also preserve stronger properties, e.g. std::ranges::random_access_range, but this depends on the view. Some views may add properties not present on the input range.

Underlying range's reference type: The reference type is the type the elements of the underlying range are accessed by (since dereferencing an iterator or calling operator[] returns the reference type). The reference type may or may not actually contain a & (see below). For many SeqAn specific views additional concept requirements are defined for the input range's reference type, e.g. seqan3::views::complement can only operate on ranges whose elements are nucleotides (meet seqan3::nucleotide_alphabet). In some case the type may even be a specific type or the result of a type trait.

Returned range's reference type: Conversely certain views make guarantees on the concepts satisfied by the return range's reference type or even always have a fixed type, e.g. seqan3::views::complement operates on nucleotides and of course also returns nucleotides and "std::ranges::range_reference_t<urng_t>" would imply that the reference type is the same. However, and this is important to note, the reference type of seqan3::views::complement has any actual & removed from the underlying ranges' reference type (if originally present), this goes hand-in-hand with std::ranges::output_range being lost → original elements cannot be written to through this view. This is because new elements are being generated. Other views like std::views::reverse also preserve the & (if originally present), because the elements in the return view still point to the elements in the original range (just in different order). This has the effect that through some combinations of views you can modify the elements in the original range (if all views in the pipe preserve std::ranges::output_range), but through others you can't.

See also
https://en.cppreference.com/w/cpp/ranges

Typedef Documentation

◆ chunk

using seqan3::views::chunk = typedef seqan::stl::views::chunk

A view adaptor that divides a range into chunks.

This entity is not part of the SeqAn API. Do not rely on it in your applications. This is a implementation of the C++23 chunk_view. It will be replaced with std::views::chunk.
.

See also
https://en.cppreference.com/w/cpp/ranges/chunk_view

◆ join_with

using seqan3::views::join_with = typedef seqan::stl::views::join_with

A view adaptor that represents view consisting of the sequence obtained from flattening a view of ranges, with every element of the delimiter inserted in between elements of the view. The delimiter can be a single element or a view of elements.

This entity is not part of the SeqAn API. Do not rely on it in your applications. This is a implementation of the C++23 join_with_view. It will be replaced with ::std::views::join_with.
.

See also
https://en.cppreference.com/w/cpp/ranges/join_with_view

◆ zip

using seqan3::views::zip = typedef seqan::stl::views::zip

A view adaptor that takes several views and returns tuple-like values from every i-th element of each view.

This entity is not part of the SeqAn API. Do not rely on it in your applications. This is a implementation of the C++23 zip_view. It will be replaced with std::views::zip.
.

See also
https://en.cppreference.com/w/cpp/ranges/zip_view

Variable Documentation

◆ convert

template<typename out_t >
constexpr auto seqan3::views::convert
inlineconstexpr

A view that converts each element in the input range (implicitly or via static_cast).

Template Parameters
urng_tThe type of the range being processed. See below for requirements. [template parameter is omitted in pipe notation]
Parameters
[in]urangeThe range being processed. [parameter is omitted in pipe notation]
Returns
A range of converted elements. See below for the properties of the returned range.

Header File

#include <seqan3/utility/views/convert.hpp>

View properties

Concepts and traits urng_t (underlying range type) rrng_t (returned range type)
std::ranges::input_range required preserved
std::ranges::forward_range preserved
std::ranges::bidirectional_range preserved
std::ranges::random_access_range preserved
std::ranges::contiguous_range lost¹
std::ranges::viewable_range required guaranteed
std::ranges::view guaranteed
std::ranges::sized_range preserved
std::ranges::common_range preserved
std::ranges::output_range lost¹
seqan3::const_iterable_range preserved
std::ranges::range_reference_t seqan3::convertible_to<out_t> out_t

¹ These are preserved if out_t is the same as std::ranges::range_reference_t<urng_t>, i.e. no conversion takes place.

See the views submodule documentation for detailed descriptions of the view properties.

Example

Convert from int to bool:

// SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin
// SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik
// SPDX-License-Identifier: CC0-1.0
#include <ranges>
#include <vector>
int main()
{
// convert from int to bool
std::vector<int> vec{7, 5, 0, 5, 0, 0, 4, 8, -3};
// pipe notation
seqan3::debug_stream << (vec | seqan3::views::convert<bool>) << '\n'; // [1,1,0,1,0,0,1,1,1]
// combinability
seqan3::debug_stream << (vec | seqan3::views::convert<bool> | std::views::reverse) << '\n'; // [1,1,1,0,0,1,0,1,1]
// function notation and immediate conversion to vector again
auto bool_vec = seqan3::views::convert<bool>(vec) | seqan3::ranges::to<std::vector<bool>>();
seqan3::debug_stream << std::boolalpha << (bool_vec == std::vector<bool>{1, 1, 0, 1, 0, 0, 1, 1, 1})
<< '\n'; // true
}
Provides seqan3::views::convert.

Convert from seqan3::dna15 to seqan3::dna5:

// SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin
// SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik
// SPDX-License-Identifier: CC0-1.0
int main()
{
using namespace seqan3::literals;
seqan3::dna15_vector vec2{"ACYGTN"_dna15};
seqan3::debug_stream << (vec2 | seqan3::views::convert<seqan3::dna5>) << '\n'; // ACNGTN
}
Provides seqan3::dna15, container aliases and string literals.
Provides seqan3::dna5, container aliases and string literals.

This entity is not part of the SeqAn API. Do not rely on it in your applications.

◆ elements

template<auto index>
constexpr auto seqan3::views::elements
inlineconstexpr

A view calling get on each element in a range.

Template Parameters
size_tThe type of the range being processed. See below for requirements. [template parameter is omitted in pipe notation]
indexThe index to get.
Parameters
[in]urangeThe range being processed. [parameter is omitted in pipe notation]
Returns
A range of elements where every element is the result of calling get<index> on the underlying element. See below for the properties of the returned range.
See also
https://en.cppreference.com/w/cpp/ranges/elements_view

Header File

#include <seqan3/utility/views/elements.hpp>

This view may be used instead of std::view::elements when the underlying range contains seqan3 types, e.g. seqan3::qualified.

View properties

Concepts and traits urng_t (underlying range type) rrng_t (returned range type)
std::ranges::input_range required preserved
std::ranges::forward_range preserved
std::ranges::bidirectional_range preserved
std::ranges::random_access_range preserved
std::ranges::contiguous_range lost
std::ranges::viewable_range required preserved
std::ranges::view preserved
std::ranges::sized_range preserved
std::ranges::common_range preserved
std::ranges::output_range preserved
seqan3::const_iterable_range preserved
std::ranges::range_reference_t seqan3::tuple_like std::tuple_element_t<index, std::ranges::range_reference_t<urng_t>>

See the views submodule documentation for detailed descriptions of the view properties.

Example

// SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin
// SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik
// SPDX-License-Identifier: CC0-1.0
#include <vector>
#include <seqan3/alphabet/quality/aliases.hpp> // includes seqan3::dna4q
int main()
{
using namespace seqan3::literals;
// Create a vector of dna4 quality composite alphabet.
{'C'_dna4, '1'_phred42},
{'G'_dna4, '2'_phred42},
{'T'_dna4, '3'_phred42}};
seqan3::debug_stream << (qv | seqan3::views::elements<0> | seqan3::views::to_char) << '\n'; // Prints [A,C,G,T]
seqan3::debug_stream << (qv | seqan3::views::elements<1> | seqan3::views::to_char) << '\n'; // Prints [!,",#,$]
}
Provides aliases for qualified.
Provides seqan3::views::elements.
auto const to_char
A view that calls seqan3::to_char() on each element in the input range.
Definition to_char.hpp:60
Provides seqan3::phred42 quality scores.
Provides seqan3::views::to_char.

This entity is experimental and subject to change in the future. Experimental since version 3.1.

◆ interleave

constexpr auto seqan3::views::interleave
inlineconstexpr

A view that interleaves a given range into another range at regular intervals.

Template Parameters
urng_tThe type of the range being processed.
inserted_rng_tThe type of the range being inserted.
Parameters
[in]urangeThe range being processed.
[in]inserted_rangeThe range being inserted.
[in]step_sizeA value of size_type which indicates the interval to insert the inserted_range.
Returns
A range with the second range inserted at regular intervals. See below for properties of said range.

Header File

#include <seqan3/utility/views/interleave.hpp>

This view can be used to insert one range into another range at regular intervals. It behaves essentially like | std::views::chunk(step_size) | seqan3::views::join_with(inserted_range) except that for input that models std::ranges::random_access_range and std::ranges::sized_range a more efficient data structure is returned (otherwise it returns exactly the above combination of views).

View properties

Concepts and traits urng_t (underlying range type) rrng_t (returned range type)
std::ranges::input_range required preserved
std::ranges::forward_range required preserved
std::ranges::bidirectional_range required preserved
std::ranges::random_access_range required preserved
std::ranges::contiguous_range lost
std::ranges::viewable_range required guaranteed
std::ranges::view guaranteed
std::ranges::sized_range required preserved
std::ranges::common_range preserved
std::ranges::output_range preserved
seqan3::const_iterable_range preserved
std::ranges::range_reference_t std::ranges::range_reference_t<urng_t>

If above requirements are not met, this adaptor forwards to | seqan3::views::chunk(step_size) | seqan3::views::join_with(inserted_range) which returns a view with the following properties:

Concepts and traits urng_t (underlying range type) rrng_t (returned range type)
std::ranges::input_range required preserved
std::ranges::forward_range required lost
std::ranges::bidirectional_range lost
std::ranges::random_access_range lost
std::ranges::contiguous_range lost
std::ranges::viewable_range required guaranteed
std::ranges::view guaranteed
std::ranges::sized_range lost
std::ranges::common_range lost
std::ranges::output_range lost
seqan3::const_iterable_range lost
std::ranges::range_reference_t std::ranges::range_value_t<urng_t>
  • urng_t is the type of the range modified by this view (input).
  • rrng_t is the type of the range returned by this view.

See the views submodule documentation for detailed descriptions of the view properties.

Example

// SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin
// SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik
// SPDX-License-Identifier: CC0-1.0
#include <string>
int main()
{
std::string u{"FOOBARBAXBAT"};
std::string i{"in"};
size_t s = 3;
auto v = u | seqan3::views::interleave(s, i);
seqan3::debug_stream << v << '\n'; // prints FOOinBARinBAXinBAT
}
constexpr auto interleave
A view that interleaves a given range into another range at regular intervals.
Definition interleave.hpp:375
Provides seqan3::views::interleave.

This entity is experimental and subject to change in the future. Experimental since version 3.1.

◆ repeat

constexpr detail::repeat_fn seqan3::views::repeat
inlineconstexpr

A view factory that repeats a given value infinitely.

Template Parameters
value_tThe type of value to repeat wrapped in a std::views::single; must model std::copy_constructible.
Parameters
[in]valueThe value to repeat.
Returns
An infinite range over value.

Header File

#include <seqan3/utility/views/repeat.hpp>

View properties

This view is source-only, it can only be at the beginning of a pipe of range transformations.

Concepts and traits rrng_t (returned range type)
std::ranges::input_range guaranteed
std::ranges::forward_range guaranteed
std::ranges::bidirectional_range guaranteed
std::ranges::random_access_range guaranteed
std::ranges::contiguous_range
std::ranges::viewable_range guaranteed
std::ranges::view guaranteed
std::ranges::sized_range
std::ranges::common_range
std::ranges::output_range guaranteed
seqan3::const_iterable_range guaranteed
std::ranges::range_reference_t std::remove_reference_t<value_t> &

See the views submodule documentation for detailed descriptions of the view properties.

Attention
The given value to repeat is always copied into the range.

Example

// SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin
// SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik
// SPDX-License-Identifier: CC0-1.0
#include <ranges>
int main()
{
auto v = seqan3::views::repeat('A');
seqan3::debug_stream << *std::ranges::begin(v) << '\n'; // prints 'A'
seqan3::debug_stream << v[12355] << '\n'; // also prints 'A'. It always prints 'A'
v[1345] = 'C';
// Now it always prints 'C'
seqan3::debug_stream << *std::ranges::begin(v) << '\n'; // prints 'C'
seqan3::debug_stream << v[12355] << '\n'; // prints 'C'
}
T begin(T... args)
constexpr detail::repeat_fn repeat
A view factory that repeats a given value infinitely.
Definition repeat.hpp:344
Provides the seqan3::views::repeat.

◆ repeat_n

constexpr auto seqan3::views::repeat_n
inlineconstexpr

A view factory that repeats a given value n times.

Template Parameters
value_tThe type of value to repeat; must be std::copy_constructible.
Parameters
[in]valueThe value to repeat.
[in]countThe number of times to repeat value.
Returns
A range of size count, where each element equals value.

Header File

#include <seqan3/utility/views/repeat_n.hpp>

View properties

This view is source-only, it can only be at the beginning of a pipe of range transformations.

Concepts and traits rrng_t (returned range type)
std::ranges::input_range guaranteed
std::ranges::forward_range guaranteed
std::ranges::bidirectional_range guaranteed
std::ranges::random_access_range guaranteed
std::ranges::contiguous_range
std::ranges::viewable_range guaranteed
std::ranges::view guaranteed
std::ranges::sized_range guaranteed
std::ranges::common_range
std::ranges::output_range guaranteed
seqan3::const_iterable_range guaranteed
std::ranges::range_reference_t std::remove_reference_t<value_t> &

See the views submodule documentation for detailed descriptions of the view properties.

Attention
The given value to repeat is always copied into the range.

Example

// SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin
// SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik
// SPDX-License-Identifier: CC0-1.0
#include <ranges>
#include <string>
int main()
{
seqan3::debug_stream << v.size() << '\n'; // prints 5
seqan3::debug_stream << v << '\n'; // prints ["foo", "foo", "foo", "foo", "foo"]
v[0] = std::string{"foobar"};
// Now it always prints "foobar"
seqan3::debug_stream << *std::ranges::begin(v) << '\n'; // prints "foobar"
seqan3::debug_stream << v.size() << '\n'; // prints 5; Note: the size cannot be changed anymore
}
constexpr auto repeat_n
A view factory that repeats a given value n times.
Definition repeat_n.hpp:88
Provides seqan3::views::repeat_n.

◆ slice

constexpr auto seqan3::views::slice
inlineconstexpr

A view adaptor that returns a half-open interval on the underlying range.

Template Parameters
urng_tThe type of the range being processed. See below for requirements. [template parameter is omitted in pipe notation]
Parameters
[in]urangeThe range being processed. [parameter is omitted in pipe notation]
[in]begin_posThe beginning of the interval (index of first element returned).
[in]end_posThe end of the interval (index behind the last element returned).
Returns
Up to end_pos - begin_pos elements of the underlying range.
Exceptions
std::invalid_argumentIf end_pos < begin_pos.

Header File

#include <seqan3/utility/views/slice.hpp>

View properties

Concepts and traits urng_t (underlying range type) rrng_t (returned range type)
std::ranges::input_range required preserved
std::ranges::forward_range preserved
std::ranges::bidirectional_range preserved
std::ranges::random_access_range preserved
std::ranges::contiguous_range preserved
std::ranges::viewable_range required guaranteed
std::ranges::view guaranteed
std::ranges::sized_range preserved
std::ranges::common_range preserved
std::ranges::output_range preserved
seqan3::const_iterable_range preserved
std::ranges::range_reference_t std::ranges::range_reference_t<urng_t>

See the views submodule documentation for detailed descriptions of the view properties.

This adaptor is a combination of std::views::drop and std::views::take.

If begin_pos is larger than the size of the underlying range an empty range is returned. If end_pos is larger than the size of the underlying range less elements are returned.

If end_pos < begin_pos an exception of type std::invalid_argument is thrown.

Return type

urng_t (underlying range type) rrng_t (returned range type)
std::basic_string const & or std::basic_string_view std::basic_string_view
std::ranges::borrowed_range && std::ranges::sized_range && std::ranges::contiguous_range std::span
std::ranges::borrowed_range && std::ranges::sized_range && std::ranges::random_access_range std::ranges::subrange
else implementation defined type

The adaptor returns exactly the type specified above.

Complexity

Construction of the returned view is in \( O(begin\_pos) \) for some views, see std::views::drop.

Example

// SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin
// SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik
// SPDX-License-Identifier: CC0-1.0
#include <ranges> // provides std::views::reverse
#include <string>
#include <seqan3/utility/views/slice.hpp> // provides views::slice
int main()
{
std::string s{"foobar"};
auto v = s | seqan3::views::slice(1, 4);
seqan3::debug_stream << v << '\n'; // "oob"
auto v2 = s | std::views::reverse | seqan3::views::slice(1, 4);
seqan3::debug_stream << v2 << '\n'; // "abo"
}
constexpr auto slice
A view adaptor that returns a half-open interval on the underlying range.
Definition slice.hpp:175
Provides seqan3::views::slice.
Hide me