Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(962)

Side by Side Diff: include/private/SkTLogic.h

Issue 1555153002: Add skstd::remove_pointer_t and use it. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | src/ports/SkFontMgr_android_parser.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 (std::integral_constant) and 8 * This header provides some of the helpers (std::integral_constant) and
9 * type transformations (std::conditional) which will become available with 9 * type transformations (std::conditional) which will become available with
10 * C++11 in the type_traits header. 10 * C++11 in the type_traits header.
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 template <typename T> using remove_volatile_t = typename remove_volatile<T>::typ e; 52 template <typename T> using remove_volatile_t = typename remove_volatile<T>::typ e;
53 53
54 template <typename T> struct remove_cv { using type = remove_volatile_t<remove_c onst_t<T>>; }; 54 template <typename T> struct remove_cv { using type = remove_volatile_t<remove_c onst_t<T>>; };
55 template <typename T> using remove_cv_t = typename remove_cv<T>::type; 55 template <typename T> using remove_cv_t = typename remove_cv<T>::type;
56 56
57 template <typename T> struct remove_reference { using type = T; }; 57 template <typename T> struct remove_reference { using type = T; };
58 template <typename T> struct remove_reference<T&> { using type = T; }; 58 template <typename T> struct remove_reference<T&> { using type = T; };
59 template <typename T> struct remove_reference<T&&> { using type = T; }; 59 template <typename T> struct remove_reference<T&&> { using type = T; };
60 template <typename T> using remove_reference_t = typename remove_reference<T>::t ype; 60 template <typename T> using remove_reference_t = typename remove_reference<T>::t ype;
61 61
62 template <typename T, typename T_cv> struct remove_pointer_no_cv { using type = T; };
mtklein 2016/01/05 02:41:00 Can't we use std::remove_ptr, then build skstd::re
bungeman-skia 2016/01/06 16:25:16 Yes, but doing so would mean fixing all the other
63 template <typename T, typename T_cv> struct remove_pointer_no_cv<T, T_cv*> { usi ng type = T_cv; };
64 template <typename T> struct remove_pointer : remove_pointer_no_cv<T, remove_cv_ t<T>> {};
65 template <typename T> using remove_pointer_t = typename remove_pointer<T>::type;
66
62 template <typename T> struct remove_extent { using type = T; }; 67 template <typename T> struct remove_extent { using type = T; };
63 template <typename T> struct remove_extent<T[]> { using type = T; }; 68 template <typename T> struct remove_extent<T[]> { using type = T; };
64 template <typename T, size_t N> struct remove_extent<T[N]> { using type = T;}; 69 template <typename T, size_t N> struct remove_extent<T[N]> { using type = T;};
65 template <typename T> using remove_extent_t = typename remove_extent<T>::type; 70 template <typename T> using remove_extent_t = typename remove_extent<T>::type;
66 71
67 template <typename T, typename U> struct is_same : false_type {}; 72 template <typename T, typename U> struct is_same : false_type {};
68 template <typename T> struct is_same<T, T> : true_type {}; 73 template <typename T> struct is_same<T, T> : true_type {};
69 74
70 template <typename T> struct is_void : is_same<void, remove_cv_t<T>> {}; 75 template <typename T> struct is_void : is_same<void, remove_cv_t<T>> {};
71 76
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 template <typename T> struct is_empty : bool_constant<is_empty_detector<T>::valu e> {}; 113 template <typename T> struct is_empty : bool_constant<is_empty_detector<T>::valu e> {};
109 114
110 template <typename T> struct is_array : false_type {}; 115 template <typename T> struct is_array : false_type {};
111 template <typename T> struct is_array<T[]> : true_type {}; 116 template <typename T> struct is_array<T[]> : true_type {};
112 template <typename T, size_t N> struct is_array<T[N]> : true_type {}; 117 template <typename T, size_t N> struct is_array<T[N]> : true_type {};
113 118
114 // template<typename R, typename... Args> struct is_function< 119 // template<typename R, typename... Args> struct is_function<
115 // R [calling-convention] (Args...[, ...]) [const] [volatile] [&|&&]> : true _type {}; 120 // R [calling-convention] (Args...[, ...]) [const] [volatile] [&|&&]> : true _type {};
116 // The cv and ref-qualified versions are strange types we're currently avoiding, so not supported. 121 // The cv and ref-qualified versions are strange types we're currently avoiding, so not supported.
117 // On all platforms, variadic functions only exist in the c calling convention. 122 // On all platforms, variadic functions only exist in the c calling convention.
118 template <typename> struct is_function : false_type { }; 123 template <typename> struct is_function : false_type {};
119 #if !defined(SK_BUILD_FOR_WIN) 124 #if !defined(SK_BUILD_FOR_WIN)
120 template <typename R, typename... Args> struct is_function<R(Args...)> : true_ty pe {}; 125 template <typename R, typename... Args> struct is_function<R(Args...)> : true_ty pe {};
121 #else 126 #else
122 #if defined(_M_IX86) 127 #if defined(_M_IX86)
123 template <typename R, typename... Args> struct is_function<R __cdecl (Args...)> : true_type {}; 128 template <typename R, typename... Args> struct is_function<R __cdecl (Args...)> : true_type {};
124 template <typename R, typename... Args> struct is_function<R __stdcall (Args...) > : true_type {}; 129 template <typename R, typename... Args> struct is_function<R __stdcall (Args...) > : true_type {};
125 template <typename R, typename... Args> struct is_function<R __fastcall (Args... )> : true_type {}; 130 template <typename R, typename... Args> struct is_function<R __fastcall (Args... )> : true_type {};
126 #if SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSE2 131 #if SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSE2
127 template <typename R, typename... Args> struct is_function<R __vectorcall (Args. ..)> : true_type {}; 132 template <typename R, typename... Args> struct is_function<R __vectorcall (Args. ..)> : true_type {};
128 #endif 133 #endif
(...skipping 11 matching lines...) Expand all
140 template <typename T> using add_volatile_t = typename add_volatile<T>::type; 145 template <typename T> using add_volatile_t = typename add_volatile<T>::type;
141 146
142 template <typename T> struct add_cv { using type = add_volatile_t<add_const_t<T> >; }; 147 template <typename T> struct add_cv { using type = add_volatile_t<add_const_t<T> >; };
143 template <typename T> using add_cv_t = typename add_cv<T>::type; 148 template <typename T> using add_cv_t = typename add_cv<T>::type;
144 149
145 template <typename T> struct add_pointer { using type = remove_reference_t<T>*; }; 150 template <typename T> struct add_pointer { using type = remove_reference_t<T>*; };
146 template <typename T> using add_pointer_t = typename add_pointer<T>::type; 151 template <typename T> using add_pointer_t = typename add_pointer<T>::type;
147 152
148 template <typename T, bool=is_void<T>::value> struct add_lvalue_reference_init { using type = T; }; 153 template <typename T, bool=is_void<T>::value> struct add_lvalue_reference_init { using type = T; };
149 template <typename T> struct add_lvalue_reference_init<T, false> { using type = T&; }; 154 template <typename T> struct add_lvalue_reference_init<T, false> { using type = T&; };
150 template <typename T> struct add_lvalue_reference : add_lvalue_reference_init<T> { }; 155 template <typename T> struct add_lvalue_reference : add_lvalue_reference_init<T> {};
151 template <typename T> using add_lvalue_reference_t = typename add_lvalue_referen ce<T>::type; 156 template <typename T> using add_lvalue_reference_t = typename add_lvalue_referen ce<T>::type;
152 157
153 template <typename T, bool=is_void<T>::value> struct add_rvalue_reference_init { using type = T; }; 158 template <typename T, bool=is_void<T>::value> struct add_rvalue_reference_init { using type = T; };
154 template <typename T> struct add_rvalue_reference_init<T, false> { using type = T&&; }; 159 template <typename T> struct add_rvalue_reference_init<T, false> { using type = T&&; };
155 template <typename T> struct add_rvalue_reference : add_rvalue_reference_init<T> {}; 160 template <typename T> struct add_rvalue_reference : add_rvalue_reference_init<T> {};
156 template <typename T> using add_rvalue_reference_t = typename add_rvalue_referen ce<T>::type; 161 template <typename T> using add_rvalue_reference_t = typename add_rvalue_referen ce<T>::type;
157 162
158 /* This is 'just' a forward declaration. */ 163 /* This is 'just' a forward declaration. */
159 template <typename T> add_rvalue_reference_t<T> declval() /*noexcept*/; 164 template <typename T> add_rvalue_reference_t<T> declval() /*noexcept*/;
160 165
161 template <typename S, typename D, bool=is_void<S>::value||is_function<D>::value| |is_array<D>::value> 166 template <typename S, typename D, bool=is_void<S>::value||is_function<D>::value| |is_array<D>::value>
162 struct is_convertible_detector { 167 struct is_convertible_detector {
163 static const/*expr*/ bool value = is_void<D>::value; 168 static const/*expr*/ bool value = is_void<D>::value;
164 }; 169 };
165 template <typename S, typename D> struct is_convertible_detector<S, D, false> { 170 template <typename S, typename D> struct is_convertible_detector<S, D, false> {
166 using yes_type = uint8_t; 171 using yes_type = uint8_t;
167 using no_type = uint16_t; 172 using no_type = uint16_t;
168 173
169 template <typename To> static void param_convertable_to(To); 174 template <typename To> static void param_convertable_to(To);
170 175
171 template <typename From, typename To> 176 template <typename From, typename To>
172 static decltype(param_convertable_to<To>(declval<From>()), yes_type()) conve rtible(int); 177 static decltype(param_convertable_to<To>(declval<From>()), yes_type()) conve rtible(int);
173 178
174 template <typename, typename> static no_type convertible(...); 179 template <typename, typename> static no_type convertible(...);
175 180
176 static const/*expr*/ bool value = sizeof(convertible<S, D>(0)) == sizeof(yes _type); 181 static const/*expr*/ bool value = sizeof(convertible<S, D>(0)) == sizeof(yes _type);
177 }; 182 };
178 template<typename S, typename D> struct is_convertible 183 template<typename S, typename D> struct is_convertible
179 : bool_constant<is_convertible_detector<S, D>::value> { }; 184 : bool_constant<is_convertible_detector<S, D>::value> {};
180 185
181 template <typename T> struct decay { 186 template <typename T> struct decay {
182 using U = remove_reference_t<T>; 187 using U = remove_reference_t<T>;
183 using type = conditional_t<is_array<U>::value, 188 using type = conditional_t<is_array<U>::value,
184 remove_extent_t<U>*, 189 remove_extent_t<U>*,
185 conditional_t<is_function<U>::value, add_pointer_t<U>, remove_cv_t<U>>>; 190 conditional_t<is_function<U>::value, add_pointer_t<U>, remove_cv_t<U>>>;
186 }; 191 };
187 template <typename T> using decay_t = typename decay<T>::type; 192 template <typename T> using decay_t = typename decay<T>::type;
188 193
189 } // namespace skstd 194 } // namespace skstd
(...skipping 29 matching lines...) Expand all
219 template <typename D, typename S> using same_volatile_t = typename same_volatile <D, S>::type; 224 template <typename D, typename S> using same_volatile_t = typename same_volatile <D, S>::type;
220 template <typename D, typename S> using same_cv = copy_cv<skstd::remove_cv_t<D>, S>; 225 template <typename D, typename S> using same_cv = copy_cv<skstd::remove_cv_t<D>, S>;
221 template <typename D, typename S> using same_cv_t = typename same_cv<D, S>::type ; 226 template <typename D, typename S> using same_cv_t = typename same_cv<D, S>::type ;
222 227
223 } // namespace sknonstd 228 } // namespace sknonstd
224 229
225 // Just a pithier wrapper for enable_if_t. 230 // Just a pithier wrapper for enable_if_t.
226 #define SK_WHEN(condition, T) skstd::enable_if_t<!!(condition), T> 231 #define SK_WHEN(condition, T) skstd::enable_if_t<!!(condition), T>
227 232
228 #endif 233 #endif
OLDNEW
« no previous file with comments | « no previous file | src/ports/SkFontMgr_android_parser.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698