Remove some static_asserts out of the common.h header

These asserts require a recursive template instantiation and are currently
checked for every file that pulls in common.h. Place them in a .cpp file so
they are only checked once, hopefully improving compile time.
This commit is contained in:
ridiculousfish 2021-05-21 13:06:43 -07:00
parent 7123e2f25d
commit 9928404920
2 changed files with 11 additions and 9 deletions

View File

@ -1998,3 +1998,14 @@ bool is_console_session() {
}();
return console_session;
}
static_assert(const_strcmp("", "a") < 0, "const_strcmp failure");
static_assert(const_strcmp("a", "a") == 0, "const_strcmp failure");
static_assert(const_strcmp("a", "") > 0, "const_strcmp failure");
static_assert(const_strcmp("aa", "a") > 0, "const_strcmp failure");
static_assert(const_strcmp("a", "aa") < 0, "const_strcmp failure");
static_assert(const_strcmp("b", "aa") > 0, "const_strcmp failure");
static_assert(const_strlen("") == 0, "const_strlen failure");
static_assert(const_strlen("a") == 1, "const_strlen failure");
static_assert(const_strlen("hello") == 5, "const_strlen failure");

View File

@ -722,12 +722,6 @@ constexpr ssize_t const_strcmp(const T *lhs, const T *rhs) {
return (*lhs == *rhs) ? (*lhs == 0 ? 0 : const_strcmp(lhs + 1, rhs + 1))
: (*lhs > *rhs ? 1 : -1);
}
static_assert(const_strcmp("", "a") < 0, "const_strcmp failure");
static_assert(const_strcmp("a", "a") == 0, "const_strcmp failure");
static_assert(const_strcmp("a", "") > 0, "const_strcmp failure");
static_assert(const_strcmp("aa", "a") > 0, "const_strcmp failure");
static_assert(const_strcmp("a", "aa") < 0, "const_strcmp failure");
static_assert(const_strcmp("b", "aa") > 0, "const_strcmp failure");
/// Compile-time agnostic-size strlen/wcslen implementation. Unicode-unaware.
template <typename T, size_t N>
@ -745,9 +739,6 @@ constexpr size_t const_strlen(const T (&val)[N], ssize_t index = -1) {
// Keep back-tracking until a non-nul byte is found
: (val[index] != static_cast<T>(0) ? 0 : 1 + const_strlen(val, index - 1));
}
static_assert(const_strlen("") == 0, "const_strlen failure");
static_assert(const_strlen("a") == 1, "const_strlen failure");
static_assert(const_strlen("hello") == 5, "const_strlen failure");
/// Compile-time assertion of alphabetical sort of array `array`, by specified
/// parameter `accessor`. This is only a macro because constexpr lambdas (to