types
int port = 443;
std::string label = "0x1RIS";
check(label + ":" + std::to_string(port) == "0x1RIS:443", "types");
That ran
Strings
std::string owns its buffer
std::string_view borrows
Use view when the data outlives the call and no copy is needed
Do not keep a view to a temporary string
Numbers
Prefer fixed width types from <cstdint> when a format depends on exact size
Otherwise int and double are fine defaults
Unsigned arithmetic wraps, signed overflow is undefined, know which one you are doing
auto
auto deduces from the initializer
Use it when the type name is noisy or obviously implied
Do not use it when the reader needs to know the exact type
Structured bindings
std::array<int, 3> fixed{1, 2, 3};
auto [a, b, c] = fixed;
Three names from one object Useful for pairs and tuples, not a replacement for clear struct fields
Next
Control in 03 control
Posted