Is element initialization a side effect of the initializer clause?

In paragraph 8.6.4p4 N4606 we have:

In the list of initializers of the list with binding-initialization, the initializer-position, ..., are evaluated in the order in which they appear. That is, the calculation of each value and the side effect associated with the given initializer parameter sequences before each value the calculation and the side effect associated with any initializer sentence that follows it in the comma-separated list of initializers list.

In this program:

#include <algorithm>
#include <numeric>
#include <iostream>
#include <iterator>
using namespace std;

int main()
{
   int i = 0;
   int a[4] = { ++i, ++i, ++i,    // These are OK.
     accumulate(begin(a), end(a)-1, 0, plus<int>())  // Is this well-defined?
   };
   copy(begin(a), end(a), ostream_iterator<int>(cout, " "));
}

, accumulate ++i ++i . ++i initializer? accumulate 1, 2 3 ?

+4

Source: https://habr.com/ru/post/1667740/


All Articles