none.cpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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/none.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<int, short, double> t(1, 2, 3.3);
  33. BOOST_TEST((boost::fusion::none(t, boost::lambda::_1 > 4)));
  34. BOOST_TEST((boost::fusion::none(t, boost::lambda::_1 < 0)));
  35. }
  36. {
  37. boost::fusion::vector<int, short, double> t(1, 2, 3.3);
  38. BOOST_TEST((!boost::fusion::none(t, boost::lambda::_1 == 1)));
  39. BOOST_TEST((!boost::fusion::none(t, boost::lambda::_1 < 3)));
  40. }
  41. {
  42. typedef boost::mpl::vector_c<int, 1, 2, 3> mpl_vec;
  43. // We cannot use lambda here as mpl vec iterators return
  44. // rvalues, and lambda needs lvalues.
  45. BOOST_TEST(boost::fusion::none(mpl_vec(), search_for(4)));
  46. BOOST_TEST(!boost::fusion::none(mpl_vec(), search_for(3)));
  47. }
  48. return boost::report_errors();
  49. }