Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
Howard Hinnant | 5b08a8a | 2010-05-11 21:36:01 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4 | // |
Howard Hinnant | 412dbeb | 2010-11-16 22:09:02 +0000 | [diff] [blame^] | 5 | // This file is dual licensed under the MIT and the University of Illinois Open |
| 6 | // Source Licenses. See LICENSE.TXT for details. |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | // <numeric> |
| 11 | |
| 12 | // template <InputIterator InIter, |
Howard Hinnant | a0eaf60 | 2010-08-22 00:42:21 +0000 | [diff] [blame] | 13 | // OutputIterator<auto, const InIter::value_type&> OutIter> |
| 14 | // requires HasMinus<InIter::value_type, InIter::value_type> |
| 15 | // && Constructible<InIter::value_type, InIter::reference> |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 16 | // && OutputIterator<OutIter, |
Howard Hinnant | a0eaf60 | 2010-08-22 00:42:21 +0000 | [diff] [blame] | 17 | // HasMinus<InIter::value_type, InIter::value_type>::result_type> |
| 18 | // && MoveAssignable<InIter::value_type> |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 19 | // OutIter |
| 20 | // adjacent_difference(InIter first, InIter last, OutIter result); |
| 21 | |
| 22 | #include <numeric> |
| 23 | #include <cassert> |
| 24 | |
| 25 | #include "../iterators.h" |
| 26 | |
| 27 | template <class InIter, class OutIter> |
| 28 | void |
| 29 | test() |
| 30 | { |
| 31 | int ia[] = {15, 10, 6, 3, 1}; |
| 32 | int ir[] = {15, -5, -4, -3, -2}; |
| 33 | const unsigned s = sizeof(ia) / sizeof(ia[0]); |
| 34 | int ib[s] = {0}; |
| 35 | OutIter r = std::adjacent_difference(InIter(ia), InIter(ia+s), OutIter(ib)); |
| 36 | assert(base(r) == ib + s); |
| 37 | for (unsigned i = 0; i < s; ++i) |
| 38 | assert(ib[i] == ir[i]); |
| 39 | } |
| 40 | |
| 41 | int main() |
| 42 | { |
| 43 | test<input_iterator<const int*>, output_iterator<int*> >(); |
| 44 | test<input_iterator<const int*>, forward_iterator<int*> >(); |
| 45 | test<input_iterator<const int*>, bidirectional_iterator<int*> >(); |
| 46 | test<input_iterator<const int*>, random_access_iterator<int*> >(); |
| 47 | test<input_iterator<const int*>, int*>(); |
| 48 | |
| 49 | test<forward_iterator<const int*>, output_iterator<int*> >(); |
| 50 | test<forward_iterator<const int*>, forward_iterator<int*> >(); |
| 51 | test<forward_iterator<const int*>, bidirectional_iterator<int*> >(); |
| 52 | test<forward_iterator<const int*>, random_access_iterator<int*> >(); |
| 53 | test<forward_iterator<const int*>, int*>(); |
| 54 | |
| 55 | test<bidirectional_iterator<const int*>, output_iterator<int*> >(); |
| 56 | test<bidirectional_iterator<const int*>, forward_iterator<int*> >(); |
| 57 | test<bidirectional_iterator<const int*>, bidirectional_iterator<int*> >(); |
| 58 | test<bidirectional_iterator<const int*>, random_access_iterator<int*> >(); |
| 59 | test<bidirectional_iterator<const int*>, int*>(); |
| 60 | |
| 61 | test<random_access_iterator<const int*>, output_iterator<int*> >(); |
| 62 | test<random_access_iterator<const int*>, forward_iterator<int*> >(); |
| 63 | test<random_access_iterator<const int*>, bidirectional_iterator<int*> >(); |
| 64 | test<random_access_iterator<const int*>, random_access_iterator<int*> >(); |
| 65 | test<random_access_iterator<const int*>, int*>(); |
| 66 | |
| 67 | test<const int*, output_iterator<int*> >(); |
| 68 | test<const int*, forward_iterator<int*> >(); |
| 69 | test<const int*, bidirectional_iterator<int*> >(); |
| 70 | test<const int*, random_access_iterator<int*> >(); |
| 71 | test<const int*, int*>(); |
| 72 | } |