21 using StringList = std::vector<std::string, std::allocator<std::string>>;
25 py::class_<StringList>(
m,
"StringList")
27 .def(
"pop_back", &StringList::pop_back)
29 .def(
"push_back", (
void (
StringList::*)(
const std::string &)) &StringList::push_back)
30 .def(
"back", (std::string &(
StringList::*)()) &StringList::back)
31 .def(
"__len__", [](
const StringList &
v) {
return v.size(); })
34 }, py::keep_alive<0, 1>());
36 class ClassWithSTLVecProperty {
40 py::class_<ClassWithSTLVecProperty>(
m,
"ClassWithSTLVecProperty")
42 .def_readwrite(
"stringList", &ClassWithSTLVecProperty::stringList);
44 m.def(
"print_opaque_list", [](
const StringList &
l) {
45 std::string
ret =
"Opaque list: [";
47 for (
auto entry : l) {
57 m.def(
"return_void_ptr", []() {
return (
void *) 0x1234; });
58 m.def(
"get_void_ptr_value", [](
void *
ptr) {
return reinterpret_cast<std::intptr_t>(
ptr); });
59 m.def(
"return_null_str", []() {
return (
char *)
nullptr; });
60 m.def(
"get_null_str_value", [](
char *ptr) {
return reinterpret_cast<std::intptr_t>(
ptr); });
62 m.def(
"return_unique_ptr", []() -> std::unique_ptr<StringList> {
64 result->push_back(
"some value");
65 return std::unique_ptr<StringList>(
result);
std::vector< std::string, std::allocator< std::string >> StringList
iterator make_iterator(Iterator first, Sentinel last, Extra &&...extra)
Makes a python iterator from a first and past-the-end C++ InputIterator.
static const Line3 l(Rot3(), 1, 1)
constexpr int first(int i)
Implementation details for constexpr functions.
TEST_SUBMODULE(opaque_types, m)
PYBIND11_MAKE_OPAQUE(std::vector< std::string, std::allocator< std::string >>)