Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libcxx / include / __numeric / reduce.h
blob8daa7cf60e25f7720bfeadcf79a74495042cb0e0
1 // -*- C++ -*-
2 //===----------------------------------------------------------------------===//
3 //
4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //
8 //===----------------------------------------------------------------------===//
10 #ifndef _LIBCPP___NUMERIC_REDUCE_H
11 #define _LIBCPP___NUMERIC_REDUCE_H
13 #include <__config>
14 #include <__functional/operations.h>
15 #include <__iterator/iterator_traits.h>
16 #include <__utility/move.h>
18 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
19 # pragma GCC system_header
20 #endif
22 _LIBCPP_BEGIN_NAMESPACE_STD
24 #if _LIBCPP_STD_VER >= 17
25 template <class _InputIterator, class _Tp, class _BinaryOp>
26 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 _Tp reduce(_InputIterator __first, _InputIterator __last,
27 _Tp __init, _BinaryOp __b) {
28 for (; __first != __last; ++__first)
29 __init = __b(std::move(__init), *__first);
30 return __init;
33 template <class _InputIterator, class _Tp>
34 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 _Tp reduce(_InputIterator __first, _InputIterator __last,
35 _Tp __init) {
36 return _VSTD::reduce(__first, __last, __init, _VSTD::plus<>());
39 template <class _InputIterator>
40 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 typename iterator_traits<_InputIterator>::value_type
41 reduce(_InputIterator __first, _InputIterator __last) {
42 return _VSTD::reduce(__first, __last, typename iterator_traits<_InputIterator>::value_type{});
44 #endif
46 _LIBCPP_END_NAMESPACE_STD
48 #endif // _LIBCPP___NUMERIC_REDUCE_H