aboutsummaryrefslogtreecommitdiff
path: root/libcxx/include/list
diff options
context:
space:
mode:
Diffstat (limited to 'libcxx/include/list')
-rw-r--r--libcxx/include/list61
1 files changed, 21 insertions, 40 deletions
diff --git a/libcxx/include/list b/libcxx/include/list
index 996dbfd..c5c2a85 100644
--- a/libcxx/include/list
+++ b/libcxx/include/list
@@ -237,6 +237,7 @@ template <class T, class Allocator, class Predicate>
# include <__type_traits/is_pointer.h>
# include <__type_traits/is_same.h>
# include <__type_traits/type_identity.h>
+# include <__utility/exception_guard.h>
# include <__utility/forward.h>
# include <__utility/move.h>
# include <__utility/swap.h>
@@ -1233,14 +1234,7 @@ list<_Tp, _Alloc>::insert(const_iterator __p, size_type __n, const value_type& _
++__ds;
__r = iterator(__node->__as_link());
iterator __e = __r;
-# if _LIBCPP_HAS_EXCEPTIONS
- try {
-# endif // _LIBCPP_HAS_EXCEPTIONS
- for (--__n; __n != 0; --__n, (void)++__e, ++__ds) {
- __e.__ptr_->__next_ = this->__create_node(/* prev = */ __e.__ptr_, /* next = */ nullptr, __x)->__as_link();
- }
-# if _LIBCPP_HAS_EXCEPTIONS
- } catch (...) {
+ auto __guard = std::__make_exception_guard([&] {
while (true) {
__base_pointer __prev = __e.__ptr_->__prev_;
__node_pointer __current = __e.__ptr_->__as_node();
@@ -1249,9 +1243,11 @@ list<_Tp, _Alloc>::insert(const_iterator __p, size_type __n, const value_type& _
break;
__e = iterator(__prev);
}
- throw;
+ });
+ for (--__n; __n != 0; --__n, (void)++__e, ++__ds) {
+ __e.__ptr_->__next_ = this->__create_node(/* prev = */ __e.__ptr_, /* next = */ nullptr, __x)->__as_link();
}
-# endif // _LIBCPP_HAS_EXCEPTIONS
+ __guard.__complete();
__link_nodes(__p.__ptr_, __r.__ptr_, __e.__ptr_);
this->__size_ += __ds;
}
@@ -1276,14 +1272,7 @@ list<_Tp, _Alloc>::__insert_with_sentinel(const_iterator __p, _Iterator __f, _Se
++__ds;
__r = iterator(__node->__as_link());
iterator __e = __r;
-# if _LIBCPP_HAS_EXCEPTIONS
- try {
-# endif // _LIBCPP_HAS_EXCEPTIONS
- for (++__f; __f != __l; ++__f, (void)++__e, ++__ds) {
- __e.__ptr_->__next_ = this->__create_node(/* prev = */ __e.__ptr_, /* next = */ nullptr, *__f)->__as_link();
- }
-# if _LIBCPP_HAS_EXCEPTIONS
- } catch (...) {
+ auto __guard = std::__make_exception_guard([&] {
while (true) {
__base_pointer __prev = __e.__ptr_->__prev_;
__node_pointer __current = __e.__ptr_->__as_node();
@@ -1292,9 +1281,11 @@ list<_Tp, _Alloc>::__insert_with_sentinel(const_iterator __p, _Iterator __f, _Se
break;
__e = iterator(__prev);
}
- throw;
+ });
+ for (++__f; __f != __l; ++__f, (void)++__e, ++__ds) {
+ __e.__ptr_->__next_ = this->__create_node(/* prev = */ __e.__ptr_, /* next = */ nullptr, *__f)->__as_link();
}
-# endif // _LIBCPP_HAS_EXCEPTIONS
+ __guard.__complete();
__link_nodes(__p.__ptr_, __r.__ptr_, __e.__ptr_);
this->__size_ += __ds;
}
@@ -1452,14 +1443,7 @@ _LIBCPP_CONSTEXPR_SINCE_CXX26 void list<_Tp, _Alloc>::resize(size_type __n) {
++__ds;
iterator __r = iterator(__node->__as_link());
iterator __e = __r;
-# if _LIBCPP_HAS_EXCEPTIONS
- try {
-# endif // _LIBCPP_HAS_EXCEPTIONS
- for (--__n; __n != 0; --__n, (void)++__e, ++__ds) {
- __e.__ptr_->__next_ = this->__create_node(/* prev = */ __e.__ptr_, /* next = */ nullptr)->__as_link();
- }
-# if _LIBCPP_HAS_EXCEPTIONS
- } catch (...) {
+ auto __guard = std::__make_exception_guard([&] {
while (true) {
__base_pointer __prev = __e.__ptr_->__prev_;
__node_pointer __current = __e.__ptr_->__as_node();
@@ -1468,9 +1452,11 @@ _LIBCPP_CONSTEXPR_SINCE_CXX26 void list<_Tp, _Alloc>::resize(size_type __n) {
break;
__e = iterator(__prev);
}
- throw;
+ });
+ for (--__n; __n != 0; --__n, (void)++__e, ++__ds) {
+ __e.__ptr_->__next_ = this->__create_node(/* prev = */ __e.__ptr_, /* next = */ nullptr)->__as_link();
}
-# endif // _LIBCPP_HAS_EXCEPTIONS
+ __guard.__complete();
__link_nodes_at_back(__r.__ptr_, __e.__ptr_);
this->__size_ += __ds;
}
@@ -1488,14 +1474,7 @@ _LIBCPP_CONSTEXPR_SINCE_CXX26 void list<_Tp, _Alloc>::resize(size_type __n, cons
__base_pointer __nl = __node->__as_link();
iterator __r = iterator(__nl);
iterator __e = __r;
-# if _LIBCPP_HAS_EXCEPTIONS
- try {
-# endif // _LIBCPP_HAS_EXCEPTIONS
- for (--__n; __n != 0; --__n, (void)++__e, ++__ds) {
- __e.__ptr_->__next_ = this->__create_node(/* prev = */ __e.__ptr_, /* next = */ nullptr, __x)->__as_link();
- }
-# if _LIBCPP_HAS_EXCEPTIONS
- } catch (...) {
+ auto __guard = std::__make_exception_guard([&] {
while (true) {
__base_pointer __prev = __e.__ptr_->__prev_;
__node_pointer __current = __e.__ptr_->__as_node();
@@ -1504,9 +1483,11 @@ _LIBCPP_CONSTEXPR_SINCE_CXX26 void list<_Tp, _Alloc>::resize(size_type __n, cons
break;
__e = iterator(__prev);
}
- throw;
+ });
+ for (--__n; __n != 0; --__n, (void)++__e, ++__ds) {
+ __e.__ptr_->__next_ = this->__create_node(/* prev = */ __e.__ptr_, /* next = */ nullptr, __x)->__as_link();
}
-# endif // _LIBCPP_HAS_EXCEPTIONS
+ __guard.__complete();
__link_nodes(__base::__end_as_link(), __r.__ptr_, __e.__ptr_);
this->__size_ += __ds;
}