FBB::Ranger(3bobcat)
π FBB::Ranger(3bobcat) π
okay bestie, welcome to the for-loop iterators page of the bobcat manual β this one's name is literally FBB::Ranger, and she's about to make your range-based for-loops eat so much better π
β¨ NAME β¨
FBB::Ranger β bestie... it generalizes ranges for range-based for-loops. that's the whole vibe. periodt.
β¨ SYNOPSIS β¨
#include <bobcat/ranger>
β¨ DESCRIPTION β¨
so like, the Ranger class template defines ranges that you can use with range-based for-loops. the standard range-based for-loop needs, for its range-specification, an array or an iterator range β the kind containers hand you through their begin and end members. but ranges defined by a pair of pointers, or by a subrange defined by iterator expressions? nope, those literally cannot currently be used with range-based for-loops. tragic. π
Ranger fixes that. she extends the applicability of range-based for-loops by turning pairs of pointers, an initial pointer plus a pointer count, or a pair of iterators into a range that range-based for-loops can actually use. iconic behavior honestly π
Ranger is a class template, and she requires one template type parameter: Iterator β an iterator or pointer type that reaches the data when dereferenced.
and here's the slay: Ranger's users don't have to specify Ranger's template type. the function template ranger returns the appropriate Ranger object for you. you just vibe, she does the deduction β¨
β¨ NAMESPACE β¨
FBB
every constructor, member, operator and manipulator mentioned in this man-page lives in the namespace FBB. no cap.
β¨ FREE FUNCTION β¨
when you use the following free functions, you can throw in any (subrange) of iterators or pointers. with iterators, subranges of reverse iterators can also be specified. the EXAMPLE section down below shows the ranger function templates in action π¦
Ranger<Iterator> ranger(Iterator &&begin, Iterator &&end)β this function template returns aRangerobject for the (sub)range defined by two (reverse) iterators;Ranger<Iterator> ranger(Iterator &&begin, size_t count)β this function template returns aRangerobject for the (sub)range defined by the (reverse) iterator rangebeginandbegin + count;Ranger<Data *> ranger(Data *begin, Data *end)β this function template returns aRangerobject for the (sub)range defined by the two pointersbeginandend;Ranger<Data *> ranger(Data *begin, size_t count)β this function template returns aRangerobject for the (sub)range defined by the two pointersbeginandbegin + count.
β¨ CONSTRUCTORS β¨
heads up: down here, Iterator refers to the Ranger class template's type parameter. and even though she's named Iterator, she can also be a pointer to some data type (like, say, std::string *). she contains multitudes π
Ranger(Iterator const &begin, Iterator const &end)β aRangerobject can be passed as a range-specifier in a range-basedfor-loop. every element defined by the range will subsequently be visited by that range-basedfor-loop. she eats, no crumbs.
copy and move constructors (and assignment operators) are available too. π
β¨ MEMBER FUNCTIONS β¨
Iterator const &begin() constβ returns (a copy of) the begin iterator that was passed to theRanger's constructor.
okay important lil note bestie: ifIteratorwas a pointer type (likeint *), then the data that the iterator returned bybegin()points to can actually be modified. why? because the member's return type (usingint *forIterator) becomesint * const &β so, a reference to a constant pointer to an int. and that's perfectly OK!consthere is protecting the pointer, not the pointee, iykyk. if the data themselves should be immutable, then the data type must be defined asint const, which is automatically the case when you passint const *data. check theEXAMPLEsection for an illustration π
Iterator const &end() constβ returns (a copy of) the end iterator that was passed to theRanger's constructor. if reverse iterators were passed toRanger's constructor, then thebeginandendmembers return reverse iterators. and since the intended use ofRangerobjects is to define a range for range-basefor-loops, members likerbeginandrendcan be omitted fromRanger. not needed, not missed, gone girl π
β¨ EXAMPLE β¨
#include <vector>
#include <iostream>
#include <bobcat/ranger>
using namespace std;
using namespace FBB;
int main()
{
vector<int> iv {1, 2, 3, 4, 5};
// display and modify a subrange
for(auto &el: ranger(iv.rbegin() + 1, iv.rend() - 1))
cout << el++ << β β;
cout << β\nβ;
// display a reversed range
for(auto &el: ranger(iv.rbegin() + 1, iv.rend() - 1))
cout << el << β β;
cout << β\nβ;
// same: display using a count
for(auto &el: ranger(iv.rbegin() + 1, 3))
cout << el << β β;
cout << β\nβ;
int intArray[] = {1, 2, 3, 4, 5};
// display and modify elements
// in a pointer-based range
for(auto &el: ranger(intArray + 1, intArray + 3))
cout << el++ << β β;
cout << β\nβ;
// data now modified
for(auto &el: ranger(intArray + 1, intArray + 3))
cout << el << β β;
cout << β\nβ;
// using a count rather than an
// end-pointer
for(auto &el: ranger(intArray + 1, 3))
cout << el << β β;
cout << β\nβ;
int const constInts[] = {1, 2, 3, 4, 5};
// data canβt be modified
for(auto &el: ranger(constInts + 1, constInts + 3))
cout << el << β β;
cout << β\nβ;
}
β¨ FILES β¨
bobcat/rangerβ defines the class interface
β¨ SEE ALSO β¨
β¨ BUGS β¨
None Reported. (we love a clean bug list, we truly do π)
β¨ BOBCAT PROJECT FILES β¨
https://fbb-git.gitlab.io/bobcat/β gitlab project page;
Debian Bobcat project files:
libbobcat6β debian package containing the shared library, changelog and copyright note;libbobcat-devβ debian package containing the static library, headers, manual pages, and developer info;
β¨ BOBCAT β¨
Bobcat is an acronym of `Brokkenβs Own Base Classes And Templates'.
β¨ COPYRIGHT β¨
This is free software, distributed under the terms of the GNU General Public License (GPL).
β¨ AUTHOR β¨
Frank B. Brokken (f.b.brokken@rug.nl).
okay that's the whole page bestie, you're officially a Ranger girly now π§π
and before you go β this lil masterpiece ships as libbobcat-dev_6.15.01, dated 2005-2026, and it lives in section 3bobcat of the manual. mwah, go use your iterators responsibly πβ¨
π¦ where this page comes from
- ubuntu stonking: libbobcat-dev 6.15.01-1 Β· GPL-3.0-or-later WITH OpenSSL exception
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms