Values & References2 / 16
Up next

const& read-only borrow

#include <print>
#include <string>

// const& borrows the string with no copy and no write access
std::size_t length(const std::string& s) {
    return s.size();
}

int main() {
    std::string text = "hello";
    std::println("{}", length(text));
    // text is untouched and still owned here
    std::println("{}", text);
}
What you're solving

look without copying or changing