testHashSTL.cxx 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. #endif
  19. template class kwsys::hash_map<const char*, int>;
  20. template class kwsys::hash_set<int>;
  21. static bool test_hash_map()
  22. {
  23. typedef kwsys::hash_map<const char*, int> mtype;
  24. mtype m;
  25. const char* keys[] = { "hello", "world" };
  26. m[keys[0]] = 1;
  27. m.insert(mtype::value_type(keys[1], 2));
  28. int sum = 0;
  29. for (mtype::iterator mi = m.begin(); mi != m.end(); ++mi) {
  30. std::cout << "Found entry [" << mi->first << "," << mi->second << "]"
  31. << std::endl;
  32. sum += mi->second;
  33. }
  34. return sum == 3;
  35. }
  36. static bool test_hash_set()
  37. {
  38. typedef kwsys::hash_set<int> stype;
  39. stype s;
  40. s.insert(1);
  41. s.insert(2);
  42. int sum = 0;
  43. for (stype::iterator si = s.begin(); si != s.end(); ++si) {
  44. std::cout << "Found entry [" << *si << "]" << std::endl;
  45. sum += *si;
  46. }
  47. return sum == 3;
  48. }
  49. int testHashSTL(int, char* [])
  50. {
  51. bool result = true;
  52. result = test_hash_map() && result;
  53. result = test_hash_set() && result;
  54. return result ? 0 : 1;
  55. }