summaryrefslogtreecommitdiffstats
path: root/libcxx/test/std/algorithms/alg.modifying.operations/alg.unique
diff options
context:
space:
mode:
Diffstat (limited to 'libcxx/test/std/algorithms/alg.modifying.operations/alg.unique')
-rw-r--r--libcxx/test/std/algorithms/alg.modifying.operations/alg.unique/unique.pass.cpp189
-rw-r--r--libcxx/test/std/algorithms/alg.modifying.operations/alg.unique/unique_copy.pass.cpp125
-rw-r--r--libcxx/test/std/algorithms/alg.modifying.operations/alg.unique/unique_copy_pred.pass.cpp152
-rw-r--r--libcxx/test/std/algorithms/alg.modifying.operations/alg.unique/unique_pred.pass.cpp231
4 files changed, 697 insertions, 0 deletions
diff --git a/libcxx/test/std/algorithms/alg.modifying.operations/alg.unique/unique.pass.cpp b/libcxx/test/std/algorithms/alg.modifying.operations/alg.unique/unique.pass.cpp
new file mode 100644
index 00000000000..ab4ffad60f9
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.modifying.operations/alg.unique/unique.pass.cpp
@@ -0,0 +1,189 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <algorithm>
+
+// template<ForwardIterator Iter>
+// requires OutputIterator<Iter, Iter::reference>
+// && EqualityComparable<Iter::value_type>
+// Iter
+// unique(Iter first, Iter last);
+
+#include <algorithm>
+#include <cassert>
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+#include <memory>
+#endif
+
+#include "test_iterators.h"
+
+template <class Iter>
+void
+test()
+{
+ int ia[] = {0};
+ const unsigned sa = sizeof(ia)/sizeof(ia[0]);
+ Iter r = std::unique(Iter(ia), Iter(ia+sa));
+ assert(base(r) == ia + sa);
+ assert(ia[0] == 0);
+
+ int ib[] = {0, 1};
+ const unsigned sb = sizeof(ib)/sizeof(ib[0]);
+ r = std::unique(Iter(ib), Iter(ib+sb));
+ assert(base(r) == ib + sb);
+ assert(ib[0] == 0);
+ assert(ib[1] == 1);
+
+ int ic[] = {0, 0};
+ const unsigned sc = sizeof(ic)/sizeof(ic[0]);
+ r = std::unique(Iter(ic), Iter(ic+sc));
+ assert(base(r) == ic + 1);
+ assert(ic[0] == 0);
+
+ int id[] = {0, 0, 1};
+ const unsigned sd = sizeof(id)/sizeof(id[0]);
+ r = std::unique(Iter(id), Iter(id+sd));
+ assert(base(r) == id + 2);
+ assert(id[0] == 0);
+ assert(id[1] == 1);
+
+ int ie[] = {0, 0, 1, 0};
+ const unsigned se = sizeof(ie)/sizeof(ie[0]);
+ r = std::unique(Iter(ie), Iter(ie+se));
+ assert(base(r) == ie + 3);
+ assert(ie[0] == 0);
+ assert(ie[1] == 1);
+ assert(ie[2] == 0);
+
+ int ig[] = {0, 0, 1, 1};
+ const unsigned sg = sizeof(ig)/sizeof(ig[0]);
+ r = std::unique(Iter(ig), Iter(ig+sg));
+ assert(base(r) == ig + 2);
+ assert(ig[0] == 0);
+ assert(ig[1] == 1);
+
+ int ih[] = {0, 1, 1};
+ const unsigned sh = sizeof(ih)/sizeof(ih[0]);
+ r = std::unique(Iter(ih), Iter(ih+sh));
+ assert(base(r) == ih + 2);
+ assert(ih[0] == 0);
+ assert(ih[1] == 1);
+
+ int ii[] = {0, 1, 1, 1, 2, 2, 2};
+ const unsigned si = sizeof(ii)/sizeof(ii[0]);
+ r = std::unique(Iter(ii), Iter(ii+si));
+ assert(base(r) == ii + 3);
+ assert(ii[0] == 0);
+ assert(ii[1] == 1);
+ assert(ii[2] == 2);
+}
+
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+
+struct do_nothing
+{
+ void operator()(void*) const {}
+};
+
+typedef std::unique_ptr<int, do_nothing> Ptr;
+
+template <class Iter>
+void
+test1()
+{
+ int one = 1;
+ int two = 2;
+ Ptr ia[1];
+ const unsigned sa = sizeof(ia)/sizeof(ia[0]);
+ Iter r = std::unique(Iter(ia), Iter(ia+sa));
+ assert(base(r) == ia + sa);
+ assert(ia[0] == 0);
+
+ Ptr ib[2];
+ ib[1].reset(&one);
+ const unsigned sb = sizeof(ib)/sizeof(ib[0]);
+ r = std::unique(Iter(ib), Iter(ib+sb));
+ assert(base(r) == ib + sb);
+ assert(ib[0] == 0);
+ assert(*ib[1] == 1);
+
+ Ptr ic[2];
+ const unsigned sc = sizeof(ic)/sizeof(ic[0]);
+ r = std::unique(Iter(ic), Iter(ic+sc));
+ assert(base(r) == ic + 1);
+ assert(ic[0] == 0);
+
+ Ptr id[3];
+ id[2].reset(&one);
+ const unsigned sd = sizeof(id)/sizeof(id[0]);
+ r = std::unique(Iter(id), Iter(id+sd));
+ assert(base(r) == id + 2);
+ assert(id[0] == 0);
+ assert(*id[1] == 1);
+
+ Ptr ie[4];
+ ie[2].reset(&one);
+ const unsigned se = sizeof(ie)/sizeof(ie[0]);
+ r = std::unique(Iter(ie), Iter(ie+se));
+ assert(base(r) == ie + 3);
+ assert(ie[0] == 0);
+ assert(*ie[1] == 1);
+ assert(ie[2] == 0);
+
+ Ptr ig[4];
+ ig[2].reset(&one);
+ ig[3].reset(&one);
+ const unsigned sg = sizeof(ig)/sizeof(ig[0]);
+ r = std::unique(Iter(ig), Iter(ig+sg));
+ assert(base(r) == ig + 2);
+ assert(ig[0] == 0);
+ assert(*ig[1] == 1);
+
+ Ptr ih[3];
+ ih[1].reset(&one);
+ ih[2].reset(&one);
+ const unsigned sh = sizeof(ih)/sizeof(ih[0]);
+ r = std::unique(Iter(ih), Iter(ih+sh));
+ assert(base(r) == ih + 2);
+ assert(ih[0] == 0);
+ assert(*ih[1] == 1);
+
+ Ptr ii[7];
+ ii[1].reset(&one);
+ ii[2].reset(&one);
+ ii[3].reset(&one);
+ ii[4].reset(&two);
+ ii[5].reset(&two);
+ ii[6].reset(&two);
+ const unsigned si = sizeof(ii)/sizeof(ii[0]);
+ r = std::unique(Iter(ii), Iter(ii+si));
+ assert(base(r) == ii + 3);
+ assert(ii[0] == 0);
+ assert(*ii[1] == 1);
+ assert(*ii[2] == 2);
+}
+
+#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
+
+int main()
+{
+ test<forward_iterator<int*> >();
+ test<bidirectional_iterator<int*> >();
+ test<random_access_iterator<int*> >();
+ test<int*>();
+
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+
+ test1<forward_iterator<Ptr*> >();
+ test1<bidirectional_iterator<Ptr*> >();
+ test1<random_access_iterator<Ptr*> >();
+ test1<Ptr*>();
+
+#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
+}
diff --git a/libcxx/test/std/algorithms/alg.modifying.operations/alg.unique/unique_copy.pass.cpp b/libcxx/test/std/algorithms/alg.modifying.operations/alg.unique/unique_copy.pass.cpp
new file mode 100644
index 00000000000..761dad4ecd0
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.modifying.operations/alg.unique/unique_copy.pass.cpp
@@ -0,0 +1,125 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <algorithm>
+
+// template<InputIterator InIter, class OutIter>
+// requires OutputIterator<OutIter, RvalueOf<InIter::value_type>::type>
+// && EqualityComparable<InIter::value_type>
+// && HasAssign<InIter::value_type, InIter::reference>
+// && Constructible<InIter::value_type, InIter::reference>
+// OutIter
+// unique_copy(InIter first, InIter last, OutIter result);
+
+#include <algorithm>
+#include <cassert>
+
+#include "test_iterators.h"
+
+template <class InIter, class OutIter>
+void
+test()
+{
+ const int ia[] = {0};
+ const unsigned sa = sizeof(ia)/sizeof(ia[0]);
+ int ja[sa] = {-1};
+ OutIter r = std::unique_copy(InIter(ia), InIter(ia+sa), OutIter(ja));
+ assert(base(r) == ja + sa);
+ assert(ja[0] == 0);
+
+ const int ib[] = {0, 1};
+ const unsigned sb = sizeof(ib)/sizeof(ib[0]);
+ int jb[sb] = {-1};
+ r = std::unique_copy(InIter(ib), InIter(ib+sb), OutIter(jb));
+ assert(base(r) == jb + sb);
+ assert(jb[0] == 0);
+ assert(jb[1] == 1);
+
+ const int ic[] = {0, 0};
+ const unsigned sc = sizeof(ic)/sizeof(ic[0]);
+ int jc[sc] = {-1};
+ r = std::unique_copy(InIter(ic), InIter(ic+sc), OutIter(jc));
+ assert(base(r) == jc + 1);
+ assert(jc[0] == 0);
+
+ const int id[] = {0, 0, 1};
+ const unsigned sd = sizeof(id)/sizeof(id[0]);
+ int jd[sd] = {-1};
+ r = std::unique_copy(InIter(id), InIter(id+sd), OutIter(jd));
+ assert(base(r) == jd + 2);
+ assert(jd[0] == 0);
+ assert(jd[1] == 1);
+
+ const int ie[] = {0, 0, 1, 0};
+ const unsigned se = sizeof(ie)/sizeof(ie[0]);
+ int je[se] = {-1};
+ r = std::unique_copy(InIter(ie), InIter(ie+se), OutIter(je));
+ assert(base(r) == je + 3);
+ assert(je[0] == 0);
+ assert(je[1] == 1);
+ assert(je[2] == 0);
+
+ const int ig[] = {0, 0, 1, 1};
+ const unsigned sg = sizeof(ig)/sizeof(ig[0]);
+ int jg[sg] = {-1};
+ r = std::unique_copy(InIter(ig), InIter(ig+sg), OutIter(jg));
+ assert(base(r) == jg + 2);
+ assert(jg[0] == 0);
+ assert(jg[1] == 1);
+
+ const int ih[] = {0, 1, 1};
+ const unsigned sh = sizeof(ih)/sizeof(ih[0]);
+ int jh[sh] = {-1};
+ r = std::unique_copy(InIter(ih), InIter(ih+sh), OutIter(jh));
+ assert(base(r) == jh + 2);
+ assert(jh[0] == 0);
+ assert(jh[1] == 1);
+
+ const int ii[] = {0, 1, 1, 1, 2, 2, 2};
+ const unsigned si = sizeof(ii)/sizeof(ii[0]);
+ int ji[si] = {-1};
+ r = std::unique_copy(InIter(ii), InIter(ii+si), OutIter(ji));
+ assert(base(r) == ji + 3);
+ assert(ji[0] == 0);
+ assert(ji[1] == 1);
+ assert(ji[2] == 2);
+}
+
+int main()
+{
+ test<input_iterator<const int*>, output_iterator<int*> >();
+ test<input_iterator<const int*>, forward_iterator<int*> >();
+ test<input_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<input_iterator<const int*>, random_access_iterator<int*> >();
+ test<input_iterator<const int*>, int*>();
+
+ test<forward_iterator<const int*>, output_iterator<int*> >();
+ test<forward_iterator<const int*>, forward_iterator<int*> >();
+ test<forward_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<forward_iterator<const int*>, random_access_iterator<int*> >();
+ test<forward_iterator<const int*>, int*>();
+
+ test<bidirectional_iterator<const int*>, output_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, forward_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, random_access_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, int*>();
+
+ test<random_access_iterator<const int*>, output_iterator<int*> >();
+ test<random_access_iterator<const int*>, forward_iterator<int*> >();
+ test<random_access_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<random_access_iterator<const int*>, random_access_iterator<int*> >();
+ test<random_access_iterator<const int*>, int*>();
+
+ test<const int*, output_iterator<int*> >();
+ test<const int*, forward_iterator<int*> >();
+ test<const int*, bidirectional_iterator<int*> >();
+ test<const int*, random_access_iterator<int*> >();
+ test<const int*, int*>();
+}
diff --git a/libcxx/test/std/algorithms/alg.modifying.operations/alg.unique/unique_copy_pred.pass.cpp b/libcxx/test/std/algorithms/alg.modifying.operations/alg.unique/unique_copy_pred.pass.cpp
new file mode 100644
index 00000000000..6819899a114
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.modifying.operations/alg.unique/unique_copy_pred.pass.cpp
@@ -0,0 +1,152 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <algorithm>
+
+// template<InputIterator InIter, class OutIter,
+// EquivalenceRelation<auto, InIter::value_type> Pred>
+// requires OutputIterator<OutIter, RvalueOf<InIter::value_type>::type>
+// && HasAssign<InIter::value_type, InIter::reference>
+// && Constructible<InIter::value_type, InIter::reference>
+// && CopyConstructible<Pred>
+// OutIter
+// unique_copy(InIter first, InIter last, OutIter result, Pred pred);
+
+#include <algorithm>
+#include <cassert>
+
+#include "test_iterators.h"
+
+struct count_equal
+{
+ static unsigned count;
+ template <class T>
+ bool operator()(const T& x, const T& y)
+ {++count; return x == y;}
+};
+
+unsigned count_equal::count = 0;
+
+template <class InIter, class OutIter>
+void
+test()
+{
+ const int ia[] = {0};
+ const unsigned sa = sizeof(ia)/sizeof(ia[0]);
+ int ja[sa] = {-1};
+ count_equal::count = 0;
+ OutIter r = std::unique_copy(InIter(ia), InIter(ia+sa), OutIter(ja), count_equal());
+ assert(base(r) == ja + sa);
+ assert(ja[0] == 0);
+ assert(count_equal::count == sa-1);
+
+ const int ib[] = {0, 1};
+ const unsigned sb = sizeof(ib)/sizeof(ib[0]);
+ int jb[sb] = {-1};
+ count_equal::count = 0;
+ r = std::unique_copy(InIter(ib), InIter(ib+sb), OutIter(jb), count_equal());
+ assert(base(r) == jb + sb);
+ assert(jb[0] == 0);
+ assert(jb[1] == 1);
+ assert(count_equal::count == sb-1);
+
+ const int ic[] = {0, 0};
+ const unsigned sc = sizeof(ic)/sizeof(ic[0]);
+ int jc[sc] = {-1};
+ count_equal::count = 0;
+ r = std::unique_copy(InIter(ic), InIter(ic+sc), OutIter(jc), count_equal());
+ assert(base(r) == jc + 1);
+ assert(jc[0] == 0);
+ assert(count_equal::count == sc-1);
+
+ const int id[] = {0, 0, 1};
+ const unsigned sd = sizeof(id)/sizeof(id[0]);
+ int jd[sd] = {-1};
+ count_equal::count = 0;
+ r = std::unique_copy(InIter(id), InIter(id+sd), OutIter(jd), count_equal());
+ assert(base(r) == jd + 2);
+ assert(jd[0] == 0);
+ assert(jd[1] == 1);
+ assert(count_equal::count == sd-1);
+
+ const int ie[] = {0, 0, 1, 0};
+ const unsigned se = sizeof(ie)/sizeof(ie[0]);
+ int je[se] = {-1};
+ count_equal::count = 0;
+ r = std::unique_copy(InIter(ie), InIter(ie+se), OutIter(je), count_equal());
+ assert(base(r) == je + 3);
+ assert(je[0] == 0);
+ assert(je[1] == 1);
+ assert(je[2] == 0);
+ assert(count_equal::count == se-1);
+
+ const int ig[] = {0, 0, 1, 1};
+ const unsigned sg = sizeof(ig)/sizeof(ig[0]);
+ int jg[sg] = {-1};
+ count_equal::count = 0;
+ r = std::unique_copy(InIter(ig), InIter(ig+sg), OutIter(jg), count_equal());
+ assert(base(r) == jg + 2);
+ assert(jg[0] == 0);
+ assert(jg[1] == 1);
+ assert(count_equal::count == sg-1);
+
+ const int ih[] = {0, 1, 1};
+ const unsigned sh = sizeof(ih)/sizeof(ih[0]);
+ int jh[sh] = {-1};
+ count_equal::count = 0;
+ r = std::unique_copy(InIter(ih), InIter(ih+sh), OutIter(jh), count_equal());
+ assert(base(r) == jh + 2);
+ assert(jh[0] == 0);
+ assert(jh[1] == 1);
+ assert(count_equal::count == sh-1);
+
+ const int ii[] = {0, 1, 1, 1, 2, 2, 2};
+ const unsigned si = sizeof(ii)/sizeof(ii[0]);
+ int ji[si] = {-1};
+ count_equal::count = 0;
+ r = std::unique_copy(InIter(ii), InIter(ii+si), OutIter(ji), count_equal());
+ assert(base(r) == ji + 3);
+ assert(ji[0] == 0);
+ assert(ji[1] == 1);
+ assert(ji[2] == 2);
+ assert(count_equal::count == si-1);
+}
+
+int main()
+{
+ test<input_iterator<const int*>, output_iterator<int*> >();
+ test<input_iterator<const int*>, forward_iterator<int*> >();
+ test<input_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<input_iterator<const int*>, random_access_iterator<int*> >();
+ test<input_iterator<const int*>, int*>();
+
+ test<forward_iterator<const int*>, output_iterator<int*> >();
+ test<forward_iterator<const int*>, forward_iterator<int*> >();
+ test<forward_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<forward_iterator<const int*>, random_access_iterator<int*> >();
+ test<forward_iterator<const int*>, int*>();
+
+ test<bidirectional_iterator<const int*>, output_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, forward_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, random_access_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, int*>();
+
+ test<random_access_iterator<const int*>, output_iterator<int*> >();
+ test<random_access_iterator<const int*>, forward_iterator<int*> >();
+ test<random_access_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<random_access_iterator<const int*>, random_access_iterator<int*> >();
+ test<random_access_iterator<const int*>, int*>();
+
+ test<const int*, output_iterator<int*> >();
+ test<const int*, forward_iterator<int*> >();
+ test<const int*, bidirectional_iterator<int*> >();
+ test<const int*, random_access_iterator<int*> >();
+ test<const int*, int*>();
+}
diff --git a/libcxx/test/std/algorithms/alg.modifying.operations/alg.unique/unique_pred.pass.cpp b/libcxx/test/std/algorithms/alg.modifying.operations/alg.unique/unique_pred.pass.cpp
new file mode 100644
index 00000000000..c6df235bed6
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.modifying.operations/alg.unique/unique_pred.pass.cpp
@@ -0,0 +1,231 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <algorithm>
+
+// template<ForwardIterator Iter, EquivalenceRelation<auto, Iter::value_type> Pred>
+// requires OutputIterator<Iter, RvalueOf<Iter::reference>::type>
+// && CopyConstructible<Pred>
+// Iter
+// unique(Iter first, Iter last, Pred pred);
+
+#include <algorithm>
+#include <cassert>
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+#include <memory>
+#endif
+
+#include "test_iterators.h"
+
+struct count_equal
+{
+ static unsigned count;
+ template <class T>
+ bool operator()(const T& x, const T& y)
+ {++count; return x == y;}
+};
+
+unsigned count_equal::count = 0;
+
+template <class Iter>
+void
+test()
+{
+ int ia[] = {0};
+ const unsigned sa = sizeof(ia)/sizeof(ia[0]);
+ count_equal::count = 0;
+ Iter r = std::unique(Iter(ia), Iter(ia+sa), count_equal());
+ assert(base(r) == ia + sa);
+ assert(ia[0] == 0);
+ assert(count_equal::count == sa-1);
+
+ int ib[] = {0, 1};
+ const unsigned sb = sizeof(ib)/sizeof(ib[0]);
+ count_equal::count = 0;
+ r = std::unique(Iter(ib), Iter(ib+sb), count_equal());
+ assert(base(r) == ib + sb);
+ assert(ib[0] == 0);
+ assert(ib[1] == 1);
+ assert(count_equal::count == sb-1);
+
+ int ic[] = {0, 0};
+ const unsigned sc = sizeof(ic)/sizeof(ic[0]);
+ count_equal::count = 0;
+ r = std::unique(Iter(ic), Iter(ic+sc), count_equal());
+ assert(base(r) == ic + 1);
+ assert(ic[0] == 0);
+ assert(count_equal::count == sc-1);
+
+ int id[] = {0, 0, 1};
+ const unsigned sd = sizeof(id)/sizeof(id[0]);
+ count_equal::count = 0;
+ r = std::unique(Iter(id), Iter(id+sd), count_equal());
+ assert(base(r) == id + 2);
+ assert(id[0] == 0);
+ assert(id[1] == 1);
+ assert(count_equal::count == sd-1);
+
+ int ie[] = {0, 0, 1, 0};
+ const unsigned se = sizeof(ie)/sizeof(ie[0]);
+ count_equal::count = 0;
+ r = std::unique(Iter(ie), Iter(ie+se), count_equal());
+ assert(base(r) == ie + 3);
+ assert(ie[0] == 0);
+ assert(ie[1] == 1);
+ assert(ie[2] == 0);
+ assert(count_equal::count == se-1);
+
+ int ig[] = {0, 0, 1, 1};
+ const unsigned sg = sizeof(ig)/sizeof(ig[0]);
+ count_equal::count = 0;
+ r = std::unique(Iter(ig), Iter(ig+sg), count_equal());
+ assert(base(r) == ig + 2);
+ assert(ig[0] == 0);
+ assert(ig[1] == 1);
+ assert(count_equal::count == sg-1);
+
+ int ih[] = {0, 1, 1};
+ const unsigned sh = sizeof(ih)/sizeof(ih[0]);
+ count_equal::count = 0;
+ r = std::unique(Iter(ih), Iter(ih+sh), count_equal());
+ assert(base(r) == ih + 2);
+ assert(ih[0] == 0);
+ assert(ih[1] == 1);
+ assert(count_equal::count == sh-1);
+
+ int ii[] = {0, 1, 1, 1, 2, 2, 2};
+ const unsigned si = sizeof(ii)/sizeof(ii[0]);
+ count_equal::count = 0;
+ r = std::unique(Iter(ii), Iter(ii+si), count_equal());
+ assert(base(r) == ii + 3);
+ assert(ii[0] == 0);
+ assert(ii[1] == 1);
+ assert(ii[2] == 2);
+ assert(count_equal::count == si-1);
+}
+
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+
+struct do_nothing
+{
+ void operator()(void*) const {}
+};
+
+typedef std::unique_ptr<int, do_nothing> Ptr;
+
+template <class Iter>
+void
+test1()
+{
+ int one = 1;
+ int two = 2;
+ Ptr ia[1];
+ const unsigned sa = sizeof(ia)/sizeof(ia[0]);
+ count_equal::count = 0;
+ Iter r = std::unique(Iter(ia), Iter(ia+sa), count_equal());
+ assert(base(r) == ia + sa);
+ assert(ia[0] == 0);
+ assert(count_equal::count == sa-1);
+
+ Ptr ib[2];
+ ib[1].reset(&one);
+ const unsigned sb = sizeof(ib)/sizeof(ib[0]);
+ count_equal::count = 0;
+ r = std::unique(Iter(ib), Iter(ib+sb), count_equal());
+ assert(base(r) == ib + sb);
+ assert(ib[0] == 0);
+ assert(*ib[1] == 1);
+ assert(count_equal::count == sb-1);
+
+ Ptr ic[2];
+ const unsigned sc = sizeof(ic)/sizeof(ic[0]);
+ count_equal::count = 0;
+ r = std::unique(Iter(ic), Iter(ic+sc), count_equal());
+ assert(base(r) == ic + 1);
+ assert(ic[0] == 0);
+ assert(count_equal::count == sc-1);
+
+ Ptr id[3];
+ id[2].reset(&one);
+ const unsigned sd = sizeof(id)/sizeof(id[0]);
+ count_equal::count = 0;
+ r = std::unique(Iter(id), Iter(id+sd), count_equal());
+ assert(base(r) == id + 2);
+ assert(id[0] == 0);
+ assert(*id[1] == 1);
+ assert(count_equal::count == sd-1);
+
+ Ptr ie[4];
+ ie[2].reset(&one);
+ const unsigned se = sizeof(ie)/sizeof(ie[0]);
+ count_equal::count = 0;
+ r = std::unique(Iter(ie), Iter(ie+se), count_equal());
+ assert(base(r) == ie + 3);
+ assert(ie[0] == 0);
+ assert(*ie[1] == 1);
+ assert(ie[2] == 0);
+ assert(count_equal::count == se-1);
+
+ Ptr ig[4];
+ ig[2].reset(&one);
+ ig[3].reset(&one);
+ const unsigned sg = sizeof(ig)/sizeof(ig[0]);
+ count_equal::count = 0;
+ r = std::unique(Iter(ig), Iter(ig+sg), count_equal());
+ assert(base(r) == ig + 2);
+ assert(ig[0] == 0);
+ assert(*ig[1] == 1);
+ assert(count_equal::count == sg-1);
+
+ Ptr ih[3];
+ ih[1].reset(&one);
+ ih[2].reset(&one);
+ const unsigned sh = sizeof(ih)/sizeof(ih[0]);
+ count_equal::count = 0;
+ r = std::unique(Iter(ih), Iter(ih+sh), count_equal());
+ assert(base(r) == ih + 2);
+ assert(ih[0] == 0);
+ assert(*ih[1] == 1);
+ assert(count_equal::count == sh-1);
+
+ Ptr ii[7];
+ ii[1].reset(&one);
+ ii[2].reset(&one);
+ ii[3].reset(&one);
+ ii[4].reset(&two);
+ ii[5].reset(&two);
+ ii[6].reset(&two);
+ const unsigned si = sizeof(ii)/sizeof(ii[0]);
+ count_equal::count = 0;
+ r = std::unique(Iter(ii), Iter(ii+si), count_equal());
+ assert(base(r) == ii + 3);
+ assert(ii[0] == 0);
+ assert(*ii[1] == 1);
+ assert(*ii[2] == 2);
+ assert(count_equal::count == si-1);
+}
+
+#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
+
+int main()
+{
+ test<forward_iterator<int*> >();
+ test<bidirectional_iterator<int*> >();
+ test<random_access_iterator<int*> >();
+ test<int*>();
+
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+
+ test1<forward_iterator<Ptr*> >();
+ test1<bidirectional_iterator<Ptr*> >();
+ test1<random_access_iterator<Ptr*> >();
+ test1<Ptr*>();
+
+#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
+}
OpenPOWER on IntegriCloud