]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
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 | ||
b32b8144 | 6 | // clang-format off |
7c673cae FG |
7 | #include "../helpers/prefix.hpp" |
8 | #include <boost/unordered/unordered_set_fwd.hpp> | |
9 | #include "../helpers/postfix.hpp" | |
b32b8144 | 10 | // clang-format on |
7c673cae | 11 | |
b32b8144 FG |
12 | struct true_type |
13 | { | |
14 | char x[100]; | |
15 | }; | |
16 | struct false_type | |
17 | { | |
18 | char x; | |
19 | }; | |
7c673cae FG |
20 | |
21 | false_type is_unordered_set_impl(void*); | |
22 | ||
23 | template <class Value, class Hash, class Pred, class Alloc> | |
24 | true_type is_unordered_set_impl( | |
b32b8144 | 25 | boost::unordered_set<Value, Hash, Pred, Alloc>*); |
7c673cae | 26 | |
b32b8144 FG |
27 | template <typename T> |
28 | void call_swap(boost::unordered_set<T>& x, boost::unordered_set<T>& y) | |
7c673cae | 29 | { |
b32b8144 | 30 | swap(x, y); |
7c673cae FG |
31 | } |
32 | ||
b32b8144 FG |
33 | template <typename T> |
34 | bool call_equals(boost::unordered_set<T>& x, boost::unordered_set<T>& y) | |
7c673cae | 35 | { |
b32b8144 | 36 | return x == y; |
7c673cae FG |
37 | } |
38 | ||
b32b8144 FG |
39 | template <typename T> |
40 | bool call_not_equals(boost::unordered_set<T>& x, boost::unordered_set<T>& y) | |
7c673cae | 41 | { |
b32b8144 | 42 | return x != y; |
7c673cae FG |
43 | } |
44 | ||
b32b8144 FG |
45 | template <typename T> |
46 | void call_swap(boost::unordered_multiset<T>& x, boost::unordered_multiset<T>& y) | |
7c673cae | 47 | { |
b32b8144 | 48 | swap(x, y); |
7c673cae FG |
49 | } |
50 | ||
b32b8144 FG |
51 | template <typename T> |
52 | bool call_equals( | |
53 | boost::unordered_multiset<T>& x, boost::unordered_multiset<T>& y) | |
7c673cae | 54 | { |
b32b8144 | 55 | return x == y; |
7c673cae FG |
56 | } |
57 | ||
b32b8144 FG |
58 | template <typename T> |
59 | bool call_not_equals( | |
60 | boost::unordered_multiset<T>& x, boost::unordered_multiset<T>& y) | |
7c673cae | 61 | { |
b32b8144 | 62 | return x != y; |
7c673cae FG |
63 | } |
64 | ||
65 | #include "../helpers/test.hpp" | |
66 | ||
67 | typedef boost::unordered_set<int> int_set; | |
68 | typedef boost::unordered_multiset<int> int_multiset; | |
69 | ||
b32b8144 FG |
70 | UNORDERED_AUTO_TEST (use_fwd_declared_trait_without_definition) { |
71 | BOOST_TEST(sizeof(is_unordered_set_impl((int_set*)0)) == sizeof(true_type)); | |
7c673cae FG |
72 | } |
73 | ||
74 | #include <boost/unordered_set.hpp> | |
75 | ||
b32b8144 FG |
76 | UNORDERED_AUTO_TEST (use_fwd_declared_trait) { |
77 | boost::unordered_set<int> x; | |
78 | BOOST_TEST(sizeof(is_unordered_set_impl(&x)) == sizeof(true_type)); | |
7c673cae | 79 | |
b32b8144 | 80 | BOOST_TEST(sizeof(is_unordered_set_impl((int*)0)) == sizeof(false_type)); |
7c673cae FG |
81 | } |
82 | ||
b32b8144 FG |
83 | UNORDERED_AUTO_TEST (use_set_fwd_declared_function) { |
84 | int_set x, y; | |
85 | x.insert(1); | |
86 | y.insert(2); | |
87 | call_swap(x, y); | |
7c673cae | 88 | |
b32b8144 FG |
89 | BOOST_TEST(y.find(1) != y.end()); |
90 | BOOST_TEST(y.find(2) == y.end()); | |
7c673cae | 91 | |
b32b8144 FG |
92 | BOOST_TEST(x.find(1) == x.end()); |
93 | BOOST_TEST(x.find(2) != x.end()); | |
7c673cae | 94 | |
b32b8144 FG |
95 | BOOST_TEST(!call_equals(x, y)); |
96 | BOOST_TEST(call_not_equals(x, y)); | |
7c673cae FG |
97 | } |
98 | ||
b32b8144 FG |
99 | UNORDERED_AUTO_TEST (use_multiset_fwd_declared_function) { |
100 | int_multiset x, y; | |
101 | call_swap(x, y); | |
102 | BOOST_TEST(call_equals(x, y)); | |
103 | BOOST_TEST(!call_not_equals(x, y)); | |
7c673cae FG |
104 | } |
105 | ||
106 | RUN_TESTS() |