FBB::Reverse(3bobcat) | for-loop reverse iterators | FBB::Reverse(3bobcat) |
FBB::Reverse - A class template offering reverse iterators
#include <bobcat/reverse>
Not all data types offering (or implicitly providing) iterators also offer reverse_iterators. Arrays don’t, and neither do initalizer_lists. Pointers to array elements can be used instead of iterators, but arrays cannot be used in range-based for-loops. The Ranger class (cf. ranger(3bobcat)) can be used for defining begin and end members allowing the use of arrays in range-based for-loops. Using Reverse objects and data structures can be used in range-based for-loops and/or to obtain reverse-iterators to visit data elements in reversed order.
The class template Reverse, ReverseArray, and ReverseSize are normally not directly used, but are returned by the various reverse support functions. These three classes offer two members begin, returning a reverse_iterator to the end of the data range of the object passed to reverse and end returning a reverse_iterator to the beginning of the data range of the object passed to reverse.
FBB
All constructors, members, operators and manipulators, mentioned in this
man-page, are defined in the namespace FBB.
-
#include <iostream> #include <vector> #include <bobcat/reverse> using namespace std; using namespace FBB; int main() {
int intArr[] = { 1, 2, 3, 4, 5}; // arrays of known sizes
for (int value: reverse(intArr))
cout << value << ’ ’;
cout << ’\n’;
for (int value: reverse(intArr, 5)) // using specified sizes
cout << value << ’ ’;
cout << ’\n’;
int const constArr[] = { 1, 2, 3, 4, 5};// arrays with const elements
for (int value: reverse(constArr))
cout << value << ’ ’;
cout << ’\n’;
for (int value: reverse(constArr, 5)) // using specified sizes
cout << value << ’ ’;
cout << ’\n’;
for (int value: reverse(intArr, 5)) // arrays of specified sizes
cout << value << ’ ’;
cout << ’\n’;
vector<int> vi{ 1, 2, 3, 4, 5 }; // handle non-const objects
for (int value: reverse(vi))
cout << value << ’ ’;
cout << ’\n’;
vector<int> const cvi{ 1, 2, 3, 4, 5 }; // handle const objects
for (int value: reverse(cvi))
cout << value << ’ ’;
cout << ’\n’;
// handle lvalues
for (int value: reverse(initializer_list<int>{ 1, 2, 4, 8 }))
cout << value << ’ ’;
cout.put(’\n’);
// named constant objects
auto ilist = initializer_list<int>{ 1, 2, 4, 8 };
for (int value: reverse(ilist))
cout << value << ’ ’;
cout.put(’\n’); }
bobcat/reverse - defines the class interfaces and declares the reverse functions.
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-2022 | libbobcat-dev_6.02.02 |