...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 a axis::variant.
// In header: <boost/histogram/axis/polymorphic_bin.hpp> template<typename RealType> class polymorphic_bin { public: // construct/copy/destruct polymorphic_bin(value_type, value_type); // public member functions 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; // private member functions bool equal_impl(std::true_type, const polymorphic_bin &) const noexcept; template<typename BinType> bool equal_impl(std::true_type, const BinType &) const noexcept; template<typename BinType> bool equal_impl(std::false_type, const BinType &) const noexcept; };
The interface is a superset of the value_bin_view
and interval_bin_view
classes. The methods value() and lower() return the same number. For a value bin, upper() and lower() and center() return the same number, width() returns zero.
This is not a view like interval_bin_view or value_bin_view for two reasons.
Sequential calls to lower() and upper() 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 of axis::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 here.
polymorphic_bin
public member functionsoperator 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.
polymorphic_bin
private member functionsbool equal_impl(std::true_type, const polymorphic_bin & rhs) const noexcept;
template<typename BinType> bool equal_impl(std::true_type, const BinType & rhs) const noexcept;
template<typename BinType> bool equal_impl(std::false_type, const BinType & rhs) const noexcept;