diff --git a/CMakeLists.txt b/CMakeLists.txt
index 71138771945c6ed087599e80d8f94a16b89bdf4e..4781b74b0e2386ba7697dd4c327ff07b91a847a3 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -182,10 +182,32 @@ SET(KWSYS_PLATFORM_CXX_TEST_DEFINES
   -DKWSYS_STL_HAVE_STD=${KWSYS_STL_HAVE_STD})
 KWSYS_PLATFORM_CXX_TEST(KWSYS_STL_STRING_HAVE_NEQ_CHAR
   "Checking whether stl string has operator!= for char*" DIRECT)
-KWSYS_PLATFORM_CXX_TEST(KWSYS_STL_HAS_ALLOCATOR_REBIND
-  "Checking for rebind member of stl allocator" DIRECT)
-KWSYS_PLATFORM_CXX_TEST(KWSYS_STL_HAS_ALLOCATOR_MAX_SIZE_ARGUMENT
-  "Checking for non-standard argument to stl allocator<>::max_size" DIRECT)
+KWSYS_PLATFORM_CXX_TEST(KWSYS_STL_HAS_ITERATOR_TRAITS
+  "Checking whether stl has iterator_traits" DIRECT)
+IF(KWSYS_STL_HAS_ITERATOR_TRAITS)
+  SET(KWSYS_STL_HAS_ITERATOR_CATEGORY 0)
+  SET(KWSYS_STL_HAS___ITERATOR_CATEGORY 0)
+ELSE(KWSYS_STL_HAS_ITERATOR_TRAITS)
+  KWSYS_PLATFORM_CXX_TEST(KWSYS_STL_HAS_ITERATOR_CATEGORY
+    "Checking whether stl has old iterator_category" DIRECT)
+  IF(KWSYS_STL_HAS_ITERATOR_CATEGORY)
+    SET(KWSYS_STL_HAS___ITERATOR_CATEGORY 0)
+  ELSE(KWSYS_STL_HAS_ITERATOR_CATEGORY)
+    KWSYS_PLATFORM_CXX_TEST(KWSYS_STL_HAS___ITERATOR_CATEGORY
+      "Checking whether stl has internal __iterator_category" DIRECT)
+  ENDIF(KWSYS_STL_HAS_ITERATOR_CATEGORY)
+ENDIF(KWSYS_STL_HAS_ITERATOR_TRAITS)
+KWSYS_PLATFORM_CXX_TEST(KWSYS_STL_HAS_ALLOCATOR_NONTEMPLATE
+  "Checking whether stl has old non-template allocator" DIRECT)
+IF(KWSYS_STL_HAS_ALLOCATOR_NONTEMPLATE)
+  SET(KWSYS_STL_HAS_ALLOCATOR_REBIND 0)
+  SET(KWSYS_STL_HAS_ALLOCATOR_MAX_SIZE_ARGUMENT 0)
+ELSE(KWSYS_STL_HAS_ALLOCATOR_NONTEMPLATE)
+  KWSYS_PLATFORM_CXX_TEST(KWSYS_STL_HAS_ALLOCATOR_REBIND
+    "Checking for rebind member of stl allocator" DIRECT)
+  KWSYS_PLATFORM_CXX_TEST(KWSYS_STL_HAS_ALLOCATOR_MAX_SIZE_ARGUMENT
+    "Checking for non-standard argument to stl allocator<>::max_size" DIRECT)
+ENDIF(KWSYS_STL_HAS_ALLOCATOR_NONTEMPLATE)
 IF(KWSYS_IOS_USE_ANSI)
   # ANSI streams always have string operators.
   SET(KWSYS_STL_STRING_HAVE_OSTREAM 1)
diff --git a/Configure.hxx.in b/Configure.hxx.in
index 785823941c5b4780875c0385854b2dba64bb1977..977297820ca702a80bbe4d9b73e3f4ba5abb5f3e 100644
--- a/Configure.hxx.in
+++ b/Configure.hxx.in
@@ -96,6 +96,18 @@
 # define @KWSYS_NAMESPACE@_CXX_DECL_TYPENAME typename
 #endif
 
