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 (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. |
11 * | 11 * |
12 * Because we lack constexpr, we cannot mimic | 12 * Because we lack constexpr, we cannot mimic |
13 * std::integral_constant::'constexpr operator T()'. | 13 * std::integral_constant::'constexpr operator T()'. |
14 * As a result we introduce SkTBool and SkTIf similar to Boost in order to | 14 * As a result we introduce SkTBool and SkTIf similar to Boost in order to |
15 * minimize the visual noise of many uses of '::value'. | 15 * minimize the visual noise of many uses of '::value'. |
16 */ | 16 */ |
17 | 17 |
18 #ifndef SkTLogic_DEFINED | 18 #ifndef SkTLogic_DEFINED |
19 #define SkTLogic_DEFINED | 19 #define SkTLogic_DEFINED |
20 | 20 |
| 21 #include <stdint.h> |
| 22 |
21 /** Represents a templated integer constant. | 23 /** Represents a templated integer constant. |
22 * Pre-C++11 version of std::integral_constant. | 24 * Pre-C++11 version of std::integral_constant. |
23 */ | 25 */ |
24 template <typename T, T v> struct SkTIntegralConstant { | 26 template <typename T, T v> struct SkTIntegralConstant { |
25 static const T value = v; | 27 static const T value = v; |
26 typedef T value_type; | 28 typedef T value_type; |
27 typedef SkTIntegralConstant<T, v> type; | 29 typedef SkTIntegralConstant<T, v> type; |
28 }; | 30 }; |
29 | 31 |
30 /** Convenience specialization of SkTIntegralConstant. */ | 32 /** Convenience specialization of SkTIntegralConstant. */ |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 // Same sort of thing as SK_CREATE_MEMBER_DETECTOR, but checks for the existence
of a nested type. | 103 // Same sort of thing as SK_CREATE_MEMBER_DETECTOR, but checks for the existence
of a nested type. |
102 #define SK_CREATE_TYPE_DETECTOR(type) \ | 104 #define SK_CREATE_TYPE_DETECTOR(type) \ |
103 template <typename T> \ | 105 template <typename T> \ |
104 class HasType_##type { \ | 106 class HasType_##type { \ |
105 template <typename U> static uint8_t func(typename U::type*); \ | 107 template <typename U> static uint8_t func(typename U::type*); \ |
106 template <typename U> static uint16_t func(...); \ | 108 template <typename U> static uint16_t func(...); \ |
107 public: \ | 109 public: \ |
108 static const bool value = sizeof(func<T>(NULL)) == sizeof(uint8_t); \ | 110 static const bool value = sizeof(func<T>(NULL)) == sizeof(uint8_t); \ |
109 } | 111 } |
110 | 112 |
| 113 namespace skstd { |
| 114 |
| 115 /** SkTRemoveReference<T>::type is the type of T with any top-level lvalue or rv
alue removed. */ |
| 116 template <typename T> struct remove_reference { typedef T type; }; |
| 117 template <typename T> struct remove_reference<T&> { typedef T type; }; |
| 118 template <typename T> struct remove_reference<T&&> { typedef T type; }; |
| 119 template <typename T> using remove_reference_t = typename remove_reference<T>::t
ype; |
| 120 |
| 121 /** SkTIsLValueReference<T>::value is true if the type T is an lvalue reference.
*/ |
| 122 template <typename T> struct is_lvalue_reference : SkFalse {}; |
| 123 template <typename T> struct is_lvalue_reference<T&> : SkTrue {}; |
| 124 |
| 125 } // namespace skstd |
| 126 |
| 127 /** |
| 128 * SkTIsConst<T>::value is true if the type T is const. |
| 129 * The type T is constrained not to be an array or reference type. |
| 130 */ |
| 131 template <typename T> struct SkTIsConst { |
| 132 static T* t; |
| 133 static uint16_t test(const volatile void*); |
| 134 static uint32_t test(volatile void *); |
| 135 static const bool value = (sizeof(uint16_t) == sizeof(test(t))); |
| 136 }; |
| 137 |
111 #endif | 138 #endif |
OLD | NEW |