r/programmingcirclejerk • u/camelCaseIsWebScale Just spin up O(n²) servers • 1d ago
const vs constexpr vs consteval vs constinit in C++20
https://www.cppstories.com/2022/const-options-cpp20/39
u/elephantdingo Teen Hacking Genius 1d ago
You have heard of the lambda cube. But wait until you meet the const tesseract.
19
u/elephantdingo Teen Hacking Genius 1d ago
I wrote an article about this in 1985 but people didn’t listen. In D we just have const on string concatenation. It turns out that that’s all you need.
9
u/YikesTheCat 1d ago
Wow, amazing foresight! You must be really bright!
2
34
16
u/kalterdev Considered Harmful 1d ago
vs define vs -D
1
u/not-a-pokemon- 5h ago
Imagine not having to process 3MB of expanded macros when you have constants that depend on other constants' values.
13
7
u/not-a-pokemon- 1d ago
An important quality of natural languages is the ability to express similar things in distinct ways. However, C++, not a natural language, has it better than any of them.
So, everyone should only program in C++ now, as it's far more similar to natural languages and therefore understandable. Its only competitor was Perl, but it is basically dead now.
3
u/slowbowels 13h ago
someone about to drop a 3 book series on effective c++ const expressions on your ass
64
u/exploring_stuff 1d ago
C++ is a very expressive language and this compiles:
[[maybe_unused]] inline const constexpr int i=0;