Make SkTFitsIn and SkTo constexpr.
Because what can be better than marking things that can be constexpr as constexpr. Also, I have a change where this would be nice to have. Change-Id: Ie313b19d1930b98ddcd60cc17a320971625f18e3 Reviewed-on: https://skia-review.googlesource.com/60862 Commit-Queue: Ben Wagner <bungeman@google.com> Reviewed-by: Mike Klein <mtklein@chromium.org>
This commit is contained in:
parent
aeaf6e771f
commit
d71c6d1994
@ -206,9 +206,9 @@ typedef unsigned U16CPU;
|
||||
typedef uint8_t SkBool8;
|
||||
|
||||
#include "../private/SkTFitsIn.h"
|
||||
template <typename D, typename S> D SkTo(S s) {
|
||||
SkASSERT(SkTFitsIn<D>(s));
|
||||
return static_cast<D>(s);
|
||||
template <typename D, typename S> constexpr D SkTo(S s) {
|
||||
return SkASSERT(SkTFitsIn<D>(s)),
|
||||
static_cast<D>(s);
|
||||
}
|
||||
#define SkToS8(x) SkTo<int8_t>(x)
|
||||
#define SkToU8(x) SkTo<uint8_t>(x)
|
||||
|
@ -66,7 +66,7 @@ template <typename A, typename B> struct SkTHasMoreDigits
|
||||
* Used when it is statically known that source values are in the range of the Destination.
|
||||
*/
|
||||
template <typename S> struct SkTInRange_True {
|
||||
static bool fits(S) {
|
||||
static constexpr bool fits(S) {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
@ -75,7 +75,7 @@ template <typename S> struct SkTInRange_True {
|
||||
* This is not valid for uX -> sx and sx -> uX conversions.
|
||||
*/
|
||||
template <typename D, typename S> struct SkTInRange_Cast {
|
||||
static bool fits(S s) {
|
||||
static constexpr bool fits(S s) {
|
||||
using S_is_bigger = SkTHasMoreDigits<S, D>;
|
||||
using D_is_bigger = SkTHasMoreDigits<D, S>;
|
||||
|
||||
@ -95,7 +95,7 @@ template <typename D, typename S> struct SkTInRange_Cast {
|
||||
* Assumes that Max(S) >= Max(D).
|
||||
*/
|
||||
template <typename D, typename S> struct SkTInRange_LE_MaxD {
|
||||
static bool fits(S s) {
|
||||
static constexpr bool fits(S s) {
|
||||
using precondition = SkTHasMoreDigits<S, D>;
|
||||
static_assert(precondition::value, "maxS < maxD");
|
||||
|
||||
@ -106,7 +106,7 @@ template <typename D, typename S> struct SkTInRange_LE_MaxD {
|
||||
|
||||
/** Tests if the source value >= 0. */
|
||||
template <typename D, typename S> struct SkTInRange_GE_Zero {
|
||||
static bool fits(S s) {
|
||||
static constexpr bool fits(S s) {
|
||||
return static_cast<S>(0) <= s;
|
||||
}
|
||||
};
|
||||
@ -197,7 +197,7 @@ template <typename T> struct underlying_type<T, false> {
|
||||
} // namespace sktfitsin
|
||||
|
||||
/** Returns true if the integer source value 's' will fit in the integer destination type 'D'. */
|
||||
template <typename D, typename S> inline bool SkTFitsIn(S s) {
|
||||
template <typename D, typename S> constexpr inline bool SkTFitsIn(S s) {
|
||||
static_assert(std::is_integral<S>::value || std::is_enum<S>::value, "S must be integral.");
|
||||
static_assert(std::is_integral<D>::value || std::is_enum<D>::value, "D must be integral.");
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user