boostorg / boostorg/python

boost::python fails to correctly handle constness of wrapped classes

未关闭
#205 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
C++
星标
537
派生
223
平均合并
11 小时 22 分钟
30 天内合并 PR
2

描述

I want to wrap C++ code that only provides `const` access to a class `Foo`:

```cpp
struct Foo {};
std::shared_ptr producer();
```
Wrapping `Foo` as usual:
```cpp
BOOST_PYTHON_MODULE(foo) {
boost::python::class_, boost::noncopyable>("Foo", boost::python::no_init);
boost::python::def("producer", &producer);
}
```
compiles fine, but complains at runtime - obviously - about a missing type converter:
`No to_python (by-value) converter found for C++ type: std::shared_ptr`

Alternatively trying:
```cpp
BOOST_PYTHON_MODULE(foo) {
// const holder
boost::python::class_, boost::noncopyable>("Foo", boost::python::no_init);
// const class + holder
boost::python::class_, boost::noncopyable>("Foo", boost::python::no_init);
}
```
yields compile-time errors about constness issues. Isn't there a solution available that respects constness?

贡献指南

这个仓库没有索引到贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。