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.

33 lines
1002 B

  1. /*
  2. example/example11.cpp -- keyword arguments and default values
  3. Copyright (c) 2015 Wenzel Jakob <wenzel@inf.ethz.ch>
  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.h>
  9. void kw_func(int x, int y) { std::cout << "kw_func(x=" << x << ", y=" << y << ")" << std::endl; }
  10. void kw_func4(const std::vector<int> &entries) {
  11. std::cout << "kw_func4: ";
  12. for (int i : entries)
  13. std::cout << i << " ";
  14. std::cout << endl;
  15. }
  16. void init_ex11(py::module &m) {
  17. m.def("kw_func", &kw_func, py::arg("x"), py::arg("y"));
  18. m.def("kw_func2", &kw_func, py::arg("x") = 100, py::arg("y") = 200);
  19. m.def("kw_func3", [](const char *) { }, py::arg("data") = std::string("Hello world!"));
  20. /* A fancier default argument */
  21. std::vector<int> list;
  22. list.push_back(13);
  23. list.push_back(17);
  24. m.def("kw_func4", &kw_func4, py::arg("myList") = list);
  25. }