changeset 13727:478efc95cb7a

Test unordered_map header location and namespace. * configure.ac: Add tests for <unordered_map> and <tr1/unordered_map>. Add test to determine whether std::tr1 namespace is required for unordered_map. * rand.cc: Use tests result.
author Michael Goffioul <michael.goffioul@gmail.com>
date Thu, 20 Oct 2011 12:51:31 +0100
parents 5a2734f26dbc
children 47f803279384
files configure.ac src/DLD-FUNCTIONS/rand.cc
diffstat 2 files changed, 31 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/configure.ac	Wed Oct 19 17:15:42 2011 +0100
+++ b/configure.ac	Thu Oct 20 12:51:31 2011 +0100
@@ -1548,6 +1548,26 @@
 
 AC_LANG_PUSH(C++)
 AC_CHECK_HEADERS(sstream)
+AC_CHECK_HEADERS([unordered_map], [], [
+  AC_CHECK_HEADERS([tr1/unordered_map])])
+AC_MSG_CHECKING([whether unordered_map requires tr1 namespace])
+unordered_map_requires_tr1_namespace=no
+if test "$ac_cv_header_unordered_map" = "yes"; then
+  ### Have <unordered_map>, but still have to check whether
+  ### tr1 namespace is required (like MSVC, for instance).
+  AC_COMPILE_IFELSE([
+    AC_LANG_PROGRAM([
+      #include <unordered_map>
+    ], [
+      std::unordered_map m;
+    ])], [], [unordered_map_requires_tr1_namespace=yes])
+elif test "$ac_cv_header_tr1_unordered_map" = "yes"; then
+  unordered_map_requires_tr1_namespace=yes
+fi
+if test "$unordered_map_requires_tr1_namespace" = "yes"; then
+  AC_DEFINE(USE_UNORDERED_MAP_WITH_TR1, 1, [Defines whether unordered_map requires the use of tr1 namespace.])
+fi
+AC_MSG_RESULT([$unordered_map_requires_tr1_namespace])
 AC_LANG_POP(C++)
 
 have_termios_h=no
--- a/src/DLD-FUNCTIONS/rand.cc	Wed Oct 19 17:15:42 2011 +0100
+++ b/src/DLD-FUNCTIONS/rand.cc	Thu Oct 20 12:51:31 2011 +0100
@@ -26,7 +26,11 @@
 #endif
 
 #include <ctime>
+#if defined (HAVE_UNORDERED_MAP)
+#include <unordered_map>
+#elif defined (HAVE_TR1_UNORDERED_MAP)
 #include <tr1/unordered_map>
+#endif
 #include <string>
 
 #include "f77-fcn.h"
@@ -42,6 +46,12 @@
 #include "utils.h"
 #include "ov-re-mat.h"
 
+#ifdef USE_UNORDERED_MAP_WITH_TR1
+using namespace std::tr1;
+#else
+using namespace std;
+#endif
+
 /*
 %!shared __random_statistical_tests__
 %! % Flag whether the statistical tests should be run in "make check" or not
@@ -1066,8 +1076,7 @@
 
           if (short_shuffle)
             {
-              std::tr1::unordered_map<octave_idx_type,
-                                      octave_idx_type> map (m);
+              unordered_map<octave_idx_type, octave_idx_type> map (m);
 
               // Perform the Knuth shuffle only keeping track of moved
               // entries in the map