Imported Upstream version 1.64.0
[platform/upstream/boost.git] / libs / unordered / test / unordered / fwd_map_test.cpp
1
2 // Copyright 2008-2009 Daniel James.
3 // Distributed under the Boost Software License, Version 1.0. (See accompanying
4 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5
6 // clang-format off
7 #include "../helpers/prefix.hpp"
8 #include <boost/unordered/unordered_map_fwd.hpp>
9 #include "../helpers/postfix.hpp"
10 // clang-format on
11
12 template <typename T>
13 void call_swap(boost::unordered_map<T, T>& x, boost::unordered_map<T, T>& y)
14 {
15     swap(x, y);
16 }
17
18 template <typename T>
19 bool call_equals(boost::unordered_map<T, T>& x, boost::unordered_map<T, T>& y)
20 {
21     return x == y;
22 }
23
24 template <typename T>
25 bool call_not_equals(
26     boost::unordered_map<T, T>& x, boost::unordered_map<T, T>& y)
27 {
28     return x != y;
29 }
30
31 template <typename T>
32 void call_swap(
33     boost::unordered_multimap<T, T>& x, boost::unordered_multimap<T, T>& y)
34 {
35     swap(x, y);
36 }
37
38 template <typename T>
39 bool call_equals(
40     boost::unordered_multimap<T, T>& x, boost::unordered_multimap<T, T>& y)
41 {
42     return x == y;
43 }
44
45 template <typename T>
46 bool call_not_equals(
47     boost::unordered_multimap<T, T>& x, boost::unordered_multimap<T, T>& y)
48 {
49     return x != y;
50 }
51
52 #include <boost/unordered_map.hpp>
53 #include "../helpers/test.hpp"
54
55 typedef boost::unordered_map<int, int> int_map;
56 typedef boost::unordered_multimap<int, int> int_multimap;
57
58 UNORDERED_AUTO_TEST(use_map_fwd_declared_function)
59 {
60     int_map x, y;
61     x[1] = 2;
62     y[2] = 1;
63     call_swap(x, y);
64
65     BOOST_TEST(y.find(1) != y.end() && y.find(1)->second == 2);
66     BOOST_TEST(y.find(2) == y.end());
67
68     BOOST_TEST(x.find(1) == x.end());
69     BOOST_TEST(x.find(2) != x.end() && x.find(2)->second == 1);
70
71     BOOST_TEST(!call_equals(x, y));
72     BOOST_TEST(call_not_equals(x, y));
73 }
74
75 UNORDERED_AUTO_TEST(use_multimap_fwd_declared_function)
76 {
77     int_multimap x, y;
78     call_swap(x, y);
79     BOOST_TEST(call_equals(x, y));
80     BOOST_TEST(!call_not_equals(x, y));
81 }
82
83 RUN_TESTS()