PageRenderTime 30ms CodeModel.GetById 21ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/Src/Dependencies/Boost/libs/phoenix/test/regression/bug4853.cpp

http://hadesmem.googlecode.com/
C++ | 70 lines | 43 code | 20 blank | 7 comment | 2 complexity | a0c0880dc817b620877fd15e2169e4e0 MD5 | raw file
 1/*==============================================================================
 2    Copyright (c) 2005-2010 Joel de Guzman
 3    Copyright (c) 2010 Thomas Heller
 4
 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
 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
19#include <vector>
20#include <string>
21
22
23namespace phoenix = boost::phoenix;
24
25struct Foo {
26    Foo(const std::string& name, int value)
27        : name_(name)
28        , value_(value)
29    { }
30    
31    std::string name_; int value_;
32};
33
34typedef boost::shared_ptr<Foo> FooPtr;
35
36int range_test_complex() {
37    typedef std::vector<FooPtr> V;
38    
39    V source;
40    
41    source.push_back(boost::make_shared<Foo>("Foo", 10));
42    source.push_back(boost::make_shared<Foo>("Bar", 20));
43    source.push_back(boost::make_shared<Foo>("Baz", 30));
44    source.push_back(boost::make_shared<Foo>("Baz", 30)); //duplicate is here
45    
46    std::vector<std::string> result1;
47    std::vector<int> result2;
48    
49    using namespace boost::adaptors;
50    using phoenix::arg_names::arg1;
51    
52    boost::push_back(result1, source | transformed(phoenix::bind(&Foo::name_, *arg1)) | uniqued);
53
54    for(unsigned i = 0; i < result1.size(); ++i)
55        std::cout << result1[i] << "\n";
56    
57    boost::push_back(result2, source | transformed(phoenix::bind(&Foo::value_, *arg1)) | uniqued);
58
59    for(unsigned i = 0; i < result2.size(); ++i)
60        std::cout << result2[i] << "\n";
61    
62    return 0;
63    
64}
65
66int main()
67{
68    return range_test_complex();
69}
70