30 #ifndef _GLIBCXX_NESTED_EXCEPTION_H
31 #define _GLIBCXX_NESTED_EXCEPTION_H 1
33 #pragma GCC visibility push(default)
35 #if __cplusplus < 201103L
67 rethrow_nested()
const
75 nested_ptr()
const noexcept
79 template<
typename _Except>
82 explicit _Nested_exception(
const _Except& __ex)
86 explicit _Nested_exception(_Except&& __ex)
87 : _Except(static_cast<_Except&&>(__ex))
94 template<
typename _Tp>
96 __throw_with_nested_impl(_Tp&& __t,
true_type)
98 using _Up =
typename remove_reference<_Tp>::type;
99 throw _Nested_exception<_Up>{std::forward<_Tp>(__t)};
102 template<
typename _Tp>
104 __throw_with_nested_impl(_Tp&& __t,
false_type)
105 {
throw std::forward<_Tp>(__t); }
109 template<
typename _Tp>
114 using _Up =
typename decay<_Tp>::type;
115 using _CopyConstructible
116 = __and_<is_copy_constructible<_Up>, is_move_constructible<_Up>>;
117 static_assert(_CopyConstructible::value,
118 "throw_with_nested argument must be CopyConstructible");
119 using __nest = __and_<is_class<_Up>,
__bool_constant<!__is_final(_Up)>,
120 __not_<is_base_of<nested_exception, _Up>>>;
121 std::__throw_with_nested_impl(std::forward<_Tp>(__t), __nest{});
125 template<
typename _Tp>
126 using __rethrow_if_nested_cond =
typename enable_if<
127 __and_<is_polymorphic<_Tp>,
128 __or_<__not_<is_base_of<nested_exception, _Tp>>,
129 is_convertible<_Tp*, nested_exception*>>>::value
133 template<
typename _Ex>
134 inline __rethrow_if_nested_cond<_Ex>
135 __rethrow_if_nested_impl(
const _Ex* __ptr)
137 if (
auto __ne_ptr = dynamic_cast<const nested_exception*>(__ptr))
138 __ne_ptr->rethrow_nested();
143 __rethrow_if_nested_impl(
const void*)
147 template<
typename _Ex>
159 #pragma GCC visibility pop
161 #endif // _GLIBCXX_NESTED_EXCEPTION_H