FBB::Ranger(3bobcat) | Error handler | FBB::Ranger(3bobcat) |
FBB::Ranger - generalizes ranges for range-based for-loops
#include <bobcat/ranger>
The Ranger class template defines ranges that can be used with range-based for-loops. The standard range-based for-loop requires for its range-specificiation an array or an iterator range as offered by, e.g., containers (through their begin and end members). Ranges defined by a pair of pointers or by a subrange defined by iterator expressions cannot currently be used in combination with range-based for-loops.
Ranger extends the applicability of range-based for-loops by turning pairs of pointers, an initial pointer and a pointer count, or a pair of iterators into a range that can be used by range-based for-loops.
Ranger is a class template requiring one template type parameter: Iterator, an iterator or pointer type reaching the data when dereferenced.
Ranger’s users don’t have to specify Ranger’s template type. The function template ranger returns the appropriate Ranger object.
FBB
All constructors, members, operators and manipulators, mentioned in this
man-page, are defined in the namespace FBB.
When using the following free functions, any (subrange) of iterators or pointers can be used. With iterators subranges of reverse iterators can also be specified. The EXAMPLE section below illustrates the use of the ranger function templates.
Below, Iterator refers to the Ranger class template’s type parameter. Although named ’Iterator’ it can also be a pointer to some data type (e.g., std::string *).
Copy and move constructors (and assignment operators) are available.
#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’; }
bobcat/ranger - defines the class interface
None Reported.
Bobcat is an acronym of `Brokken’s Own Base Classes And Templates’.
This is free software, distributed under the terms of the GNU General Public License (GPL).
Frank B. Brokken (f.b.brokken@rug.nl).
2005-2020 | libbobcat-dev_5.07.00 |