all.cpp 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*=============================================================================
  2. Copyright (c) 2001-2011 Joel de Guzman
  3. Copyright (c) 2007 Dan Marsden
  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. #include <boost/detail/lightweight_test.hpp>
  8. #include <boost/fusion/container/vector/vector.hpp>
  9. #include <boost/fusion/adapted/mpl.hpp>
  10. #include <boost/fusion/algorithm/query/all.hpp>
  11. #include <boost/lambda/lambda.hpp>
  12. #include <boost/mpl/vector_c.hpp>
  13. namespace
  14. {
  15. struct search_for
  16. {
  17. explicit search_for(int in_search)
  18. : search(in_search)
  19. {}
  20. template<typename T>
  21. bool operator()(T const& v) const
  22. {
  23. return v == search;
  24. }
  25. int search;
  26. };
  27. }
  28. int
  29. main()
  30. {
  31. {
  32. boost::fusion::vector<> t;
  33. BOOST_TEST((boost::fusion::all(t, boost::lambda::_1 < 4)));
  34. BOOST_TEST((boost::fusion::all(t, boost::lambda::_1 > 0)));
  35. }
  36. {
  37. boost::fusion::vector<int, short, double> t(1, 2, 3.3);
  38. BOOST_TEST((boost::fusion::all(t, boost::lambda::_1 < 4)));
  39. BOOST_TEST((boost::fusion::all(t, boost::lambda::_1 > 0)));
  40. }
  41. {
  42. boost::fusion::vector<int, short, double, long> t(1, 2, 3.3, 2);
  43. BOOST_TEST((boost::fusion::all(t, boost::lambda::_1 < 4)));
  44. BOOST_TEST((boost::fusion::all(t, boost::lambda::_1 > 0)));
  45. }
  46. {
  47. boost::fusion::vector<int, short, double> t(1, 2, 3.3);
  48. BOOST_TEST((!boost::fusion::all(t, boost::lambda::_1 == 1)));
  49. BOOST_TEST((!boost::fusion::all(t, boost::lambda::_1 < 3)));
  50. }
  51. {
  52. typedef boost::mpl::vector_c<int, 1> mpl_vec;
  53. // We cannot use lambda here as mpl vec iterators return
  54. // rvalues, and lambda needs lvalues.
  55. BOOST_TEST(boost::fusion::all(mpl_vec(), search_for(1)));
  56. BOOST_TEST(!boost::fusion::all(mpl_vec(), search_for(2)));
  57. }
  58. return boost::report_errors();
  59. }