Clang-Tidy: Pass by value and use std::move
时间: 2024-06-05 15:12:59 浏览: 188
Clang-Tidy is a static analysis tool for C++ code that helps identify potential bugs or issues in the code. One of the checks it can perform is to suggest passing arguments by value and using std::move instead of passing by reference.
Passing arguments by value means that a copy of the argument is made and passed to the function. This can be more efficient than passing by reference if the argument is small enough to be copied quickly. Additionally, passing by value can improve code safety because it avoids the possibility of accidentally modifying the original object.
Using std::move can improve efficiency when dealing with large objects or objects that are expensive to copy. std::move allows the contents of an object to be moved to a new location without copying, which can be much faster than copying the entire object.
In summary, Clang-Tidy is suggesting to pass arguments by value and use std::move to improve code efficiency and safety.
阅读全文