cxtream  0.5.1
C++17 data pipeline with Python bindings.
Public Member Functions | List of all members
cxtream::python::range< Rng > Class Template Reference

Python adapter for C++ ranges. More...

#include <cxtream/python/range.hpp>

Public Member Functions

 range ()=default
 Default empty constructor.
 
 range (Rng rng)
 Construct python range from a C++ range. This function creates a copy of the range.
 
 range (std::shared_ptr< Rng > rng_ptr)
 Construct python range from a std::shared_ptr to a C++ range.
 

Detailed Description

template<typename Rng>
class cxtream::python::range< Rng >

Python adapter for C++ ranges.

This class provides __next__, __iter__, __len__, and __getitem__ methods emulating python containers. __getitem__ and __len__ are provided only for random access ranges.

Note that this class is useful for infinite ranges and views. However, for normal finite ranges, it seems to be many times slower than using boost::python::list.

Example:

std::vector<int> data = {1, 2, 3};
range<std::vector<int>> py_range{std::move(data)};
// py_range is now a registered boost::python object
// supporting iteration and random access.

Definition at line 59 of file range.hpp.


The documentation for this class was generated from the following file: