SeqAn3 3.4.0-rc.1
The Modern C++ library for sequence analysis.
Loading...
Searching...
No Matches
seqan3::detail::pairwise_combine_view< underlying_range_type > Class Template Reference

Generates all pairwise combinations of the elements in the underlying range. More...

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

+ Inheritance diagram for seqan3::detail::pairwise_combine_view< underlying_range_type >:

Classes

class  basic_iterator
 The forward declared iterator type for pairwise_combine_view. More...
 

Public Member Functions

Constructors, destructor and assignment
 pairwise_combine_view ()=default
 Defaulted.
 
 pairwise_combine_view (pairwise_combine_view const &)=default
 Defaulted.
 
 pairwise_combine_view (pairwise_combine_view &&)=default
 Defaulted.
 
pairwise_combine_viewoperator= (pairwise_combine_view const &)=default
 Defaulted.
 
pairwise_combine_viewoperator= (pairwise_combine_view &&)=default
 Defaulted.
 
 ~pairwise_combine_view ()=default
 Defaulted.
 
constexpr pairwise_combine_view (underlying_range_type range)
 Constructs from a view.
 
template<typename other_range_t >
requires (!std::same_as<std::remove_cvref_t<other_range_t>, pairwise_combine_view>) && std::ranges::viewable_range<other_range_t> && std::constructible_from<underlying_range_type, std::ranges::ref_view<std::remove_reference_t<other_range_t>>>
constexpr pairwise_combine_view (other_range_t &&range)
 Constructs from a view.
 
Iterators
constexpr iterator begin () noexcept
 Returns an iterator to the first element of the range.
 
constexpr const_iterator begin () const noexcept
 Returns an iterator to the first element of the range.
 
constexpr iterator end () noexcept
 Returns an iterator to the element following the last element of the range.
 
constexpr const_iterator end () const noexcept
 Returns an iterator to the element following the last element of the range.
 
Capacity
constexpr auto size () const noexcept
 Computes the size based on the size of the underlying range.
 

Private Types

Associated types
using iterator = basic_iterator< underlying_range_type >
 The iterator type.
 
using const_iterator = transformation_trait_or_t< std::type_identity< basic_iterator< underlying_range_type const > >, void >
 The const iterator type. Evaluates to void if the underlying range is not const iterable.
 

Private Attributes

std::ranges::iterator_t< underlying_range_type > back_iterator {}
 The cached iterator pointing to the last element of the underlying range.
 
underlying_range_type u_range
 The underling range.
 

Detailed Description

template<std::ranges::view underlying_range_type>
requires std::ranges::forward_range<underlying_range_type> && std::ranges::common_range<underlying_range_type>
class seqan3::detail::pairwise_combine_view< underlying_range_type >

Generates all pairwise combinations of the elements in the underlying range.

Template Parameters
underlying_range_typeThe type of the underlying range; must model std::ranges::view, std::ranges::forward_range and std::ranges::common_range.

This view will provide a convenient way to iterate over all pairwise combinations of the elements of the underlying range (in no defined order). A underlying range with n elements will therefore have n choose 2 possible combinations.

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>
int main()
{
std::vector vec{'a', 'b', 'c', 'a'};
for (auto res : vec | seqan3::views::pairwise_combine)
{
seqan3::debug_stream << res << '\n';
}
// Possible Output:
// (a,b)
// (a,c)
// (a,a)
// (b,c)
// (b,a)
// (c,a)
}
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
The main SeqAn3 namespace.
Definition aligned_sequence_concept.hpp:26
Provides seqan3::views::pairwise_combine.

Constructor & Destructor Documentation

◆ pairwise_combine_view() [1/2]

template<std::ranges::view underlying_range_type>
constexpr seqan3::detail::pairwise_combine_view< underlying_range_type >::pairwise_combine_view ( underlying_range_type  range)
inlineexplicitconstexpr

Constructs from a view.

Parameters
[in]rangeThe underlying range to be wrapped. Of type underlying_range_type.

During construction the iterator pointing to the last element of the view is cached (not the end of the range). This optimises the call to end if the underlying range models only forward_range. Otherwise the call to end will be linear in the number of elements of the underlying range.

Attention
This view cannot be chained immediately after an infinite range, because upon construction it will take forever to reach the last element of the view.

Complexity

Constant if underlying_range_type models std::ranges::bidirectional_range, otherwise linear.

◆ pairwise_combine_view() [2/2]

template<std::ranges::view underlying_range_type>
template<typename other_range_t >
requires (!std::same_as<std::remove_cvref_t<other_range_t>, pairwise_combine_view>) && std::ranges::viewable_range<other_range_t> && std::constructible_from<underlying_range_type, std::ranges::ref_view<std::remove_reference_t<other_range_t>>>
constexpr seqan3::detail::pairwise_combine_view< underlying_range_type >::pairwise_combine_view ( other_range_t &&  range)
inlineexplicitconstexpr

Constructs from a view.

Template Parameters
other_range_tThe type of the range to be wrapped with seqan3::detail::pairwise_combine_view; must model std::ranges::viewable_range and underlying_range_type must be constructible with other_range wrapped in std::views::all.
Parameters
[in]rangeThe underlying range to be wrapped.

During construction the iterator pointing to the last element of the view is cached (not the end of the range). This optimises the call to end if the underlying range models only forward_range. Otherwise the call to end will be linear in the number of elements of the underlying range.

Attention
This view cannot be chained immediately after an infinite range, because upon construction it will take forever to reach the last element of the view.

Complexity

Constant if other_range_t models std::ranges::bidirectional_range, otherwise linear.

Member Function Documentation

◆ begin() [1/2]

template<std::ranges::view underlying_range_type>
constexpr const_iterator seqan3::detail::pairwise_combine_view< underlying_range_type >::begin ( ) const
inlineconstexprnoexcept

Returns an iterator to the first element of the range.

Returns
Iterator to the first element.

If the range is empty, the returned iterator will be equal to end().

Complexity

Constant.

Exceptions

No-throw guarantee.

◆ begin() [2/2]

template<std::ranges::view underlying_range_type>
constexpr iterator seqan3::detail::pairwise_combine_view< underlying_range_type >::begin ( )
inlineconstexprnoexcept

Returns an iterator to the first element of the range.

Returns
Iterator to the first element.

If the range is empty, the returned iterator will be equal to end().

Complexity

Constant.

Exceptions

No-throw guarantee.

◆ end() [1/2]

template<std::ranges::view underlying_range_type>
constexpr const_iterator seqan3::detail::pairwise_combine_view< underlying_range_type >::end ( ) const
inlineconstexprnoexcept

Returns an iterator to the element following the last element of the range.

Returns
Iterator to the end.

This element acts as a placeholder; attempting to dereference it results in undefined behaviour.

Complexity

Constant.

Exceptions

No-throw guarantee.

◆ end() [2/2]

template<std::ranges::view underlying_range_type>
constexpr iterator seqan3::detail::pairwise_combine_view< underlying_range_type >::end ( )
inlineconstexprnoexcept

Returns an iterator to the element following the last element of the range.

Returns
Iterator to the end.

This element acts as a placeholder; attempting to dereference it results in undefined behaviour.

Complexity

Constant.

Exceptions

No-throw guarantee.


The documentation for this class was generated from the following file:
Hide me