/Src/Dependencies/Boost/boost/fusion/container/vector/vector.hpp

http://hadesmem.googlecode.com/ · C++ Header · 151 lines · 115 code · 23 blank · 13 comment · 0 complexity · 4c913c617d07d46e572511774243f747 MD5 · raw file

  1. /*=============================================================================
  2. Copyright (c) 2001-2006 Joel de Guzman
  3. Distributed under the Boost Software License, Version 1.0. (See accompanying
  4. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. ==============================================================================*/
  6. #if !defined(FUSION_VECTOR_07072005_1244)
  7. #define FUSION_VECTOR_07072005_1244
  8. #include <boost/fusion/container/vector/vector_fwd.hpp>
  9. #include <boost/fusion/container/vector/detail/vector_n_chooser.hpp>
  10. #include <boost/fusion/sequence/intrinsic/begin.hpp>
  11. #include <boost/mpl/at.hpp>
  12. #include <boost/mpl/bool.hpp>
  13. #include <boost/type_traits/add_reference.hpp>
  14. #include <boost/type_traits/add_const.hpp>
  15. #include <boost/type_traits/is_base_of.hpp>
  16. #include <boost/detail/workaround.hpp>
  17. namespace boost { namespace fusion
  18. {
  19. struct void_;
  20. struct fusion_sequence_tag;
  21. template <BOOST_PP_ENUM_PARAMS(FUSION_MAX_VECTOR_SIZE, typename T)>
  22. struct vector
  23. : sequence_base<vector<BOOST_PP_ENUM_PARAMS(FUSION_MAX_VECTOR_SIZE, T)> >
  24. {
  25. private:
  26. typedef typename detail::vector_n_chooser<
  27. BOOST_PP_ENUM_PARAMS(FUSION_MAX_VECTOR_SIZE, T)>::type
  28. vector_n;
  29. template <BOOST_PP_ENUM_PARAMS(FUSION_MAX_VECTOR_SIZE, typename U)>
  30. friend struct vector;
  31. public:
  32. typedef typename vector_n::types types;
  33. typedef typename vector_n::fusion_tag fusion_tag;
  34. typedef typename vector_n::tag tag;
  35. typedef typename vector_n::size size;
  36. typedef typename vector_n::category category;
  37. typedef typename vector_n::is_view is_view;
  38. vector()
  39. : vec() {}
  40. template <BOOST_PP_ENUM_PARAMS(FUSION_MAX_VECTOR_SIZE, typename U)>
  41. vector(vector<BOOST_PP_ENUM_PARAMS(FUSION_MAX_VECTOR_SIZE, U)> const& rhs)
  42. : vec(rhs.vec) {}
  43. vector(vector const& rhs)
  44. : vec(rhs.vec) {}
  45. template <typename Sequence>
  46. vector(Sequence const& rhs)
  47. #if BOOST_WORKAROUND(BOOST_MSVC, <= 1600)
  48. : vec(ctor_helper(rhs, is_base_of<vector, Sequence>())) {}
  49. #else
  50. : vec(rhs) {}
  51. #endif
  52. // Expand a couple of forwarding constructors for arguments
  53. // of type (T0), (T0, T1), (T0, T1, T2) etc. Example:
  54. //
  55. // vector(
  56. // typename detail::call_param<T0>::type _0
  57. // , typename detail::call_param<T1>::type _1)
  58. // : vec(_0, _1) {}
  59. #include <boost/fusion/container/vector/detail/vector_forward_ctor.hpp>
  60. template <BOOST_PP_ENUM_PARAMS(FUSION_MAX_VECTOR_SIZE, typename U)>
  61. vector&
  62. operator=(vector<BOOST_PP_ENUM_PARAMS(FUSION_MAX_VECTOR_SIZE, U)> const& rhs)
  63. {
  64. vec = rhs.vec;
  65. return *this;
  66. }
  67. template <typename T>
  68. vector&
  69. operator=(T const& rhs)
  70. {
  71. vec = rhs;
  72. return *this;
  73. }
  74. template <int N>
  75. typename add_reference<
  76. typename mpl::at_c<types, N>::type
  77. >::type
  78. at_impl(mpl::int_<N> index)
  79. {
  80. return vec.at_impl(index);
  81. }
  82. template <int N>
  83. typename add_reference<
  84. typename add_const<
  85. typename mpl::at_c<types, N>::type
  86. >::type
  87. >::type
  88. at_impl(mpl::int_<N> index) const
  89. {
  90. return vec.at_impl(index);
  91. }
  92. template <typename I>
  93. typename add_reference<
  94. typename mpl::at<types, I>::type
  95. >::type
  96. at_impl(I /*index*/)
  97. {
  98. return vec.at_impl(mpl::int_<I::value>());
  99. }
  100. template<typename I>
  101. typename add_reference<
  102. typename add_const<
  103. typename mpl::at<types, I>::type
  104. >::type
  105. >::type
  106. at_impl(I /*index*/) const
  107. {
  108. return vec.at_impl(mpl::int_<I::value>());
  109. }
  110. private:
  111. #if BOOST_WORKAROUND(BOOST_MSVC, <= 1600)
  112. static vector_n const&
  113. ctor_helper(vector const& rhs, mpl::true_)
  114. {
  115. return rhs.vec;
  116. }
  117. template <typename T>
  118. static T const&
  119. ctor_helper(T const& rhs, mpl::false_)
  120. {
  121. return rhs;
  122. }
  123. #endif
  124. vector_n vec;
  125. };
  126. }}
  127. #endif