Good Code
The good version uses std::string_view for borrowed text. The signature communicates that the function reads the strings and does not retain them.
Lesson 04
Use const references or string_view for read-only inputs so call sites avoid copies and mutation stays visible.
#include <string_view>
bool has_review_prefix(std::string_view title, std::string_view prefix)
{
// string_view borrows read-only text without copying it.
return title.starts_with(prefix);
}#include <string>
bool has_review_prefix(std::string title, std::string prefix)
{
// Copying both strings hides the read-only intent.
title.shrink_to_fit();
return title.rfind(prefix, 0) == 0;
}The good version uses std::string_view for borrowed text. The signature communicates that the function reads the strings and does not retain them.
The bad version copies both strings, then mutates a copy inside a predicate. That makes a read-only check look heavier and less direct than it is.