bug4853.cpp 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*==============================================================================
  2. Copyright (c) 2005-2010 Joel de Guzman
  3. Copyright (c) 2010 Thomas Heller
  4. Copyright (c) 2015 John Fletcher
  5. Distributed under the Boost Software License, Version 1.0. (See accompanying
  6. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  7. ==============================================================================*/
  8. #include <utility> // for std::forward used by boost/range in some cases.
  9. #include <boost/phoenix/core.hpp>
  10. #include <boost/phoenix/operator.hpp>
  11. #include <boost/phoenix/bind.hpp>
  12. #include <boost/range.hpp>
  13. #include <boost/shared_ptr.hpp>
  14. #include <boost/make_shared.hpp>
  15. #include <boost/range/adaptor/transformed.hpp>
  16. #include <boost/range/adaptor/uniqued.hpp>
  17. #include <boost/range/algorithm_ext/push_back.hpp>
  18. #include <vector>
  19. #include <string>
  20. #include <iostream>
  21. namespace phoenix = boost::phoenix;
  22. struct Foo {
  23. Foo(const std::string& name, int value)
  24. : name_(name)
  25. , value_(value)
  26. { }
  27. std::string name_; int value_;
  28. };
  29. typedef boost::shared_ptr<Foo> FooPtr;
  30. int range_test_complex() {
  31. typedef std::vector<FooPtr> V;
  32. V source;
  33. source.push_back(boost::make_shared<Foo>("Foo", 10));
  34. source.push_back(boost::make_shared<Foo>("Bar", 20));
  35. source.push_back(boost::make_shared<Foo>("Baz", 30));
  36. source.push_back(boost::make_shared<Foo>("Baz", 30)); //duplicate is here
  37. std::vector<std::string> result1;
  38. std::vector<int> result2;
  39. using namespace boost::adaptors;
  40. using phoenix::arg_names::arg1;
  41. // This is failing for gcc 4.4 and 4.5 - reason not identified.
  42. #if ((BOOST_GCC_VERSION < 40400) || (BOOST_GCC_VERSION >= 40600))
  43. boost::push_back(result1, source | transformed(phoenix::bind(&Foo::name_, *arg1)) | uniqued);
  44. for(unsigned i = 0; i < result1.size(); ++i)
  45. std::cout << result1[i] << "\n";
  46. #endif
  47. // This is failing for gcc 4.4 and 4.5 - reason not identified.
  48. #if !(BOOST_GCC_VERSION < 40600)
  49. boost::push_back(result2, source | transformed(phoenix::bind(&Foo::value_, *arg1)) | uniqued);
  50. for(unsigned i = 0; i < result2.size(); ++i)
  51. std::cout << result2[i] << "\n";
  52. #endif
  53. return 0;
  54. }
  55. int main()
  56. {
  57. return range_test_complex();
  58. }