1 // Copyright 2015-2019 Hans Dembinski
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)
7 #ifndef BOOST_HISTOGRAM_AXIS_INTERVAL_VIEW_HPP
8 #define BOOST_HISTOGRAM_AXIS_INTERVAL_VIEW_HPP
17 Represents the current bin interval.
19 template <typename Axis>
22 interval_view(const Axis& axis, int idx) : axis_(axis), idx_(idx) {}
23 // avoid viewing a temporary that goes out of scope
24 interval_view(Axis&& axis, int idx) = delete;
26 /// Return lower edge of bin.
27 decltype(auto) lower() const noexcept { return axis_.value(idx_); }
28 /// Return upper edge of bin.
29 decltype(auto) upper() const noexcept { return axis_.value(idx_ + 1); }
30 /// Return center of bin.
31 decltype(auto) center() const noexcept { return axis_.value(idx_ + 0.5); }
32 /// Return width of bin.
33 decltype(auto) width() const noexcept { return upper() - lower(); }
35 template <typename BinType>
36 bool operator==(const BinType& rhs) const noexcept {
37 return lower() == rhs.lower() && upper() == rhs.upper();
40 template <typename BinType>
41 bool operator!=(const BinType& rhs) const noexcept {
42 return !operator==(rhs);
51 } // namespace histogram