constexpr
The value is evaluated at compile time instead of runtime.
Lambda Function
Assert
Assertions are statements used to test assumptions made by programmers, such as validating logic or invariants in the code. For example, we may use an assertion to check if the index of an array is within valid bounds during development.
Examples
#include <iostream>
#include <cassert>
constexpr int square(int x) { return x * x; };
// Assert that the divisor is never zero (programmer error)
void divide(int a, int b) {
assert(b != 0);
int result = a / b;
}
int main()
{
// constexpr
constexpr int n = square(5);
std::cout << n << std::endl;
// Lambda Function
auto func = [](int x){return x * x;};
return 0;
}