]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/unordered/test/unordered/incomplete_test.cpp
2 // Copyright 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)
7 #include "../helpers/prefix.hpp"
8 #include <boost/unordered_map.hpp>
9 #include <boost/unordered_set.hpp>
10 #include "../helpers/postfix.hpp"
18 boost::unordered_map
<D
, D
> x
;
22 namespace incomplete_test
{
23 // Declare, but don't define some types.
28 template <class T
> struct allocator
;
30 // Declare some instances
32 typedef boost::unordered_map
<value
, value
, hash
, equals
,
33 allocator
<std::pair
<value
const, value
> > >
35 typedef boost::unordered_multimap
<value
, value
, hash
, equals
,
36 allocator
<std::pair
<value
const, value
> > >
38 typedef boost::unordered_set
<value
, hash
, equals
, allocator
<value
> > set
;
39 typedef boost::unordered_multiset
<value
, hash
, equals
, allocator
<value
> >
42 // Now define the types which are stored as members, as they are needed for
43 // declaring struct members.
47 template <typename T
> std::size_t operator()(T
const&) const { return 0; }
52 template <typename T
> bool operator()(T
const&, T
const&) const
58 // This is a dubious way to implement an allocator, but good enough
60 template <typename T
> struct allocator
: std::allocator
<T
>
64 template <typename T2
>
65 allocator(const allocator
<T2
>& other
) : std::allocator
<T
>(other
)
69 template <typename T2
>
70 allocator(const std::allocator
<T2
>& other
) : std::allocator
<T
>(other
)
75 // Declare some members of a structs.
77 // Incomplete hash, equals and allocator aren't here supported at the
82 boost::unordered_map
<struct1
, struct1
, hash
, equals
,
83 allocator
<std::pair
<struct1
const, struct1
> > >
88 boost::unordered_multimap
<struct2
, struct2
, hash
, equals
,
89 allocator
<std::pair
<struct2
const, struct2
> > >
94 boost::unordered_set
<struct3
, hash
, equals
, allocator
<struct3
> > x
;
98 boost::unordered_multiset
<struct4
, hash
, equals
, allocator
<struct4
> > x
;
101 // Now define the value type.
107 // Create some instances.
109 incomplete_test::map m1
;
110 incomplete_test::multimap m2
;
111 incomplete_test::set s1
;
112 incomplete_test::multiset s2
;
114 incomplete_test::struct1 c1
;
115 incomplete_test::struct2 c2
;
116 incomplete_test::struct3 c3
;
117 incomplete_test::struct4 c4
;
119 // Now declare, but don't define, the operators required for comparing
122 std::size_t hash_value(value
const&);
123 bool operator==(value
const&, value
const&);
125 std::size_t hash_value(struct1
const&);
126 std::size_t hash_value(struct2
const&);
127 std::size_t hash_value(struct3
const&);
128 std::size_t hash_value(struct4
const&);
130 bool operator==(struct1
const&, struct1
const&);
131 bool operator==(struct2
const&, struct2
const&);
132 bool operator==(struct3
const&, struct3
const&);
133 bool operator==(struct4
const&, struct4
const&);
135 // And finally use these
139 incomplete_test::value x
;
141 m2
.insert(std::make_pair(x
, x
));
145 c1
.x
.insert(std::make_pair(c1
, c1
));
146 c2
.x
.insert(std::make_pair(c2
, c2
));
151 // And finally define the operators required for comparing elements.
153 std::size_t hash_value(value
const&) { return 0; }
154 bool operator==(value
const&, value
const&) { return true; }
156 std::size_t hash_value(struct1
const&) { return 0; }
157 std::size_t hash_value(struct2
const&) { return 0; }
158 std::size_t hash_value(struct3
const&) { return 0; }
159 std::size_t hash_value(struct4
const&) { return 0; }
161 bool operator==(struct1
const&, struct1
const&) { return true; }
162 bool operator==(struct2
const&, struct2
const&) { return true; }
163 bool operator==(struct3
const&, struct3
const&) { return true; }
164 bool operator==(struct4
const&, struct4
const&) { return true; }
169 // This could just be a compile test, but I like to be able to run these
170 // things. It's probably irrational, but I find it reassuring.
172 incomplete_test::use_types();