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