set.hpp 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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_SET_11062014_1726
  7. #define FUSION_SET_11062014_1726
  8. #include <boost/fusion/support/config.hpp>
  9. #include <boost/fusion/container/set/set_fwd.hpp>
  10. ///////////////////////////////////////////////////////////////////////////////
  11. // Without variadics, we will use the PP version
  12. ///////////////////////////////////////////////////////////////////////////////
  13. #if !defined(BOOST_FUSION_HAS_VARIADIC_SET)
  14. # include <boost/fusion/container/set/detail/cpp03/set.hpp>
  15. #else
  16. ///////////////////////////////////////////////////////////////////////////////
  17. // C++11 interface
  18. ///////////////////////////////////////////////////////////////////////////////
  19. #include <boost/fusion/support/detail/access.hpp>
  20. #include <boost/fusion/support/void.hpp>
  21. #include <boost/fusion/support/detail/enabler.hpp>
  22. #include <boost/fusion/support/sequence_base.hpp>
  23. #include <boost/fusion/support/category_of.hpp>
  24. #include <boost/fusion/support/is_sequence.hpp>
  25. #include <boost/fusion/support/detail/is_same_size.hpp>
  26. #include <boost/fusion/container/vector/vector.hpp>
  27. #include <boost/fusion/container/set/detail/begin_impl.hpp>
  28. #include <boost/fusion/container/set/detail/end_impl.hpp>
  29. #include <boost/fusion/container/set/detail/value_of_impl.hpp>
  30. #include <boost/fusion/container/set/detail/deref_data_impl.hpp>
  31. #include <boost/fusion/container/set/detail/deref_impl.hpp>
  32. #include <boost/fusion/container/set/detail/key_of_impl.hpp>
  33. #include <boost/fusion/container/set/detail/value_of_data_impl.hpp>
  34. #include <boost/mpl/bool.hpp>
  35. #include <boost/core/enable_if.hpp>
  36. namespace boost { namespace fusion
  37. {
  38. struct fusion_sequence_tag;
  39. template <>
  40. struct set<> : sequence_base<set<> >
  41. {
  42. struct category : forward_traversal_tag, associative_tag {};
  43. typedef set_tag fusion_tag;
  44. typedef fusion_sequence_tag tag; // this gets picked up by MPL
  45. typedef mpl::false_ is_view;
  46. typedef vector<> storage_type;
  47. typedef storage_type::size size;
  48. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  49. set()
  50. : data() {}
  51. template <typename Sequence>
  52. BOOST_FUSION_GPU_ENABLED
  53. set(Sequence const& rhs,
  54. typename enable_if<traits::is_sequence<Sequence>, detail::enabler_>::type = detail::enabler,
  55. typename enable_if<detail::is_same_size<Sequence, storage_type>, detail::enabler_>::type = detail::enabler)
  56. : data(rhs) {}
  57. template <typename T>
  58. BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  59. set&
  60. operator=(T const& rhs)
  61. {
  62. data = rhs;
  63. return *this;
  64. }
  65. BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  66. storage_type& get_data() { return data; }
  67. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  68. storage_type const& get_data() const { return data; }
  69. private:
  70. storage_type data;
  71. };
  72. template <typename ...T>
  73. struct set : sequence_base<set<T...> >
  74. {
  75. struct category : forward_traversal_tag, associative_tag {};
  76. typedef set_tag fusion_tag;
  77. typedef fusion_sequence_tag tag; // this gets picked up by MPL
  78. typedef mpl::false_ is_view;
  79. typedef vector<T...> storage_type;
  80. typedef typename storage_type::size size;
  81. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  82. set()
  83. : data() {}
  84. template <typename Sequence>
  85. BOOST_FUSION_GPU_ENABLED
  86. set(Sequence&& rhs,
  87. typename enable_if<traits::is_sequence<Sequence>, detail::enabler_>::type = detail::enabler,
  88. typename enable_if<detail::is_same_size<Sequence, storage_type>, detail::enabler_>::type = detail::enabler)
  89. : data(std::forward<Sequence>(rhs)) {}
  90. template <typename ...U>
  91. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  92. explicit
  93. set(U&& ...args)
  94. : data(std::forward<U>(args)...) {}
  95. template <typename U>
  96. BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  97. set&
  98. operator=(U&& rhs)
  99. {
  100. data = std::forward<U>(rhs);
  101. return *this;
  102. }
  103. BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  104. storage_type& get_data() { return data; }
  105. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  106. storage_type const& get_data() const { return data; }
  107. private:
  108. storage_type data;
  109. };
  110. }}
  111. #endif
  112. #endif