#ifndef TypeTraits_h
#define TypeTraits_h
+#include <utility>
+
namespace WTF {
// The following are provided in this file:
//
// IsInteger<T>::value
- // IsPod<T>::value, see the definition for a note about its limitations
+ // IsPod<T>::value
// IsConvertibleToInteger<T>::value
//
// IsArray<T>::value
template<typename T> struct IsArithmetic { static const bool value = IsInteger<T>::value || IsFloatingPoint<T>::value; };
+ template<typename T> struct IsPointer {
+ static const bool value = false;
+ };
+
+ template<typename P> struct IsPointer<const P*> {
+ static const bool value = true;
+ };
+
+ template<typename P> struct IsPointer<P*> {
+ static const bool value = true;
+ };
+
+ template<typename T> struct IsEnum {
+ static const bool value = __is_enum(T);
+ };
+
+ template<typename T> struct IsScalar {
+ static const bool value = IsEnum<T>::value || IsArithmetic<T>::value || IsPointer<T>::value;
+ };
+
template<typename T> struct IsWeak { static const bool value = false; };
- // IsPod is misnamed as it doesn't cover all plain old data (pod) types.
- // Specifically, it doesn't allow for enums or for structs.
- template <typename T> struct IsPod { static const bool value = IsArithmetic<T>::value; };
- template <typename P> struct IsPod<P*> { static const bool value = true; };
+ enum WeakHandlingFlag {
+ NoWeakHandlingInCollections,
+ WeakHandlingInCollections
+ };
+
+ template <typename T> struct IsPod {
+ static const bool value = __is_pod(T);
+ };
+
+ template <typename T> struct IsTriviallyCopyAssignable {
+ static const bool value = __has_trivial_assign(T);
+ };
+
+ template <typename T> struct IsTriviallyMoveAssignable {
+ static const bool value = __has_trivial_assign(T);
+ };
+
+ template <typename T> struct IsTriviallyDefaultConstructible {
+ static const bool value = __has_trivial_constructor(T);
+ };
+
+ template <typename T> struct IsTriviallyDestructible {
+ static const bool value = __has_trivial_destructor(T);
+ };
template<typename T> class IsConvertibleToInteger {
// Avoid "possible loss of data" warning when using Microsoft's C++ compiler
static const bool value = sizeof(subclassCheck(t)) == sizeof(YesType);
};
- template <typename T, template<class V> class U> class IsSubclassOfTemplate {
+ template <typename T, template<typename... V> class U> class IsSubclassOfTemplate {
typedef char YesType;
struct NoType {
char padding[8];
};
- template<typename W> static YesType subclassCheck(U<W>*);
+ template<typename... W> static YesType subclassCheck(U<W...>*);
static NoType subclassCheck(...);
static T* t;
public:
static const bool value = sizeof(subclassCheck(t)) == sizeof(YesType);
};
- template <typename T, template<class A, class B, class C> class U> class IsSubclassOfTemplate3 {
- typedef char YesType;
- struct NoType {
- char padding[8];
- };
-
- template<typename D, typename E, typename F> static YesType subclassCheck(U<D, E, F>*);
- static NoType subclassCheck(...);
- static T* t;
- public:
- static const bool value = sizeof(subclassCheck(t)) == sizeof(YesType);
- };
-
- template <typename T, template<class A, class B, class C, class D, class E> class U> class IsSubclassOfTemplate5 {
- typedef char YesType;
- struct NoType {
- char padding[8];
- };
-
- template<typename F, typename G, typename H, typename I, typename J> static YesType subclassCheck(U<F, G, H, I, J>*);
- static NoType subclassCheck(...);
- static T* t;
- public:
- static const bool value = sizeof(subclassCheck(t)) == sizeof(YesType);
- };
-
template <typename T, template <class V> class OuterTemplate> struct RemoveTemplate {
typedef T Type;
};
typedef T Type;
};
+ // Determines whether this type has a vtable.
+ template <typename T> struct IsPolymorphic {
+ static const bool value = __is_polymorphic(T);
+ };
+
#define EnsurePtrConvertibleArgDecl(From, To) \
typename WTF::EnableIf<WTF::IsPointerConvertible<From, To>::Value, bool>::Type = true
#define EnsurePtrConvertibleArgDefn(From, To) \
} // namespace WTF
-namespace WebCore {
+namespace blink {
class JSONValue;
-} // namespace WebCore
+} // namespace blink
namespace WTF {
// FIXME: Disable pointer conversion checking against JSONValue.
// The current CodeGeneratorInspector.py generates code which upcasts to JSONValue from undefined types.
- template<typename From> class IsPointerConvertible<From, WebCore::JSONValue> {
+ template<typename From> class IsPointerConvertible<From, blink::JSONValue> {
public:
enum {
Value = true
typedef struct NoType {
char padding[8];
} NoType;
-
#if COMPILER(MSVC)
template<typename V> static YesType checkHasTraceMethod(char[&V::trace != 0]);
#else
#endif // COMPILER(MSVC)
template<typename V> static NoType checkHasTraceMethod(...);
public:
- static const bool value = sizeof(YesType) == sizeof(checkHasTraceMethod<T>(0));
+ // 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);
};
// Convenience template wrapping the NeedsTracingLazily template in
static const bool value = Traits::template NeedsTracingLazily<>::value;
};
+template<typename T, typename U>
+struct NeedsTracing<std::pair<T, U> > {
+ static const bool value = NeedsTracing<T>::value || NeedsTracing<U>::value || IsWeak<T>::value || IsWeak<U>::value;
+};
+
} // namespace WTF
#endif // TypeTraits_h