• 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/container/set/set.hpp>
11 #include <boost/fusion/container/map/map.hpp>
12 #include <boost/fusion/algorithm/query/find.hpp>
13 #include <boost/fusion/iterator/deref.hpp>
14 #include <boost/mpl/vector.hpp>
15 #include <string>
16 
17 struct X
18 {
operator intX19     operator int() const
20     {
21         return 12345;
22     }
23 };
24 int
main()25 main()
26 {
27     using namespace boost::fusion;
28     using boost::mpl::identity;
29 
30     {
31         typedef vector<int, char, int, double> seq_type;
32         seq_type seq(12345, 'x', 678910, 3.36);
33 
34         std::cout << *boost::fusion::find<char>(seq) << std::endl;
35         BOOST_TEST(*boost::fusion::find<char>(seq) == 'x');
36 
37         std::cout << *boost::fusion::find<int>(seq) << std::endl;
38         BOOST_TEST(*boost::fusion::find<int>(seq) == 12345);
39 
40         std::cout << *boost::fusion::find<double>(seq) << std::endl;
41         BOOST_TEST(*boost::fusion::find<double>(seq) == 3.36);
42 
43         BOOST_TEST(boost::fusion::find<bool>(seq) == boost::fusion::end(seq));
44     }
45 
46     {
47         typedef set<int, char, double> seq_type;
48         seq_type seq(12345, 'x', 3.36);
49         std::cout << *boost::fusion::find<char>(seq) << std::endl;
50         BOOST_TEST(*boost::fusion::find<char>(seq) == 'x');
51         BOOST_TEST(boost::fusion::find<bool>(seq) == boost::fusion::end(seq));
52     }
53 
54     {
55         typedef map<
56             pair<int, char>
57           , pair<double, std::string> >
58         map_type;
59 
60         map_type seq(
61             make_pair<int>('X')
62           , make_pair<double>("Men"));
63 
64         std::cout << *boost::fusion::find<int>(seq) << std::endl;
65         std::cout << *boost::fusion::find<double>(seq) << std::endl;
66         BOOST_TEST((*boost::fusion::find<int>(seq)).second == 'X');
67         BOOST_TEST((*boost::fusion::find<double>(seq)).second == "Men");
68         BOOST_TEST(boost::fusion::find<bool>(seq) == boost::fusion::end(seq));
69     }
70 
71     {
72         typedef boost::mpl::vector<int, char, X, double> mpl_vec;
73         BOOST_TEST((*boost::fusion::find<X>(mpl_vec()) == 12345));
74         BOOST_TEST(boost::fusion::find<bool>(mpl_vec()) == boost::fusion::end(mpl_vec()));
75     }
76 
77     return boost::report_errors();
78 }
79 
80