Back to home page

EIC code displayed by LXR

 
 

    


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

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___NUMERIC_REDUCE_H
0011 #define _LIBCPP___CXX03___NUMERIC_REDUCE_H
0012 
0013 #include <__cxx03/__config>
0014 #include <__cxx03/__functional/operations.h>
0015 #include <__cxx03/__iterator/iterator_traits.h>
0016 #include <__cxx03/__utility/move.h>
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 
0027 #if _LIBCPP_STD_VER >= 17
0028 template <class _InputIterator, class _Tp, class _BinaryOp>
0029 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Tp
0030 reduce(_InputIterator __first, _InputIterator __last, _Tp __init, _BinaryOp __b) {
0031   for (; __first != __last; ++__first)
0032     __init = __b(std::move(__init), *__first);
0033   return __init;
0034 }
0035 
0036 template <class _InputIterator, class _Tp>
0037 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Tp
0038 reduce(_InputIterator __first, _InputIterator __last, _Tp __init) {
0039   return std::reduce(__first, __last, __init, std::plus<>());
0040 }
0041 
0042 template <class _InputIterator>
0043 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 typename iterator_traits<_InputIterator>::value_type
0044 reduce(_InputIterator __first, _InputIterator __last) {
0045   return std::reduce(__first, __last, typename iterator_traits<_InputIterator>::value_type{});
0046 }
0047 #endif
0048 
0049 _LIBCPP_END_NAMESPACE_STD
0050 
0051 _LIBCPP_POP_MACROS
0052 
0053 #endif // _LIBCPP___CXX03___NUMERIC_REDUCE_H