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 |
11 * as SK_WHEN and the sknonstd namespace. | 11 * as SK_WHEN and the sknonstd namespace. |
12 */ | 12 */ |
13 | 13 |
14 #ifndef SkTLogic_DEFINED | 14 #ifndef SkTLogic_DEFINED |
15 #define SkTLogic_DEFINED | 15 #define SkTLogic_DEFINED |
16 | 16 |
17 #include "SkTypes.h" | |
18 | |
19 #include <stddef.h> | 17 #include <stddef.h> |
20 #include <stdint.h> | 18 #include <stdint.h> |
21 #include <type_traits> | 19 #include <type_traits> |
22 #include <utility> | 20 #include <utility> |
23 | 21 |
24 namespace skstd { | 22 namespace skstd { |
25 | 23 |
26 template <bool B> using bool_constant = std::integral_constant<bool, B>; | 24 template <bool B> using bool_constant = std::integral_constant<bool, B>; |
27 | 25 |
28 template <bool B, typename T, typename F> using conditional_t = typename std::co
nditional<B, T, F>::type; | 26 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; | 27 template <bool B, typename T = void> using enable_if_t = typename std::enable_if
<B, T>::type; |
30 | 28 |
31 template <typename T> using remove_const_t = typename std::remove_const<T>::type
; | 29 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; | 30 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; | 31 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; | 32 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; | 33 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; | 34 template <typename T> using remove_extent_t = typename std::remove_extent<T>::ty
pe; |
37 | 35 |
38 // template<typename R, typename... Args> struct is_function< | 36 // template<typename R, typename... Args> struct is_function< |
39 // R [calling-convention] (Args...[, ...]) [const] [volatile] [&|&&]> : std:
:true_type {}; | 37 // R [calling-convention] (Args...[, ...]) [const] [volatile] [&|&&]> : std:
:true_type {}; |
40 // The cv and ref-qualified versions are strange types we're currently avoiding,
so not supported. | 38 // 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. | 39 // These aren't supported in msvc either until vs2015u2. |
42 // On all platforms, variadic functions only exist in the c calling convention. | 40 // 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. | 41 // mcvc 2013 introduced __vectorcall, but it wan't until 2015 that it was added
to is_function. |
44 template <typename> struct is_function : std::false_type {}; | 42 template <typename> struct is_function : std::false_type {}; |
45 #if !defined(SK_BUILD_FOR_WIN) | 43 #if !defined(WIN32) |
46 template <typename R, typename... Args> struct is_function<R(Args...)> : std::tr
ue_type {}; | 44 template <typename R, typename... Args> struct is_function<R(Args...)> : std::tr
ue_type {}; |
47 #else | 45 #else |
48 template <typename R, typename... Args> struct is_function<R __cdecl (Args...)>
: std::true_type {}; | 46 template <typename R, typename... Args> struct is_function<R __cdecl (Args...)>
: std::true_type {}; |
49 #if defined(_M_IX86) | 47 #if defined(_M_IX86) |
50 template <typename R, typename... Args> struct is_function<R __stdcall (Args...)
> : std::true_type {}; | 48 template <typename R, typename... Args> struct is_function<R __stdcall (Args...)
> : std::true_type {}; |
51 template <typename R, typename... Args> struct is_function<R __fastcall (Args...
)> : std::true_type {}; | 49 template <typename R, typename... Args> struct is_function<R __fastcall (Args...
)> : std::true_type {}; |
52 #endif | 50 #endif |
53 #if defined(_MSC_VER) && SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSE2 | 51 #if defined(_MSC_VER) && (_M_IX86_FP >= 2 || defined(_M_AMD64) || defined(_M_X64
)) |
54 template <typename R, typename... Args> struct is_function<R __vectorcall (Args.
..)> : std::true_type {}; | 52 template <typename R, typename... Args> struct is_function<R __vectorcall (Args.
..)> : std::true_type {}; |
55 #endif | 53 #endif |
56 #endif | 54 #endif |
57 template <typename R, typename... Args> struct is_function<R(Args..., ...)> : st
d::true_type {}; | 55 template <typename R, typename... Args> struct is_function<R(Args..., ...)> : st
d::true_type {}; |
58 | 56 |
59 template <typename T> using add_const_t = typename std::add_const<T>::type; | 57 template <typename T> using add_const_t = typename std::add_const<T>::type; |
60 template <typename T> using add_volatile_t = typename std::add_volatile<T>::type
; | 58 template <typename T> using add_volatile_t = typename std::add_volatile<T>::type
; |
61 template <typename T> using add_cv_t = typename std::add_cv<T>::type; | 59 template <typename T> using add_cv_t = typename std::add_cv<T>::type; |
62 template <typename T> using add_pointer_t = typename std::add_pointer<T>::type; | 60 template <typename T> using add_pointer_t = typename std::add_pointer<T>::type; |
63 template <typename T> using add_lvalue_reference_t = typename std::add_lvalue_re
ference<T>::type; | 61 template <typename T> using add_lvalue_reference_t = typename std::add_lvalue_re
ference<T>::type; |
64 | 62 |
65 template <typename... T> using common_type_t = typename std::common_type<T...>::
type; | 63 template <typename... T> using common_type_t = typename std::common_type<T...>::
type; |
66 | 64 |
| 65 // Chromium currently requires gcc 4.8.2 or a recent clang compiler, but uses li
bstdc++4.6.4. |
| 66 // Note that Precise actually uses libstdc++4.6.3. |
| 67 // Unfortunately, libstdc++ STL before libstdc++4.7 do not define std::underlyin
g_type. |
| 68 // Newer gcc and clang compilers have __underlying_type which does not depend on
runtime support. |
| 69 // See https://gcc.gnu.org/onlinedocs/libstdc++/manual/abi.html for __GLIBCXX__
values. |
| 70 // Unfortunately __GLIBCXX__ is a date, but no updates to versions before 4.7 ar
e now anticipated. |
| 71 #define SK_GLIBCXX_4_7_0 20120322 |
| 72 // Updates to versions before 4.7 but released after 4.7 was released. |
| 73 #define SK_GLIBCXX_4_5_4 20120702 |
| 74 #define SK_GLIBCXX_4_6_4 20121127 |
| 75 #if defined(__GLIBCXX__) && (__GLIBCXX__ < SK_GLIBCXX_4_7_0 || \ |
| 76 __GLIBCXX__ == SK_GLIBCXX_4_5_4 || \ |
| 77 __GLIBCXX__ == SK_GLIBCXX_4_6_4) |
| 78 template <typename T> struct underlying_type { |
| 79 using type = __underlying_type(T); |
| 80 }; |
| 81 #else |
| 82 template <typename T> using underlying_type = std::underlying_type<T>; |
| 83 #endif |
| 84 template <typename T> using underlying_type_t = typename skstd::underlying_type<
T>::type; |
| 85 |
67 template <typename S, typename D, | 86 template <typename S, typename D, |
68 bool=std::is_void<S>::value || is_function<D>::value || std::is_array<
D>::value> | 87 bool=std::is_void<S>::value || is_function<D>::value || std::is_array<
D>::value> |
69 struct is_convertible_detector { | 88 struct is_convertible_detector { |
70 static const/*expr*/ bool value = std::is_void<D>::value; | 89 static const/*expr*/ bool value = std::is_void<D>::value; |
71 }; | 90 }; |
72 template <typename S, typename D> struct is_convertible_detector<S, D, false> { | 91 template <typename S, typename D> struct is_convertible_detector<S, D, false> { |
73 using yes_type = uint8_t; | 92 using yes_type = uint8_t; |
74 using no_type = uint16_t; | 93 using no_type = uint16_t; |
75 | 94 |
76 template <typename To> static void param_convertable_to(To); | 95 template <typename To> static void param_convertable_to(To); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 template <typename D, typename S> using same_volatile_t = typename same_volatile
<D, S>::type; | 139 template <typename D, typename S> using same_volatile_t = typename same_volatile
<D, S>::type; |
121 template <typename D, typename S> using same_cv = copy_cv<skstd::remove_cv_t<D>,
S>; | 140 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_t = typename same_cv<D, S>::type
; | 141 template <typename D, typename S> using same_cv_t = typename same_cv<D, S>::type
; |
123 | 142 |
124 } // namespace sknonstd | 143 } // namespace sknonstd |
125 | 144 |
126 // Just a pithier wrapper for enable_if_t. | 145 // Just a pithier wrapper for enable_if_t. |
127 #define SK_WHEN(condition, T) skstd::enable_if_t<!!(condition), T> | 146 #define SK_WHEN(condition, T) skstd::enable_if_t<!!(condition), T> |
128 | 147 |
129 #endif | 148 #endif |
OLD | NEW |