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