Initial C++0x support.
[luabind.git] / luabind / vector.hpp
blob69a5796e105ccdeccc6412c95f16d99800cc79dd
1 // Copyright Daniel Wallin 2010. 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 #ifndef LUABIND_VECTOR_100629_HPP
6 # define LUABIND_VECTOR_100629_HPP
8 # ifdef LUABIND_CPP0x
10 # include <boost/mpl/fold.hpp>
11 # include <boost/mpl/begin_end_fwd.hpp>
12 # include <boost/mpl/front_fwd.hpp>
13 # include <boost/mpl/size_fwd.hpp>
15 namespace luabind {
17 // This is used to specify function signatures, both in the user interface and
18 // in the implementation. In the C++03 version this used to be any MPL forward
19 // sequence. For backward compatibility reasons we provide a conversion layer
20 // from an MPL sequence.
21 template <class... Args>
22 struct vector
23 {};
25 namespace detail
29 template <class... Args>
30 struct vector_iterator;
32 template <class Head, class... Tail>
33 struct vector_iterator<Head, Tail...>
35 typedef Head type;
36 typedef vector_iterator<Tail...> next;
39 template <>
40 struct vector_iterator<>
41 {};
43 } // namespace detail
45 } // namespace luabind
47 namespace boost { namespace mpl
50 // MPL sequence adaption layer to ease the transition to C++0x.
52 template <class... Args>
53 struct begin<luabind::vector<Args...> >
55 typedef luabind::detail::vector_iterator<Args...> type;
58 template <class... Args>
59 struct end<luabind::vector<Args...> >
61 typedef luabind::detail::vector_iterator<> type;
64 template <class... Args>
65 struct size<luabind::vector<Args...> >
66 : long_<sizeof...(Args)>
67 {};
69 template <class Head, class... Tail>
70 struct front<luabind::vector<Head, Tail...> >
72 typedef Head type;
75 template <class Head, class... Tail>
76 struct deref<luabind::detail::vector_iterator<Head, Tail...> >
78 typedef Head type;
81 }} // namespace boost::mpl
83 # endif // LUABIND_CPP0x
85 namespace luabind { namespace detail
88 # ifdef LUABIND_CPP0x
90 struct append_vector
92 template <class V, class T>
93 struct apply;
95 template <class... Args, class T>
96 struct apply<vector<Args...>, T>
98 typedef vector<Args..., T> type;
102 template <class Sequence>
103 struct as_vector
104 : boost::mpl::fold<Sequence, vector<>, append_vector>
107 template <class... Args>
108 struct as_vector<vector<Args...> >
110 typedef vector<Args...> type;
113 # else // LUABIND_CPP0x
115 template <class Sequence>
116 struct as_vector
118 typedef Sequence type;
121 # endif
123 }} // namespace luabind::detail
125 #endif // LUABIND_VECTOR_100629_HPP