Message from C, C++ talks

July 2019

— How long your explanation of that would be?

— My point is, const is enough for a novice

— Mh

— I guess we have different opinions on that :)


Yeah, then we say, that it is good to have a lot of little simple functions. We do

int calc() {
int r{ 0 };
// some shit
return r;

constexpr int important_var{ calc() }; // duh

— Thing is, we can't explain constexpr as "just slap it somewhere, it's a good stuff"

— I think constexpr is even easier to explain than plain const

— Rly? Then say what type s has in constexpr char* s{ "str" };

— And why this is a compilation error

— To a person who isn't sure how to use if

— Constexpr doesn't really say anything about the type like const does. It just tells the compiler that the value has to be known at compile time

Message permanent page

— Because you didn't mark the function as constexpr

— Constexpr implies const

constexpr int f{ 3 }; // f has type const int

— Now list all the conditions a func must meet to may be evaluated at compile time

— It may be harder than virtual functions