Path: blob/main/contrib/llvm-project/libcxx/include/__pstl/handle_exception.h
35233 views
//===----------------------------------------------------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#ifndef _LIBCPP___PSTL_HANDLE_EXCEPTION_H9#define _LIBCPP___PSTL_HANDLE_EXCEPTION_H1011#include <__config>12#include <__utility/forward.h>13#include <__utility/move.h>14#include <new> // __throw_bad_alloc15#include <optional>1617#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)18# pragma GCC system_header19#endif2021_LIBCPP_PUSH_MACROS22#include <__undef_macros>2324_LIBCPP_BEGIN_NAMESPACE_STD25namespace __pstl {2627template <class _BackendFunction, class... _Args>28_LIBCPP_HIDE_FROM_ABI auto __handle_exception_impl(_Args&&... __args) noexcept {29return _BackendFunction{}(std::forward<_Args>(__args)...);30}3132// This function is used to call a backend PSTL algorithm from a frontend algorithm.33//34// All PSTL backend algorithms return an optional denoting whether there was an35// "infrastructure"-level failure (aka failure to allocate). This function takes36// care of unwrapping that and throwing `bad_alloc()` in case there was a problem37// in the underlying implementation.38//39// We must also be careful not to call any user code that could throw an exception40// (such as moving or copying iterators) in here since that should terminate the41// program, which is why we delegate to a noexcept helper below.42template <class _BackendFunction, class... _Args>43_LIBCPP_HIDE_FROM_ABI auto __handle_exception(_Args&&... __args) {44auto __result = __pstl::__handle_exception_impl<_BackendFunction>(std::forward<_Args>(__args)...);45if (__result == nullopt)46std::__throw_bad_alloc();47else48return std::move(*__result);49}5051} // namespace __pstl52_LIBCPP_END_NAMESPACE_STD5354_LIBCPP_POP_MACROS5556#endif // _LIBCPP___PSTL_HANDLE_EXCEPTION_H575859