Message from C, C++ talks

July 2019

— You can find them in cppreference. In C+11 were restricted to a single return statement, but they relaxed that in C++14. You can do pretty much anything that doesn't involve dynamic allocations

Message permanent page

— Remember, we're talking about novices: people, who hasn't even heard about classes e.g. They're struggling with unformatted text output

Message permanent page

— It's as simple as "constexpr implies compile time execution instead of runtime"

— If you have constexpr int sum(int lhs, int rhs){ return lhs + rhs; }, what you're telling the compiler is "Hey, do this at compile time if you can"

Message permanent page

— 

In C++20 we will have inmediate functions, which will be marked as consteval. This forces the function to be executed at compile time

— First bullet:
> its return type must be a LiteralType
Okay. Let's take a look
> possibly cv-qualified (da hell?) void
Well, that's relatively easy to google
> trivial dtor, aggregate, closure
Et cetera

Message permanent page

— One need to know hella lot terms and principles to understand conxtexpr conditions

— It may sound easy for one who faced this things a lot

— I don't even understand all of them. I just program functions normally, mark them as contexpr and wait for the compiler to tell me what's wrong and adapt as I go

Message permanent page

— Just avoid dynamic allocations and you're good to go

— They're not used for everything, but if you think your function is quite simple, just mark it as constexpr and the compiler will execute at compile time everytime it can

Message permanent page

— A lot of work for like fifth example after hello world

— It's not that difficult. You just want to know EVERYTHING, which isn't really necessary

— > mark them as contexpr and wait for the compiler to tell me what's wrong and adapt as I go
That's a way actually. But what we want them to learn is const. And slapping constexpr everywhere explains neither const nor constexpr

Message permanent page

— I admit I may've crossed a line, but I do think every single word in a program should be clear to one who writes it, especially if one learns a language

Message permanent page