Boost C++ Libraries

...one 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.
PrevUpHomeNext

Class template histogram

boost::histogram::histogram — Central class of the histogram library.

Synopsis

// In header: <boost/histogram/histogram.hpp>

template<typename Axes, typename Storage> 
class histogram {
public:
  // types
  typedef Axes                                  axes_type;     
  typedef Storage                               storage_type;  
  typedef typename storage_type::value_type     value_type;    
  typedef typename storage_type::iterator       iterator;      
  typedef typename storage_type::const_iterator const_iterator;

  // construct/copy/destruct
  histogram() = default;
  histogram(const histogram &) = default;
  histogram(histogram &&) = default;
  template<typename A, typename S> explicit histogram(histogram< A, S > &&);
  template<typename A, typename S> 
    explicit histogram(const histogram< A, S > &);
  template<typename A, typename S> histogram(A &&, S &&);
  template<typename A, typename  = detail::requires_axes<A> > 
    explicit histogram(A &&);
  histogram & operator=(const histogram &) = default;
  histogram & operator=(histogram &&) = default;
  template<typename A, typename S> histogram & operator=(histogram< A, S > &&);
  template<typename A, typename S> 
    histogram & operator=(const histogram< A, S > &);

  // public member functions
  constexpr unsigned rank() const noexcept;
  std::size_t size() const noexcept;
  void reset();
  template<unsigned N = 0> 
    decltype(auto) axis(std::integral_constant< unsigned, N > = {}) const;
  decltype(auto) axis(unsigned) const;
  template<typename Unary> auto for_each_axis(Unary &&) const;
  template<class... Ts> auto operator()(const Ts &...);
  template<class... Ts> auto operator()(const std::tuple< Ts... > &);
  template<class... Ts> decltype(auto) at(axis::index_type, Ts...);
  template<class... Ts> decltype(auto) at(axis::index_type, Ts...) const;
  template<typename... Ts> decltype(auto) at(const std::tuple< Ts... > &);
  template<typename... Ts> 
    decltype(auto) at(const std::tuple< Ts... > &) const;
  template<typename Iterable, 
           typename  = detail::requires_iterable<Iterable> > 
    decltype(auto) at(const Iterable &);
  template<typename Iterable, 
           typename  = detail::requires_iterable<Iterable> > 
    decltype(auto) at(const Iterable &) const;
  template<typename T> decltype(auto) operator[](const T &);
  template<typename T> decltype(auto) operator[](const T &) const;
  template<typename A, typename S> 
    bool operator==(const histogram< A, S > &) const noexcept;
  template<typename A, typename S> 
    bool operator!=(const histogram< A, S > &) const noexcept;
  template<typename A, typename S> 
    histogram & operator+=(const histogram< A, S > &);
  template<typename A, typename S> 
    histogram & operator-=(const histogram< A, S > &);
  template<typename A, typename S> 
    histogram & operator *=(const histogram< A, S > &);
  template<typename A, typename S> 
    histogram & operator/=(const histogram< A, S > &);
  template<typename V = value_type, 
           typename  = std::enable_if_t<detail::has_operator_rmul<V, double>::value> > 
    histogram & operator *=(const double);
  template<typename V = value_type, 
           typename  = std::enable_if_t<detail::has_operator_rmul<V, double>::value> > 
    histogram & operator/=(const double);
  iterator begin() noexcept;
  iterator end() noexcept;
  const_iterator begin() const noexcept;
  const_iterator end() const noexcept;
  const_iterator cbegin() const noexcept;
  const_iterator cend() const noexcept;
};

Description

Histogram uses the call operator to insert data, like the Boost.Accumulators.

Use factory functions (see make_histogram.hpp and make_profile.hpp) to conveniently create histograms rather than calling the ctors directly.

Use the indexed range generator to iterate over filled histograms, which is convenient and faster than hand-written loops for multi-dimensional histograms.

Template Parameters

  1. typename Axes

    std::tuple of axis types OR std::vector of an axis type or axis::variant

  2. typename Storage

    class that implements the storage interface

histogram public construct/copy/destruct

  1. histogram() = default;
  2. histogram(const histogram & rhs) = default;
  3. histogram(histogram && rhs) = default;
  4. template<typename A, typename S> explicit histogram(histogram< A, S > && rhs);
  5. template<typename A, typename S> 
      explicit histogram(const histogram< A, S > & rhs);
  6. template<typename A, typename S> histogram(A && a, S && s);
  7. template<typename A, typename  = detail::requires_axes<A> > 
      explicit histogram(A && a);
  8. histogram & operator=(const histogram & rhs) = default;
  9. histogram & operator=(histogram && rhs) = default;
  10. template<typename A, typename S> 
      histogram & operator=(histogram< A, S > && rhs);
  11. template<typename A, typename S> 
      histogram & operator=(const histogram< A, S > & rhs);

