list.hpp 3.7 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_LIST_10262014_0537
  7. #define FUSION_LIST_10262014_0537
  8. #include <boost/fusion/support/config.hpp>
  9. #include <boost/fusion/container/list/list_fwd.hpp>
  10. ///////////////////////////////////////////////////////////////////////////////
  11. // Without variadics, we will use the PP version
  12. ///////////////////////////////////////////////////////////////////////////////
  13. #if !defined(BOOST_FUSION_HAS_VARIADIC_LIST)
  14. # include <boost/fusion/container/list/detail/cpp03/list.hpp>
  15. #else
  16. ///////////////////////////////////////////////////////////////////////////////
  17. // C++11 interface
  18. ///////////////////////////////////////////////////////////////////////////////
  19. #include <utility>
  20. #include <boost/fusion/container/list/detail/list_to_cons.hpp>
  21. namespace boost { namespace fusion
  22. {
  23. struct nil_;
  24. template <>
  25. struct list<>
  26. : detail::list_to_cons<>::type
  27. {
  28. private:
  29. typedef detail::list_to_cons<> list_to_cons;
  30. typedef list_to_cons::type inherited_type;
  31. public:
  32. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  33. list()
  34. : inherited_type() {}
  35. #if defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
  36. template <typename Sequence>
  37. BOOST_FUSION_GPU_ENABLED
  38. list(Sequence const& rhs)
  39. : inherited_type(rhs) {}
  40. template <typename Sequence>
  41. BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  42. list&
  43. operator=(Sequence const& rhs)
  44. {
  45. inherited_type::operator=(rhs);
  46. return *this;
  47. }
  48. #else
  49. template <typename Sequence>
  50. BOOST_FUSION_GPU_ENABLED
  51. list(Sequence&& rhs)
  52. : inherited_type(std::forward<Sequence>(rhs)) {}
  53. template <typename Sequence>
  54. BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  55. list&
  56. operator=(Sequence&& rhs)
  57. {
  58. inherited_type::operator=(std::forward<Sequence>(rhs));
  59. return *this;
  60. }
  61. #endif
  62. };
  63. template <typename ...T>
  64. struct list
  65. : detail::list_to_cons<T...>::type
  66. {
  67. private:
  68. typedef detail::list_to_cons<T...> list_to_cons;
  69. typedef typename list_to_cons::type inherited_type;
  70. public:
  71. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  72. list()
  73. : inherited_type() {}
  74. #if defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
  75. template <typename Sequence>
  76. BOOST_FUSION_GPU_ENABLED
  77. list(Sequence const& rhs)
  78. : inherited_type(rhs) {}
  79. #else
  80. template <typename Sequence>
  81. BOOST_FUSION_GPU_ENABLED
  82. list(Sequence&& rhs)
  83. : inherited_type(std::forward<Sequence>(rhs)) {}
  84. #endif
  85. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  86. explicit
  87. list(typename detail::call_param<T>::type ...args)
  88. : inherited_type(list_to_cons::call(args...)) {}
  89. #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
  90. template <typename Sequence>
  91. BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  92. list&
  93. operator=(Sequence const& rhs)
  94. {
  95. inherited_type::operator=(rhs);
  96. return *this;
  97. }
  98. #else
  99. template <typename Sequence>
  100. BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  101. list&
  102. operator=(Sequence&& rhs)
  103. {
  104. inherited_type::operator=(std::forward<Sequence>(rhs));
  105. return *this;
  106. }
  107. #endif
  108. };
  109. }}
  110. #endif
  111. #endif