tuple.hpp 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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/fusion/container/vector/vector.hpp>
  20. #include <boost/fusion/sequence/intrinsic/size.hpp>
  21. #include <boost/fusion/sequence/intrinsic/value_at.hpp>
  22. #include <boost/fusion/sequence/intrinsic/at.hpp>
  23. #include <boost/fusion/sequence/comparison.hpp>
  24. #include <boost/fusion/sequence/io.hpp>
  25. #include <utility>
  26. namespace boost { namespace fusion
  27. {
  28. template <typename ...T>
  29. struct tuple : vector<T...>
  30. {
  31. typedef vector<T...> base_type;
  32. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  33. tuple()
  34. : base_type() {}
  35. template <typename ...U>
  36. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  37. tuple(tuple<U...> const& other)
  38. : base_type(other) {}
  39. template <typename ...U>
  40. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  41. tuple(tuple<U...>&& other)
  42. : base_type(std::move(other)) {}
  43. template <typename ...U>
  44. /*BOOST_CONSTEXPR*/ BOOST_FUSION_GPU_ENABLED
  45. explicit
  46. tuple(U&&... args)
  47. : base_type(std::forward<U>(args)...) {}
  48. template <typename U>
  49. BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  50. tuple& operator=(U&& rhs)
  51. {
  52. base_type::operator=(std::forward<U>(rhs));
  53. return *this;
  54. }
  55. };
  56. template <typename Tuple>
  57. struct tuple_size : result_of::size<Tuple> {};
  58. template <int N, typename Tuple>
  59. struct tuple_element : result_of::value_at_c<Tuple, N> {};
  60. template <int N, typename Tuple>
  61. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  62. inline typename result_of::at_c<Tuple, N>::type
  63. get(Tuple& tup)
  64. {
  65. return at_c<N>(tup);
  66. }
  67. template <int N, typename Tuple>
  68. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  69. inline typename result_of::at_c<Tuple const, N>::type
  70. get(Tuple const& tup)
  71. {
  72. return at_c<N>(tup);
  73. }
  74. }}
  75. #endif
  76. #endif