testHashSTL.cxx 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing#kwsys for details. */
  3. #include "kwsysPrivate.h"
  4. #include KWSYS_HEADER(hash_map.hxx)
  5. #include KWSYS_HEADER(hash_set.hxx)
  6. // Work-around CMake dependency scanning limitation. This must
  7. // duplicate the above list of headers.
  8. #if 0
  9. # include "hash_map.hxx.in"
  10. # include "hash_set.hxx.in"
  11. #endif
  12. #include <iostream>
  13. #if defined(_MSC_VER)
  14. # pragma warning(disable : 4786)
  15. #endif
  16. #if defined(__sgi) && !defined(__GNUC__)
  17. # pragma set woff 1468 /* inline function cannot be explicitly instantiated \
  18. */
  19. #endif
  20. template class kwsys::hash_map<const char*, int>;
  21. template class kwsys::hash_set<int>;
  22. static bool test_hash_map()
  23. {
  24. using mtype = kwsys::hash_map<const char*, int>;
  25. mtype m;
  26. const char* keys[] = { "hello", "world" };
  27. m[keys[0]] = 1;
  28. m.insert(mtype::value_type(keys[1], 2));
  29. int sum = 0;
  30. for (auto& mi : m) {
  31. std::cout << "Found entry [" << mi.first << "," << mi.second << "]"
  32. << std::endl;
  33. sum += mi.second;
  34. }
  35. return sum == 3;
  36. }
  37. static bool test_hash_set()
  38. {
  39. using stype = kwsys::hash_set<int>;
  40. stype s;
  41. s.insert(1);
  42. s.insert(2);
  43. int sum = 0;
  44. for (int si : s) {
  45. std::cout << "Found entry [" << si << "]" << std::endl;
  46. sum += si;
  47. }
  48. return sum == 3;
  49. }
  50. int testHashSTL(int, char* [])
  51. {
  52. bool result = true;
  53. result = test_hash_map() && result;
  54. result = test_hash_set() && result;
  55. return result ? 0 : 1;
  56. }