make_keyword_range_fn.hpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. // Copyright David Abrahams 2002.
  2. // Distributed under the Boost Software License, Version 1.0. (See
  3. // accompanying file LICENSE_1_0.txt or copy at
  4. // http://www.boost.org/LICENSE_1_0.txt)
  5. #ifndef MAKE_KEYWORD_RANGE_FN_DWA2002927_HPP
  6. # define MAKE_KEYWORD_RANGE_FN_DWA2002927_HPP
  7. # include <boost/python/make_function.hpp>
  8. # include <boost/python/args_fwd.hpp>
  9. # include <boost/python/object/make_holder.hpp>
  10. # include <boost/mpl/size.hpp>
  11. namespace boost { namespace python { namespace detail {
  12. // Think of this as a version of make_function without a compile-time
  13. // check that the size of kw is no greater than the expected arity of
  14. // F. This version is needed when defining functions with default
  15. // arguments, because compile-time information about the number of
  16. // keywords is missing for all but the initial function definition.
  17. //
  18. // @group make_keyword_range_function {
  19. template <class F, class Policies>
  20. object make_keyword_range_function(
  21. F f
  22. , Policies const& policies
  23. , keyword_range const& kw)
  24. {
  25. return detail::make_function_aux(
  26. f, policies, detail::get_signature(f), kw, mpl::int_<0>());
  27. }
  28. template <class F, class Policies, class Signature>
  29. object make_keyword_range_function(
  30. F f
  31. , Policies const& policies
  32. , keyword_range const& kw
  33. , Signature const& sig)
  34. {
  35. return detail::make_function_aux(
  36. f, policies, sig, kw, mpl::int_<0>());
  37. }
  38. // }
  39. // Builds an '__init__' function which inserts the given Holder type
  40. // in a wrapped C++ class instance. ArgList is an MPL type sequence
  41. // describing the C++ argument types to be passed to Holder's
  42. // constructor.
  43. //
  44. // Holder and ArgList are intended to be explicitly specified.
  45. template <class ArgList, class Arity, class Holder, class CallPolicies>
  46. object make_keyword_range_constructor(
  47. CallPolicies const& policies // The CallPolicies with which to invoke the Holder's constructor
  48. , detail::keyword_range const& kw // The (possibly empty) set of associated argument keywords
  49. , Holder* = 0
  50. , ArgList* = 0, Arity* = 0)
  51. {
  52. #if !defined( BOOST_PYTHON_NO_PY_SIGNATURES) && defined( BOOST_PYTHON_PY_SIGNATURES_PROPER_INIT_SELF_TYPE)
  53. python_class<BOOST_DEDUCED_TYPENAME Holder::value_type>::register_();
  54. #endif
  55. return detail::make_keyword_range_function(
  56. objects::make_holder<Arity::value>
  57. ::template apply<Holder,ArgList>::execute
  58. , policies
  59. , kw);
  60. }
  61. }}} // namespace boost::python::detail
  62. #endif // MAKE_KEYWORD_RANGE_FN_DWA2002927_HPP