向量元素分配中较早计算的内容

What is calculated earlier in vector element assignment

如果我有那行代码:

vec[f1(x, y)] = f2(a, b);

编译器 运行 首先会是什么:f1(x, y)f2(a, b)

f2(a, b) 首先计算,根据 [expr.ass#1]1(重点是我的):

[...] In all cases, the assignment is sequenced after the value computation of the right and left operands, and before the value computation of the assignment expression. The right operand is sequenced before the left operand. [...]

注意 1: 这仅适用于 C++17 及更高版本,对于以前的标准,评估顺序是特定于实现的。

注2:这不是vector item assignment特有的(标准中没有这样的东西),任何赋值(或复合赋值)都遵循这些规则。

1 这是来自C++17最新草案(第8.18节),但措辞没有改变(还),见[expr.ass#1] 在最新的草稿中。