other-languages 2025-04-24

https://www.sandordargo.com/blog/2025/04/23/cpp26-constexpr-language-changes C++ is slowly allowing more and more of the lang to be executed at compile-time.

I have really come around to "constexpr is silly, just run at comptime"

zig is early but very interesting

Zig and C++ are very different languages. I appreciate what Zig's doing with comptime, though, and even more with cross-compilation. C++'s constexpr, even in its hobbled state, enables some pretty crazy power. I think this especially comes together with if constexpr which enables compile-time branching. This way, we can write one template but have multiple different implementations within, just using concepts (compile-time predicates) to check what we want to do. We can easily check, at compile-time, "Does this T have a count member function? If so, use this branch. Otherwise, do something less efficient."

there are proposals for adding it to c++ though

C++ has consteval, which is required to run at compile-time, unlike constexpr which may run either at compile-time or run-time.

It's not quite as flexible as Zig's comptime. Especially for things like compile-time params. We can do something like that already, but it's hackier. Libs like fmt do the entire format string validation at compile-time, for example.

With that said, I'm not sure if adding comptime to C++ would make it better or worse. Does C++ need more features? 🤔