ring_span.hpp
Go to the documentation of this file.
1 //
2 // Copyright (c) 2015 Arthur O'Dwyer
3 // Copyright 2017-2019 by Martin Moene
4 //
5 // https://github.com/martinmoene/ring-span-lite
6 //
7 // Distributed under the Boost Software License, Version 1.0.
8 // (See accompanying file LICENSE.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
9 
10 #pragma once
11 
12 #ifndef NONSTD_RING_SPAN_LITE_HPP
13 #define NONSTD_RING_SPAN_LITE_HPP
14 
15 #define ring_span_lite_MAJOR 0
16 #define ring_span_lite_MINOR 3
17 #define ring_span_lite_PATCH 0
18 
19 #define ring_span_lite_VERSION \
20  nsrs_STRINGIFY(ring_span_lite_MAJOR) "." nsrs_STRINGIFY( \
21  ring_span_lite_MINOR) "." nsrs_STRINGIFY(ring_span_lite_PATCH)
22 
23 #define nsrs_STRINGIFY(x) nsrs_STRINGIFY_(x)
24 #define nsrs_STRINGIFY_(x) #x
25 
26 // ring-span-lite configuration:
27 
28 #define nsrs_RING_SPAN_DEFAULT 0
29 #define nsrs_RING_SPAN_NONSTD 1
30 #define nsrs_RING_SPAN_STD 2
31 
32 #if !defined(nsrs_CONFIG_SELECT_RING_SPAN)
33 #define nsrs_CONFIG_SELECT_RING_SPAN \
34  (nsrs_HAVE_STD_RING_SPAN ? nsrs_RING_SPAN_STD : nsrs_RING_SPAN_NONSTD)
35 #endif
36 
37 #ifndef nsrs_CONFIG_STRICT_P0059
38 #define nsrs_CONFIG_STRICT_P0059 0
39 #endif
40 
41 #define nsrs_RING_SPAN_LITE_EXTENSION (!nsrs_CONFIG_STRICT_P0059)
42 
43 #ifndef nsrs_CONFIG_CONFIRMS_COMPILATION_ERRORS
44 #define nsrs_CONFIG_CONFIRMS_COMPILATION_ERRORS 0
45 #endif
46 
47 // C++ language version detection (C++20 is speculative):
48 // Note: VC14.0/1900 (VS2015) lacks too much from C++14.
49 
50 #ifndef nsrs_CPLUSPLUS
51 #if defined(_MSVC_LANG) && !defined(__clang__)
52 #define nsrs_CPLUSPLUS (_MSC_VER == 1900 ? 201103L : _MSVC_LANG)
53 #else
54 #define nsrs_CPLUSPLUS __cplusplus
55 #endif
56 #endif
57 
58 #define nsrs_CPP98_OR_GREATER (nsrs_CPLUSPLUS >= 199711L)
59 #define nsrs_CPP11_OR_GREATER (nsrs_CPLUSPLUS >= 201103L)
60 #define nsrs_CPP11_OR_GREATER_ (nsrs_CPLUSPLUS >= 201103L)
61 #define nsrs_CPP14_OR_GREATER (nsrs_CPLUSPLUS >= 201402L)
62 #define nsrs_CPP17_OR_GREATER (nsrs_CPLUSPLUS >= 201703L)
63 #define nsrs_CPP20_OR_GREATER (nsrs_CPLUSPLUS >= 202000L)
64 
65 // Use C++XX std::ring_span if available and requested:
66 
67 #define nsrs_HAVE_STD_RING_SPAN 0
68 
69 // #if nsrs_CPP17_OR_GREATER && defined(__has_include )
70 // # if __has_include( <any> )
71 // # define nsrs_HAVE_STD_RING_SPAN 1
72 // # else
73 // # define nsrs_HAVE_STD_RING_SPAN 0
74 // # endif
75 // #else
76 // # define nsrs_HAVE_STD_RING_SPAN 0
77 // #endif
78 
79 #define nsrs_USES_STD_RING_SPAN \
80  ((nsrs_CONFIG_SELECT_RING_SPAN == nsrs_RING_SPAN_STD) || \
81  ((nsrs_CONFIG_SELECT_RING_SPAN == nsrs_RING_SPAN_DEFAULT) && \
82  nsrs_HAVE_STD_RING_SPAN))
83 
84 // Compiler versions:
85 //
86 // MSVC++ 6.0 _MSC_VER == 1200 nsrs_COMPILER_MSVC_VERSION == 60 (Visual Studio 6.0)
87 // MSVC++ 7.0 _MSC_VER == 1300 nsrs_COMPILER_MSVC_VERSION == 70 (Visual Studio .NET
88 // 2002) MSVC++ 7.1 _MSC_VER == 1310 nsrs_COMPILER_MSVC_VERSION == 71 (Visual Studio
89 // .NET 2003) MSVC++ 8.0 _MSC_VER == 1400 nsrs_COMPILER_MSVC_VERSION == 80 (Visual
90 // Studio 2005) MSVC++ 9.0 _MSC_VER == 1500 nsrs_COMPILER_MSVC_VERSION == 90 (Visual
91 // Studio 2008) MSVC++ 10.0 _MSC_VER == 1600 nsrs_COMPILER_MSVC_VERSION == 100 (Visual
92 // Studio 2010) MSVC++ 11.0 _MSC_VER == 1700 nsrs_COMPILER_MSVC_VERSION == 110 (Visual
93 // Studio 2012) MSVC++ 12.0 _MSC_VER == 1800 nsrs_COMPILER_MSVC_VERSION == 120 (Visual
94 // Studio 2013) MSVC++ 14.0 _MSC_VER == 1900 nsrs_COMPILER_MSVC_VERSION == 140 (Visual
95 // Studio 2015)
96 // ............ _MSVC_LANG: 201402 for -std:c++14, default
97 // MSVC++ 14.1 _MSC_VER >= 1910 nsrs_COMPILER_MSVC_VERSION == 141 (Visual Studio 2017)
98 // ............ _MSVC_LANG: 201402 for -std:c++14, default
99 // ............ _MSVC_LANG: 201703 for -std:c++17
100 // MSVC++ 14.2 _MSC_VER >= 1920 nsrs_COMPILER_MSVC_VERSION == 142 (Visual Studio 2019)
101 
102 #if defined(_MSC_VER) && !defined(__clang__)
103 #define nsrs_COMPILER_MSVC_VER (_MSC_VER)
104 #define nsrs_COMPILER_MSVC_VERSION (_MSC_VER / 10 - 10 * (5 + (_MSC_VER < 1900)))
105 #else
106 #define nsrs_COMPILER_MSVC_VER 0
107 #define nsrs_COMPILER_MSVC_VERSION 0
108 #endif
109 
110 #define nsrs_COMPILER_VERSION(major, minor, patch) \
111  (10 * (10 * (major) + (minor)) + (patch))
112 
113 #if defined(__clang__)
114 #define nsrs_COMPILER_CLANG_VERSION \
115  nsrs_COMPILER_VERSION(__clang_major__, __clang_minor__, __clang_patchlevel__)
116 #else
117 #define nsrs_COMPILER_CLANG_VERSION 0
118 #endif
119 
120 #if defined(__GNUC__) && !defined(__clang__)
121 #define nsrs_COMPILER_GNUC_VERSION \
122  nsrs_COMPILER_VERSION(__GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__)
123 #else
124 #define nsrs_COMPILER_GNUC_VERSION 0
125 #endif
126 
127 // half-open range [lo..hi):
128 // #define nsrs_BETWEEN( v, lo, hi ) ( (lo) <= (v) && (v) < (hi) )
129 
130 // Presence of language and library features:
131 
132 #ifdef _HAS_CPP0X
133 #define nsrs_HAS_CPP0X _HAS_CPP0X
134 #else
135 #define nsrs_HAS_CPP0X 0
136 #endif
137 
138 // Unless defined otherwise below, consider VC14 as C++11 for ring-span-lite:
139 
140 #if nsrs_COMPILER_MSVC_VER >= 1900
141 #undef nsrs_CPP11_OR_GREATER
142 #define nsrs_CPP11_OR_GREATER 1
143 #endif
144 
145 #define nsrs_CPP11_90 (nsrs_CPP11_OR_GREATER_ || nsrs_COMPILER_MSVC_VER >= 1500)
146 #define nsrs_CPP11_100 (nsrs_CPP11_OR_GREATER_ || nsrs_COMPILER_MSVC_VER >= 1600)
147 #define nsrs_CPP11_110 (nsrs_CPP11_OR_GREATER_ || nsrs_COMPILER_MSVC_VER >= 1700)
148 #define nsrs_CPP11_120 (nsrs_CPP11_OR_GREATER_ || nsrs_COMPILER_MSVC_VER >= 1800)
149 #define nsrs_CPP11_140 (nsrs_CPP11_OR_GREATER_ || nsrs_COMPILER_MSVC_VER >= 1900)
150 
151 #define nsrs_CPP14_000 (nsrs_CPP14_OR_GREATER)
152 #define nsrs_CPP17_000 (nsrs_CPP17_OR_GREATER)
153 
154 // Presence of C++11 language features:
155 
156 // half-open range [lo..hi):
157 #define nsrs_BETWEEN(v, lo, hi) ((lo) <= (v) && (v) < (hi))
158 
159 // Presence of C++11 language features:
160 
161 #define nsrs_HAVE_CONSTEXPR_11 nsrs_CPP11_140
162 #define nsrs_HAVE_IS_DEFAULT nsrs_CPP11_140
163 #define nsrs_HAVE_IS_DELETE nsrs_CPP11_140
164 #define nsrs_HAVE_NOEXCEPT nsrs_CPP11_140
165 #define nsrs_HAVE_NULLPTR nsrs_CPP11_100
166 
167 // Presence of C++14 language features:
168 
169 #define nsrs_HAVE_CONSTEXPR_14 nsrs_CPP14_000
170 
171 // Presence of C++17 language features:
172 // no tag
173 
174 // Presence of C++ library features:
175 // no tag
176 
177 // Compiler warning suppression:
178 
179 #if defined(__clang__)
180 #pragma clang diagnostic push
181 #pragma clang diagnostic ignored "-Wundef"
182 #define nsrs_RESTORE_WARNINGS() _Pragma("clang diagnostic pop")
183 
184 #elif defined __GNUC__
185 #pragma GCC diagnostic push
186 #pragma GCC diagnostic ignored "-Wundef"
187 #define nsrs_RESTORE_WARNINGS() _Pragma("GCC diagnostic pop")
188 
189 #elif nsrs_COMPILER_MSVC_VERSION >= 140
190 #define nsrs_DISABLE_MSVC_WARNINGS(codes) \
191  __pragma(warning(push)) __pragma(warning(disable : codes))
192 #define nsrs_RESTORE_WARNINGS() __pragma(warning(pop))
193 
194 // Suppress the following MSVC warnings:
195 // - C4345: initialization behavior changed
196 //
197 // Suppress the following MSVC GSL warnings:
198 // - C26439, gsl::f.6 : special function 'function' can be declared 'noexcept'
199 // - C26440, gsl::f.6 : function 'function' can be declared 'noexcept'
200 // - C26472, gsl::t.1 : don't use a static_cast for arithmetic conversions;
201 // use brace initialization, gsl::narrow_cast or gsl::narrow
202 // - C26473: gsl::t.1 : don't cast between pointer types where the source type and the
203 // target type are the same
204 // - C26481: gsl::b.1 : don't use pointer arithmetic. Use span instead
205 // - C26490: gsl::t.1 : don't use reinterpret_cast
206 
207 nsrs_DISABLE_MSVC_WARNINGS(4345 26439 26440 26472 26473 26481 26490)
208 
209 #else
210 #define nsrs_RESTORE_WARNINGS() /*empty*/
211 #endif
212 
213 // C++ feature usage:
214 
215 #if nsrs_HAVE_CONSTEXPR_11
216 #define nsrs_constexpr constexpr
217 #else
218 #define nsrs_constexpr /*constexpr*/
219 #endif
220 
221 #if nsrs_HAVE_CONSTEXPR_14
222 #define nsrs_constexpr14 constexpr
223 #else
224 #define nsrs_constexpr14 /*constexpr*/
225 #endif
226 
227 #if nsrs_HAVE_NOEXCEPT
228 #define nsrs_noexcept noexcept
229 #define nsrs_noexcept_op noexcept
230 #else
231 #define nsrs_noexcept /*noexcept*/
232 #define nsrs_noexcept_op(expr) /*noexcept(expr)*/
233 #endif
234 
235 #if nsrs_HAVE_NULLPTR
236 #define nsrs_nullptr nullptr
237 #else
238 #define nsrs_nullptr NULL
239 #endif
240 
241 // Method enabling
242 
243 #if nsrs_CPP11_OR_GREATER
244 
245 #define nsrs_REQUIRES_0(...) \
246  template <bool B = (__VA_ARGS__), typename std::enable_if<B, int>::type = 0>
247 
248 #define nsrs_REQUIRES_T(...) , typename std::enable_if<(__VA_ARGS__), int>::type = 0
249 
250 #endif
251 
252 // includes:
253 
254 #include <cassert>
255 #include <iterator>
256 #include <utility>
257 
258 // additional includes:
259 
260 #if !nsrs_CPP11_OR_GREATER
261 #include <algorithm> // std::swap() until C++11
262 #endif
263 
264 namespace nonstd
265 {
266 namespace ring_span_lite
267 {
268 
269 // type traits C++11:
270 
271 namespace std11
272 {
273 
274 #if nsrs_CPP11_OR_GREATER
275 using std::move;
276 #else
277 template <typename T>
278 T const& move(T const& t)
279 {
280  return t;
281 }
282 #endif
283 
284 template <bool B, class T, class F>
286 {
287  typedef T type;
288 };
289 
290 template <class T, class F>
291 struct conditional<false, T, F>
292 {
293  typedef F type;
294 };
295 
296 } // namespace std11
297 
298 // type traits C++17:
299 
300 namespace std17
301 {
302 
303 #if nsrs_CPP17_OR_GREATER
304 
305 using std::is_nothrow_swappable;
306 using std::is_swappable;
307 
308 #elif nsrs_CPP11_OR_GREATER
309 
310 namespace detail
311 {
312 
313 using std::swap;
314 
315 struct is_swappable
316 {
317  template <typename T, typename = decltype(swap(std::declval<T&>(), std::declval<T&>()))>
318  static std::true_type test(int);
319 
320  template <typename>
321  static std::false_type test(...);
322 };
323 
324 struct is_nothrow_swappable
325 {
326  // wrap noexcept(epr) in separate function as work-around for VC140 (VS2015):
327 
328  template <typename T>
329  static constexpr bool test()
330  {
331  return noexcept(swap(std::declval<T&>(), std::declval<T&>()));
332  }
333 
334  template <typename T>
335  static auto test(int) -> std::integral_constant<bool, test<T>()>
336  {
337  }
338 
339  template <typename>
340  static std::false_type test(...);
341 };
342 
343 } // namespace detail
344 
345 // is [nothow] swappable:
346 
347 template <typename T>
348 struct is_swappable : decltype(detail::is_swappable::test<T>(0))
349 {
350 };
351 
352 template <typename T>
353 struct is_nothrow_swappable : decltype(detail::is_nothrow_swappable::test<T>(0))
354 {
355 };
356 
357 #endif // nsrs_CPP17_OR_GREATER
358 
359 } // namespace std17
360 
361 //
362 // element extraction policies:
363 //
364 
365 template <class T>
367 {
368  typedef void return_type;
369 
370  void operator()(T&) const nsrs_noexcept
371  {
372  }
373 };
374 
375 template <class T>
377 {
378  typedef T return_type;
379 
380  T operator()(T& t) const
381  {
382  return std11::move(t);
383  }
384 };
385 
386 template <class T>
388 {
389  typedef T return_type;
390 
391 #if nsrs_RING_SPAN_LITE_EXTENSION
392 #if nsrs_CPP11_OR_GREATER
393  copy_popper(T t) : m_copy(std::move(t))
394  {
395  }
396 #else
397  copy_popper(T const& t) : m_copy(t)
398  {
399  }
400 #endif
401 #else
402  copy_popper(T&& t) : copy(std::move(t))
403  {
404  }
405 #endif
406 
407  T operator()(T& t) const
408  {
409  using std::swap;
410  T result(m_copy);
411  swap(t, result);
412  return result;
413  }
414 
416 };
417 
418 // forward-declare iterator:
419 
420 namespace detail
421 {
422 
423 template <class, bool>
425 
426 }
427 
428 //
429 // ring span:
430 //
431 template <class T, class Popper = default_popper<T> >
433 {
434 public:
435  typedef T value_type;
436  typedef T* pointer;
437  typedef T& reference;
438  typedef T const& const_reference;
439 
441 
443 
446 
447 #if nsrs_RING_SPAN_LITE_EXTENSION
448  typedef std::reverse_iterator<iterator> reverse_iterator;
449  typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
450 #endif
451 
452  // construction:
453 
454  template <class ContiguousIterator>
455  ring_span(ContiguousIterator begin, ContiguousIterator end,
456  Popper popper = Popper()) nsrs_noexcept
457  : m_data(&*begin),
458  m_size(0),
459  m_capacity(static_cast<size_type>(end - begin)),
460  m_front_idx(0),
461  m_popper(std11::move(popper))
462  {
463  }
464 
465  template <class ContiguousIterator>
466  ring_span(ContiguousIterator begin, ContiguousIterator end, ContiguousIterator first,
467  size_type size, Popper popper = Popper()) nsrs_noexcept
468  : m_data(&*begin),
469  m_size(size),
470  m_capacity(static_cast<size_type>(end - begin)),
471  m_front_idx(static_cast<size_type>(first - begin)),
472  m_popper(std11::move(popper))
473  {
475  }
476 
477 #if nsrs_HAVE_IS_DEFAULT
478  ring_span(ring_span&&) = default;
479  ring_span& operator=(ring_span&&) = default;
480 #else
481 private:
482  ring_span(ring_span const&);
483  ring_span& operator=(ring_span const&);
484 
485 public:
486 #endif
487 
488  // observers:
489 
490  bool empty() const nsrs_noexcept
491  {
492  return m_size == 0;
493  }
494 
495  bool full() const nsrs_noexcept
496  {
497  return m_size == m_capacity;
498  }
499 
501  {
502  return m_size;
503  }
504 
506  {
507  return m_capacity;
508  }
509 
510  // element access:
511 
512 #if nsrs_RING_SPAN_LITE_EXTENSION
514  {
515  assert(idx < m_size);
516  return at_(idx);
517  }
518 
520  {
521  assert(idx < m_size);
522  return at_(idx);
523  }
524 #endif
525 
527  {
528  return *begin();
529  }
530 
532  {
533  return *begin();
534  }
535 
537  {
538  return *(--end());
539  }
540 
542  {
543  return *(--end());
544  }
545 
546  // iteration:
547 
549  {
550  return iterator(0, this);
551  }
552 
554  {
555  return cbegin();
556  }
557 
559  {
560  return const_iterator(0, this);
561  }
562 
564  {
565  return iterator(size(), this);
566  }
567 
569  {
570  return cend();
571  }
572 
574  {
575  return const_iterator(size(), this);
576  }
577 
578 #if nsrs_RING_SPAN_LITE_EXTENSION
579 
581  {
582  return reverse_iterator(end());
583  }
584 
586  {
587  return reverse_iterator(begin());
588  }
589 
591  {
592  return crbegin();
593  }
594 
596  {
597  return crend();
598  }
599 
601  {
602  return const_reverse_iterator(cend());
603  }
604 
606  {
607  return const_reverse_iterator(cbegin());
608  }
609 #endif
610 
611  // element insertion, extraction:
612 
613  typename Popper::return_type pop_front()
614  {
615  assert(!empty());
616 
617  reference element = front_();
619 
620  return m_popper(element);
621  }
622 
623 #if nsrs_RING_SPAN_LITE_EXTENSION
624  typename Popper::return_type pop_back()
625  {
626  assert(!empty());
627 
628  reference element = back_();
629  decrement_back_();
630 
631  return m_popper(element);
632  }
633 #endif
634 
635 #if nsrs_CPP11_OR_GREATER
636  nsrs_REQUIRES_0(std::is_copy_assignable<T>::value) void push_back(
637  value_type const& value) noexcept(std::is_nothrow_copy_assignable<T>::value)
638 #else
639  void push_back(value_type const& value)
640 #endif
641  {
642  if (full())
644  else
645  increment_back_();
646 
647  back_() = value;
648  }
649 
650 #if nsrs_CPP11_OR_GREATER
651  nsrs_REQUIRES_0(std::is_move_assignable<T>::value) void push_back(
652  value_type&& value) noexcept(std::is_nothrow_move_assignable<T>::value)
653  {
654  if (full())
656  else
657  increment_back_();
658 
659  back_() = std::move(value);
660  }
661 
662  template <typename... Args nsrs_REQUIRES_T(
663  std::is_constructible<T, Args&&...>::value&& std::is_move_assignable<T>::value)>
664  void emplace_back(Args&&... args) noexcept(
665  std::is_nothrow_constructible<T, Args...>::value &&
666  std::is_nothrow_move_assignable<T>::value)
667  {
668  if (full())
670  else
671  increment_back_();
672 
673  back_() = T(std::forward<Args>(args)...);
674  }
675 #endif
676 
677 #if nsrs_RING_SPAN_LITE_EXTENSION
678 
679 #if nsrs_CPP11_OR_GREATER
680  nsrs_REQUIRES_0(std::is_copy_assignable<T>::value) void push_front(
681  T const& value) noexcept((std::is_nothrow_copy_assignable<T>::value))
682 #else
683  void push_front(T const& value)
684 #endif
685  {
686  if (full())
688  else
690 
691  front_() = value;
692  }
693 
694 #if nsrs_CPP11_OR_GREATER
695  nsrs_REQUIRES_0(std::is_move_assignable<T>::value) void push_front(T&& value) noexcept(
696  (std::is_nothrow_move_assignable<T>::value))
697  {
698  if (full())
700  else
702 
703  front_() = std::move(value);
704  }
705 
706  template <typename... Args nsrs_REQUIRES_T(
707  std::is_constructible<T, Args&&...>::value&& std::is_move_assignable<T>::value)>
708  void emplace_front(Args&&... args) noexcept(
709  std::is_nothrow_constructible<T, Args...>::value &&
710  std::is_nothrow_move_assignable<T>::value)
711  {
712  if (full())
714  else
716 
717  front_() = T(std::forward<Args>(args)...);
718  }
719 #endif
720 #endif // nsrs_RING_SPAN_LITE_EXTENSION
721 
722  // swap:
723 
724  void swap(type& rhs)
725 #if nsrs_CPP11_OR_GREATER
726  noexcept(std17::is_nothrow_swappable<Popper>::value)
727 #endif
728  {
729  using std::swap;
730  swap(m_data, rhs.m_data);
731  swap(m_size, rhs.m_size);
732  swap(m_capacity, rhs.m_capacity);
734  swap(m_popper, rhs.m_popper);
735  }
736 
737 private:
738  friend class detail::ring_iterator<ring_span, true>; // const_iterator;
739  friend class detail::ring_iterator<ring_span, false>; // iterator;
740 
742  {
743  return idx % m_capacity;
744  }
745 
747  {
748  return m_data[normalize_(m_front_idx + idx)];
749  }
750 
752  {
753  return m_data[normalize_(m_front_idx + idx)];
754  }
755 
757  {
758  return *(m_data + m_front_idx);
759  }
760 
762  {
763  return *(m_data + m_front_idx);
764  }
765 
767  {
768  return *(m_data + normalize_(m_front_idx + m_size - 1));
769  }
770 
772  {
773  return *(m_data + normalize_(m_front_idx + m_size - 1));
774  }
775 
777  {
779  --m_size;
780  }
781 
783  {
785  ++m_size;
786  }
787 
789  {
790  ++m_size;
791  }
792 
794  {
795  --m_size;
796  }
797 
799  {
801  }
802 
804  {
806  }
807 
808 private:
813  Popper m_popper;
814 };
815 
816 // swap:
817 
818 template <class T, class Popper>
820  nsrs_noexcept_op(nsrs_noexcept_op(lhs.swap(rhs)))
821 {
822  lhs.swap(rhs);
823 }
824 
825 namespace detail
826 {
827 
828 //
829 // ring iterator:
830 //
831 #if 0
832 template< class RS, bool is_const >
833 class ring_iterator : public std::iterator
834 <
835  std::random_access_iterator_tag
836  , typename std11::conditional<is_const, const typename RS::value_type, typename RS::value_type>::type
837 >
838 #endif
839 
840 template <class RS, bool is_const>
841 class ring_iterator
842 {
843 public:
845 
846  typedef std::ptrdiff_t difference_type;
847  typedef typename RS::value_type value_type;
848 
849  typedef
853  typedef std::random_access_iterator_tag iterator_category;
854 
855 #if nsrs_CPP11_OR_GREATER
856  ring_iterator() = default;
857 #else
859  {
860  }
861 #endif
862 
863 #if nsrs_RING_SPAN_LITE_EXTENSION
864  // conversion to const iterator:
865 
867  {
869  }
870 #endif
871 
872  // access content:
873 
875  {
876  return m_rs->at_(m_idx);
877  }
878 
879  // advance iterator:
880 
882  {
883  ++m_idx;
884  return *this;
885  }
886 
888  {
889  type r(*this);
890  ++*this;
891  return r;
892  }
893 
895  {
896  --m_idx;
897  return *this;
898  }
899 
901  {
902  type r(*this);
903  --*this;
904  return r;
905  }
906 
907 #if defined(__clang__) || defined(__GNUC__)
908 #pragma GCC diagnostic push
909 #pragma GCC diagnostic ignored "-Wsign-conversion"
910 #endif
911 
913  {
914  m_idx += i;
915  return *this;
916  }
917 
919  {
920  m_idx -= i;
921  return *this;
922  }
923 
924 #if defined(__clang__) || defined(__GNUC__)
925 #pragma GCC diagnostic pop
926 #endif
927 
928 #if nsrs_RING_SPAN_LITE_EXTENSION
929 
930  template <bool C>
932  {
933  return static_cast<difference_type>(this->m_idx) -
934  static_cast<difference_type>(rhs.m_idx);
935  }
936 #endif
937 
938  // comparison:
939 
940  template <bool C>
942  {
943  assert(this->m_rs == rhs.m_rs);
944  return (this->m_idx < rhs.m_idx);
945  }
946 
947  template <bool C>
949  {
950  assert(this->m_rs == rhs.m_rs);
951  return (this->m_idx == rhs.m_idx);
952  }
953 
954  // other comparisons expressed in <, ==:
955 
956  template <bool C>
957  inline bool operator!=(ring_iterator<RS, C> const& rhs) const nsrs_noexcept
958  {
959  return !(*this == rhs);
960  }
961 
962  template <bool C>
963  inline bool operator<=(ring_iterator<RS, C> const& rhs) const nsrs_noexcept
964  {
965  return !(rhs < *this);
966  }
967 
968  template <bool C>
969  inline bool operator>(ring_iterator<RS, C> const& rhs) const nsrs_noexcept
970  {
971  return rhs < *this;
972  }
973 
974  template <bool C>
975  inline bool operator>=(ring_iterator<RS, C> const& rhs) const nsrs_noexcept
976  {
977  return !(*this < rhs);
978  }
979 
980 private:
981  friend RS; // clang: non-class friend type 'RS' is a C++11 extension
982  // [-Wc++11-extensions]
983  friend class ring_iterator<RS, !is_const>;
984 
985  typedef typename RS::size_type size_type;
987 
990  nsrs_noexcept : m_idx(idx),
991  m_rs(rs)
992  {
993  }
994 
995 private:
998 };
999 
1000 // advanced iterator:
1001 
1002 template <class RS, bool C>
1004 {
1005  it += i;
1006  return it;
1007 }
1008 
1009 template <class RS, bool C>
1011 {
1012  it -= i;
1013  return it;
1014 }
1015 
1016 } // namespace detail
1017 } // namespace ring_span_lite
1018 
1019 using ring_span_lite::copy_popper;
1020 using ring_span_lite::default_popper;
1021 using ring_span_lite::null_popper;
1022 using ring_span_lite::ring_span;
1023 
1024 } // namespace nonstd
1025 
1027 
1028 #endif // NONSTD_RING_SPAN_LITE_HPP
nonstd::ring_span_lite::ring_span::crend
const_reverse_iterator crend() const nsrs_noexcept
Definition: ring_span.hpp:605
nonstd::ring_span_lite::default_popper::operator()
T operator()(T &t) const
Definition: ring_span.hpp:380
nonstd::ring_span_lite::ring_span::front_
const_reference front_() const nsrs_noexcept
Definition: ring_span.hpp:761
nonstd::ring_span_lite::copy_popper::operator()
T operator()(T &t) const
Definition: ring_span.hpp:407
detail::first
auto first(const T &value, const Tail &...) -> const T &
Definition: compile.h:60
nonstd::ring_span_lite::detail::ring_iterator
Definition: ring_span.hpp:424
nonstd::ring_span_lite::ring_span::back_
reference back_() nsrs_noexcept
Definition: ring_span.hpp:766
nonstd::ring_span_lite::ring_span::end
const_iterator end() const nsrs_noexcept
Definition: ring_span.hpp:568
detail::copy
auto copy(const Range &range, OutputIt out) -> OutputIt
Definition: ranges.h:22
nonstd::ring_span_lite::copy_popper::return_type
T return_type
Definition: ring_span.hpp:389
nonstd::ring_span_lite::ring_span::reverse_iterator
std::reverse_iterator< iterator > reverse_iterator
Definition: ring_span.hpp:448
nonstd::span_lite::size_t
span_CONFIG_SIZE_TYPE size_t
Definition: span.hpp:576
nonstd::ring_span_lite::ring_span::rbegin
reverse_iterator rbegin() nsrs_noexcept
Definition: ring_span.hpp:580
nonstd::ring_span_lite::ring_span::front_
reference front_() nsrs_noexcept
Definition: ring_span.hpp:756
nonstd::ring_span_lite::ring_span::operator[]
const_reference operator[](size_type idx) const nsrs_noexcept
Definition: ring_span.hpp:519
nonstd::ring_span_lite::ring_span::normalize_
size_type normalize_(size_type const idx) const nsrs_noexcept
Definition: ring_span.hpp:741
nonstd::ring_span_lite::detail::ring_iterator::operator--
type operator--(int) nsrs_noexcept
Definition: ring_span.hpp:900
nonstd::ring_span_lite::detail::ring_iterator::operator++
type operator++(int) nsrs_noexcept
Definition: ring_span.hpp:887
template
string template
nonstd::ring_span_lite::ring_span::back
const_reference back() const nsrs_noexcept
Definition: ring_span.hpp:541
nonstd::ring_span_lite::std11::conditional
Definition: ring_span.hpp:285
nonstd::ring_span_lite::ring_span::ring_span
ring_span(ContiguousIterator begin, ContiguousIterator end, Popper popper=Popper()) nsrs_noexcept
Definition: ring_span.hpp:455
nonstd::ring_span_lite::ring_span::decrement_front_and_back_
void decrement_front_and_back_() nsrs_noexcept
Definition: ring_span.hpp:803
nonstd::span_lite::std11::false_type
integral_constant< bool, false > false_type
Definition: span.hpp:657
detail
Definition: args.h:19
nonstd::ring_span_lite::detail::ring_iterator::operator==
bool operator==(ring_iterator< RS, C > const &rhs) const nsrs_noexcept
Definition: ring_span.hpp:948
nonstd::ring_span_lite::ring_span::front
const_reference front() const nsrs_noexcept
Definition: ring_span.hpp:531
nsrs_noexcept
#define nsrs_noexcept
Definition: ring_span.hpp:231
nonstd::ring_span_lite::ring_span::rbegin
const_reverse_iterator rbegin() const nsrs_noexcept
Definition: ring_span.hpp:590
nonstd::ring_span_lite::detail::ring_iterator::pointer
std11::conditional< is_const, const value_type, value_type >::type * pointer
Definition: ring_span.hpp:850
nonstd::ring_span_lite::detail::ring_iterator::operator-=
type & operator-=(int i) nsrs_noexcept
Definition: ring_span.hpp:918
nonstd::ring_span_lite::detail::ring_iterator::size_type
RS::size_type size_type
Definition: ring_span.hpp:985
nonstd::ring_span_lite::ring_span::pop_back
Popper::return_type pop_back()
Definition: ring_span.hpp:624
nonstd::ring_span_lite::detail::ring_iterator::ring_type
std11::conditional< is_const, const RS, RS >::type ring_type
Definition: ring_span.hpp:986
nonstd::span_lite::std11::true_type
integral_constant< bool, true > true_type
Definition: span.hpp:656
nonstd::ring_span_lite::ring_span::reference
T & reference
Definition: ring_span.hpp:437
nonstd::ring_span_lite::detail::ring_iterator::m_idx
size_type m_idx
Definition: ring_span.hpp:996
nonstd::ring_span_lite::detail::ring_iterator::operator++
type & operator++() nsrs_noexcept
Definition: ring_span.hpp:881
nonstd::ring_span_lite::detail::ring_iterator::operator<=
bool operator<=(ring_iterator< RS, C > const &rhs) const nsrs_noexcept
Definition: ring_span.hpp:963
nonstd::ring_span_lite::ring_span::const_reference
T const & const_reference
Definition: ring_span.hpp:438
nonstd::ring_span_lite::detail::ring_iterator::m_rs
ring_type * m_rs
Definition: ring_span.hpp:997
nonstd::ring_span_lite::ring_span::decrement_back_
void decrement_back_() nsrs_noexcept
Definition: ring_span.hpp:793
nonstd::ring_span_lite::ring_span::type
ring_span< T, Popper > type
Definition: ring_span.hpp:442
nonstd::ring_span_lite::detail::operator-
ring_iterator< RS, C > operator-(ring_iterator< RS, C > it, int i) nsrs_noexcept
Definition: ring_span.hpp:1010
nsrs_noexcept_op
#define nsrs_noexcept_op(expr)
Definition: ring_span.hpp:232
nonstd::ring_span_lite::std11::conditional::type
T type
Definition: ring_span.hpp:287
nonstd::ring_span_lite::copy_popper
Definition: ring_span.hpp:387
nonstd::ring_span_lite::null_popper::return_type
void return_type
Definition: ring_span.hpp:368
nonstd::ring_span_lite::ring_span::m_size
size_type m_size
Definition: ring_span.hpp:810
nonstd::ring_span_lite::detail::operator+
ring_iterator< RS, C > operator+(ring_iterator< RS, C > it, int i) nsrs_noexcept
Definition: ring_span.hpp:1003
nonstd::ring_span_lite::detail::ring_iterator::type
ring_iterator< RS, is_const > type
Definition: ring_span.hpp:844
nonstd::ring_span_lite::ring_span::begin
const_iterator begin() const nsrs_noexcept
Definition: ring_span.hpp:553
nonstd::ring_span_lite::detail::ring_iterator::value_type
RS::value_type value_type
Definition: ring_span.hpp:847
nonstd::ring_span_lite::ring_span::operator=
ring_span & operator=(ring_span const &)
nonstd::ring_span_lite::detail::ring_iterator::operator>=
bool operator>=(ring_iterator< RS, C > const &rhs) const nsrs_noexcept
Definition: ring_span.hpp:975
nonstd::ring_span_lite::ring_span::capacity
size_type capacity() const nsrs_noexcept
Definition: ring_span.hpp:505
nonstd::ring_span_lite::ring_span::const_iterator
detail::ring_iterator< type, true > const_iterator
Definition: ring_span.hpp:445
nonstd::ring_span_lite::ring_span::decrement_front_
void decrement_front_() nsrs_noexcept
Definition: ring_span.hpp:782
nonstd::ring_span_lite::ring_span::m_data
pointer m_data
Definition: ring_span.hpp:809
nonstd::ring_span_lite::null_popper::operator()
void operator()(T &) const nsrs_noexcept
Definition: ring_span.hpp:370
nonstd
Definition: ring_span.hpp:264
nonstd::ring_span_lite::ring_span::at_
reference at_(size_type idx) nsrs_noexcept
Definition: ring_span.hpp:746
nonstd::ring_span_lite::ring_span::at_
const_reference at_(size_type idx) const nsrs_noexcept
Definition: ring_span.hpp:751
nonstd::ring_span_lite::ring_span::rend
const_reverse_iterator rend() const nsrs_noexcept
Definition: ring_span.hpp:595
nonstd::ring_span_lite::default_popper::return_type
T return_type
Definition: ring_span.hpp:378
std::swap
NLOHMANN_BASIC_JSON_TPL_DECLARATION void swap(nlohmann::NLOHMANN_BASIC_JSON_TPL &j1, nlohmann::NLOHMANN_BASIC_JSON_TPL &j2) noexcept(//NOLINT(readability-inconsistent-declaration-parameter-name) is_nothrow_move_constructible< nlohmann::NLOHMANN_BASIC_JSON_TPL >::value &&//NOLINT(misc-redundant-expression) is_nothrow_move_assignable< nlohmann::NLOHMANN_BASIC_JSON_TPL >::value)
exchanges the values of two JSON objects
Definition: json.hpp:21884
nonstd::ring_span_lite::ring_span::back_
const_reference back_() const nsrs_noexcept
Definition: ring_span.hpp:771
nonstd::ring_span_lite::ring_span::value_type
T value_type
Definition: ring_span.hpp:435
nonstd::ring_span_lite::ring_span::cend
const_iterator cend() const nsrs_noexcept
Definition: ring_span.hpp:573
nonstd::ring_span_lite::detail::ring_iterator::operator--
type & operator--() nsrs_noexcept
Definition: ring_span.hpp:894
nonstd::ring_span_lite::detail::ring_iterator::ring_iterator
ring_iterator()
Definition: ring_span.hpp:858
nonstd::ring_span_lite::ring_span::increment_front_and_back_
void increment_front_and_back_() nsrs_noexcept
Definition: ring_span.hpp:798
nonstd::ring_span_lite::ring_span::increment_front_
void increment_front_() nsrs_noexcept
Definition: ring_span.hpp:776
nonstd::ring_span_lite::ring_span::begin
iterator begin() nsrs_noexcept
Definition: ring_span.hpp:548
nonstd::ring_span_lite::ring_span::size
size_type size() const nsrs_noexcept
Definition: ring_span.hpp:500
nonstd::ring_span_lite::detail::ring_iterator::RS
friend RS
Definition: ring_span.hpp:981
nonstd::ring_span_lite::ring_span::empty
bool empty() const nsrs_noexcept
Definition: ring_span.hpp:490
nonstd::ring_span_lite::detail::ring_iterator::operator+=
type & operator+=(int i) nsrs_noexcept
Definition: ring_span.hpp:912
nonstd::ring_span_lite::detail::ring_iterator::reference
std11::conditional< is_const, const value_type, value_type >::type & reference
Definition: ring_span.hpp:852
nonstd::ring_span_lite::ring_span::ring_span
ring_span(ContiguousIterator begin, ContiguousIterator end, ContiguousIterator first, size_type size, Popper popper=Popper()) nsrs_noexcept
Definition: ring_span.hpp:466
assert
#define assert(condition)
Definition: lz4.c:271
nonstd::ring_span_lite::std11::conditional< false, T, F >::type
F type
Definition: ring_span.hpp:293
nonstd::ring_span_lite::copy_popper::copy_popper
copy_popper(T const &t)
Definition: ring_span.hpp:397
nonstd::ring_span_lite::ring_span::swap
void swap(type &rhs)
Definition: ring_span.hpp:724
nonstd::ring_span_lite::copy_popper::m_copy
T m_copy
Definition: ring_span.hpp:415
nonstd::ring_span_lite::detail::ring_iterator::operator>
bool operator>(ring_iterator< RS, C > const &rhs) const nsrs_noexcept
Definition: ring_span.hpp:969
std
nonstd::ring_span_lite::ring_span::size_type
std::size_t size_type
Definition: ring_span.hpp:440
nonstd::ring_span_lite::ring_span::push_front
void push_front(T const &value)
Definition: ring_span.hpp:683
nonstd::ring_span_lite::std11::move
T const & move(T const &t)
Definition: ring_span.hpp:278
nonstd::ring_span_lite::ring_span::iterator
detail::ring_iterator< type, false > iterator
Definition: ring_span.hpp:444
nonstd::ring_span_lite::ring_span::increment_back_
void increment_back_() nsrs_noexcept
Definition: ring_span.hpp:788
nonstd::ring_span_lite::ring_span::pointer
T * pointer
Definition: ring_span.hpp:436
nonstd::ring_span_lite::detail::ring_iterator::operator-
difference_type operator-(ring_iterator< RS, C > const &rhs) const nsrs_noexcept
Definition: ring_span.hpp:931
nsrs_RESTORE_WARNINGS
#define nsrs_RESTORE_WARNINGS()
Definition: ring_span.hpp:210
nonstd::ring_span_lite::detail::ring_iterator::operator*
reference operator*() const nsrs_noexcept
Definition: ring_span.hpp:874
nonstd::ring_span_lite::null_popper
Definition: ring_span.hpp:366
nonstd::ring_span_lite::detail::ring_iterator::difference_type
std::ptrdiff_t difference_type
Definition: ring_span.hpp:846
nonstd::ring_span_lite::ring_span::front
reference front() nsrs_noexcept
Definition: ring_span.hpp:526
nonstd::ring_span_lite::ring_span::back
reference back() nsrs_noexcept
Definition: ring_span.hpp:536
nonstd::ring_span_lite::ring_span::rend
reverse_iterator rend() nsrs_noexcept
Definition: ring_span.hpp:585
nonstd::ring_span_lite::ring_span::full
bool full() const nsrs_noexcept
Definition: ring_span.hpp:495
nonstd::ring_span_lite::ring_span::push_back
void push_back(value_type const &value)
Definition: ring_span.hpp:639
nonstd::ring_span_lite::ring_span::m_capacity
size_type m_capacity
Definition: ring_span.hpp:811
nonstd::ring_span_lite::ring_span::const_reverse_iterator
std::reverse_iterator< const_iterator > const_reverse_iterator
Definition: ring_span.hpp:449
nonstd::ring_span_lite::detail::ring_iterator::iterator_category
std::random_access_iterator_tag iterator_category
Definition: ring_span.hpp:853
nonstd::ring_span_lite::ring_span::m_front_idx
size_type m_front_idx
Definition: ring_span.hpp:812
nonstd::ring_span_lite::default_popper
Definition: ring_span.hpp:376
nonstd::ring_span_lite::ring_span
Definition: ring_span.hpp:432
nonstd::ring_span_lite::ring_span::pop_front
Popper::return_type pop_front()
Definition: ring_span.hpp:613
nonstd::ring_span_lite::ring_span::cbegin
const_iterator cbegin() const nsrs_noexcept
Definition: ring_span.hpp:558
nonstd::ring_span_lite::ring_span::crbegin
const_reverse_iterator crbegin() const nsrs_noexcept
Definition: ring_span.hpp:600
nonstd::ring_span_lite::ring_span::end
iterator end() nsrs_noexcept
Definition: ring_span.hpp:563
nonstd::ring_span_lite::ring_span::m_popper
Popper m_popper
Definition: ring_span.hpp:813
nonstd::ring_span_lite::detail::ring_iterator::ring_iterator
ring_iterator(size_type idx, typename std11::conditional< is_const, const RS, RS >::type *rs) nsrs_noexcept
Definition: ring_span.hpp:988
nonstd::ring_span_lite::swap
void swap(ring_span< T, Popper > &lhs, ring_span< T, Popper > &rhs) nsrs_noexcept_op(nsrs_noexcept_op(lhs.swap(rhs)))
Definition: ring_span.hpp:819
udp_client.args
args
Definition: udp_client.py:12
nonstd::ring_span_lite::detail::ring_iterator::operator<
bool operator<(ring_iterator< RS, C > const &rhs) const nsrs_noexcept
Definition: ring_span.hpp:941
nonstd::ring_span_lite::ring_span::operator[]
reference operator[](size_type idx) nsrs_noexcept
Definition: ring_span.hpp:513
nonstd::ring_span_lite::detail::ring_iterator::operator!=
bool operator!=(ring_iterator< RS, C > const &rhs) const nsrs_noexcept
Definition: ring_span.hpp:957


plotjuggler
Author(s): Davide Faconti
autogenerated on Sun Aug 11 2024 02:24:25