deref.hpp 2.0 KB

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