- bookworm 6.02.02-1
- testing 6.06.02-1
- unstable 6.06.02-1
- experimental 6.07.01-1
FBB::Reverse(3bobcat) | for-loop reverse iterators | FBB::Reverse(3bobcat) |
NAME¶
FBB::Reverse - A class template offering reverse iterators
SYNOPSIS¶
#include <bobcat/reverse>
DESCRIPTION¶
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.
NAMESPACE¶
FBB
All constructors, members, operators and manipulators, mentioned in this
man-page, are defined in the namespace FBB.
INHERITS FROM¶
-
REVERSE FUNCTIONS¶
- o
- reverse(Type &object):
returns a Reverse object offering reverse iterators to the data range of object, which must support begin and end members. If Type is a constant type, then Reverse’s begin and end members return const_reverse_iterators, otherwise reverse_iterators are returned; - o
- reverse(Type (&array)[size]):
returns a Reverse object offering reverse iterators to the reversed range of elements of array. If Type is a constant type, then Reverse’s begin and end members return const_reverse_iterators, otherwise reverse_iterators are returned; - o
- reverse(Type *array, size_t size):
returns a Reverse object offering reverse iterators to the reversed range of elements of array to array + size. If Type is a constant type, then Reverse’s begin and end members return const_reverse_iterators, otherwise reverse_iterators are returned.
EXAMPLE¶
#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’); }
FILES¶
bobcat/reverse - defines the class interfaces and declares the reverse functions.
SEE ALSO¶
bobcat(7), ranger(3bobcat)
BUGS¶
None Reported.
BOBCAT PROJECT FILES¶
- o
- https://fbb-git.gitlab.io/bobcat/: gitlab project page;
Debian Bobcat project files:
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).
2005-2025 | libbobcat-dev_6.07.01 |