我在Stroustrup的一本书中找到了这段代码:
void print_book(const vector<Entry>& book)
{
for (const auto& x : book) // for "auto" see §1.5
cout << x << '\n';
}
Run Code Online (Sandbox Code Playgroud)
但const似乎是多余的,因为x会被推断为一个const_iterator,因为book是const在参数.是const auto真的更好吗?