boostorg / boostorg/python

Exporting wrapped functions doesn't work

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

描述

I find myself in need of exporting a whole lot of functions to Python which require a wrapper (the API needs locking and whatnot).

The following code probably should work (pybind11 can handle it, for the most part), but doesn't.

```
#include
#include

template
struct wrap
{
using funct_type = R(*)(Args...);
funct_type func;
wrap(funct_type f): func(f) {};
R operator()(Args&&... args)
{
std::cout << "before calling\n";
R ret=func(std::forward(args)...);
std::cout << "After calling\n";
return ret;
}
};

class bar {};
class foo : bar {
public:
enum xfoo { FOO=1, BAR=2, BAZ=3 };
static int add(int a, int b, enum xfoo c) { return a+b; }
static int add2(int a, int b) { return a+b; }
};

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

// this works
std::cout << "Result" << wrap{foo::add}(1,2, foo::xfoo::FOO) << std::endl;

// so does this
def("add", foo::add, "A function that adds two numbers and no enum");

// this works with pybind11 but not boost
def("add2", wrap{foo::add2}, "A function that adds two numbers");

// this works with neither
def("add", wrap{foo::add}, "A function that adds two numbers and no enum");
}
```

贡献指南

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

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

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