h22*_*h22 5 c++ constructor tensorflow
In TensorFlow's documentation, it is possible to find the following text:
// Not recommended
MatMul m(scope, a, b);
// Recommended
auto m = MatMul(scope, a, b);
Run Code Online (Sandbox Code Playgroud)
I see no obvious benefit from using the "recommended" style. The first version is shorter at least. Also the "recommended" version might include more actions related to the unnecessary assignment operation.
I have read that documentation page no less than six times and still cannot get the rationale behind their reasoning.
Is this recommendation just a matter of style or may the second version have some benefits?
此外,“推荐”版本可能包括更多与不必要的赋值操作相关的操作。
没有任务。这是初始化。原则上可能存在的任何额外对象在任何值得使用的编译器中都被完全忽略。
您引用的建议与Herb Sutter 的“几乎总是自动”建议一致。支持这种风格的最强点(完全公开,我不遵循)是它使得不可能让变量处于未初始化状态。
auto foo; // ill-formed.
int foo; // indeterminate value
auto foo = int(); // a zero integer
Run Code Online (Sandbox Code Playgroud)
当然,一个好的静态分析工具也可以对此发出警告,但这仍然是一个非常强的点,不需要编译器或外部工具进行额外的分析。
除此之外,风格论点是它还可以使您的代码与您auto出于理智而使用的情况保持一致,例如
auto it = myVec.begin();
Run Code Online (Sandbox Code Playgroud)
但从各方面来说,YMMV 都是如此。这最终将是一种风格选择,无论选择哪种风格,两种风格都存在例外。
| 归档时间: |
|
| 查看次数: |
120 次 |
| 最近记录: |