.. index:: py::builtins::range .. _doxycast_pypp_classpy_1_1builtins_1_1range: .. _py-builtins-range: *py::builtins::*\ range ======================= *Defined in* ```` .. code-block:: cpp template class range; Class for holding a range of values. ``py::builtins::range`` holds a range of values. The range is specified by three value: * :ref:`start `: The start value of the range. * :ref:`stop `: The end value of the range (exclusive). * :ref:`step `: The difference between values. .. warning:: Although ``range`` support iterators, it's iterators don't support ``operator ->`` as objects are constructed on demand. It's iterators also don't return any references to object, they return the object. Template parameters ------------------- ``type``: The type of values. Members types ------------- .. list-table:: :class: width-full :widths: 25 75 * - :ref:`value_type ` - The type of values * - :ref:`iterator ` - The type of iterators * - :ref:`const_iterator ` - The type of constant iterators * - :ref:`reverse_iterator ` - The type of reverse iterators * - :ref:`const_reverse_iterator ` - The type of constant reverse iterators Members functions ----------------- .. list-table:: :class: width-full :widths: 25 75 * - :ref:`(constructor) ` - Constructs a range * - :ref:`operator = ` - Assigns a range to the range **Value access** .. list-table:: :class: width-full :widths: 25 75 * - :ref:`operator [] ` - Accesses value at specified index * - :ref:`operator [] ` - Returns a slice of the range * - :ref:`front ` - Acceses the first value * - :ref:`back ` - Acceses the last value **Capacity** .. list-table:: :class: width-full :widths: 25 75 * - :ref:`size ` - Returns the size of the range **Iterators** .. list-table:: :class: width-full :widths: 25 75 * - :ref:`begin ` :ref:`cbegin ` - Returns an iterator to the beginning * - :ref:`end ` :ref:`cend ` - Returns an iterator to the end * - :ref:`rbegin ` :ref:`crbegin ` - Returns a reverse iterator to the beginning * - :ref:`rend ` :ref:`crend ` - Returns a reverse iterator to the end **Observers** .. list-table:: :class: width-full :widths: 25 75 * - :ref:`start ` - Returns the start value of the range * - :ref:`stop ` - Returns the stop value of the range * - :ref:`step ` - Returns the step value of the range **Lookup** .. list-table:: :class: width-full :widths: 25 75 * - :ref:`count ` - Returns the count of a value in the range * - :ref:`index ` - Returns the index of a value in the range * - :ref:`find ` - Finds and returns an iterator to a value in the range **Modifiers** .. list-table:: :class: width-full :widths: 25 75 * - :ref:`swap ` - Swaps the range with another Non-member functions -------------------- .. list-table:: :class: width-full :widths: 25 75 * - :ref:`operator \< ` :ref:`operator > ` :ref:`operator == ` :ref:`operator != ` :ref:`operator \<= ` :ref:`operator >= ` - Compares two ranges lexicographically * - :ref:`operator ->* ` - Specializes the :ref:`py-builtins-operator-pointer_to_member-in` algorithm * - :ref:`::std::swap ` - Specializes the ``std::swap`` algorithm Example ------- .. code-block:: cpp #include #include #include int main() { py::range nums(10); py::print(py::list(nums)); } **Output**: .. code-block:: text {0, 1, 2, 3, 4, 5, 6, 7, 8, 9} Member hierarchy ---------------- * :ref:`value_type ` * :ref:`iterator ` * :ref:`const_iterator ` * :ref:`reverse_iterator ` * :ref:`const_reverse_iterator ` * :ref:`range ` * :ref:`size ` * :ref:`count ` * :ref:`index ` * :ref:`find ` * :ref:`start ` * :ref:`stop ` * :ref:`step ` * :ref:`front ` * :ref:`back ` * :ref:`swap ` * :ref:`begin ` * :ref:`cbegin ` * :ref:`rbegin ` * :ref:`crbegin ` * :ref:`end ` * :ref:`cend ` * :ref:`rend ` * :ref:`crend ` * :ref:`operator [] ` * :ref:`operator = ` .. toctree:: :hidden: value_type iterator const_iterator reverse_iterator const_reverse_iterator range size count index find start stop step front back swap begin cbegin rbegin crbegin end cend rend crend operator [] operator =