| Home | Libraries | People | FAQ | More

## Class accessor

boost::histogram::indexed_range::accessor — Lightweight view to access value and index of current cell.

## Synopsis

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

    // Lightweight view to access value and index of current cell.

    class accessor {
    public:
      // member classes/structs/unions

      // Array-like view into the current multi-dimensional index.

      class index_view {
      public:
        // types
        typedef unspecified              const_iterator;
        typedef const axis::index_type & const_reference;

        // public member functions
        const_iterator begin() const noexcept;
        const_iterator end() const noexcept;
        std::size_t size() const noexcept;
        const_reference operator[](unsigned) const noexcept;
        const_reference at(unsigned) const;
      };
      // construct/copy/destruct
      accessor(iterator &) noexcept;
      accessor(const accessor &) = default;
      accessor & operator=(const accessor &);
      template<typename T> accessor & operator=(const T &);

      // public member functions
      value_reference get() const noexcept;
      value_reference operator*() const noexcept;
      value_iterator operator->() const noexcept;
      axis::index_type index(unsigned = 0) const noexcept;
      index_view indices() const noexcept;
      template<unsigned N = 0>
        decltype(auto) bin(std::integral_constant< unsigned, N > = {}) const;
      decltype(auto) bin(unsigned) const;
      double density() const;
      bool operator<(const accessor &) noexcept;
      bool operator>(const accessor &) noexcept;
      bool operator==(const accessor &) noexcept;
      bool operator!=(const accessor &) noexcept;
      bool operator<=(const accessor &) noexcept;
      bool operator>=(const accessor &) noexcept;
      template<typename U> bool operator<(const U &) const noexcept;
      template<typename U> bool operator>(const U &) const noexcept;
      template<typename U> bool operator==(const U &) const noexcept;
      template<typename U> bool operator!=(const U &) const noexcept;
      template<typename U> bool operator<=(const U &) const noexcept;
      template<typename U> bool operator>=(const U &) const noexcept;
      operator value_type() const noexcept;
    };

## Description

The methods provide access to the current cell indices and bins. It acts like a pointer to the cell value, and in a limited way also like a reference. To interoperate with the algorithms of the standard library, the accessor is implicitly convertible to a cell value. Assignments and comparisons are passed through to the cell. An accessor is coupled to its parent indexed_range::iterator. Moving the parent iterator forward also updates the linked accessor. Accessors are not copyable. They cannot be stored in containers, butindexed_range::iterator can be stored.

### `accessor` public construct/copy/destruct

1.     accessor(iterator & i) noexcept;

2.     accessor(const accessor &) = default;

3.     accessor & operator=(const accessor & o);

4.     template<typename T> accessor & operator=(const T & x);

### `accessor` public member functions

1.     value_reference get() const noexcept;

   Returns the cell reference.

2.     value_reference operator*() const noexcept;

3.     value_iterator operator->() const noexcept;

   Access fields and methods of the cell object.

4.     axis::index_type index(unsigned d = 0) const noexcept;

   Access current index.

   Parameters:

   `d` | axis dimension.

5.     index_view indices() const noexcept;

   Access indices as an iterable range.

6.     template<unsigned N = 0>
         decltype(auto) bin(std::integral_constant< unsigned, N > = {}) const;

   Access current bin.

   Template Parameters:

   `N` | axis dimension.

7.     decltype(auto) bin(unsigned d) const;

   Access current bin.

   Parameters:

   `d` | axis dimension.

8.     double density() const;

   Computes density in current cell.

   The density is computed as the cell value divided by the product of bin widths. Axes without bin widths, like `axis::category`, are treated as having unit bin with.

9.     bool operator<(const accessor & o) noexcept;

10.     bool operator>(const accessor & o) noexcept;

11.     bool operator==(const accessor & o) noexcept;

12.     bool operator!=(const accessor & o) noexcept;

13.     bool operator<=(const accessor & o) noexcept;

14.     bool operator>=(const accessor & o) noexcept;

15.     template<typename U> bool operator<(const U & o) const noexcept;

16.     template<typename U> bool operator>(const U & o) const noexcept;

17.     template<typename U> bool operator==(const U & o) const noexcept;

18.     template<typename U> bool operator!=(const U & o) const noexcept;

19.     template<typename U> bool operator<=(const U & o) const noexcept;

20.     template<typename U> bool operator>=(const U & o) const noexcept;

21.     operator value_type() const noexcept;