1//===----------------------------------------------------------------------===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is dual licensed under the MIT and the University of Illinois Open 6// Source Licenses. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9 10// <algorithm> 11 12// template<InputIterator InIter, class OutIter> 13// requires OutputIterator<OutIter, RvalueOf<InIter::value_type>::type> 14// && EqualityComparable<InIter::value_type> 15// && HasAssign<InIter::value_type, InIter::reference> 16// && Constructible<InIter::value_type, InIter::reference> 17// OutIter 18// unique_copy(InIter first, InIter last, OutIter result); 19 20#include <algorithm> 21#include <cassert> 22 23#include "test_iterators.h" 24 25template <class InIter, class OutIter> 26void 27test() 28{ 29 const int ia[] = {0}; 30 const unsigned sa = sizeof(ia)/sizeof(ia[0]); 31 int ja[sa] = {-1}; 32 OutIter r = std::unique_copy(InIter(ia), InIter(ia+sa), OutIter(ja)); 33 assert(base(r) == ja + sa); 34 assert(ja[0] == 0); 35 36 const int ib[] = {0, 1}; 37 const unsigned sb = sizeof(ib)/sizeof(ib[0]); 38 int jb[sb] = {-1}; 39 r = std::unique_copy(InIter(ib), InIter(ib+sb), OutIter(jb)); 40 assert(base(r) == jb + sb); 41 assert(jb[0] == 0); 42 assert(jb[1] == 1); 43 44 const int ic[] = {0, 0}; 45 const unsigned sc = sizeof(ic)/sizeof(ic[0]); 46 int jc[sc] = {-1}; 47 r = std::unique_copy(InIter(ic), InIter(ic+sc), OutIter(jc)); 48 assert(base(r) == jc + 1); 49 assert(jc[0] == 0); 50 51 const int id[] = {0, 0, 1}; 52 const unsigned sd = sizeof(id)/sizeof(id[0]); 53 int jd[sd] = {-1}; 54 r = std::unique_copy(InIter(id), InIter(id+sd), OutIter(jd)); 55 assert(base(r) == jd + 2); 56 assert(jd[0] == 0); 57 assert(jd[1] == 1); 58 59 const int ie[] = {0, 0, 1, 0}; 60 const unsigned se = sizeof(ie)/sizeof(ie[0]); 61 int je[se] = {-1}; 62 r = std::unique_copy(InIter(ie), InIter(ie+se), OutIter(je)); 63 assert(base(r) == je + 3); 64 assert(je[0] == 0); 65 assert(je[1] == 1); 66 assert(je[2] == 0); 67 68 const int ig[] = {0, 0, 1, 1}; 69 const unsigned sg = sizeof(ig)/sizeof(ig[0]); 70 int jg[sg] = {-1}; 71 r = std::unique_copy(InIter(ig), InIter(ig+sg), OutIter(jg)); 72 assert(base(r) == jg + 2); 73 assert(jg[0] == 0); 74 assert(jg[1] == 1); 75 76 const int ih[] = {0, 1, 1}; 77 const unsigned sh = sizeof(ih)/sizeof(ih[0]); 78 int jh[sh] = {-1}; 79 r = std::unique_copy(InIter(ih), InIter(ih+sh), OutIter(jh)); 80 assert(base(r) == jh + 2); 81 assert(jh[0] == 0); 82 assert(jh[1] == 1); 83 84 const int ii[] = {0, 1, 1, 1, 2, 2, 2}; 85 const unsigned si = sizeof(ii)/sizeof(ii[0]); 86 int ji[si] = {-1}; 87 r = std::unique_copy(InIter(ii), InIter(ii+si), OutIter(ji)); 88 assert(base(r) == ji + 3); 89 assert(ji[0] == 0); 90 assert(ji[1] == 1); 91 assert(ji[2] == 2); 92} 93 94int main() 95{ 96 test<input_iterator<const int*>, output_iterator<int*> >(); 97 test<input_iterator<const int*>, forward_iterator<int*> >(); 98 test<input_iterator<const int*>, bidirectional_iterator<int*> >(); 99 test<input_iterator<const int*>, random_access_iterator<int*> >(); 100 test<input_iterator<const int*>, int*>(); 101 102 test<forward_iterator<const int*>, output_iterator<int*> >(); 103 test<forward_iterator<const int*>, forward_iterator<int*> >(); 104 test<forward_iterator<const int*>, bidirectional_iterator<int*> >(); 105 test<forward_iterator<const int*>, random_access_iterator<int*> >(); 106 test<forward_iterator<const int*>, int*>(); 107 108 test<bidirectional_iterator<const int*>, output_iterator<int*> >(); 109 test<bidirectional_iterator<const int*>, forward_iterator<int*> >(); 110 test<bidirectional_iterator<const int*>, bidirectional_iterator<int*> >(); 111 test<bidirectional_iterator<const int*>, random_access_iterator<int*> >(); 112 test<bidirectional_iterator<const int*>, int*>(); 113 114 test<random_access_iterator<const int*>, output_iterator<int*> >(); 115 test<random_access_iterator<const int*>, forward_iterator<int*> >(); 116 test<random_access_iterator<const int*>, bidirectional_iterator<int*> >(); 117 test<random_access_iterator<const int*>, random_access_iterator<int*> >(); 118 test<random_access_iterator<const int*>, int*>(); 119 120 test<const int*, output_iterator<int*> >(); 121 test<const int*, forward_iterator<int*> >(); 122 test<const int*, bidirectional_iterator<int*> >(); 123 test<const int*, random_access_iterator<int*> >(); 124 test<const int*, int*>(); 125} 126