std::ranges::view::counted (3) - Linux Manuals
std::ranges::view::counted: std::ranges::view::counted
Command to display std::ranges::view::counted
manual in Linux: $ man 3 std::ranges::view::counted
NAME
std::ranges::view::counted - std::ranges::view::counted
Synopsis
namespace view {
inline constexpr /*unspecified*/ counted = /*unspecified*/; (since C++20)
}
A counted view presents a View of the elements of the counted range [i, n) for some iterator i and non-negative integer n.
A counted range [i, n) is the n elements starting with the element pointed to by i and up to but not including the element, if any, pointed to by the result of n applications of ++i.
If n == 0, the counted range is valid and empty. Otherwise, the counted range is only valid if n is positive, i is dereferenceable, and [++i, --n) is a valid counted range.
Formally, if E and F are expressions, and T is the type std::decay_t<decltype((E))>, then
if T models Iterator and decltype((F)) models ConvertibleTo<iter_difference_t<T>>,
if T models RandomAccessIterator, view::counted(E, F) is expression-equivalent to ranges::subrange{E, E + static_cast<std::iter_difference_t<T>>(F)}
otherwise view::counted(E, F) is expression-equivalent to ranges::subrange{std::counted_iterator{E, F}, std::default_sentinel}
otherwise, view::counted(E, F) is ill-formed.
Example
// Run this code
#include <ranges>
#include <iostream>
int main()
{
int a[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
for(int i : std::view::counted(a, 3))
std::cout << i << ' ';
}
Output:
1 2 3
See also
combines an iterator-sentinel pair into a View
subrange (class template)
counted_iterator iterator adaptor that tracks the distance to the end of the range
(class template)
(C++20)
Pages related to std::ranges::view::counted
- std::ranges::view::all,std::ranges::all_view (3) - std::ranges::view::all,std::ranges::all_view
- std::ranges::view::empty,std::ranges::empty_view (3) - std::ranges::view::empty,std::ranges::empty_view
- std::ranges::view::filter,std::ranges::filter_view (3) - std::ranges::view::filter,std::ranges::filter_view
- std::ranges::view::iota,std::ranges::iota_view (3) - std::ranges::view::iota,std::ranges::iota_view
- std::ranges::view::reverse,std::ranges::reverse_view (3) - std::ranges::view::reverse,std::ranges::reverse_view
- std::ranges::BidirectionalRange (3) - std::ranges::BidirectionalRange
- std::ranges::CommonRange (3) - std::ranges::CommonRange
- std::ranges::ContiguousRange (3) - std::ranges::ContiguousRange
- std::ranges::ForwardRange (3) - std::ranges::ForwardRange
- std::ranges::InputRange (3) - std::ranges::InputRange
- std::ranges::OutputRange (3) - std::ranges::OutputRange
- std::ranges::RandomAccessRange (3) - std::ranges::RandomAccessRange
- std::ranges::Range (3) - std::ranges::Range
- std::ranges::SizedRange,std::ranges::disable_sized_range (3) - std::ranges::SizedRange,std::ranges::disable_sized_range
- std::ranges::View,std::ranges::enable_view,std::ranges::view_base (3) - std::ranges::View,std::ranges::enable_view,std::ranges::view_base
- std::ranges::ViewableRange (3) - std::ranges::ViewableRange
- std::ranges::all_of,std::ranges::any_of,std::ranges::none_of (3) - std::ranges::all_of,std::ranges::any_of,std::ranges::none_of