File indexing completed on 2025-01-18 09:38:10
0001
0002
0003
0004
0005
0006
0007 #ifndef BOOST_HISTOGRAM_AXIS_ITERATOR_HPP
0008 #define BOOST_HISTOGRAM_AXIS_ITERATOR_HPP
0009
0010 #include <boost/histogram/axis/interval_view.hpp>
0011 #include <boost/histogram/detail/iterator_adaptor.hpp>
0012 #include <iterator>
0013
0014 namespace boost {
0015 namespace histogram {
0016 namespace axis {
0017
0018 template <class Axis>
0019 class iterator : public detail::iterator_adaptor<iterator<Axis>, index_type,
0020 decltype(std::declval<Axis>().bin(0))> {
0021 public:
0022 using reference = typename iterator::iterator_adaptor_::reference;
0023
0024
0025 iterator(const Axis& axis, index_type idx)
0026 : iterator::iterator_adaptor_(idx), axis_(axis) {}
0027
0028
0029 reference operator*() const { return axis_.bin(this->base()); }
0030
0031 private:
0032 const Axis& axis_;
0033 };
0034
0035
0036 template <class Derived>
0037 class iterator_mixin {
0038 public:
0039 using const_iterator = iterator<Derived>;
0040 using const_reverse_iterator = std::reverse_iterator<const_iterator>;
0041
0042
0043 const_iterator begin() const noexcept {
0044 return const_iterator(*static_cast<const Derived*>(this), 0);
0045 }
0046
0047
0048 const_iterator end() const noexcept {
0049 return const_iterator(*static_cast<const Derived*>(this),
0050 static_cast<const Derived*>(this)->size());
0051 }
0052
0053
0054 const_reverse_iterator rbegin() const noexcept {
0055 return std::make_reverse_iterator(end());
0056 }
0057
0058
0059 const_reverse_iterator rend() const noexcept {
0060 return std::make_reverse_iterator(begin());
0061 }
0062 };
0063
0064 }
0065 }
0066 }
0067
0068 #endif