Commit 75939be3 authored by Stuart Langley's avatar Stuart Langley Committed by Commit Bot

Use std:: type traits where available instead of WTF versions.

This patch removes the hand crafted implementation of WTF type traits with the
versions now available in the std:: type_traits library. The first patch
will have the WTF versions use the std:: implementation, a followup
patch will remove the WTF versions entirely.

This patch replaces the implementations of -> with:

WTF::IsCopyAssignable -> std::is_copy_assignable
WTF::IsMoveAssignable -> std::is_move_assignable
WTF::IsTriviallyCopyAssignable -> std::is_trivially_copy_assignable
WTF::IsTriviallyMoveAssignable* -> std::is_trivially_move_assignable
WTF::IsDestructible -> std::is_destructible
WTF::IsTriviallyDefaultConstructible -> std::is_trivially_default_constructible

Bug: 579462
Change-Id: I4ac335929e298f8b28a23021fef8e58ae855f3c6
Reviewed-on: https://chromium-review.googlesource.com/756258
Commit-Queue: Yuta Kitamura <yutak@chromium.org>
Reviewed-by: default avatarYuta Kitamura <yutak@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Cr-Commit-Position: refs/heads/master@{#515452}
parent 19322015
......@@ -46,83 +46,47 @@ enum WeakHandlingFlag {
kWeakHandlingInCollections
};
template <typename T, typename From>
class IsAssignable {
typedef char YesType;
struct NoType {
char padding[8];
};
template <typename T2,
typename From2,
typename = decltype(std::declval<T2&>() = std::declval<From2>())>
static YesType CheckAssignability(int);
template <typename T2, typename From2>
static NoType CheckAssignability(...);
public:
static const bool value =
sizeof(CheckAssignability<T, From>(0)) == sizeof(YesType);
};
template <typename T>
struct IsCopyAssignable {
static_assert(!std::is_reference<T>::value, "T must not be a reference.");
static const bool value = IsAssignable<T, const T&>::value;
static constexpr bool value = std::is_copy_assignable<T>::value;
};
template <typename T>
struct IsMoveAssignable {
static_assert(!std::is_reference<T>::value, "T must not be a reference.");
static const bool value = IsAssignable<T, T&&>::value;
static constexpr bool value = std::is_move_assignable<T>::value;
};
template <typename T>
struct IsTriviallyCopyAssignable {
static const bool value =
__has_trivial_assign(T) && IsCopyAssignable<T>::value;
static constexpr bool value = std::is_trivially_copy_assignable<T>::value;
};
template <typename T>
struct IsTriviallyMoveAssignable {
// TODO(yutak): This isn't really correct, because __has_trivial_assign
// appears to look only at copy assignment. However,
// std::is_trivially_move_assignable isn't available at this moment, and
// there isn't a good way to write that ourselves.
//
// Here we use IsTriviallyCopyAssignable as a conservative approximation: if T
// is trivially copy assignable, T is trivially move assignable, too. This
// definition misses a case where T is trivially move-only assignable, but
// such cases should be rare.
static const bool value = IsTriviallyCopyAssignable<T>::value;
static constexpr bool value = std::is_trivially_move_assignable<T>::value;
};
template <typename T>
class IsDestructible {
typedef char YesType;
struct NoType {
char padding[8];
};
template <typename T2, typename = decltype(std::declval<T2>().~T2())>
static YesType CheckDestructibility(int);
template <typename T2>
static NoType CheckDestructibility(...);
struct IsDestructible {
static constexpr bool value = std::is_destructible<T>::value;
};
public:
static const bool value =
sizeof(CheckDestructibility<T>(0)) == sizeof(YesType);
template <typename T>
struct IsDefaultConstructible {
static constexpr bool value = std::is_default_constructible<T>::value;
};
template <typename T>
struct IsTriviallyDefaultConstructible {
static const bool value =
__has_trivial_constructor(T) && std::is_constructible<T>::value;
static constexpr bool value =
std::is_trivially_default_constructible<T>::value;
};
template <typename T>
struct IsTriviallyDestructible {
static const bool value =
// TODO(slangley): crbug.com/783060 - std::is_trivially_destructible behaves
// differently on across platforms.
static constexpr bool value =
__has_trivial_destructor(T) && IsDestructible<T>::value;
};
......
......@@ -43,8 +43,8 @@ static_assert(IsTriviallyMoveAssignable<DestructorClass>::value,
"DestructorClass should be trivially move assignable");
static_assert(IsTriviallyCopyAssignable<DestructorClass>::value,
"DestructorClass should be trivially copy assignable");
static_assert(IsTriviallyDefaultConstructible<DestructorClass>::value,
"DestructorClass should have a trivial default constructor");
static_assert(IsDefaultConstructible<DestructorClass>::value,
"DestructorClass should be default constructible");
struct MixedPrivate {
int M2() { return m2; }
......
......@@ -33,20 +33,22 @@ template <typename T>
struct VectorTraitsBase {
static const bool kNeedsDestruction = !IsTriviallyDestructible<T>::value;
static const bool kCanInitializeWithMemset =
IsTriviallyDefaultConstructible<T>::value;
static constexpr bool kCanInitializeWithMemset =
std::is_trivially_default_constructible<T>::value;
// true iff memset(slot, 0, size) constructs an unused slot value that is
// valid for Oilpan to trace and if the value needs destruction, its
// destructor can be invoked over. The zero'ed value representing an unused
// slot in the vector's backing storage; it does not have to be equal to
// what its constructor(s) would create, only be valid for those two uses.
static const bool kCanClearUnusedSlotsWithMemset =
IsTriviallyDefaultConstructible<T>::value;
static constexpr bool kCanClearUnusedSlotsWithMemset =
std::is_trivially_constructible<T>::value &&
std::is_trivially_destructible<T>::value &&
std::is_trivially_copyable<T>::value;
static const bool kCanMoveWithMemcpy = IsTriviallyMoveAssignable<T>::value;
static const bool kCanCopyWithMemcpy = IsTriviallyCopyAssignable<T>::value;
static const bool kCanFillWithMemset =
IsTriviallyDefaultConstructible<T>::value && (sizeof(T) == sizeof(char));
IsDefaultConstructible<T>::value && (sizeof(T) == sizeof(char));
static const bool kCanCompareWithMemcmp =
std::is_scalar<T>::value; // Types without padding.
......
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