| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 * | 6 * |
| 7 * | 7 * |
| 8 * This header provides some of the helpers (like std::enable_if_t) which will | 8 * This header provides some of the helpers (like std::enable_if_t) which will |
| 9 * become available with C++14 in the type_traits header (in the skstd | 9 * become available with C++14 in the type_traits header (in the skstd |
| 10 * namespace). This header also provides several Skia specific additions such | 10 * namespace). This header also provides several Skia specific additions such |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 template <bool B, typename T, typename F> using conditional_t = typename std::co
nditional<B, T, F>::type; | 28 template <bool B, typename T, typename F> using conditional_t = typename std::co
nditional<B, T, F>::type; |
| 29 template <bool B, typename T = void> using enable_if_t = typename std::enable_if
<B, T>::type; | 29 template <bool B, typename T = void> using enable_if_t = typename std::enable_if
<B, T>::type; |
| 30 | 30 |
| 31 template <typename T> using remove_const_t = typename std::remove_const<T>::type
; | 31 template <typename T> using remove_const_t = typename std::remove_const<T>::type
; |
| 32 template <typename T> using remove_volatile_t = typename std::remove_volatile<T>
::type; | 32 template <typename T> using remove_volatile_t = typename std::remove_volatile<T>
::type; |
| 33 template <typename T> using remove_cv_t = typename std::remove_cv<T>::type; | 33 template <typename T> using remove_cv_t = typename std::remove_cv<T>::type; |
| 34 template <typename T> using remove_pointer_t = typename std::remove_pointer<T>::
type; | 34 template <typename T> using remove_pointer_t = typename std::remove_pointer<T>::
type; |
| 35 template <typename T> using remove_reference_t = typename std::remove_reference<
T>::type; | 35 template <typename T> using remove_reference_t = typename std::remove_reference<
T>::type; |
| 36 template <typename T> using remove_extent_t = typename std::remove_extent<T>::ty
pe; | 36 template <typename T> using remove_extent_t = typename std::remove_extent<T>::ty
pe; |
| 37 | 37 |
| 38 template <typename T> struct is_class_detector { | |
| 39 using yes_type = uint8_t; | |
| 40 using no_type = uint16_t; | |
| 41 template <typename U> static yes_type clazz(int U::*); | |
| 42 template <typename U> static no_type clazz(...); | |
| 43 static const/*expr*/ bool value = sizeof(clazz<T>(0)) == sizeof(yes_type) && | |
| 44 !std::is_union<T>::value; | |
| 45 }; | |
| 46 template <typename T> struct is_class : bool_constant<is_class_detector<T>::valu
e> {}; | |
| 47 | |
| 48 template <typename T, bool = is_class<T>::value> struct is_empty_detector { | |
| 49 struct Derived : public T { char unused; }; | |
| 50 static const/*expr*/ bool value = sizeof(Derived) == sizeof(char); | |
| 51 }; | |
| 52 template <typename T> struct is_empty_detector<T, false> { | |
| 53 static const/*expr*/ bool value = false; | |
| 54 }; | |
| 55 template <typename T> struct is_empty : bool_constant<is_empty_detector<T>::valu
e> {}; | |
| 56 | |
| 57 // template<typename R, typename... Args> struct is_function< | 38 // template<typename R, typename... Args> struct is_function< |
| 58 // R [calling-convention] (Args...[, ...]) [const] [volatile] [&|&&]> : std:
:true_type {}; | 39 // R [calling-convention] (Args...[, ...]) [const] [volatile] [&|&&]> : std:
:true_type {}; |
| 59 // The cv and ref-qualified versions are strange types we're currently avoiding,
so not supported. | 40 // The cv and ref-qualified versions are strange types we're currently avoiding,
so not supported. |
| 41 // These aren't supported in msvc either until vs2015u2. |
| 60 // On all platforms, variadic functions only exist in the c calling convention. | 42 // On all platforms, variadic functions only exist in the c calling convention. |
| 43 // mcvc 2013 introduced __vectorcall, but it wan't until 2015 that it was added
to is_function. |
| 61 template <typename> struct is_function : std::false_type {}; | 44 template <typename> struct is_function : std::false_type {}; |
| 62 #if !defined(SK_BUILD_FOR_WIN) | 45 #if !defined(SK_BUILD_FOR_WIN) |
| 63 template <typename R, typename... Args> struct is_function<R(Args...)> : std::tr
ue_type {}; | 46 template <typename R, typename... Args> struct is_function<R(Args...)> : std::tr
ue_type {}; |
| 64 #else | 47 #else |
| 65 #if defined(_M_IX86) | 48 #if defined(_M_IX86) |
| 66 template <typename R, typename... Args> struct is_function<R __cdecl (Args...)>
: std::true_type {}; | 49 template <typename R, typename... Args> struct is_function<R __cdecl (Args...)>
: std::true_type {}; |
| 67 template <typename R, typename... Args> struct is_function<R __stdcall (Args...)
> : std::true_type {}; | 50 template <typename R, typename... Args> struct is_function<R __stdcall (Args...)
> : std::true_type {}; |
| 68 template <typename R, typename... Args> struct is_function<R __fastcall (Args...
)> : std::true_type {}; | 51 template <typename R, typename... Args> struct is_function<R __fastcall (Args...
)> : std::true_type {}; |
| 69 #if SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSE2 | 52 #if SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSE2 |
| 70 template <typename R, typename... Args> struct is_function<R __vectorcall (Args.
..)> : std::true_type {}; | 53 template <typename R, typename... Args> struct is_function<R __vectorcall (Args.
..)> : std::true_type {}; |
| 71 #endif | 54 #endif |
| 72 #else | 55 #else |
| 73 template <typename R, typename... Args> struct is_function<R __cdecl (Args...)>
: std::true_type {}; | 56 template <typename R, typename... Args> struct is_function<R __cdecl (Args...)>
: std::true_type {}; |
| 74 template <typename R, typename... Args> struct is_function<R __vectorcall (Args.
..)> : std::true_type {}; | 57 template <typename R, typename... Args> struct is_function<R __vectorcall (Args.
..)> : std::true_type {}; |
| 75 #endif | 58 #endif |
| 76 #endif | 59 #endif |
| 77 template <typename R, typename... Args> struct is_function<R(Args..., ...)> : st
d::true_type {}; | 60 template <typename R, typename... Args> struct is_function<R(Args..., ...)> : st
d::true_type {}; |
| 78 | 61 |
| 79 template <typename T> using add_const_t = typename std::add_const<T>::type; | 62 template <typename T> using add_const_t = typename std::add_const<T>::type; |
| 80 template <typename T> using add_volatile_t = typename std::add_volatile<T>::type
; | 63 template <typename T> using add_volatile_t = typename std::add_volatile<T>::type
; |
| 81 template <typename T> using add_cv_t = typename std::add_cv<T>::type; | 64 template <typename T> using add_cv_t = typename std::add_cv<T>::type; |
| 82 template <typename T> using add_pointer_t = typename std::add_pointer<T>::type; | 65 template <typename T> using add_pointer_t = typename std::add_pointer<T>::type; |
| 83 | 66 template <typename T> using add_lvalue_reference_t = typename std::add_lvalue_re
ference<T>::type; |
| 84 template <typename T, bool=std::is_void<T>::value> struct add_lvalue_reference_i
nit { using type = T; }; | |
| 85 template <typename T> struct add_lvalue_reference_init<T, false> { using type =
T&; }; | |
| 86 template <typename T> struct add_lvalue_reference : add_lvalue_reference_init<T>
{}; | |
| 87 template <typename T> using add_lvalue_reference_t = typename add_lvalue_referen
ce<T>::type; | |
| 88 | |
| 89 template <typename T, bool=std::is_void<T>::value> struct add_rvalue_reference_i
nit { using type = T; }; | |
| 90 template <typename T> struct add_rvalue_reference_init<T, false> { using type =
T&&; }; | |
| 91 template <typename T> struct add_rvalue_reference : add_rvalue_reference_init<T>
{}; | |
| 92 template <typename T> using add_rvalue_reference_t = typename add_rvalue_referen
ce<T>::type; | |
| 93 | 67 |
| 94 template <typename S, typename D, | 68 template <typename S, typename D, |
| 95 bool=std::is_void<S>::value || is_function<D>::value || std::is_array<
D>::value> | 69 bool=std::is_void<S>::value || is_function<D>::value || std::is_array<
D>::value> |
| 96 struct is_convertible_detector { | 70 struct is_convertible_detector { |
| 97 static const/*expr*/ bool value = std::is_void<D>::value; | 71 static const/*expr*/ bool value = std::is_void<D>::value; |
| 98 }; | 72 }; |
| 99 template <typename S, typename D> struct is_convertible_detector<S, D, false> { | 73 template <typename S, typename D> struct is_convertible_detector<S, D, false> { |
| 100 using yes_type = uint8_t; | 74 using yes_type = uint8_t; |
| 101 using no_type = uint16_t; | 75 using no_type = uint16_t; |
| 102 | 76 |
| 103 template <typename To> static void param_convertable_to(To); | 77 template <typename To> static void param_convertable_to(To); |
| 104 | 78 |
| 105 template <typename From, typename To> | 79 template <typename From, typename To> |
| 106 static decltype(param_convertable_to<To>(std::declval<From>()), yes_type())
convertible(int); | 80 static decltype(param_convertable_to<To>(std::declval<From>()), yes_type())
convertible(int); |
| 107 | 81 |
| 108 template <typename, typename> static no_type convertible(...); | 82 template <typename, typename> static no_type convertible(...); |
| 109 | 83 |
| 110 static const/*expr*/ bool value = sizeof(convertible<S, D>(0)) == sizeof(yes
_type); | 84 static const/*expr*/ bool value = sizeof(convertible<S, D>(0)) == sizeof(yes
_type); |
| 111 }; | 85 }; |
| 86 // std::is_convertable is known to be broken (not work with incomplete types) in
Android clang NDK. |
| 87 // This is currently what prevents us from using std::unique_ptr. |
| 112 template<typename S, typename D> struct is_convertible | 88 template<typename S, typename D> struct is_convertible |
| 113 : bool_constant<is_convertible_detector<S, D>::value> {}; | 89 : bool_constant<is_convertible_detector<S, D>::value> {}; |
| 114 | 90 |
| 115 template <typename T> struct decay { | |
| 116 using U = remove_reference_t<T>; | |
| 117 using type = conditional_t<std::is_array<U>::value, | |
| 118 remove_extent_t<U>*, | |
| 119 conditional_t<is_function<U>::value, | |
| 120 add_pointer_t<U>, | |
| 121 remove_cv_t<U>>>; | |
| 122 }; | |
| 123 template <typename T> using decay_t = typename decay<T>::type; | |
| 124 | |
| 125 } // namespace skstd | 91 } // namespace skstd |
| 126 | 92 |
| 127 // The sknonstd namespace contains things we would like to be proposed and feel
std-ish. | 93 // The sknonstd namespace contains things we would like to be proposed and feel
std-ish. |
| 128 namespace sknonstd { | 94 namespace sknonstd { |
| 129 | 95 |
| 130 // The name 'copy' here is fraught with peril. In this case it means 'append', n
ot 'overwrite'. | 96 // The name 'copy' here is fraught with peril. In this case it means 'append', n
ot 'overwrite'. |
| 131 // Alternate proposed names are 'propagate', 'augment', or 'append' (and 'add',
but already taken). | 97 // Alternate proposed names are 'propagate', 'augment', or 'append' (and 'add',
but already taken). |
| 132 // std::experimental::propagate_const already exists for other purposes in TSv2. | 98 // std::experimental::propagate_const already exists for other purposes in TSv2. |
| 133 // These also follow the <dest, source> pattern used by boost. | 99 // These also follow the <dest, source> pattern used by boost. |
| 134 template <typename D, typename S> struct copy_const { | 100 template <typename D, typename S> struct copy_const { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 155 template <typename D, typename S> using same_volatile_t = typename same_volatile
<D, S>::type; | 121 template <typename D, typename S> using same_volatile_t = typename same_volatile
<D, S>::type; |
| 156 template <typename D, typename S> using same_cv = copy_cv<skstd::remove_cv_t<D>,
S>; | 122 template <typename D, typename S> using same_cv = copy_cv<skstd::remove_cv_t<D>,
S>; |
| 157 template <typename D, typename S> using same_cv_t = typename same_cv<D, S>::type
; | 123 template <typename D, typename S> using same_cv_t = typename same_cv<D, S>::type
; |
| 158 | 124 |
| 159 } // namespace sknonstd | 125 } // namespace sknonstd |
| 160 | 126 |
| 161 // Just a pithier wrapper for enable_if_t. | 127 // Just a pithier wrapper for enable_if_t. |
| 162 #define SK_WHEN(condition, T) skstd::enable_if_t<!!(condition), T> | 128 #define SK_WHEN(condition, T) skstd::enable_if_t<!!(condition), T> |
| 163 | 129 |
| 164 #endif | 130 #endif |
| OLD | NEW |