strictest_traversal.hpp 2.5 KB

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