Use C++20 concepts to require constraints on template parameters (#1977)

This commit is contained in:
Rangi
2026-05-22 17:54:34 -04:00
committed by GitHub
parent 728bed39d5
commit dce14fd4b8
12 changed files with 64 additions and 27 deletions
+5 -2
View File
@@ -39,8 +39,11 @@ bool startsIdentifier(int c);
bool continuesIdentifier(int c);
template<uint32_t Base>
inline constexpr bool BaseV = Base > 0 && Base <= 36;
template<uint32_t Base>
requires BaseV<Base>
bool isDigit(int c) {
static_assert(Base <= 36, "Base must be 36 or less to allow digits 0-9A-Z");
if constexpr (Base <= 10) {
return c >= '0' && c < static_cast<int>('0' + Base);
} else {
@@ -50,8 +53,8 @@ bool isDigit(int c) {
}
template<uint32_t Base>
requires BaseV<Base>
uint8_t parseDigit(int c) {
static_assert(Base <= 36, "Base must be 36 or less to allow digits 0-9A-Z");
assume(isDigit<Base>(c));
if constexpr (Base <= 10) {
return c - '0';