Exporting wrapped functions doesn't work
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 38/100
Direzione di ricerca
Inizia riproducendo gli esempi di funzioni wrappate presenti nell’issue, quindi esamina l’entry point boost::python::def e la gestione degli oggetti richiamabili. Il lavoro è completato quando gli esempi wrappati add2 e add possono essere esportati correttamente, come i casi che funzionano già direttamente.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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 <iostream>
#include <boost/python.hpp>
template <class R, class... Args>
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>(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");
}
- Lingua principale
- C++
- Stelle
- 537
- Fork
- 223
- Merge medio
- 11h 22m
- PR unite (30g)
- 2
Guida per i contributori
Nessuna guida per i contributori indicizzata per questo repository
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di boostorg/python
-
numpy::from_data calls vector::front and crashes (or has UB) when called with a scalar object Aperta
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 84/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 64/100
-
BoostDetectToolset-1.90.0.cmake file not found in an include() call in boost_python-config.cmake Aperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 48/100
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 25/100
Tutte le issue di boostorg/python
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
objectionary/eo-graphs#74 ·
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 95/100
-
enhancement
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 88/100
QuantStack/git2cpp#187 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 86/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100