| 
									
										
										
										
											2009-11-20 08:03:26 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | // Copyright 2009 Daniel James.
 | 
					
						
							|  |  |  | // Distributed under the Boost Software License, Version 1.0. (See accompanying
 | 
					
						
							|  |  |  | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-26 23:15:30 +00:00
										 |  |  | #include "../helpers/prefix.hpp"
 | 
					
						
							| 
									
										
										
										
											2009-11-20 08:03:26 +00:00
										 |  |  | #include <boost/unordered_map.hpp>
 | 
					
						
							|  |  |  | #include <boost/unordered_set.hpp>
 | 
					
						
							| 
									
										
										
										
											2012-04-08 15:29:15 +00:00
										 |  |  | #include "../helpers/postfix.hpp"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <utility>
 | 
					
						
							| 
									
										
										
										
											2009-11-20 08:03:26 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-27 19:43:06 +00:00
										 |  |  | namespace x | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     struct D { boost::unordered_map<D, D> x; }; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-07-08 11:53:39 +00:00
										 |  |  | namespace incomplete_test | 
					
						
							| 
									
										
										
										
											2009-11-20 08:03:26 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-11-27 19:43:06 +00:00
										 |  |  |     // Declare, but don't define some types.
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-20 08:03:26 +00:00
										 |  |  |     struct value; | 
					
						
							|  |  |  |     struct hash; | 
					
						
							|  |  |  |     struct equals; | 
					
						
							| 
									
										
										
										
											2012-07-08 11:53:39 +00:00
										 |  |  |     template <class T> struct allocator; | 
					
						
							| 
									
										
										
										
											2009-11-27 19:43:06 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     // Declare some instances
 | 
					
						
							| 
									
										
										
										
											2009-11-20 08:03:26 +00:00
										 |  |  |      | 
					
						
							| 
									
										
										
										
											2010-01-04 22:49:39 +00:00
										 |  |  |     typedef boost::unordered_map<value, value, hash, equals, | 
					
						
							| 
									
										
										
										
											2012-07-08 11:53:39 +00:00
										 |  |  |         allocator<std::pair<value const, value> > > map; | 
					
						
							| 
									
										
										
										
											2010-01-04 22:49:39 +00:00
										 |  |  |     typedef boost::unordered_multimap<value, value, hash, equals, | 
					
						
							| 
									
										
										
										
											2012-07-08 11:53:39 +00:00
										 |  |  |         allocator<std::pair<value const, value> > > multimap; | 
					
						
							| 
									
										
										
										
											2010-01-04 22:49:39 +00:00
										 |  |  |     typedef boost::unordered_set<value, hash, equals, | 
					
						
							| 
									
										
										
										
											2012-07-08 11:53:39 +00:00
										 |  |  |         allocator<value> > set; | 
					
						
							| 
									
										
										
										
											2010-01-04 22:49:39 +00:00
										 |  |  |     typedef boost::unordered_multiset<value, hash, equals, | 
					
						
							| 
									
										
										
										
											2012-07-08 11:53:39 +00:00
										 |  |  |         allocator<value> > multiset; | 
					
						
							| 
									
										
										
										
											2009-11-20 08:03:26 +00:00
										 |  |  |      | 
					
						
							| 
									
										
										
										
											2009-11-27 19:43:06 +00:00
										 |  |  |     // Now define the types which are stored as members, as they are needed for
 | 
					
						
							|  |  |  |     // declaring struct members.
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     struct hash {  | 
					
						
							|  |  |  |         template <typename T> | 
					
						
							|  |  |  |         std::size_t operator()(T const&) const { return 0; } | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     struct equals { | 
					
						
							|  |  |  |         template <typename T> | 
					
						
							|  |  |  |         bool operator()(T const&, T const&) const { return true; } | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-07-08 11:53:39 +00:00
										 |  |  |     // This is a dubious way to implement an allocator, but good enough
 | 
					
						
							|  |  |  |     // for this test.
 | 
					
						
							|  |  |  |     template <typename T> | 
					
						
							|  |  |  |     struct allocator : std::allocator<T> { | 
					
						
							|  |  |  |         allocator() {} | 
					
						
							| 
									
										
										
										
											2009-11-20 08:03:26 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-07-08 11:53:39 +00:00
										 |  |  |         template <typename T2> | 
					
						
							|  |  |  |         allocator(const allocator<T2>& other) : | 
					
						
							|  |  |  |             std::allocator<T>(other) {} | 
					
						
							|  |  |  |     }; | 
					
						
							| 
									
										
										
										
											2009-11-20 08:03:26 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-27 19:43:06 +00:00
										 |  |  |     // Declare some members of a structs.
 | 
					
						
							|  |  |  |     //
 | 
					
						
							| 
									
										
										
										
											2010-01-04 22:49:39 +00:00
										 |  |  |     // Incomplete hash, equals and allocator aren't here supported at the
 | 
					
						
							|  |  |  |     // moment.
 | 
					
						
							| 
									
										
										
										
											2009-11-27 19:43:06 +00:00
										 |  |  |      | 
					
						
							|  |  |  |     struct struct1 { | 
					
						
							| 
									
										
										
										
											2010-01-04 22:49:39 +00:00
										 |  |  |         boost::unordered_map<struct1, struct1, hash, equals, | 
					
						
							| 
									
										
										
										
											2012-07-08 11:53:39 +00:00
										 |  |  |             allocator<std::pair<struct1 const, struct1> > > x; | 
					
						
							| 
									
										
										
										
											2009-11-27 19:43:06 +00:00
										 |  |  |     }; | 
					
						
							|  |  |  |     struct struct2 { | 
					
						
							| 
									
										
										
										
											2010-01-04 22:49:39 +00:00
										 |  |  |         boost::unordered_multimap<struct2, struct2, hash, equals, | 
					
						
							| 
									
										
										
										
											2012-07-08 11:53:39 +00:00
										 |  |  |             allocator<std::pair<struct2 const, struct2> > > x; | 
					
						
							| 
									
										
										
										
											2009-11-27 19:43:06 +00:00
										 |  |  |     }; | 
					
						
							|  |  |  |     struct struct3 { | 
					
						
							| 
									
										
										
										
											2010-01-04 22:49:39 +00:00
										 |  |  |         boost::unordered_set<struct3, hash, equals, | 
					
						
							| 
									
										
										
										
											2012-07-08 11:53:39 +00:00
										 |  |  |             allocator<struct3> > x; | 
					
						
							| 
									
										
										
										
											2009-11-27 19:43:06 +00:00
										 |  |  |     }; | 
					
						
							|  |  |  |     struct struct4 { | 
					
						
							| 
									
										
										
										
											2010-01-04 22:49:39 +00:00
										 |  |  |         boost::unordered_multiset<struct4, hash, equals, | 
					
						
							| 
									
										
										
										
											2012-07-08 11:53:39 +00:00
										 |  |  |             allocator<struct4> > x; | 
					
						
							| 
									
										
										
										
											2009-11-27 19:43:06 +00:00
										 |  |  |     }; | 
					
						
							|  |  |  |      | 
					
						
							|  |  |  |     // Now define the value type.
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     struct value {}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // Create some instances.
 | 
					
						
							|  |  |  |      | 
					
						
							| 
									
										
										
										
											2012-07-08 11:53:39 +00:00
										 |  |  |     incomplete_test::map m1; | 
					
						
							|  |  |  |     incomplete_test::multimap m2; | 
					
						
							|  |  |  |     incomplete_test::set s1; | 
					
						
							|  |  |  |     incomplete_test::multiset s2; | 
					
						
							| 
									
										
										
										
											2009-11-27 19:43:06 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-07-08 11:53:39 +00:00
										 |  |  |     incomplete_test::struct1 c1; | 
					
						
							|  |  |  |     incomplete_test::struct2 c2; | 
					
						
							|  |  |  |     incomplete_test::struct3 c3; | 
					
						
							|  |  |  |     incomplete_test::struct4 c4; | 
					
						
							| 
									
										
										
										
											2010-01-04 22:49:39 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     // Now declare, but don't define, the operators required for comparing
 | 
					
						
							|  |  |  |     // elements.
 | 
					
						
							| 
									
										
										
										
											2009-11-27 19:43:06 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     std::size_t hash_value(value const&); | 
					
						
							|  |  |  |     bool operator==(value const&, value const&); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     std::size_t hash_value(struct1 const&); | 
					
						
							|  |  |  |     std::size_t hash_value(struct2 const&); | 
					
						
							|  |  |  |     std::size_t hash_value(struct3 const&); | 
					
						
							|  |  |  |     std::size_t hash_value(struct4 const&); | 
					
						
							|  |  |  |      | 
					
						
							|  |  |  |     bool operator==(struct1 const&, struct1 const&); | 
					
						
							|  |  |  |     bool operator==(struct2 const&, struct2 const&); | 
					
						
							|  |  |  |     bool operator==(struct3 const&, struct3 const&); | 
					
						
							|  |  |  |     bool operator==(struct4 const&, struct4 const&); | 
					
						
							|  |  |  |      | 
					
						
							|  |  |  |     // And finally use these
 | 
					
						
							|  |  |  |      | 
					
						
							|  |  |  |     void use_types() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2012-07-08 11:53:39 +00:00
										 |  |  |         incomplete_test::value x; | 
					
						
							| 
									
										
										
										
											2009-11-27 19:43:06 +00:00
										 |  |  |         m1[x] = x; | 
					
						
							|  |  |  |         m2.insert(std::make_pair(x, x)); | 
					
						
							|  |  |  |         s1.insert(x); | 
					
						
							|  |  |  |         s2.insert(x); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         c1.x.insert(std::make_pair(c1, c1)); | 
					
						
							|  |  |  |         c2.x.insert(std::make_pair(c2, c2)); | 
					
						
							|  |  |  |         c3.x.insert(c3); | 
					
						
							|  |  |  |         c4.x.insert(c4); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // And finally define the operators required for comparing elements.
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     std::size_t hash_value(value const&) { return 0; } | 
					
						
							|  |  |  |     bool operator==(value const&, value const&) { return true; } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     std::size_t hash_value(struct1 const&) { return 0; } | 
					
						
							|  |  |  |     std::size_t hash_value(struct2 const&) { return 0; } | 
					
						
							|  |  |  |     std::size_t hash_value(struct3 const&) { return 0; } | 
					
						
							|  |  |  |     std::size_t hash_value(struct4 const&) { return 0; } | 
					
						
							| 
									
										
										
										
											2009-11-20 08:03:26 +00:00
										 |  |  |      | 
					
						
							| 
									
										
										
										
											2009-11-27 19:43:06 +00:00
										 |  |  |     bool operator==(struct1 const&, struct1 const&) { return true; } | 
					
						
							|  |  |  |     bool operator==(struct2 const&, struct2 const&) { return true; } | 
					
						
							|  |  |  |     bool operator==(struct3 const&, struct3 const&) { return true; } | 
					
						
							|  |  |  |     bool operator==(struct4 const&, struct4 const&) { return true; } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int main() { | 
					
						
							|  |  |  |     // This could just be a compile test, but I like to be able to run these
 | 
					
						
							|  |  |  |     // things. It's probably irrational, but I find it reassuring.
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-07-08 11:53:39 +00:00
										 |  |  |     incomplete_test::use_types(); | 
					
						
							| 
									
										
										
										
											2009-11-21 19:40:28 +00:00
										 |  |  | } |