by psyclobe · 1y ago · 0 comments
It’s too bad you still can’t cast a char to a uint8_t though in a constexpr expression.
#include <cstdint>
#include <print>
constexpr uint8_t f(char ch) {
return static_cast<uint8_t>(ch);
}
int main() {
constexpr uint8_t r = f('a');
std::print("{}", r);
}Could be wrong I am no expert…
What is possible in constexpr contexts has been improving in each revision, the end goal is to support the whole language, eventually.
Naturally introducing everything at once would be too hard in a language with such a big ecosystem like C++.
Uh, what? That has worked fine since the introduction of constexpr in C++11.