From 99284049207b60abce4fa684335a2e93f973a811 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Fri, 21 May 2021 13:06:43 -0700 Subject: [PATCH] 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. --- src/common.cpp | 11 +++++++++++ src/common.h | 9 --------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/common.cpp b/src/common.cpp index 44271ee0b..3146f90d5 100644 --- a/src/common.cpp +++ b/src/common.cpp @@ -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"); diff --git a/src/common.h b/src/common.h index cbda24a56..7adb90164 100644 --- a/src/common.h +++ b/src/common.h @@ -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 @@ -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(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