Back to home page

EIC code displayed by LXR

 
 

    


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

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___CXX03___PSTL_HANDLE_EXCEPTION_H
0010 #define _LIBCPP___CXX03___PSTL_HANDLE_EXCEPTION_H
0011 
0012 #include <__cxx03/__config>
0013 #include <__cxx03/__utility/forward.h>
0014 #include <__cxx03/__utility/move.h>
0015 #include <__cxx03/new> // __throw_bad_alloc
0016 #include <__cxx03/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 <__cxx03/__undef_macros>
0024 
0025 _LIBCPP_BEGIN_NAMESPACE_STD
0026 namespace __pstl {
0027 
0028 template <class _BackendFunction, class... _Args>
0029 _LIBCPP_HIDE_FROM_ABI auto __handle_exception_impl(_Args&&... __args) noexcept {
0030   return _BackendFunction{}(std::forward<_Args>(__args)...);
0031 }
0032 
0033 // This function is used to call a backend PSTL algorithm from a frontend algorithm.
0034 //
0035 // All PSTL backend algorithms return an optional denoting whether there was an
0036 // "infrastructure"-level failure (aka failure to allocate). This function takes
0037 // care of unwrapping that and throwing `bad_alloc()` in case there was a problem
0038 // in the underlying implementation.
0039 //
0040 // We must also be careful not to call any user code that could throw an exception
0041 // (such as moving or copying iterators) in here since that should terminate the
0042 // program, which is why we delegate to a noexcept helper below.
0043 template <class _BackendFunction, class... _Args>
0044 _LIBCPP_HIDE_FROM_ABI auto __handle_exception(_Args&&... __args) {
0045   auto __result = __pstl::__handle_exception_impl<_BackendFunction>(std::forward<_Args>(__args)...);
0046   if (__result == nullopt)
0047     std::__throw_bad_alloc();
0048   else
0049     return std::move(*__result);
0050 }
0051 
0052 } // namespace __pstl
0053 _LIBCPP_END_NAMESPACE_STD
0054 
0055 _LIBCPP_POP_MACROS
0056 
0057 #endif // _LIBCPP___CXX03___PSTL_HANDLE_EXCEPTION_H