testHashSTL.cxx 1.59 KB
Newer Older
1 2
/* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
   file Copyright.txt or https://cmake.org/licensing#kwsys for details.  */
Andy Cedilnik's avatar
Andy Cedilnik committed
3 4 5 6 7 8 9
#include "kwsysPrivate.h"
#include KWSYS_HEADER(hash_map.hxx)
#include KWSYS_HEADER(hash_set.hxx)

// Work-around CMake dependency scanning limitation.  This must
// duplicate the above list of headers.
#if 0
10 11
#  include "hash_map.hxx.in"
#  include "hash_set.hxx.in"
Andy Cedilnik's avatar
Andy Cedilnik committed
12 13
#endif

14 15
#include <iostream>

Andy Cedilnik's avatar
Andy Cedilnik committed
16
#if defined(_MSC_VER)
17
#  pragma warning(disable : 4786)
Andy Cedilnik's avatar
Andy Cedilnik committed
18 19 20
#endif

#if defined(__sgi) && !defined(__GNUC__)
21 22
#  pragma set woff 1468 /* inline function cannot be explicitly instantiated  \
                         */
Andy Cedilnik's avatar
Andy Cedilnik committed
23 24 25 26 27
#endif

template class kwsys::hash_map<const char*, int>;
template class kwsys::hash_set<int>;

28
static bool test_hash_map()
Andy Cedilnik's avatar
Andy Cedilnik committed
29 30 31
{
  typedef kwsys::hash_map<const char*, int> mtype;
  mtype m;
32
  const char* keys[] = { "hello", "world" };
Andy Cedilnik's avatar
Andy Cedilnik committed
33 34 35
  m[keys[0]] = 1;
  m.insert(mtype::value_type(keys[1], 2));
  int sum = 0;
36
  for (mtype::iterator mi = m.begin(); mi != m.end(); ++mi) {
37 38
    std::cout << "Found entry [" << mi->first << "," << mi->second << "]"
              << std::endl;
Andy Cedilnik's avatar
Andy Cedilnik committed
39
    sum += mi->second;
40
  }
Andy Cedilnik's avatar
Andy Cedilnik committed
41 42 43
  return sum == 3;
}

44
static bool test_hash_set()
Andy Cedilnik's avatar
Andy Cedilnik committed
45 46 47 48 49 50
{
  typedef kwsys::hash_set<int> stype;
  stype s;
  s.insert(1);
  s.insert(2);
  int sum = 0;
51
  for (stype::iterator si = s.begin(); si != s.end(); ++si) {
52
    std::cout << "Found entry [" << *si << "]" << std::endl;
Andy Cedilnik's avatar
Andy Cedilnik committed
53
    sum += *si;
54
  }
Andy Cedilnik's avatar
Andy Cedilnik committed
55 56 57
  return sum == 3;
}

58
int testHashSTL(int, char* [])
Andy Cedilnik's avatar
Andy Cedilnik committed
59 60 61 62
{
  bool result = true;
  result = test_hash_map() && result;
  result = test_hash_set() && result;
63
  return result ? 0 : 1;
Andy Cedilnik's avatar
Andy Cedilnik committed
64
}