@@ -819,7 +819,6 @@ public:
819819
820820 template <class _InputIterator , class _Sentinel >
821821 _LIBCPP_HIDE_FROM_ABI iterator __insert_after_with_sentinel (const_iterator __p, _InputIterator __f, _Sentinel __l);
822- _LIBCPP_HIDE_FROM_ABI iterator __default_insert_after (const_iterator __p, size_type __n);
823822
824823 _LIBCPP_HIDE_FROM_ABI iterator erase_after (const_iterator __p);
825824 _LIBCPP_HIDE_FROM_ABI iterator erase_after (const_iterator __f, const_iterator __l);
@@ -1129,36 +1128,6 @@ forward_list<_Tp, _Alloc>::insert_after(const_iterator __p, const value_type& __
11291128 return iterator (__r->__next_ );
11301129}
11311130
1132- template <class _Tp , class _Alloc >
1133- typename forward_list<_Tp, _Alloc>::iterator
1134- forward_list<_Tp, _Alloc>::__default_insert_after(const_iterator __p, size_type __n) {
1135- __begin_node_pointer __r = __p.__get_begin ();
1136- if (__n > 0 ) {
1137- __node_pointer __first = this ->__create_node (/* next = */ nullptr );
1138- __node_pointer __last = __first;
1139- # if _LIBCPP_HAS_EXCEPTIONS
1140- try {
1141- # endif // _LIBCPP_HAS_EXCEPTIONS
1142- for (--__n; __n != 0 ; --__n, __last = __last->__next_ ) {
1143- __last->__next_ = this ->__create_node (/* next = */ nullptr );
1144- }
1145- # if _LIBCPP_HAS_EXCEPTIONS
1146- } catch (...) {
1147- while (__first != nullptr ) {
1148- __node_pointer __next = __first->__next_ ;
1149- this ->__delete_node (__first);
1150- __first = __next;
1151- }
1152- throw ;
1153- }
1154- # endif // _LIBCPP_HAS_EXCEPTIONS
1155- __last->__next_ = __r->__next_ ;
1156- __r->__next_ = __first;
1157- __r = static_cast <__begin_node_pointer>(__last);
1158- }
1159- return iterator (__r);
1160- }
1161-
11621131template <class _Tp , class _Alloc >
11631132typename forward_list<_Tp, _Alloc>::iterator
11641133forward_list<_Tp, _Alloc>::insert_after(const_iterator __p, size_type __n, const value_type& __v) {
@@ -1271,7 +1240,31 @@ void forward_list<_Tp, _Alloc>::resize(size_type __n) {
12711240 if (__i != __e)
12721241 erase_after (__p, __e);
12731242 else {
1274- __default_insert_after (__p, __n - __sz);
1243+ __n -= __sz;
1244+ __begin_node_pointer __r = __p.__get_begin ();
1245+ if (__n > 0 ) {
1246+ __node_pointer __first = this ->__create_node (/* next = */ nullptr );
1247+ __node_pointer __last = __first;
1248+ # if _LIBCPP_HAS_EXCEPTIONS
1249+ try {
1250+ # endif // _LIBCPP_HAS_EXCEPTIONS
1251+ for (--__n; __n != 0 ; --__n, __last = __last->__next_ ) {
1252+ __last->__next_ = this ->__create_node (/* next = */ nullptr );
1253+ }
1254+ # if _LIBCPP_HAS_EXCEPTIONS
1255+ } catch (...) {
1256+ while (__first != nullptr ) {
1257+ __node_pointer __next = __first->__next_ ;
1258+ this ->__delete_node (__first);
1259+ __first = __next;
1260+ }
1261+ throw ;
1262+ }
1263+ # endif // _LIBCPP_HAS_EXCEPTIONS
1264+ __last->__next_ = __r->__next_ ;
1265+ __r->__next_ = __first;
1266+ __r = static_cast <__begin_node_pointer>(__last);
1267+ }
12751268 }
12761269}
12771270
0 commit comments