raw_function.qbk 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. using namespace boost::python;
  24. tuple raw(tuple args, dict kw)
  25. {
  26. return make_tuple(args, kw);
  27. }
  28. BOOST_PYTHON_MODULE(raw_test)
  29. {
  30. def("raw", raw_function(raw));
  31. }
  32. ``
  33. Python:
  34. ``
  35. >>> from raw_test import *
  36. >>> raw(3, 4, foo = 'bar', baz = 42)
  37. ((3, 4), {'foo': 'bar', 'baz': 42})
  38. ``
  39. [endsect]
  40. [endsect]