Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(296)

Side by Side Diff: src/utils/SkTLogic.h

Issue 258693006: Start using type traits in src/record instead of macros. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: ben Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/record/SkRecordTraits.h ('k') | tests/RecordDrawTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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_c::type = (condition) ? T : [does not exist]; */
62 template <bool condition, class T = void> struct SkTEnableIf_c { };
63 template <class T> struct SkTEnableIf_c<true, T> {
64 typedef T type;
65 };
66
67 /** SkTEnableIf::type = (Condition::value) ? T : [does not exist]; */
68 template <class Condition, class T = void> struct SkTEnableIf
69 : public SkTEnableIf_c<static_cast<bool>(Condition::value), T> { };
70
71 /** Use as a return type to enable a function only when cond_type::value is true ,
72 * like C++14's std::enable_if_t. E.g. (N.B. this is a dumb example.)
73 * SK_WHEN(SkTrue, int) f(void* ptr) { return 1; }
74 * SK_WHEN(!SkTrue, int) f(void* ptr) { return 2; }
75 */
76 #define SK_WHEN(cond_prefix, T) typename SkTEnableIf_c<cond_prefix::value, T>::t ype
77
78 // See http://en.wikibooks.org/wiki/More_C++_Idioms/Member_Detector
79 #define SK_CREATE_MEMBER_DETECTOR(member) \
80 template <typename T> \
81 class HasMember_##member { \
82 struct Fallback { int member; }; \
83 struct Derived : T, Fallback {}; \
84 template <typename U, U> struct Check; \
85 template <typename U> static uint8_t func(Check<int Fallback::*, &U::member> *); \
86 template <typename U> static uint16_t func(...); \
87 public: \
88 typedef HasMember_##member type; \
89 static const bool value = sizeof(func<Derived>(NULL)) == sizeof(uint16_t); \
90 }
91
61 #endif 92 #endif
OLDNEW
« no previous file with comments | « src/record/SkRecordTraits.h ('k') | tests/RecordDrawTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698