changeset 659:1dfa777590ac

Add autoconf checks for unordered_map
author jordigh
date Tue, 23 Oct 2012 18:42:12 +0000
parents 24d88d1a329d
children afef2b0ed913
files src/autogen.sh src/bwlabeln.cc src/config.h.in src/configure.ac src/undef_unordered_map.h
diffstat 5 files changed, 90 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
new file mode 100755
--- /dev/null
+++ b/src/autogen.sh
@@ -0,0 +1,5 @@
+#!/bin/bash
+
+set -e
+
+autoconf
\ No newline at end of file
--- a/src/bwlabeln.cc
+++ b/src/bwlabeln.cc
@@ -16,10 +16,21 @@
 
 // bwlabeln.cc ---
 
+
 #include <oct.h>
 #include <set>
 #include "union-find.h++"
+
+#include "config.h"
+
+#if defined (HAVE_UNORDERED_MAP)
 #include <unordered_map>
+#elif defined (HAVE_TR1_UNORDERED_MAP)
+#include <tr1/unordered_map>
+#else
+#error Must have the TR1 or C++11 unordered_map header
+#endif
+
 
 typedef Array<octave_idx_type> coord;
 
@@ -392,8 +403,13 @@
         }
     }
 
+#ifdef USE_UNORDERED_MAP_WITH_TR1
+  using std::tr1::unordered_map;
+#else
+  using std::unordered_map;
+#endif
 
-  std::unordered_map<octave_idx_type, octave_idx_type> ids_to_label;
+  unordered_map<octave_idx_type, octave_idx_type> ids_to_label;
   octave_idx_type next_label = 1;
 
   auto idxs  = u_f.get_ids ();
new file mode 100644
--- /dev/null
+++ b/src/config.h.in
@@ -0,0 +1,13 @@
+/* config.h.in. Generated by hand.  */
+
+/* Need to undef some Octave things */
+#include "undef_unordered_map.h"
+
+/* Define to 1 if you have the <tr1/unordered_map> header file. */
+#undef HAVE_TR1_UNORDERED_MAP
+
+/* Define to 1 if you have the <unordered_map> header file. */
+#undef HAVE_UNORDERED_MAP
+
+/* Define to 1 if unordered_map requires the use of tr1 namespace. */
+#undef USE_UNORDERED_MAP_WITH_TR1
new file mode 100644
--- /dev/null
+++ b/src/configure.ac
@@ -0,0 +1,51 @@
+AC_PREREQ([2.67])
+AC_INIT
+AH_BOTTOM([#include "undef_unordered_map.h"])
+
+AC_CONFIG_HEADERS(config.h)
+
+
+
+CXXFLAGS="-std=c++0x"
+CPPFLAGS="-std=c++0x"
+
+AC_PROG_CXX
+AC_LANG(C++)
+
+dnl
+dnl Check for unordered map headers and whether tr1 namespace is
+dnl required. This is copied from m4/acinclude.m4 from core Octave
+dnl
+AC_DEFUN([OCTAVE_UNORDERED_MAP_HEADERS], [
+  AC_CHECK_HEADERS([unordered_map], [],
+    [AC_CHECK_HEADERS([tr1/unordered_map])])
+  AC_CACHE_CHECK([whether unordered_map requires tr1 namespace], 
+    [octave_cv_header_require_tr1_namespace],
+    [AC_LANG_PUSH(C++)
+    octave_cv_header_require_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<int,int> m;
+        ]])],
+        octave_cv_header_require_tr1_namespace=no, 
+        octave_cv_header_require_tr1_namespace=yes)
+    elif test $ac_cv_header_tr1_unordered_map = yes; then
+      octave_cv_header_require_tr1_namespace=yes
+    fi
+    AC_LANG_POP(C++)
+  ])
+  if test $octave_cv_header_require_tr1_namespace = yes; then
+    AC_DEFINE(USE_UNORDERED_MAP_WITH_TR1, 1, 
+      [Define to 1 if unordered_map requires the use of tr1 namespace.])
+  fi
+])
+
+OCTAVE_UNORDERED_MAP_HEADERS
+
+
+AC_OUTPUT
new file mode 100644
--- /dev/null
+++ b/src/undef_unordered_map.h
@@ -0,0 +1,4 @@
+/* Octave ships its own config.h and these macros conflict with us*/
+#undef HAVE_TR1_UNORDERED_MAP
+#undef HAVE_UNORDERED_MAP
+#undef USE_UNORDERED_MAP_WITH_TR1