erase.cpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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/container/vector/vector_iterator.hpp>
  9. #include <boost/fusion/adapted/mpl.hpp>
  10. #include <boost/fusion/sequence/io/out.hpp>
  11. #include <boost/fusion/sequence/comparison/equal_to.hpp>
  12. #include <boost/fusion/container/generation/make_vector.hpp>
  13. #include <boost/fusion/algorithm/transformation/erase.hpp>
  14. #include <boost/mpl/vector_c.hpp>
  15. #include <boost/mpl/begin_end.hpp>
  16. #include <boost/mpl/advance.hpp>
  17. #include <boost/mpl/int.hpp>
  18. int
  19. main()
  20. {
  21. using namespace boost::fusion;
  22. using boost::mpl::vector_c;
  23. using boost::mpl::begin;
  24. using boost::mpl::advance;
  25. using boost::mpl::int_;
  26. std::cout << tuple_open('[');
  27. std::cout << tuple_close(']');
  28. std::cout << tuple_delimiter(", ");
  29. /// Testing erase
  30. {
  31. typedef vector<int, char, double, char const*> vector_type;
  32. vector_type t1(1, 'x', 3.3, "Ruby");
  33. vector_iterator<vector_type, 2> pos(t1);
  34. std::cout << erase(t1, pos) << std::endl;
  35. BOOST_TEST((erase(t1, pos) == make_vector(1, 'x', std::string("Ruby"))));
  36. BOOST_TEST((erase(t1, end(t1)) == make_vector(1, 'x', 3.3, std::string("Ruby"))));
  37. }
  38. {
  39. typedef vector_c<int, 1, 2, 3, 4, 5> mpl_vec;
  40. typedef boost::mpl::begin<mpl_vec>::type mpl_vec_begin;
  41. typedef boost::mpl::advance<mpl_vec_begin, int_<3> >::type mpl_vec_at3;
  42. typedef boost::mpl::next<mpl_vec_begin>::type n1;
  43. typedef boost::mpl::next<n1>::type n2;
  44. typedef boost::mpl::next<n2>::type n3;
  45. BOOST_STATIC_ASSERT((boost::is_same<mpl_vec_at3, n3>::value));
  46. std::cout << erase(mpl_vec(), mpl_vec_at3()) << std::endl;
  47. BOOST_TEST((erase(mpl_vec(), mpl_vec_at3())
  48. == make_vector(1, 2, 3, 5)));
  49. }
  50. return boost::report_errors();
  51. }