tuple.hpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /*=============================================================================
  2. Copyright (c) 2014-2015 Kohei Takahashi
  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. #ifndef FUSION_TUPLE_14122014_0102
  7. #define FUSION_TUPLE_14122014_0102
  8. #include <boost/fusion/support/config.hpp>
  9. #include <boost/fusion/tuple/tuple_fwd.hpp>
  10. ///////////////////////////////////////////////////////////////////////////////
  11. // With no variadics, we will use the C++03 version
  12. ///////////////////////////////////////////////////////////////////////////////
  13. #if !defined(BOOST_FUSION_HAS_VARIADIC_TUPLE)
  14. # include <boost/fusion/tuple/detail/tuple.hpp>
  15. #else
  16. ///////////////////////////////////////////////////////////////////////////////
  17. // C++11 interface
  18. ///////////////////////////////////////////////////////////////////////////////
  19. #include <boost/core/enable_if.hpp>
  20. #include <boost/fusion/container/vector/vector.hpp>
  21. #include <boost/fusion/sequence/intrinsic/size.hpp>
  22. #include <boost/fusion/sequence/intrinsic/value_at.hpp>
  23. #include <boost/fusion/sequence/intrinsic/at.hpp>
  24. #include <boost/fusion/sequence/comparison.hpp>
  25. #include <boost/fusion/sequence/io.hpp>
  26. #include <boost/fusion/support/detail/and.hpp>
  27. #include <boost/type_traits/is_convertible.hpp>
  28. #include <utility>
  29. namespace boost { namespace fusion
  30. {
  31. template <typename ...T>
  32. struct tuple
  33. : vector_detail::vector_data<
  34. typename detail::make_index_sequence<sizeof...(T)>::type
  35. , T...
  36. >
  37. {
  38. typedef vector_detail::vector_data<
  39. typename detail::make_index_sequence<sizeof...(T)>::type
  40. , T...
  41. > base;
  42. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  43. BOOST_DEFAULTED_FUNCTION(tuple(), {})
  44. template <
  45. typename ...U
  46. , typename = typename boost::enable_if_c<
  47. sizeof...(U) >= sizeof...(T)
  48. >::type
  49. >
  50. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  51. tuple(tuple<U...> const& other)
  52. : base(vector_detail::each_elem(), other) {}
  53. template <
  54. typename ...U
  55. , typename = typename boost::enable_if_c<
  56. sizeof...(U) >= sizeof...(T)
  57. >::type
  58. >
  59. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  60. tuple(tuple<U...>&& other)
  61. : base(vector_detail::each_elem(), std::move(other)) {}
  62. template <
  63. typename ...U
  64. , typename = typename boost::enable_if_c<(
  65. fusion::detail::and_<is_convertible<U, T>...>::value &&
  66. sizeof...(U) >= 1
  67. )>::type
  68. >
  69. /*BOOST_CONSTEXPR*/ BOOST_FUSION_GPU_ENABLED
  70. explicit
  71. tuple(U&&... args)
  72. : base(vector_detail::each_elem(), std::forward<U>(args)...) {}
  73. template<typename U1, typename U2>
  74. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  75. tuple(std::pair<U1, U2> const& other)
  76. : base(vector_detail::each_elem(), other.first, other.second) {}
  77. template<typename U1, typename U2>
  78. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  79. tuple(std::pair<U1, U2>&& other)
  80. : base(vector_detail::each_elem(), std::move(other.first), std::move(other.second)) {}
  81. template<typename U>
  82. BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  83. tuple& operator=(U&& rhs)
  84. {
  85. base::assign_sequence(std::forward<U>(rhs));
  86. return *this;
  87. }
  88. };
  89. template <typename Tuple>
  90. struct tuple_size : result_of::size<Tuple> {};
  91. template <int N, typename Tuple>
  92. struct tuple_element : result_of::value_at_c<Tuple, N> {};
  93. template <int N, typename Tuple>
  94. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  95. inline typename result_of::at_c<Tuple, N>::type
  96. get(Tuple& tup)
  97. {
  98. return at_c<N>(tup);
  99. }
  100. template <int N, typename Tuple>
  101. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  102. inline typename result_of::at_c<Tuple const, N>::type
  103. get(Tuple const& tup)
  104. {
  105. return at_c<N>(tup);
  106. }
  107. }}
  108. #endif
  109. #endif