Path: blob/main/contrib/llvm-project/libcxx/include/__numeric/transform_reduce.h
35233 views
// -*- C++ -*-1//===----------------------------------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//89#ifndef _LIBCPP___NUMERIC_TRANSFORM_REDUCE_H10#define _LIBCPP___NUMERIC_TRANSFORM_REDUCE_H1112#include <__config>13#include <__functional/operations.h>14#include <__utility/move.h>1516#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)17# pragma GCC system_header18#endif1920_LIBCPP_PUSH_MACROS21#include <__undef_macros>2223_LIBCPP_BEGIN_NAMESPACE_STD2425#if _LIBCPP_STD_VER >= 1726template <class _InputIterator, class _Tp, class _BinaryOp, class _UnaryOp>27_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Tp28transform_reduce(_InputIterator __first, _InputIterator __last, _Tp __init, _BinaryOp __b, _UnaryOp __u) {29for (; __first != __last; ++__first)30__init = __b(std::move(__init), __u(*__first));31return __init;32}3334template <class _InputIterator1, class _InputIterator2, class _Tp, class _BinaryOp1, class _BinaryOp2>35_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Tp transform_reduce(36_InputIterator1 __first1,37_InputIterator1 __last1,38_InputIterator2 __first2,39_Tp __init,40_BinaryOp1 __b1,41_BinaryOp2 __b2) {42for (; __first1 != __last1; ++__first1, (void)++__first2)43__init = __b1(std::move(__init), __b2(*__first1, *__first2));44return __init;45}4647template <class _InputIterator1, class _InputIterator2, class _Tp>48_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Tp49transform_reduce(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _Tp __init) {50return std::transform_reduce(__first1, __last1, __first2, std::move(__init), std::plus<>(), std::multiplies<>());51}52#endif5354_LIBCPP_END_NAMESPACE_STD5556_LIBCPP_POP_MACROS5758#endif // _LIBCPP___NUMERIC_TRANSFORM_REDUCE_H596061