any_if_ns.hpp 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*=============================================================================
  2. Copyright (c) 2001-2011 Hartmut Kaiser
  3. Copyright (c) 2001-2011 Joel de Guzman
  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_SPIRIT_ANY_IF_NS_NOVEMBER_04_2008_0906PM)
  8. #define BOOST_SPIRIT_ANY_IF_NS_NOVEMBER_04_2008_0906PM
  9. #if defined(_MSC_VER)
  10. #pragma once
  11. #endif
  12. #include <boost/spirit/home/support/algorithm/any_if.hpp>
  13. #include <boost/spirit/home/support/algorithm/any_ns.hpp>
  14. namespace boost { namespace spirit
  15. {
  16. ///////////////////////////////////////////////////////////////////////////
  17. // This is a special version for a binary fusion::any. The predicate
  18. // is used to decide whether to advance the second iterator or not.
  19. // This is needed for sequences containing components with unused
  20. // attributes. The second iterator is advanced only if the attribute
  21. // of the corresponding component iterator is not unused.
  22. //
  23. // This is a non-short circuiting (ns) version of the any_if algorithm.
  24. // see any_if.hpp (uses | instead of ||).
  25. ///////////////////////////////////////////////////////////////////////////
  26. namespace detail
  27. {
  28. template <
  29. typename Pred, typename First1, typename Last1, typename First2
  30. , typename Last2, typename F
  31. >
  32. inline bool
  33. any_if_ns(First1 const&, First2 const&, Last1 const&, Last2 const&
  34. , F const&, mpl::true_)
  35. {
  36. return false;
  37. }
  38. template <
  39. typename Pred, typename First1, typename Last1, typename First2
  40. , typename Last2, typename F
  41. >
  42. inline bool
  43. any_if_ns(First1 const& first1, First2 const& first2
  44. , Last1 const& last1, Last2 const& last2, F& f, mpl::false_)
  45. {
  46. typename result_of::attribute_value<First1, First2, Last2, Pred>::type
  47. attribute = spirit::detail::attribute_value<Pred, First1, Last2>(first2);
  48. return (0 != (f(*first1, attribute) |
  49. detail::any_if_ns<Pred>(
  50. fusion::next(first1)
  51. , attribute_next<Pred, First1, Last2>(first2)
  52. , last1, last2
  53. , f
  54. , fusion::result_of::equal_to<
  55. typename fusion::result_of::next<First1>::type, Last1>())));
  56. }
  57. }
  58. template <typename Pred, typename Sequence1, typename Sequence2, typename F>
  59. inline bool
  60. any_if_ns(Sequence1 const& seq1, Sequence2& seq2, F f, Pred)
  61. {
  62. return detail::any_if_ns<Pred>(
  63. fusion::begin(seq1), fusion::begin(seq2)
  64. , fusion::end(seq1), fusion::end(seq2)
  65. , f
  66. , fusion::result_of::equal_to<
  67. typename fusion::result_of::begin<Sequence1>::type
  68. , typename fusion::result_of::end<Sequence1>::type>());
  69. }
  70. template <typename Pred, typename Sequence, typename F>
  71. inline bool
  72. any_if_ns(Sequence const& seq, unused_type const, F f, Pred)
  73. {
  74. return detail::any_ns(
  75. fusion::begin(seq)
  76. , fusion::end(seq)
  77. , f
  78. , fusion::result_of::equal_to<
  79. typename fusion::result_of::begin<Sequence>::type
  80. , typename fusion::result_of::end<Sequence>::type>());
  81. }
  82. }}
  83. #endif