typedef std::vector < std::complex < double > > complex_vec_type;
// option1
int main()
{
complex_vec_type cc ( 24000 );
complex_vec_type dd ( &cc[ 0 ], &cc[ 12000 ] );
}
versus
// option 2
int main()
{
complex_vec_type cc ( 24000 );
complex_vec_type dd ( cc.begin(), cc.begin()+12000 );
}
Does reallocation occur during construction of dd for either option?
Now if I interpret the standard, more specifically the statement ..
The constructor template <class InputIterator> vector(InputIteratorbrigns to mind the question of what are vector iterators? If memory
first, InputIterator last) makes only N calls to the copy construc-
tor of T (where N is the distance between first and last) and no
reallocations if iterators first and last are of forward, bidirec-
tional, or random access categories. It does at most 2N calls to
the copy constructor of T and logN reallocations if they are just
input iterators, since it is impossible to determine the distance
between first and last and then do copying.
serves, they meet requirements of output / input / forward and
bidirectional iterators. With regards to option 2, I'm assuming no
reallocation occurs since iterators first and last are 'forward' (
correct ? ) iterators.
Things get muddled though with the statement " does at most 2N calls
to
the copy constructor of T and logN reallocations if they are just
input iterators"
Now vector iterators meet the category of input iterators hence, what
is 'cc.begin()'? If cc.begin is an input interator then reallocations
does occur during the construction of dd. I'm a little confused.