- template <class Iterator>
- typename iterator_traits<Iterator>::value_type*
- value_type(Iterator &iterator) {
- return static_cast<typename iterator_traits<Iterator>::value_type*>(0);
- }
- template <class InputIterator, class OutputIterator, class T, class BinaryOperation>
- OutputIterator __adjacent_difference(InputIterator first, InputIterator last,
- OutputIterator result, T*, BinaryOperation binary_op) {
- T value = *first;
- while(++first != last) {
- T tmp = *first;
- *++result = binary_op(tmp, value);
- value = tmp;
- }
- return ++result;
- }
- template <class InputIterator, class OutputIterator, class BinaryOperation>
- OutputIterator adjacent_difference(InputIterator first, InputIterator last,
- OutputIterator result, BinaryOperation binary_op) {
- if(first == last) return result;
- *result = *first;
- return __adjacent_difference(first, last, result, value_type(first), binary_op);
- }