any.hpp 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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(BOOST_SPIRIT_ANY_APRIL_22_2006_1147AM)
  7. #define BOOST_SPIRIT_ANY_APRIL_22_2006_1147AM
  8. #if defined(_MSC_VER)
  9. #pragma once
  10. #endif
  11. #include <boost/mpl/bool.hpp>
  12. #include <boost/fusion/include/equal_to.hpp>
  13. #include <boost/fusion/include/next.hpp>
  14. #include <boost/fusion/include/deref.hpp>
  15. #include <boost/fusion/include/begin.hpp>
  16. #include <boost/fusion/include/end.hpp>
  17. #include <boost/fusion/include/any.hpp>
  18. #include <boost/spirit/home/support/unused.hpp>
  19. namespace boost { namespace spirit
  20. {
  21. // This is the binary version of fusion::any. This might
  22. // be a good candidate for inclusion in fusion algorithm
  23. namespace detail
  24. {
  25. template <typename First1, typename Last, typename First2, typename F>
  26. inline bool
  27. any(First1 const&, First2 const&, Last const&, F const&, mpl::true_)
  28. {
  29. return false;
  30. }
  31. template <typename First1, typename Last, typename First2, typename F>
  32. inline bool
  33. any(First1 const& first1, First2 const& first2, Last const& last, F& f, mpl::false_)
  34. {
  35. return f(*first1, *first2) ||
  36. detail::any(
  37. fusion::next(first1)
  38. , fusion::next(first2)
  39. , last
  40. , f
  41. , fusion::result_of::equal_to<
  42. typename fusion::result_of::next<First1>::type, Last>());
  43. }
  44. }
  45. template <typename Sequence1, typename Sequence2, typename F>
  46. inline bool
  47. any(Sequence1 const& seq1, Sequence2& seq2, F f)
  48. {
  49. return detail::any(
  50. fusion::begin(seq1)
  51. , fusion::begin(seq2)
  52. , fusion::end(seq1)
  53. , f
  54. , fusion::result_of::equal_to<
  55. typename fusion::result_of::begin<Sequence1>::type
  56. , typename fusion::result_of::end<Sequence1>::type>());
  57. }
  58. template <typename Sequence, typename F>
  59. inline bool
  60. any(Sequence const& seq, unused_type, F f)
  61. {
  62. return fusion::any(seq, f);
  63. }
  64. }}
  65. #endif