]> khamidou — GitHub mirrors - electron.git/commitdiff
Fix template related compilation errors of VC++.
authorCheng Zhao <zcbenz@gmail.com>
Mon, 9 Dec 2013 08:34:10 +0000 (16:34 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Mon, 9 Dec 2013 08:34:10 +0000 (16:34 +0800)
common/swap_or_assign.h
common/v8_conversions.h

index 3953653f8f5718ec0e903ed1ce413612863d8e2a..a3749ca88202c60b452fcd98b6bf6c53777c1888 100644 (file)
@@ -5,8 +5,37 @@
 #ifndef ATOM_COMMON_SWAP_OR_ASSIGN_H_
 #define ATOM_COMMON_SWAP_OR_ASSIGN_H_
 
+#include "base/compiler_specific.h"
+
 namespace internal {
 
+#if defined(OS_WIN)
+template<typename T> inline
+void SwapOrAssign(T& v1, const T& v2) {
+  __if_exists(T::swap) {
+    v1.swap(const_cast<T&>(v2));
+  }
+
+  __if_not_exists(T::swap) {
+    v1 = v2;
+  }
+}
+
+template<typename T> inline
+void SwapOrAssign(T*& v1, T* v2) {
+  v1 = v2;
+}
+
+inline
+void SwapOrAssign(int& v1, int v2) {
+  v1 = v2;
+}
+
+inline
+void SwapOrAssign(bool& v1, bool v2) {
+  v1 = v2;
+}
+#else  // defined(OS_WIN)
 // Helper to detect whether value has specified method.
 template <typename T>
 class HasSwapMethod {
@@ -24,17 +53,18 @@ struct enable_if {};
 template<class T>
 struct enable_if<true, T> { typedef T type; };
 
-template<typename T>
+template<typename T> inline
 typename enable_if<HasSwapMethod<T>::value>::type SwapOrAssign(
     T& v1, const T& v2) {
   v1.swap(const_cast<T&>(v2));
 }
 
-template<typename T>
+template<typename T> inline
 typename enable_if<!HasSwapMethod<T>::value>::type SwapOrAssign(
     T& v1, const T& v2) {
   v1 = v2;
 }
+#endif  // !defined(OS_WIN)
 
 }  // namespace internal
 
index 90ae2fc79d2bf7b2c6d0b9a9f4f74b5a88dc183d..0c1f147e1417ed0278e4f199aca07fcfd67df048 100644 (file)
@@ -237,7 +237,7 @@ bool FromV8Arguments(const v8::Arguments& args, T1* value, int index = 0) {
   if (!V8ValueCanBeConvertedTo<T1>(args[index]))
     return false;
   internal::SwapOrAssign(*value,
-                         static_cast<const T1&>(FromV8Value(args[index])));
+                         FromV8Value(args[index]).operator T1());
   return true;
 }