blob: 1a472c9e86cfac611106480e086f80ba6091d193 [file] [log] [blame]
Wenzel Jakoba576e6a2015-07-29 17:51:54 +02001/*
2 example/example11.cpp -- keyword arguments and default values
3
Wenzel Jakob8cb6cb32016-04-17 20:21:41 +02004 Copyright (c) 2016 Wenzel Jakob <wenzel.jakob@epfl.ch>
Wenzel Jakoba576e6a2015-07-29 17:51:54 +02005
6 All rights reserved. Use of this source code is governed by a
7 BSD-style license that can be found in the LICENSE file.
8*/
9
10#include "example.h"
Wenzel Jakob91805192016-01-17 22:36:43 +010011#include <pybind11/stl.h>
Wenzel Jakoba576e6a2015-07-29 17:51:54 +020012
13void kw_func(int x, int y) { std::cout << "kw_func(x=" << x << ", y=" << y << ")" << std::endl; }
14
Wenzel Jakob91805192016-01-17 22:36:43 +010015void kw_func4(const std::vector<int> &entries) {
16 std::cout << "kw_func4: ";
17 for (int i : entries)
18 std::cout << i << " ";
19 std::cout << endl;
20}
21
Wenzel Jakoba576e6a2015-07-29 17:51:54 +020022void init_ex11(py::module &m) {
23 m.def("kw_func", &kw_func, py::arg("x"), py::arg("y"));
24 m.def("kw_func2", &kw_func, py::arg("x") = 100, py::arg("y") = 200);
Wenzel Jakob66c9a402016-01-17 22:36:36 +010025 m.def("kw_func3", [](const char *) { }, py::arg("data") = std::string("Hello world!"));
Wenzel Jakob91805192016-01-17 22:36:43 +010026
27 /* A fancier default argument */
28 std::vector<int> list;
29 list.push_back(13);
30 list.push_back(17);
31
32 m.def("kw_func4", &kw_func4, py::arg("myList") = list);
Wenzel Jakoba576e6a2015-07-29 17:51:54 +020033}