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