/src/contrib/boost/spirit/home/support/algorithm/any_if_ns.hpp

http://pythonocc.googlecode.com/ · C++ Header · 91 lines · 65 code · 9 blank · 17 comment · 1 complexity · bb657548c23c57fc7805190a767dfb1a MD5 · raw file

  1. /*=============================================================================
  2. Copyright (c) 2001-2010 Hartmut Kaiser
  3. Copyright (c) 2001-2010 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. return (0 != (f(*first1, attribute_value<Pred, First1, Last2>(first2)) |
  47. detail::any_if_ns<Pred>(
  48. fusion::next(first1)
  49. , attribute_next<Pred, First1, Last2>(first2)
  50. , last1, last2
  51. , f
  52. , fusion::result_of::equal_to<
  53. typename fusion::result_of::next<First1>::type, Last1>())));
  54. }
  55. }
  56. template <typename Pred, typename Sequence1, typename Sequence2, typename F>
  57. inline bool
  58. any_if_ns(Sequence1 const& seq1, Sequence2& seq2, F f, Pred)
  59. {
  60. return detail::any_if_ns<Pred>(
  61. fusion::begin(seq1), fusion::begin(seq2)
  62. , fusion::end(seq1), fusion::end(seq2)
  63. , f
  64. , fusion::result_of::equal_to<
  65. typename fusion::result_of::begin<Sequence1>::type
  66. , typename fusion::result_of::end<Sequence1>::type>());
  67. }
  68. template <typename Pred, typename Sequence, typename F>
  69. inline bool
  70. any_if_ns(Sequence const& seq, unused_type const, F f, Pred)
  71. {
  72. return detail::any_ns(
  73. fusion::begin(seq)
  74. , fusion::end(seq)
  75. , f
  76. , fusion::result_of::equal_to<
  77. typename fusion::result_of::begin<Sequence>::type
  78. , typename fusion::result_of::end<Sequence>::type>());
  79. }
  80. }}
  81. #endif