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/algorithm/query/find_if.hpp>
12 #include <boost/mpl/vector.hpp>
13 #include <boost/mpl/vector_c.hpp>
14 #include <boost/mpl/less.hpp>
15 #include <boost/type_traits/is_same.hpp>
16
17 struct X
18 {
operator intX19 operator int() const
20 {
21 return 12345;
22 }
23 };
24
25 int
main()26 main()
27 {
28 using namespace boost::fusion;
29
30 {
31 using boost::is_same;
32 using boost::mpl::_;
33
34 typedef vector<int, char, int, double> vector_type;
35 vector_type v(12345, 'x', 678910, 3.36);
36
37 std::cout << *find_if<is_same<_, char> >(v) << std::endl;
38 BOOST_TEST((*find_if<is_same<_, char> >(v) == 'x'));
39
40 std::cout << *find_if<is_same<_, int> >(v) << std::endl;
41 BOOST_TEST((*find_if<is_same<_, int> >(v) == 12345));
42
43 std::cout << *find_if<is_same<_, double> >(v) << std::endl;
44 BOOST_TEST((*find_if<is_same<_, double> >(v) == 3.36));
45 }
46
47 {
48 using boost::mpl::vector;
49 using boost::is_same;
50 using boost::mpl::_;
51
52 typedef vector<int, char, X, double> mpl_vec;
53 BOOST_TEST((*find_if<is_same<_, X> >(mpl_vec()) == 12345));
54 }
55
56 {
57 using boost::mpl::vector_c;
58 using boost::mpl::less;
59 using boost::mpl::int_;
60 using boost::is_same;
61 using boost::mpl::_;
62
63 typedef vector_c<int, 1, 2, 3, 4> mpl_vec;
64 BOOST_TEST((*find_if<less<_, int_<3> > >(mpl_vec()) == 1));
65 }
66
67 return boost::report_errors();
68 }
69
70