summaryrefslogtreecommitdiff
path: root/libs/range/doc/reference/semantics.qbk
blob: 335ab90d6fad482a35968f71ae7b08449b492c42 (plain)
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
[/
    Copyright 2010 Neil Groves
    Distributed under the Boost Software License, Version 1.0.
    (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
/]
[section:semantics Semantics]

[heading notation]

[table
  [[Type   ] [Object] [Describes                                ]]
  [[`X`    ] [`x`   ] [any type                                 ]]
  [[`T`    ] [`t`   ] [denotes behavior of the primary templates]]
  [[`P`    ] [`p`   ] [denotes `std::pair<iterator,iterator>`   ]]
  [[`A[sz]`] [`a`   ] [denotes an array of type `A` of size `sz`]]
  [[`Char*`] [`s`   ] [denotes either `char*` or `wchar_t*`     ]]
]

[section Metafunctions]

[table
    [[Expression] [Return type] [Complexity]]
    [
        [`range_iterator<X>::type`]
        [``
            T::iterator
            P::first_type
            A*
        ``]
        [compile time]
    ]
    [
        [`range_iterator<const X>::type`]
        [``
            T::const_iterator
            P::first_type
            const A*
        ``]
        [compile time]
    ]
    [
        [`range_value<X>::type`]
        [`boost::iterator_value<range_iterator<X>::type>::type`]
        [compile time]
    ]
    [
        [`range_reference<X>::type`]
        [`boost::iterator_reference<range_iterator<X>::type>::type`]
        [compile time]
    ]
    [
        [`range_pointer<X>::type`]
        [`boost::iterator_pointer<range_iterator<X>::type>::type`]
        [compile time]
    ]
    [
        [`range_category<X>::type`]
        [`boost::iterator_category<range_iterator<X>::type>::type`]
        [compile time]
    ]
    [
        [`range_difference<X>::type`]
        [`boost::iterator_category<range_iterator<X>::type>::type`]
        [compile time]
    ]
    [
        [`range_reverse_iterator<X>::type`]
        [`boost::reverse_iterator<range_iterator<X>::type>`]
        [compile time]
    ]
    [
        [`range_reverse_iterator<const X>::type`]
        [`boost::reverse_iterator<range_iterator<const X>::type`]
        [compile time]
    ]
    [
        [`has_range_iterator<X>::type`]
        [`mpl::true_` if `range_mutable_iterator<X>::type` is a valid expression, `mpl::false_` otherwise]
        [compile time]
    ]
    [
        [`has_range_const_iterator<X>::type`]
        [`mpl::true_` if `range_const_iterator<X>::type` is a valid expression, `mpl::false_` otherwise]
        [compile time]
    ]
]

[endsect]

[section Functions]

[table
    [[Expression] [Return type] [Returns] [Complexity]]

    [
        [`begin(x)`]
        [`range_iterator<X>::type`]
        [
            `p.first` if `p` is of type `std::pair<T>`
            `a` if `a` is an array
            `range_begin(x)` if that expression would invoke a function found by ADL
            `t.begin()` otherwise
        ]
        [constant time]
    ]
    [
        [`end(x)`]
        [`range_iterator<X>::type`]
        [
            `p.second` if `p` is of type `std::pair<T>`
            `a + sz` if `a` is an array of size `sz`
            `range_end(x)` if that expression would invoke a function found by ADL
            `t.end()` otherwise
        ]
        [constant time]
    ]
    [
        [`empty(x)`]
        [`bool`]
        [`boost::begin(x) == boost::end(x)`]
        [constant time]
    ]
    [
        [`distance(x)`]
        [`range_difference<X>::type`]
        [`std::distance(boost::begin(x),boost::end(x))`]
        [-]
    ]
    [
        [`size(x)`]
        [`range_difference<X>::type`]
        [`range_calculate_size(x)` which by default is `boost::end(x) - boost::begin(x)`. Users may supply alternative implementations by implementing `range_calculate_size(x)` so that it will be found via ADL]
        [constant time]
    ]
    [
        [`rbegin(x)`]
        [`range_reverse_iterator<X>::type`]
        [`range_reverse_iterator<X>::type(boost::end(x))`]
        [constant time]
    ]
    [
        [`rend(x)`]
        [`range_reverse_iterator<X>::type`]
        [`range_reverse_iterator<X>::type(boost::begin(x))`]
        [constant time]
    ]
    [
        [`const_begin(x)`]
        [`range_iterator<const X>::type`]
        [`range_iterator<const X>::type(boost::begin(x))`]
        [constant time]
    ]
    [
        [`const_end(x)`]
        [`range_iterator<const X>::type`]
        [`range_iterator<const X>::type(boost::end(x))`]
        [constant time]
    ]
    [
        [`const_rbegin(x)`]
        [`range_reverse_iterator<const X>::type`]
        [`range_reverse_iterator<const X>::type(boost::rbegin(x))`]
        [constant time]
    ]
    [
        [`const_rend(x)`]
        [`range_reverse_iterator<const X>::type`]
        [`range_reverse_iterator<const X>::type(boost::rend(x))`]
        [constant time]
    ]
    [
        [`as_literal(x)`]
        [`iterator_range<U>` where `U` is `Char*` if `x` is a pointer to a string and `U` is `range_iterator<X>::type` otherwise]
        [
            `[s,s + std::char_traits<X>::length(s))` if `s` is a `Char*` or an array of `Char` `[boost::begin(x),boost::end(x))` otherwise
        ]
        [
            linear time for pointers to a string or arrays of `Char`, constant time otherwise
        ]
    ]
    [
        [`as_array(x)`]
        [`iterator_range<X>`]
        [`[boost::begin(x),boost::end(x))`]
    ]
]

The special `const_`-named functions are useful when you want to document clearly that your code is read-only.

`as_literal()` can be used ['*internally*] in string algorithm libraries such that arrays of characters are handled correctly.

`as_array()` can be used with string algorithm libraries to make it clear that arrays of characters are handled like an array and not like a string.

Notice that the above functions should always be called with qualification (`boost::`) to prevent ['*unintended*] Argument Dependent Lookup (ADL).

[endsect]

[endsect]