replace_if.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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/adapted/mpl.hpp>
  10. #include <boost/fusion/sequence/io/out.hpp>
  11. #include <boost/fusion/sequence/comparison/equal_to.hpp>
  12. #include <boost/fusion/sequence/intrinsic/at.hpp>
  13. #include <boost/fusion/container/generation/make_vector.hpp>
  14. #include <boost/fusion/algorithm/transformation/replace_if.hpp>
  15. #include <string>
  16. struct gt3
  17. {
  18. template <typename T>
  19. bool operator()(T x) const
  20. {
  21. return x > 3;
  22. }
  23. };
  24. int
  25. main()
  26. {
  27. using namespace boost::fusion;
  28. std::cout << tuple_open('[');
  29. std::cout << tuple_close(']');
  30. std::cout << tuple_delimiter(", ");
  31. /// Testing replace
  32. {
  33. char const* s = "Ruby";
  34. typedef vector<int, short, double, long, char const*, float> vector_type;
  35. vector_type t1(1, 2, 3.3, 4, s, 5.5f);
  36. {
  37. std::cout << replace_if(t1, gt3(), -456) << std::endl;
  38. BOOST_TEST((replace_if(t1, gt3(), -456)
  39. == make_vector(1, 2, -456, -456, s, -456)));
  40. }
  41. }
  42. return boost::report_errors();
  43. }