Functions
Functions
Declarations, overloads, parameters, return types, and callable objects.
Functions
Declarations, overloads, parameters, return types, and callable objects.
int add(int lhs, int rhs);
int add(int lhs, int rhs) {
return lhs + rhs;
}
void log(std::string_view message, int level = 1);
void set_name(std::string& out, std::string_view value);
void print(const std::string& name);
void store(std::string name); // copy or move in
auto area(double w, double h) -> double {
return w * h;
}
void draw(int x, int y);
void draw(double x, double y);
constexprinline int triple(int x) { return x * 3; }
constexpr int square(int x) { return x * x; }
auto is_even = [](int x) { return x % 2 == 0; };
template <typename... Args>
void print_all(const Args&... args);
const& unless you intend to move from them.noexcept and contracts of intentvoid swap_buffers(Buffer& lhs, Buffer& rhs) noexcept {
lhs.swap(rhs);
}
noexcept when failure is not part of the contract.noexcept.template <typename T>
void push_name(std::vector<std::string>& names, T&& name) {
names.emplace_back(std::forward<T>(name));
}
Use forwarding references in generic wrappers that should preserve lvalue/rvalue behavior.
std::function only when you truly need type erasure and runtime polymorphism.