• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2015-2019 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_INTERVAL_VIEW_HPP
8 #define BOOST_HISTOGRAM_AXIS_INTERVAL_VIEW_HPP
9 
10 #include <boost/histogram/fwd.hpp>
11 
12 namespace boost {
13 namespace histogram {
14 namespace axis {
15 
16 /**
17   Lightweight bin view.
18 
19   Represents the current bin interval.
20 */
21 template <class Axis>
22 class interval_view {
23 public:
interval_view(const Axis & axis,index_type idx)24   interval_view(const Axis& axis, index_type idx) : axis_(axis), idx_(idx) {}
25   // avoid viewing a temporary that goes out of scope
26   interval_view(Axis&& axis, index_type idx) = delete;
27 
28   /// Return lower edge of bin.
lower() const29   decltype(auto) lower() const noexcept { return axis_.value(idx_); }
30   /// Return upper edge of bin.
upper() const31   decltype(auto) upper() const noexcept { return axis_.value(idx_ + 1); }
32   /// Return center of bin.
center() const33   decltype(auto) center() const noexcept { return axis_.value(idx_ + 0.5); }
34   /// Return width of bin.
width() const35   decltype(auto) width() const noexcept { return upper() - lower(); }
36 
37   template <class BinType>
operator ==(const BinType & rhs) const38   bool operator==(const BinType& rhs) const noexcept {
39     return lower() == rhs.lower() && upper() == rhs.upper();
40   }
41 
42   template <class BinType>
operator !=(const BinType & rhs) const43   bool operator!=(const BinType& rhs) const noexcept {
44     return !operator==(rhs);
45   }
46 
47 private:
48   const Axis& axis_;
49   const index_type idx_;
50 };
51 
52 } // namespace axis
53 } // namespace histogram
54 } // namespace boost
55 
56 #endif
57