• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*=============================================================================
2     Copyright (c) 2005 Dan Marsden
3     Copyright (c) 2005-2007 Joel de Guzman
4     Copyright (c) 2007 Hartmut Kaiser
5     Copyright (c) 2015 John Fletcher
6 
7     Distributed under the Boost Software License, Version 1.0. (See accompanying
8     file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
9 ==============================================================================*/
10 
11 #include <boost/phoenix/core.hpp>
12 #include <boost/phoenix/stl/algorithm/querying.hpp>
13 #include <boost/detail/lightweight_test.hpp>
14 #include <boost/assign/list_of.hpp>
15 
16 #include <boost/config.hpp>
17 
18 #ifdef BOOST_PHOENIX_HAS_HASH
19 #include BOOST_PHOENIX_HASH_SET_HEADER
20 #include BOOST_PHOENIX_HASH_MAP_HEADER
21 #endif
22 #ifdef BOOST_PHOENIX_HAS_UNORDERED_SET_AND_MAP
23 #include BOOST_PHOENIX_UNORDERED_SET_HEADER
24 #include BOOST_PHOENIX_UNORDERED_MAP_HEADER
25 #endif
26 
27 #include <set>
28 #include <map>
29 #include <functional>
30 
31 namespace
32 {
33     struct even
34     {
operator ()__anonb29511f80111::even35         bool operator()(const int i) const
36         {
37             return i % 2 == 0;
38         }
39     };
40 
41     struct mod_2_comparison
42     {
operator ()__anonb29511f80111::mod_2_comparison43         bool operator()(
44             const int lhs,
45             const int rhs)
46         {
47             return lhs % 2 == rhs % 2;
48         }
49     };
50 
find_test()51     void find_test()
52     {
53         using boost::phoenix::arg_names::arg1;
54         int array[] = {1,2,3};
55         BOOST_TEST(boost::phoenix::find(arg1,2)(array) == array + 1);
56 
57         std::set<int> s(array, array + 3);
58         BOOST_TEST(boost::phoenix::find(arg1, 2)(s) == s.find(2));
59 
60         //#if !(defined(BOOST_MSVC) && (BOOST_MSVC >= 1900))
61         //std::map<int, int> m = boost::assign::map_list_of(0, 1)(2, 3)(4, 5).to_container(m);
62         std::map<int, int> m = boost::assign::map_list_of(0, 1)(2, 3)(4, 5).
63                                convert_to_container<std::map<int, int> >();
64         BOOST_TEST(boost::phoenix::find(arg1, 2)(m) == m.find(2));
65         //#endif
66 
67 #ifdef BOOST_PHOENIX_HAS_HASH
68 
69         BOOST_PHOENIX_HASH_NAMESPACE::hash_set<int> hs(array, array + 3);
70         BOOST_TEST(boost::phoenix::find(arg1, 2)(hs) == hs.find(2));
71 
72         BOOST_PHOENIX_HASH_NAMESPACE::hash_map<int, int> hm = boost::assign::map_list_of(0, 1)(2, 3)(4, 5).
73         convert_to_container<BOOST_PHOENIX_HASH_NAMESPACE::hash_map<int, int> >();
74         BOOST_TEST(boost::phoenix::find(arg1, 2)(hm) == hm.find(2));
75 
76 #endif
77 #ifdef BOOST_PHOENIX_HAS_UNORDERED_SET_AND_MAP
78 
79         std::unordered_set<int> us(array, array + 3);
80         BOOST_TEST(boost::phoenix::find(arg1, 2)(us) == us.find(2));
81 
82         std::unordered_map<int, int> um = boost::assign::map_list_of(0, 1)(2, 3)(4, 5).
83         convert_to_container<std::unordered_map<int, int> >();
84         BOOST_TEST(boost::phoenix::find(arg1, 2)(um) == um.find(2));
85 
86 #endif
87         return;
88     }
89 }
90 
main()91 int main()
92 {
93     find_test();
94     return boost::report_errors();
95 }
96 
97