]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/histogram/axis/interval_view.hpp
2838ce0f8dde4de88d8201dc57fe6b712a6ee2be
[ceph.git] / ceph / src / boost / boost / histogram / axis / interval_view.hpp
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 namespace boost {
11 namespace histogram {
12 namespace axis {
13
14 /**
15 Lightweight bin view.
16
17 Represents the current bin interval.
18 */
19 template <typename Axis>
20 class interval_view {
21 public:
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;
25
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(); }
34
35 template <typename BinType>
36 bool operator==(const BinType& rhs) const noexcept {
37 return lower() == rhs.lower() && upper() == rhs.upper();
38 }
39
40 template <typename BinType>
41 bool operator!=(const BinType& rhs) const noexcept {
42 return !operator==(rhs);
43 }
44
45 private:
46 const Axis& axis_;
47 const int idx_;
48 };
49
50 } // namespace axis
51 } // namespace histogram
52 } // namespace boost
53
54 #endif