• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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>
call_swap(boost::unordered_map<T,T> & x,boost::unordered_map<T,T> & y)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>
call_equals(boost::unordered_map<T,T> & x,boost::unordered_map<T,T> & y)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>
call_not_equals(boost::unordered_map<T,T> & x,boost::unordered_map<T,T> & y)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>
call_swap(boost::unordered_multimap<T,T> & x,boost::unordered_multimap<T,T> & y)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>
call_equals(boost::unordered_multimap<T,T> & x,boost::unordered_multimap<T,T> & y)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>
call_not_equals(boost::unordered_multimap<T,T> & x,boost::unordered_multimap<T,T> & y)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 
UNORDERED_AUTO_TEST(use_map_fwd_declared_function)58 UNORDERED_AUTO_TEST (use_map_fwd_declared_function) {
59   int_map x, y;
60   x[1] = 2;
61   y[2] = 1;
62   call_swap(x, y);
63 
64   BOOST_TEST(y.find(1) != y.end() && y.find(1)->second == 2);
65   BOOST_TEST(y.find(2) == y.end());
66 
67   BOOST_TEST(x.find(1) == x.end());
68   BOOST_TEST(x.find(2) != x.end() && x.find(2)->second == 1);
69 
70   BOOST_TEST(!call_equals(x, y));
71   BOOST_TEST(call_not_equals(x, y));
72 }
73 
UNORDERED_AUTO_TEST(use_multimap_fwd_declared_function)74 UNORDERED_AUTO_TEST (use_multimap_fwd_declared_function) {
75   int_multimap x, y;
76   call_swap(x, y);
77   BOOST_TEST(call_equals(x, y));
78   BOOST_TEST(!call_not_equals(x, y));
79 }
80 
81 RUN_TESTS()
82