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