1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- #ifndef BOOST_HISTOGRAM_AXIS_POLYMORPHIC_BIN_HPP
- #define BOOST_HISTOGRAM_AXIS_POLYMORPHIC_BIN_HPP
- namespace boost {
- namespace histogram {
- namespace axis {
- template <class RealType>
- class polymorphic_bin {
- using value_type = RealType;
- public:
- polymorphic_bin(value_type lower, value_type upper)
- : lower_or_value_(lower), upper_(upper) {}
-
- operator const value_type&() const noexcept { return lower_or_value_; }
-
- value_type lower() const noexcept { return lower_or_value_; }
-
- value_type upper() const noexcept { return upper_; }
-
- value_type center() const noexcept { return 0.5 * (lower() + upper()); }
-
- value_type width() const noexcept { return upper() - lower(); }
- template <class BinType>
- bool operator==(const BinType& rhs) const noexcept {
- return equal_impl(rhs, 0);
- }
- template <class BinType>
- bool operator!=(const BinType& rhs) const noexcept {
- return !operator==(rhs);
- }
-
- bool is_discrete() const noexcept { return lower_or_value_ == upper_; }
- private:
- bool equal_impl(const polymorphic_bin& rhs, int) const noexcept {
- return lower_or_value_ == rhs.lower_or_value_ && upper_ == rhs.upper_;
- }
- template <class BinType>
- auto equal_impl(const BinType& rhs, decltype(rhs.lower(), 0)) const noexcept {
- return lower() == rhs.lower() && upper() == rhs.upper();
- }
- template <class BinType>
- bool equal_impl(const BinType& rhs, float) const noexcept {
- return is_discrete() && static_cast<value_type>(*this) == rhs;
- }
- const value_type lower_or_value_, upper_;
- };
- }
- }
- }
- #endif
|