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 |
17 #include <stddef.h> | 19 #include <stddef.h> |
18 #include <stdint.h> | 20 #include <stdint.h> |
19 #include <type_traits> | 21 #include <type_traits> |
20 #include <utility> | 22 #include <utility> |
21 | 23 |
22 namespace skstd { | 24 namespace skstd { |
23 | 25 |
24 template <bool B> using bool_constant = std::integral_constant<bool, B>; | 26 template <bool B> using bool_constant = std::integral_constant<bool, B>; |
25 | 27 |
26 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; |
27 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; |
28 | 30 |
29 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
; |
30 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; |
31 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; |
32 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; |
33 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; |
34 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; |
35 | 37 |
36 // template<typename R, typename... Args> struct is_function< | 38 // template<typename R, typename... Args> struct is_function< |
37 // R [calling-convention] (Args...[, ...]) [const] [volatile] [&|&&]> : std:
:true_type {}; | 39 // R [calling-convention] (Args...[, ...]) [const] [volatile] [&|&&]> : std:
:true_type {}; |
38 // 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. |
39 // These aren't supported in msvc either until vs2015u2. | 41 // These aren't supported in msvc either until vs2015u2. |
40 // 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. |
41 // mcvc 2013 introduced __vectorcall, but it wan't until 2015 that it was added
to is_function. | 43 // mcvc 2013 introduced __vectorcall, but it wan't until 2015 that it was added
to is_function. |
42 template <typename> struct is_function : std::false_type {}; | 44 template <typename> struct is_function : std::false_type {}; |
43 #if !defined(WIN32) | 45 #if !defined(SK_BUILD_FOR_WIN) |
44 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 {}; |
45 #else | 47 #else |
46 template <typename R, typename... Args> struct is_function<R __cdecl (Args...)>
: std::true_type {}; | 48 template <typename R, typename... Args> struct is_function<R __cdecl (Args...)>
: std::true_type {}; |
47 #if defined(_M_IX86) | 49 #if defined(_M_IX86) |
48 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 {}; |
49 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 {}; |
50 #endif | 52 #endif |
51 #if defined(_MSC_VER) && (_M_IX86_FP >= 2 || defined(_M_AMD64) || defined(_M_X64
)) | 53 #if defined(_MSC_VER) && SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSE2 |
52 template <typename R, typename... Args> struct is_function<R __vectorcall (Args.
..)> : std::true_type {}; | 54 template <typename R, typename... Args> struct is_function<R __vectorcall (Args.
..)> : std::true_type {}; |
53 #endif | 55 #endif |
54 #endif | 56 #endif |
55 template <typename R, typename... Args> struct is_function<R(Args..., ...)> : st
d::true_type {}; | 57 template <typename R, typename... Args> struct is_function<R(Args..., ...)> : st
d::true_type {}; |
56 | 58 |
57 template <typename T> using add_const_t = typename std::add_const<T>::type; | 59 template <typename T> using add_const_t = typename std::add_const<T>::type; |
58 template <typename T> using add_volatile_t = typename std::add_volatile<T>::type
; | 60 template <typename T> using add_volatile_t = typename std::add_volatile<T>::type
; |
59 template <typename T> using add_cv_t = typename std::add_cv<T>::type; | 61 template <typename T> using add_cv_t = typename std::add_cv<T>::type; |
60 template <typename T> using add_pointer_t = typename std::add_pointer<T>::type; | 62 template <typename T> using add_pointer_t = typename std::add_pointer<T>::type; |
61 template <typename T> using add_lvalue_reference_t = typename std::add_lvalue_re
ference<T>::type; | 63 template <typename T> using add_lvalue_reference_t = typename std::add_lvalue_re
ference<T>::type; |
62 | 64 |
63 template <typename... T> using common_type_t = typename std::common_type<T...>::
type; | 65 template <typename... T> using common_type_t = typename std::common_type<T...>::
type; |
64 template <typename T> using underlying_type_t = typename std::underlying_type<T>
::type; | |
65 | 66 |
66 template <typename S, typename D, | 67 template <typename S, typename D, |
67 bool=std::is_void<S>::value || is_function<D>::value || std::is_array<
D>::value> | 68 bool=std::is_void<S>::value || is_function<D>::value || std::is_array<
D>::value> |
68 struct is_convertible_detector { | 69 struct is_convertible_detector { |
69 static const/*expr*/ bool value = std::is_void<D>::value; | 70 static const/*expr*/ bool value = std::is_void<D>::value; |
70 }; | 71 }; |
71 template <typename S, typename D> struct is_convertible_detector<S, D, false> { | 72 template <typename S, typename D> struct is_convertible_detector<S, D, false> { |
72 using yes_type = uint8_t; | 73 using yes_type = uint8_t; |
73 using no_type = uint16_t; | 74 using no_type = uint16_t; |
74 | 75 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 template <typename D, typename S> using same_volatile_t = typename same_volatile
<D, S>::type; | 120 template <typename D, typename S> using same_volatile_t = typename same_volatile
<D, S>::type; |
120 template <typename D, typename S> using same_cv = copy_cv<skstd::remove_cv_t<D>,
S>; | 121 template <typename D, typename S> using same_cv = copy_cv<skstd::remove_cv_t<D>,
S>; |
121 template <typename D, typename S> using same_cv_t = typename same_cv<D, S>::type
; | 122 template <typename D, typename S> using same_cv_t = typename same_cv<D, S>::type
; |
122 | 123 |
123 } // namespace sknonstd | 124 } // namespace sknonstd |
124 | 125 |
125 // Just a pithier wrapper for enable_if_t. | 126 // Just a pithier wrapper for enable_if_t. |
126 #define SK_WHEN(condition, T) skstd::enable_if_t<!!(condition), T> | 127 #define SK_WHEN(condition, T) skstd::enable_if_t<!!(condition), T> |
127 | 128 |
128 #endif | 129 #endif |
OLD | NEW |