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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 __GLIBCXX__ == SK_GLIBCXX_4_5_4 || \ | 76 __GLIBCXX__ == SK_GLIBCXX_4_5_4 || \ |
77 __GLIBCXX__ == SK_GLIBCXX_4_6_4) | 77 __GLIBCXX__ == SK_GLIBCXX_4_6_4) |
78 template <typename T> struct underlying_type { | 78 template <typename T> struct underlying_type { |
79 using type = __underlying_type(T); | 79 using type = __underlying_type(T); |
80 }; | 80 }; |
81 #else | 81 #else |
82 template <typename T> using underlying_type = std::underlying_type<T>; | 82 template <typename T> using underlying_type = std::underlying_type<T>; |
83 #endif | 83 #endif |
84 template <typename T> using underlying_type_t = typename skstd::underlying_type<
T>::type; | 84 template <typename T> using underlying_type_t = typename skstd::underlying_type<
T>::type; |
85 | 85 |
86 template <typename S, typename D, | |
87 bool=std::is_void<S>::value || is_function<D>::value || std::is_array<
D>::value> | |
88 struct is_convertible_detector { | |
89 static const/*expr*/ bool value = std::is_void<D>::value; | |
90 }; | |
91 template <typename S, typename D> struct is_convertible_detector<S, D, false> { | |
92 using yes_type = uint8_t; | |
93 using no_type = uint16_t; | |
94 | |
95 template <typename To> static void param_convertable_to(To); | |
96 | |
97 template <typename From, typename To> | |
98 static decltype(param_convertable_to<To>(std::declval<From>()), yes_type())
convertible(int); | |
99 | |
100 template <typename, typename> static no_type convertible(...); | |
101 | |
102 static const/*expr*/ bool value = sizeof(convertible<S, D>(0)) == sizeof(yes
_type); | |
103 }; | |
104 // std::is_convertable is known to be broken (not work with incomplete types) in
Android clang NDK. | |
105 // This is currently what prevents us from using std::unique_ptr. | |
106 template<typename S, typename D> struct is_convertible | |
107 : bool_constant<is_convertible_detector<S, D>::value> {}; | |
108 | |
109 } // namespace skstd | 86 } // namespace skstd |
110 | 87 |
111 // The sknonstd namespace contains things we would like to be proposed and feel
std-ish. | 88 // The sknonstd namespace contains things we would like to be proposed and feel
std-ish. |
112 namespace sknonstd { | 89 namespace sknonstd { |
113 | 90 |
114 // The name 'copy' here is fraught with peril. In this case it means 'append', n
ot 'overwrite'. | 91 // The name 'copy' here is fraught with peril. In this case it means 'append', n
ot 'overwrite'. |
115 // Alternate proposed names are 'propagate', 'augment', or 'append' (and 'add',
but already taken). | 92 // Alternate proposed names are 'propagate', 'augment', or 'append' (and 'add',
but already taken). |
116 // std::experimental::propagate_const already exists for other purposes in TSv2. | 93 // std::experimental::propagate_const already exists for other purposes in TSv2. |
117 // These also follow the <dest, source> pattern used by boost. | 94 // These also follow the <dest, source> pattern used by boost. |
118 template <typename D, typename S> struct copy_const { | 95 template <typename D, typename S> struct copy_const { |
(...skipping 20 matching lines...) Expand all Loading... |
139 template <typename D, typename S> using same_volatile_t = typename same_volatile
<D, S>::type; | 116 template <typename D, typename S> using same_volatile_t = typename same_volatile
<D, S>::type; |
140 template <typename D, typename S> using same_cv = copy_cv<skstd::remove_cv_t<D>,
S>; | 117 template <typename D, typename S> using same_cv = copy_cv<skstd::remove_cv_t<D>,
S>; |
141 template <typename D, typename S> using same_cv_t = typename same_cv<D, S>::type
; | 118 template <typename D, typename S> using same_cv_t = typename same_cv<D, S>::type
; |
142 | 119 |
143 } // namespace sknonstd | 120 } // namespace sknonstd |
144 | 121 |
145 // Just a pithier wrapper for enable_if_t. | 122 // Just a pithier wrapper for enable_if_t. |
146 #define SK_WHEN(condition, T) skstd::enable_if_t<!!(condition), T> | 123 #define SK_WHEN(condition, T) skstd::enable_if_t<!!(condition), T> |
147 | 124 |
148 #endif | 125 #endif |
OLD | NEW |