Update contrib.
1 // Copyright David Abrahams 2001.
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_FUNCTION_DWA20011221_HPP
6 # define MAKE_FUNCTION_DWA20011221_HPP
8 # include <boost/python/detail/prefix.hpp>
10 # include <boost/python/default_call_policies.hpp>
11 # include <boost/python/args.hpp>
12 # include <boost/python/detail/caller.hpp>
14 # include <boost/python/object/function_object.hpp>
16 # include <boost/mpl/size.hpp>
17 # include <boost/mpl/int.hpp>
19 namespace boost { namespace python {
23 // make_function_aux --
25 // These helper functions for make_function (below) do the raw work
26 // of constructing a Python object from some invokable entity. See
27 // <boost/python/detail/caller.hpp> for more information about how
28 // the Sig arguments is used.
29 template <class F, class CallPolicies, class Sig>
30 object make_function_aux(
31 F f // An object that can be invoked by detail::invoke()
32 , CallPolicies const& p // CallPolicies to use in the invocation
33 , Sig const& // An MPL sequence of argument types expected by F
36 return objects::function_object(
37 detail::caller<F,CallPolicies,Sig>(f, p)
41 // As above, except that it accepts argument keywords. NumKeywords
42 // is used only for a compile-time assertion to make sure the user
43 // doesn't pass more keywords than the function can accept. To
44 // disable all checking, pass mpl::int_<0> for NumKeywords.
45 template <class F, class CallPolicies, class Sig, class NumKeywords>
46 object make_function_aux(
48 , CallPolicies const& p
50 , detail::keyword_range const& kw // a [begin,end) pair of iterators over keyword names
51 , NumKeywords // An MPL integral type wrapper: the size of kw
54 enum { arity = mpl::size<Sig>::value - 1 };
56 typedef typename detail::error::more_keywords_than_function_arguments<
57 NumKeywords::value, arity
58 >::too_many_keywords assertion;
60 return objects::function_object(
61 detail::caller<F,CallPolicies,Sig>(f, p)
65 // Helpers for make_function when called with 3 arguments. These
66 // dispatch functions are used to discriminate between the cases
67 // when the 3rd argument is keywords or when it is a signature.
70 template <class F, class CallPolicies, class Keywords>
71 object make_function_dispatch(F f, CallPolicies const& policies, Keywords const& kw, mpl::true_)
73 return detail::make_function_aux(
76 , detail::get_signature(f)
78 , mpl::int_<Keywords::size>()
82 template <class F, class CallPolicies, class Signature>
83 object make_function_dispatch(F f, CallPolicies const& policies, Signature const& sig, mpl::false_)
85 return detail::make_function_aux(
95 // These overloaded functions wrap a function or member function
96 // pointer as a Python object, using optional CallPolicies,
97 // Keywords, and/or Signature.
101 object make_function(F f)
103 return detail::make_function_aux(
104 f,default_call_policies(), detail::get_signature(f));
107 template <class F, class CallPolicies>
108 object make_function(F f, CallPolicies const& policies)
110 return detail::make_function_aux(
111 f, policies, detail::get_signature(f));
114 template <class F, class CallPolicies, class KeywordsOrSignature>
115 object make_function(
117 , CallPolicies const& policies
118 , KeywordsOrSignature const& keywords_or_signature)
121 detail::is_reference_to_keywords<KeywordsOrSignature&>::type
124 return detail::make_function_dispatch(
127 , keywords_or_signature
132 template <class F, class CallPolicies, class Keywords, class Signature>
133 object make_function(
135 , CallPolicies const& policies
137 , Signature const& sig
140 return detail::make_function_aux(
145 , mpl::int_<Keywords::size>()
153 #endif // MAKE_FUNCTION_DWA20011221_HPP