Fundamentals14 / 15
Up next

Structured bindings

#include <print>
#include <utility>

std::pair<int, int> min_max(int a, int b) {
    return (a < b) ? std::pair{a, b} : std::pair{b, a};
}

int main() {
    // bind both returned fields at once
    auto [lo, hi] = min_max(9, 4);
    std::println("{} {}", lo, hi);
}
What you're solving

unpack a pair or struct into names