# xgenerator

Defined in `xtensor/xgenerator.hpp`

template <class F, class R, class S>
class `xt::``xgenerator`

  Multidimensional function operating on indices.

  The xgenerator class implements a multidimensional function, generating a value from the supplied indices.

  Template Parameters
    - `F`: the function type
    - `R`: the return type of the function
    - `S`: the shape type of the generator

  Inherits from xt::xexpression< xgenerator< F, R, S > >, xt::xexpression_const_iterable< xgenerator< F, R, S > >

  Constructor

  template <class Func>
  `xgenerator`(Func &&f, const S &shape)

    Constructs an xgenerator applying the specified function over the given shape.

    Parameters
      - `f`: the function to apply
      - `shape`: the shape of the xgenerator

  Size and shape

  auto `size`() const

    Returns the size of the expression.

  auto `dimension`() const

    Returns the number of dimensions of the function.

  auto `shape`() const

    Returns the shape of the xgenerator.

  Data

  template <class... Args>
  auto `operator()`(Args... args) const

    Returns the evaluated element at the specified position in the function.

    Parameters
      - `args`: a list of indices specifying the position in the function. Indices must be unsigned integers, the number of indices should be equal or greater than the number of dimensions of the function.
  template <class It>
  auto `element`(It first, It last) const

    Returns a constant reference to the element at the specified position in the function.

    Parameters
      - `first`: iterator starting the sequence of indices
      - `last`: iterator ending the sequence of indices The number of indices in the sequence should be equal to or greater than the number of dimensions of the container.

  Broadcasting

  template <class O>
  bool `broadcast_shape`(O &shape) const

    Broadcast the shape of the function to the specified parameter.

    Return
      a boolean indicating whether the broadcasting is trivial
    Parameters
      - `shape`: the result shape
  template <class O>
  bool `is_trivial_broadcast`(const O&) const

    Compares the specified strides with those of the container to see whether the broadcasting is trivial.

    Return
      a boolean indicating whether the broadcasting is trivial