| 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. |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 /** SkTEnableIf::type = (Condition::value) ? T : [does not exist]; */ | 75 /** SkTEnableIf::type = (Condition::value) ? T : [does not exist]; */ |
| 76 template <class Condition, class T = void> struct SkTEnableIf | 76 template <class Condition, class T = void> struct SkTEnableIf |
| 77 : public SkTEnableIf_c<static_cast<bool>(Condition::value), T> { }; | 77 : public SkTEnableIf_c<static_cast<bool>(Condition::value), T> { }; |
| 78 | 78 |
| 79 /** Use as a return type to enable a function only when cond_type::value is true
, | 79 /** Use as a return type to enable a function only when cond_type::value is true
, |
| 80 * like C++14's std::enable_if_t. E.g. (N.B. this is a dumb example.) | 80 * like C++14's std::enable_if_t. E.g. (N.B. this is a dumb example.) |
| 81 * SK_WHEN(SkTrue, int) f(void* ptr) { return 1; } | 81 * SK_WHEN(SkTrue, int) f(void* ptr) { return 1; } |
| 82 * SK_WHEN(!SkTrue, int) f(void* ptr) { return 2; } | 82 * SK_WHEN(!SkTrue, int) f(void* ptr) { return 2; } |
| 83 */ | 83 */ |
| 84 #define SK_WHEN(cond_prefix, T) typename SkTEnableIf_c<cond_prefix::value, T>::t
ype | 84 #define SK_WHEN(cond_prefix, T) typename SkTEnableIf_c<cond_prefix::value, T>::t
ype |
| 85 #define SK_WHEN_C(cond, T) typename SkTEnableIf_c<cond, T>::type |
| 85 | 86 |
| 86 // See http://en.wikibooks.org/wiki/More_C++_Idioms/Member_Detector | 87 // See http://en.wikibooks.org/wiki/More_C++_Idioms/Member_Detector |
| 87 #define SK_CREATE_MEMBER_DETECTOR(member)
\ | 88 #define SK_CREATE_MEMBER_DETECTOR(member)
\ |
| 88 template <typename T>
\ | 89 template <typename T>
\ |
| 89 class HasMember_##member {
\ | 90 class HasMember_##member {
\ |
| 90 struct Fallback { int member; };
\ | 91 struct Fallback { int member; };
\ |
| 91 struct Derived : T, Fallback {};
\ | 92 struct Derived : T, Fallback {};
\ |
| 92 template <typename U, U> struct Check;
\ | 93 template <typename U, U> struct Check;
\ |
| 93 template <typename U> static uint8_t func(Check<int Fallback::*, &U::member>
*); \ | 94 template <typename U> static uint8_t func(Check<int Fallback::*, &U::member>
*); \ |
| 94 template <typename U> static uint16_t func(...);
\ | 95 template <typename U> static uint16_t func(...);
\ |
| 95 public:
\ | 96 public:
\ |
| 96 typedef HasMember_##member type;
\ | 97 typedef HasMember_##member type;
\ |
| 97 static const bool value = sizeof(func<Derived>(NULL)) == sizeof(uint16_t);
\ | 98 static const bool value = sizeof(func<Derived>(NULL)) == sizeof(uint16_t);
\ |
| 98 } | 99 } |
| 99 | 100 |
| 100 // Same sort of thing as SK_CREATE_MEMBER_DETECTOR, but checks for the existence
of a nested type. | 101 // Same sort of thing as SK_CREATE_MEMBER_DETECTOR, but checks for the existence
of a nested type. |
| 101 #define SK_CREATE_TYPE_DETECTOR(type) \ | 102 #define SK_CREATE_TYPE_DETECTOR(type) \ |
| 102 template <typename T> \ | 103 template <typename T> \ |
| 103 class HasType_##type { \ | 104 class HasType_##type { \ |
| 104 template <typename U> static uint8_t func(typename U::type*); \ | 105 template <typename U> static uint8_t func(typename U::type*); \ |
| 105 template <typename U> static uint16_t func(...); \ | 106 template <typename U> static uint16_t func(...); \ |
| 106 public: \ | 107 public: \ |
| 107 static const bool value = sizeof(func<T>(NULL)) == sizeof(uint8_t); \ | 108 static const bool value = sizeof(func<T>(NULL)) == sizeof(uint8_t); \ |
| 108 } | 109 } |
| 109 | 110 |
| 110 #endif | 111 #endif |
| OLD | NEW |