Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:38:10

0001 // Copyright 2015-2017 Hans Dembinski
0002 //
0003 // Distributed under the Boost Software License, Version 1.0.
0004 // (See accompanying file LICENSE_1_0.txt
0005 // or copy at http://www.boost.org/LICENSE_1_0.txt)
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   /// Make iterator from axis and index.
0025   iterator(const Axis& axis, index_type idx)
0026       : iterator::iterator_adaptor_(idx), axis_(axis) {}
0027 
0028   /// Return current bin object.
0029   reference operator*() const { return axis_.bin(this->base()); }
0030 
0031 private:
0032   const Axis& axis_;
0033 };
0034 
0035 /// Uses CRTP to inject iterator logic into Derived.
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   /// Bin iterator to beginning of the axis (read-only).
0043   const_iterator begin() const noexcept {
0044     return const_iterator(*static_cast<const Derived*>(this), 0);
0045   }
0046 
0047   /// Bin iterator to the end of the axis (read-only).
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   /// Reverse bin iterator to the last entry of the axis (read-only).
0054   const_reverse_iterator rbegin() const noexcept {
0055     return std::make_reverse_iterator(end());
0056   }
0057 
0058   /// Reverse bin iterator to the end (read-only).
0059   const_reverse_iterator rend() const noexcept {
0060     return std::make_reverse_iterator(begin());
0061   }
0062 };
0063 
0064 } // namespace axis
0065 } // namespace histogram
0066 } // namespace boost
0067 
0068 #endif