OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright 2013 Google Inc. |
| 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. |
| 6 */ |
| 7 |
| 8 #ifndef SkTLogic_DEFINED |
| 9 #define SkTLogic_DEFINED |
| 10 |
| 11 /** SkTBool::type = self; SkTBool::value = b; */ |
| 12 template <bool b> struct SkTBool { |
| 13 typedef SkTBool type; |
| 14 static const bool value = b; |
| 15 }; |
| 16 typedef SkTBool<true> SkTrue; |
| 17 typedef SkTBool<false> SkFalse; |
| 18 |
| 19 /** SkTIf_c::type = (condition) ? T : F; */ |
| 20 template <bool condition, typename T, typename F> struct SkTIf_c { |
| 21 typedef F type; |
| 22 }; |
| 23 template <typename T, typename F> struct SkTIf_c<true, T, F> { |
| 24 typedef T type; |
| 25 }; |
| 26 |
| 27 /** SkTIf::type = (Condition::value) ? T : F; */ |
| 28 template <typename Condition, typename T, typename F> struct SkTIf { |
| 29 typedef typename SkTIf_c<static_cast<bool>(Condition::value), T, F>::type ty
pe; |
| 30 }; |
| 31 |
| 32 /** SkTMux::type = (a && b) ? Both : (a) ? A : (b) ? B : Neither; */ |
| 33 template <typename a, typename b, typename Both, typename A, typename B, typenam
e Neither> |
| 34 struct SkTMux { |
| 35 typedef typename SkTIf<a, typename SkTIf<b, Both, A>::type, |
| 36 typename SkTIf<b, B, Neither>::type>::type type; |
| 37 }; |
| 38 |
| 39 /** SkTEnableIf_c::type = (condition) ? T : [does not exist]; */ |
| 40 template <bool condition, class T = void> struct SkTEnableIf_c { }; |
| 41 template <class T> struct SkTEnableIf_c<true, T> { |
| 42 typedef T type; |
| 43 }; |
| 44 |
| 45 /** SkTEnableIf::type = (Condition::value) ? T : [does not exist]; */ |
| 46 template <class Condition, class T = void> struct SkTEnableIf |
| 47 : public SkTEnableIf_c<static_cast<bool>(Condition::value), T> { }; |
| 48 |
| 49 #endif |
OLD | NEW |