/Src/Dependencies/Boost/libs/unordered/test/unordered/incomplete_test.cpp

http://hadesmem.googlecode.com/ · C++ · 147 lines · 95 code · 33 blank · 19 comment · 0 complexity · 7dc6635a4fd0f57f9c848f91aef9742c MD5 · raw file

  1. // Copyright 2009 Daniel James.
  2. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  3. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  4. #include "../helpers/prefix.hpp"
  5. #include <boost/unordered_map.hpp>
  6. #include <boost/unordered_set.hpp>
  7. namespace x
  8. {
  9. struct D { boost::unordered_map<D, D> x; };
  10. }
  11. namespace test
  12. {
  13. // Declare, but don't define some types.
  14. struct value;
  15. struct hash;
  16. struct equals;
  17. template <class T>
  18. struct malloc_allocator;
  19. // Declare some instances
  20. typedef boost::unordered_map<value, value, hash, equals,
  21. malloc_allocator<std::pair<value const, value> > > map;
  22. typedef boost::unordered_multimap<value, value, hash, equals,
  23. malloc_allocator<std::pair<value const, value> > > multimap;
  24. typedef boost::unordered_set<value, hash, equals,
  25. malloc_allocator<value> > set;
  26. typedef boost::unordered_multiset<value, hash, equals,
  27. malloc_allocator<value> > multiset;
  28. // Now define the types which are stored as members, as they are needed for
  29. // declaring struct members.
  30. struct hash {
  31. template <typename T>
  32. std::size_t operator()(T const&) const { return 0; }
  33. };
  34. struct equals {
  35. template <typename T>
  36. bool operator()(T const&, T const&) const { return true; }
  37. };
  38. }
  39. #include "../helpers/allocator.hpp"
  40. namespace test
  41. {
  42. // Declare some members of a structs.
  43. //
  44. // Incomplete hash, equals and allocator aren't here supported at the
  45. // moment.
  46. struct struct1 {
  47. boost::unordered_map<struct1, struct1, hash, equals,
  48. malloc_allocator<std::pair<struct1 const, struct1> > > x;
  49. };
  50. struct struct2 {
  51. boost::unordered_multimap<struct2, struct2, hash, equals,
  52. malloc_allocator<std::pair<struct2 const, struct2> > > x;
  53. };
  54. struct struct3 {
  55. boost::unordered_set<struct3, hash, equals,
  56. malloc_allocator<struct3> > x;
  57. };
  58. struct struct4 {
  59. boost::unordered_multiset<struct4, hash, equals,
  60. malloc_allocator<struct4> > x;
  61. };
  62. // Now define the value type.
  63. struct value {};
  64. // Create some instances.
  65. test::map m1;
  66. test::multimap m2;
  67. test::set s1;
  68. test::multiset s2;
  69. test::struct1 c1;
  70. test::struct2 c2;
  71. test::struct3 c3;
  72. test::struct4 c4;
  73. // Now declare, but don't define, the operators required for comparing
  74. // elements.
  75. std::size_t hash_value(value const&);
  76. bool operator==(value const&, value const&);
  77. std::size_t hash_value(struct1 const&);
  78. std::size_t hash_value(struct2 const&);
  79. std::size_t hash_value(struct3 const&);
  80. std::size_t hash_value(struct4 const&);
  81. bool operator==(struct1 const&, struct1 const&);
  82. bool operator==(struct2 const&, struct2 const&);
  83. bool operator==(struct3 const&, struct3 const&);
  84. bool operator==(struct4 const&, struct4 const&);
  85. // And finally use these
  86. void use_types()
  87. {
  88. test::value x;
  89. m1[x] = x;
  90. m2.insert(std::make_pair(x, x));
  91. s1.insert(x);
  92. s2.insert(x);
  93. c1.x.insert(std::make_pair(c1, c1));
  94. c2.x.insert(std::make_pair(c2, c2));
  95. c3.x.insert(c3);
  96. c4.x.insert(c4);
  97. }
  98. // And finally define the operators required for comparing elements.
  99. std::size_t hash_value(value const&) { return 0; }
  100. bool operator==(value const&, value const&) { return true; }
  101. std::size_t hash_value(struct1 const&) { return 0; }
  102. std::size_t hash_value(struct2 const&) { return 0; }
  103. std::size_t hash_value(struct3 const&) { return 0; }
  104. std::size_t hash_value(struct4 const&) { return 0; }
  105. bool operator==(struct1 const&, struct1 const&) { return true; }
  106. bool operator==(struct2 const&, struct2 const&) { return true; }
  107. bool operator==(struct3 const&, struct3 const&) { return true; }
  108. bool operator==(struct4 const&, struct4 const&) { return true; }
  109. }
  110. int main() {
  111. // This could just be a compile test, but I like to be able to run these
  112. // things. It's probably irrational, but I find it reassuring.
  113. test::use_types();
  114. }