1*4824e7fdSDimitry Andric // -*- C++ -*- 2*4824e7fdSDimitry Andric //===----------------------------------------------------------------------===// 3*4824e7fdSDimitry Andric // 4*4824e7fdSDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 5*4824e7fdSDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 6*4824e7fdSDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 7*4824e7fdSDimitry Andric // 8*4824e7fdSDimitry Andric //===----------------------------------------------------------------------===// 9*4824e7fdSDimitry Andric 10*4824e7fdSDimitry Andric #ifndef _LIBCPP___NUMERIC_REDUCE_H 11*4824e7fdSDimitry Andric #define _LIBCPP___NUMERIC_REDUCE_H 12*4824e7fdSDimitry Andric 13*4824e7fdSDimitry Andric #include <__config> 14*4824e7fdSDimitry Andric #include <__functional/operations.h> 15*4824e7fdSDimitry Andric #include <__iterator/iterator_traits.h> 16*4824e7fdSDimitry Andric 17*4824e7fdSDimitry Andric #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 18*4824e7fdSDimitry Andric # pragma GCC system_header 19*4824e7fdSDimitry Andric #endif 20*4824e7fdSDimitry Andric 21*4824e7fdSDimitry Andric _LIBCPP_BEGIN_NAMESPACE_STD 22*4824e7fdSDimitry Andric 23*4824e7fdSDimitry Andric #if _LIBCPP_STD_VER > 14 24*4824e7fdSDimitry Andric template <class _InputIterator, class _Tp, class _BinaryOp> 25*4824e7fdSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _Tp reduce(_InputIterator __first, _InputIterator __last, 26*4824e7fdSDimitry Andric _Tp __init, _BinaryOp __b) { 27*4824e7fdSDimitry Andric for (; __first != __last; ++__first) 28*4824e7fdSDimitry Andric __init = __b(__init, *__first); 29*4824e7fdSDimitry Andric return __init; 30*4824e7fdSDimitry Andric } 31*4824e7fdSDimitry Andric 32*4824e7fdSDimitry Andric template <class _InputIterator, class _Tp> 33*4824e7fdSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _Tp reduce(_InputIterator __first, _InputIterator __last, 34*4824e7fdSDimitry Andric _Tp __init) { 35*4824e7fdSDimitry Andric return _VSTD::reduce(__first, __last, __init, _VSTD::plus<>()); 36*4824e7fdSDimitry Andric } 37*4824e7fdSDimitry Andric 38*4824e7fdSDimitry Andric template <class _InputIterator> 39*4824e7fdSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 typename iterator_traits<_InputIterator>::value_type 40*4824e7fdSDimitry Andric reduce(_InputIterator __first, _InputIterator __last) { 41*4824e7fdSDimitry Andric return _VSTD::reduce(__first, __last, typename iterator_traits<_InputIterator>::value_type{}); 42*4824e7fdSDimitry Andric } 43*4824e7fdSDimitry Andric #endif 44*4824e7fdSDimitry Andric 45*4824e7fdSDimitry Andric _LIBCPP_END_NAMESPACE_STD 46*4824e7fdSDimitry Andric 47*4824e7fdSDimitry Andric #endif // _LIBCPP___NUMERIC_REDUCE_H 48