...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::category — Maps at a set of unique values to bin indices.
// In header: <boost/histogram/axis/category.hpp> template<typename Value, typename MetaData, typename Options, typename Allocator> class category : public boost::histogram::axis::iterator_mixin< category< Value, MetaData, Options, Allocator > > { public: // construct/copy/destruct explicit category(allocator_type = {}); category(const category &) = default; category(category &&) noexcept; template<typename It> category(It, It, metadata_type = {}, allocator_type = {}); template<typename C> category(const C &, metadata_type = {}, allocator_type = {}); template<typename U> category(std::initializer_list< U >, metadata_type = {}, allocator_type = {}); category & operator=(const category &) = default; category & operator=(category &&) noexcept; // public member functions index_type index(const value_type &) const noexcept; auto update(const value_type &); decltype(auto) value(index_type) const; decltype(auto) bin(index_type) const noexcept; index_type size() const noexcept; metadata_type & metadata() noexcept; const metadata_type & metadata() const noexcept; template<typename V, typename M, typename O, typename A> bool operator==(const category< V, M, O, A > &) const noexcept; template<typename V, typename M, typename O, typename A> bool operator!=(const category< V, M, O, A > &) const noexcept; auto get_allocator() const; template<typename Archive> void serialize(Archive &, unsigned); // public static functions static constexpr unsigned options() noexcept; };
The axis maps a set of values to bins, following the order of arguments in the constructor. The optional overflow bin for this axis counts input values that are not part of the set. Binning has O(N) complexity, but with a very small factor. For small N (the typical use case) it beats other kinds of lookup.
The options underflow
and circular
are not allowed. The options growth
and overflow
are mutually exclusive.
typename Value
input value type, must be equal-comparable.
typename MetaData
type to store meta data.
typename Options
see boost::histogram::axis::option.
typename Allocator
allocator to use for dynamic memory management.
category
public
construct/copy/destructexplicit category(allocator_type alloc = {});
category(const category &) = default;
category(category && o) noexcept;
template<typename It> category(It begin, It end, metadata_type meta = {}, allocator_type alloc = {});Construct from iterator range of unique values.
Parameters: |
|
template<typename C> category(const C & iterable, metadata_type meta = {}, allocator_type alloc = {});Construct axis from iterable sequence of unique values.
Parameters: |
|
template<typename U> category(std::initializer_list< U > list, metadata_type meta = {}, allocator_type alloc = {});Construct axis from an initializer list of unique values.
Parameters: |
|
category & operator=(const category &) = default;
category & operator=(category && o) noexcept;
category
public member functionsindex_type index(const value_type & x) const noexcept;Return index for value argument.
auto update(const value_type & x);Returns index and shift (if axis has grown) for the passed argument.
decltype(auto) value(index_type idx) const;Return value for index argument.
Throws std::out_of_range
if the index is out of bounds.
decltype(auto) bin(index_type idx) const noexcept;Return value for index argument.
index_type size() const noexcept;Returns the number of bins, without over- or underflow.
metadata_type & metadata() noexcept;Returns reference to metadata.
const metadata_type & metadata() const noexcept;Returns reference to const metadata.
template<typename V, typename M, typename O, typename A> bool operator==(const category< V, M, O, A > & o) const noexcept;
template<typename V, typename M, typename O, typename A> bool operator!=(const category< V, M, O, A > & o) const noexcept;
auto get_allocator() const;
template<typename Archive> void serialize(Archive &, unsigned);