std::ranges::forward_range(3)
π std::ranges::forward_range
okay so this is a page from the C++ Standard Library manual, bestie β yes, the whole lib, and this one little concept is our main character today. sit down, hydrate, let's go π«Ά
β¨ NAME β¨
std::ranges::forward_range β which is, and I cannot stress this enough, std::ranges::forward_range π« (the manpage really said "name: the name" and honestly? iconic confidence.)
πΈ SYNOPSIS πΈ
it lives right here, in the header <ranges>:
template< class T >
concept forward_range =
and this part is since C++20 β:
ranges::input_range<T> &&
std::forward_iterator<ranges::iterator_t<T>>;
π DESCRIPTION π
so like. forward_range? it's literally a refinement of range, no cap. it's the vibe check that says: when you call ranges::begin on this thing, what you get back is a model of forward_iterator. that's it. that's the whole concept. she's simple, she's precise, she ate π
β¨
think of it as: input range energy, but upgraded β you can walk through it more than once and it won't ghost you π¦
π§ EXAMPLE π§
run this code, bestie β the comments said so:
// Run this code
#include <forward_list>
#include <queue>
#include <ranges>
#include <span>
#include <stack>
#include <tuple>
const char* str{"not a forward range"};
const char str2[] = "a forward range";
static_assert(
std::ranges::forward_range<decltype("a forward range")> &&
!std::ranges::forward_range<decltype(str)> &&
std::ranges::forward_range<decltype(str2)> &&
!std::ranges::forward_range<std::stack<char>> &&
std::ranges::forward_range<std::forward_list<char>> &&
!std::ranges::forward_range<std::tuple<std::forward_list<char>>> &&
std::ranges::forward_range<std::span<char>> &&
!std::ranges::forward_range<std::queue<char>> &&
"");
int main() {}
look at all those static_asserts doing their little checks π₯Ή yes the trailing "" is in there, don't touch it, it's part of the artifact β copy it exactly character for character, okay? π₯
and int main() {} β an empty main that does absolutely nothing and still gets to be in the docs. main character energy fr fr π
π©· tiny note: thatstatic_assertblock ends with"");β keep it verbatim when you paste this. no fixing, no tidying. the manpage said what it said π
π SEE ALSO π
ngl there's no SEE ALSO section in this one β she stands alone, independent, unbothered π§ββοΈ
and that's the page!! source is http://cppreference.com, the version stamp situation is 2024.06.10, and the page answers to std::ranges::forward_range(3) πΈ love that for her, love that for you, 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