Skip to content

Instantly share code, notes, and snippets.

@AWhetter
Created July 17, 2020 21:28
Show Gist options
  • Save AWhetter/5af5ee75cc4fd4733ee21d9cdd52ec4d to your computer and use it in GitHub Desktop.
Save AWhetter/5af5ee75cc4fd4733ee21d9cdd52ec4d to your computer and use it in GitHub Desktop.
#include "moda.h"
#include <pybind11/pybind11.h>
#include <pybind11/stl_bind.h>
namespace py = pybind11;
PYBIND11_MODULE(moda, m) {
py::class_<A, std::shared_ptr<A>>(m, "A")
;
py::bind_vector<AList>(m, "AList");
m.def("get_list", []() {
AList lst;
P_A p_a;
lst.push_back(p_a);
return lst;
});
}
#include <memory>
#include <vector>
#include <pybind11/pybind11.h>
class A {
};
typedef std::shared_ptr<A> P_A;
typedef std::vector<P_A> AList;
PYBIND11_DECLARE_HOLDER_TYPE(T, std::shared_ptr<T>);
PYBIND11_MAKE_OPAQUE(AList);
#include <pybind11/pybind11.h>
#include "moda.h"
namespace py = pybind11;
PYBIND11_MODULE(modb, m) {
py::module::import("moda");
m.def("get_list", []() {
AList lst;
P_A p_a(new A());
lst.push_back(p_a);
return lst;
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment