More <type_traits> for SkTLogic.h.

SkTLogic.h specifies a number of declarations now found in
<type_traits>. This removes some of these declarations from SkTLogic.h
in favor of the ::std versions. These declarations are fairly safe to
change as the implementations are striaght forward and no known stl
implementations are known to have issues with them.

Review URL: https://codereview.chromium.org/1565283003
This commit is contained in:
bungeman 2016-01-07 12:39:11 -08:00 committed by Commit bot
parent f96bf1a2d0
commit de029d0e41
2 changed files with 29 additions and 50 deletions

View File

@ -35,37 +35,13 @@ template <typename T> using remove_pointer_t = typename std::remove_pointer<T>::
template <typename T> using remove_reference_t = typename std::remove_reference<T>::type;
template <typename T> using remove_extent_t = typename std::remove_extent<T>::type;
template <typename T, typename U> struct is_same : std::false_type {};
template <typename T> struct is_same<T, T> : std::true_type {};
template <typename T> struct is_void : is_same<void, remove_cv_t<T>> {};
template <typename T> struct is_const : std::false_type {};
template <typename T> struct is_const<const T> : std::true_type {};
template <typename T> struct is_volatile : std::false_type {};
template <typename T> struct is_volatile<volatile T> : std::true_type {};
template <typename T> struct is_pointer_detector : std::false_type {};
template <typename T> struct is_pointer_detector<T*> : std::true_type {};
template <typename T> struct is_pointer : is_pointer_detector<remove_cv_t<T>> {};
template <typename T> struct is_reference : std::false_type {};
template <typename T> struct is_reference<T&> : std::true_type {};
template <typename T> struct is_reference<T&&> : std::true_type {};
template <typename T> struct is_lvalue_reference : std::false_type {};
template <typename T> struct is_lvalue_reference<T&> : std::true_type {};
template <typename T> struct is_rvalue_reference : std::false_type {};
template <typename T> struct is_rvalue_reference<T&&> : std::true_type {};
template <typename T> struct is_class_detector {
using yes_type = uint8_t;
using no_type = uint16_t;
template <typename U> static yes_type clazz(int U::*);
template <typename U> static no_type clazz(...);
static const/*expr*/ bool value = sizeof(clazz<T>(0)) == sizeof(yes_type) /*&& !is_union<T>::value*/;
static const/*expr*/ bool value = sizeof(clazz<T>(0)) == sizeof(yes_type) &&
!std::is_union<T>::value;
};
template <typename T> struct is_class : bool_constant<is_class_detector<T>::value> {};
@ -78,10 +54,6 @@ template <typename T> struct is_empty_detector<T, false> {
};
template <typename T> struct is_empty : bool_constant<is_empty_detector<T>::value> {};
template <typename T> struct is_array : std::false_type {};
template <typename T> struct is_array<T[]> : std::true_type {};
template <typename T, size_t N> struct is_array<T[N]> : std::true_type {};
// template<typename R, typename... Args> struct is_function<
// R [calling-convention] (Args...[, ...]) [const] [volatile] [&|&&]> : std::true_type {};
// The cv and ref-qualified versions are strange types we're currently avoiding, so not supported.
@ -109,19 +81,20 @@ template <typename T> using add_volatile_t = typename std::add_volatile<T>::type
template <typename T> using add_cv_t = typename std::add_cv<T>::type;
template <typename T> using add_pointer_t = typename std::add_pointer<T>::type;
template <typename T, bool=is_void<T>::value> struct add_lvalue_reference_init { using type = T; };
template <typename T, bool=std::is_void<T>::value> struct add_lvalue_reference_init { using type = T; };
template <typename T> struct add_lvalue_reference_init<T, false> { using type = T&; };
template <typename T> struct add_lvalue_reference : add_lvalue_reference_init<T> {};
template <typename T> using add_lvalue_reference_t = typename add_lvalue_reference<T>::type;
template <typename T, bool=is_void<T>::value> struct add_rvalue_reference_init { using type = T; };
template <typename T, bool=std::is_void<T>::value> struct add_rvalue_reference_init { using type = T; };
template <typename T> struct add_rvalue_reference_init<T, false> { using type = T&&; };
template <typename T> struct add_rvalue_reference : add_rvalue_reference_init<T> {};
template <typename T> using add_rvalue_reference_t = typename add_rvalue_reference<T>::type;
template <typename S, typename D, bool=is_void<S>::value||is_function<D>::value||is_array<D>::value>
template <typename S, typename D,
bool=std::is_void<S>::value || is_function<D>::value || std::is_array<D>::value>
struct is_convertible_detector {
static const/*expr*/ bool value = is_void<D>::value;
static const/*expr*/ bool value = std::is_void<D>::value;
};
template <typename S, typename D> struct is_convertible_detector<S, D, false> {
using yes_type = uint8_t;
@ -141,9 +114,11 @@ template<typename S, typename D> struct is_convertible
template <typename T> struct decay {
using U = remove_reference_t<T>;
using type = conditional_t<is_array<U>::value,
remove_extent_t<U>*,
conditional_t<is_function<U>::value, add_pointer_t<U>, remove_cv_t<U>>>;
using type = conditional_t<std::is_array<U>::value,
remove_extent_t<U>*,
conditional_t<is_function<U>::value,
add_pointer_t<U>,
remove_cv_t<U>>>;
};
template <typename T> using decay_t = typename decay<T>::type;
@ -157,12 +132,12 @@ namespace sknonstd {
// std::experimental::propagate_const already exists for other purposes in TSv2.
// These also follow the <dest, source> pattern used by boost.
template <typename D, typename S> struct copy_const {
using type = skstd::conditional_t<skstd::is_const<S>::value, skstd::add_const_t<D>, D>;
using type = skstd::conditional_t<std::is_const<S>::value, skstd::add_const_t<D>, D>;
};
template <typename D, typename S> using copy_const_t = typename copy_const<D, S>::type;
template <typename D, typename S> struct copy_volatile {
using type = skstd::conditional_t<skstd::is_volatile<S>::value, skstd::add_volatile_t<D>, D>;
using type = skstd::conditional_t<std::is_volatile<S>::value, skstd::add_volatile_t<D>, D>;
};
template <typename D, typename S> using copy_volatile_t = typename copy_volatile<D, S>::type;

View File

@ -94,24 +94,25 @@ private:
public:
/*constexpr*/ unique_ptr() /*noexcept*/ : data() {
static_assert(!is_pointer<deleter_type>::value, "Deleter is nullptr function pointer!");
static_assert(!std::is_pointer<deleter_type>::value, "Deleter nullptr function pointer!");
}
/*constexpr*/ unique_ptr(std::nullptr_t) /*noexcept*/ : unique_ptr() { }
explicit unique_ptr(pointer ptr) /*noexcept*/ : data(ptr, deleter_type()) {
static_assert(!is_pointer<deleter_type>::value, "Deleter is nullptr function pointer!");
static_assert(!std::is_pointer<deleter_type>::value, "Deleter nullptr function pointer!");
}
unique_ptr(pointer ptr,
conditional_t<is_reference<deleter_type>::value, deleter_type,const deleter_type&> d)
conditional_t<std::is_reference<deleter_type>::value,
deleter_type, const deleter_type&> d)
/*noexcept*/ : data(ptr, d)
{}
unique_ptr(pointer ptr, remove_reference_t<deleter_type>&& d) /*noexcept*/
: data(std::move(ptr), std::move(d))
{
static_assert(!is_reference<deleter_type>::value,
static_assert(!std::is_reference<deleter_type>::value,
"Binding an rvalue reference deleter as an lvalue reference deleter is not allowed.");
}
@ -122,8 +123,10 @@ public:
template <typename U, typename ThatD, typename = enable_if_t<
is_convertible<typename unique_ptr<U, ThatD>::pointer, pointer>::value &&
!is_array<U>::value &&
conditional_t<is_reference<D>::value, is_same<ThatD, D>, is_convertible<ThatD, D>>::value>>
!std::is_array<U>::value &&
conditional_t<std::is_reference<D>::value,
std::is_same<ThatD, D>,
is_convertible<ThatD, D>>::value>>
unique_ptr(unique_ptr<U, ThatD>&& that) /*noexcept*/
: data(that.release(), std::forward<ThatD>(that.get_deleter()))
{}
@ -144,7 +147,7 @@ public:
template <typename U, typename ThatD> enable_if_t<
is_convertible<typename unique_ptr<U, ThatD>::pointer, pointer>::value &&
!is_array<U>::value,
!std::is_array<U>::value,
unique_ptr&> operator=(unique_ptr<U, ThatD>&& that) /*noexcept*/ {
reset(that.release());
get_deleter() = std::forward<ThatD>(that.get_deleter());
@ -264,24 +267,25 @@ private:
public:
/*constexpr*/ unique_ptr() /*noexcept*/ : data() {
static_assert(!is_pointer<deleter_type>::value, "Deleter is nullptr function pointer!");
static_assert(!std::is_pointer<deleter_type>::value, "Deleter nullptr function pointer!");
}
/*constexpr*/ unique_ptr(std::nullptr_t) /*noexcept*/ : unique_ptr() { }
explicit unique_ptr(pointer ptr) /*noexcept*/ : data(ptr, deleter_type()) {
static_assert(!is_pointer<deleter_type>::value, "Deleter is nullptr function pointer!");
static_assert(!std::is_pointer<deleter_type>::value, "Deleter nullptr function pointer!");
}
unique_ptr(pointer ptr,
conditional_t<is_reference<deleter_type>::value, deleter_type,const deleter_type&> d)
conditional_t<std::is_reference<deleter_type>::value,
deleter_type, const deleter_type&> d)
/*noexcept*/ : data(ptr, d)
{}
unique_ptr(pointer ptr, remove_reference_t<deleter_type>&& d) /*noexcept*/
: data(std::move(ptr), std::move(d))
{
static_assert(!is_reference<deleter_type>::value,
static_assert(!std::is_reference<deleter_type>::value,
"Binding an rvalue reference deleter as an lvalue reference deleter is not allowed.");
}