testHashSTL.cxx 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*============================================================================
  2. KWSys - Kitware System Library
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #include "kwsysPrivate.h"
  11. #include KWSYS_HEADER(hash_map.hxx)
  12. #include KWSYS_HEADER(hash_set.hxx)
  13. // Work-around CMake dependency scanning limitation. This must
  14. // duplicate the above list of headers.
  15. #if 0
  16. # include "hash_map.hxx.in"
  17. # include "hash_set.hxx.in"
  18. #endif
  19. #include <iostream>
  20. #if defined(_MSC_VER)
  21. # pragma warning (disable:4786)
  22. #endif
  23. #if defined(__sgi) && !defined(__GNUC__)
  24. # pragma set woff 1468 /* inline function cannot be explicitly instantiated */
  25. #endif
  26. template class kwsys::hash_map<const char*, int>;
  27. template class kwsys::hash_set<int>;
  28. static bool test_hash_map()
  29. {
  30. typedef kwsys::hash_map<const char*, int> mtype;
  31. mtype m;
  32. const char* keys[] = {"hello", "world"};
  33. m[keys[0]] = 1;
  34. m.insert(mtype::value_type(keys[1], 2));
  35. int sum = 0;
  36. for(mtype::iterator mi = m.begin(); mi != m.end(); ++mi)
  37. {
  38. std::cout << "Found entry [" << mi->first << "," << mi->second << "]"
  39. << std::endl;
  40. sum += mi->second;
  41. }
  42. return sum == 3;
  43. }
  44. static bool test_hash_set()
  45. {
  46. typedef kwsys::hash_set<int> stype;
  47. stype s;
  48. s.insert(1);
  49. s.insert(2);
  50. int sum = 0;
  51. for(stype::iterator si = s.begin(); si != s.end(); ++si)
  52. {
  53. std::cout << "Found entry [" << *si << "]" << std::endl;
  54. sum += *si;
  55. }
  56. return sum == 3;
  57. }
  58. int testHashSTL(int, char*[])
  59. {
  60. bool result = true;
  61. result = test_hash_map() && result;
  62. result = test_hash_set() && result;
  63. return result? 0:1;
  64. }