Chromium Code Reviews| Index: src/utils/SkTLogic.h |
| diff --git a/src/utils/SkTLogic.h b/src/utils/SkTLogic.h |
| index bf9ee1ab2505d8a772ad8e8cff4760afbcccb791..ae0affbe4950246b78cb68cc910d6f24fb2930c3 100644 |
| --- a/src/utils/SkTLogic.h |
| +++ b/src/utils/SkTLogic.h |
| @@ -58,4 +58,30 @@ struct SkTMux { |
| typename SkTIf<b, B, Neither>::type>::type type; |
| }; |
| +/** 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.
|
| +template <bool B, class T = void> |
| +struct SkTEnableIf {}; |
| + |
| +template <class T> |
| +struct SkTEnableIf<true, T> { typedef T type; }; |
| + |
| +// A macro that makes it clearer to use SkTEnableIf in parameter lists. |
| +// 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.
|
| +// 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.
|
| +#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.
|
| + |
| +// See http://en.wikibooks.org/wiki/More_C++_Idioms/Member_Detector |
| +#define SK_CREATE_MEMBER_DETECTOR(member) \ |
| +template <typename T> \ |
| +class HasMember_##member { \ |
| + struct Fallback { int member; }; \ |
| + struct Derived : T, Fallback {}; \ |
| + template <typename U, U> struct Check; \ |
| + template <typename U> static uint8_t func(Check<int Fallback::*, &U::member> *); \ |
| + template <typename U> static uint16_t func(...); \ |
| +public: \ |
| + typedef HasMember_##member type; \ |
| + 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.
|
| +} |
| + |
| #endif |