build_map.hpp 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*=============================================================================
  2. Copyright (c) 2005-2013 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(BOOST_FUSION_BUILD_MAP_02042013_1448)
  7. #define BOOST_FUSION_BUILD_MAP_02042013_1448
  8. #include <boost/fusion/support/config.hpp>
  9. #include <boost/fusion/iterator/equal_to.hpp>
  10. #include <boost/fusion/iterator/next.hpp>
  11. #include <boost/fusion/iterator/value_of.hpp>
  12. #include <boost/fusion/iterator/deref.hpp>
  13. #include <boost/fusion/sequence/intrinsic/begin.hpp>
  14. #include <boost/fusion/sequence/intrinsic/end.hpp>
  15. #include <boost/fusion/container/map/map.hpp>
  16. #include <boost/fusion/algorithm/transformation/push_front.hpp>
  17. namespace boost { namespace fusion { namespace detail
  18. {
  19. template <typename First, typename Last, bool is_assoc
  20. , bool is_empty = result_of::equal_to<First, Last>::value
  21. >
  22. struct build_map;
  23. template <typename First, typename Last, bool is_assoc>
  24. struct build_map<First, Last, is_assoc, true>
  25. {
  26. typedef map<> type;
  27. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  28. static type
  29. call(First const&, Last const&)
  30. {
  31. return type();
  32. }
  33. };
  34. template <typename T, typename Rest>
  35. struct push_front_map;
  36. template <typename T, typename ...Rest>
  37. struct push_front_map<T, map<Rest...>>
  38. {
  39. typedef map<T, Rest...> type;
  40. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  41. static type
  42. call(T const& first, map<Rest...> const& rest)
  43. {
  44. return type(push_front(rest, first));
  45. }
  46. };
  47. template <typename First, typename Last, bool is_assoc>
  48. struct build_map<First, Last, is_assoc, false>
  49. {
  50. typedef
  51. build_map<typename result_of::next<First>::type, Last, is_assoc>
  52. next_build_map;
  53. typedef push_front_map<
  54. typename pair_from<First, is_assoc>::type
  55. , typename next_build_map::type>
  56. push_front;
  57. typedef typename push_front::type type;
  58. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  59. static type
  60. call(First const& f, Last const& l)
  61. {
  62. return push_front::call(
  63. pair_from<First, is_assoc>::call(f)
  64. , next_build_map::call(fusion::next(f), l));
  65. }
  66. };
  67. }}}
  68. #endif