any.hpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // any.hpp
  3. //
  4. // Copyright 2008 Eric Niebler. Distributed under the Boost
  5. // Software License, Version 1.0. (See accompanying file
  6. // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  7. #ifndef BOOST_XPRESSIVE_DETAIL_UTILITY_ANY_HPP_EAN_11_19_2005
  8. #define BOOST_XPRESSIVE_DETAIL_UTILITY_ANY_HPP_EAN_11_19_2005
  9. #include <boost/version.hpp>
  10. #if BOOST_VERSION >= 103300
  11. // In Boost 1.33+, we have a cons list in Fusion, so just include it.
  12. # if BOOST_VERSION >= 103500
  13. # include <boost/fusion/include/any.hpp> // Boost 1.35+ has Fusion2
  14. # else
  15. # include <boost/spirit/fusion/algorithm/any.hpp> // Fusion1
  16. # endif
  17. #else
  18. # include <boost/spirit/fusion/sequence/begin.hpp>
  19. # include <boost/spirit/fusion/sequence/end.hpp>
  20. # include <boost/spirit/fusion/iterator/equal_to.hpp>
  21. # include <boost/mpl/bool.hpp>
  22. # include <boost/spirit/fusion/iterator/equal_to.hpp>
  23. # include <boost/spirit/fusion/iterator/next.hpp>
  24. # include <boost/spirit/fusion/iterator/deref.hpp>
  25. namespace boost { namespace fusion
  26. {
  27. namespace detail
  28. {
  29. template <typename First, typename Last, typename F>
  30. inline bool
  31. any(First const&, Last const&, F const&, mpl::true_)
  32. {
  33. return false;
  34. }
  35. template <typename First, typename Last, typename F>
  36. inline bool
  37. any(First const& first, Last const& last, F const& f, mpl::false_)
  38. {
  39. if(f(*first))
  40. return true;
  41. return detail::any(fusion::next(first), last, f
  42. , meta::equal_to<BOOST_DEDUCED_TYPENAME meta::next<First>::type, Last>());
  43. }
  44. }
  45. namespace meta
  46. {
  47. template <typename Sequence, typename F>
  48. struct any
  49. {
  50. typedef bool type;
  51. };
  52. }
  53. namespace function
  54. {
  55. struct any
  56. {
  57. template <typename Sequence, typename F>
  58. struct apply
  59. {
  60. typedef bool type;
  61. };
  62. template <typename Sequence, typename F>
  63. inline bool
  64. operator()(Sequence const& seq, F const& f) const
  65. {
  66. return detail::any(
  67. fusion::begin(seq)
  68. , fusion::end(seq)
  69. , f
  70. , meta::equal_to<
  71. BOOST_DEDUCED_TYPENAME meta::begin<Sequence>::type
  72. , BOOST_DEDUCED_TYPENAME meta::end<Sequence>::type>());
  73. }
  74. template <typename Sequence, typename F>
  75. inline bool
  76. operator()(Sequence& seq, F const& f) const
  77. {
  78. return detail::any(
  79. fusion::begin(seq)
  80. , fusion::end(seq)
  81. , f
  82. , meta::equal_to<
  83. BOOST_DEDUCED_TYPENAME meta::begin<Sequence>::type
  84. , BOOST_DEDUCED_TYPENAME meta::end<Sequence>::type>());
  85. }
  86. };
  87. }
  88. function::any const any = function::any();
  89. }}
  90. #endif
  91. #endif