Q:

Initialize a C++ vector with a variable inital value

I was coding up a Union find data structure , and was trying to initialize the parent vector with a value parent[i]=i, Is there a way in c++ to initialize the vector like this , that is declaring a vector of size N , and not assigning fixed values to each element, rather position dependent value to each element. (without using any obvious for loops)
This is what I was looking for:
  std::vector<int> parent(Initializer);

where Initializer is some class or a function.
To try out my hand a bit, I wrote this:
#include <iostream>
#include <vector>
using namespace std;

class Initializer {
private:
    static int i;
public:
    int operator() ()
    {
        return i++;
    }
};

int main()
{
    vector<int> parent(Initializer);
    cout << parent[0];
    return 0;
}

However I think I have messed up my concepts pretty bad here, and I am not getting what the declaration means, or what it is doing.
Please answer both the questions,
(1) How to initialize a vector with variable initial values.
(2) What exactly is the code I wrote doing?

A:

This is a function declaration:
vector<int> parent(Initializer);

Becasue Initializer is a type name, you declared a function parent that takes Initializer as a (unnamed) parameter and returns vector<int>. See Most vexing parse.
To do what you want, you can do this:
std::vector<int> parent(N);    // where N is the size you want
std::iota(parent.begin(), parent.end(), 0);  // fill it with consecutive values
                                             // starting  with 0

There's std::generate algorithm that you can use to save result of a function (or function object) in a range:
std::generate(parent.begin(), parent.end(), Initializer());

Live demo.

