deref_impl.hpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*=============================================================================
  2. Copyright (c) 2001-2011 Joel de Guzman
  3. Copyright (c) 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_DEREF_IMPL_20060222_1952)
  8. #define BOOST_FUSION_DEREF_IMPL_20060222_1952
  9. #include <boost/static_assert.hpp>
  10. #include <boost/type_traits/is_const.hpp>
  11. #include <boost/mpl/if.hpp>
  12. #include <string>
  13. namespace example
  14. {
  15. struct example_struct_iterator_tag;
  16. template<typename Struct, int Pos>
  17. struct example_struct_iterator;
  18. }
  19. namespace boost { namespace fusion {
  20. namespace extension
  21. {
  22. template<typename Tag>
  23. struct deref_impl;
  24. template<>
  25. struct deref_impl<example::example_struct_iterator_tag>
  26. {
  27. template<typename Iterator>
  28. struct apply;
  29. template<typename Struct>
  30. struct apply<example::example_struct_iterator<Struct, 0> >
  31. {
  32. typedef typename mpl::if_<
  33. is_const<Struct>, std::string const&, std::string&>::type type;
  34. static type
  35. call(example::example_struct_iterator<Struct, 0> const& it)
  36. {
  37. return it.struct_.name;
  38. }
  39. };
  40. template<typename Struct>
  41. struct apply<example::example_struct_iterator<Struct, 1> >
  42. {
  43. typedef typename mpl::if_<
  44. is_const<Struct>, int const&, int&>::type type;
  45. static type
  46. call(example::example_struct_iterator<Struct, 1> const& it)
  47. {
  48. return it.struct_.age;
  49. }
  50. };
  51. };
  52. }
  53. }}
  54. #endif