File: ranger.yo

package info (click to toggle)
bobcat 6.02.02-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 13,960 kB
  • sloc: cpp: 18,954; fortran: 5,617; makefile: 2,787; sh: 659; perl: 401; ansic: 26
file content (100 lines) | stat: -rw-r--r-- 4,381 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
includefile(include/header)

COMMENT(manpage, section, releasedate, archive, short name)
manpage(FBB::Ranger)(3bobcat)(_CurYrs_)(libbobcat-dev__CurVers_)
                    (for-loop iterators)

manpagename(FBB::Ranger)(generalizes ranges for range-based for-loops)

manpagesynopsis()
    bf(#include <bobcat/ranger>)nl()

manpagedescription()

The tt(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 tt(begin) and tt(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.

tt(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.

tt(Ranger) is a class template requiring one template type parameter:
tt(Iterator), an iterator or pointer type reaching the data when dereferenced.

tt(Ranger)'s users don't have to specify tt(Ranger)'s template type. The
function template tt(ranger) returns the appropriate tt(Ranger) object.

includefile(include/namespace)

manpagesection(FREE FUNCTION)
    When using the following free functions, any (subrange) of iterators or
pointers can be used. With iterators subranges of em(reverse iterators) can
also be specified. The bf(EXAMPLE) section below illustrates the use of the
tt(ranger) function templates.
    itemization(
    itb(Ranger<Iterator> ranger(Iterator &&begin, Iterator &&end))
        this function template returns a tt(Ranger) object for the (sub)range
        defined by two (reverse) iterators;
    itb(Ranger<Iterator> ranger(Iterator &&begin, size_t count))
        this function template returns a tt(Ranger) object for the (sub)range
        defined by the (reverse) iterator range tt(begin) and tt(begin +
        count);
    itb(Ranger<Data *> ranger(Data *begin, Data *end))
        this function template returns a tt(Ranger) object for the (sub)range
        defined by the two pointers tt(begin) and tt(end);
    itb(Ranger<Data *> ranger(Data *begin, size_t count))
        this function template returns a tt(Ranger) object for the (sub)range
        defined by the two pointers tt(begin) and tt(begin + count).
    )

manpagesection(CONSTRUCTORS)
    Below, tt(Iterator) refers to the tt(Ranger) class template's type
parameter. Although named 'Iterator' it can also be a pointer to some data
type (e.g., tt(std::string *)).
    itemization(
    itb(Ranger(Iterator const &begin, Iterator const &end))
        A tt(Ranger) object can be passed as range-specifier in a range-based
for-loop. All elements defined by the range will subsequently be visited by
the range-based for-loop.
    )

    Copy and move constructors (and assignment operators) are available.

manpagesection(MEMBER FUNCTIONS)
    itemization(
    itb(Iterator const &begin() const)
        returns (a copy of) the tt(begin) iterator passed to the tt(Ranger)'s
constructor. Note that if tt(Iterator) was a pointer type (like tt(int *)) the
data to which the iterator returned by tt(begin()) can actually be modified,
as the member's return type (using tt(int *) for tt(Iterator)) becomes tt(int
* const &), so a reference to a constant pointer to an tt(int). This is
perfectly OK: if the data themselves should be immutable, then the data type
must be defined as tt(int const), which is automatically the case when passing
tt(int const *) data. See the bf(EXAMPLE) section for an illustration.
    itb(Iterator const &end() const)
        returns (a copy of) the tt(end) iterator passed to the tt(Ranger)'s
constructor.
    )
    If reverse iterators are passed to tt(Ranger)'s constructor, then
    the tt(begin) and tt(end) members return em(reverse iterators). Since
the intended use of tt(Ranger) objects is to define a range for range-base
for-loops, members like tt(rbegin) and tt(rend) can be omitted from
tt(Ranger).

manpagesection(EXAMPLE)
    verbinclude(../../ranger/driver/driver.cc)

manpagefiles()
    em(bobcat/ranger) - defines the class interface

manpageseealso()
    bf(bobcat)(7), bf(reverse)(3bobcat)

manpagebugs()
    None Reported.

includefile(include/trailer)