FBB::Ranger(3bobcat)

Error handler
(libbobcat-dev_4.08.03-x.tar.gz)

2005-2018

NAME

FBB::Ranger - generalizes ranges for range-based for-loops

SYNOPSIS

#include <bobcat/ranger>

DESCRIPTION

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.

NAMESPACE

FBB
All constructors, members, operators and manipulators, mentioned in this man-page, are defined in the namespace FBB.

FREE FUNCTION

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.

CONSTRUCTORS

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 *). The copy and move constructors are available.

OVERLOADED OPERATORS

The copy and move assignment operators are available.

MEMBER FUNCTIONS

If reverse iterators are passed to Ranger's constructor, then the begin and end members return reverse iterators. Since the intended use of Ranger objects is to define a range for range-base for-loops, members like rbegin and rend can be omitted from Ranger.

EXAMPLE

#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';
}

FILES

bobcat/ranger - defines the class interface

SEE ALSO

bobcat(7)

BUGS

None Reported.

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