push_front.cpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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/sequence/comparison/equal_to.hpp>
  11. #include <boost/fusion/container/generation/make_vector.hpp>
  12. #include <boost/fusion/algorithm/transformation/push_front.hpp>
  13. #include <boost/mpl/vector_c.hpp>
  14. #include <string>
  15. int
  16. main()
  17. {
  18. using namespace boost::fusion;
  19. std::cout << tuple_open('[');
  20. std::cout << tuple_close(']');
  21. std::cout << tuple_delimiter(", ");
  22. /// Testing push_front
  23. {
  24. char const* s = "Ruby";
  25. typedef vector<int, char, double, char const*> vector_type;
  26. vector_type t1(1, 'x', 3.3, s);
  27. {
  28. std::cout << push_front(t1, 123456) << std::endl;
  29. BOOST_TEST((push_front(t1, 123456)
  30. == make_vector(123456, 1, 'x', 3.3, s)));
  31. }
  32. {
  33. std::cout << push_front(t1, "lively") << std::endl;
  34. BOOST_TEST((push_front(t1, "lively")
  35. == make_vector(std::string("lively"), 1, 'x', 3.3, s)));
  36. }
  37. }
  38. {
  39. typedef boost::mpl::vector_c<int, 2, 3, 4, 5, 6> mpl_vec;
  40. std::cout << boost::fusion::push_front(mpl_vec(), boost::mpl::int_<1>()) << std::endl;
  41. BOOST_TEST((boost::fusion::push_front(mpl_vec(), boost::mpl::int_<1>())
  42. == make_vector(1, 2, 3, 4, 5, 6)));
  43. }
  44. return boost::report_errors();
  45. }