4 ms·
I'm no C++ expert (I'm actually just starting my first job in a few weeks using it!) but is it really true that C++ exceptions have no runtime cost at all? I th
by user492966 8y ago
I'm no C++ expert (I'm actually just starting my first job in a few weeks using it!) but is it really true that C++ exceptions have no runtime cost at all? I thought various optimisations aren't possible to implement in the presence of exceptions; for example, a move constructor that isn't marked "noexcept" will not be used during a std::vector resize (instead it defers to the copy constructor), right? Isn't that a runtime cost?
- josefx 8y agoThat isn't a consequence of exceptions, it is a consequence of the fact that your move can fail and that std::vector has to maintain a sane state in the case of an error. You could write a bad::vector that just clears its contents in case of an error and it could use a throwing move just fine.