Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Types | Static Public Member Functions | List of all members
base::internal::CheckedAddOp< T, U, typename std::enable_if< std::is_integral< T >::value &&std::is_integral< U >::value >::type > Struct Template Reference

#include <checked_math_impl.h>

Public Types

using result_type = typename MaxExponentPromotion< T, U >::type
 

Static Public Member Functions

template<typename V >
static constexpr bool Do (T x, U y, V *result)
 

Detailed Description

template<typename T, typename U>
struct base::internal::CheckedAddOp< T, U, typename std::enable_if< std::is_integral< T >::value &&std::is_integral< U >::value >::type >

Definition at line 44 of file checked_math_impl.h.

Member Typedef Documentation

◆ result_type

template<typename T , typename U >
using base::internal::CheckedAddOp< T, U, typename std::enable_if< std::is_integral< T >::value &&std::is_integral< U >::value >::type >::result_type = typename MaxExponentPromotion<T, U>::type

Definition at line 48 of file checked_math_impl.h.

Member Function Documentation

◆ Do()

template<typename T , typename U >
template<typename V >
static constexpr bool base::internal::CheckedAddOp< T, U, typename std::enable_if< std::is_integral< T >::value &&std::is_integral< U >::value >::type >::Do ( T  x,
y,
V result 
)
inlinestaticconstexpr

Definition at line 50 of file checked_math_impl.h.

50 {
51 // TODO(jschuh) Make this "constexpr if" once we're C++17.
54
55 // Double the underlying type up to a full machine word.
56 using FastPromotion = typename FastIntegerArithmeticPromotion<T, U>::type;
57 using Promotion =
58 typename std::conditional<(IntegerBitsPlusSign<FastPromotion>::value >
60 typename BigEnoughPromotion<T, U>::type,
61 FastPromotion>::type;
62 // Fail if either operand is out of range for the promoted type.
63 // TODO(jschuh): This could be made to work for a broader range of values.
64 if (BASE_NUMERICS_UNLIKELY(!IsValueInRangeForNumericType<Promotion>(x) ||
65 !IsValueInRangeForNumericType<Promotion>(y))) {
66 return false;
67 }
68
69 Promotion presult = {};
70 bool is_valid = true;
72 presult = static_cast<Promotion>(x) + static_cast<Promotion>(y);
73 } else {
74 is_valid = CheckedAddImpl(static_cast<Promotion>(x),
75 static_cast<Promotion>(y), &presult);
76 }
77 *result = static_cast<V>(presult);
78 return is_valid && IsValueInRangeForNumericType<V>(presult);
79 }
static bool is_valid(SkISize dim)
GAsyncResult * result
T __attribute__((ext_vector_type(N))) V
double y
double x
constexpr bool CheckedAddImpl(T x, T y, T *result)
#define BASE_NUMERICS_UNLIKELY(x)
static constexpr bool Do(T, U, V *)

The documentation for this struct was generated from the following file: