Loading...
Searching...
No Matches
repeat.hpp
Go to the documentation of this file.
// SPDX-FileCopyrightText: 2006-2025 Knut Reinert & Freie Universität Berlin
// SPDX-FileCopyrightText: 2016-2025 Knut Reinert & MPI für molekulare Genetik
// SPDX-License-Identifier: BSD-3-Clause
#pragma once
#include <algorithm>
#include <ranges>
#include <seqan3/core/detail/iterator_traits.hpp>
#include <seqan3/core/range/detail/random_access_iterator.hpp>
#include <seqan3/core/range/type_traits.hpp>
namespace seqan3::detail
{
// ---------------------------------------------------------------------------------------------------------------------
// repeat_view class
// ---------------------------------------------------------------------------------------------------------------------
template <std::copy_constructible value_t>
class repeat_view : public std::ranges::view_interface<repeat_view<value_t>>
{
private:
using base_t = std::ranges::view_interface<repeat_view<value_t>>;
using sentinel_type = std::default_sentinel_t;
using single_value_t = decltype(std::views::single(std::declval<value_t>()));
using value_type = std::remove_reference_t<value_t>;
using reference = value_type &;
using const_reference = value_type const &;
using difference_type = ptrdiff_t;
template <typename parent_type>
class basic_iterator;
using iterator = basic_iterator<repeat_view>;
using const_iterator = basic_iterator<repeat_view const>;
template <typename range_type, template <typename...> typename derived_t_template, typename... args_t>
friend class detail::random_access_iterator_base;
public:
repeat_view() = default;
repeat_view(repeat_view const &) = default;
repeat_view & operator=(repeat_view const &) = default;
repeat_view(repeat_view &&) = default;
repeat_view & operator=(repeat_view &&) = default;
~repeat_view() = default;
constexpr explicit repeat_view(value_t const & value) : single_value{value}
{}
constexpr explicit repeat_view(value_t && value) : single_value{std::move(value)}
{}
constexpr iterator begin() noexcept
{
return iterator{*this};
}
constexpr const_iterator begin() const noexcept
{
return const_iterator{*this};
}
constexpr sentinel_type end() noexcept
{
return {};
}
constexpr sentinel_type end() const noexcept
{
return {};
}
constexpr const_reference operator[](difference_type const SEQAN3_DOXYGEN_ONLY(n)) const noexcept
{
return *single_value.begin();
}
constexpr reference operator[](difference_type const SEQAN3_DOXYGEN_ONLY(n)) noexcept
{
return *single_value.begin();
}
private:
single_value_t single_value;
};
template <std::copy_constructible value_t>
template <typename parent_type>
class repeat_view<value_t>::basic_iterator : public detail::random_access_iterator_base<parent_type, basic_iterator>
{
using base_t = detail::random_access_iterator_base<parent_type, basic_iterator>;
using typename base_t::position_type;
public:
using typename base_t::difference_type;
using typename base_t::value_type;
using typename base_t::reference;
using typename base_t::pointer;
using typename base_t::iterator_category;
basic_iterator() = default;
basic_iterator(basic_iterator const &) = default;
basic_iterator & operator=(basic_iterator const &) = default;
basic_iterator(basic_iterator &&) = default;
basic_iterator & operator=(basic_iterator &&) = default;
~basic_iterator() = default;
explicit constexpr basic_iterator(parent_type & host) noexcept : base_t{host}
{}
template <typename parent_type2>
requires std::is_const_v<parent_type> && (!std::is_const_v<parent_type2>)
&& std::is_same_v<std::remove_const_t<parent_type>, parent_type2>
constexpr basic_iterator(basic_iterator<parent_type2> const & rhs) noexcept : base_t{rhs}
{}
constexpr bool operator==(basic_iterator const & rhs) const noexcept
{
return base_t::operator==(rhs);
}
constexpr bool operator!=(basic_iterator const & rhs) const noexcept
{
return !(*this == rhs);
}
constexpr bool operator==(std::default_sentinel_t const &) const noexcept
{
return false;
}
constexpr bool operator!=(std::default_sentinel_t const &) const noexcept
{
return true;
}
friend constexpr bool operator==(std::default_sentinel_t const &, basic_iterator const &) noexcept
{
return false;
}
friend constexpr bool operator!=(std::default_sentinel_t const &, basic_iterator const &) noexcept
{
return true;
}
};
// ---------------------------------------------------------------------------------------------------------------------
// repeat (factory)
// ---------------------------------------------------------------------------------------------------------------------
struct repeat_fn
{
template <std::copy_constructible value_type>
constexpr auto operator()(value_type && value) const
{
return detail::repeat_view{std::forward<value_type>(value)};
}
};
} // namespace seqan3::detail
namespace seqan3::views
{
inline constexpr detail::repeat_fn repeat{};
} // namespace seqan3::views
algorithm
type_traits.hpp
Provides various transformation traits used by the range module.
std::declval
T declval(T... args)
std::forward
T forward(T... args)
seqan3::views::repeat
constexpr detail::repeat_fn repeat
A view factory that repeats a given value infinitely.
Definition repeat.hpp:344
std::is_const_v
T is_const_v
std::is_same_v
T is_same_v
iterator_traits.hpp
Provides various transformation traits for use on iterators.
seqan3::views
The SeqAn namespace for views.
Definition char_strictly_to.hpp:19
std::rel_ops::operator!=
T operator!=(T... args)
random_access_iterator.hpp
Provides the seqan3::detail::random_access_iterator class.
Hide me