| Home | Libraries | People | FAQ | More

## Class template count

boost::histogram::accumulators::count — Wraps a C++ arithmetic type with optionally thread-safe increments and adds.

## Synopsis

    // 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;

      // public member functions
      count();
      count(const_reference) noexcept;
      template<typename T, bool B> count(const count< T, B > &) noexcept;
      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 bool thread_safe() noexcept;
    };

## Description

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), use`accumulators::weighted_sum`.

### Template Parameters

1.     typename ValueType

2.     bool ThreadSafe

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

### `count` public member functions

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.

4.     count & operator++() noexcept;

   Increment count by one.

5.     count & operator+=(const_reference value) noexcept;

   Increment count by value.

6.     count & operator+=(const count & s) noexcept;

   Add another count.

7.     count & operator*=(const_reference value) noexcept;

   Scale by value.

8.     bool operator==(const count & rhs) const noexcept;

9.     bool operator!=(const count & rhs) const noexcept;

10.     value_type value() const noexcept;

    Return count.

11.     explicit operator value_type() const noexcept;

12.     template<typename Archive> void serialize(Archive & ar, unsigned);

13.     count & operator*=(const count & rhs) noexcept;

14.     count operator*(const count & rhs) const noexcept;

15.     count & operator/=(const count & rhs) noexcept;

16.     count operator/(const count & rhs) const noexcept;

17.     bool operator<(const count & rhs) const noexcept;

18.     bool operator>(const count & rhs) const noexcept;

19.     bool operator<=(const count & rhs) const noexcept;

20.     bool operator>=(const count & rhs) const noexcept;

### `count` public static functions

1.     static bool thread_safe() noexcept;