C++: Difference between revisions
Line 459: | Line 459: | ||
std::cout << '\n'; | std::cout << '\n'; | ||
</syntaxhighlight> | </syntaxhighlight> | ||
===const=== | |||
For variables: | |||
# Use <code>const</code> for values initialized at runtime and won't change. | |||
# Use <code>constexpr</code> for values initialized at compile time and won't change at runtime. | |||
# Use <code>constinit</code> for values initialized at compile time and may change at runtime. | |||
For functions: | |||
# Add <code>const</code> to the end of a method declaration if it won't change the object. | |||
# Add <code>constexpr</code> if the function can be evaluated at compile time, i.e. can accepts and output <code>constexpr</code> variables. | |||
# Add <code>consteval</code> if you want to force the function to only be evaluated at compile time. | |||
==STL== | ==STL== |