“复制”实现示例中的运算符优先级

Operator precedence in `copy` implementation example

本文关键字:运算符 优先级 复制 实现      更新时间:2023-10-16

我读了几行代码,在我看来应该有一些括号。

template<class InputIterator, class OutputIterator>
  OutputIterator copy ( InputIterator first, InputIterator last, OutputIterator result )
{
  while (first!=last) 
     *result++ = *first++; // <--- this line
  return result;
}

根据这里的操作符优先级表,我认为后缀自增操作应该优先,然后是解引用操作,然后是赋值操作。但在我看来,它的意图是先解引用,然后赋值,然后是后缀自增。

我读错了吗?还是表错了,还是代码段错了?还是另有隐情?

先执行后置自增操作,但是后置自增操作的返回值是指针的原始值。