]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/histogram/axis/iterator.hpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / boost / histogram / axis / iterator.hpp
1 // Copyright 2015-2017 Hans Dembinski
2 //
3 // Distributed under the Boost Software License, Version 1.0.
4 // (See accompanying file LICENSE_1_0.txt
5 // or copy at http://www.boost.org/LICENSE_1_0.txt)
6
7 #ifndef BOOST_HISTOGRAM_AXIS_ITERATOR_HPP
8 #define BOOST_HISTOGRAM_AXIS_ITERATOR_HPP
9
10 #include <boost/histogram/axis/interval_view.hpp>
11 #include <boost/histogram/detail/iterator_adaptor.hpp>
12 #include <iterator>
13
14 namespace boost {
15 namespace histogram {
16 namespace axis {
17
18 template <class Axis>
19 class iterator : public detail::iterator_adaptor<iterator<Axis>, int,
20 decltype(std::declval<Axis>().bin(0))> {
21 public:
22 /// Make iterator from axis and index.
23 iterator(const Axis& axis, int idx) : iterator::iterator_adaptor_(idx), axis_(axis) {}
24
25 /// Return current bin object.
26 decltype(auto) operator*() const { return axis_.bin(this->base()); }
27
28 private:
29 const Axis& axis_;
30 };
31
32 /// Uses CRTP to inject iterator logic into Derived.
33 template <typename Derived>
34 class iterator_mixin {
35 public:
36 using const_iterator = iterator<Derived>;
37 using const_reverse_iterator = std::reverse_iterator<const_iterator>;
38
39 /// Bin iterator to beginning of the axis (read-only).
40 const_iterator begin() const noexcept {
41 return const_iterator(*static_cast<const Derived*>(this), 0);
42 }
43
44 /// Bin iterator to the end of the axis (read-only).
45 const_iterator end() const noexcept {
46 return const_iterator(*static_cast<const Derived*>(this),
47 static_cast<const Derived*>(this)->size());
48 }
49
50 /// Reverse bin iterator to the last entry of the axis (read-only).
51 const_reverse_iterator rbegin() const noexcept {
52 return std::make_reverse_iterator(end());
53 }
54
55 /// Reverse bin iterator to the end (read-only).
56 const_reverse_iterator rend() const noexcept {
57 return std::make_reverse_iterator(begin());
58 }
59 };
60
61 } // namespace axis
62 } // namespace histogram
63 } // namespace boost
64
65 #endif