• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*=============================================================================
2     Copyright (c) 2001-2011 Joel de Guzman
3 
4     Distributed under the Boost Software License, Version 1.0. (See accompanying
5     file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 ==============================================================================*/
7 #include <boost/detail/lightweight_test.hpp>
8 #include <boost/fusion/container/vector/vector.hpp>
9 #include <boost/fusion/adapted/mpl.hpp>
10 #include <boost/fusion/sequence/io/out.hpp>
11 #include <boost/fusion/container/generation/make_vector.hpp>
12 #include <boost/fusion/sequence/comparison/equal_to.hpp>
13 #include <boost/fusion/algorithm/transformation/remove_if.hpp>
14 #include <boost/type_traits/is_class.hpp>
15 #include <boost/type_traits/is_same.hpp>
16 #include <boost/mpl/not.hpp>
17 #include <boost/mpl/vector.hpp>
18 
19 struct X
20 {
operator char const*X21     operator char const*() const
22     {
23         return "<X-object>";
24     }
25 };
26 
27 struct Y
28 {
operator char const*Y29     operator char const*() const
30     {
31         return "<Y-object>";
32     }
33 };
34 
35 int
main()36 main()
37 {
38     using namespace boost::fusion;
39     using boost::mpl::vector;
40     using boost::mpl::_;
41     using boost::mpl::not_;
42     using boost::is_class;
43     using boost::is_same;
44     namespace fusion = boost::fusion;
45 
46     std::cout << tuple_open('[');
47     std::cout << tuple_close(']');
48     std::cout << tuple_delimiter(", ");
49 
50 /// Testing remove_if
51 
52     X x; Y y;
53     typedef fusion::vector<Y, char, long, X, bool, double> vector_type;
54     vector_type t(y, '@', 987654, x, true, 6.6);
55 
56     {
57         std::cout << remove_if<not_<is_class<_> > >(t) << std::endl;
58         BOOST_TEST((remove_if<not_<is_class<_> > >(t)
59             == make_vector(y, x)));
60     }
61 
62     {
63         std::cout << remove_if<is_class<_> >(t) << std::endl;
64         BOOST_TEST((remove_if<is_class<_> >(t)
65             == make_vector('@', 987654, true, 6.6)));
66     }
67 
68     {
69         typedef vector<Y, char, long, X, bool> mpl_vec;
70         BOOST_TEST((remove_if<not_<is_class<_> > >(mpl_vec())
71             == vector<Y, X>()));
72         BOOST_TEST((remove_if<is_class<_> >(mpl_vec())
73             == vector<char, long, bool>()));
74     }
75 
76     return boost::report_errors();
77 }
78 
79