Initial C++0x support.
[luabind.git] / luabind / tag_function.hpp
blob4a32db83980b5c2089e015535bc35af4b3528542
1 // Copyright Daniel Wallin 2008. Use, modification and distribution is
2 // subject to the Boost Software License, Version 1.0. (See accompanying
3 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5 #if !BOOST_PP_IS_ITERATING
7 # ifndef LUABIND_TAG_FUNCTION_081129_HPP
8 # define LUABIND_TAG_FUNCTION_081129_HPP
10 # ifndef LUABIND_CPP0x
11 # if LUABIND_MAX_ARITY <= 8
12 # include <boost/mpl/vector/vector10.hpp>
13 # else
14 # include <boost/mpl/vector/vector50.hpp>
15 # endif
16 # include <boost/preprocessor/cat.hpp>
17 # include <boost/preprocessor/iterate.hpp>
18 # include <boost/preprocessor/repetition/enum_params.hpp>
19 # include <boost/preprocessor/repetition/enum_trailing_params.hpp>
20 # endif
22 namespace luabind {
24 namespace detail
27 template <class Signature, class F>
28 struct tagged_function
30 tagged_function(F f)
31 : f(f)
34 F f;
37 template <class Signature, class F>
38 Signature deduce_signature(tagged_function<Signature, F> const&, ...)
40 return Signature();
43 template <class Function>
44 struct signature_from_function;
46 # ifdef LUABIND_CPP0x
48 template <class... Args, class F, class Policies>
49 int invoke(
50 lua_State* L, function_object const& self, invoke_context& ctx
51 , tagged_function<vector<Args...>, F> const& tagged
52 , vector<Args...>, Policies const& policies)
54 return invoke(L, self, ctx, tagged.f, vector<Args...>(), policies);
57 template <class R, class... Args>
58 struct signature_from_function<R(Args...)>
60 typedef vector<R, Args...> type;
63 # else // LUABIND_CPP0x
65 template <class Signature, class F, class Policies>
66 int invoke(
67 lua_State* L, function_object const& self, invoke_context& ctx
68 , tagged_function<Signature, F> const& tagged
69 , Signature, Policies const& policies)
71 return invoke(L, self, ctx, tagged.f, Signature(), policies);
74 # define BOOST_PP_ITERATION_PARAMS_1 \
75 (3, (0, LUABIND_MAX_ARITY, <luabind/tag_function.hpp>))
76 # include BOOST_PP_ITERATE()
78 # endif // LUABIND_CPP0x
80 } // namespace detail
82 template <class Signature, class F>
83 detail::tagged_function<
84 typename detail::signature_from_function<Signature>::type
85 , F
87 tag_function(F f)
89 return f;
92 } // namespace luabind
94 # endif // LUABIND_TAG_FUNCTION_081129_HPP
96 #else // BOOST_PP_IS_ITERATING
98 # define N BOOST_PP_ITERATION()
99 # define NPLUS1 BOOST_PP_INC(N)
101 template <class R BOOST_PP_ENUM_TRAILING_PARAMS(N, class A)>
102 struct signature_from_function<R(BOOST_PP_ENUM_PARAMS(N, A))>
104 typedef BOOST_PP_CAT(mpl::vector, NPLUS1)<
105 R BOOST_PP_ENUM_TRAILING_PARAMS(N, A)
106 > type;
109 #endif // BOOST_PP_IS_ITERATING