+/* Whether the stl has iterator_traits.  */
+#define @KWSYS_NAMESPACE@_STL_HAS_ITERATOR_TRAITS @KWSYS_STL_HAS_ITERATOR_TRAITS@
+
+/* Whether the stl has iterator_category.  */
+#define @KWSYS_NAMESPACE@_STL_HAS_ITERATOR_CATEGORY @KWSYS_STL_HAS_ITERATOR_CATEGORY@
+
+/* Whether the stl has __iterator_category.  */
+#define @KWSYS_NAMESPACE@_STL_HAS___ITERATOR_CATEGORY @KWSYS_STL_HAS___ITERATOR_CATEGORY@
+
+/* Whether the stl allocator is not a template.  */
+#define @KWSYS_NAMESPACE@_STL_HAS_ALLOCATOR_NONTEMPLATE @KWSYS_STL_HAS_ALLOCATOR_NONTEMPLATE@
+
 /* Whether the stl allocator has rebind.  */
 #define @KWSYS_NAMESPACE@_STL_HAS_ALLOCATOR_REBIND @KWSYS_STL_HAS_ALLOCATOR_REBIND@
 
@@ -132,6 +144,10 @@
 # define KWSYS_STL_HAS_ALLOCATOR_REBIND @KWSYS_NAMESPACE@_STL_HAS_ALLOCATOR_REBIND
 # define KWSYS_STL_HAS_ALLOCATOR_MAX_SIZE_ARGUMENT @KWSYS_NAMESPACE@_STL_HAS_ALLOCATOR_MAX_SIZE_ARGUMENT
 # define KWSYS_CXX_HAS_ARGUMENT_DEPENDENT_LOOKUP @KWSYS_NAMESPACE@_CXX_HAS_ARGUMENT_DEPENDENT_LOOKUP
+# define KWSYS_STL_HAS_ITERATOR_TRAITS @KWSYS_NAMESPACE@_STL_HAS_ITERATOR_TRAITS
+# define KWSYS_STL_HAS_ITERATOR_CATEGORY @KWSYS_NAMESPACE@_STL_HAS_ITERATOR_CATEGORY
+# define KWSYS_STL_HAS___ITERATOR_CATEGORY @KWSYS_NAMESPACE@_STL_HAS___ITERATOR_CATEGORY
+# define KWSYS_STL_HAS_ALLOCATOR_NONTEMPLATE @KWSYS_NAMESPACE@_STL_HAS_ALLOCATOR_NONTEMPLATE
 #endif
 
 #endif
diff --git a/hash_map.hxx.in b/hash_map.hxx.in
index 35f0823a51f91f24019c3d55b39897f0b5588c97..5b4e12e7f32b2eab1742526b463920d682467c8d 100644
--- a/hash_map.hxx.in
+++ b/hash_map.hxx.in
@@ -71,7 +71,7 @@ struct hash_select1st:
 template <class _Key, class _Tp,
           class _HashFcn  = hash<_Key>,
           class _EqualKey = kwsys_stl::equal_to<_Key>,
-          class _Alloc =  kwsys_stl::allocator<char> >
+          class _Alloc = @KWSYS_NAMESPACE@_HASH_DEFAULT_ALLOCATOR(char) >
 class hash_map;
 
 template <class _Key, class _Tp, class _HashFn, class _EqKey, class _Alloc>
