On 2/27/2014 2:39 PM,
hbdev...@gmail.com wrote:
>
> The reason why I don't want to use Reset is because it holds the same code as the constructor and is only used in this case.
> So I just wondered if I could get rid of Reset and use the constructor, for both, when pushing for the first time and when resetting.
> And now, red floyd has given another reason why I might want to use the placement new in future.
>
> Thank you very much Victor and red for your help and constructive feed back
>
1. Please don't top-post.
2. I'd be VERRRRY careful about using placement new for that unless
you ABSOLUTELY POSITIVELY need to do so. I would definitely prefer
a Reset() function, or even an operator=(). Remember, readability
and maintainability trump cleverness every single time.
Also remember Hoare's law (also attributed to Knuth, or vice-versa):
"Premature optimization is the root of all evil."
Do you *really* need to do this "for efficency reasons"? Have you
actually benchmarked to see if your insertion/deletion code is a
bottleneck? Would an alternate data structure such as a std::list<>
perhaps suit your purposes better?
Think about that before embarking on this path.