...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::accumulators::count — Wraps a C++ arithmetic type with optionally thread-safe increments and adds.
// In header: <boost/histogram/accumulators/count.hpp> template<typename ValueType, bool ThreadSafe> class count { public: // types typedef ValueType value_type; typedef const value_type & const_reference; // construct/copy/destruct count(); count(const_reference) noexcept; template<typename T, bool B> count(const count< T, B > &) noexcept; // public member functions count & operator++() noexcept; count & operator+=(const_reference) noexcept; count & operator+=(const count &) noexcept; count & operator *=(const_reference) noexcept; bool operator==(const count &) const noexcept; bool operator!=(const count &) const noexcept; value_type value() const noexcept; explicit operator value_type() const noexcept; template<typename Archive> void serialize(Archive &, unsigned); count & operator *=(const count &) noexcept; count operator *(const count &) const noexcept; count & operator/=(const count &) noexcept; count operator/(const count &) const noexcept; bool operator<(const count &) const noexcept; bool operator>(const count &) const noexcept; bool operator<=(const count &) const noexcept; bool operator>=(const count &) const noexcept; // public static functions static constexpr bool thread_safe() noexcept; };
This adaptor optionally uses atomic operations to make concurrent increments and additions thread-safe for the stored arithmetic value, which can be integral or floating point. For small histograms, the performance will still be poor because of False Sharing, see https://en.wikipedia.org/wiki/False_sharing for details.
Warning: Assignment is not thread-safe in this implementation, so don't assign concurrently.
This wrapper class can be used as a base class by users to add arbitrary metadata to each bin of a histogram.
When weighted samples are accumulated and high precision is required, use accumulators::sum
instead (at the cost of lower performance). If a local variance estimate for the weight distribution should be computed as well (generally needed for a detailed statistical analysis), useaccumulators::weighted_sum
.
typename ValueType
bool ThreadSafe
Set to true to make increments and adds thread-safe.
count
public
construct/copy/destructcount();
count(const_reference value) noexcept;Initialize count to value and allow implicit conversion.
template<typename T, bool B> count(const count< T, B > & c) noexcept;Allow implicit conversion from other count.
count
public member functionscount & operator++() noexcept;Increment count by one.
count & operator+=(const_reference value) noexcept;Increment count by value.
count & operator+=(const count & s) noexcept;Add another count.
count & operator *=(const_reference value) noexcept;Scale by value.
bool operator==(const count & rhs) const noexcept;
bool operator!=(const count & rhs) const noexcept;
value_type value() const noexcept;Return count.
explicit operator value_type() const noexcept;
template<typename Archive> void serialize(Archive & ar, unsigned);
count & operator *=(const count & rhs) noexcept;
count operator *(const count & rhs) const noexcept;
count & operator/=(const count & rhs) noexcept;
count operator/(const count & rhs) const noexcept;
bool operator<(const count & rhs) const noexcept;
bool operator>(const count & rhs) const noexcept;
bool operator<=(const count & rhs) const noexcept;
bool operator>=(const count & rhs) const noexcept;