How to define vectors in an existing vector ?

Hi all,
I have defined a big vector :

vector<int> v(1000000);

If I initialise it like this :

for (int i = 0; i < 1000000; i++) v[i] = i;

I would like to do something like the following pseudo-code :

1
2
3
vector<int>* pv1 = &(v[1618]), pv2 = &(v[1620]);
pv1->size = 4;
pv2->size = 3;


To obtain :

1
2
3
ostream_iterator<int> out(cout, " ");
cout << "pv1 = "; copy(pv1->begin(), pv1->end(), out); cout << endl;
cout << "pv1 = "; copy(pv1->begin(), pv1->end(), out); cout << endl;


pv1 = 1618 1619 1620 1621
pv2 = 1620 1621 1622


How to do that with vectors ?
I can do it with arrays, but I would like to stay with vectors if possible.
template <class InputIterator> vector ( InputIterator first, InputIterator last, const Allocator& = Allocator() );

Iteration constructor: Iterates between first and last, setting a copy of each of the sequence of elements as the content of the container.

is constructor may meet your request.
Thanks for your answer fanasy, but this constructor makes copies, what is not acceptable for me because I have to manipulate huge chunks of data.
If the object of the exercise is just to ouput some sub_part of the original vector - then
there is no need to make new vectors - just set a vector_iterator ( lets call it pv1) to the first element, loop until pv1+x (where x is the number of elements required to output).

However, if you really want to create a second vector then you have no choice but to copy.
(I'm waiting...)

NOTE: certainly in the context of an ostream iterator, the copy function does not actually make
a copy (it doesn't need to) - it just does the usual ostream << object
thing.
Thanks guestgulkan. Of course, my example is simple for clarity.

So I am back to arrays.

Thought, to clarify my need : I want to create a big hash table class that will be loaded in shared memory with a lot of methods using side tables of different sizes. So I want these tables to be stored in a continuous array of memory.
Topic archived. No new replies allowed.