Visit svelte.dev/docs/kit to read the documentation
blah blah blah
Unpack compound values (pairs, tuples, arrays, objects, structs) into named variables in a single declaration. Eliminates index noise and .first/.second boilerplate.
pair / tuple pair / tuple
auto [x, y] = std::pair{1, 2};
auto [name, age] = std::tuple{"alice", 30};
map iteration
for (auto& [key, val] : my_map) {
std::cout << key << ": " << val << '\n';
}
insert result
auto [it, inserted] = my_set.insert(42);
if (inserted) { /* new element */ }
plain aggregate struct
struct Point { int x, y; };
auto [px, py] = Point{3, 4};
Warning
C++ binding are copies by default. Use auto& in loops to avoid copying every element. Use const auto& when mutation isn't needed.
array destructuring
const [a, b, ...rest] = arr;
const [, second] = list; // skip first
object destructuring + defaults
const { name, age = 0, address: { city } } = user;
function parameters
function greet({ name, role = 'guest' }) {
return `hi ${name} (${role})`;
}
swap without temp
[a, b] = [b, a];