example_struct_iterator.hpp 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*=============================================================================
  2. Copyright (c) 2001-2011 Joel de Guzman
  3. Copyright (c) 2005-2006 Dan Marsden
  4. Distributed under the Boost Software License, Version 1.0. (See accompanying
  5. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. ==============================================================================*/
  7. #if !defined(BOOST_FUSION_EXAMPLE_STRUCT_ITERATOR)
  8. #define BOOST_FUSION_EXAMPLE_STRUCT_ITERATOR
  9. #include <boost/fusion/support/iterator_base.hpp>
  10. #include <boost/fusion/support/category_of.hpp>
  11. #include <boost/fusion/support/tag_of_fwd.hpp>
  12. #include <boost/mpl/int.hpp>
  13. #include <boost/type_traits/add_const.hpp>
  14. #include <boost/static_assert.hpp>
  15. #include "./detail/next_impl.hpp"
  16. #include "./detail/prior_impl.hpp"
  17. #include "./detail/deref_impl.hpp"
  18. #include "./detail/advance_impl.hpp"
  19. #include "./detail/distance_impl.hpp"
  20. #include "./detail/value_of_impl.hpp"
  21. #include "./detail/equal_to_impl.hpp"
  22. #include "./detail/key_of_impl.hpp"
  23. #include "./detail/value_of_data_impl.hpp"
  24. #include "./detail/deref_data_impl.hpp"
  25. namespace example
  26. {
  27. struct example_struct_iterator_tag;
  28. template<typename Struct, int Pos>
  29. struct example_struct_iterator;
  30. }
  31. namespace boost { namespace fusion {
  32. namespace traits
  33. {
  34. template<typename Struct, int Pos>
  35. struct tag_of<example::example_struct_iterator<Struct, Pos> >
  36. {
  37. typedef example::example_struct_iterator_tag type;
  38. };
  39. }
  40. }}
  41. namespace example {
  42. template<typename Struct, int Pos>
  43. struct example_struct_iterator
  44. : boost::fusion::iterator_base<example_struct_iterator<Struct, Pos> >
  45. {
  46. BOOST_STATIC_ASSERT(Pos >=0 && Pos < 3);
  47. typedef Struct struct_type;
  48. typedef boost::mpl::int_<Pos> index;
  49. struct category
  50. : boost::fusion::random_access_traversal_tag
  51. , boost::fusion::associative_tag
  52. {};
  53. example_struct_iterator(Struct& str)
  54. : struct_(str) {}
  55. Struct& struct_;
  56. };
  57. }
  58. #endif