DOKK / manpages / debian 12 / libbobcat-dev / reverse.3bobcat.en
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.

-

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;
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;
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.

#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.

bobcat(7), ranger(3bobcat)

None Reported.

https://fbb-git.gitlab.io/bobcat/: gitlab project page;
bobcat_6.02.02-x.dsc: detached signature;
bobcat_6.02.02-x.tar.gz: source archive;
bobcat_6.02.02-x_i386.changes: change log;
libbobcat1_6.02.02-x_*.deb: debian package containing the libraries;
libbobcat1-dev_6.02.02-x_*.deb: debian package containing the libraries, headers and manual pages;

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