<p>Does anybody know why</p>

<pre><code>  vector&lt;int&gt; test(10);
  int a=0;

  for_each(test.begin(),test.end(),(_1+=var(a),++var(a)));

  for_each(test.begin(),test.end(),(cout &lt;&lt; _1 &lt;&lt; " "));
  cout &lt;&lt; "\n"
</code></pre>

<p>Gives :  "0 1 2 3 4 5 6 7 8 9"</p>

<p>but </p>

<pre><code>  transform(test.begin(),test.end(),test.begin(), (_1+=var(a),++var(a)));
  ...(as before)
</code></pre>

<p>Gives : "1 2 3 4 5 6 7 8 9 10"</p>

<p>?</p>

Comma operator evaluates left to right, so the result of the
```
```
_1+=var(a), ++var(a)
```
```
is ++var(a), which you'll store using the transform version.
for_each:
_1 += var(a) is evaluated, updating your sequence (via the lambda _1), then ++var(a) is evaluated, but this has no effect on your sequence.
transform:
_1+=var(a) is evaluated, updating your sequence (just like before), then ++var(a) is evaluated, this also gives the result of the whole expression, then that is used to update your sequence again (via the transform)