Cpp

C++ is an ever evolving compiled programming language. It's a super fast object oriented language.

Keywords

• Constexpr

constexpr evaluates a function or variable at compile time, as opposed to execution time.

constexpr int square(int n) {
    return n * n;
}

int main() {
    constexpr int v = square(5); // 25
}

Lambda

Lambda functions are simple small functions that don't warrant being made into a full function. They are generally only needed in the scope of the function they are declared in.

• Syntax

[] () mutable throw() -> int {
    return 5;
}
  • []: Capture clause. Specifies what variables are captured from the environment.
    • Variables prefixed with & are passed by reference, otherwise they are passed by value
    • [&]: All variables are captured by reference
    • [=]: All variables are captured by value
    • Example: [=, &var], capture all variables by value, capture "var" by reference
    • Variables cannot be repeated, for example [&, &i] has &i repeated
  • (): Parameter list. Optional. Used like a normal function's parameter list.
  • mutable: Mutable specification. Optional. Allows capture by value variables to be modified inside the lambda's body.
  • throw(...): Exception specification. Optional.
    • noexcept or throw() means no exception is thrown
    • throw(...) if an exception of any type can be thrown
    • throw(type) if an exception of type type can be thrown
  • -> int: Trailing return type. Optional. Defaults to auto
  • { ... }: Lambda body

For more information: Microsoft Docs.