Warning: This file is not a C or C++ file. It does not have highlighting.

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//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP___CXX03___NUMERIC_ADJACENT_DIFFERENCE_H
11#define _LIBCPP___CXX03___NUMERIC_ADJACENT_DIFFERENCE_H
12
13#include <__cxx03/__config>
14#include <__cxx03/__iterator/iterator_traits.h>
15#include <__cxx03/__utility/move.h>
16
17#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
18# pragma GCC system_header
19#endif
20
21_LIBCPP_PUSH_MACROS
22#include <__cxx03/__undef_macros>
23
24_LIBCPP_BEGIN_NAMESPACE_STD
25
26template <class _InputIterator, class _OutputIterator>
27_LIBCPP_HIDE_FROM_ABI _OutputIterator
28adjacent_difference(_InputIterator __first, _InputIterator __last, _OutputIterator __result) {
29 if (__first != __last) {
30 typename iterator_traits<_InputIterator>::value_type __acc(*__first);
31 *__result = __acc;
32 for (++__first, (void)++__result; __first != __last; ++__first, (void)++__result) {
33 typename iterator_traits<_InputIterator>::value_type __val(*__first);
34 *__result = __val - __acc;
35 __acc = std::move(__val);
36 }
37 }
38 return __result;
39}
40
41template <class _InputIterator, class _OutputIterator, class _BinaryOperation>
42_LIBCPP_HIDE_FROM_ABI _OutputIterator adjacent_difference(
43 _InputIterator __first, _InputIterator __last, _OutputIterator __result, _BinaryOperation __binary_op) {
44 if (__first != __last) {
45 typename iterator_traits<_InputIterator>::value_type __acc(*__first);
46 *__result = __acc;
47 for (++__first, (void)++__result; __first != __last; ++__first, (void)++__result) {
48 typename iterator_traits<_InputIterator>::value_type __val(*__first);
49 *__result = __binary_op(__val, __acc);
50 __acc = std::move(__val);
51 }
52 }
53 return __result;
54}
55
56_LIBCPP_END_NAMESPACE_STD
57
58_LIBCPP_POP_MACROS
59
60#endif // _LIBCPP___CXX03___NUMERIC_ADJACENT_DIFFERENCE_H
61

Warning: This file is not a C or C++ file. It does not have highlighting.

source code of libcxx/include/__cxx03/__numeric/adjacent_difference.h