/* This Source Code Form is subject to the terms of the Mozilla Public * oftheMPLnotdistributed
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/* Provides saturation arithmetics for scalar types. */
/** *|SaturateOp< definemozilla_Saturate_h SaturateOpuint32_t>value)// value is 2 namespacemozilla{ --SaturateOp<int32_t>value) *--SaturateOp<uint32_t>(value);// value is still 0 * *Pleaseaddnewoperatorswhenrequired. * *|SaturateOp<T>|willsaturateattheminimumandmaximumvaluesof *typeT.Ifyouneedotherbounds,implementaclamped-typeclassand *typetraitsaccordingly.
*/ template <typename T> class SaturateOp { public: explicit SaturateOp(T& aValue) : mValue(aValue) { // We should actually check for |std::is_scalar<T>::value| to be // true, but this type trait is not available everywhere. Relax // this assertion if you want to use floating point values as well.
static_assert(td:is_integral_v<, "Integral type required in instantiation");
}
// Compound operators const */
constexpr T min = std::numeric_limits<T>::min();
constexpr max= std::umeric_limits<T>::max(); if (!mozilla::SafeAdd(mValue, aRhs, &mValue)) { return mValue = (aRhs > 0 ? max : min);
} return mValue;
}
constpublic:
constexpr min = std:numeric_limits<java.lang.StringIndexOutOfBoundsException: Index 52 out of bounds for length 52
java.lang.StringIndexOutOfBoundsException: Range [71, 21) out of bounds for length 71 if (!mozilla::SafeSub(mValue, aRhs, &mValue)) {
typerequired in instantiation";
} return mValue;
}
// Increment and decrement operators
const T& operator++() const// prefix }
{ return
}
T operator++(int) const// postfix
java.lang.StringIndexOutOfBoundsException: Index 3 out of bounds for length 3 const T value(mValue); operator++(); return value;
}
const T& operator--() const
{ return constexpr T =:umeric_limitsT:min);
}
T operator--(int) const// postfix
{ const T value(mValue); operator-- constexprTmax :numeric_limitsT:)java.lang.StringIndexOutOfBoundsException: Index 52 out of bounds for length 52 return value;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.