书中C++ Core Guidelines Explained: Best Practices for Modern C++有一句话:
\n\n现代C++中有一句谚语:\xe2\x80\x9c当你使用显式循环时,你不\xe2\x80\x99不知道STL的算法。\xe2\x80\x9d
\n
我现在正在编写一个程序,它使用显式的 for 循环,在每次迭代中更改变量指向的对象,直到它指向nullptr.
for(auto object = get_object(arg);object != nullptr;object = get_object_next(arg)) {\n if (condition) {\n vector_of_objects.push_back(object);\n }\n }\nRun Code Online (Sandbox Code Playgroud)\n哪种 STL 函数比显式 for 循环更适合这种情况?
\n