Commit 1ccd19c0 authored by mikhail.pozdnyakov's avatar mikhail.pozdnyakov Committed by Commit bot

more switching to standard type traits

The patch changes removes WTF type trais and changes the client code as following:
WTF::EnableIf -> std::enable_if
WTF::IsSameType -> std::is_same
WTF::IsConvertibleTo.. -> std::is_convertible
WTF::IsPolymorphic -> std::is_polymorphic

BUG=554293

Review URL: https://codereview.chromium.org/1477213003

Cr-Commit-Position: refs/heads/master@{#367242}
parent b0bb8262
......@@ -198,7 +198,7 @@ public:
}
template<typename T> static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> create(T value)
{
static_assert(!WTF::IsSameType<T, CSSValueID>::value, "Do not call create() with a CSSValueID; call createIdentifier() instead");
static_assert(!std::is_same<T, CSSValueID>::value, "Do not call create() with a CSSValueID; call createIdentifier() instead");
return adoptRefWillBeNoop(new CSSPrimitiveValue(value));
}
......
......@@ -80,8 +80,8 @@ row, const LayoutTableCell* cell)
void CellSpan::ensureConsistency(const unsigned maximumSpanSize)
{
static_assert(WTF::IsSameType<decltype(m_start), unsigned>::value, "Asserts below assume m_start is unsigned");
static_assert(WTF::IsSameType<decltype(m_end), unsigned>::value, "Asserts below assume m_end is unsigned");
static_assert(std::is_same<decltype(m_start), unsigned>::value, "Asserts below assume m_start is unsigned");
static_assert(std::is_same<decltype(m_end), unsigned>::value, "Asserts below assume m_end is unsigned");
RELEASE_ASSERT(m_start <= maximumSpanSize);
RELEASE_ASSERT(m_end <= maximumSpanSize);
RELEASE_ASSERT(m_start <= m_end);
......
......@@ -69,17 +69,17 @@ CrossThreadCopierBase<false, false, false, ResourceResponse>::Type CrossThreadCo
class CopierThreadSafeRefCountedTest : public ThreadSafeRefCounted<CopierThreadSafeRefCountedTest> {
};
static_assert((WTF::IsSameType<
static_assert((std::is_same<
PassRefPtr<CopierThreadSafeRefCountedTest>,
CrossThreadCopier<PassRefPtr<CopierThreadSafeRefCountedTest>>::Type
>::value),
"PassRefPtr test");
static_assert((WTF::IsSameType<
static_assert((std::is_same<
PassRefPtr<CopierThreadSafeRefCountedTest>,
CrossThreadCopier<RefPtr<CopierThreadSafeRefCountedTest>>::Type
>::value),
"RefPtr test");
static_assert((WTF::IsSameType<
static_assert((std::is_same<
PassRefPtr<CopierThreadSafeRefCountedTest>,
CrossThreadCopier<CopierThreadSafeRefCountedTest*>::Type
>::value),
......@@ -95,33 +95,33 @@ template<typename T> struct CrossThreadCopierBase<false, false, false, T> {
class CopierRefCountedTest : public RefCounted<CopierRefCountedTest> {
};
static_assert((WTF::IsSameType<
static_assert((std::is_same<
int,
CrossThreadCopier<PassRefPtr<CopierRefCountedTest>>::Type
>::value),
"PassRefPtr<RefCountedTest> test");
static_assert((WTF::IsSameType<
static_assert((std::is_same<
int,
CrossThreadCopier<RefPtr<CopierRefCountedTest>>::Type
>::value),
"RefPtr<RefCounted> test");
static_assert((WTF::IsSameType<
static_assert((std::is_same<
int,
CrossThreadCopier<CopierRefCountedTest*>::Type
>::value),
"Raw pointer RefCounted test");
// Verify that PassOwnPtr gets passed through.
static_assert((WTF::IsSameType<
static_assert((std::is_same<
PassOwnPtr<float>,
CrossThreadCopier<PassOwnPtr<float>>::Type
>::value),
"PassOwnPtr test");
// Verify that PassOwnPtr does not get passed through.
static_assert((WTF::IsSameType<
static_assert((std::is_same<
int,
CrossThreadCopier<OwnPtr<float>>::Type
>::value),
......
......@@ -87,9 +87,9 @@ namespace blink {
typedef typename std::remove_pointer<TypeWithoutPassRefPtr>::type RefCountedType;
// Verify that only one of the above did a change.
static_assert((WTF::IsSameType<RefPtr<RefCountedType>, T>::value
|| WTF::IsSameType<PassRefPtr<RefCountedType>, T>::value
|| WTF::IsSameType<RefCountedType*, T>::value),
static_assert((std::is_same<RefPtr<RefCountedType>, T>::value
|| std::is_same<PassRefPtr<RefCountedType>, T>::value
|| std::is_same<RefCountedType*, T>::value),
"only one type modification should be allowed");
typedef PassRefPtr<RefCountedType> Type;
......@@ -184,7 +184,7 @@ namespace blink {
}
};
template<typename T> struct CrossThreadCopier : public CrossThreadCopierBase<WTF::IsConvertibleToInteger<T>::value,
template<typename T> struct CrossThreadCopier : public CrossThreadCopierBase<std::is_convertible<T, int>::value,
WTF::IsSubclassOfTemplate<typename WTF::RemoveTemplate<T, RefPtr>::Type, ThreadSafeRefCounted>::value
|| WTF::IsSubclassOfTemplate<typename std::remove_pointer<T>::type, ThreadSafeRefCounted>::value
|| WTF::IsSubclassOfTemplate<typename WTF::RemoveTemplate<T, PassRefPtr>::Type, ThreadSafeRefCounted>::value,
......
......@@ -390,7 +390,7 @@ template<typename T> struct ConvertableToTraceFormatTraits {
};
template<typename T> struct ConvertableToTraceFormatTraits<PassRefPtr<T>> {
static const bool isConvertable = WTF::IsSubclass<T, TraceEvent::ConvertableToTraceFormat>::value;
static const bool isConvertable = std::is_convertible<T*, TraceEvent::ConvertableToTraceFormat*>::value;
static PassRefPtr<ConvertableToTraceFormat> moveFromIfConvertable(const PassRefPtr<T>& convertableToTraceFormat)
{
return convertableToTraceFormat;
......
......@@ -233,7 +233,7 @@ TEST(ContiguousContainerTest, ForwardIteration)
}
EXPECT_EQ(kNumElements, count);
static_assert(WTF::IsSameType<decltype(*list.begin()), Point2D&>::value,
static_assert(std::is_same<decltype(*list.begin()), Point2D&>::value,
"Non-const iteration should produce non-const references.");
}
......@@ -251,7 +251,7 @@ TEST(ContiguousContainerTest, ConstForwardIteration)
}
EXPECT_EQ(kNumElements, count);
static_assert(WTF::IsSameType<decltype(*constList.begin()), const Point2D&>::value,
static_assert(std::is_same<decltype(*constList.begin()), const Point2D&>::value,
"Const iteration should produce const references.");
}
......@@ -268,7 +268,7 @@ TEST(ContiguousContainerTest, ReverseIteration)
}
EXPECT_EQ(kNumElements, count);
static_assert(WTF::IsSameType<decltype(*list.rbegin()), Point2D&>::value,
static_assert(std::is_same<decltype(*list.rbegin()), Point2D&>::value,
"Non-const iteration should produce non-const references.");
}
......
......@@ -164,7 +164,7 @@ struct GCInfoAtBaseType {
TraceTrait<T>::trace,
FinalizerTrait<T>::finalize,
FinalizerTrait<T>::nonTrivialFinalizer,
WTF::IsPolymorphic<T>::value,
std::is_polymorphic<T>::value,
#if ENABLE(DETAILED_MEMORY_INFRA)
TypenameStringTrait<T>::get
#endif
......
......@@ -250,7 +250,7 @@ void HeapVectorBacking<T, Traits>::finalize(void* pointer)
{
static_assert(Traits::needsDestruction, "Only vector buffers with items requiring destruction should be finalized");
// See the comment in HeapVectorBacking::trace.
static_assert(Traits::canClearUnusedSlotsWithMemset || WTF::IsPolymorphic<T>::value, "HeapVectorBacking doesn't support objects that cannot be cleared as unused with memset or don't have a vtable");
static_assert(Traits::canClearUnusedSlotsWithMemset || std::is_polymorphic<T>::value, "HeapVectorBacking doesn't support objects that cannot be cleared as unused with memset or don't have a vtable");
ASSERT(!WTF::IsTriviallyDestructible<T>::value);
HeapObjectHeader* header = HeapObjectHeader::fromPayload(pointer);
......@@ -264,7 +264,7 @@ void HeapVectorBacking<T, Traits>::finalize(void* pointer)
// (which are already zeroed out).
ANNOTATE_CHANGE_SIZE(buffer, length, 0, length);
#endif
if (WTF::IsPolymorphic<T>::value) {
if (std::is_polymorphic<T>::value) {
for (unsigned i = 0; i < length; ++i) {
if (blink::vTableInitialized(&buffer[i]))
buffer[i].~T();
......
......@@ -385,7 +385,7 @@ struct TraceInCollectionTrait<NoWeakHandlingInCollections, strongify, blink::Hea
// This is fine because the fact that the object can be initialized
// with memset indicates that it is safe to treat the zerod slot
// as a valid object.
static_assert(!NeedsTracingTrait<Traits>::value || Traits::canClearUnusedSlotsWithMemset || WTF::IsPolymorphic<T>::value, "HeapVectorBacking doesn't support objects that cannot be cleared as unused with memset.");
static_assert(!NeedsTracingTrait<Traits>::value || Traits::canClearUnusedSlotsWithMemset || std::is_polymorphic<T>::value, "HeapVectorBacking doesn't support objects that cannot be cleared as unused with memset.");
// This trace method is instantiated for vectors where
// NeedsTracingTrait<Traits>::value is false, but the trace method
......@@ -399,7 +399,7 @@ struct TraceInCollectionTrait<NoWeakHandlingInCollections, strongify, blink::Hea
// Use the payload size as recorded by the heap to determine how many
// elements to trace.
size_t length = header->payloadSize() / sizeof(T);
if (WTF::IsPolymorphic<T>::value) {
if (std::is_polymorphic<T>::value) {
for (size_t i = 0; i < length; ++i) {
if (blink::vTableInitialized(&array[i]))
blink::TraceIfEnabled<T, NeedsTracingTrait<Traits>::value>::trace(visitor, array[i]);
......
......@@ -187,7 +187,7 @@ public:
void trace(const T& t)
{
static_assert(sizeof(T), "T must be fully defined");
if (WTF::IsPolymorphic<T>::value) {
if (std::is_polymorphic<T>::value) {
intptr_t vtable = *reinterpret_cast<const intptr_t*>(&t);
if (!vtable)
return;
......
......@@ -159,7 +159,7 @@ template <typename Target, typename Source> struct BoundsChecker<Target, Source,
}
};
template <typename Target, typename Source, bool CanElide = IsSameType<Target, Source>::value || (sizeof(Target) > sizeof(Source)) > struct BoundsCheckElider;
template <typename Target, typename Source, bool CanElide = std::is_same<Target, Source>::value || (sizeof(Target) > sizeof(Source)) > struct BoundsCheckElider;
template <typename Target, typename Source> struct BoundsCheckElider<Target, Source, true> {
static bool inBounds(Source) { return true; }
};
......
......@@ -226,7 +226,7 @@ inline Deque<T, inlineCapacity, Allocator>::Deque()
: m_start(0)
, m_end(0)
{
static_assert(!IsPolymorphic<T>::value || !VectorTraits<T>::canInitializeWithMemset, "Cannot initialize with memset if there is a vtable");
static_assert(!std::is_polymorphic<T>::value || !VectorTraits<T>::canInitializeWithMemset, "Cannot initialize with memset if there is a vtable");
#if ENABLE(OILPAN)
static_assert(Allocator::isGarbageCollected || !AllowsOnlyPlacementNew<T>::value || !NeedsTracing<T>::value, "Cannot put DISALLOW_NEW_EXCEPT_PLACEMENT_NEW objects that have trace methods into an off-heap Deque");
#endif
......
......@@ -995,10 +995,10 @@ Value* HashTable<Key, Value, Extractor, HashFunctions, Traits, KeyTraits, Alloca
ValueType* result;
// Assert that we will not use memset on things with a vtable entry. The
// compiler will also check this on some platforms. We would like to check
// this on the whole value (key-value pair), but IsPolymorphic will return
// this on the whole value (key-value pair), but std::is_polymorphic will return
// false for a pair of two types, even if one of the components is
// polymorphic.
static_assert(!Traits::emptyValueIsZero || !IsPolymorphic<KeyType>::value, "empty value cannot be zero for things with a vtable");
static_assert(!Traits::emptyValueIsZero || !std::is_polymorphic<KeyType>::value, "empty value cannot be zero for things with a vtable");
#if ENABLE(OILPAN)
static_assert(Allocator::isGarbageCollected
......
......@@ -103,7 +103,7 @@ class CanRegisterStaticLocalReference {
} NoType;
// Check if class T has public method "T* registerAsStaticReference()".
template<typename V> static YesType checkHasRegisterAsStaticReferenceMethod(V* p, typename EnableIf<IsSubclass<V, typename std::remove_pointer<decltype(p->registerAsStaticReference())>::type>::value>::Type* = 0);
template<typename V> static YesType checkHasRegisterAsStaticReferenceMethod(V* p, typename std::enable_if<IsSubclass<V, typename std::remove_pointer<decltype(p->registerAsStaticReference())>::type>::value>::Type* = 0);
template<typename V> static NoType checkHasRegisterAsStaticReferenceMethod(...);
public:
......
......@@ -21,9 +21,7 @@
#include "wtf/TypeTraits.h"
#include "wtf/Assertions.h"
#include "wtf/Noncopyable.h"
#include <type_traits>
namespace WTF {
......@@ -87,37 +85,6 @@ static_assert(!IsTriviallyCopyAssignable<NonCopyableClass>::value, "NonCopyableC
static_assert(IsTriviallyDefaultConstructible<NonCopyableClass>::value, "NonCopyableClass should have a trivial default constructor");
#endif // 0
enum IsConvertibleToIntegerCheck { };
static_assert(IsConvertibleToInteger<IsConvertibleToIntegerCheck>::value, "enum should be convertible to integer");
static_assert(IsConvertibleToInteger<bool>::value, "bool should be convertible to integer");
static_assert(IsConvertibleToInteger<char>::value, "char should be convertible to integer");
static_assert(IsConvertibleToInteger<signed char>::value, "signed char should be convertible to integer");
static_assert(IsConvertibleToInteger<unsigned char>::value, "unsigned char should be convertible to integer");
static_assert(IsConvertibleToInteger<short>::value, "short should be convertible to integer");
static_assert(IsConvertibleToInteger<unsigned short>::value, "unsigned short should be convertible to integer");
static_assert(IsConvertibleToInteger<int>::value, "int should be convertible to integer");
static_assert(IsConvertibleToInteger<unsigned>::value, "unsigned int should be convertible to integer");
static_assert(IsConvertibleToInteger<long>::value, "long should be convertible to integer");
static_assert(IsConvertibleToInteger<unsigned long>::value, "unsigned long should be convertible to integer");
static_assert(IsConvertibleToInteger<long long>::value, "long long should be convertible to integer");
static_assert(IsConvertibleToInteger<unsigned long long>::value, "unsigned long long should be convertible to integer");
#if !COMPILER(MSVC) || defined(_NATIVE_WCHAR_T_DEFINED)
static_assert(IsConvertibleToInteger<wchar_t>::value, "whcar_t should be convertible to integer");
#endif
static_assert(IsConvertibleToInteger<double>::value, "double should be convertible to integer");
static_assert(IsConvertibleToInteger<long double>::value, "long double should be convertible to integer");
static_assert(IsConvertibleToInteger<float>::value, "float should be convertible to integer");
static_assert(!IsConvertibleToInteger<char*>::value, "char* should not be convertible to integer");
static_assert(!IsConvertibleToInteger<const char*>::value, "const char* should not be convertible to integer");
static_assert(!IsConvertibleToInteger<volatile char*>::value, "volatile char* should not be convertible to integer");
static_assert(!IsConvertibleToInteger<IsConvertibleToInteger<bool>>::value, "struct should not be convertible to integer");
static_assert((IsSameType<bool, bool>::value), "bool should be the same type as itself");
static_assert((IsSameType<int*, int*>::value), "int* should be the same type as itself");
static_assert((!IsSameType<int, int*>::value), "int should not be the same type as int*");
static_assert((!IsSameType<bool, const bool>::value), "T should not be the same type as const T");
static_assert((!IsSameType<bool, volatile bool>::value), "T should not be the same type as volatile T");
template <typename T>
class TestBaseClass {
};
......@@ -128,8 +95,6 @@ class TestDerivedClass : public TestBaseClass<int> {
static_assert((IsSubclass<TestDerivedClass, TestBaseClass<int>>::value), "Derived class should be a subclass of its base");
static_assert((!IsSubclass<TestBaseClass<int>, TestDerivedClass>::value), "Base class should not be a sublass of a derived class");
static_assert((IsSubclassOfTemplate<TestDerivedClass, TestBaseClass>::value), "Derived class should be a subclass of template from its base");
static_assert((IsSameType<RemoveTemplate<TestBaseClass<int>, TestBaseClass>::Type, int>::value), "RemoveTemplate should remove the template typename from the type");
static_assert((IsSameType<RemoveTemplate<int, TestBaseClass>::Type, int>::value), "RemoveTemplate should not alter non-template types");
typedef int IntArray[];
typedef int IntArraySized[4];
......
......@@ -39,17 +39,6 @@ inline const char* getStringWithTypeName()
template<typename T> class RawPtr;
// The following are provided in this file:
//
// IsConvertibleToInteger<T>::value
//
// IsSameType<T, U>::value
//
// static_assert's in TypeTraits.cpp illustrate their usage and what they do.
template <bool Predicate, class T = void> struct EnableIf;
template <class T> struct EnableIf<true, T> { typedef T Type; };
template <typename T> struct IsWeak {
static const bool value = false;
};
......@@ -75,40 +64,6 @@ 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
// by not converting int's to doubles.
template <bool performCheck, typename U> class IsConvertibleToDouble;
template <typename U> class IsConvertibleToDouble<false, U> {
public:
static const bool value = false;
};
template <typename U> class IsConvertibleToDouble<true, U> {
typedef char YesType;
struct NoType {
char padding[8];
};
static YesType floatCheck(long double);
static NoType floatCheck(...);
static T& t;
public:
static const bool value = sizeof(floatCheck(t)) == sizeof(YesType);
};
public:
static const bool value = std::is_integral<T>::value || IsConvertibleToDouble<!std::is_integral<T>::value, T>::value;
};
template <typename T, typename U> struct IsSameType {
static const bool value = false;
};
template <typename T> struct IsSameType<T, T> {
static const bool value = true;
};
template <typename T, typename U> class IsSubclass {
typedef char YesType;
struct NoType {
......@@ -173,11 +128,6 @@ struct RemoveTemplate<OuterTemplate<T>, OuterTemplate> {
typedef T Type;
};
// Determines whether this type has a vtable.
template <typename T> struct IsPolymorphic {
static const bool value = __is_polymorphic(T);
};
#if (COMPILER(MSVC) || !GCC_VERSION_AT_LEAST(4, 9, 0)) && !COMPILER(CLANG)
// FIXME: MSVC bug workaround. Remove once MSVC STL is fixed.
// FIXME: GCC before 4.9.0 seems to have the same issue.
......@@ -226,7 +176,7 @@ class NeedsTracing {
} NoType;
// Note that this also checks if a superclass of V has a trace method.
template <typename V> static YesType checkHasTraceMethod(V* v, blink::Visitor* p = nullptr, typename EnableIf<IsSameType<decltype(v->trace(p)), void>::value>::Type* g = nullptr);
template <typename V> static YesType checkHasTraceMethod(V* v, blink::Visitor* p = nullptr, typename std::enable_if<std::is_same<decltype(v->trace(p)), void>::value>::type* g = nullptr);
template <typename V> static NoType checkHasTraceMethod(...);
public:
// We add sizeof(T) to both sides here, because we want it to fail for
......
......@@ -631,7 +631,7 @@ public:
Vector()
{
static_assert(!IsPolymorphic<T>::value || !VectorTraits<T>::canInitializeWithMemset, "Cannot initialize with memset if there is a vtable");
static_assert(!std::is_polymorphic<T>::value || !VectorTraits<T>::canInitializeWithMemset, "Cannot initialize with memset if there is a vtable");
#if ENABLE(OILPAN)
static_assert(Allocator::isGarbageCollected || !AllowsOnlyPlacementNew<T>::value || !NeedsTracing<T>::value, "Cannot put DISALLOW_NEW_EXCEPT_PLACEMENT_NEW objects that have trace methods into an off-heap Vector");
#endif
......@@ -644,7 +644,7 @@ public:
explicit Vector(size_t size)
: Base(size)
{
static_assert(!IsPolymorphic<T>::value || !VectorTraits<T>::canInitializeWithMemset, "Cannot initialize with memset if there is a vtable");
static_assert(!std::is_polymorphic<T>::value || !VectorTraits<T>::canInitializeWithMemset, "Cannot initialize with memset if there is a vtable");
#if ENABLE(OILPAN)
static_assert(Allocator::isGarbageCollected || !AllowsOnlyPlacementNew<T>::value || !NeedsTracing<T>::value, "Cannot put DISALLOW_NEW_EXCEPT_PLACEMENT_NEW objects that have trace methods into an off-heap Vector");
#endif
......
......@@ -127,7 +127,7 @@ private:
// correctly-folded code point in all cases (see comment below).
template<typename T> static inline UChar foldCase(T ch)
{
if (IsSameType<T, LChar>::value)
if (std::is_same<T, LChar>::value)
return StringImpl::latin1CaseFoldTable[ch];
// It's possible for WTF::Unicode::foldCase() to return a 32-bit value
// that's not representable as a UChar. However, since this is rare and
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment