Quote:Original post by Enigma
You find it quicker and cleaner to correctly construct an array in an exception-safe manner using placement new than to use vector or another standard container [wow]?
Σnigma
Don't get me wrong, I rarely ever use new/delete, and have successfully replaced this method of dynamic allocation by relying on the vector's inherent contiguous data layout / address-of operator to interface with functions requiring a pointer.
Yes, one could definitely use the reserve function to preallocate the buffer, then use the [] or .at or some iterator to initialize/assign the elements by using a temporary object. I find however, that it can be extremely prohibitive in terms of CPU time to create temporary objects to initialize arrays as such.
I see your point, but I don't always find it to be the most optimal solution in terms of speed or plain code reuse -- I am the epitome of the programmer who consistently forgets what they were attempting to code only hours ago. :)
On one final note, exceptions to me are similar (but more than just) debug assertions. They should theoretically only occur in production code when there is a catastrophic system failure, like an out of memory state, or if there is a bug in the code which still needs to be resolved.
At that point, I rarely care what the behaviour of the application is. I either need to fix it and re-release the production code (if it's a bug), or ignore it completely since the system's whole state is way beyond the control of my app/myself.