convert.hpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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/container/map/map.hpp>
  9. ///////////////////////////////////////////////////////////////////////////////
  10. // Without variadics, we will use the PP version
  11. ///////////////////////////////////////////////////////////////////////////////
  12. #if !defined(BOOST_FUSION_HAS_VARIADIC_MAP)
  13. # include <boost/fusion/container/map/detail/cpp03/convert.hpp>
  14. #else
  15. ///////////////////////////////////////////////////////////////////////////////
  16. // C++11 variadic implementation
  17. ///////////////////////////////////////////////////////////////////////////////
  18. #include <boost/fusion/container/map/detail/build_map.hpp>
  19. namespace boost { namespace fusion
  20. {
  21. namespace result_of
  22. {
  23. template <typename Sequence>
  24. struct as_map :
  25. detail::build_map<
  26. typename result_of::begin<Sequence>::type
  27. , typename result_of::end<Sequence>::type
  28. >
  29. {
  30. };
  31. }
  32. template <typename Sequence>
  33. inline typename result_of::as_map<Sequence>::type
  34. as_map(Sequence& seq)
  35. {
  36. typedef result_of::as_map<Sequence> gen;
  37. return gen::call(fusion::begin(seq), fusion::end(seq));
  38. }
  39. template <typename Sequence>
  40. inline typename result_of::as_map<Sequence const>::type
  41. as_map(Sequence const& seq)
  42. {
  43. typedef result_of::as_map<Sequence const> gen;
  44. return gen::call(fusion::begin(seq), fusion::end(seq));
  45. }
  46. namespace extension
  47. {
  48. template <typename T>
  49. struct convert_impl;
  50. template <>
  51. struct convert_impl<map_tag>
  52. {
  53. template <typename Sequence>
  54. struct apply
  55. {
  56. typedef typename
  57. result_of::as_map<Sequence>::type
  58. type;
  59. static type call(Sequence& seq)
  60. {
  61. typedef result_of::as_map<Sequence> gen;
  62. return gen::call(fusion::begin(seq), fusion::end(seq));
  63. }
  64. };
  65. };
  66. }
  67. }}
  68. #endif
  69. #endif