histogram public member functions

  1. constexpr unsigned rank() const noexcept;
    Number of axes (dimensions).
  2. std::size_t size() const noexcept;
    Total number of bins (including underflow/overflow).
  3. void reset();
    Reset all bins to default initialized values.
  4. template<unsigned N = 0> 
      decltype(auto) axis(std::integral_constant< unsigned, N > = {}) const;
    Get N-th axis using a compile-time number.

    This version is more efficient than the one accepting a run-time number.

  5. decltype(auto) axis(unsigned i) const;
    Get N-th axis with run-time number.

    Use version that accepts a compile-time number, if possible.

  6. template<typename Unary> auto for_each_axis(Unary && unary) const;
    Apply unary functor/function to each axis.
  7. template<class... Ts> auto operator()(const Ts &... ts);
    Fill histogram with values, an optional weight, and/or a sample.

    Arguments are passed in order to the axis objects. Passing an argument type that is not convertible to the value type accepted by the axis or passing the wrong number of arguments causes a throw of std::invalid_argument.

    Axis with multiple arguments

    If the histogram contains an axis which accepts a std::tuple of arguments, the arguments for that axis need to passed as a std::tuple, for example, std::make_tuple(1.2, 2.3). If the histogram contains only this axis and no other, the arguments can be passed directly.

    Optional weight

    An optional weight can be passed as the first or last argument with the weight helper function. Compilation fails if the storage elements do not support weights.

    Samples

    If the storage elements accept samples, pass them with the sample helper function in addition to the axis arguments, which can be the first or last argument. The sample helper function can pass one or more arguments to the storage element. If samples and weights are used together, they can be passed in any order at the beginning or end of the argument list.

  8. template<class... Ts> auto operator()(const std::tuple< Ts... > & t);
    Fill histogram with values, an optional weight, and/or a sample from a std::tuple.
  9. template<class... Ts> decltype(auto) at(axis::index_type t, Ts... ts);
    Access cell value at integral indices.

    You can pass indices as individual arguments, as a std::tuple of integers, or as an interable range of integers. Passing the wrong number of arguments causes a throw of std::invalid_argument. Passing an index which is out of bounds causes a throw of std::out_of_range.

  10. template<class... Ts> decltype(auto) at(axis::index_type t, Ts... ts) const;
    Access cell value at integral indices (read-only).

    Access cell value at integral indices. You can pass indices as individual arguments, as a std::tuple of integers, or as an interable range of integers. Passing the wrong number of arguments causes a throw of std::invalid_argument. Passing an index which is out of bounds causes a throw of std::out_of_range.

  11. template<typename... Ts> decltype(auto) at(const std::tuple< Ts... > & t);
    Access cell value at integral indices stored in std::tuple.

    Access cell value at integral indices. You can pass indices as individual arguments, as a std::tuple of integers, or as an interable range of integers. Passing the wrong number of arguments causes a throw of std::invalid_argument. Passing an index which is out of bounds causes a throw of std::out_of_range.

  12. template<typename... Ts> 
      decltype(auto) at(const std::tuple< Ts... > & t) const;
    Access cell value at integral indices stored in std::tuple (read-only).

    Access cell value at integral indices. You can pass indices as individual arguments, as a std::tuple of integers, or as an interable range of integers. Passing the wrong number of arguments causes a throw of std::invalid_argument. Passing an index which is out of bounds causes a throw of std::out_of_range.

  13. template<typename Iterable, typename  = detail::requires_iterable<Iterable> > 
      decltype(auto) at(const Iterable & c);
    Access cell value at integral indices stored in iterable.

    Access cell value at integral indices. You can pass indices as individual arguments, as a std::tuple of integers, or as an interable range of integers. Passing the wrong number of arguments causes a throw of std::invalid_argument. Passing an index which is out of bounds causes a throw of std::out_of_range.

  14. template<typename Iterable, typename  = detail::requires_iterable<Iterable> > 
      decltype(auto) at(const Iterable & c) const;
    Access cell value at integral indices stored in iterable (read-only).

    Access cell value at integral indices. You can pass indices as individual arguments, as a std::tuple of integers, or as an interable range of integers. Passing the wrong number of arguments causes a throw of std::invalid_argument. Passing an index which is out of bounds causes a throw of std::out_of_range.

  15. template<typename T> decltype(auto) operator[](const T & t);
    Access value at index (number for rank = 1, else std::tuple or iterable).
  16. template<typename T> decltype(auto) operator[](const T & t) const;
    Access value at index (number for rank = 1, else std::tuple or iterable).
  17. template<typename A, typename S> 
      bool operator==(const histogram< A, S > & rhs) const noexcept;
    Equality operator, tests equality for all axes and the storage.
  18. template<typename A, typename S> 
      bool operator!=(const histogram< A, S > & rhs) const noexcept;
    Negation of the equality operator.
  19. template<typename A, typename S> 
      histogram & operator+=(const histogram< A, S > & rhs);
    Add values of another histogram.
  20. template<typename A, typename S> 
      histogram & operator-=(const histogram< A, S > & rhs);
    Subtract values of another histogram.
  21. template<typename A, typename S> 
      histogram & operator *=(const histogram< A, S > & rhs);
    Multiply by values of another histogram.
  22. template<typename A, typename S> 
      histogram & operator/=(const histogram< A, S > & rhs);
    Divide by values of another histogram.
  23. template<typename V = value_type, 
             typename  = std::enable_if_t<detail::has_operator_rmul<V, double>::value> > 
      histogram & operator *=(const double x);
    Multiply all values with a scalar.
  24. template<typename V = value_type, 
             typename  = std::enable_if_t<detail::has_operator_rmul<V, double>::value> > 
      histogram & operator/=(const double x);
    Divide all values by a scalar.
  25. iterator begin() noexcept;
    Return value iterator to the beginning of the histogram.
  26. iterator end() noexcept;
    Return value iterator to the end in the histogram.
  27. const_iterator begin() const noexcept;
    Return value iterator to the beginning of the histogram (read-only).
  28. const_iterator end() const noexcept;
    Return value iterator to the end in the histogram (read-only).
  29. const_iterator cbegin() const noexcept;
    Return value iterator to the beginning of the histogram (read-only).
  30. const_iterator cend() const noexcept;
    Return value iterator to the end in the histogram (read-only).

PrevUpHomeNext