Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2823)

Unified Diff: Source/wtf/TypeTraits.h

Issue 827723002: Reland: Templatize visitor arguments for TraceTrait mark and trace methods. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: rebased Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/wtf/HashTable.h ('k') | Source/wtf/Vector.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/wtf/TypeTraits.h
diff --git a/Source/wtf/TypeTraits.h b/Source/wtf/TypeTraits.h
index 367978f216561b0aef482a68d4fbc89a0107c3b6..d9eeecdcc448bde2de262491b2c91ca6d28003b5 100644
--- a/Source/wtf/TypeTraits.h
+++ b/Source/wtf/TypeTraits.h
@@ -303,6 +303,7 @@ namespace WTF {
namespace blink {
class JSONValue;
+class Visitor;
} // namespace blink
@@ -317,24 +318,46 @@ namespace WTF {
};
};
+#if COMPILER(MSVC)
+template<typename T, bool = __is_class(T)> struct NeedsTracingMSVC;
+
+template<typename T>
+struct NeedsTracingMSVC<T, true> {
+ __if_exists(T::trace)
+ {
+ static const bool value = true;
+ }
+ __if_not_exists(T::trace)
+ {
+ static const bool value = false;
+ }
+};
+
+template<typename T>
+struct NeedsTracingMSVC<T, false> {
+ static const bool value = false;
+};
+#endif
+
template<typename T>
class NeedsTracing {
+#if COMPILER(MSVC)
+public:
+ static const bool value = NeedsTracingMSVC<T>::value;
+#else
typedef char YesType;
typedef struct NoType {
char padding[8];
} NoType;
-#if COMPILER(MSVC)
- template<typename V> static YesType checkHasTraceMethod(char[&V::trace != 0]);
-#else
template<size_t> struct HasMethod;
- template<typename V> static YesType checkHasTraceMethod(HasMethod<sizeof(&V::trace)>*);
-#endif // COMPILER(MSVC)
+ template<typename V> static YesType checkHasTraceMethod(HasMethod<sizeof(static_cast<void (V::*)(blink::Visitor*)>(&V::trace))>*);
template<typename V> static NoType checkHasTraceMethod(...);
public:
// We add sizeof(T) to both sides here, because we want it to fail for
// incomplete types. Otherwise it just assumes that incomplete types do not
// have a trace method, which may not be true.
- static const bool value = sizeof(YesType) + sizeof(T) == sizeof(checkHasTraceMethod<T>(0)) + sizeof(T);
+ static const bool value = sizeof(YesType) + sizeof(T) == sizeof(checkHasTraceMethod<T>(nullptr)) + sizeof(T);
+#endif // COMPILER(MSVC)
};
// Convenience template wrapping the NeedsTracingLazily template in
« no previous file with comments | « Source/wtf/HashTable.h ('k') | Source/wtf/Vector.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698