deque.hpp 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. /*=============================================================================
  2. Copyright (c) 2005-2012 Joel de Guzman
  3. Copyright (c) 2005-2006 Dan Marsden
  4. Distributed under the Boost Software License, Version 1.0. (See accompanying
  5. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. ==============================================================================*/
  7. #if !defined(BOOST_FUSION_DEQUE_26112006_1649)
  8. #define BOOST_FUSION_DEQUE_26112006_1649
  9. # include <boost/fusion/container/deque/deque_fwd.hpp>
  10. ///////////////////////////////////////////////////////////////////////////////
  11. // Without variadics, we will use the PP version
  12. ///////////////////////////////////////////////////////////////////////////////
  13. #if !defined(BOOST_FUSION_HAS_VARIADIC_DEQUE)
  14. # include <boost/fusion/container/deque/detail/cpp03/deque.hpp>
  15. #else
  16. ///////////////////////////////////////////////////////////////////////////////
  17. // C++11 interface
  18. ///////////////////////////////////////////////////////////////////////////////
  19. #include <boost/fusion/support/sequence_base.hpp>
  20. #include <boost/fusion/support/void.hpp>
  21. #include <boost/fusion/support/detail/enabler.hpp>
  22. #include <boost/fusion/support/detail/access.hpp>
  23. #include <boost/fusion/support/is_sequence.hpp>
  24. #include <boost/fusion/container/deque/detail/keyed_element.hpp>
  25. #include <boost/fusion/container/deque/detail/deque_keyed_values.hpp>
  26. #include <boost/fusion/container/deque/deque_fwd.hpp>
  27. #include <boost/fusion/container/deque/detail/value_at_impl.hpp>
  28. #include <boost/fusion/container/deque/detail/at_impl.hpp>
  29. #include <boost/fusion/container/deque/detail/begin_impl.hpp>
  30. #include <boost/fusion/container/deque/detail/end_impl.hpp>
  31. #include <boost/fusion/container/deque/detail/is_sequence_impl.hpp>
  32. #include <boost/fusion/sequence/intrinsic/begin.hpp>
  33. #include <boost/fusion/sequence/intrinsic/empty.hpp>
  34. #include <boost/mpl/int.hpp>
  35. #include <boost/mpl/and.hpp>
  36. #include <boost/utility/enable_if.hpp>
  37. #include <boost/type_traits/is_convertible.hpp>
  38. namespace boost { namespace fusion
  39. {
  40. struct deque_tag;
  41. template <typename ...Elements>
  42. struct deque : detail::nil_keyed_element
  43. {
  44. typedef deque_tag fusion_tag;
  45. typedef bidirectional_traversal_tag category;
  46. typedef mpl::int_<0> size;
  47. typedef mpl::int_<0> next_up;
  48. typedef mpl::int_<-1> next_down;
  49. typedef mpl::false_ is_view;
  50. template <typename Sequence>
  51. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  52. deque(Sequence const&,
  53. typename enable_if<
  54. mpl::and_<
  55. traits::is_sequence<Sequence>
  56. , result_of::empty<Sequence>>, detail::enabler_>::type = detail::enabler) BOOST_NOEXCEPT
  57. {}
  58. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  59. deque() BOOST_NOEXCEPT {}
  60. };
  61. template <typename Head, typename ...Tail>
  62. struct deque<Head, Tail...>
  63. : detail::deque_keyed_values<Head, Tail...>::type
  64. , sequence_base<deque<Head, Tail...>>
  65. {
  66. typedef deque_tag fusion_tag;
  67. typedef bidirectional_traversal_tag category;
  68. typedef typename detail::deque_keyed_values<Head, Tail...>::type base;
  69. typedef mpl::int_<(sizeof ...(Tail) + 1)> size;
  70. typedef mpl::int_<size::value> next_up;
  71. typedef mpl::int_<-1> next_down;
  72. typedef mpl::false_ is_view;
  73. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  74. deque()
  75. {}
  76. template <typename Head_, typename ...Tail_, typename =
  77. typename enable_if<is_convertible<Head_, Head> >::type
  78. >
  79. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  80. deque(deque<Head_, Tail_...> const& seq)
  81. : base(seq)
  82. {}
  83. template <typename Head_, typename ...Tail_, typename =
  84. typename enable_if<is_convertible<Head_, Head> >::type
  85. >
  86. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  87. deque(deque<Head_, Tail_...>& seq)
  88. : base(seq)
  89. {}
  90. #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
  91. template <typename Head_, typename ...Tail_, typename =
  92. typename enable_if<is_convertible<Head_, Head> >::type
  93. >
  94. BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  95. deque(deque<Head_, Tail_...>&& seq)
  96. : base(std::forward<deque<Head_, Tail_...>>(seq))
  97. {}
  98. #endif
  99. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  100. deque(deque const& seq)
  101. : base(seq)
  102. {}
  103. #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
  104. BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  105. deque(deque&& seq)
  106. : base(std::forward<deque>(seq))
  107. {}
  108. #endif
  109. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  110. explicit deque(typename detail::call_param<Head>::type head
  111. , typename detail::call_param<Tail>::type... tail)
  112. : base(detail::deque_keyed_values<Head, Tail...>::construct(head, tail...))
  113. {}
  114. #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
  115. template <typename Head_, typename ...Tail_, typename =
  116. typename enable_if<is_convertible<Head_, Head> >::type
  117. >
  118. BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  119. explicit deque(Head_&& head, Tail_&&... tail)
  120. : base(detail::deque_keyed_values<Head, Tail...>
  121. ::forward_(BOOST_FUSION_FWD_ELEM(Head_, head), BOOST_FUSION_FWD_ELEM(Tail_, tail)...))
  122. {}
  123. #else
  124. template <typename Head_, typename ...Tail_, typename =
  125. typename enable_if<is_convertible<Head_, Head> >::type
  126. >
  127. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  128. explicit deque(Head_ const& head, Tail_ const&... tail)
  129. : base(detail::deque_keyed_values<Head_, Tail_...>::construct(head, tail...))
  130. {}
  131. #endif
  132. template <typename Sequence>
  133. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  134. explicit deque(Sequence const& seq
  135. , typename disable_if<is_convertible<Sequence, Head>, detail::enabler_>::type = detail::enabler
  136. , typename enable_if<traits::is_sequence<Sequence>, detail::enabler_>::type = detail::enabler)
  137. : base(base::from_iterator(fusion::begin(seq)))
  138. {}
  139. template <typename ...Elements>
  140. BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  141. deque& operator=(deque<Elements...> const& rhs)
  142. {
  143. base::operator=(rhs);
  144. return *this;
  145. }
  146. template <typename T>
  147. BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  148. deque& operator=(T const& rhs)
  149. {
  150. base::operator=(rhs);
  151. return *this;
  152. }
  153. #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
  154. template <typename T>
  155. BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  156. deque& operator=(T&& rhs)
  157. {
  158. base::operator=(BOOST_FUSION_FWD_ELEM(T, rhs));
  159. return *this;
  160. }
  161. #endif
  162. };
  163. }}
  164. #endif
  165. #endif