Back to home page

EIC code displayed by LXR

 
 

    


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

0001 // -*- C++ -*-
0002 //===----------------------------------------------------------------------===//
0003 //
0004 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0005 // See https://llvm.org/LICENSE.txt for license information.
0006 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0007 //
0008 //===----------------------------------------------------------------------===//
0009 
0010 #ifndef _LIBCPP___CXX03___PSTL_BACKENDS_SERIAL_H
0011 #define _LIBCPP___CXX03___PSTL_BACKENDS_SERIAL_H
0012 
0013 #include <__cxx03/__algorithm/find_if.h>
0014 #include <__cxx03/__algorithm/for_each.h>
0015 #include <__cxx03/__algorithm/merge.h>
0016 #include <__cxx03/__algorithm/stable_sort.h>
0017 #include <__cxx03/__algorithm/transform.h>
0018 #include <__cxx03/__config>
0019 #include <__cxx03/__numeric/transform_reduce.h>
0020 #include <__cxx03/__pstl/backend_fwd.h>
0021 #include <__cxx03/__utility/empty.h>
0022 #include <__cxx03/__utility/forward.h>
0023 #include <__cxx03/__utility/move.h>
0024 #include <__cxx03/optional>
0025 
0026 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0027 #  pragma GCC system_header
0028 #endif
0029 
0030 _LIBCPP_PUSH_MACROS
0031 #include <__cxx03/__undef_macros>
0032 
0033 _LIBCPP_BEGIN_NAMESPACE_STD
0034 namespace __pstl {
0035 
0036 //
0037 // This partial PSTL backend runs everything serially.
0038 //
0039 // TODO: Right now, the serial backend must be used with another backend
0040 //       like the "default backend" because it doesn't implement all the
0041 //       necessary PSTL operations. It would be better to dispatch all
0042 //       algorithms to their serial counterpart directly, since this can
0043 //       often be more efficient than the "default backend"'s implementation
0044 //       if we end up running serially anyways.
0045 //
0046 
0047 template <class _ExecutionPolicy>
0048 struct __find_if<__serial_backend_tag, _ExecutionPolicy> {
0049   template <class _Policy, class _ForwardIterator, class _Pred>
0050   _LIBCPP_HIDE_FROM_ABI optional<_ForwardIterator>
0051   operator()(_Policy&&, _ForwardIterator __first, _ForwardIterator __last, _Pred&& __pred) const noexcept {
0052     return std::find_if(std::move(__first), std::move(__last), std::forward<_Pred>(__pred));
0053   }
0054 };
0055 
0056 template <class _ExecutionPolicy>
0057 struct __for_each<__serial_backend_tag, _ExecutionPolicy> {
0058   template <class _Policy, class _ForwardIterator, class _Function>
0059   _LIBCPP_HIDE_FROM_ABI optional<__empty>
0060   operator()(_Policy&&, _ForwardIterator __first, _ForwardIterator __last, _Function&& __func) const noexcept {
0061     std::for_each(std::move(__first), std::move(__last), std::forward<_Function>(__func));
0062     return __empty{};
0063   }
0064 };
0065 
0066 template <class _ExecutionPolicy>
0067 struct __merge<__serial_backend_tag, _ExecutionPolicy> {
0068   template <class _Policy, class _ForwardIterator1, class _ForwardIterator2, class _ForwardOutIterator, class _Comp>
0069   _LIBCPP_HIDE_FROM_ABI optional<_ForwardOutIterator> operator()(
0070       _Policy&&,
0071       _ForwardIterator1 __first1,
0072       _ForwardIterator1 __last1,
0073       _ForwardIterator2 __first2,
0074       _ForwardIterator2 __last2,
0075       _ForwardOutIterator __outit,
0076       _Comp&& __comp) const noexcept {
0077     return std::merge(
0078         std::move(__first1),
0079         std::move(__last1),
0080         std::move(__first2),
0081         std::move(__last2),
0082         std::move(__outit),
0083         std::forward<_Comp>(__comp));
0084   }
0085 };
0086 
0087 template <class _ExecutionPolicy>
0088 struct __stable_sort<__serial_backend_tag, _ExecutionPolicy> {
0089   template <class _Policy, class _RandomAccessIterator, class _Comp>
0090   _LIBCPP_HIDE_FROM_ABI optional<__empty>
0091   operator()(_Policy&&, _RandomAccessIterator __first, _RandomAccessIterator __last, _Comp&& __comp) const noexcept {
0092     std::stable_sort(std::move(__first), std::move(__last), std::forward<_Comp>(__comp));
0093     return __empty{};
0094   }
0095 };
0096 
0097 template <class _ExecutionPolicy>
0098 struct __transform<__serial_backend_tag, _ExecutionPolicy> {
0099   template <class _Policy, class _ForwardIterator, class _ForwardOutIterator, class _UnaryOperation>
0100   _LIBCPP_HIDE_FROM_ABI optional<_ForwardOutIterator> operator()(
0101       _Policy&&, _ForwardIterator __first, _ForwardIterator __last, _ForwardOutIterator __outit, _UnaryOperation&& __op)
0102       const noexcept {
0103     return std::transform(
0104         std::move(__first), std::move(__last), std::move(__outit), std::forward<_UnaryOperation>(__op));
0105   }
0106 };
0107 
0108 template <class _ExecutionPolicy>
0109 struct __transform_binary<__serial_backend_tag, _ExecutionPolicy> {
0110   template <class _Policy,
0111             class _ForwardIterator1,
0112             class _ForwardIterator2,
0113             class _ForwardOutIterator,
0114             class _BinaryOperation>
0115   _LIBCPP_HIDE_FROM_ABI optional<_ForwardOutIterator>
0116   operator()(_Policy&&,
0117              _ForwardIterator1 __first1,
0118              _ForwardIterator1 __last1,
0119              _ForwardIterator2 __first2,
0120              _ForwardOutIterator __outit,
0121              _BinaryOperation&& __op) const noexcept {
0122     return std::transform(
0123         std::move(__first1),
0124         std::move(__last1),
0125         std::move(__first2),
0126         std::move(__outit),
0127         std::forward<_BinaryOperation>(__op));
0128   }
0129 };
0130 
0131 template <class _ExecutionPolicy>
0132 struct __transform_reduce<__serial_backend_tag, _ExecutionPolicy> {
0133   template <class _Policy, class _ForwardIterator, class _Tp, class _BinaryOperation, class _UnaryOperation>
0134   _LIBCPP_HIDE_FROM_ABI optional<_Tp>
0135   operator()(_Policy&&,
0136              _ForwardIterator __first,
0137              _ForwardIterator __last,
0138              _Tp __init,
0139              _BinaryOperation&& __reduce,
0140              _UnaryOperation&& __transform) const noexcept {
0141     return std::transform_reduce(
0142         std::move(__first),
0143         std::move(__last),
0144         std::move(__init),
0145         std::forward<_BinaryOperation>(__reduce),
0146         std::forward<_UnaryOperation>(__transform));
0147   }
0148 };
0149 
0150 template <class _ExecutionPolicy>
0151 struct __transform_reduce_binary<__serial_backend_tag, _ExecutionPolicy> {
0152   template <class _Policy,
0153             class _ForwardIterator1,
0154             class _ForwardIterator2,
0155             class _Tp,
0156             class _BinaryOperation1,
0157             class _BinaryOperation2>
0158   _LIBCPP_HIDE_FROM_ABI optional<_Tp> operator()(
0159       _Policy&&,
0160       _ForwardIterator1 __first1,
0161       _ForwardIterator1 __last1,
0162       _ForwardIterator2 __first2,
0163       _Tp __init,
0164       _BinaryOperation1&& __reduce,
0165       _BinaryOperation2&& __transform) const noexcept {
0166     return std::transform_reduce(
0167         std::move(__first1),
0168         std::move(__last1),
0169         std::move(__first2),
0170         std::move(__init),
0171         std::forward<_BinaryOperation1>(__reduce),
0172         std::forward<_BinaryOperation2>(__transform));
0173   }
0174 };
0175 
0176 } // namespace __pstl
0177 _LIBCPP_END_NAMESPACE_STD
0178 
0179 _LIBCPP_POP_MACROS
0180 
0181 #endif // _LIBCPP___CXX03___PSTL_BACKENDS_SERIAL_H