boostorg / boostorg/python

std::vector<std::tuple<>> working only with NoProxy set with vector_indexing_suite

Đang mở
#112 0 bình luận 0 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
C++
Star
537
Fork
223
Merge trung bình
11 giờ 22 phút
Pull request đã merge (30 ngày)
2

Mô tả

Hi, I'm trying to export from C++ an std::vector of a tuple. Unfortunately, while both the vector (exported via `vector_indexing_suite`) and the tuple (exported via `to_python_converter`) themselves are exported correctly and can be accessed, accessing a tuple element *from* the vector results in an `No Python class registered for C++ class` error. This does not happen when the `vector_indexing_suite` has the `NoProxy` template parameter set to `true`, which for me is undesirable.

Am I doing something wrong, or is there a way to bypass this limitation?

Here is a MVE:

```
#include
#include

#include
#include

template
struct TupleToPython {
TupleToPython() {
boost::python::to_python_converter>();
}

template
struct sequence {};

template
struct generator : generator { };

template
struct generator<0, S...> {
using type = sequence;
};

template
static boost::python::tuple boostConvertImpl(const T& t, sequence) {
return boost::python::make_tuple(std::get(t)...);
}

template
static boost::python::tuple boostConvert(const std::tuple & t) {
return boostConvertImpl(t, typename generator::type());
}

static PyObject* convert(const T& t) {
return boost::python::incref(boostConvert(t).ptr());
}
};

using MyTuple = std::tuple;
using Tuples = std::vector;

MyTuple makeMyTuple() {
return MyTuple();
}

Tuples makeTuples() {
return Tuples{MyTuple()};
}

BOOST_PYTHON_MODULE(h)
{
using namespace boost::python;

TupleToPython();
def("makeMyTuple", makeMyTuple);

class_>{"Tuples"}
.def(vector_indexing_suite>());
def("makeTuples", makeTuples);
}
```

Then from Python:

```
>>> print makeMyTuple()
(0,)
>>> print makeTuples()

>>> print makeTuples()[0]
Traceback (most recent call last):
File "", line 1, in
TypeError: No Python class registered for C++ class std::tuple
>>>
```

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.