You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
763 B

  1. /*
  2. example/example17.cpp -- Usage of stl_binders functions
  3. Copyright (c) 2016 Sergey Lyskov
  4. All rights reserved. Use of this source code is governed by a
  5. BSD-style license that can be found in the LICENSE file.
  6. */
  7. #include "example.h"
  8. #include <pybind11/stl_bind.h>
  9. class El {
  10. public:
  11. El() = delete;
  12. El(int v) : a(v) { }
  13. int a;
  14. };
  15. std::ostream & operator<<(std::ostream &s, El const&v) {
  16. s << "El{" << v.a << '}';
  17. return s;
  18. }
  19. void init_ex17(py::module &m) {
  20. pybind11::class_<El>(m, "El")
  21. .def(pybind11::init<int>());
  22. pybind11::bind_vector<unsigned int>(m, "VectorInt");
  23. pybind11::bind_vector<bool>(m, "VectorBool");
  24. pybind11::bind_vector<El>(m, "VectorEl");
  25. pybind11::bind_vector<std::vector<El>>(m, "VectorVectorEl");
  26. }