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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
51 typedef typename SkTIf_c<static_cast<bool>(Condition::value), T, F>::type ty pe; | 51 typedef typename SkTIf_c<static_cast<bool>(Condition::value), T, F>::type ty pe; |
52 }; | 52 }; |
53 | 53 |
54 /** SkTMux::type = (a && b) ? Both : (a) ? A : (b) ? B : Neither; */ | 54 /** SkTMux::type = (a && b) ? Both : (a) ? A : (b) ? B : Neither; */ |
55 template <typename a, typename b, typename Both, typename A, typename B, typenam e Neither> | 55 template <typename a, typename b, typename Both, typename A, typename B, typenam e Neither> |
56 struct SkTMux { | 56 struct SkTMux { |
57 typedef typename SkTIf<a, typename SkTIf<b, Both, A>::type, | 57 typedef typename SkTIf<a, typename SkTIf<b, Both, A>::type, |
58 typename SkTIf<b, B, Neither>::type>::type type; | 58 typename SkTIf<b, B, Neither>::type>::type type; |
59 }; | 59 }; |
60 | 60 |
61 /** SkTEnableIf is a pre-C++11 std::enable_if. */ | |
bungeman-skia
2014/04/25 21:45:55
The first time I wrote this: https://codereview.ch
mtklein
2014/04/28 15:47:05
Done.
| |
62 template <bool B, class T = void> | |
63 struct SkTEnableIf {}; | |
64 | |
65 template <class T> | |
66 struct SkTEnableIf<true, T> { typedef T type; }; | |
67 | |
68 // A macro that makes it clearer to use SkTEnableIf in parameter lists. | |
69 // template <typaname T> void foo(T a, SK_ENABLE_IF(condition)) { ... } | |
bungeman-skia
2014/04/25 21:45:55
'condition' here seems misleading, since this is a
mtklein
2014/04/28 15:47:05
Done.
| |
70 // template <typaname T> void foo(T a, SK_ENABLE_IF(!condition)) { ... } | |
bungeman-skia
2014/04/25 21:45:55
For example this is somewhat odd, in that this rea
mtklein
2014/04/28 15:47:05
Done.
| |
71 #define SK_ENABLE_IF(cond) typename SkTEnableIf<cond::value, bool>::type = false | |
bungeman-skia
2014/04/25 21:45:55
#define SK_FUNCTION_ARGUMENT_REQUIRES(type) typena
mtklein
2014/04/28 15:47:05
Done.
| |
72 | |
73 // See http://en.wikibooks.org/wiki/More_C++_Idioms/Member_Detector | |
74 #define SK_CREATE_MEMBER_DETECTOR(member) \ | |
75 template <typename T> \ | |
76 class HasMember_##member { \ | |
77 struct Fallback { int member; }; \ | |
78 struct Derived : T, Fallback {}; \ | |
79 template <typename U, U> struct Check; \ | |
80 template <typename U> static uint8_t func(Check<int Fallback::*, &U::member> *); \ | |
81 template <typename U> static uint16_t func(...); \ | |
82 public: \ | |
83 typedef HasMember_##member type; \ | |
84 enum { value = sizeof(func<Derived>(NULL)) == 2 }; \ | |
bungeman-skia
2014/04/25 21:45:55
We don't normally write it like this, something mo
mtklein
2014/04/28 15:47:05
Done.
| |
85 } | |
86 | |
61 #endif | 87 #endif |
OLD | NEW |