...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
boost::histogram::axis::polymorphic_bin — Holds the bin data of an axis::variant.
// In header: <boost/histogram/axis/polymorphic_bin.hpp> template<typename RealType> class polymorphic_bin { public: // public member functions polymorphic_bin(value_type, value_type); operator const value_type &() const noexcept; value_type lower() const noexcept; value_type upper() const noexcept; value_type center() const noexcept; value_type width() const noexcept; template<typename BinType> bool operator==(const BinType &) const noexcept; template<typename BinType> bool operator!=(const BinType &) const noexcept; bool is_discrete() const noexcept; };
The interface is a superset of the axis::interval_view class. In addition, the object is implicitly convertible to the value type, returning the equivalent of a call tolower(). For discrete axes,lower() ==upper(), andwidth() returns zero.
This is not a view like axis::interval_view for two reasons.
Sequential calls to lower() andupper() would have to each loop through the variant types. This is likely to be slower than filling all the data in one loop.
polymorphic_bin may be created from a temporary instance ofaxis::variant, like in the call histogram::axis(0). Storing a reference to the axis would result in a dangling reference. Rather than specialing the code to handle this, it seems easier to just use a value instead of a view.
polymorphic_bin
public member functionspolymorphic_bin(value_type lower, value_type upper);
operator const value_type &() const noexcept;Implicitly convert to bin value (for axis with discrete values).
value_type lower() const noexcept;Return lower edge of bin.
value_type upper() const noexcept;Return upper edge of bin.
value_type center() const noexcept;Return center of bin.
value_type width() const noexcept;Return width of bin.
template<typename BinType> bool operator==(const BinType & rhs) const noexcept;
template<typename BinType> bool operator!=(const BinType & rhs) const noexcept;
bool is_discrete() const noexcept;Return true if bin is discrete.