vector.hpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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)
  4. #ifndef LUABIND_VECTOR_100629_HPP
  5. # define LUABIND_VECTOR_100629_HPP
  6. # ifdef LUABIND_CPP0x
  7. # include <boost/mpl/fold.hpp>
  8. # include <boost/mpl/begin_end_fwd.hpp>
  9. # include <boost/mpl/front_fwd.hpp>
  10. # include <boost/mpl/size_fwd.hpp>
  11. namespace luabind {
  12. // This is used to specify function signatures, both in the user interface and
  13. // in the implementation. In the C++03 version this used to be any MPL forward
  14. // sequence. For backward compatibility reasons we provide a conversion layer
  15. // from an MPL sequence.
  16. template <class... Args>
  17. struct vector
  18. {};
  19. namespace detail
  20. {
  21. template <class... Args>
  22. struct vector_iterator;
  23. template <class Head, class... Tail>
  24. struct vector_iterator<Head, Tail...>
  25. {
  26. typedef Head type;
  27. typedef vector_iterator<Tail...> next;
  28. };
  29. template <>
  30. struct vector_iterator<>
  31. {};
  32. } // namespace detail
  33. } // namespace luabind
  34. namespace boost { namespace mpl
  35. {
  36. // MPL sequence adaption layer to ease the transition to C++0x.
  37. template <class... Args>
  38. struct begin<luabind::vector<Args...> >
  39. {
  40. typedef luabind::detail::vector_iterator<Args...> type;
  41. };
  42. template <class... Args>
  43. struct end<luabind::vector<Args...> >
  44. {
  45. typedef luabind::detail::vector_iterator<> type;
  46. };
  47. template <class... Args>
  48. struct size<luabind::vector<Args...> >
  49. : long_<sizeof...(Args)>
  50. {};
  51. template <class Head, class... Tail>
  52. struct front<luabind::vector<Head, Tail...> >
  53. {
  54. typedef Head type;
  55. };
  56. template <class Head, class... Tail>
  57. struct deref<luabind::detail::vector_iterator<Head, Tail...> >
  58. {
  59. typedef Head type;
  60. };
  61. }} // namespace boost::mpl
  62. # endif // LUABIND_CPP0x
  63. namespace luabind { namespace detail
  64. {
  65. # ifdef LUABIND_CPP0x
  66. struct append_vector
  67. {
  68. template <class V, class T>
  69. struct apply;
  70. template <class... Args, class T>
  71. struct apply<vector<Args...>, T>
  72. {
  73. typedef vector<Args..., T> type;
  74. };
  75. };
  76. template <class Sequence>
  77. struct as_vector
  78. : boost::mpl::fold<Sequence, vector<>, append_vector>
  79. {};
  80. template <class... Args>
  81. struct as_vector<vector<Args...> >
  82. {
  83. typedef vector<Args...> type;
  84. };
  85. # else // LUABIND_CPP0x
  86. template <class Sequence>
  87. struct as_vector
  88. {
  89. typedef Sequence type;
  90. };
  91. # endif
  92. }} // namespace luabind::detail
  93. #endif // LUABIND_VECTOR_100629_HPP