Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-03 08:13:59

0001 //===----------------------------------------------------------------------===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef _LIBCPP___PSTL_HANDLE_EXCEPTION_H
0010 #define _LIBCPP___PSTL_HANDLE_EXCEPTION_H
0011 
0012 #include <__config>
0013 #include <__new/exceptions.h>
0014 #include <__utility/forward.h>
0015 #include <__utility/move.h>
0016 #include <optional>
0017 
0018 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0019 #  pragma GCC system_header
0020 #endif
0021 
0022 _LIBCPP_PUSH_MACROS
0023 #include <__undef_macros>
0024 
0025 #if _LIBCPP_STD_VER >= 17
0026 
0027 _LIBCPP_BEGIN_NAMESPACE_STD
0028 namespace __pstl {
0029 
0030 template <class _BackendFunction, class... _Args>
0031 _LIBCPP_HIDE_FROM_ABI auto __handle_exception_impl(_Args&&... __args) noexcept {
0032   return _BackendFunction{}(std::forward<_Args>(__args)...);
0033 }
0034 
0035 // This function is used to call a backend PSTL algorithm from a frontend algorithm.
0036 //
0037 // All PSTL backend algorithms return an optional denoting whether there was an
0038 // "infrastructure"-level failure (aka failure to allocate). This function takes
0039 // care of unwrapping that and throwing `bad_alloc()` in case there was a problem
0040 // in the underlying implementation.
0041 //
0042 // We must also be careful not to call any user code that could throw an exception
0043 // (such as moving or copying iterators) in here since that should terminate the
0044 // program, which is why we delegate to a noexcept helper below.
0045 template <class _BackendFunction, class... _Args>
0046 _LIBCPP_HIDE_FROM_ABI auto __handle_exception(_Args&&... __args) {
0047   auto __result = __pstl::__handle_exception_impl<_BackendFunction>(std::forward<_Args>(__args)...);
0048   if (__result == nullopt)
0049     std::__throw_bad_alloc();
0050   else
0051     return std::move(*__result);
0052 }
0053 
0054 } // namespace __pstl
0055 _LIBCPP_END_NAMESPACE_STD
0056 
0057 #endif // _LIBCPP_STD_VER >= 17
0058 
0059 _LIBCPP_POP_MACROS
0060 
0061 #endif // _LIBCPP___PSTL_HANDLE_EXCEPTION_H