Commits

jeremy_barnes  committed e26f083

make jml useable with c++0x mode on

  • Participants
  • Parent commits 279d67f

Comments (0)

Files changed (3)

File src/compiler/compiler.h

 #define JML_LIKELY(x) __builtin_expect((x), true)
 #define JML_UNLIKELY(x) __builtin_expect((x), false)
 
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+#  define jml_typeof(x) decltype(x)
+#else
+#  define jml_typeof(x) typeof(x)
+#endif
 
 #ifdef JML_COMPILER_NVCC
 # define JML_COMPUTE_METHOD __device__ __host__

File src/utils/float_traits.h

 #ifndef __utils__float_traits_h__
 #define __utils__float_traits_h__
 
+#include "jml/compiler/compiler.h"
+
 namespace ML {
 
 template<typename F1, typename F2>
 struct float_traits {
-    typedef typeof(F1() + F2()) return_type;
-    typedef typeof(F1() / F2(1)) fraction_type;
+    typedef jml_typeof(F1() + F2()) return_type;
+    typedef jml_typeof(F1() / F2(1)) fraction_type;
 };
 
 template <typename F>
 struct float_traits<F, F> {
     typedef F return_type;
-    typedef typeof(F() / F(1)) fraction_type;
+    typedef jml_typeof(F() / F(1)) fraction_type;
 };
 
 template<typename F1, typename F2, typename F3>
 struct float_traits3 {
-    typedef typeof(*((F1*)(0)) + (*((F2*)(0))) + (*((F3*)(0)))) return_type;
+    typedef jml_typeof(*((F1*)(0)) + (*((F2*)(0))) + (*((F3*)(0)))) return_type;
 };
 
 template <typename F>

File src/utils/hash_specializations.h

 #include <string>
 #include "jml/utils/floating_point.h"
 
+#define JML_HASH_NS __gnu_cxx
 
-#define JML_HASH_NS __gnu_cxx
+
+#ifndef __GXX_EXPERIMENTAL_CXX0X__
 
 namespace std {
 
 
 } // namespace std
 
-namespace JML_HASH_NS {
+#endif
+
+namespace __gnu_cxx {
 
 template<>
 struct hash<std::string> {
 struct hash<float> : public ML::float_hasher {
 };
 
+inline size_t chain_hash(size_t h1, size_t h2 = 0)
+{
+    return 18446744073709551557ULL * h1 + h2;
+}
+
 template<typename T>
 struct hash<T *> {
     size_t operator () (const T * ptr) const
     {
-        return 18446744073709551557ULL * reinterpret_cast<size_t>(ptr);
+        return chain_hash(reinterpret_cast<size_t>(ptr));
     }
-
 };
 
-} // namespace HASH_NS
+template<typename X, typename Y>
+struct hash<std::pair<X, Y> > {
+
+    hash<X> hash1;
+    hash<Y> hash2;
+
+    size_t operator () (const std::pair<X, Y> & p)
+    {
+        return chain_hash(hash1(p.first),
+                          chain_hash(hash2(p.second)));
+    }
+};
+
+} // namespace JML_HASH_NS
 
 
 #endif /* __utils__hash_specializations_h__ */