std::ranges...ke_view::end(3)
π
std::ranges::take_view::end π
manual vibe: C++ Standard Libary, section 3 β yes the header really spells it like that, and we're keeping the lore. this page is the C++20 take_view::end situation, bestie.
πΈ NAME πΈ
std::ranges::take_view::end β okay so this is literally the end() member of std::ranges::take_view, and the NAME line is just the same thing twice like a little echo. iconic.
β¨ SYNOPSIS β¨
constexpr auto end() requires (!__SimpleView<V>); (1)
(since C++20)
constexpr auto end() const requires ranges::range<const V>; (2)
(since C++20)
π¦ DESCRIPTION π¦
Okay so end() gives you back a sentinel or an iterator that represents the end of the take_view. The end of the take_view is either one past the count-th element in the underlying range, or the end of the underlying range if the latter has less than count elements. no cap.
- Returns a
take_view::/*sentinel*/<false>, astd::default_sentinel_t, or aranges::iterator_t<V>. - Returns a
take_view::/*sentinel*/<true>, astd::default_sentinel_t, or aranges::iterator_t<const V>.
cute caveat: overload (1) does not participate in overload resolution ifVis a simple view β that is, ifVandconst Vare views with the same iterator and sentinel types. periodt.
π«Ά PARAMETERS π«Ά
(none) β literally no parameters, bestie. zero. the void is cute.
π₯ RETURN VALUE π₯
The result depends on the concepts satisfied by the possibly const-qualified underlying view type Base_, that is V (for overload (1)) or const V (for overload (2)).
Let base_ be the underlying view.
- If the underlying view satisfies
sized_rangeandrandom_access_range: it returnsranges::begin(base_) + ranges::range_difference_t<Base_>(this->size()). - If the underlying view satisfies
sized_rangebut notrandom_access_range: it returnsstd::default_sentinel. - If the underlying view does not satisfy
sized_range: overload (1) returns1) /*sentinel*/<false>{ranges::end(base_)}, and overload (2) returns2) /*sentinel*/<true>{ranges::end(base_)}.
iykyk: that's the whole table from the page, just with better vibes and every cell kept intact π
π EXAMPLE π
// Run this code
#include <iostream>
#include <iterator>
#include <list>
#include <ranges>
#include <type_traits>
int main()
{
const auto list1 = {3, 1, 4, 1, 5};
const auto seq1 = list1 | std::views::take(4);
static_assert(std::ranges::sized_range<decltype(seq1)> &&
std::ranges::random_access_range<decltype(seq1)> &&
std::is_same_v<decltype(seq1.end()),
decltype(list1.end())>);
for (auto it = seq1.begin(); it != seq1.end(); ++it)
std::cout << *it << ' ';
std::cout << '\n';
std::list list2 = {2, 7, 1, 8, 2};
const auto seq2 = list2 | std::views::take(4);
static_assert(std::ranges::sized_range<decltype(seq2)> &&
not std::ranges::random_access_range<decltype(seq2)>
&&
std::is_same_v<decltype(seq2.end()),
std::default_sentinel_t>);
for (auto it = seq2.begin(); it != std::default_sentinel; ++it)
std::cout << *it << ' ';
std::cout << '\n';
}
π OUTPUT π
3 1 4 1
2 7 1 8
π DEFECT REPORTS π
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
P2393R1β applied toC++20; behavior as published: implicit conversions between signed and unsigned integer-class types might fail; correct behavior: made explicit.
π SEE ALSO π
begin(C++20) β returns an iterator to the beginning (public member function)counted_iterator(C++20) β iterator adaptor that tracks the distance to the end of the range (class template)operator==(C++20) β compares a sentinel with an iterator returned fromtake_view::begin(function)
okay bye bestie π this page came from http://cppreference.com, version/date 2024.06.10, and yes that's the footer energy folded into a cute little sign-off. mwah π
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms