mirror of
https://github.com/gbdev/rgbds.git
synced 2026-06-10 02:32:34 +00:00
Use C++20 concepts to require constraints on template parameters (#1977)
This commit is contained in:
+5
-2
@@ -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';
|
||||
|
||||
Reference in New Issue
Block a user