示例取自 std::uninitialized_copy 可能的实现,我想知道 (void) ++current. 的含义是什么?
template<class InputIt, class NoThrowForwardIt>
NoThrowForwardIt uninitialized_copy(InputIt first, InputIt last, NoThrowForwardIt d_first)
{
using T = typename std::iterator_traits<NoThrowForwardIt>::value_type;
NoThrowForwardIt current = d_first;
try {
for (; first != last; ++first, (void) ++current) {
::new (static_cast<void*>(std::addressof(*current))) T(*first);
}
return current;
} catch (...) {
for (; d_first != current; ++d_first) {
d_first->~T();
}
throw;
}
}
我唯一的猜测是它是对编译器的提示,不要将变量视为未使用,但它已经在 *current 部分使用,另一个猜测是它是关于逗号表达式的返回类型 ++first, (void) + +电流。但是这个表达式在任何地方都没有使用,所以我不知道 authour 试图做什么