build_map.hpp 2.2 KB

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