any_if_ns_so.hpp 3.5 KB

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