我使用git blame命令来查看在哪个提交中添加了一些特定的代码行,但是有时我碰到同样的问题:有人进行了某种代码格式化,或者更改了功能接口并刷新了所有客户端代码。
最终,git blame仅向我显示了对特定代码行的最后一次提交。如何忽略此提交并查看之前发生了什么?
当然,我可以在进行格式编辑的提交之前检出提交,然后再次指责,但是在大型项目上可能要花费很多时间,因此不合适。
CustomDynamicArray类包装std::vector并通过重载运算符通过索引对提供对其项目的访问operator()
CustomCell& CustomDynamicArray::operator()(size_t colIdx, size_t rowIdx)
Run Code Online (Sandbox Code Playgroud)
它使得以自然的方式寻址数组项成为可能:
CustomDynamicArray _field;
_field(x, y) = cell;
const CustomCell& currentCell = _field(x, y);
Run Code Online (Sandbox Code Playgroud)
但由于我将变量覆盖到std::shared_ptr我有一个错误
std::shared_ptr<CustomDynamicArray> _fieldPtr;
_fieldPtr(x, y) = cell; // Error! C2064 term does not evaluate to a function taking 2 arguments
const CustomCell& currentCell = _fieldPtr(x, y); // Error! C2064 term does not evaluate to a function taking 2 arguments
Run Code Online (Sandbox Code Playgroud)
我该如何修复这个编译错误?现在我只能看到使用此语法的方法:
(*_newCells)(x, y) = cell;
Run Code Online (Sandbox Code Playgroud) 我注意到在项目中,我在很多地方使用了lambda表达式来捕获指针,但是并未使用它。它是否会导致某种开销,例如指针复制或由编译器进行优化?
void MyClass::SomeFunction()
{
...
grid->ForEachItem([this](const Item& item)
{
// Some code doesn't use this
}
}
Run Code Online (Sandbox Code Playgroud)
相同的问题专门用于通过引用捕获所有信息[&]