---
name: "reverse"
section: "3bobcat"
platform: "linux"
package: "libbobcat-dev"
version: "6.07.01-2"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/reverse/3bobcat"
---

# reverse(3bobcat)

A class template offering reverse iterators

## 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)](/ranger/3bobcat.md)) 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)](/bobcat/7.md), [**ranger**(3bobcat)](/ranger/3bobcat.md)

## BUGS

None Reported.

## BOBCAT PROJECT FILES

- o

  *https://fbb-git.gitlab.io/bobcat/*: gitlab project page;

Debian Bobcat project files:

- o

  *libbobcat6*: debian package containing the shared library, changelog and copyright note;

- o

  *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**).
