convert.hpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*=============================================================================
  2. Copyright (c) 2001-2011 Joel de Guzman
  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. #if !defined(FUSION_CONVERT_MAIN_09232005_1340)
  7. #define FUSION_CONVERT_MAIN_09232005_1340
  8. #include <boost/fusion/support/config.hpp>
  9. #include <boost/fusion/container/map/map.hpp>
  10. namespace boost { namespace fusion { namespace detail
  11. {
  12. template <typename It, bool is_assoc>
  13. struct pair_from
  14. {
  15. typedef typename result_of::value_of<It>::type type;
  16. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  17. static inline type call(It const& it)
  18. {
  19. return *it;
  20. }
  21. };
  22. template <typename It>
  23. struct pair_from<It, true>
  24. {
  25. typedef typename result_of::key_of<It>::type key_type;
  26. typedef typename result_of::value_of_data<It>::type data_type;
  27. typedef typename fusion::pair<key_type, data_type> type;
  28. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  29. static inline type call(It const& it)
  30. {
  31. return type(deref_data(it));
  32. }
  33. };
  34. }}}
  35. ///////////////////////////////////////////////////////////////////////////////
  36. // Without variadics, we will use the PP version
  37. ///////////////////////////////////////////////////////////////////////////////
  38. #if !defined(BOOST_FUSION_HAS_VARIADIC_MAP)
  39. # include <boost/fusion/container/map/detail/cpp03/convert.hpp>
  40. #else
  41. ///////////////////////////////////////////////////////////////////////////////
  42. // C++11 variadic implementation
  43. ///////////////////////////////////////////////////////////////////////////////
  44. #include <boost/fusion/container/map/detail/build_map.hpp>
  45. namespace boost { namespace fusion
  46. {
  47. namespace result_of
  48. {
  49. template <typename Sequence>
  50. struct as_map :
  51. detail::build_map<
  52. typename result_of::begin<Sequence>::type
  53. , typename result_of::end<Sequence>::type
  54. , is_base_of<
  55. associative_tag
  56. , typename traits::category_of<Sequence>::type>::value
  57. >
  58. {
  59. };
  60. }
  61. template <typename Sequence>
  62. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  63. inline typename result_of::as_map<Sequence>::type
  64. as_map(Sequence& seq)
  65. {
  66. typedef result_of::as_map<Sequence> gen;
  67. return gen::call(fusion::begin(seq), fusion::end(seq));
  68. }
  69. template <typename Sequence>
  70. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  71. inline typename result_of::as_map<Sequence const>::type
  72. as_map(Sequence const& seq)
  73. {
  74. typedef result_of::as_map<Sequence const> gen;
  75. return gen::call(fusion::begin(seq), fusion::end(seq));
  76. }
  77. namespace extension
  78. {
  79. template <typename T>
  80. struct convert_impl;
  81. template <>
  82. struct convert_impl<map_tag>
  83. {
  84. template <typename Sequence>
  85. struct apply
  86. {
  87. typedef typename
  88. result_of::as_map<Sequence>::type
  89. type;
  90. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  91. static type call(Sequence& seq)
  92. {
  93. typedef result_of::as_map<Sequence> gen;
  94. return gen::call(fusion::begin(seq), fusion::end(seq));
  95. }
  96. };
  97. };
  98. }
  99. }}
  100. #endif
  101. #endif