D
David
Suppose that I have a class A with a constructor A(B b, C c) and I want
to make a vector of A's. Also, suppose that A's are VERY expensive to
construct, copy, assign. I also want to have a very many vectors of A's
and cannot afford to store a smart pointer to each A as the type in my
vectors.. So I want to write something like:
v.push_back(A(b1,c1));
and not have a sequence which goes like:
.... make space for an A in v at v...
construct A() in v
destruct v
assign A(b1,c1) to v
Unfortunately, this is the behaviour I am seeing in my compiler. I want:
.... make space for an A in v at v...
construct A(b1,c1) in v
Is there any known way to ensure that compilers will give the latter
code? I have a work around, but it is clunky...
Cheers
David
to make a vector of A's. Also, suppose that A's are VERY expensive to
construct, copy, assign. I also want to have a very many vectors of A's
and cannot afford to store a smart pointer to each A as the type in my
vectors.. So I want to write something like:
v.push_back(A(b1,c1));
and not have a sequence which goes like:
.... make space for an A in v at v...
construct A() in v
destruct v
assign A(b1,c1) to v
Unfortunately, this is the behaviour I am seeing in my compiler. I want:
.... make space for an A in v at v...
construct A(b1,c1) in v
Is there any known way to ensure that compilers will give the latter
code? I have a work around, but it is clunky...
Cheers
David