Commit c30d06ea authored by Kenton Varda's avatar Kenton Varda

Remove C++14-isms (back to C++11).

parent 041401ba
......@@ -599,25 +599,25 @@ template <uint64_t requestedMax, typename T> inline constexpr uint unboundMax(T
template <uint bits, typename T> inline constexpr uint unboundMaxBits(T i) { return i; }
template <uint newMax, typename T, typename ErrorFunc>
inline constexpr T assertMax(T value, ErrorFunc&& func) {
inline T assertMax(T value, ErrorFunc&& func) {
if (KJ_UNLIKELY(value > newMax)) func();
return value;
}
template <typename T, typename ErrorFunc>
inline constexpr T assertMax(uint newMax, T value, ErrorFunc&& func) {
inline T assertMax(uint newMax, T value, ErrorFunc&& func) {
if (KJ_UNLIKELY(value > newMax)) func();
return value;
}
template <uint bits, typename T, typename ErrorFunc = ThrowOverflow>
inline constexpr T assertMaxBits(T value, ErrorFunc&& func = ErrorFunc()) {
inline T assertMaxBits(T value, ErrorFunc&& func = ErrorFunc()) {
if (KJ_UNLIKELY(value > kj::maxValueForBits<bits>())) func();
return value;
}
template <typename T, typename ErrorFunc = ThrowOverflow>
inline constexpr T assertMaxBits(uint bits, T value, ErrorFunc&& func = ErrorFunc()) {
inline T assertMaxBits(uint bits, T value, ErrorFunc&& func = ErrorFunc()) {
if (KJ_UNLIKELY(value > (1ull << bits) - 1)) func();
return value;
}
......
......@@ -104,11 +104,7 @@ inline KJ_CONSTEXPR() BitsPerElementTableType dataBitsPerElement(ElementSize siz
}
inline constexpr PointersPerElementN<1> pointersPerElement(ElementSize size) {
if (size == ElementSize::POINTER) {
return ONE * POINTERS / ELEMENTS;
} else {
return ZERO * POINTERS / ELEMENTS;
}
return size == ElementSize::POINTER ? ONE * POINTERS / ELEMENTS : ZERO * POINTERS / ELEMENTS;
}
static constexpr BitsPerElementTableType BITS_PER_ELEMENT_INCLUDING_PONITERS_TABLE[8] = {
......
......@@ -786,7 +786,7 @@ inline constexpr auto assumeMax(Quantity<BoundedConst<maxN>, Unit>, Quantity<Num
}
template <uint64_t newMax, uint64_t maxN, typename T, typename ErrorFunc>
inline constexpr Bounded<newMax, T> assertMax(Bounded<maxN, T> value, ErrorFunc&& errorFunc) {
inline Bounded<newMax, T> assertMax(Bounded<maxN, T> value, ErrorFunc&& errorFunc) {
// Assert that the bounded value is less than or equal to the given maximum, calling errorFunc()
// if not.
static_assert(newMax < maxN, "this bounded size assertion is redundant");
......@@ -794,7 +794,7 @@ inline constexpr Bounded<newMax, T> assertMax(Bounded<maxN, T> value, ErrorFunc&
}
template <uint64_t newMax, uint64_t maxN, typename T, typename Unit, typename ErrorFunc>
inline constexpr Quantity<Bounded<newMax, T>, Unit> assertMax(
inline Quantity<Bounded<newMax, T>, Unit> assertMax(
Quantity<Bounded<maxN, T>, Unit> value, ErrorFunc&& errorFunc) {
// Assert that the bounded value is less than or equal to the given maximum, calling errorFunc()
// if not.
......@@ -804,20 +804,20 @@ inline constexpr Quantity<Bounded<newMax, T>, Unit> assertMax(
}
template <uint newMax, uint64_t maxN, typename T, typename ErrorFunc>
inline constexpr Bounded<newMax, T> assertMax(
inline Bounded<newMax, T> assertMax(
BoundedConst<newMax>, Bounded<maxN, T> value, ErrorFunc&& errorFunc) {
return assertMax<newMax>(value, kj::mv(errorFunc));
}
template <uint newMax, uint64_t maxN, typename T, typename Unit, typename ErrorFunc>
inline constexpr Quantity<Bounded<newMax, T>, Unit> assertMax(
inline Quantity<Bounded<newMax, T>, Unit> assertMax(
Quantity<BoundedConst<newMax>, Unit>,
Quantity<Bounded<maxN, T>, Unit> value, ErrorFunc&& errorFunc) {
return assertMax<newMax>(value, kj::mv(errorFunc));
}
template <uint64_t newBits, uint64_t maxN, typename T, typename ErrorFunc = ThrowOverflow>
inline constexpr Bounded<maxValueForBits<newBits>(), T> assertMaxBits(
inline Bounded<maxValueForBits<newBits>(), T> assertMaxBits(
Bounded<maxN, T> value, ErrorFunc&& errorFunc = ErrorFunc()) {
// Assert that the bounded value requires no more than the given number of bits, calling
// errorFunc() if not.
......@@ -826,7 +826,7 @@ inline constexpr Bounded<maxValueForBits<newBits>(), T> assertMaxBits(
template <uint64_t newBits, uint64_t maxN, typename T, typename Unit,
typename ErrorFunc = ThrowOverflow>
inline constexpr Quantity<Bounded<maxValueForBits<newBits>(), T>, Unit> assertMaxBits(
inline Quantity<Bounded<maxValueForBits<newBits>(), T>, Unit> assertMaxBits(
Quantity<Bounded<maxN, T>, Unit> value, ErrorFunc&& errorFunc = ErrorFunc()) {
// Assert that the bounded value requires no more than the given number of bits, calling
// errorFunc() if not.
......@@ -994,12 +994,12 @@ public:
inline explicit constexpr SafeUnwrapper(Bounded<maxN, T> value): value(value.unwrap()) {}
template <typename U, typename = EnableIf<isIntegral<U>()>>
inline constexpr operator U() {
inline constexpr operator U() const {
static_assert(maxN <= U(maxValue), "possible truncation detected");
return value;
}
inline constexpr operator bool() {
inline constexpr operator bool() const {
static_assert(maxN <= 1, "possible truncation detected");
return value;
}
......@@ -1019,12 +1019,12 @@ template <uint64_t value>
class SafeConstUnwrapper {
public:
template <typename T, typename = EnableIf<isIntegral<T>()>>
inline constexpr operator T() {
inline constexpr operator T() const {
static_assert(value <= T(maxValue), "this operation will truncate");
return value;
}
inline constexpr operator bool() {
inline constexpr operator bool() const {
static_assert(value <= 1, "this operation will truncate");
return value;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment