diff options
author | mtklein <mtklein@chromium.org> | 2015-09-28 10:33:02 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-09-28 10:33:02 -0700 |
commit | 449d9b7e2d1b2e20963f18639c6e541ef953f069 (patch) | |
tree | 0510fb4fd639ebd7e43a2388d5d545a3f0259c18 /include/private/SkTLogic.h | |
parent | 476506d070dbc59b158acc1a00c34bff95ab2968 (diff) |
simplify code in SkRecords.h
- use C++11 features ({} init, move constructors) to eliminate the need
for explicit constructors
- collapse RECORD0...RECORD8 into just one RECORD macro
- explicitly tag record types instead of using member detectors.
Removing member detectors makes this code significantly less fragile.
This exposes a few places where we didn't really think through what to do
with SkDrawable. I've marked them TODO for now.
BUG=skia:
Review URL: https://codereview.chromium.org/1360943003
Diffstat (limited to 'include/private/SkTLogic.h')
-rw-r--r-- | include/private/SkTLogic.h | 32 |
1 files changed, 2 insertions, 30 deletions
diff --git a/include/private/SkTLogic.h b/include/private/SkTLogic.h index e7fc3dd40d..c252001a00 100644 --- a/include/private/SkTLogic.h +++ b/include/private/SkTLogic.h @@ -220,35 +220,7 @@ template <typename D, typename S> using same_cv_t = typename same_cv<D, S>::type } // namespace sknonstd -/** Use as a return type to enable a function only when cond_type::value is true, - * like C++14's std::enable_if_t. E.g. (N.B. this is a dumb example.) - * SK_WHEN(true_type, int) f(void* ptr) { return 1; } - * SK_WHEN(!true_type, int) f(void* ptr) { return 2; } - */ -#define SK_WHEN(cond_prefix, T) skstd::enable_if_t<cond_prefix::value, T> - -// 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; \ - static const bool value = sizeof(func<Derived>(NULL)) == sizeof(uint16_t); \ -} - -// Same sort of thing as SK_CREATE_MEMBER_DETECTOR, but checks for the existence of a nested type. -#define SK_CREATE_TYPE_DETECTOR(type) \ -template <typename T> \ -class HasType_##type { \ - template <typename U> static uint8_t func(typename U::type*); \ - template <typename U> static uint16_t func(...); \ -public: \ - static const bool value = sizeof(func<T>(NULL)) == sizeof(uint8_t); \ -} +// Just a pithier wrapper for enable_if_t. +#define SK_WHEN(condition, T) skstd::enable_if_t<!!(condition), T> #endif |