Erik Engheim
Nov 9, 2022

--

My series covering unique features is about languages I have used where particular features stuck out. Const expressions are not a central part of C++ programming. It is not something the language is centered around. Templates play a much more important part.

In Zig much of the standard library is very centered around comptime. E.g. that is how type safe printf is built.

I don’t think you could build a type safe printf function with C++ constexpr.

Zig comptime allows you to create template types. Again not something I believe constexpr can be used for.

Zig comptime gives you reflection at compile time. Does C++ give you that? You can iterate over fields of a struct or variable and lookup the type and name. Types can be treated as ordinary values. Does C++ allow you to treat types as ordinary values with constexpr?

--

--

Erik Engheim
Erik Engheim

Written by Erik Engheim

Geek dad, living in Oslo, Norway with passion for UX, Julia programming, science, teaching, reading and writing.

No responses yet