File Coverage

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


line stmt bran cond sub pod time code
1             /// \file
2             // Range v3 library
3             //
4             // Copyright Eric Niebler 2014-present
5             // Copyright Casey Carter 2016
6             //
7             // Use, modification and distribution is subject to the
8             // Boost Software License, Version 1.0. (See accompanying
9             // file LICENSE_1_0.txt or copy at
10             // http://www.boost.org/LICENSE_1_0.txt)
11             //
12             // Project home: https://github.com/ericniebler/range-v3
13             //
14              
15             #ifndef RANGES_V3_RANGE_ACCESS_HPP
16             #define RANGES_V3_RANGE_ACCESS_HPP
17              
18             #include
19             #include
20             #include
21             #include
22             #include
23              
24             namespace ranges
25             {
26             inline namespace v3
27             {
28             /// \addtogroup group-core
29             /// @{
30             struct range_access
31             {
32             /// \cond
33             private:
34             template
35             static std::false_type single_pass_2_(long);
36             template
37             static typename T::single_pass single_pass_2_(int);
38              
39             template
40             struct single_pass_
41             {
42             using type = decltype(range_access::single_pass_2_(42));
43             };
44              
45             template
46             static meta::id> mixin_base_2_(long);
47             template
48             static meta::id mixin_base_2_(int);
49              
50             template
51             struct mixin_base_
52             : decltype(range_access::mixin_base_2_(42))
53             {};
54              
55             public:
56             template
57             using single_pass_t = meta::_t>;
58              
59             template
60             using mixin_base_t = meta::_t>;
61              
62             //
63             // Concepts that the range cursor must model
64             //
65             struct Cursor
66             {
67             template
68             auto requires_() -> decltype(
69             concepts::valid_expr(
70             concepts::model_of(),
71             concepts::model_of>(),
72             concepts::model_of, T>(),
73             concepts::model_of, T const &>()
74             ));
75             // Axiom: mixin_base_t has a member get(), accessible to derived classes,
76             // which perfectly-returns the contained cursor object and does not throw
77             // exceptions.
78             };
79             struct HasCursorNext
80             {
81             template
82             auto requires_(T &t) -> decltype(
83             concepts::valid_expr(
84             (t.next(), concepts::void_)
85             ));
86             };
87             struct CursorSentinel
88             : concepts::refines
89             {
90             template
91             auto requires_(S &s, C &c) -> decltype(
92             concepts::valid_expr(
93             concepts::convertible_to(c.equal(s))
94             ));
95             };
96             struct ReadableCursor
97             {
98             template
99             auto requires_(T &t) -> decltype(
100             concepts::valid_expr(
101             t.read()
102             ));
103             };
104             struct HasCursorArrow
105             {
106             template
107             auto requires_(C const &c) -> decltype(
108             concepts::valid_expr(
109             c.arrow()
110             ));
111             };
112             struct WritableCursor
113             {
114             template
115             auto requires_(T &t, U &&u) -> decltype(
116             concepts::valid_expr(
117             (t.write((U &&) u), 42)
118             ));
119             };
120             struct SizedCursorSentinel
121             : concepts::refines
122             {
123             template
124             auto requires_(S &s, C &c) -> decltype(
125             concepts::valid_expr(
126             concepts::model_of(c.distance_to(s))
127             ));
128             };
129             struct OutputCursor
130             : concepts::refines
131             {};
132             struct InputCursor
133             : concepts::refines
134             {};
135             struct ForwardCursor
136             : concepts::refines
137             {
138             template
139             auto requires_() -> decltype(
140             concepts::valid_expr(
141             concepts::is_false(single_pass_t>())
142             ));
143             };
144             struct BidirectionalCursor
145             : concepts::refines
146             {
147             template
148             auto requires_(T &t) -> decltype(
149             concepts::valid_expr(
150             (t.prev(), concepts::void_)
151             ));
152             };
153             struct RandomAccessCursor
154             : concepts::refines
155             {
156             template
157             auto requires_(T &t) -> decltype(
158             concepts::valid_expr(
159             (t.advance(t.distance_to(t)), concepts::void_)
160             ));
161             };
162             struct InfiniteCursor
163             {
164             template
165             auto requires_() -> decltype(
166             concepts::valid_expr(
167             concepts::is_true(typename T::is_infinite{})
168             ));
169             };
170              
171             template
172 638           static RANGES_CXX14_CONSTEXPR auto begin_cursor(Rng &rng)
173 638           RANGES_DECLTYPE_AUTO_RETURN_NOEXCEPT
174             (
175             rng.begin_cursor()
176             )
177             template
178 638           static RANGES_CXX14_CONSTEXPR auto end_cursor(Rng &rng)
179 638           RANGES_DECLTYPE_AUTO_RETURN_NOEXCEPT
180             (
181             rng.end_cursor()
182             )
183              
184             template
185 638           static RANGES_CXX14_CONSTEXPR auto begin_adaptor(Rng &rng)
186 638           RANGES_DECLTYPE_AUTO_RETURN_NOEXCEPT
187             (
188             rng.begin_adaptor()
189             )
190             template
191 638           static RANGES_CXX14_CONSTEXPR auto end_adaptor(Rng &rng)
192 638           RANGES_DECLTYPE_AUTO_RETURN_NOEXCEPT
193             (
194             rng.end_adaptor()
195             )
196              
197             template
198 308           static RANGES_CXX14_CONSTEXPR auto read(Cur const &pos)
199 308           RANGES_DECLTYPE_AUTO_RETURN_NOEXCEPT
200             (
201             pos.read()
202             )
203             template
204             static RANGES_CXX14_CONSTEXPR auto arrow(Cur const &pos)
205             RANGES_DECLTYPE_AUTO_RETURN_NOEXCEPT
206             (
207             pos.arrow()
208             )
209             template
210             static RANGES_CXX14_CONSTEXPR auto move(Cur const &pos)
211             RANGES_DECLTYPE_AUTO_RETURN_NOEXCEPT
212             (
213             pos.move()
214             )
215             template
216             static RANGES_CXX14_CONSTEXPR auto write(Cur &pos, T && t)
217             RANGES_DECLTYPE_AUTO_RETURN_NOEXCEPT
218             (
219             pos.write((T &&) t)
220             )
221             template
222 308           static RANGES_CXX14_CONSTEXPR auto next(Cur & pos)
223 308           RANGES_DECLTYPE_AUTO_RETURN
224             (
225             pos.next()
226             )
227             template
228 946           static RANGES_CXX14_CONSTEXPR auto equal(Cur const &pos, O const &other)
229 946           RANGES_DECLTYPE_AUTO_RETURN
230             (
231             pos.equal(other)
232             )
233             template
234             static RANGES_CXX14_CONSTEXPR auto prev(Cur & pos)
235             RANGES_DECLTYPE_AUTO_RETURN
236             (
237             pos.prev()
238             )
239             template
240             static RANGES_CXX14_CONSTEXPR auto advance(Cur & pos, D n)
241             RANGES_DECLTYPE_AUTO_RETURN
242             (
243             pos.advance(n)
244             )
245             template
246             static RANGES_CXX14_CONSTEXPR auto distance_to(Cur const &pos, O const &other)
247             RANGES_DECLTYPE_AUTO_RETURN
248             (
249             pos.distance_to(other)
250             )
251              
252             private:
253             template
254             using sized_cursor_difference_t =
255             decltype(range_access::distance_to(std::declval(), std::declval()));
256              
257             template
258             static std::ptrdiff_t cursor_difference_2_(detail::any);
259             template
260             static sized_cursor_difference_t cursor_difference_2_(long);
261             template
262             static typename T::difference_type cursor_difference_2_(int);
263              
264             template
265             using cursor_reference_t = decltype(std::declval().read());
266              
267             template
268             static meta::id>> cursor_value_2_(long);
269             template
270             static meta::id cursor_value_2_(int);
271              
272             #ifdef RANGES_WORKAROUND_CWG_1554
273             template
274             struct cursor_difference
275             {
276             using type = decltype(range_access::cursor_difference_2_(42));
277             };
278              
279             template
280             struct cursor_value
281             : decltype(range_access::cursor_value_2_(42))
282             {};
283             #endif // RANGES_WORKAROUND_CWG_1554
284             public:
285             #ifdef RANGES_WORKAROUND_CWG_1554
286             template
287             using cursor_difference_t = meta::_t>;
288              
289             template
290             using cursor_value_t = meta::_t>;
291             #else // ^^^ workaround ^^^ / vvv no workaround vvv
292             template
293             using cursor_difference_t = decltype(range_access::cursor_difference_2_(42));
294              
295             template
296             using cursor_value_t = meta::_t(42))>;
297             #endif // RANGES_WORKAROUND_CWG_1554
298              
299             template
300             static RANGES_CXX14_CONSTEXPR Cur &pos(basic_iterator &it) noexcept
301             {
302             return it.pos();
303             }
304             template
305 946           static constexpr Cur const &pos(basic_iterator const &it) noexcept
306             {
307 946           return it.pos();
308             }
309             template
310             static RANGES_CXX14_CONSTEXPR Cur &&pos(basic_iterator &&it) noexcept
311             {
312             return detail::move(it.pos());
313             }
314              
315             template
316             static RANGES_CXX14_CONSTEXPR Cur cursor(basic_iterator it)
317             {
318             return std::move(it.pos());
319             }
320             /// endcond
321             };
322             /// @}
323              
324             /// \cond
325             namespace detail
326             {
327             template
328             using Cursor =
329             concepts::models;
330              
331             template
332             using CursorSentinel =
333             concepts::models;
334              
335             template
336             using ReadableCursor =
337             concepts::models;
338              
339             template
340             using WritableCursor =
341             concepts::models;
342              
343             template
344             using HasCursorNext =
345             concepts::models;
346              
347             template
348             using HasCursorArrow =
349             concepts::models;
350              
351             template
352             using SizedCursorSentinel =
353             concepts::models;
354              
355             template
356             using OutputCursor =
357             concepts::models;
358              
359             template
360             using InputCursor =
361             concepts::models;
362              
363             template
364             using ForwardCursor =
365             concepts::models;
366              
367             template
368             using BidirectionalCursor =
369             concepts::models;
370              
371             template
372             using RandomAccessCursor =
373             concepts::models;
374              
375             template
376             using InfiniteCursor =
377             concepts::models;
378              
379             template
380             using cursor_concept =
381             concepts::most_refined<
382             meta::list<
383             range_access::RandomAccessCursor,
384             range_access::BidirectionalCursor,
385             range_access::ForwardCursor,
386             range_access::InputCursor,
387             range_access::Cursor>, T>;
388              
389             template
390             using cursor_concept_t = meta::_t>;
391              
392             template()>
393             struct is_writable_cursor_
394             : std::true_type
395             {};
396              
397             template
398             struct is_writable_cursor_
399             : WritableCursor>
400             {};
401              
402             template
403             struct is_writable_cursor
404             : detail::is_writable_cursor_
405             {};
406             }
407             /// \endcond
408             }
409             }
410              
411             #endif