@@ -263,7 +263,7 @@ swap(hash_map<_Key,_Tp,_HashFcn,_EqlKey,_Alloc>& __hm1,
 template <class _Key, class _Tp,
           class _HashFcn  = hash<_Key>,
           class _EqualKey = kwsys_stl::equal_to<_Key>,
-          class _Alloc =  kwsys_stl::allocator<char> >
+          class _Alloc = @KWSYS_NAMESPACE@_HASH_DEFAULT_ALLOCATOR(char) >
 class hash_multimap;
 
 template <class _Key, class _Tp, class _HF, class _EqKey, class _Alloc>
diff --git a/hash_set.hxx.in b/hash_set.hxx.in
index cac50da7b7f47e2c92380472367b2861b3a628f5..85e82a3e29e075a5c56d6a6d1981050a598928df 100644
--- a/hash_set.hxx.in
+++ b/hash_set.hxx.in
@@ -69,7 +69,7 @@ struct _Identity : public kwsys_stl::unary_function<_Tp,_Tp>
 template <class _Value,
           class _HashFcn  = hash<_Value>,
           class _EqualKey = kwsys_stl::equal_to<_Value>,
-          class _Alloc =  kwsys_stl::allocator<char> >
+          class _Alloc = @KWSYS_NAMESPACE@_HASH_DEFAULT_ALLOCATOR(char) >
 class hash_set;
 
 template <class _Value, class _HashFcn, class _EqualKey, class _Alloc>
@@ -257,7 +257,7 @@ swap(hash_set<_Val,_HashFcn,_EqualKey,_Alloc>& __hs1,
 template <class _Value,
           class _HashFcn = hash<_Value>,
           class _EqualKey = kwsys_stl::equal_to<_Value>,
-          class _Alloc =  kwsys_stl::allocator<char> >
+          class _Alloc = @KWSYS_NAMESPACE@_HASH_DEFAULT_ALLOCATOR(char) >
 class hash_multiset;
 
 template <class _Val, class _HashFcn, class _EqualKey, class _Alloc>
diff --git a/hashtable.hxx.in b/hashtable.hxx.in
index e1589bac4bc95c50da842d3519c59338795164d8..19ccefb4b4cc3384154f117b9dfdd838b398d491 100644
--- a/hashtable.hxx.in
+++ b/hashtable.hxx.in
@@ -54,6 +54,12 @@
 # pragma warning (disable:4786)
 #endif
 
+#if @KWSYS_NAMESPACE@_STL_HAS_ALLOCATOR_NONTEMPLATE
+# define @KWSYS_NAMESPACE@_HASH_DEFAULT_ALLOCATOR(T) kwsys_stl::allocator
+#else
+# define @KWSYS_NAMESPACE@_HASH_DEFAULT_ALLOCATOR(T) kwsys_stl::allocator< T >
+#endif
+
 namespace @KWSYS_NAMESPACE@
 {
 
@@ -72,8 +78,13 @@ class hash_allocator: public hash_allocator_base
 private:
   // Store the real allocator privately.
   typedef Alloc alloc_type;
+#if @KWSYS_NAMESPACE@_STL_HAS_ALLOCATOR_NONTEMPLATE
+  typedef char alloc_value_type;
+  typedef void* alloc_pointer;
+#else
   typedef typename alloc_type::value_type alloc_value_type;
   typedef typename alloc_type::pointer alloc_pointer;
+#endif
   alloc_type alloc_;
 
 public:
@@ -97,11 +108,17 @@ public:
 # endif
   pointer address(reference x) const { return &x; }
   const_pointer address(const_reference x) const { return &x; }
-  pointer allocate(size_type n=1, kwsys_stl::allocator<void>::const_pointer hint = 0)
+#if @KWSYS_NAMESPACE@_STL_HAS_ALLOCATOR_NONTEMPLATE
+  typedef void* void_pointer;
+  typedef const void* const_void_pointer;
+#else
+  typedef kwsys_stl::allocator<void>::pointer void_pointer;
+  typedef kwsys_stl::allocator<void>::const_pointer const_void_pointer;
+#endif
+  pointer allocate(size_type n=1, const_void_pointer hint = 0)
     {
     if(n)
       {
-      typedef kwsys_stl::allocator<void>::pointer void_pointer;
       return
         static_cast<pointer>(
           static_cast<void*>(
@@ -116,7 +133,12 @@ public:
     {
     if(n)
       {
-      alloc_.deallocate(static_cast<alloc_pointer>(static_cast<void*>(p)), n*chunk());
+#if @KWSYS_NAMESPACE@_STL_HAS_ALLOCATOR_NONTEMPLATE
+      alloc_.deallocate(static_cast<alloc_pointer>(static_cast<void*>(p)));
+#else
+      alloc_.deallocate(static_cast<alloc_pointer>(static_cast<void*>(p)),
+                        n*chunk());
+#endif
       }
     }
 #if @KWSYS_NAMESPACE@_STL_HAS_ALLOCATOR_MAX_SIZE_ARGUMENT
@@ -151,7 +173,7 @@ struct _Hashtable_node
 
 template <class _Val, class _Key, class _HashFcn,
           class _ExtractKey, class _EqualKey,
-          class _Alloc = kwsys_stl::allocator<char> >
+          class _Alloc = @KWSYS_NAMESPACE@_HASH_DEFAULT_ALLOCATOR(char) >
 class hashtable;
 
 template <class _Val, class _Key, class _HashFcn,
@@ -459,21 +481,31 @@ public:
   kwsys_stl::pair<iterator, bool> insert_unique_noresize(const value_type& __obj);
   iterator insert_equal_noresize(const value_type& __obj);
 
-#if @KWSYS_NAMESPACE@_CXX_HAS_MEMBER_TEMPLATES
+#if @KWSYS_NAMESPACE@_STL_HAS_ITERATOR_TRAITS
+# define @KWSYS_NAMESPACE@_HASH_ITERATOR_CATEGORY(T,I) \
+  typename kwsys_stl::iterator_traits< T >::iterator_category()
+#elif @KWSYS_NAMESPACE@_STL_HAS_ITERATOR_CATEGORY
+# define @KWSYS_NAMESPACE@_HASH_ITERATOR_CATEGORY(T,I) \
+  kwsys_stl::iterator_category( I )
+#elif @KWSYS_NAMESPACE@_STL_HAS___ITERATOR_CATEGORY
+# define @KWSYS_NAMESPACE@_HASH_ITERATOR_CATEGORY(T,I) \
+  kwsys_stl::__iterator_category( I )
+#endif
+
+#if @KWSYS_NAMESPACE@_CXX_HAS_MEMBER_TEMPLATES && \
+    defined(@KWSYS_NAMESPACE@_HASH_ITERATOR_CATEGORY)
   template <class _InputIterator>
   void insert_unique(_InputIterator __f, _InputIterator __l)
   {
-    typedef typename kwsys_stl::iterator_traits<_InputIterator>::iterator_category
-      iterator_category;
-    insert_unique(__f, __l, iterator_category());
+    insert_unique(__f, __l,
+      @KWSYS_NAMESPACE@_HASH_ITERATOR_CATEGORY(_InputIterator, __f));
   }
 
   template <class _InputIterator>
   void insert_equal(_InputIterator __f, _InputIterator __l)
   {
-    typedef typename kwsys_stl::iterator_traits<_InputIterator>::iterator_category
-      iterator_category;
-    insert_equal(__f, __l, iterator_category());
+    insert_equal(__f, __l,
+      @KWSYS_NAMESPACE@_HASH_ITERATOR_CATEGORY(_InputIterator, __f));
   }
 
   template <class _InputIterator>
diff --git a/kwsysPlatformCxxTests.cxx b/kwsysPlatformCxxTests.cxx
index 9edbfc0ab5767e8144c61f250dafce31502ef00c..a8b3d6f446c8c7651100522a962b4fc8aa1b6cd4 100644
--- a/kwsysPlatformCxxTests.cxx
+++ b/kwsysPlatformCxxTests.cxx
@@ -122,6 +122,30 @@ int main()
 }
 #endif
 
+#ifdef TEST_KWSYS_STL_HAS_ITERATOR_TRAITS
+#include <iterator>
+void f(kwsys_stl::iterator_traits<int*>::iterator_category const&) {}
+int main() { return 0; }
+#endif
+
+#ifdef TEST_KWSYS_STL_HAS_ITERATOR_CATEGORY
+#include <iterator>
+void f(int* x) { kwsys_stl::iterator_category(x); }
+int main() { return 0; }
+#endif
+
+#ifdef TEST_KWSYS_STL_HAS___ITERATOR_CATEGORY
+#include <iterator>
+void f(int* x) { kwsys_stl::__iterator_category(x); }
+int main() { return 0; }
+#endif
+
+#ifdef TEST_KWSYS_STL_HAS_ALLOCATOR_NONTEMPLATE
+#include <memory>
+void f(kwsys_stl::allocator const&) {}
+int main() { return 0; }
+#endif
+
 #ifdef TEST_KWSYS_STL_HAS_ALLOCATOR_REBIND
 #include <memory>
 template <class T, class Alloc>