Pybind11 is a C++program that processes vector&functions. After passing [] in Python, it appears to be a value pass, and modifications in C++cannot affect this list #5425
Unanswered
wuguinianjing
asked this question in
Q&A
Replies: 1 comment
-
普通类型也一样,真服了 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
#include <pybind11/pybind11.h>
#include
namespace py = pybind11;
void process_vector(std::vector& vec) {
for (auto& v : vec) {
v *= 2;
}
}
PYBIND11_MODULE(example, m) {
m.def("process_vector", &process_vector, "A function that processes a vector of integers by reference.");
}
/////////////////////////
import example
vec = [1, 2, 3]
print("Before:", vec)
example.process_vector(vec)
print("After:", vec)
//////
OUTPUT:
Before: [1, 2, 3]
After: [1,2,3]
Beta Was this translation helpful? Give feedback.
All reactions