From 597e17b540560f73d79601a820432a1b1236f036 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 9 Dec 2013 16:34:10 +0800 Subject: [PATCH] Fix template related compilation errors of VC++. --- common/swap_or_assign.h | 34 ++++++++++++++++++++++++++++++++-- common/v8_conversions.h | 2 +- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/common/swap_or_assign.h b/common/swap_or_assign.h index 3953653f8..a3749ca88 100644 --- a/common/swap_or_assign.h +++ b/common/swap_or_assign.h @@ -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 inline +void SwapOrAssign(T& v1, const T& v2) { + __if_exists(T::swap) { + v1.swap(const_cast(v2)); + } + + __if_not_exists(T::swap) { + v1 = v2; + } +} + +template 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 class HasSwapMethod { @@ -24,17 +53,18 @@ struct enable_if {}; template struct enable_if { typedef T type; }; -template +template inline typename enable_if::value>::type SwapOrAssign( T& v1, const T& v2) { v1.swap(const_cast(v2)); } -template +template inline typename enable_if::value>::type SwapOrAssign( T& v1, const T& v2) { v1 = v2; } +#endif // !defined(OS_WIN) } // namespace internal diff --git a/common/v8_conversions.h b/common/v8_conversions.h index 90ae2fc79..0c1f147e1 100644 --- a/common/v8_conversions.h +++ b/common/v8_conversions.h @@ -237,7 +237,7 @@ bool FromV8Arguments(const v8::Arguments& args, T1* value, int index = 0) { if (!V8ValueCanBeConvertedTo(args[index])) return false; internal::SwapOrAssign(*value, - static_cast(FromV8Value(args[index]))); + FromV8Value(args[index]).operator T1()); return true; } -- 2.34.1