py::builtins::range

Defined in <pypp/builtins/range.hpp>

template <class type>
class range;

Class for holding a range of values.

py::builtins::range holds a range of values. The range is specified by three value:

  • start: The start value of the range.

  • stop: The end value of the range (exclusive).

  • 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

value_type

The type of values

iterator

The type of iterators

const_iterator

The type of constant iterators

reverse_iterator

The type of reverse iterators

const_reverse_iterator

The type of constant reverse iterators

Members functions

(constructor)

Constructs a range

operator =

Assigns a range to the range

Value access

operator []

Accesses value at specified index

operator []

Returns a slice of the range

front

Acceses the first value

back

Acceses the last value

Capacity

size

Returns the size of the range

Iterators

begin

cbegin

Returns an iterator to the beginning

end

cend

Returns an iterator to the end

rbegin

crbegin

Returns a reverse iterator to the beginning

rend

crend

Returns a reverse iterator to the end

Observers

start

Returns the start value of the range

stop

Returns the stop value of the range

step

Returns the step value of the range

Lookup

count

Returns the count of a value in the range

index

Returns the index of a value in the range

find

Finds and returns an iterator to a value in the range

Modifiers

swap

Swaps the range with another

Non-member functions

operator <

operator >

operator ==

operator !=

operator <=

operator >=

Compares two ranges lexicographically

operator ->*

Specializes the py::builtins::operator ->* (py::builtins::in) algorithm

::std::swap

Specializes the std::swap algorithm

Example

#include <pypp/builtins/range.hpp>
#include <pypp/builtins/list.hpp>
#include <pypp/builtins/print.hpp>

int main()
{
    py::range<int> nums(10);
    py::print(py::list(nums));
}

Output:

{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}