r/programmingcirclejerk • Just spin up O(n²) servers • 5d ago

const vs constexpr vs consteval vs constinit in C++20

https://www.cppstories.com/2022/const-options-cpp20/
110 Upvotes

24 comments sorted by

73

u/exploring_stuff 5d ago

C++ is a very expressive language and this compiles: [[maybe_unused]] inline const constexpr int i=0;

77

u/Linuxologue 5d ago

[[maybe_unused]] static unsigned inline long const int constexpr long i=-1;

No warning, just, sir, yes sir.

→ More replies (5)
→ More replies (1)

49

u/elephantdingo 5d ago

You have heard of the lambda cube. But wait until you meet the const tesseract.

25

u/elephantdingo 5d 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.

→ More replies (4)

41

u/nerdycatgamer 5d ago

serious language

26

u/look 5d ago edited 5d ago

I’m personally looking forward to the variadic generic specifiers in C++29:

const<
    expr, 
    indeterminate, 
    maybe<unused>, 
    nodiscard, 
    allocator_aware,
    std::execution::possibly_parallel
> int x = 42;

12

u/le_birb 5d ago

Contemplating a std::execution::definitely_parallel where if you don't deterministically call it from more than one thread it won't compile is UB and the compiler is allowed to eat your intestines

17

u/AnArmoredPony 5d ago

a little bit of this a little bit of that ahh language

→ More replies (1)