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_ADJACENT_DIFFERENCE_H 11*4824e7fdSDimitry Andric #define _LIBCPP___NUMERIC_ADJACENT_DIFFERENCE_H 12*4824e7fdSDimitry Andric 13*4824e7fdSDimitry Andric #include <__config> 14*4824e7fdSDimitry Andric #include <__iterator/iterator_traits.h> 15*4824e7fdSDimitry Andric #include <__utility/move.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 template <class _InputIterator, class _OutputIterator> 24*4824e7fdSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 25*4824e7fdSDimitry Andric _OutputIterator 26*4824e7fdSDimitry Andric adjacent_difference(_InputIterator __first, _InputIterator __last, _OutputIterator __result) 27*4824e7fdSDimitry Andric { 28*4824e7fdSDimitry Andric if (__first != __last) 29*4824e7fdSDimitry Andric { 30*4824e7fdSDimitry Andric typename iterator_traits<_InputIterator>::value_type __acc(*__first); 31*4824e7fdSDimitry Andric *__result = __acc; 32*4824e7fdSDimitry Andric for (++__first, (void) ++__result; __first != __last; ++__first, (void) ++__result) 33*4824e7fdSDimitry Andric { 34*4824e7fdSDimitry Andric typename iterator_traits<_InputIterator>::value_type __val(*__first); 35*4824e7fdSDimitry Andric #if _LIBCPP_STD_VER > 17 36*4824e7fdSDimitry Andric *__result = __val - _VSTD::move(__acc); 37*4824e7fdSDimitry Andric #else 38*4824e7fdSDimitry Andric *__result = __val - __acc; 39*4824e7fdSDimitry Andric #endif 40*4824e7fdSDimitry Andric __acc = _VSTD::move(__val); 41*4824e7fdSDimitry Andric } 42*4824e7fdSDimitry Andric } 43*4824e7fdSDimitry Andric return __result; 44*4824e7fdSDimitry Andric } 45*4824e7fdSDimitry Andric 46*4824e7fdSDimitry Andric template <class _InputIterator, class _OutputIterator, class _BinaryOperation> 47*4824e7fdSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 48*4824e7fdSDimitry Andric _OutputIterator 49*4824e7fdSDimitry Andric adjacent_difference(_InputIterator __first, _InputIterator __last, _OutputIterator __result, 50*4824e7fdSDimitry Andric _BinaryOperation __binary_op) 51*4824e7fdSDimitry Andric { 52*4824e7fdSDimitry Andric if (__first != __last) 53*4824e7fdSDimitry Andric { 54*4824e7fdSDimitry Andric typename iterator_traits<_InputIterator>::value_type __acc(*__first); 55*4824e7fdSDimitry Andric *__result = __acc; 56*4824e7fdSDimitry Andric for (++__first, (void) ++__result; __first != __last; ++__first, (void) ++__result) 57*4824e7fdSDimitry Andric { 58*4824e7fdSDimitry Andric typename iterator_traits<_InputIterator>::value_type __val(*__first); 59*4824e7fdSDimitry Andric #if _LIBCPP_STD_VER > 17 60*4824e7fdSDimitry Andric *__result = __binary_op(__val, _VSTD::move(__acc)); 61*4824e7fdSDimitry Andric #else 62*4824e7fdSDimitry Andric *__result = __binary_op(__val, __acc); 63*4824e7fdSDimitry Andric #endif 64*4824e7fdSDimitry Andric __acc = _VSTD::move(__val); 65*4824e7fdSDimitry Andric } 66*4824e7fdSDimitry Andric } 67*4824e7fdSDimitry Andric return __result; 68*4824e7fdSDimitry Andric } 69*4824e7fdSDimitry Andric 70*4824e7fdSDimitry Andric _LIBCPP_END_NAMESPACE_STD 71*4824e7fdSDimitry Andric 72*4824e7fdSDimitry Andric #endif // _LIBCPP___NUMERIC_ADJACENT_DIFFERENCE_H 73