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/config.hpp>
12
13 #include <boost/phoenix/core.hpp>
14 #include <boost/phoenix/stl/algorithm/querying.hpp>
15 #include <boost/detail/lightweight_test.hpp>
16 #include <boost/assign/list_of.hpp>
17
18 #include <set>
19 #include <map>
20 #include <functional>
21
22 #ifdef BOOST_PHOENIX_HAS_HASH
23 #include BOOST_PHOENIX_HASH_SET_HEADER
24 #include BOOST_PHOENIX_HASH_MAP_HEADER
25 #endif
26 #ifdef BOOST_PHOENIX_HAS_UNORDERED_SET_AND_MAP
27 #include BOOST_PHOENIX_UNORDERED_SET_HEADER
28 #include BOOST_PHOENIX_UNORDERED_MAP_HEADER
29 #endif
30
31 namespace
32 {
33 struct even
34 {
operator ()__anon2ec82dd90111::even35 bool operator()(const int i) const
36 {
37 return i % 2 == 0;
38 }
39 };
40
41 struct mod_2_comparison
42 {
operator ()__anon2ec82dd90111::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 std::map<int, int> m = boost::assign::map_list_of(0, 1)(2, 3)(4, 5).
61 convert_to_container<std::map<int, int> >();
62 BOOST_TEST(boost::phoenix::find(arg1, 2)(m) == m.find(2));
63
64 #ifdef BOOST_PHOENIX_HAS_HASH
65
66 BOOST_PHOENIX_HASH_NAMESPACE::hash_set<int> hs(array, array + 3);
67 BOOST_TEST(boost::phoenix::find(arg1, 2)(hs) == hs.find(2));
68
69 BOOST_PHOENIX_HASH_NAMESPACE::hash_map<int, int> hm = boost::assign::map_list_of(0, 1)(2, 3)(4, 5).
70 convert_to_container<BOOST_PHOENIX_HASH_NAMESPACE::hash_map<int, int> >();
71 BOOST_TEST(boost::phoenix::find(arg1, 2)(hm) == hm.find(2));
72
73 #endif
74 #ifdef BOOST_PHOENIX_HAS_UNORDERED_SET_AND_MAP
75
76 std::unordered_set<int> us(array, array + 3);
77 BOOST_TEST(boost::phoenix::find(arg1, 2)(us) == us.find(2));
78
79 int marray[] = {1,1,2,3,3};
80 std::unordered_multiset<int> ums(marray, marray + 5);
81 BOOST_TEST(boost::phoenix::find(arg1, 2)(ums) == ums.find(2));
82
83 std::unordered_map<int, int> um =
84 boost::assign::map_list_of(0, 1)(2, 3)(4, 5).
85 convert_to_container<std::unordered_map<int, int> >();
86 BOOST_TEST(boost::phoenix::find(arg1, 2)(um) == um.find(2));
87
88 std::unordered_multimap<int, int> umm =
89 boost::assign::map_list_of(0, 1)(2, 3)(4, 5)(4, 6).
90 convert_to_container<std::unordered_multimap<int, int> >();
91 BOOST_TEST(boost::phoenix::find(arg1, 2)(umm) == umm.find(2));
92
93 #endif
94 return;
95 }
96 }
97
main()98 int main()
99 {
100 find_test();
101 return boost::report_errors();
102 }
103
104