更新时间:2023-11-11 16:21:34
当所需的 y
类型为:
expr
类型不同(或可能不同)。如果相同,则 auto
会更简洁。 auto&
或 auto
可以表示的 expr
类型的其他修改。expr
. If it was the same then auto
would be more concise.auto &
or other modifications of the type of expr
that auto
can express.和以下其中一项:
decltype
可能不会使您定义一个。 decltype
would save you defining one.因此例如替换 std :: iterator_traits< RandomAccessIterator> ; :: value_type
与 decltype(* it)
可能是一个胜利,尽管 auto
确实会处理这类情况。
So for example replacing std::iterator_traits<RandomAccessIterator>::value_type
with decltype(*it)
might well be a win, although auto
does often handle such cases.
主观判断是在困难是什么,困难是什么和清楚是什么的时候输入的,但是无论您如何在特定情况下做出这些判断,程序规则都可以相同。
Subjective judgements enter at the point of "what is difficult", "what is long-winded" and "what is clear", but the rules of procedure can be the same regardless of how you make those judgements in specific cases.