Boost C++ Libraries of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is the documentation for an old version of Boost. Click here to view this page for the latest version.

Class template count

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 {
  // types
  typedef ValueType          value_type;     
  typedef const value_type & const_reference;

  // construct/copy/destruct
  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 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.

Template Parameters

  1. typename ValueType
  2. bool ThreadSafe

    Set to true to make increments and adds thread-safe.

count public construct/copy/destruct

  1. count();
  2. count(const_reference value) noexcept;
    Initialize count to value and allow implicit conversion.
  3. template<typename T, bool B> count(const count< T, B > & c) noexcept;
    Allow implicit conversion from other count.

count public member functions

  1. count & operator++() noexcept;
    Increment count by one.
  2. count & operator+=(const_reference value) noexcept;
    Increment count by value.
  3. count & operator+=(const count & s) noexcept;
    Add another count.
  4. count & operator *=(const_reference value) noexcept;
    Scale by value.
  5. bool operator==(const count & rhs) const noexcept;
  6. bool operator!=(const count & rhs) const noexcept;
  7. value_type value() const noexcept;
    Return count.
  8. explicit operator value_type() const noexcept;
  9. template<typename Archive> void serialize(Archive & ar, unsigned);
  10. count & operator *=(const count & rhs) noexcept;
  11. count operator *(const count & rhs) const noexcept;
  12. count & operator/=(const count & rhs) noexcept;
  13. count operator/(const count & rhs) const noexcept;
  14. bool operator<(const count & rhs) const noexcept;
  15. bool operator>(const count & rhs) const noexcept;
  16. bool operator<=(const count & rhs) const noexcept;
  17. bool operator>=(const count & rhs) const noexcept;

count public static functions

  1. static constexpr bool thread_safe() noexcept;