Back to home page

EIC code displayed by LXR

 
 

    


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

0001 // Copyright 2015-2019 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_INTERVAL_VIEW_HPP
0008 #define BOOST_HISTOGRAM_AXIS_INTERVAL_VIEW_HPP
0009 
0010 #include <boost/histogram/fwd.hpp>
0011 
0012 namespace boost {
0013 namespace histogram {
0014 namespace axis {
0015 
0016 /**
0017   Lightweight bin view.
0018 
0019   Represents the current bin interval.
0020 */
0021 template <class Axis>
0022 class interval_view {
0023 public:
0024   interval_view(const Axis& axis, index_type idx) : axis_(axis), idx_(idx) {}
0025   // avoid viewing a temporary that goes out of scope
0026   interval_view(Axis&& axis, index_type idx) = delete;
0027 
0028   /// Return lower edge of bin.
0029   decltype(auto) lower() const noexcept { return axis_.value(idx_); }
0030   /// Return upper edge of bin.
0031   decltype(auto) upper() const noexcept { return axis_.value(idx_ + 1); }
0032   /// Return center of bin.
0033   decltype(auto) center() const noexcept { return axis_.value(idx_ + 0.5); }
0034   /// Return width of bin.
0035   decltype(auto) width() const noexcept { return upper() - lower(); }
0036 
0037   template <class BinType>
0038   bool operator==(const BinType& rhs) const noexcept {
0039     return lower() == rhs.lower() && upper() == rhs.upper();
0040   }
0041 
0042   template <class BinType>
0043   bool operator!=(const BinType& rhs) const noexcept {
0044     return !operator==(rhs);
0045   }
0046 
0047 private:
0048   const Axis& axis_;
0049   const index_type idx_;
0050 };
0051 
0052 } // namespace axis
0053 } // namespace histogram
0054 } // namespace boost
0055 
0056 #endif