Why vector.tcc implement _M_fill_insert by __uninitialized_move_a?

324 Views Asked by At

In gcc vector.tcc::_M_fill_insert function (line524), the implementation uses

  1. case 1: __uninitialized_move_a(line562) for case of uninitialized but existing memory;
  2. case 2: __uninitialized_move_if_noexcept_a(line580) for newly allocated memory.

I am wondering why __uninitialized_move_if_noexcept_a has not been used in case1: there is no guarantee that the copy constructor or move constructor is noexcept. If copy constructor failed, the original vector could be recovered; if move constructor throws exception, the original vector will be in a unclear state?

0

There are 0 best solutions below