• 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/filter_if.hpp>
14 #include <boost/type_traits/is_class.hpp>
15 #include <boost/type_traits/is_same.hpp>
16 #include <boost/mpl/vector.hpp>
17 #include <boost/mpl/not.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 
40     using boost::mpl::_;
41     using boost::mpl::not_;
42     using boost::is_class;
43     using boost::is_same;
44 
45     std::cout << tuple_open('[');
46     std::cout << tuple_close(']');
47     std::cout << tuple_delimiter(", ");
48 
49 /// Testing filter_if
50 
51     X x; Y y;
52     typedef boost::fusion::vector<Y, char, long, X, bool, double> vector_type;
53     vector_type t(y, '@', 987654, x, true, 6.6);
54 
55     {
56         std::cout << filter_if<not_<is_class<_> > >(t) << std::endl;
57         BOOST_TEST((filter_if<not_<is_class<_> > >(t)
58             == make_vector('@', 987654, true, 6.6)));
59     }
60 
61     {
62         std::cout << filter_if<is_class<_> >(t) << std::endl;
63         BOOST_TEST((filter_if<is_class<_> >(t)
64             == make_vector(y, x)));
65     }
66 
67     {
68         typedef boost::mpl::vector<Y, char, long, X, bool> mpl_vec;
69         BOOST_TEST((filter_if<not_<is_class<_> > >(mpl_vec())
70             == make_vector(char(), long(), bool())));
71         BOOST_TEST((filter_if<is_class<_> >(mpl_vec())
72             == make_vector(y, x)));
73     }
74 
75     return boost::report_errors();
76 }
77 
78