aboutsummaryrefslogtreecommitdiff
path: root/libcxx/include
diff options
context:
space:
mode:
Diffstat (limited to 'libcxx/include')
-rw-r--r--libcxx/include/__algorithm/find.h2
-rw-r--r--libcxx/include/__hash_table66
-rw-r--r--libcxx/include/__memory/shared_ptr.h93
-rw-r--r--libcxx/include/__memory/uninitialized_algorithms.h158
-rw-r--r--libcxx/include/__utility/scope_guard.h2
-rw-r--r--libcxx/include/__vector/vector_bool.h23
-rw-r--r--libcxx/include/deque39
-rw-r--r--libcxx/include/forward_list31
-rw-r--r--libcxx/include/future14
-rw-r--r--libcxx/include/list61
-rw-r--r--libcxx/include/string33
-rw-r--r--libcxx/include/valarray152
12 files changed, 216 insertions, 458 deletions
diff --git a/libcxx/include/__algorithm/find.h b/libcxx/include/__algorithm/find.h
index 72e201a..10379d7 100644
--- a/libcxx/include/__algorithm/find.h
+++ b/libcxx/include/__algorithm/find.h
@@ -17,12 +17,14 @@
#include <__bit/countr.h>
#include <__bit/invert_if.h>
#include <__config>
+#include <__cstddef/size_t.h>
#include <__functional/identity.h>
#include <__fwd/bit_reference.h>
#include <__iterator/segmented_iterator.h>
#include <__string/constexpr_c_functions.h>
#include <__type_traits/enable_if.h>
#include <__type_traits/invoke.h>
+#include <__type_traits/is_constant_evaluated.h>
#include <__type_traits/is_equality_comparable.h>
#include <__type_traits/is_integral.h>
#include <__type_traits/is_signed.h>
diff --git a/libcxx/include/__hash_table b/libcxx/include/__hash_table
index 2b246f8..74923ddb 100644
--- a/libcxx/include/__hash_table
+++ b/libcxx/include/__hash_table
@@ -44,6 +44,7 @@
#include <__utility/forward.h>
#include <__utility/move.h>
#include <__utility/pair.h>
+#include <__utility/scope_guard.h>
#include <__utility/swap.h>
#include <__utility/try_key_extraction.h>
#include <limits>
@@ -1317,23 +1318,14 @@ void __hash_table<_Tp, _Hash, _Equal, _Alloc>::__move_assign(__hash_table& __u,
max_load_factor() = __u.max_load_factor();
if (bucket_count() != 0) {
__next_pointer __cache = __detach();
-#if _LIBCPP_HAS_EXCEPTIONS
- try {
-#endif // _LIBCPP_HAS_EXCEPTIONS
- const_iterator __i = __u.begin();
- while (__cache != nullptr && __u.size() != 0) {
- __assign_value(__cache->__upcast()->__get_value(), std::move(__u.remove(__i++)->__get_value()));
- __next_pointer __next = __cache->__next_;
- __node_insert_multi(__cache->__upcast());
- __cache = __next;
- }
-#if _LIBCPP_HAS_EXCEPTIONS
- } catch (...) {
- __deallocate_node(__cache);
- throw;
+ auto __guard = std::__make_scope_guard([&] { __deallocate_node(__cache); });
+ const_iterator __i = __u.begin();
+ while (__cache != nullptr && __u.size() != 0) {
+ __assign_value(__cache->__upcast()->__get_value(), std::move(__u.remove(__i++)->__get_value()));
+ __next_pointer __next = __cache->__next_;
+ __node_insert_multi(__cache->__upcast());
+ __cache = __next;
}
-#endif // _LIBCPP_HAS_EXCEPTIONS
- __deallocate_node(__cache);
}
const_iterator __i = __u.begin();
while (__u.size() != 0)
@@ -1361,22 +1353,13 @@ void __hash_table<_Tp, _Hash, _Equal, _Alloc>::__assign_unique(_InputIterator __
if (bucket_count() != 0) {
__next_pointer __cache = __detach();
-#if _LIBCPP_HAS_EXCEPTIONS
- try {
-#endif // _LIBCPP_HAS_EXCEPTIONS
- for (; __cache != nullptr && __first != __last; ++__first) {
- __assign_value(__cache->__upcast()->__get_value(), *__first);
- __next_pointer __next = __cache->__next_;
- __node_insert_unique(__cache->__upcast());
- __cache = __next;
- }
-#if _LIBCPP_HAS_EXCEPTIONS
- } catch (...) {
- __deallocate_node(__cache);
- throw;
+ auto __guard = std::__make_scope_guard([&] { __deallocate_node(__cache); });
+ for (; __cache != nullptr && __first != __last; ++__first) {
+ __assign_value(__cache->__upcast()->__get_value(), *__first);
+ __next_pointer __next = __cache->__next_;
+ __node_insert_unique(__cache->__upcast());
+ __cache = __next;
}
-#endif // _LIBCPP_HAS_EXCEPTIONS
- __deallocate_node(__cache);
}
for (; __first != __last; ++__first)
__emplace_unique(*__first);
@@ -1391,22 +1374,13 @@ void __hash_table<_Tp, _Hash, _Equal, _Alloc>::__assign_multi(_InputIterator __f
"__assign_multi may only be called with the containers value type or the nodes value type");
if (bucket_count() != 0) {
__next_pointer __cache = __detach();
-#if _LIBCPP_HAS_EXCEPTIONS
- try {
-#endif // _LIBCPP_HAS_EXCEPTIONS
- for (; __cache != nullptr && __first != __last; ++__first) {
- __assign_value(__cache->__upcast()->__get_value(), *__first);
- __next_pointer __next = __cache->__next_;
- __node_insert_multi(__cache->__upcast());
- __cache = __next;
- }
-#if _LIBCPP_HAS_EXCEPTIONS
- } catch (...) {
- __deallocate_node(__cache);
- throw;
+ auto __guard = std::__make_scope_guard([&] { __deallocate_node(__cache); });
+ for (; __cache != nullptr && __first != __last; ++__first) {
+ __assign_value(__cache->__upcast()->__get_value(), *__first);
+ __next_pointer __next = __cache->__next_;
+ __node_insert_multi(__cache->__upcast());
+ __cache = __next;
}
-#endif // _LIBCPP_HAS_EXCEPTIONS
- __deallocate_node(__cache);
}
for (; __first != __last; ++__first)
__emplace_multi(*__first);
diff --git a/libcxx/include/__memory/shared_ptr.h b/libcxx/include/__memory/shared_ptr.h
index 0cbd995..e90db58 100644
--- a/libcxx/include/__memory/shared_ptr.h
+++ b/libcxx/include/__memory/shared_ptr.h
@@ -54,6 +54,7 @@
#include <__type_traits/remove_extent.h>
#include <__type_traits/remove_reference.h>
#include <__utility/declval.h>
+#include <__utility/exception_guard.h>
#include <__utility/forward.h>
#include <__utility/move.h>
#include <__utility/swap.h>
@@ -352,23 +353,16 @@ public:
template <class _Yp, class _Dp, __enable_if_t<__shared_ptr_deleter_ctor_reqs<_Dp, _Yp, _Tp>::value, int> = 0>
_LIBCPP_HIDE_FROM_ABI shared_ptr(_Yp* __p, _Dp __d) : __ptr_(__p) {
-#if _LIBCPP_HAS_EXCEPTIONS
- try {
-#endif // _LIBCPP_HAS_EXCEPTIONS
- typedef typename __shared_ptr_default_allocator<_Yp>::type _AllocT;
- typedef __shared_ptr_pointer<_Yp*, _Dp, _AllocT> _CntrlBlk;
+ auto __guard = std::__make_exception_guard([&] { __d(__p); });
+ typedef typename __shared_ptr_default_allocator<_Yp>::type _AllocT;
+ typedef __shared_ptr_pointer<_Yp*, _Dp, _AllocT> _CntrlBlk;
#ifndef _LIBCPP_CXX03_LANG
- __cntrl_ = new _CntrlBlk(__p, std::move(__d), _AllocT());
+ __cntrl_ = new _CntrlBlk(__p, std::move(__d), _AllocT());
#else
__cntrl_ = new _CntrlBlk(__p, __d, _AllocT());
#endif // not _LIBCPP_CXX03_LANG
- __enable_weak_this(__p, __p);
-#if _LIBCPP_HAS_EXCEPTIONS
- } catch (...) {
- __d(__p);
- throw;
- }
-#endif // _LIBCPP_HAS_EXCEPTIONS
+ __enable_weak_this(__p, __p);
+ __guard.__complete();
}
template <class _Yp,
@@ -376,28 +370,21 @@ public:
class _Alloc,
__enable_if_t<__shared_ptr_deleter_ctor_reqs<_Dp, _Yp, _Tp>::value, int> = 0>
_LIBCPP_HIDE_FROM_ABI shared_ptr(_Yp* __p, _Dp __d, _Alloc __a) : __ptr_(__p) {
-#if _LIBCPP_HAS_EXCEPTIONS
- try {
-#endif // _LIBCPP_HAS_EXCEPTIONS
- typedef __shared_ptr_pointer<_Yp*, _Dp, _Alloc> _CntrlBlk;
- typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2;
- typedef __allocator_destructor<_A2> _D2;
- _A2 __a2(__a);
- unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
- ::new ((void*)std::addressof(*__hold2.get()))
+ auto __guard = std::__make_exception_guard([&] { __d(__p); });
+ typedef __shared_ptr_pointer<_Yp*, _Dp, _Alloc> _CntrlBlk;
+ typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2;
+ typedef __allocator_destructor<_A2> _D2;
+ _A2 __a2(__a);
+ unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
+ ::new ((void*)std::addressof(*__hold2.get()))
#ifndef _LIBCPP_CXX03_LANG
- _CntrlBlk(__p, std::move(__d), __a);
+ _CntrlBlk(__p, std::move(__d), __a);
#else
_CntrlBlk(__p, __d, __a);
#endif // not _LIBCPP_CXX03_LANG
- __cntrl_ = std::addressof(*__hold2.release());
- __enable_weak_this(__p, __p);
-#if _LIBCPP_HAS_EXCEPTIONS
- } catch (...) {
- __d(__p);
- throw;
- }
-#endif // _LIBCPP_HAS_EXCEPTIONS
+ __cntrl_ = std::addressof(*__hold2.release());
+ __enable_weak_this(__p, __p);
+ __guard.__complete();
}
template <class _Dp>
@@ -406,22 +393,15 @@ public:
_Dp __d,
__enable_if_t<__shared_ptr_nullptr_deleter_ctor_reqs<_Dp>::value, __nullptr_sfinae_tag> = __nullptr_sfinae_tag())
: __ptr_(nullptr) {
-#if _LIBCPP_HAS_EXCEPTIONS
- try {
-#endif // _LIBCPP_HAS_EXCEPTIONS
- typedef typename __shared_ptr_default_allocator<_Tp>::type _AllocT;
- typedef __shared_ptr_pointer<nullptr_t, _Dp, _AllocT> _CntrlBlk;
+ auto __guard = std::__make_exception_guard([&] { __d(__p); });
+ typedef typename __shared_ptr_default_allocator<_Tp>::type _AllocT;
+ typedef __shared_ptr_pointer<nullptr_t, _Dp, _AllocT> _CntrlBlk;
#ifndef _LIBCPP_CXX03_LANG
- __cntrl_ = new _CntrlBlk(__p, std::move(__d), _AllocT());
+ __cntrl_ = new _CntrlBlk(__p, std::move(__d), _AllocT());
#else
__cntrl_ = new _CntrlBlk(__p, __d, _AllocT());
#endif // not _LIBCPP_CXX03_LANG
-#if _LIBCPP_HAS_EXCEPTIONS
- } catch (...) {
- __d(__p);
- throw;
- }
-#endif // _LIBCPP_HAS_EXCEPTIONS
+ __guard.__complete();
}
template <class _Dp, class _Alloc>
@@ -431,27 +411,20 @@ public:
_Alloc __a,
__enable_if_t<__shared_ptr_nullptr_deleter_ctor_reqs<_Dp>::value, __nullptr_sfinae_tag> = __nullptr_sfinae_tag())
: __ptr_(nullptr) {
-#if _LIBCPP_HAS_EXCEPTIONS
- try {
-#endif // _LIBCPP_HAS_EXCEPTIONS
- typedef __shared_ptr_pointer<nullptr_t, _Dp, _Alloc> _CntrlBlk;
- typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2;
- typedef __allocator_destructor<_A2> _D2;
- _A2 __a2(__a);
- unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
- ::new ((void*)std::addressof(*__hold2.get()))
+ auto __guard = std::__make_exception_guard([&] { __d(__p); });
+ typedef __shared_ptr_pointer<nullptr_t, _Dp, _Alloc> _CntrlBlk;
+ typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2;
+ typedef __allocator_destructor<_A2> _D2;
+ _A2 __a2(__a);
+ unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
+ ::new ((void*)std::addressof(*__hold2.get()))
#ifndef _LIBCPP_CXX03_LANG
- _CntrlBlk(__p, std::move(__d), __a);
+ _CntrlBlk(__p, std::move(__d), __a);
#else
_CntrlBlk(__p, __d, __a);
#endif // not _LIBCPP_CXX03_LANG
- __cntrl_ = std::addressof(*__hold2.release());
-#if _LIBCPP_HAS_EXCEPTIONS
- } catch (...) {
- __d(__p);
- throw;
- }
-#endif // _LIBCPP_HAS_EXCEPTIONS
+ __cntrl_ = std::addressof(*__hold2.release());
+ __guard.__complete();
}
template <class _Yp>
diff --git a/libcxx/include/__memory/uninitialized_algorithms.h b/libcxx/include/__memory/uninitialized_algorithms.h
index e802366..34d065d 100644
--- a/libcxx/include/__memory/uninitialized_algorithms.h
+++ b/libcxx/include/__memory/uninitialized_algorithms.h
@@ -61,17 +61,10 @@ template <class _ValueType, class _InputIterator, class _Sentinel1, class _Forwa
inline _LIBCPP_HIDE_FROM_ABI pair<_InputIterator, _ForwardIterator> __uninitialized_copy(
_InputIterator __ifirst, _Sentinel1 __ilast, _ForwardIterator __ofirst, _EndPredicate __stop_copying) {
_ForwardIterator __idx = __ofirst;
-#if _LIBCPP_HAS_EXCEPTIONS
- try {
-#endif
- for (; __ifirst != __ilast && !__stop_copying(__idx); ++__ifirst, (void)++__idx)
- ::new (static_cast<void*>(std::addressof(*__idx))) _ValueType(*__ifirst);
-#if _LIBCPP_HAS_EXCEPTIONS
- } catch (...) {
- std::__destroy(__ofirst, __idx);
- throw;
- }
-#endif
+ auto __guard = std::__make_exception_guard([&] { std::__destroy(__ofirst, __idx); });
+ for (; __ifirst != __ilast && !__stop_copying(__idx); ++__ifirst, (void)++__idx)
+ ::new (static_cast<void*>(std::addressof(*__idx))) _ValueType(*__ifirst);
+ __guard.__complete();
return pair<_InputIterator, _ForwardIterator>(std::move(__ifirst), std::move(__idx));
}
@@ -91,17 +84,10 @@ template <class _ValueType, class _InputIterator, class _Size, class _ForwardIte
inline _LIBCPP_HIDE_FROM_ABI pair<_InputIterator, _ForwardIterator>
__uninitialized_copy_n(_InputIterator __ifirst, _Size __n, _ForwardIterator __ofirst, _EndPredicate __stop_copying) {
_ForwardIterator __idx = __ofirst;
-#if _LIBCPP_HAS_EXCEPTIONS
- try {
-#endif
- for (; __n > 0 && !__stop_copying(__idx); ++__ifirst, (void)++__idx, (void)--__n)
- ::new (static_cast<void*>(std::addressof(*__idx))) _ValueType(*__ifirst);
-#if _LIBCPP_HAS_EXCEPTIONS
- } catch (...) {
- std::__destroy(__ofirst, __idx);
- throw;
- }
-#endif
+ auto __guard = std::__make_exception_guard([&] { std::__destroy(__ofirst, __idx); });
+ for (; __n > 0 && !__stop_copying(__idx); ++__ifirst, (void)++__idx, (void)--__n)
+ ::new (static_cast<void*>(std::addressof(*__idx))) _ValueType(*__ifirst);
+ __guard.__complete();
return pair<_InputIterator, _ForwardIterator>(std::move(__ifirst), std::move(__idx));
}
@@ -121,17 +107,10 @@ template <class _ValueType, class _ForwardIterator, class _Sentinel, class _Tp>
inline _LIBCPP_HIDE_FROM_ABI _ForwardIterator
__uninitialized_fill(_ForwardIterator __first, _Sentinel __last, const _Tp& __x) {
_ForwardIterator __idx = __first;
-#if _LIBCPP_HAS_EXCEPTIONS
- try {
-#endif
- for (; __idx != __last; ++__idx)
- ::new (static_cast<void*>(std::addressof(*__idx))) _ValueType(__x);
-#if _LIBCPP_HAS_EXCEPTIONS
- } catch (...) {
- std::__destroy(__first, __idx);
- throw;
- }
-#endif
+ auto __guard = std::__make_exception_guard([&] { std::__destroy(__first, __idx); });
+ for (; __idx != __last; ++__idx)
+ ::new (static_cast<void*>(std::addressof(*__idx))) _ValueType(__x);
+ __guard.__complete();
return __idx;
}
@@ -149,17 +128,10 @@ template <class _ValueType, class _ForwardIterator, class _Size, class _Tp>
inline _LIBCPP_HIDE_FROM_ABI _ForwardIterator
__uninitialized_fill_n(_ForwardIterator __first, _Size __n, const _Tp& __x) {
_ForwardIterator __idx = __first;
-#if _LIBCPP_HAS_EXCEPTIONS
- try {
-#endif
- for (; __n > 0; ++__idx, (void)--__n)
- ::new (static_cast<void*>(std::addressof(*__idx))) _ValueType(__x);
-#if _LIBCPP_HAS_EXCEPTIONS
- } catch (...) {
- std::__destroy(__first, __idx);
- throw;
- }
-#endif
+ auto __guard = std::__make_exception_guard([&] { std::__destroy(__first, __idx); });
+ for (; __n > 0; ++__idx, (void)--__n)
+ ::new (static_cast<void*>(std::addressof(*__idx))) _ValueType(__x);
+ __guard.__complete();
return __idx;
}
@@ -178,18 +150,11 @@ uninitialized_fill_n(_ForwardIterator __first, _Size __n, const _Tp& __x) {
template <class _ValueType, class _ForwardIterator, class _Sentinel>
inline _LIBCPP_HIDE_FROM_ABI _ForwardIterator
__uninitialized_default_construct(_ForwardIterator __first, _Sentinel __last) {
- auto __idx = __first;
-# if _LIBCPP_HAS_EXCEPTIONS
- try {
-# endif
- for (; __idx != __last; ++__idx)
- ::new (static_cast<void*>(std::addressof(*__idx))) _ValueType;
-# if _LIBCPP_HAS_EXCEPTIONS
- } catch (...) {
- std::__destroy(__first, __idx);
- throw;
- }
-# endif
+ auto __idx = __first;
+ auto __guard = std::__make_exception_guard([&] { std::__destroy(__first, __idx); });
+ for (; __idx != __last; ++__idx)
+ ::new (static_cast<void*>(std::addressof(*__idx))) _ValueType;
+ __guard.__complete();
return __idx;
}
@@ -205,17 +170,10 @@ inline _LIBCPP_HIDE_FROM_ABI void uninitialized_default_construct(_ForwardIterat
template <class _ValueType, class _ForwardIterator, class _Size>
inline _LIBCPP_HIDE_FROM_ABI _ForwardIterator __uninitialized_default_construct_n(_ForwardIterator __first, _Size __n) {
auto __idx = __first;
-# if _LIBCPP_HAS_EXCEPTIONS
- try {
-# endif
- for (; __n > 0; ++__idx, (void)--__n)
- ::new (static_cast<void*>(std::addressof(*__idx))) _ValueType;
-# if _LIBCPP_HAS_EXCEPTIONS
- } catch (...) {
- std::__destroy(__first, __idx);
- throw;
- }
-# endif
+ auto __guard = std::__make_exception_guard([&] { std::__destroy(__first, __idx); });
+ for (; __n > 0; ++__idx, (void)--__n)
+ ::new (static_cast<void*>(std::addressof(*__idx))) _ValueType;
+ __guard.__complete();
return __idx;
}
@@ -231,18 +189,11 @@ inline _LIBCPP_HIDE_FROM_ABI _ForwardIterator uninitialized_default_construct_n(
template <class _ValueType, class _ForwardIterator, class _Sentinel>
inline _LIBCPP_HIDE_FROM_ABI _ForwardIterator
__uninitialized_value_construct(_ForwardIterator __first, _Sentinel __last) {
- auto __idx = __first;
-# if _LIBCPP_HAS_EXCEPTIONS
- try {
-# endif
- for (; __idx != __last; ++__idx)
- ::new (static_cast<void*>(std::addressof(*__idx))) _ValueType();
-# if _LIBCPP_HAS_EXCEPTIONS
- } catch (...) {
- std::__destroy(__first, __idx);
- throw;
- }
-# endif
+ auto __idx = __first;
+ auto __guard = std::__make_exception_guard([&] { std::__destroy(__first, __idx); });
+ for (; __idx != __last; ++__idx)
+ ::new (static_cast<void*>(std::addressof(*__idx))) _ValueType();
+ __guard.__complete();
return __idx;
}
@@ -258,17 +209,10 @@ inline _LIBCPP_HIDE_FROM_ABI void uninitialized_value_construct(_ForwardIterator
template <class _ValueType, class _ForwardIterator, class _Size>
inline _LIBCPP_HIDE_FROM_ABI _ForwardIterator __uninitialized_value_construct_n(_ForwardIterator __first, _Size __n) {
auto __idx = __first;
-# if _LIBCPP_HAS_EXCEPTIONS
- try {
-# endif
- for (; __n > 0; ++__idx, (void)--__n)
- ::new (static_cast<void*>(std::addressof(*__idx))) _ValueType();
-# if _LIBCPP_HAS_EXCEPTIONS
- } catch (...) {
- std::__destroy(__first, __idx);
- throw;
- }
-# endif
+ auto __guard = std::__make_exception_guard([&] { std::__destroy(__first, __idx); });
+ for (; __n > 0; ++__idx, (void)--__n)
+ ::new (static_cast<void*>(std::addressof(*__idx))) _ValueType();
+ __guard.__complete();
return __idx;
}
@@ -293,19 +237,12 @@ inline _LIBCPP_HIDE_FROM_ABI pair<_InputIterator, _ForwardIterator> __uninitiali
_ForwardIterator __ofirst,
_EndPredicate __stop_moving,
_IterMove __iter_move) {
- auto __idx = __ofirst;
-# if _LIBCPP_HAS_EXCEPTIONS
- try {
-# endif
- for (; __ifirst != __ilast && !__stop_moving(__idx); ++__idx, (void)++__ifirst) {
- ::new (static_cast<void*>(std::addressof(*__idx))) _ValueType(__iter_move(__ifirst));
- }
-# if _LIBCPP_HAS_EXCEPTIONS
- } catch (...) {
- std::__destroy(__ofirst, __idx);
- throw;
+ auto __idx = __ofirst;
+ auto __guard = std::__make_exception_guard([&] { std::__destroy(__ofirst, __idx); });
+ for (; __ifirst != __ilast && !__stop_moving(__idx); ++__idx, (void)++__ifirst) {
+ ::new (static_cast<void*>(std::addressof(*__idx))) _ValueType(__iter_move(__ifirst));
}
-# endif
+ __guard.__complete();
return {std::move(__ifirst), std::move(__idx)};
}
@@ -331,18 +268,11 @@ template <class _ValueType,
class _IterMove>
inline _LIBCPP_HIDE_FROM_ABI pair<_InputIterator, _ForwardIterator> __uninitialized_move_n(
_InputIterator __ifirst, _Size __n, _ForwardIterator __ofirst, _EndPredicate __stop_moving, _IterMove __iter_move) {
- auto __idx = __ofirst;
-# if _LIBCPP_HAS_EXCEPTIONS
- try {
-# endif
- for (; __n > 0 && !__stop_moving(__idx); ++__idx, (void)++__ifirst, --__n)
- ::new (static_cast<void*>(std::addressof(*__idx))) _ValueType(__iter_move(__ifirst));
-# if _LIBCPP_HAS_EXCEPTIONS
- } catch (...) {
- std::__destroy(__ofirst, __idx);
- throw;
- }
-# endif
+ auto __idx = __ofirst;
+ auto __guard = std::__make_exception_guard([&] { std::__destroy(__ofirst, __idx); });
+ for (; __n > 0 && !__stop_moving(__idx); ++__idx, (void)++__ifirst, --__n)
+ ::new (static_cast<void*>(std::addressof(*__idx))) _ValueType(__iter_move(__ifirst));
+ __guard.__complete();
return {std::move(__ifirst), std::move(__idx)};
}
diff --git a/libcxx/include/__utility/scope_guard.h b/libcxx/include/__utility/scope_guard.h
index 3972102..db4f0e4 100644
--- a/libcxx/include/__utility/scope_guard.h
+++ b/libcxx/include/__utility/scope_guard.h
@@ -43,6 +43,8 @@ public:
#endif
};
+_LIBCPP_CTAD_SUPPORTED_FOR_TYPE(__scope_guard);
+
template <class _Func>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 __scope_guard<_Func> __make_scope_guard(_Func __func) {
return __scope_guard<_Func>(std::move(__func));
diff --git a/libcxx/include/__vector/vector_bool.h b/libcxx/include/__vector/vector_bool.h
index 7595427..6cb8f2a 100644
--- a/libcxx/include/__vector/vector_bool.h
+++ b/libcxx/include/__vector/vector_bool.h
@@ -963,21 +963,14 @@ vector<bool, _Allocator>::__insert_with_sentinel(const_iterator __position, _Inp
}
vector __v(get_allocator());
if (__first != __last) {
-#if _LIBCPP_HAS_EXCEPTIONS
- try {
-#endif // _LIBCPP_HAS_EXCEPTIONS
- __v.__assign_with_sentinel(std::move(__first), std::move(__last));
- difference_type __old_size = static_cast<difference_type>(__old_end - begin());
- difference_type __old_p = __p - begin();
- reserve(__recommend(size() + __v.size()));
- __p = begin() + __old_p;
- __old_end = begin() + __old_size;
-#if _LIBCPP_HAS_EXCEPTIONS
- } catch (...) {
- erase(__old_end, end());
- throw;
- }
-#endif // _LIBCPP_HAS_EXCEPTIONS
+ auto __guard = std::__make_exception_guard([&] { erase(__old_end, end()); });
+ __v.__assign_with_sentinel(std::move(__first), std::move(__last));
+ difference_type __old_size = static_cast<difference_type>(__old_end - begin());
+ difference_type __old_p = __p - begin();
+ reserve(__recommend(size() + __v.size()));
+ __p = begin() + __old_p;
+ __old_end = begin() + __old_size;
+ __guard.__complete();
}
__p = std::rotate(__p, __old_end, end());
insert(__p, __v.begin(), __v.end());
diff --git a/libcxx/include/deque b/libcxx/include/deque
index c8e1025..3e7ee8d85 100644
--- a/libcxx/include/deque
+++ b/libcxx/include/deque
@@ -235,6 +235,7 @@ template <class T, class Allocator, class Predicate>
# include <__type_traits/is_swappable.h>
# include <__type_traits/is_trivially_relocatable.h>
# include <__type_traits/type_identity.h>
+# include <__utility/exception_guard.h>
# include <__utility/forward.h>
# include <__utility/move.h>
# include <__utility/pair.h>
@@ -2135,22 +2136,17 @@ void deque<_Tp, _Allocator>::__add_front_capacity(size_type __n) {
size_type __ds = (__nb + __back_capacity) * __block_size - __map_.empty();
__split_buffer<pointer, __pointer_allocator&> __buf(
std::max<size_type>(2 * __map_.capacity(), __nb + __map_.size()), 0, __map_.__get_allocator());
-# if _LIBCPP_HAS_EXCEPTIONS
- try {
-# endif // _LIBCPP_HAS_EXCEPTIONS
- for (; __nb > 0; --__nb) {
- __buf.emplace_back(__alloc_traits::allocate(__a, __block_size));
- // ASan: this is empty container, we have to poison whole block
- __annotate_poison_block(std::__to_address(__buf.back()), std::__to_address(__buf.back() + __block_size));
- }
-# if _LIBCPP_HAS_EXCEPTIONS
- } catch (...) {
+ auto __guard = std::__make_exception_guard([&] {
__annotate_delete();
for (__map_pointer __i = __buf.begin(); __i != __buf.end(); ++__i)
__alloc_traits::deallocate(__a, *__i, __block_size);
- throw;
+ });
+ for (; __nb > 0; --__nb) {
+ __buf.emplace_back(__alloc_traits::allocate(__a, __block_size));
+ // ASan: this is empty container, we have to poison whole block
+ __annotate_poison_block(std::__to_address(__buf.back()), std::__to_address(__buf.back() + __block_size));
}
-# endif // _LIBCPP_HAS_EXCEPTIONS
+ __guard.__complete();
for (; __back_capacity > 0; --__back_capacity) {
__buf.emplace_back(__map_.back());
__map_.pop_back();
@@ -2254,22 +2250,17 @@ void deque<_Tp, _Allocator>::__add_back_capacity(size_type __n) {
std::max<size_type>(2 * __map_.capacity(), __nb + __map_.size()),
__map_.size() - __front_capacity,
__map_.__get_allocator());
-# if _LIBCPP_HAS_EXCEPTIONS
- try {
-# endif // _LIBCPP_HAS_EXCEPTIONS
- for (; __nb > 0; --__nb) {
- __buf.emplace_back(__alloc_traits::allocate(__a, __block_size));
- // ASan: this is an empty container, we have to poison the whole block
- __annotate_poison_block(std::__to_address(__buf.back()), std::__to_address(__buf.back() + __block_size));
- }
-# if _LIBCPP_HAS_EXCEPTIONS
- } catch (...) {
+ auto __guard = std::__make_exception_guard([&] {
__annotate_delete();
for (__map_pointer __i = __buf.begin(); __i != __buf.end(); ++__i)
__alloc_traits::deallocate(__a, *__i, __block_size);
- throw;
+ });
+ for (; __nb > 0; --__nb) {
+ __buf.emplace_back(__alloc_traits::allocate(__a, __block_size));
+ // ASan: this is an empty container, we have to poison the whole block
+ __annotate_poison_block(std::__to_address(__buf.back()), std::__to_address(__buf.back() + __block_size));
}
-# endif // _LIBCPP_HAS_EXCEPTIONS
+ __guard.__complete();
for (; __front_capacity > 0; --__front_capacity) {
__buf.emplace_back(__map_.front());
__map_.pop_front();
diff --git a/libcxx/include/forward_list b/libcxx/include/forward_list
index 05f22e3..df7da20 100644
--- a/libcxx/include/forward_list
+++ b/libcxx/include/forward_list
@@ -235,6 +235,7 @@ template <class T, class Allocator, class Predicate>
# include <__type_traits/is_swappable.h>
# include <__type_traits/remove_cv.h>
# include <__type_traits/type_identity.h>
+# include <__utility/exception_guard.h>
# include <__utility/forward.h>
# include <__utility/move.h>
# include <__utility/swap.h>
@@ -1180,22 +1181,17 @@ forward_list<_Tp, _Alloc>::__insert_after(const_iterator __p, size_type __n, _Ar
if (__n > 0) {
__node_pointer __first = this->__create_node(/* next = */ nullptr, std::forward<_Args>(__args)...);
__node_pointer __last = __first;
-# if _LIBCPP_HAS_EXCEPTIONS
- try {
-# endif // _LIBCPP_HAS_EXCEPTIONS
- for (--__n; __n != 0; --__n, __last = __last->__next_) {
- __last->__next_ = this->__create_node(/* next = */ nullptr, std::forward<_Args>(__args)...);
- }
-# if _LIBCPP_HAS_EXCEPTIONS
- } catch (...) {
+ auto __guard = std::__make_exception_guard([&] {
while (__first != nullptr) {
__node_pointer __next = __first->__next_;
this->__delete_node(__first);
__first = __next;
}
- throw;
+ });
+ for (--__n; __n != 0; --__n, __last = __last->__next_) {
+ __last->__next_ = this->__create_node(/* next = */ nullptr, std::forward<_Args>(__args)...);
}
-# endif // _LIBCPP_HAS_EXCEPTIONS
+ __guard.__complete();
__last->__next_ = __r->__next_;
__r->__next_ = __first;
__r = std::__static_fancy_pointer_cast<__begin_node_pointer>(__last);
@@ -1220,22 +1216,17 @@ forward_list<_Tp, _Alloc>::__insert_after_with_sentinel(const_iterator __p, _Inp
__node_pointer __first = this->__create_node(/* next = */ nullptr, *__f);
__node_pointer __last = __first;
-# if _LIBCPP_HAS_EXCEPTIONS
- try {
-# endif // _LIBCPP_HAS_EXCEPTIONS
- for (++__f; __f != __l; ++__f, ((void)(__last = __last->__next_))) {
- __last->__next_ = this->__create_node(/* next = */ nullptr, *__f);
- }
-# if _LIBCPP_HAS_EXCEPTIONS
- } catch (...) {
+ auto __guard = std::__make_exception_guard([&] {
while (__first != nullptr) {
__node_pointer __next = __first->__next_;
this->__delete_node(__first);
__first = __next;
}
- throw;
+ });
+ for (++__f; __f != __l; ++__f, ((void)(__last = __last->__next_))) {
+ __last->__next_ = this->__create_node(/* next = */ nullptr, *__f);
}
-# endif // _LIBCPP_HAS_EXCEPTIONS
+ __guard.__complete();
__last->__next_ = __r->__next_;
__r->__next_ = __first;
diff --git a/libcxx/include/future b/libcxx/include/future
index 3df9dc9..4b7c098 100644
--- a/libcxx/include/future
+++ b/libcxx/include/future
@@ -403,6 +403,7 @@ template <class R, class Alloc> struct uses_allocator<packaged_task<R>, Alloc>;
# include <__type_traits/strip_signature.h>
# include <__type_traits/underlying_type.h>
# include <__utility/auto_cast.h>
+# include <__utility/exception_guard.h>
# include <__utility/forward.h>
# include <__utility/move.h>
# include <__utility/swap.h>
@@ -1815,16 +1816,9 @@ template <class _Rp, class _Fp>
_LIBCPP_HIDE_FROM_ABI future<_Rp> __make_async_assoc_state(_Fp&& __f) {
unique_ptr<__async_assoc_state<_Rp, _Fp>, __release_shared_count> __h(
new __async_assoc_state<_Rp, _Fp>(std::forward<_Fp>(__f)));
-# if _LIBCPP_HAS_EXCEPTIONS
- try {
-# endif
- std::thread(&__async_assoc_state<_Rp, _Fp>::__execute, __h.get()).detach();
-# if _LIBCPP_HAS_EXCEPTIONS
- } catch (...) {
- __h->__make_ready();
- throw;
- }
-# endif
+ auto __guard = std::__make_exception_guard([&] { __h->__make_ready(); });
+ std::thread(&__async_assoc_state<_Rp, _Fp>::__execute, __h.get()).detach();
+ __guard.__complete();
return future<_Rp>(__h.get());
}
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;
}
diff --git a/libcxx/include/string b/libcxx/include/string
index 363f27a..8f80afbc 100644
--- a/libcxx/include/string
+++ b/libcxx/include/string
@@ -640,6 +640,7 @@ basic_string<char32_t> operator""s( const char32_t *str, size_t len );
# include <__type_traits/is_trivially_relocatable.h>
# include <__type_traits/remove_cvref.h>
# include <__utility/default_three_way_comparator.h>
+# include <__utility/exception_guard.h>
# include <__utility/forward.h>
# include <__utility/is_pointer_in_range.h>
# include <__utility/move.h>
@@ -1311,6 +1312,8 @@ public:
# if _LIBCPP_STD_VER >= 23
template <class _Op>
_LIBCPP_HIDE_FROM_ABI constexpr void resize_and_overwrite(size_type __n, _Op __op) {
+ using __result_type = decltype(std::move(__op)(data(), auto(__n)));
+ static_assert(__integer_like<__result_type>, "Operation return type must be integer-like");
size_type __sz = size();
size_type __cap = capacity();
if (__n > __cap)
@@ -2652,17 +2655,10 @@ basic_string<_CharT, _Traits, _Allocator>::__init_with_sentinel(_InputIterator _
__rep_ = __rep();
__annotate_new(0);
-# if _LIBCPP_HAS_EXCEPTIONS
- try {
-# endif // _LIBCPP_HAS_EXCEPTIONS
- for (; __first != __last; ++__first)
- push_back(*__first);
-# if _LIBCPP_HAS_EXCEPTIONS
- } catch (...) {
- __reset_internal_buffer();
- throw;
- }
-# endif // _LIBCPP_HAS_EXCEPTIONS
+ auto __guard = std::__make_exception_guard([this] { __reset_internal_buffer(); });
+ for (; __first != __last; ++__first)
+ push_back(*__first);
+ __guard.__complete();
}
template <class _CharT, class _Traits, class _Allocator>
@@ -2679,17 +2675,10 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
basic_string<_CharT, _Traits, _Allocator>::__init_with_size(_InputIterator __first, _Sentinel __last, size_type __sz) {
pointer __p = __init_internal_buffer(__sz);
-# if _LIBCPP_HAS_EXCEPTIONS
- try {
-# endif // _LIBCPP_HAS_EXCEPTIONS
- auto __end = __copy_non_overlapping_range(std::move(__first), std::move(__last), std::__to_address(__p));
- traits_type::assign(*__end, value_type());
-# if _LIBCPP_HAS_EXCEPTIONS
- } catch (...) {
- __reset_internal_buffer();
- throw;
- }
-# endif // _LIBCPP_HAS_EXCEPTIONS
+ auto __guard = std::__make_exception_guard([this] { __reset_internal_buffer(); });
+ auto __end = __copy_non_overlapping_range(std::move(__first), std::move(__last), std::__to_address(__p));
+ traits_type::assign(*__end, value_type());
+ __guard.__complete();
}
template <class _CharT, class _Traits, class _Allocator>
diff --git a/libcxx/include/valarray b/libcxx/include/valarray
index 96501ca..215811d 100644
--- a/libcxx/include/valarray
+++ b/libcxx/include/valarray
@@ -362,6 +362,7 @@ template <class T> unspecified2 end(const valarray<T>& v);
# include <__memory/uninitialized_algorithms.h>
# include <__type_traits/decay.h>
# include <__type_traits/remove_reference.h>
+# include <__utility/exception_guard.h>
# include <__utility/move.h>
# include <__utility/swap.h>
# include <cmath>
@@ -1992,17 +1993,10 @@ template <class _Tp>
inline valarray<_Tp>::valarray(size_t __n) : __begin_(nullptr), __end_(nullptr) {
if (__n) {
__begin_ = __end_ = allocator<value_type>().allocate(__n);
-# if _LIBCPP_HAS_EXCEPTIONS
- try {
-# endif // _LIBCPP_HAS_EXCEPTIONS
- for (size_t __n_left = __n; __n_left; --__n_left, ++__end_)
- ::new ((void*)__end_) value_type();
-# if _LIBCPP_HAS_EXCEPTIONS
- } catch (...) {
- __clear(__n);
- throw;
- }
-# endif // _LIBCPP_HAS_EXCEPTIONS
+ auto __guard = std::__make_exception_guard([&] { __clear(__n); });
+ for (size_t __n_left = __n; __n_left; --__n_left, ++__end_)
+ ::new ((void*)__end_) value_type();
+ __guard.__complete();
}
}
@@ -2015,17 +2009,10 @@ template <class _Tp>
valarray<_Tp>::valarray(const value_type* __p, size_t __n) : __begin_(nullptr), __end_(nullptr) {
if (__n) {
__begin_ = __end_ = allocator<value_type>().allocate(__n);
-# if _LIBCPP_HAS_EXCEPTIONS
- try {
-# endif // _LIBCPP_HAS_EXCEPTIONS
- for (size_t __n_left = __n; __n_left; ++__end_, ++__p, --__n_left)
- ::new ((void*)__end_) value_type(*__p);
-# if _LIBCPP_HAS_EXCEPTIONS
- } catch (...) {
- __clear(__n);
- throw;
- }
-# endif // _LIBCPP_HAS_EXCEPTIONS
+ auto __guard = std::__make_exception_guard([&] { __clear(__n); });
+ for (size_t __n_left = __n; __n_left; ++__end_, ++__p, --__n_left)
+ ::new ((void*)__end_) value_type(*__p);
+ __guard.__complete();
}
}
@@ -2033,17 +2020,10 @@ template <class _Tp>
valarray<_Tp>::valarray(const valarray& __v) : __begin_(nullptr), __end_(nullptr) {
if (__v.size()) {
__begin_ = __end_ = allocator<value_type>().allocate(__v.size());
-# if _LIBCPP_HAS_EXCEPTIONS
- try {
-# endif // _LIBCPP_HAS_EXCEPTIONS
- for (value_type* __p = __v.__begin_; __p != __v.__end_; ++__end_, ++__p)
- ::new ((void*)__end_) value_type(*__p);
-# if _LIBCPP_HAS_EXCEPTIONS
- } catch (...) {
- __clear(__v.size());
- throw;
- }
-# endif // _LIBCPP_HAS_EXCEPTIONS
+ auto __guard = std::__make_exception_guard([&] { __clear(__v.size()); });
+ for (value_type* __p = __v.__begin_; __p != __v.__end_; ++__end_, ++__p)
+ ::new ((void*)__end_) value_type(*__p);
+ __guard.__complete();
}
}
@@ -2059,18 +2039,11 @@ valarray<_Tp>::valarray(initializer_list<value_type> __il) : __begin_(nullptr),
const size_t __n = __il.size();
if (__n) {
__begin_ = __end_ = allocator<value_type>().allocate(__n);
-# if _LIBCPP_HAS_EXCEPTIONS
- try {
-# endif // _LIBCPP_HAS_EXCEPTIONS
- size_t __n_left = __n;
- for (const value_type* __p = __il.begin(); __n_left; ++__end_, ++__p, --__n_left)
- ::new ((void*)__end_) value_type(*__p);
-# if _LIBCPP_HAS_EXCEPTIONS
- } catch (...) {
- __clear(__n);
- throw;
- }
-# endif // _LIBCPP_HAS_EXCEPTIONS
+ auto __guard = std::__make_exception_guard([&] { __clear(__n); });
+ size_t __n_left = __n;
+ for (const value_type* __p = __il.begin(); __n_left; ++__end_, ++__p, --__n_left)
+ ::new ((void*)__end_) value_type(*__p);
+ __guard.__complete();
}
}
@@ -2081,18 +2054,11 @@ valarray<_Tp>::valarray(const slice_array<value_type>& __sa) : __begin_(nullptr)
const size_t __n = __sa.__size_;
if (__n) {
__begin_ = __end_ = allocator<value_type>().allocate(__n);
-# if _LIBCPP_HAS_EXCEPTIONS
- try {
-# endif // _LIBCPP_HAS_EXCEPTIONS
- size_t __n_left = __n;
- for (const value_type* __p = __sa.__vp_; __n_left; ++__end_, __p += __sa.__stride_, --__n_left)
- ::new ((void*)__end_) value_type(*__p);
-# if _LIBCPP_HAS_EXCEPTIONS
- } catch (...) {
- __clear(__n);
- throw;
- }
-# endif // _LIBCPP_HAS_EXCEPTIONS
+ auto __guard = std::__make_exception_guard([&] { __clear(__n); });
+ size_t __n_left = __n;
+ for (const value_type* __p = __sa.__vp_; __n_left; ++__end_, __p += __sa.__stride_, --__n_left)
+ ::new ((void*)__end_) value_type(*__p);
+ __guard.__complete();
}
}
@@ -2101,19 +2067,12 @@ valarray<_Tp>::valarray(const gslice_array<value_type>& __ga) : __begin_(nullptr
const size_t __n = __ga.__1d_.size();
if (__n) {
__begin_ = __end_ = allocator<value_type>().allocate(__n);
-# if _LIBCPP_HAS_EXCEPTIONS
- try {
-# endif // _LIBCPP_HAS_EXCEPTIONS
- typedef const size_t* _Ip;
- const value_type* __s = __ga.__vp_;
- for (_Ip __i = __ga.__1d_.__begin_, __e = __ga.__1d_.__end_; __i != __e; ++__i, ++__end_)
- ::new ((void*)__end_) value_type(__s[*__i]);
-# if _LIBCPP_HAS_EXCEPTIONS
- } catch (...) {
- __clear(__n);
- throw;
- }
-# endif // _LIBCPP_HAS_EXCEPTIONS
+ auto __guard = std::__make_exception_guard([&] { __clear(__n); });
+ typedef const size_t* _Ip;
+ const value_type* __s = __ga.__vp_;
+ for (_Ip __i = __ga.__1d_.__begin_, __e = __ga.__1d_.__end_; __i != __e; ++__i, ++__end_)
+ ::new ((void*)__end_) value_type(__s[*__i]);
+ __guard.__complete();
}
}
@@ -2122,19 +2081,12 @@ valarray<_Tp>::valarray(const mask_array<value_type>& __ma) : __begin_(nullptr),
const size_t __n = __ma.__1d_.size();
if (__n) {
__begin_ = __end_ = allocator<value_type>().allocate(__n);
-# if _LIBCPP_HAS_EXCEPTIONS
- try {
-# endif // _LIBCPP_HAS_EXCEPTIONS
- typedef const size_t* _Ip;
- const value_type* __s = __ma.__vp_;
- for (_Ip __i = __ma.__1d_.__begin_, __e = __ma.__1d_.__end_; __i != __e; ++__i, ++__end_)
- ::new ((void*)__end_) value_type(__s[*__i]);
-# if _LIBCPP_HAS_EXCEPTIONS
- } catch (...) {
- __clear(__n);
- throw;
- }
-# endif // _LIBCPP_HAS_EXCEPTIONS
+ auto __guard = std::__make_exception_guard([&] { __clear(__n); });
+ typedef const size_t* _Ip;
+ const value_type* __s = __ma.__vp_;
+ for (_Ip __i = __ma.__1d_.__begin_, __e = __ma.__1d_.__end_; __i != __e; ++__i, ++__end_)
+ ::new ((void*)__end_) value_type(__s[*__i]);
+ __guard.__complete();
}
}
@@ -2143,19 +2095,12 @@ valarray<_Tp>::valarray(const indirect_array<value_type>& __ia) : __begin_(nullp
const size_t __n = __ia.__1d_.size();
if (__n) {
__begin_ = __end_ = allocator<value_type>().allocate(__n);
-# if _LIBCPP_HAS_EXCEPTIONS
- try {
-# endif // _LIBCPP_HAS_EXCEPTIONS
- typedef const size_t* _Ip;
- const value_type* __s = __ia.__vp_;
- for (_Ip __i = __ia.__1d_.__begin_, __e = __ia.__1d_.__end_; __i != __e; ++__i, ++__end_)
- ::new ((void*)__end_) value_type(__s[*__i]);
-# if _LIBCPP_HAS_EXCEPTIONS
- } catch (...) {
- __clear(__n);
- throw;
- }
-# endif // _LIBCPP_HAS_EXCEPTIONS
+ auto __guard = std::__make_exception_guard([&] { __clear(__n); });
+ typedef const size_t* _Ip;
+ const value_type* __s = __ia.__vp_;
+ for (_Ip __i = __ia.__1d_.__begin_, __e = __ia.__1d_.__end_; __i != __e; ++__i, ++__end_)
+ ::new ((void*)__end_) value_type(__s[*__i]);
+ __guard.__complete();
}
}
@@ -2644,17 +2589,10 @@ void valarray<_Tp>::resize(size_t __n, value_type __x) {
__clear(size());
if (__n) {
__begin_ = __end_ = allocator<value_type>().allocate(__n);
-# if _LIBCPP_HAS_EXCEPTIONS
- try {
-# endif // _LIBCPP_HAS_EXCEPTIONS
- for (size_t __n_left = __n; __n_left; --__n_left, ++__end_)
- ::new ((void*)__end_) value_type(__x);
-# if _LIBCPP_HAS_EXCEPTIONS
- } catch (...) {
- __clear(__n);
- throw;
- }
-# endif // _LIBCPP_HAS_EXCEPTIONS
+ auto __guard = std::__make_exception_guard([&] { __clear(__n); });
+ for (size_t __n_left = __n; __n_left; --__n_left, ++__end_)
+ ::new ((void*)__end_) value_type(__x);
+ __guard.__complete();
}
}