I have a pattern in which I want to fill an array:
even indices value = -1
odd indices value = 1
I currently achieve it like this:
#include <array>
#include <algorithm>
using namespace std;
int generator(){
static int i = 1;
i *= -1;
return i;
}
std::array<int ,64> arr;
std::generate(arr.begin(), arr.end(), generator);
Edit: Current implementation has a caveat - returned value of generator doesn't depend on iteration's object index.
Is there a way to pass current index to the generator function so it's output will depend on this index?