by rwmj · 5y ago · 0 comments
#if LIBVERSION >= 2
draw_point (2, 3, RED);
#else
set_color (RED);
draw_point (2, 3);
#endif
This is actually a case where the C preprocessor would be useful in many more languages. OCaml has cppo which is like a better cpp and is very useful for solving these sorts of problems. (https://github.com/ocaml-community/cppo)https://www.godbolt.org/z/4KK997
PS: interesting to note that Zig does the "right thing":
Andrei Alexandrescu mentions it in a talk, if constexpr doesn't really do much of anything useful because it introduces a scope.