I've read through copy_n documentation https://en.cppreference.com/w/cpp/algorithm/copy_n and there's an interesting line in Exceptions section:
What allocation is it talking about?
When we want to copy N bytes we firstly allocate a buffer ourselves with T* buffer = new T[SIZE] and then use copy_n with given SIZE
What situation when copy_n allocates memory exist?
This section is talking about the overload with a template parameter named ExecutionPolicy. That overload allows the algorithm to use multiple threads to do the copying. To facilitate that, the implementation might need to allocate some resources and that could throw.
These exceptions do not apply to the serial version of the algorithm.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With