File Coverage

/usr/local/lib/perl5/site_perl/5.26.1/XS/librangeV3.x/i/range/v3/begin_end.hpp
Criterion Covered Total %
statement 8 8 100.0
branch n/a
condition n/a
subroutine n/a
pod n/a
total 8 8 100.0


line stmt bran cond sub pod time code
1             /// \file
2             // Range v3 library
3             //
4             // Copyright Eric Niebler 2013-present
5             //
6             // Use, modification and distribution is subject to the
7             // Boost Software License, Version 1.0. (See accompanying
8             // file LICENSE_1_0.txt or copy at
9             // http://www.boost.org/LICENSE_1_0.txt)
10             //
11             // Project home: https://github.com/ericniebler/range-v3
12             //
13              
14             #ifndef RANGES_V3_BEGIN_END_HPP
15             #define RANGES_V3_BEGIN_END_HPP
16              
17             #include
18             #include
19             #include
20             #include
21             #include
22              
23             #include
24             #include
25             #include
26             #include
27             #include
28             #include
29             #include
30              
31             namespace ranges
32             {
33             inline namespace v3
34             {
35             /// \cond
36             namespace _begin_
37             {
38             // Poison pill for std::begin. (See the detailed discussion at
39             // https://github.com/ericniebler/stl2/issues/139)
40             template
41             void begin(T &) = delete;
42             template
43             void begin(T const &) = delete;
44              
45             #ifdef RANGES_WORKAROUND_MSVC_620035
46             void begin();
47             #endif
48              
49             #if defined(__GNUC__) && !defined(__clang__) && __GNUC__ >= 8 && __GNUC_MINOR__ < 2
50             // Workaround https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85765
51             template
52             void begin(std::initializer_list volatile &) = delete;
53             template
54             void begin(std::initializer_list const volatile &) = delete;
55             #endif
56              
57             struct fn
58             {
59             private:
60             template
61             static constexpr R *impl_(R (&array)[N], int) noexcept
62             {
63             return array;
64             }
65              
66             // Prefer member if it returns Iterator.
67             template
68             typename I = decltype(aux::copy(std::declval().begin())),
69             CONCEPT_REQUIRES_(Iterator())>
70 1276           static constexpr I impl_(R &r, int)
71 1276           RANGES_AUTO_RETURN_NOEXCEPT
72             (
73             r.begin()
74             )
75              
76             // Use ADL if it returns Iterator.
77             template
78             typename I = decltype(aux::copy(begin(std::declval()))),
79             CONCEPT_REQUIRES_(Iterator())>
80             static constexpr I impl_(R &r, long)
81             RANGES_AUTO_RETURN_NOEXCEPT
82             (
83             begin(r)
84             )
85              
86             public:
87             template
88 1276           constexpr auto operator()(R &r) const
89 1276           RANGES_DECLTYPE_AUTO_RETURN_NOEXCEPT
90             (
91             fn::impl_(r, 42)
92             )
93              
94             template
95             RANGES_DEPRECATED("Passing an rvalue to ranges::begin is deprecated.")
96             constexpr auto operator()(const R &&r) const
97             RANGES_DECLTYPE_AUTO_RETURN_NOEXCEPT
98             (
99             fn::impl_(r, 42)
100             )
101              
102             template
103             constexpr auto operator()(std::reference_wrapper ref) const
104             RANGES_DECLTYPE_AUTO_RETURN_NOEXCEPT
105             (
106             Fn()(ref.get())
107             )
108              
109             template
110             constexpr auto operator()(ranges::reference_wrapper ref) const
111             RANGES_DECLTYPE_AUTO_RETURN_NOEXCEPT
112             (
113             Fn()(ref.get())
114             )
115             };
116             }
117             /// \endcond
118              
119             /// \ingroup group-core
120             /// \param r
121             /// \return \c r, if \c r is an array. Otherwise, `r.begin()` if that expression is
122             /// well-formed and returns an Iterator. Otherwise, `begin(r)` if that expression
123             /// returns an Iterator.
124             inline namespace CPOs
125             {
126             RANGES_INLINE_VARIABLE(_begin_::fn, begin)
127             }
128              
129             /// \cond
130             namespace _end_
131             {
132             // Poison pill for std::end. (See the detailed discussion at
133             // https://github.com/ericniebler/stl2/issues/139)
134             template
135             void end(T &) = delete;
136             template
137             void end(T const &) = delete;
138              
139             #ifdef RANGES_WORKAROUND_MSVC_620035
140             void end();
141             #endif
142              
143             #if defined(__GNUC__) && !defined(__clang__) && __GNUC__ >= 8 && __GNUC_MINOR__ < 2
144             // Workaround https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85765
145             template
146             void end(std::initializer_list volatile &) = delete;
147             template
148             void end(std::initializer_list const volatile &) = delete;
149             #endif
150              
151             struct fn
152             {
153             private:
154             template
155             static constexpr R *impl_(R (&array)[N], int) noexcept
156             {
157             return array + N;
158             }
159              
160             // Prefer member if it returns Sentinel.
161             template
162             typename I = decltype(ranges::begin(std::declval())),
163             typename S = decltype(aux::copy(std::declval().end())),
164             CONCEPT_REQUIRES_(Sentinel())>
165 1903           static constexpr S impl_(R &r, int)
166 1903           RANGES_AUTO_RETURN_NOEXCEPT
167             (
168             r.end()
169             )
170              
171             // Use ADL if it returns Sentinel.
172             template
173             typename I = decltype(ranges::begin(std::declval())),
174             typename S = decltype(aux::copy(end(std::declval()))),
175             CONCEPT_REQUIRES_(Sentinel())>
176             static constexpr S impl_(R &r, long)
177             RANGES_AUTO_RETURN_NOEXCEPT
178             (
179             end(r)
180             )
181              
182             public:
183             template
184 1903           constexpr auto operator()(R &r) const
185 1903           RANGES_DECLTYPE_AUTO_RETURN_NOEXCEPT
186             (
187             fn::impl_(r, 42)
188             )
189              
190             template
191             RANGES_DEPRECATED("Passing an rvalue to ranges::end is deprecated.")
192             constexpr auto operator()(const R &&r) const
193             RANGES_DECLTYPE_AUTO_RETURN_NOEXCEPT
194             (
195             fn::impl_(r, 42)
196             )
197              
198             template
199             constexpr auto operator()(std::reference_wrapper ref) const
200             RANGES_DECLTYPE_AUTO_RETURN_NOEXCEPT
201             (
202             Fn()(ref.get())
203             )
204              
205             template
206             constexpr auto operator()(ranges::reference_wrapper ref) const
207             RANGES_DECLTYPE_AUTO_RETURN_NOEXCEPT
208             (
209             Fn()(ref.get())
210             )
211              
212             template())>
213             detail::from_end_>> operator-(Int dist) const
214             {
215             using T = meta::_t>;
216             RANGES_EXPECT(0 <= dist);
217             RANGES_EXPECT(dist <= static_cast(std::numeric_limits::max()));
218             return {-static_cast>>(dist)};
219             }
220             };
221             }
222             /// \endcond
223              
224             /// \ingroup group-core
225             /// \param r
226             /// \return \c r+size(r), if \c r is an array. Otherwise, `r.end()` if that expression is
227             /// well-formed and returns an Iterator. Otherwise, `end(r)` if that expression
228             /// returns an Iterator.
229             inline namespace CPOs
230             {
231             RANGES_INLINE_VARIABLE(_end_::fn, end)
232             }
233              
234             /// \cond
235             namespace _cbegin_
236             {
237             struct fn
238             {
239             template
240             constexpr auto operator()(R const &r) const
241             RANGES_DECLTYPE_AUTO_RETURN_NOEXCEPT
242             (
243             ranges::begin(r)
244             )
245              
246             template
247             RANGES_DEPRECATED("Passing an rvalue to ranges::cbegin is deprecated.")
248             constexpr auto operator()(const R &&r) const
249             RANGES_DECLTYPE_AUTO_RETURN_NOEXCEPT
250             (
251             ranges::begin(r)
252             )
253             };
254             }
255             /// \endcond
256              
257             /// \ingroup group-core
258             /// \param r
259             /// \return The result of calling `ranges::begin` with a const-qualified
260             /// reference to r.
261             inline namespace CPOs
262             {
263             RANGES_INLINE_VARIABLE(_cbegin_::fn, cbegin)
264             }
265              
266             /// \cond
267             namespace _cend_
268             {
269             struct fn
270             {
271             template
272             constexpr auto operator()(R const &r) const
273             RANGES_DECLTYPE_AUTO_RETURN_NOEXCEPT
274             (
275             ranges::end(r)
276             )
277              
278             template
279             RANGES_DEPRECATED("Passing an rvalue to ranges::cend is deprecated.")
280             constexpr auto operator()(const R &&r) const
281             RANGES_DECLTYPE_AUTO_RETURN_NOEXCEPT
282             (
283             ranges::end(r)
284             )
285             };
286             }
287             /// \endcond
288              
289             /// \ingroup group-core
290             /// \param r
291             /// \return The result of calling `ranges::end` with a const-qualified
292             /// reference to r.
293             inline namespace CPOs
294             {
295             RANGES_INLINE_VARIABLE(_cend_::fn, cend)
296             }
297              
298             /// \cond
299             namespace _rbegin_
300             {
301             struct fn
302             {
303             private:
304             template
305             static constexpr reverse_iterator impl_(R (&array)[N], int) noexcept
306             {
307             return ranges::make_reverse_iterator(array + N);
308             }
309              
310             // Prefer member if it returns Iterator.
311             template
312             typename I = decltype(aux::copy(std::declval().rbegin())),
313             CONCEPT_REQUIRES_(Iterator())>
314             static constexpr I impl_(R &r, int)
315             RANGES_AUTO_RETURN_NOEXCEPT
316             (
317             r.rbegin()
318             )
319              
320             template
321             typename I = decltype(ranges::begin(std::declval())),
322             typename S = decltype(ranges::end(std::declval())),
323             CONCEPT_REQUIRES_(Same() && BidirectionalIterator())>
324             static constexpr reverse_iterator impl_(R &r, long)
325             RANGES_AUTO_RETURN_NOEXCEPT
326             (
327             ranges::make_reverse_iterator(ranges::end(r))
328             )
329              
330             public:
331             template
332             constexpr auto operator()(R &r) const
333             RANGES_DECLTYPE_AUTO_RETURN_NOEXCEPT
334             (
335             fn::impl_(r, 42)
336             )
337              
338             template
339             RANGES_DEPRECATED("Passing an rvalue to ranges::rbegin is deprecated.")
340             constexpr auto operator()(const R &&r) const
341             RANGES_DECLTYPE_AUTO_RETURN_NOEXCEPT
342             (
343             fn::impl_(r, 42)
344             )
345              
346             template
347             constexpr auto operator()(std::reference_wrapper ref) const
348             RANGES_DECLTYPE_AUTO_RETURN_NOEXCEPT
349             (
350             Fn()(ref.get())
351             )
352              
353             template
354             constexpr auto operator()(ranges::reference_wrapper ref) const
355             RANGES_DECLTYPE_AUTO_RETURN_NOEXCEPT
356             (
357             Fn()(ref.get())
358             )
359             };
360             }
361             /// \endcond
362              
363             /// \ingroup group-core
364             /// \param r
365             /// \return `make_reverse_iterator(r+size(r))` if r is an array. Otherwise,
366             /// `r.rbegin()` if that expression is well-formed and returns an Iterator.
367             /// Otherwise, `make_reverse_iterator(ranges::end(r))` if `ranges::begin(r)`
368             /// and `ranges::end(r)` are both well-formed and have the same type that
369             /// satisfies BidirectionalIterator.
370             inline namespace CPOs
371             {
372             RANGES_INLINE_VARIABLE(_rbegin_::fn, rbegin)
373             }
374              
375             /// \cond
376             namespace _rend_
377             {
378             struct fn
379             {
380             private:
381             template
382             static constexpr reverse_iterator impl_(R (&array)[N], int) noexcept
383             {
384             return ranges::make_reverse_iterator(array);
385             }
386              
387             // Prefer member if it returns Sentinel.
388             template
389             typename I = decltype(ranges::rbegin(std::declval())),
390             typename S = decltype(aux::copy(std::declval().rend())),
391             CONCEPT_REQUIRES_(Sentinel())>
392             static constexpr S impl_(R &r, int)
393             RANGES_AUTO_RETURN_NOEXCEPT
394             (
395             r.rend()
396             )
397              
398             template
399             typename I = decltype(ranges::begin(std::declval())),
400             typename S = decltype(ranges::end(std::declval())),
401             CONCEPT_REQUIRES_(Same() && BidirectionalIterator())>
402             static constexpr reverse_iterator impl_(R &r, long)
403             RANGES_AUTO_RETURN_NOEXCEPT
404             (
405             ranges::make_reverse_iterator(ranges::begin(r))
406             )
407              
408             public:
409             template
410             constexpr auto operator()(R &r) const
411             RANGES_DECLTYPE_AUTO_RETURN_NOEXCEPT
412             (
413             fn::impl_(r, 42)
414             )
415              
416             template
417             RANGES_DEPRECATED("Passing an rvalue to ranges::rend is deprecated.")
418             constexpr auto operator()(const R &&r) const
419             RANGES_DECLTYPE_AUTO_RETURN_NOEXCEPT
420             (
421             fn::impl_(r, 42)
422             )
423              
424             template
425             constexpr auto operator()(std::reference_wrapper ref) const
426             RANGES_DECLTYPE_AUTO_RETURN_NOEXCEPT
427             (
428             Fn()(ref.get())
429             )
430              
431             template
432             constexpr auto operator()(ranges::reference_wrapper ref) const
433             RANGES_DECLTYPE_AUTO_RETURN_NOEXCEPT
434             (
435             Fn()(ref.get())
436             )
437             };
438             }
439             /// \endcond
440              
441             /// \ingroup group-core
442             /// \param r
443             /// \return `make_reverse_iterator(r))` if r is an array. Otherwise,
444             /// `r.rend()` if that expression is well-formed and returns a type that
445             /// satisfies `Sentinel` where `I` is the type of `ranges::rbegin(r)`.
446             /// Otherwise, `make_reverse_iterator(ranges::begin(r))` if `ranges::begin(r)`
447             /// and `ranges::end(r)` are both well-formed and have the same type that
448             /// satisfies BidirectionalIterator.
449             inline namespace CPOs
450             {
451             RANGES_INLINE_VARIABLE(_rend_::fn, rend)
452             }
453              
454             /// \cond
455             namespace _crbegin_
456             {
457             struct fn
458             {
459             template
460             constexpr auto operator()(R const &r) const
461             RANGES_DECLTYPE_AUTO_RETURN_NOEXCEPT
462             (
463             ranges::rbegin(r)
464             )
465              
466             template
467             RANGES_DEPRECATED("Passing an rvalue to ranges::crbegin is deprecated.")
468             constexpr auto operator()(const R &&r) const
469             RANGES_DECLTYPE_AUTO_RETURN_NOEXCEPT
470             (
471             ranges::rbegin(r)
472             )
473             };
474             }
475             /// \endcond
476              
477             /// \ingroup group-core
478             /// \param r
479             /// \return The result of calling `ranges::rbegin` with a const-qualified
480             /// reference to r.
481             inline namespace CPOs
482             {
483             RANGES_INLINE_VARIABLE(_crbegin_::fn, crbegin)
484             }
485              
486             /// \cond
487             namespace _crend_
488             {
489             struct fn
490             {
491             template
492             constexpr auto operator()(R const &r) const
493             RANGES_DECLTYPE_AUTO_RETURN_NOEXCEPT
494             (
495             ranges::rend(r)
496             )
497              
498             template
499             RANGES_DEPRECATED("Passing an rvalue to ranges::crend is deprecated.")
500             constexpr auto operator()(const R &&r) const
501             RANGES_DECLTYPE_AUTO_RETURN_NOEXCEPT
502             (
503             ranges::rend(r)
504             )
505             };
506             }
507             /// \endcond
508              
509             /// \ingroup group-core
510             /// \param r
511             /// \return The result of calling `ranges::rend` with a const-qualified
512             /// reference to r.
513             inline namespace CPOs
514             {
515             RANGES_INLINE_VARIABLE(_crend_::fn, crend)
516             }
517             }
518             }
519              
520             #endif