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_ADJACENT_DIFFERENCE_H 114824e7fdSDimitry Andric #define _LIBCPP___NUMERIC_ADJACENT_DIFFERENCE_H 124824e7fdSDimitry Andric 134824e7fdSDimitry Andric #include <__config> 144824e7fdSDimitry Andric #include <__iterator/iterator_traits.h> 154824e7fdSDimitry Andric #include <__utility/move.h> 164824e7fdSDimitry Andric 174824e7fdSDimitry Andric #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 184824e7fdSDimitry Andric # pragma GCC system_header 194824e7fdSDimitry Andric #endif 204824e7fdSDimitry Andric 214824e7fdSDimitry Andric _LIBCPP_BEGIN_NAMESPACE_STD 224824e7fdSDimitry Andric 234824e7fdSDimitry Andric template <class _InputIterator, class _OutputIterator> 24*bdd1243dSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 254824e7fdSDimitry Andric _OutputIterator 264824e7fdSDimitry Andric adjacent_difference(_InputIterator __first, _InputIterator __last, _OutputIterator __result) 274824e7fdSDimitry Andric { 284824e7fdSDimitry Andric if (__first != __last) 294824e7fdSDimitry Andric { 304824e7fdSDimitry Andric typename iterator_traits<_InputIterator>::value_type __acc(*__first); 314824e7fdSDimitry Andric *__result = __acc; 324824e7fdSDimitry Andric for (++__first, (void) ++__result; __first != __last; ++__first, (void) ++__result) 334824e7fdSDimitry Andric { 344824e7fdSDimitry Andric typename iterator_traits<_InputIterator>::value_type __val(*__first); 354824e7fdSDimitry Andric #if _LIBCPP_STD_VER > 17 364824e7fdSDimitry Andric *__result = __val - _VSTD::move(__acc); 374824e7fdSDimitry Andric #else 384824e7fdSDimitry Andric *__result = __val - __acc; 394824e7fdSDimitry Andric #endif 404824e7fdSDimitry Andric __acc = _VSTD::move(__val); 414824e7fdSDimitry Andric } 424824e7fdSDimitry Andric } 434824e7fdSDimitry Andric return __result; 444824e7fdSDimitry Andric } 454824e7fdSDimitry Andric 464824e7fdSDimitry Andric template <class _InputIterator, class _OutputIterator, class _BinaryOperation> 47*bdd1243dSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 484824e7fdSDimitry Andric _OutputIterator 494824e7fdSDimitry Andric adjacent_difference(_InputIterator __first, _InputIterator __last, _OutputIterator __result, 504824e7fdSDimitry Andric _BinaryOperation __binary_op) 514824e7fdSDimitry Andric { 524824e7fdSDimitry Andric if (__first != __last) 534824e7fdSDimitry Andric { 544824e7fdSDimitry Andric typename iterator_traits<_InputIterator>::value_type __acc(*__first); 554824e7fdSDimitry Andric *__result = __acc; 564824e7fdSDimitry Andric for (++__first, (void) ++__result; __first != __last; ++__first, (void) ++__result) 574824e7fdSDimitry Andric { 584824e7fdSDimitry Andric typename iterator_traits<_InputIterator>::value_type __val(*__first); 594824e7fdSDimitry Andric #if _LIBCPP_STD_VER > 17 604824e7fdSDimitry Andric *__result = __binary_op(__val, _VSTD::move(__acc)); 614824e7fdSDimitry Andric #else 624824e7fdSDimitry Andric *__result = __binary_op(__val, __acc); 634824e7fdSDimitry Andric #endif 644824e7fdSDimitry Andric __acc = _VSTD::move(__val); 654824e7fdSDimitry Andric } 664824e7fdSDimitry Andric } 674824e7fdSDimitry Andric return __result; 684824e7fdSDimitry Andric } 694824e7fdSDimitry Andric 704824e7fdSDimitry Andric _LIBCPP_END_NAMESPACE_STD 714824e7fdSDimitry Andric 724824e7fdSDimitry Andric #endif // _LIBCPP___NUMERIC_ADJACENT_DIFFERENCE_H 73