strictest_traversal.hpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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(FUSION_STRICTEST_TRAVERSAL_20060123_2101)
  8. #define FUSION_STRICTEST_TRAVERSAL_20060123_2101
  9. #include <boost/fusion/support/config.hpp>
  10. #include <boost/config.hpp>
  11. #include <boost/mpl/or.hpp>
  12. #include <boost/mpl/if.hpp>
  13. #include <boost/fusion/support/category_of.hpp>
  14. #include <boost/fusion/mpl.hpp>
  15. #include <boost/fusion/algorithm/iteration/fold.hpp>
  16. #include <boost/type_traits/remove_reference.hpp>
  17. #include <boost/type_traits/is_convertible.hpp>
  18. namespace boost { namespace fusion
  19. {
  20. struct forward_traversal_tag;
  21. struct bidirectional_traversal_tag;
  22. struct random_access_traversal_tag;
  23. namespace detail
  24. {
  25. template<typename Tag1, typename Tag2,
  26. bool Tag1Stricter = boost::is_convertible<Tag2,Tag1>::value>
  27. struct stricter_traversal
  28. {
  29. typedef Tag1 type;
  30. };
  31. template<typename Tag1, typename Tag2>
  32. struct stricter_traversal<Tag1,Tag2,false>
  33. {
  34. typedef Tag2 type;
  35. };
  36. struct strictest_traversal_impl
  37. {
  38. template<typename Sig>
  39. struct result;
  40. template<typename StrictestSoFar, typename Next>
  41. struct result<strictest_traversal_impl(StrictestSoFar, Next)>
  42. {
  43. typedef typename remove_reference<Next>::type next_value;
  44. typedef typename remove_reference<StrictestSoFar>::type strictest_so_far;
  45. typedef strictest_so_far tag1;
  46. typedef typename traits::category_of<next_value>::type tag2;
  47. typedef typename stricter_traversal<tag1,tag2>::type type;
  48. };
  49. // never called, but needed for decltype-based result_of (C++0x)
  50. #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
  51. template<typename StrictestSoFar, typename Next>
  52. BOOST_FUSION_GPU_ENABLED
  53. typename result<strictest_traversal_impl(StrictestSoFar, Next)>::type
  54. operator()(StrictestSoFar&&, Next&&) const;
  55. #endif
  56. };
  57. template<typename Sequence>
  58. struct strictest_traversal
  59. : result_of::fold<
  60. Sequence, fusion::random_access_traversal_tag,
  61. strictest_traversal_impl>
  62. {};
  63. }
  64. }}
  65. #endif