]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | [section boost/python/raw_function.hpp] |
2 | [section Introduction] | |
3 | `raw_function(...)` is used to convert a function taking a [link object_wrappers.boost_python_tuple_hpp.class_tuple `tuple`] and a [link object_wrappers.boost_python_dict_hpp.class_dict `dict`] into a Python callable object which accepts a variable number of arguments and arbitrary keyword arguments. | |
4 | [endsect] | |
5 | [section Function `raw_function`] | |
6 | `` | |
7 | template <class F> | |
8 | object raw_function(F f, std::size_t min_args = 0); | |
9 | `` | |
10 | [variablelist | |
11 | [[Requires][f(tuple(), dict()) is well-formed.]] | |
12 | [[Returns][a callable object which requires at least min_args arguments. When called, the actual non-keyword arguments will be passed in a tuple as the first argument to f, and the keyword arguments will be passed in a dict as the second argument to f. ]] | |
13 | ] | |
14 | [endsect] | |
15 | [section Example] | |
16 | C++: | |
17 | `` | |
18 | #include <boost/python/def.hpp> | |
19 | #include <boost/python/tuple.hpp> | |
20 | #include <boost/python/dict.hpp> | |
21 | #include <boost/python/module.hpp> | |
22 | #include <boost/python/raw_function.hpp> | |
23 | ||
24 | using namespace boost::python; | |
25 | ||
26 | tuple raw(tuple args, dict kw) | |
27 | { | |
28 | return make_tuple(args, kw); | |
29 | } | |
30 | ||
31 | BOOST_PYTHON_MODULE(raw_test) | |
32 | { | |
33 | def("raw", raw_function(raw)); | |
34 | } | |
35 | `` | |
36 | Python: | |
37 | `` | |
38 | >>> from raw_test import * | |
39 | ||
40 | >>> raw(3, 4, foo = 'bar', baz = 42) | |
41 | ((3, 4), {'foo': 'bar', 'baz': 42}) | |
42 | `` | |
43 | [endsect] | |
44 | [endsect] |