diff options
Diffstat (limited to 'include/core')
-rw-r--r-- | include/core/SkTemplates.h | 11 | ||||
-rw-r--r-- | include/core/SkTypes.h | 5 |
2 files changed, 15 insertions, 1 deletions
diff --git a/include/core/SkTemplates.h b/include/core/SkTemplates.h index a3a846600a..4bcaf3f7b3 100644 --- a/include/core/SkTemplates.h +++ b/include/core/SkTemplates.h @@ -11,6 +11,8 @@ #define SkTemplates_DEFINED #include "SkTypes.h" +#include <limits> +#include <limits.h> #include <new> /** \file SkTemplates.h @@ -64,6 +66,15 @@ template <typename D, typename S> static D* SkTAddOffset(S* ptr, size_t byteOffs ); } +/** SkTSetBit<N, T>::value is a T with the Nth bit set. */ +template<unsigned N, typename T = uintmax_t> struct SkTSetBit { + static const T value = static_cast<T>(1) << N; + SK_COMPILE_ASSERT(sizeof(T)*CHAR_BIT > N, SkTSetBit_N_too_large); + SK_COMPILE_ASSERT(std::numeric_limits<T>::is_integer, SkTSetBit_T_must_be_integer); + SK_COMPILE_ASSERT(!std::numeric_limits<T>::is_signed, SkTSetBit_T_must_be_unsigned); + SK_COMPILE_ASSERT(std::numeric_limits<T>::radix == 2, SkTSetBit_T_radix_must_be_2); +}; + /** \class SkAutoTCallVProc Call a function when this goes out of scope. The template uses two diff --git a/include/core/SkTypes.h b/include/core/SkTypes.h index ab43767c6d..705c030164 100644 --- a/include/core/SkTypes.h +++ b/include/core/SkTypes.h @@ -127,8 +127,11 @@ template <bool> struct SkCompileAssert { }; +// Uses static_cast<bool>(expr) instead of bool(expr) due to +// https://connect.microsoft.com/VisualStudio/feedback/details/832915 #define SK_COMPILE_ASSERT(expr, msg) \ - typedef SkCompileAssert<(bool(expr))> msg[bool(expr) ? 1 : -1] SK_UNUSED + typedef SkCompileAssert<static_cast<bool>(expr)> \ + msg[static_cast<bool>(expr) ? 1 : -1] SK_UNUSED /* * Usage: SK_MACRO_CONCAT(a, b) to construct the symbol ab |