deref.hpp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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_DEREF_05042005_1019)
  7. #define FUSION_DEREF_05042005_1019
  8. #include <boost/fusion/support/config.hpp>
  9. #include <boost/fusion/support/iterator_base.hpp>
  10. #include <boost/fusion/support/tag_of.hpp>
  11. namespace boost { namespace fusion
  12. {
  13. // Special tags:
  14. struct iterator_facade_tag; // iterator facade tag
  15. struct boost_array_iterator_tag; // boost::array iterator tag
  16. struct mpl_iterator_tag; // mpl sequence iterator tag
  17. struct std_pair_iterator_tag; // std::pair iterator tag
  18. namespace extension
  19. {
  20. template <typename Tag>
  21. struct deref_impl
  22. {
  23. template <typename Iterator>
  24. struct apply {};
  25. };
  26. template <>
  27. struct deref_impl<iterator_facade_tag>
  28. {
  29. template <typename Iterator>
  30. struct apply : Iterator::template deref<Iterator> {};
  31. };
  32. template <>
  33. struct deref_impl<boost_array_iterator_tag>;
  34. template <>
  35. struct deref_impl<mpl_iterator_tag>;
  36. template <>
  37. struct deref_impl<std_pair_iterator_tag>;
  38. }
  39. namespace result_of
  40. {
  41. template <typename Iterator>
  42. struct deref
  43. : extension::deref_impl<typename detail::tag_of<Iterator>::type>::
  44. template apply<Iterator>
  45. {};
  46. }
  47. template <typename Iterator>
  48. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  49. inline typename result_of::deref<Iterator>::type
  50. deref(Iterator const& i)
  51. {
  52. typedef result_of::deref<Iterator> deref_meta;
  53. return deref_meta::call(i);
  54. }
  55. template <typename Iterator>
  56. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  57. inline typename result_of::deref<Iterator>::type
  58. operator*(iterator_base<Iterator> const& i)
  59. {
  60. return fusion::deref(i.cast());
  61. }
  62. }}
  63. #endif