From 7f59e8e0581d7424d3e856cdc28c670345fa5c18 Mon Sep 17 00:00:00 2001 From: Daniel James Date: Fri, 27 Nov 2009 19:43:06 +0000 Subject: [PATCH] Better testing of incomplete types. [SVN r57975] --- test/unordered/incomplete_test.cpp | 112 ++++++++++++++++++++++++++--- 1 file changed, 103 insertions(+), 9 deletions(-) diff --git a/test/unordered/incomplete_test.cpp b/test/unordered/incomplete_test.cpp index b1666c9e..a8bf784a 100644 --- a/test/unordered/incomplete_test.cpp +++ b/test/unordered/incomplete_test.cpp @@ -8,35 +8,129 @@ #include #include +namespace x +{ + struct D { boost::unordered_map x; }; +} + namespace test { + // Declare, but don't define some types. + struct value; struct hash; struct equals; template struct malloc_allocator; + + // Declare some instances typedef boost::unordered_map > > map; typedef boost::unordered_multimap > > multimap; typedef boost::unordered_set > set; typedef boost::unordered_multiset > multiset; - struct value {}; - struct hash { std::size_t operator()(value const&) const { return 0; } }; - struct equals { bool operator()(value const&, value const&) const { return true; } }; + // Now define the types which are stored as members, as they are needed for + // declaring struct members. + + struct hash { + template + std::size_t operator()(T const&) const { return 0; } + }; + + struct equals { + template + bool operator()(T const&, T const&) const { return true; } + }; + } #include "../helpers/allocator.hpp" -int main() { +namespace test +{ + // Declare some members of a structs. + // + // Incomplete hash, equals and allocator aren't here supported at the moment. + + struct struct1 { + boost::unordered_map > > x; + }; + struct struct2 { + boost::unordered_multimap > > x; + }; + struct struct3 { + boost::unordered_set > x; + }; + struct struct4 { + boost::unordered_multiset > x; + }; + + // Now define the value type. + + struct value {}; + + // Create some instances. + test::map m1; test::multimap m2; test::set s1; test::multiset s2; + + test::struct1 c1; + test::struct2 c2; + test::struct3 c3; + test::struct4 c4; + // Now declare, but don't define, the operators required for comparing elements. + + 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&); - test::value x; - m1[x] = x; - m2.insert(std::make_pair(x, x)); - s1.insert(x); - s2.insert(x); + 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() + { + test::value x; + 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; } + + 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. + + test::use_types(); }