14824e7fdSDimitry Andric // -*- C++ -*-
24824e7fdSDimitry Andric //===----------------------------------------------------------------------===//
34824e7fdSDimitry Andric //
44824e7fdSDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
54824e7fdSDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
64824e7fdSDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
74824e7fdSDimitry Andric //
84824e7fdSDimitry Andric //===----------------------------------------------------------------------===//
94824e7fdSDimitry Andric
104824e7fdSDimitry Andric #ifndef _LIBCPP___NUMERIC_REDUCE_H
114824e7fdSDimitry Andric #define _LIBCPP___NUMERIC_REDUCE_H
124824e7fdSDimitry Andric
134824e7fdSDimitry Andric #include <__config>
144824e7fdSDimitry Andric #include <__functional/operations.h>
154824e7fdSDimitry Andric #include <__iterator/iterator_traits.h>
1606c3fb27SDimitry Andric #include <__utility/move.h>
174824e7fdSDimitry Andric
184824e7fdSDimitry Andric #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
194824e7fdSDimitry Andric # pragma GCC system_header
204824e7fdSDimitry Andric #endif
214824e7fdSDimitry Andric
22*b3edf446SDimitry Andric _LIBCPP_PUSH_MACROS
23*b3edf446SDimitry Andric #include <__undef_macros>
24*b3edf446SDimitry Andric
254824e7fdSDimitry Andric _LIBCPP_BEGIN_NAMESPACE_STD
264824e7fdSDimitry Andric
2706c3fb27SDimitry Andric #if _LIBCPP_STD_VER >= 17
284824e7fdSDimitry Andric template <class _InputIterator, class _Tp, class _BinaryOp>
29cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Tp
reduce(_InputIterator __first,_InputIterator __last,_Tp __init,_BinaryOp __b)30cb14a3feSDimitry Andric reduce(_InputIterator __first, _InputIterator __last, _Tp __init, _BinaryOp __b) {
314824e7fdSDimitry Andric for (; __first != __last; ++__first)
3206c3fb27SDimitry Andric __init = __b(std::move(__init), *__first);
334824e7fdSDimitry Andric return __init;
344824e7fdSDimitry Andric }
354824e7fdSDimitry Andric
364824e7fdSDimitry Andric template <class _InputIterator, class _Tp>
37cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Tp
reduce(_InputIterator __first,_InputIterator __last,_Tp __init)38cb14a3feSDimitry Andric reduce(_InputIterator __first, _InputIterator __last, _Tp __init) {
395f757f3fSDimitry Andric return std::reduce(__first, __last, __init, std::plus<>());
404824e7fdSDimitry Andric }
414824e7fdSDimitry Andric
424824e7fdSDimitry Andric template <class _InputIterator>
435f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 typename iterator_traits<_InputIterator>::value_type
reduce(_InputIterator __first,_InputIterator __last)444824e7fdSDimitry Andric reduce(_InputIterator __first, _InputIterator __last) {
455f757f3fSDimitry Andric return std::reduce(__first, __last, typename iterator_traits<_InputIterator>::value_type{});
464824e7fdSDimitry Andric }
474824e7fdSDimitry Andric #endif
484824e7fdSDimitry Andric
494824e7fdSDimitry Andric _LIBCPP_END_NAMESPACE_STD
504824e7fdSDimitry Andric
51*b3edf446SDimitry Andric _LIBCPP_POP_MACROS
52*b3edf446SDimitry Andric
534824e7fdSDimitry Andric #endif // _LIBCPP___NUMERIC_REDUCE_H
54