BioC++ core-0.7.0
The Modern C++ libraries for Bioinformatics.
 
Loading...
Searching...
No Matches
repeat_n.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 <concepts>
17
20
21namespace bio::ranges::detail
22{
23
29struct repeat_n_fn
30{
37 template <typename value_t>
38 constexpr auto operator()(value_t && value, size_t const count) const
39 {
40 static_assert(std::constructible_from<std::remove_cvref_t<value_t>, value_t>,
41 "The value passed to repeat_n must be (1) an lvalue and its type copy constructible; or "
42 "(2) an rvalue and its type move constructible.");
43
44 return views::repeat(std::forward<value_t>(value)) | views::take_exactly(count);
45 }
46};
47
48} // namespace bio::ranges::detail
49
50namespace bio::ranges::views
51{
52
98inline constexpr auto repeat_n = detail::repeat_n_fn{};
100
101} // namespace bio::ranges::views
constexpr auto repeat_n
A view factory that repeats a given value n times.
Definition: repeat_n.hpp:98
constexpr auto take_exactly
A view adaptor that returns the first size elements from the underlying range (or less if the underly...
Definition: take_exactly.hpp:78
constexpr detail::repeat_fn repeat
A view factory that repeats a given value infinitely.
Definition: repeat.hpp:314
The BioC++ namespace for views.
Provides the views::repeat_view.
Provides bio::views::take_exactly and bio::views::take_exactly_or_throw.