remove.cpp 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*=============================================================================
  2. Copyright (c) 2001-2011 Joel de Guzman
  3. Distributed under the Boost Software License, Version 1.0. (See accompanying
  4. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. ==============================================================================*/
  6. #include <boost/detail/lightweight_test.hpp>
  7. #include <boost/fusion/container/vector/vector.hpp>
  8. #include <boost/fusion/adapted/mpl.hpp>
  9. #include <boost/fusion/sequence/io/out.hpp>
  10. #include <boost/fusion/container/generation/make_vector.hpp>
  11. #include <boost/fusion/sequence/comparison/equal_to.hpp>
  12. #include <boost/fusion/algorithm/transformation/remove.hpp>
  13. #include <boost/mpl/vector.hpp>
  14. struct X
  15. {
  16. operator char const*() const
  17. {
  18. return "<X-object>";
  19. }
  20. };
  21. struct Y
  22. {
  23. operator char const*() const
  24. {
  25. return "<Y-object>";
  26. }
  27. };
  28. int
  29. main()
  30. {
  31. using namespace boost::fusion;
  32. using boost::mpl::identity;
  33. using boost::mpl::vector;
  34. namespace fusion = boost::fusion;
  35. std::cout << tuple_open('[');
  36. std::cout << tuple_close(']');
  37. std::cout << tuple_delimiter(", ");
  38. /// Testing remove
  39. X x; Y y;
  40. typedef fusion::vector<Y, char, long, X, bool, double> vector_type;
  41. vector_type t(y, '@', 987654, x, true, 6.6);
  42. {
  43. std::cout << fusion::remove<X>(t) << std::endl;
  44. BOOST_TEST((fusion::remove<X>(t)
  45. == make_vector(y, '@', 987654, true, 6.6)));
  46. }
  47. {
  48. std::cout << fusion::remove<Y>(t) << std::endl;
  49. BOOST_TEST((fusion::remove<Y>(t)
  50. == make_vector('@', 987654, x, true, 6.6)));
  51. }
  52. {
  53. std::cout << fusion::remove<long>(t) << std::endl;
  54. BOOST_TEST((fusion::remove<long>(t)
  55. == make_vector(y, '@', x, true, 6.6)));
  56. }
  57. {
  58. typedef vector<Y, char, long, X, bool> mpl_vec;
  59. BOOST_TEST((fusion::remove<X>(mpl_vec())
  60. == vector<Y, char, long, bool>()));
  61. BOOST_TEST((fusion::remove<Y>(mpl_vec())
  62. == vector<char, long, X, bool>()));
  63. BOOST_TEST((fusion::remove<long>(mpl_vec())
  64. == vector<Y, char, X, bool>()));
  65. }
  66. return boost::report_errors();
  67. }