iterator_facade.hpp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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_ITERATOR_FACADE_09252006_1011)
  7. #define FUSION_ITERATOR_FACADE_09252006_1011
  8. #include <boost/fusion/support/config.hpp>
  9. #include <boost/fusion/support/iterator_base.hpp>
  10. #include <boost/fusion/iterator/detail/advance.hpp>
  11. #include <boost/fusion/iterator/detail/distance.hpp>
  12. #include <boost/fusion/support/category_of.hpp>
  13. #include <boost/type_traits/is_same.hpp>
  14. #include <boost/mpl/assert.hpp>
  15. #include <boost/mpl/if.hpp>
  16. namespace boost { namespace fusion
  17. {
  18. struct iterator_facade_tag;
  19. template <typename Derived, typename Category>
  20. struct iterator_facade : iterator_base<Derived>
  21. {
  22. typedef iterator_facade_tag fusion_tag;
  23. typedef Derived derived_type;
  24. typedef Category category;
  25. // default implementation
  26. template <typename I1, typename I2>
  27. struct equal_to // default implementation
  28. : is_same<
  29. typename I1::derived_type
  30. , typename I2::derived_type
  31. >
  32. {};
  33. // default implementation
  34. template <typename Iterator, typename N>
  35. struct advance :
  36. mpl::if_c<
  37. (N::value > 0)
  38. , advance_detail::forward<Iterator, N::value>
  39. , advance_detail::backward<Iterator, N::value>
  40. >::type
  41. {
  42. BOOST_MPL_ASSERT_NOT((traits::is_random_access<Iterator>));
  43. };
  44. // default implementation
  45. template <typename First, typename Last>
  46. struct distance :
  47. distance_detail::linear_distance<First, Last>
  48. {};
  49. };
  50. }}
  51. #ifdef BOOST_FUSION_WORKAROUND_FOR_LWG_2408
  52. namespace std
  53. {
  54. template <typename Derived, typename Category>
  55. struct iterator_traits< ::boost::fusion::iterator_facade<Derived, Category> >
  56. { };
  57. }
  58. #endif
  59. #endif