aboutsummaryrefslogtreecommitdiff
path: root/libs/plugin_python/tests/python/test_functional.cpp
blob: 485851629d329cc271b92d5d839035c7984de90b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include "pybind11_utils/functional.h"

#include <pybind11/pybind11.h>

PYBIND11_MODULE(functional, m)
{
    m.def("fn_0_arg", [](std::function<int()> const& fn) {
        return fn();
    });

    m.def("fn_1_arg", [](std::function<int(int)> const& fn, int a) {
        return fn(a);
    });

    m.def("fn_2_arg", [](std::function<int(int, int)> const& fn, int a, int b) {
        return fn(a, b);
    });

    m.def("fn_0_or_1_arg", [](std::function<int()> const& fn) {
        return fn();
    });

    m.def("fn_0_or_1_arg", [](std::function<int(int)> const& fn) {
        return fn(1);
    });

    m.def("fn_1_or_2_or_3_arg", [](std::function<int(int)> const& fn) {
        return fn(1);
    });

    m.def("fn_1_or_2_or_3_arg", [](std::function<int(int, int)> const& fn) {
        return fn(1, 2);
    });

    m.def("fn_1_or_2_or_3_arg", [](std::function<int(int, int, int)> const& fn) {
        return fn(1, 2, 3);
    });
}