/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* vim: set ts=8 sts=2 et sw=2 tw=80: */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
template <typename IntType> staticvoid TestSingleParamRange(const IntType aN) {
IntType array[kArraySize];
IntType* ptr = array; for (auto i : IntegerRange(aN)) {
static_assert(std::is_same_v<decltype(i), IntType>, "type of the loop var and the param should be the same");
*ptr++ = i;
}
MOZ_RELEASE_ASSERT(ptr - array == static_cast<ptrdiff_t>(aN), "Should iterates N items"); for (size_t i = 0; i < static_cast<size_t>(aN); i++) {
MOZ_RELEASE_ASSERT(array[i] == static_cast<IntType>(i), "Values should equal to the index");
}
}
template <typename IntType> staticvoid TestSingleParamReverseRange(const IntType aN) {
IntType array[kArraySize];
IntType* ptr = array; for (auto i : Reversed(IntegerRange(aN))) {
static_assert(std::is_same_v<decltype(i), IntType>, "type of the loop var and the param should be the same");
*ptr++ = i;
}
MOZ_RELEASE_ASSERT(ptr - array == static_cast<ptrdiff_t>(aN), "Should iterates N items"); for (size_t i = 0; i < static_cast<size_t>(aN); i++) {
MOZ_RELEASE_ASSERT(array[i] == static_cast<IntType>(aN - i - 1), "Values should be the reverse of their index");
}
}
template <typename IntType1, typename IntType2> staticvoid TestDoubleParamRange(const IntType1 aBegin, const IntType2 aEnd) {
IntType2 array[kArraySize];
IntType2* ptr = array; for (auto i : IntegerRange(aBegin, aEnd)) {
static_assert(std::is_same_v<decltype(i), IntType2>, "type of the loop var " "should be same as that of the second param");
*ptr++ = i;
}
MOZ_RELEASE_ASSERT(ptr - array == static_cast<ptrdiff_t>(aEnd - aBegin), "Should iterates (aEnd - aBegin) times"); for (size_t i = 0; i < static_cast<size_t>(aEnd - aBegin); i++) {
MOZ_RELEASE_ASSERT(array[i] == static_cast<IntType2>(aBegin + i), "Should iterate integers in [aBegin, aEnd) in order");
}
}
template <typename IntType1, typename IntType2> staticvoid TestDoubleParamReverseRange(const IntType1 aBegin, const IntType2 aEnd) {
IntType2 array[kArraySize];
IntType2* ptr = array; for (auto i : Reversed(IntegerRange(aBegin, aEnd))) {
static_assert(std::is_same_v<decltype(i), IntType2>, "type of the loop var " "should be same as that of the second param");
*ptr++ = i;
}
MOZ_RELEASE_ASSERT(ptr - array == static_cast<ptrdiff_t>(aEnd - aBegin), "Should iterates (aEnd - aBegin) times"); for (size_t i = 0; i < static_cast<size_t>(aEnd - aBegin); i++) {
MOZ_RELEASE_ASSERT(
array[i] == static_cast<IntType2>(aEnd - i - 1), "Should iterate integers in [aBegin, aEnd) in reverse order");
}
}
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 ist noch experimentell.