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 ...@@ -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 bits, typename T> inline constexpr uint unboundMaxBits(T i) { return i; }
template <uint newMax, typename T, typename ErrorFunc> 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(); if (KJ_UNLIKELY(value > newMax)) func();
return value; return value;
} }
template <typename T, typename ErrorFunc> 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(); if (KJ_UNLIKELY(value > newMax)) func();
return value; return value;
} }
template <uint bits, typename T, typename ErrorFunc = ThrowOverflow> 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(); if (KJ_UNLIKELY(value > kj::maxValueForBits<bits>())) func();
return value; return value;
} }
template <typename T, typename ErrorFunc = ThrowOverflow> 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(); if (KJ_UNLIKELY(value > (1ull << bits) - 1)) func();
return value; return value;
} }
......
...@@ -104,11 +104,7 @@ inline KJ_CONSTEXPR() BitsPerElementTableType dataBitsPerElement(ElementSize siz ...@@ -104,11 +104,7 @@ inline KJ_CONSTEXPR() BitsPerElementTableType dataBitsPerElement(ElementSize siz
} }
inline constexpr PointersPerElementN<1> pointersPerElement(ElementSize size) { inline constexpr PointersPerElementN<1> pointersPerElement(ElementSize size) {
if (size == ElementSize::POINTER) { return size == ElementSize::POINTER ? ONE * POINTERS / ELEMENTS : ZERO * POINTERS / ELEMENTS;
return ONE * POINTERS / ELEMENTS;
} else {
return ZERO * POINTERS / ELEMENTS;
}
} }
static constexpr BitsPerElementTableType BITS_PER_ELEMENT_INCLUDING_PONITERS_TABLE[8] = { static constexpr BitsPerElementTableType BITS_PER_ELEMENT_INCLUDING_PONITERS_TABLE[8] = {
......
...@@ -786,7 +786,7 @@ inline constexpr auto assumeMax(Quantity<BoundedConst<maxN>, Unit>, Quantity<Num ...@@ -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> 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() // Assert that the bounded value is less than or equal to the given maximum, calling errorFunc()
// if not. // if not.
static_assert(newMax < maxN, "this bounded size assertion is redundant"); 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& ...@@ -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> 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) { Quantity<Bounded<maxN, T>, Unit> value, ErrorFunc&& errorFunc) {
// Assert that the bounded value is less than or equal to the given maximum, calling errorFunc() // Assert that the bounded value is less than or equal to the given maximum, calling errorFunc()
// if not. // if not.
...@@ -804,20 +804,20 @@ inline constexpr Quantity<Bounded<newMax, T>, Unit> assertMax( ...@@ -804,20 +804,20 @@ inline constexpr Quantity<Bounded<newMax, T>, Unit> assertMax(
} }
template <uint newMax, uint64_t maxN, typename T, typename ErrorFunc> 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) { BoundedConst<newMax>, Bounded<maxN, T> value, ErrorFunc&& errorFunc) {
return assertMax<newMax>(value, kj::mv(errorFunc)); return assertMax<newMax>(value, kj::mv(errorFunc));
} }
template <uint newMax, uint64_t maxN, typename T, typename Unit, typename 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<BoundedConst<newMax>, Unit>,
Quantity<Bounded<maxN, T>, Unit> value, ErrorFunc&& errorFunc) { Quantity<Bounded<maxN, T>, Unit> value, ErrorFunc&& errorFunc) {
return assertMax<newMax>(value, kj::mv(errorFunc)); return assertMax<newMax>(value, kj::mv(errorFunc));
} }
template <uint64_t newBits, uint64_t maxN, typename T, typename ErrorFunc = ThrowOverflow> 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()) { Bounded<maxN, T> value, ErrorFunc&& errorFunc = ErrorFunc()) {
// Assert that the bounded value requires no more than the given number of bits, calling // Assert that the bounded value requires no more than the given number of bits, calling
// errorFunc() if not. // errorFunc() if not.
...@@ -826,7 +826,7 @@ inline constexpr Bounded<maxValueForBits<newBits>(), T> assertMaxBits( ...@@ -826,7 +826,7 @@ inline constexpr Bounded<maxValueForBits<newBits>(), T> assertMaxBits(
template <uint64_t newBits, uint64_t maxN, typename T, typename Unit, template <uint64_t newBits, uint64_t maxN, typename T, typename Unit,
typename ErrorFunc = ThrowOverflow> 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()) { Quantity<Bounded<maxN, T>, Unit> value, ErrorFunc&& errorFunc = ErrorFunc()) {
// Assert that the bounded value requires no more than the given number of bits, calling // Assert that the bounded value requires no more than the given number of bits, calling
// errorFunc() if not. // errorFunc() if not.
...@@ -994,12 +994,12 @@ public: ...@@ -994,12 +994,12 @@ public:
inline explicit constexpr SafeUnwrapper(Bounded<maxN, T> value): value(value.unwrap()) {} inline explicit constexpr SafeUnwrapper(Bounded<maxN, T> value): value(value.unwrap()) {}
template <typename U, typename = EnableIf<isIntegral<U>()>> template <typename U, typename = EnableIf<isIntegral<U>()>>
inline constexpr operator U() { inline constexpr operator U() const {
static_assert(maxN <= U(maxValue), "possible truncation detected"); static_assert(maxN <= U(maxValue), "possible truncation detected");
return value; return value;
} }
inline constexpr operator bool() { inline constexpr operator bool() const {
static_assert(maxN <= 1, "possible truncation detected"); static_assert(maxN <= 1, "possible truncation detected");
return value; return value;
} }
...@@ -1019,12 +1019,12 @@ template <uint64_t value> ...@@ -1019,12 +1019,12 @@ template <uint64_t value>
class SafeConstUnwrapper { class SafeConstUnwrapper {
public: public:
template <typename T, typename = EnableIf<isIntegral<T>()>> 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"); static_assert(value <= T(maxValue), "this operation will truncate");
return value; return value;
} }
inline constexpr operator bool() { inline constexpr operator bool() const {
static_assert(value <= 1, "this operation will truncate"); static_assert(value <= 1, "this operation will truncate");
return value; 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