3 ms·
Here’s what we do in MSVC’s STL: constexpr bool test_is_even() { assert(is_even(0)); assert(!is_even(1)); // … more test coverage
by StephanTLavavej 4y ago
Here’s what we do in MSVC’s STL:
constexpr bool test_is_even() {
assert(is_even(0));
assert(!is_even(1));
// … more test coverage
return true;
}
int main() {
test_is_even(); // runtime coverage
static_assert(test_is_even()); // compile-time coverage
This lets us run all test cases at both runtime and compiletime. (The static_assert performs constant evaluation, and if an assert within test_is_even would fail, it won’t be a constant expression.)
- arcticbull 4y agoThat's very cool, thank you for sharing!