summaryrefslogtreecommitdiffstats
path: root/libcxx/test/std/algorithms
diff options
context:
space:
mode:
authorEric Fiselier <eric@efcs.ca>2014-12-20 01:40:03 +0000
committerEric Fiselier <eric@efcs.ca>2014-12-20 01:40:03 +0000
commit5a83710e371fe68a06e6e3876c6a2c8b820a8976 (patch)
treeafde4c82ad6704681781c5cd49baa3fbd05c85db /libcxx/test/std/algorithms
parentf11e8eab527fba316c64112f6e05de1a79693a3e (diff)
downloadbcm5719-llvm-5a83710e371fe68a06e6e3876c6a2c8b820a8976.tar.gz
bcm5719-llvm-5a83710e371fe68a06e6e3876c6a2c8b820a8976.zip
Move test into test/std subdirectory.
llvm-svn: 224658
Diffstat (limited to 'libcxx/test/std/algorithms')
-rw-r--r--libcxx/test/std/algorithms/alg.c.library/tested_elsewhere.pass.cpp12
-rw-r--r--libcxx/test/std/algorithms/alg.modifying.operations/alg.copy/copy.pass.cpp73
-rw-r--r--libcxx/test/std/algorithms/alg.modifying.operations/alg.copy/copy_backward.pass.cpp51
-rw-r--r--libcxx/test/std/algorithms/alg.modifying.operations/alg.copy/copy_if.pass.cpp80
-rw-r--r--libcxx/test/std/algorithms/alg.modifying.operations/alg.copy/copy_n.pass.cpp73
-rw-r--r--libcxx/test/std/algorithms/alg.modifying.operations/alg.fill/fill.pass.cpp59
-rw-r--r--libcxx/test/std/algorithms/alg.modifying.operations/alg.fill/fill_n.pass.cpp153
-rw-r--r--libcxx/test/std/algorithms/alg.modifying.operations/alg.generate/generate.pass.cpp47
-rw-r--r--libcxx/test/std/algorithms/alg.modifying.operations/alg.generate/generate_n.pass.cpp47
-rw-r--r--libcxx/test/std/algorithms/alg.modifying.operations/alg.move/move.pass.cpp134
-rw-r--r--libcxx/test/std/algorithms/alg.modifying.operations/alg.move/move_backward.pass.cpp88
-rw-r--r--libcxx/test/std/algorithms/alg.modifying.operations/alg.partitions/is_partitioned.pass.cpp58
-rw-r--r--libcxx/test/std/algorithms/alg.modifying.operations/alg.partitions/partition.pass.cpp104
-rw-r--r--libcxx/test/std/algorithms/alg.modifying.operations/alg.partitions/partition_copy.pass.cpp50
-rw-r--r--libcxx/test/std/algorithms/alg.modifying.operations/alg.partitions/partition_point.pass.cpp76
-rw-r--r--libcxx/test/std/algorithms/alg.modifying.operations/alg.partitions/stable_partition.pass.cpp314
-rw-r--r--libcxx/test/std/algorithms/alg.modifying.operations/alg.random.shuffle/random_shuffle.pass.cpp30
-rw-r--r--libcxx/test/std/algorithms/alg.modifying.operations/alg.random.shuffle/random_shuffle_rand.pass.cpp37
-rw-r--r--libcxx/test/std/algorithms/alg.modifying.operations/alg.random.shuffle/random_shuffle_urng.pass.cpp31
-rw-r--r--libcxx/test/std/algorithms/alg.modifying.operations/alg.remove/remove.pass.cpp83
-rw-r--r--libcxx/test/std/algorithms/alg.modifying.operations/alg.remove/remove_copy.pass.cpp70
-rw-r--r--libcxx/test/std/algorithms/alg.modifying.operations/alg.remove/remove_copy_if.pass.cpp73
-rw-r--r--libcxx/test/std/algorithms/alg.modifying.operations/alg.remove/remove_if.pass.cpp98
-rw-r--r--libcxx/test/std/algorithms/alg.modifying.operations/alg.replace/replace.pass.cpp44
-rw-r--r--libcxx/test/std/algorithms/alg.modifying.operations/alg.replace/replace_copy.pass.cpp72
-rw-r--r--libcxx/test/std/algorithms/alg.modifying.operations/alg.replace/replace_copy_if.pass.cpp74
-rw-r--r--libcxx/test/std/algorithms/alg.modifying.operations/alg.replace/replace_if.pass.cpp45
-rw-r--r--libcxx/test/std/algorithms/alg.modifying.operations/alg.reverse/reverse.pass.cpp60
-rw-r--r--libcxx/test/std/algorithms/alg.modifying.operations/alg.reverse/reverse_copy.pass.cpp81
-rw-r--r--libcxx/test/std/algorithms/alg.modifying.operations/alg.rotate/rotate.pass.cpp439
-rw-r--r--libcxx/test/std/algorithms/alg.modifying.operations/alg.rotate/rotate_copy.pass.cpp134
-rw-r--r--libcxx/test/std/algorithms/alg.modifying.operations/alg.swap/iter_swap.pass.cpp27
-rw-r--r--libcxx/test/std/algorithms/alg.modifying.operations/alg.swap/swap_ranges.pass.cpp110
-rw-r--r--libcxx/test/std/algorithms/alg.modifying.operations/alg.transform/binary_transform.pass.cpp217
-rw-r--r--libcxx/test/std/algorithms/alg.modifying.operations/alg.transform/unary_transform.pass.cpp77
-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
-rw-r--r--libcxx/test/std/algorithms/alg.modifying.operations/nothing_to_do.pass.cpp12
-rw-r--r--libcxx/test/std/algorithms/alg.nonmodifying/alg.adjacent.find/adjacent_find.pass.cpp35
-rw-r--r--libcxx/test/std/algorithms/alg.nonmodifying/alg.adjacent.find/adjacent_find_pred.pass.cpp39
-rw-r--r--libcxx/test/std/algorithms/alg.nonmodifying/alg.all_of/all_of.pass.cpp47
-rw-r--r--libcxx/test/std/algorithms/alg.nonmodifying/alg.any_of/any_of.pass.cpp55
-rw-r--r--libcxx/test/std/algorithms/alg.nonmodifying/alg.count/count.pass.cpp32
-rw-r--r--libcxx/test/std/algorithms/alg.nonmodifying/alg.count/count_if.pass.cpp36
-rw-r--r--libcxx/test/std/algorithms/alg.nonmodifying/alg.equal/equal.pass.cpp66
-rw-r--r--libcxx/test/std/algorithms/alg.nonmodifying/alg.equal/equal_pred.pass.cpp87
-rw-r--r--libcxx/test/std/algorithms/alg.nonmodifying/alg.find.end/find_end.pass.cpp57
-rw-r--r--libcxx/test/std/algorithms/alg.nonmodifying/alg.find.end/find_end_pred.pass.cpp86
-rw-r--r--libcxx/test/std/algorithms/alg.nonmodifying/alg.find.first.of/find_first_of.pass.cpp49
-rw-r--r--libcxx/test/std/algorithms/alg.nonmodifying/alg.find.first.of/find_first_of_pred.pass.cpp55
-rw-r--r--libcxx/test/std/algorithms/alg.nonmodifying/alg.find/find.pass.cpp31
-rw-r--r--libcxx/test/std/algorithms/alg.nonmodifying/alg.find/find_if.pass.cpp35
-rw-r--r--libcxx/test/std/algorithms/alg.nonmodifying/alg.find/find_if_not.pass.cpp35
-rw-r--r--libcxx/test/std/algorithms/alg.nonmodifying/alg.foreach/test.pass.cpp39
-rw-r--r--libcxx/test/std/algorithms/alg.nonmodifying/alg.is_permutation/is_permutation.pass.cpp605
-rw-r--r--libcxx/test/std/algorithms/alg.nonmodifying/alg.is_permutation/is_permutation_pred.pass.cpp729
-rw-r--r--libcxx/test/std/algorithms/alg.nonmodifying/alg.none_of/none_of.pass.cpp55
-rw-r--r--libcxx/test/std/algorithms/alg.nonmodifying/alg.search/search.pass.cpp72
-rw-r--r--libcxx/test/std/algorithms/alg.nonmodifying/alg.search/search_n.pass.cpp73
-rw-r--r--libcxx/test/std/algorithms/alg.nonmodifying/alg.search/search_n_pred.pass.cpp148
-rw-r--r--libcxx/test/std/algorithms/alg.nonmodifying/alg.search/search_pred.pass.cpp111
-rw-r--r--libcxx/test/std/algorithms/alg.nonmodifying/mismatch/mismatch.pass.cpp53
-rw-r--r--libcxx/test/std/algorithms/alg.nonmodifying/mismatch/mismatch_pred.pass.cpp71
-rw-r--r--libcxx/test/std/algorithms/alg.nonmodifying/nothing_to_do.pass.cpp12
-rw-r--r--libcxx/test/std/algorithms/alg.sorting/alg.binary.search/binary.search/binary_search.pass.cpp63
-rw-r--r--libcxx/test/std/algorithms/alg.sorting/alg.binary.search/binary.search/binary_search_comp.pass.cpp64
-rw-r--r--libcxx/test/std/algorithms/alg.sorting/alg.binary.search/equal.range/equal_range.pass.cpp69
-rw-r--r--libcxx/test/std/algorithms/alg.sorting/alg.binary.search/equal.range/equal_range_comp.pass.cpp70
-rw-r--r--libcxx/test/std/algorithms/alg.sorting/alg.binary.search/lower.bound/lower_bound.pass.cpp64
-rw-r--r--libcxx/test/std/algorithms/alg.sorting/alg.binary.search/lower.bound/lower_bound_comp.pass.cpp65
-rw-r--r--libcxx/test/std/algorithms/alg.sorting/alg.binary.search/nothing_to_do.pass.cpp12
-rw-r--r--libcxx/test/std/algorithms/alg.sorting/alg.binary.search/upper.bound/upper_bound.pass.cpp64
-rw-r--r--libcxx/test/std/algorithms/alg.sorting/alg.binary.search/upper.bound/upper_bound_comp.pass.cpp65
-rw-r--r--libcxx/test/std/algorithms/alg.sorting/alg.heap.operations/is.heap/is_heap.pass.cpp521
-rw-r--r--libcxx/test/std/algorithms/alg.sorting/alg.heap.operations/is.heap/is_heap_comp.pass.cpp522
-rw-r--r--libcxx/test/std/algorithms/alg.sorting/alg.heap.operations/is.heap/is_heap_until.pass.cpp521
-rw-r--r--libcxx/test/std/algorithms/alg.sorting/alg.heap.operations/is.heap/is_heap_until_comp.pass.cpp522
-rw-r--r--libcxx/test/std/algorithms/alg.sorting/alg.heap.operations/make.heap/make_heap.pass.cpp39
-rw-r--r--libcxx/test/std/algorithms/alg.sorting/alg.heap.operations/make.heap/make_heap_comp.pass.cpp101
-rw-r--r--libcxx/test/std/algorithms/alg.sorting/alg.heap.operations/nothing_to_do.pass.cpp12
-rw-r--r--libcxx/test/std/algorithms/alg.sorting/alg.heap.operations/pop.heap/pop_heap.pass.cpp39
-rw-r--r--libcxx/test/std/algorithms/alg.sorting/alg.heap.operations/pop.heap/pop_heap_comp.pass.cpp68
-rw-r--r--libcxx/test/std/algorithms/alg.sorting/alg.heap.operations/push.heap/push_heap.pass.cpp38
-rw-r--r--libcxx/test/std/algorithms/alg.sorting/alg.heap.operations/push.heap/push_heap_comp.pass.cpp66
-rw-r--r--libcxx/test/std/algorithms/alg.sorting/alg.heap.operations/sort.heap/sort_heap.pass.cpp40
-rw-r--r--libcxx/test/std/algorithms/alg.sorting/alg.heap.operations/sort.heap/sort_heap_comp.pass.cpp66
-rw-r--r--libcxx/test/std/algorithms/alg.sorting/alg.lex.comparison/lexicographical_compare.pass.cpp69
-rw-r--r--libcxx/test/std/algorithms/alg.sorting/alg.lex.comparison/lexicographical_compare_comp.pass.cpp73
-rw-r--r--libcxx/test/std/algorithms/alg.sorting/alg.merge/inplace_merge.pass.cpp79
-rw-r--r--libcxx/test/std/algorithms/alg.sorting/alg.merge/inplace_merge_comp.pass.cpp112
-rw-r--r--libcxx/test/std/algorithms/alg.sorting/alg.merge/merge.pass.cpp224
-rw-r--r--libcxx/test/std/algorithms/alg.sorting/alg.merge/merge_comp.pass.cpp229
-rw-r--r--libcxx/test/std/algorithms/alg.sorting/alg.min.max/max.pass.cpp54
-rw-r--r--libcxx/test/std/algorithms/alg.sorting/alg.min.max/max_comp.pass.cpp56
-rw-r--r--libcxx/test/std/algorithms/alg.sorting/alg.min.max/max_element.pass.cpp66
-rw-r--r--libcxx/test/std/algorithms/alg.sorting/alg.min.max/max_element_comp.pass.cpp85
-rw-r--r--libcxx/test/std/algorithms/alg.sorting/alg.min.max/max_init_list.pass.cpp42
-rw-r--r--libcxx/test/std/algorithms/alg.sorting/alg.min.max/max_init_list_comp.pass.cpp43
-rw-r--r--libcxx/test/std/algorithms/alg.sorting/alg.min.max/min.pass.cpp54
-rw-r--r--libcxx/test/std/algorithms/alg.sorting/alg.min.max/min_comp.pass.cpp56
-rw-r--r--libcxx/test/std/algorithms/alg.sorting/alg.min.max/min_element.pass.cpp66
-rw-r--r--libcxx/test/std/algorithms/alg.sorting/alg.min.max/min_element_comp.pass.cpp85
-rw-r--r--libcxx/test/std/algorithms/alg.sorting/alg.min.max/min_init_list.pass.cpp42
-rw-r--r--libcxx/test/std/algorithms/alg.sorting/alg.min.max/min_init_list_comp.pass.cpp43
-rw-r--r--libcxx/test/std/algorithms/alg.sorting/alg.min.max/minmax.pass.cpp62
-rw-r--r--libcxx/test/std/algorithms/alg.sorting/alg.min.max/minmax_comp.pass.cpp65
-rw-r--r--libcxx/test/std/algorithms/alg.sorting/alg.min.max/minmax_element.pass.cpp83
-rw-r--r--libcxx/test/std/algorithms/alg.sorting/alg.min.max/minmax_element_comp.pass.cpp88
-rw-r--r--libcxx/test/std/algorithms/alg.sorting/alg.min.max/minmax_init_list.pass.cpp39
-rw-r--r--libcxx/test/std/algorithms/alg.sorting/alg.min.max/minmax_init_list_comp.pass.cpp40
-rw-r--r--libcxx/test/std/algorithms/alg.sorting/alg.nth.element/nth_element.pass.cpp63
-rw-r--r--libcxx/test/std/algorithms/alg.sorting/alg.nth.element/nth_element_comp.pass.cpp86
-rw-r--r--libcxx/test/std/algorithms/alg.sorting/alg.permutation.generators/next_permutation.pass.cpp66
-rw-r--r--libcxx/test/std/algorithms/alg.sorting/alg.permutation.generators/next_permutation_comp.pass.cpp68
-rw-r--r--libcxx/test/std/algorithms/alg.sorting/alg.permutation.generators/prev_permutation.pass.cpp66
-rw-r--r--libcxx/test/std/algorithms/alg.sorting/alg.permutation.generators/prev_permutation_comp.pass.cpp68
-rw-r--r--libcxx/test/std/algorithms/alg.sorting/alg.set.operations/includes/includes.pass.cpp84
-rw-r--r--libcxx/test/std/algorithms/alg.sorting/alg.set.operations/includes/includes_comp.pass.cpp85
-rw-r--r--libcxx/test/std/algorithms/alg.sorting/alg.set.operations/nothing_to_do.pass.cpp12
-rw-r--r--libcxx/test/std/algorithms/alg.sorting/alg.set.operations/set.difference/set_difference.pass.cpp200
-rw-r--r--libcxx/test/std/algorithms/alg.sorting/alg.set.operations/set.difference/set_difference_comp.pass.cpp202
-rw-r--r--libcxx/test/std/algorithms/alg.sorting/alg.set.operations/set.intersection/set_intersection.pass.cpp198
-rw-r--r--libcxx/test/std/algorithms/alg.sorting/alg.set.operations/set.intersection/set_intersection_comp.pass.cpp200
-rw-r--r--libcxx/test/std/algorithms/alg.sorting/alg.set.operations/set.symmetric.difference/set_symmetric_difference.pass.cpp199
-rw-r--r--libcxx/test/std/algorithms/alg.sorting/alg.set.operations/set.symmetric.difference/set_symmetric_difference_comp.pass.cpp203
-rw-r--r--libcxx/test/std/algorithms/alg.sorting/alg.set.operations/set.union/set_union.pass.cpp198
-rw-r--r--libcxx/test/std/algorithms/alg.sorting/alg.set.operations/set.union/set_union_comp.pass.cpp200
-rw-r--r--libcxx/test/std/algorithms/alg.sorting/alg.sort/is.sorted/is_sorted.pass.cpp183
-rw-r--r--libcxx/test/std/algorithms/alg.sorting/alg.sort/is.sorted/is_sorted_comp.pass.cpp184
-rw-r--r--libcxx/test/std/algorithms/alg.sorting/alg.sort/is.sorted/is_sorted_until.pass.cpp183
-rw-r--r--libcxx/test/std/algorithms/alg.sorting/alg.sort/is.sorted/is_sorted_until_comp.pass.cpp184
-rw-r--r--libcxx/test/std/algorithms/alg.sorting/alg.sort/nothing_to_do.pass.cpp12
-rw-r--r--libcxx/test/std/algorithms/alg.sorting/alg.sort/partial.sort.copy/partial_sort_copy.pass.cpp86
-rw-r--r--libcxx/test/std/algorithms/alg.sorting/alg.sort/partial.sort.copy/partial_sort_copy_comp.pass.cpp90
-rw-r--r--libcxx/test/std/algorithms/alg.sorting/alg.sort/partial.sort/partial_sort.pass.cpp63
-rw-r--r--libcxx/test/std/algorithms/alg.sorting/alg.sort/partial.sort/partial_sort_comp.pass.cpp87
-rw-r--r--libcxx/test/std/algorithms/alg.sorting/alg.sort/sort/sort.pass.cpp150
-rw-r--r--libcxx/test/std/algorithms/alg.sorting/alg.sort/sort/sort_comp.pass.cpp57
-rw-r--r--libcxx/test/std/algorithms/alg.sorting/alg.sort/stable.sort/stable_sort.pass.cpp150
-rw-r--r--libcxx/test/std/algorithms/alg.sorting/alg.sort/stable.sort/stable_sort_comp.pass.cpp83
-rw-r--r--libcxx/test/std/algorithms/alg.sorting/nothing_to_do.pass.cpp12
-rw-r--r--libcxx/test/std/algorithms/algorithms.general/nothing_to_do.pass.cpp12
-rw-r--r--libcxx/test/std/algorithms/version.pass.cpp20
145 files changed, 15343 insertions, 0 deletions
diff --git a/libcxx/test/std/algorithms/alg.c.library/tested_elsewhere.pass.cpp b/libcxx/test/std/algorithms/alg.c.library/tested_elsewhere.pass.cpp
new file mode 100644
index 00000000000..b58f5c55b64
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.c.library/tested_elsewhere.pass.cpp
@@ -0,0 +1,12 @@
+//===----------------------------------------------------------------------===//
+//
+// 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.
+//
+//===----------------------------------------------------------------------===//
+
+int main()
+{
+}
diff --git a/libcxx/test/std/algorithms/alg.modifying.operations/alg.copy/copy.pass.cpp b/libcxx/test/std/algorithms/alg.modifying.operations/alg.copy/copy.pass.cpp
new file mode 100644
index 00000000000..a20d6ab7df8
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.modifying.operations/alg.copy/copy.pass.cpp
@@ -0,0 +1,73 @@
+//===----------------------------------------------------------------------===//
+//
+// 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, OutputIterator<auto, InIter::reference> OutIter>
+// OutIter
+// copy(InIter first, InIter last, OutIter result);
+
+#include <algorithm>
+#include <cassert>
+
+#include "test_iterators.h"
+
+template <class InIter, class OutIter>
+void
+test()
+{
+ const unsigned N = 1000;
+ int ia[N];
+ for (unsigned i = 0; i < N; ++i)
+ ia[i] = i;
+ int ib[N] = {0};
+
+ OutIter r = std::copy(InIter(ia), InIter(ia+N), OutIter(ib));
+ assert(base(r) == ib+N);
+ for (unsigned i = 0; i < N; ++i)
+ assert(ia[i] == ib[i]);
+}
+
+int main()
+{
+ test<input_iterator<const int*>, output_iterator<int*> >();
+ test<input_iterator<const int*>, input_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*>, input_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*>, input_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*>, input_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*, input_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.copy/copy_backward.pass.cpp b/libcxx/test/std/algorithms/alg.modifying.operations/alg.copy/copy_backward.pass.cpp
new file mode 100644
index 00000000000..039fd2fe026
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.modifying.operations/alg.copy/copy_backward.pass.cpp
@@ -0,0 +1,51 @@
+//===----------------------------------------------------------------------===//
+//
+// 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<BidirectionalIterator InIter, BidirectionalIterator OutIter>
+// requires OutputIterator<OutIter, InIter::reference>
+// OutIter
+// copy_backward(InIter first, InIter last, OutIter result);
+
+#include <algorithm>
+#include <cassert>
+
+#include "test_iterators.h"
+
+template <class InIter, class OutIter>
+void
+test()
+{
+ const unsigned N = 1000;
+ int ia[N];
+ for (unsigned i = 0; i < N; ++i)
+ ia[i] = i;
+ int ib[N] = {0};
+
+ OutIter r = std::copy_backward(InIter(ia), InIter(ia+N), OutIter(ib+N));
+ assert(base(r) == ib);
+ for (unsigned i = 0; i < N; ++i)
+ assert(ia[i] == ib[i]);
+}
+
+int main()
+{
+ 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*>, bidirectional_iterator<int*> >();
+ test<random_access_iterator<const int*>, random_access_iterator<int*> >();
+ test<random_access_iterator<const int*>, 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.copy/copy_if.pass.cpp b/libcxx/test/std/algorithms/alg.modifying.operations/alg.copy/copy_if.pass.cpp
new file mode 100644
index 00000000000..ab402a5eb8b
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.modifying.operations/alg.copy/copy_if.pass.cpp
@@ -0,0 +1,80 @@
+//===----------------------------------------------------------------------===//
+//
+// 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, OutputIterator<auto, InIter::reference> OutIter,
+// Predicate<auto, InIter::value_type> Pred>
+// requires CopyConstructible<Pred>
+// OutIter
+// copy_if(InIter first, InIter last, OutIter result, Pred pred);
+
+#include <algorithm>
+#include <cassert>
+
+#include "test_iterators.h"
+
+struct Pred
+{
+ bool operator()(int i) {return i % 3 == 0;}
+};
+
+template <class InIter, class OutIter>
+void
+test()
+{
+ const unsigned N = 1000;
+ int ia[N];
+ for (unsigned i = 0; i < N; ++i)
+ ia[i] = i;
+ int ib[N] = {0};
+
+ OutIter r = std::copy_if(InIter(ia), InIter(ia+N), OutIter(ib), Pred());
+ assert(base(r) == ib+N/3+1);
+ for (unsigned i = 0; i < N/3+1; ++i)
+ assert(ib[i] % 3 == 0);
+}
+
+int main()
+{
+ test<input_iterator<const int*>, output_iterator<int*> >();
+ test<input_iterator<const int*>, input_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*>, input_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*>, input_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*>, input_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*, input_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.copy/copy_n.pass.cpp b/libcxx/test/std/algorithms/alg.modifying.operations/alg.copy/copy_n.pass.cpp
new file mode 100644
index 00000000000..f594a0bf618
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.modifying.operations/alg.copy/copy_n.pass.cpp
@@ -0,0 +1,73 @@
+//===----------------------------------------------------------------------===//
+//
+// 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, OutputIterator<auto, InIter::reference> OutIter>
+// OutIter
+// copy_n(InIter first, InIter::difference_type n, OutIter result);
+
+#include <algorithm>
+#include <cassert>
+
+#include "test_iterators.h"
+
+template <class InIter, class OutIter>
+void
+test()
+{
+ const unsigned N = 1000;
+ int ia[N];
+ for (unsigned i = 0; i < N; ++i)
+ ia[i] = i;
+ int ib[N] = {0};
+
+ OutIter r = std::copy_n(InIter(ia), N/2, OutIter(ib));
+ assert(base(r) == ib+N/2);
+ for (unsigned i = 0; i < N/2; ++i)
+ assert(ia[i] == ib[i]);
+}
+
+int main()
+{
+ test<input_iterator<const int*>, output_iterator<int*> >();
+ test<input_iterator<const int*>, input_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*>, input_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*>, input_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*>, input_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*, input_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.fill/fill.pass.cpp b/libcxx/test/std/algorithms/alg.modifying.operations/alg.fill/fill.pass.cpp
new file mode 100644
index 00000000000..c72adac9e2e
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.modifying.operations/alg.fill/fill.pass.cpp
@@ -0,0 +1,59 @@
+//===----------------------------------------------------------------------===//
+//
+// 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, class T>
+// requires OutputIterator<Iter, const T&>
+// void
+// fill(Iter first, Iter last, const T& value);
+
+#include <algorithm>
+#include <cassert>
+
+#include "test_iterators.h"
+
+template <class Iter>
+void
+test_char()
+{
+ const unsigned n = 4;
+ char ca[n] = {0};
+ std::fill(Iter(ca), Iter(ca+n), char(1));
+ assert(ca[0] == 1);
+ assert(ca[1] == 1);
+ assert(ca[2] == 1);
+ assert(ca[3] == 1);
+}
+
+template <class Iter>
+void
+test_int()
+{
+ const unsigned n = 4;
+ int ia[n] = {0};
+ std::fill(Iter(ia), Iter(ia+n), 1);
+ assert(ia[0] == 1);
+ assert(ia[1] == 1);
+ assert(ia[2] == 1);
+ assert(ia[3] == 1);
+}
+
+int main()
+{
+ test_char<forward_iterator<char*> >();
+ test_char<bidirectional_iterator<char*> >();
+ test_char<random_access_iterator<char*> >();
+ test_char<char*>();
+
+ test_int<forward_iterator<int*> >();
+ test_int<bidirectional_iterator<int*> >();
+ test_int<random_access_iterator<int*> >();
+ test_int<int*>();
+}
diff --git a/libcxx/test/std/algorithms/alg.modifying.operations/alg.fill/fill_n.pass.cpp b/libcxx/test/std/algorithms/alg.modifying.operations/alg.fill/fill_n.pass.cpp
new file mode 100644
index 00000000000..bffcf1b63cb
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.modifying.operations/alg.fill/fill_n.pass.cpp
@@ -0,0 +1,153 @@
+//===----------------------------------------------------------------------===//
+//
+// 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<class Iter, IntegralLike Size, class T>
+// requires OutputIterator<Iter, const T&>
+// OutputIterator
+// fill_n(Iter first, Size n, const T& value);
+
+#include <algorithm>
+#include <cassert>
+
+#include "test_iterators.h"
+
+template <class Iter>
+void
+test_char()
+{
+ const unsigned n = 4;
+ char ca[n] = {0};
+ assert(std::fill_n(Iter(ca), n, char(1)) == std::next(Iter(ca), n));
+ assert(ca[0] == 1);
+ assert(ca[1] == 1);
+ assert(ca[2] == 1);
+ assert(ca[3] == 1);
+}
+
+template <class Iter>
+void
+test_int()
+{
+ const unsigned n = 4;
+ int ia[n] = {0};
+ assert(std::fill_n(Iter(ia), n, 1) == std::next(Iter(ia), n));
+ assert(ia[0] == 1);
+ assert(ia[1] == 1);
+ assert(ia[2] == 1);
+ assert(ia[3] == 1);
+}
+
+void
+test_int_array()
+{
+ const unsigned n = 4;
+ int ia[n] = {0};
+ assert(std::fill_n(ia, n, static_cast<char>(1)) == std::next(ia, n));
+ assert(ia[0] == 1);
+ assert(ia[1] == 1);
+ assert(ia[2] == 1);
+ assert(ia[3] == 1);
+}
+
+struct source {
+ source() : i(0) { }
+
+ operator int() const { return i++; }
+ mutable int i;
+};
+
+void
+test_int_array_struct_source()
+{
+ const unsigned n = 4;
+ int ia[n] = {0};
+ assert(std::fill_n(ia, n, source()) == std::next(ia, n));
+ assert(ia[0] == 0);
+ assert(ia[1] == 1);
+ assert(ia[2] == 2);
+ assert(ia[3] == 3);
+}
+
+struct test1 {
+ test1() : c(0) { }
+ test1(char c) : c(c + 1) { }
+ char c;
+};
+
+void
+test_struct_array()
+{
+ const unsigned n = 4;
+ test1 test1a[n] = {0};
+ assert(std::fill_n(test1a, n, static_cast<char>(10)) == std::next(test1a, n));
+ assert(test1a[0].c == 11);
+ assert(test1a[1].c == 11);
+ assert(test1a[2].c == 11);
+ assert(test1a[3].c == 11);
+}
+
+class A
+{
+ char a_;
+public:
+ A() {}
+ explicit A(char a) : a_(a) {}
+ operator unsigned char() const {return 'b';}
+
+ friend bool operator==(const A& x, const A& y)
+ {return x.a_ == y.a_;}
+};
+
+void
+test5()
+{
+ A a[3];
+ assert(std::fill_n(&a[0], 3, A('a')) == a+3);
+ assert(a[0] == A('a'));
+ assert(a[1] == A('a'));
+ assert(a[2] == A('a'));
+}
+
+struct Storage
+{
+ union
+ {
+ unsigned char a;
+ unsigned char b;
+ };
+};
+
+void test6()
+{
+ Storage foo[5];
+ std::fill_n(&foo[0], 5, Storage());
+}
+
+
+int main()
+{
+ test_char<forward_iterator<char*> >();
+ test_char<bidirectional_iterator<char*> >();
+ test_char<random_access_iterator<char*> >();
+ test_char<char*>();
+
+ test_int<forward_iterator<int*> >();
+ test_int<bidirectional_iterator<int*> >();
+ test_int<random_access_iterator<int*> >();
+ test_int<int*>();
+
+ test_int_array();
+ test_int_array_struct_source();
+ test_struct_array();
+
+ test5();
+ test6();
+}
diff --git a/libcxx/test/std/algorithms/alg.modifying.operations/alg.generate/generate.pass.cpp b/libcxx/test/std/algorithms/alg.modifying.operations/alg.generate/generate.pass.cpp
new file mode 100644
index 00000000000..f166d67ba2f
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.modifying.operations/alg.generate/generate.pass.cpp
@@ -0,0 +1,47 @@
+//===----------------------------------------------------------------------===//
+//
+// 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, Callable Generator>
+// requires OutputIterator<Iter, Generator::result_type>
+// && CopyConstructible<Generator>
+// void
+// generate(Iter first, Iter last, Generator gen);
+
+#include <algorithm>
+#include <cassert>
+
+#include "test_iterators.h"
+
+struct gen_test
+{
+ int operator()() const {return 1;}
+};
+
+template <class Iter>
+void
+test()
+{
+ const unsigned n = 4;
+ int ia[n] = {0};
+ std::generate(Iter(ia), Iter(ia+n), gen_test());
+ assert(ia[0] == 1);
+ assert(ia[1] == 1);
+ assert(ia[2] == 1);
+ assert(ia[3] == 1);
+}
+
+int main()
+{
+ test<forward_iterator<int*> >();
+ test<bidirectional_iterator<int*> >();
+ test<random_access_iterator<int*> >();
+ test<int*>();
+}
diff --git a/libcxx/test/std/algorithms/alg.modifying.operations/alg.generate/generate_n.pass.cpp b/libcxx/test/std/algorithms/alg.modifying.operations/alg.generate/generate_n.pass.cpp
new file mode 100644
index 00000000000..249419169a1
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.modifying.operations/alg.generate/generate_n.pass.cpp
@@ -0,0 +1,47 @@
+//===----------------------------------------------------------------------===//
+//
+// 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<class Iter, IntegralLike Size, Callable Generator>
+// requires OutputIterator<Iter, Generator::result_type>
+// && CopyConstructible<Generator>
+// void
+// generate_n(Iter first, Size n, Generator gen);
+
+#include <algorithm>
+#include <cassert>
+
+#include "test_iterators.h"
+
+struct gen_test
+{
+ int operator()() const {return 2;}
+};
+
+template <class Iter>
+void
+test()
+{
+ const unsigned n = 4;
+ int ia[n] = {0};
+ assert(std::generate_n(Iter(ia), n, gen_test()) == Iter(ia+n));
+ assert(ia[0] == 2);
+ assert(ia[1] == 2);
+ assert(ia[2] == 2);
+ assert(ia[3] == 2);
+}
+
+int main()
+{
+ test<forward_iterator<int*> >();
+ test<bidirectional_iterator<int*> >();
+ test<random_access_iterator<int*> >();
+ test<int*>();
+}
diff --git a/libcxx/test/std/algorithms/alg.modifying.operations/alg.move/move.pass.cpp b/libcxx/test/std/algorithms/alg.modifying.operations/alg.move/move.pass.cpp
new file mode 100644
index 00000000000..43234be5d3b
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.modifying.operations/alg.move/move.pass.cpp
@@ -0,0 +1,134 @@
+//===----------------------------------------------------------------------===//
+//
+// 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, typename OutIter>
+// requires OutputIterator<OutIter, RvalueOf<InIter::reference>::type>
+// OutIter
+// move(InIter first, InIter last, OutIter result);
+
+#include <algorithm>
+#include <cassert>
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+#include <memory>
+#endif
+
+#include "test_iterators.h"
+
+template <class InIter, class OutIter>
+void
+test()
+{
+ const unsigned N = 1000;
+ int ia[N];
+ for (unsigned i = 0; i < N; ++i)
+ ia[i] = i;
+ int ib[N] = {0};
+
+ OutIter r = std::move(InIter(ia), InIter(ia+N), OutIter(ib));
+ assert(base(r) == ib+N);
+ for (unsigned i = 0; i < N; ++i)
+ assert(ia[i] == ib[i]);
+}
+
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+
+template <class InIter, class OutIter>
+void
+test1()
+{
+ const unsigned N = 100;
+ std::unique_ptr<int> ia[N];
+ for (unsigned i = 0; i < N; ++i)
+ ia[i].reset(new int(i));
+ std::unique_ptr<int> ib[N];
+
+ OutIter r = std::move(InIter(ia), InIter(ia+N), OutIter(ib));
+ assert(base(r) == ib+N);
+ for (unsigned i = 0; i < N; ++i)
+ assert(*ib[i] == i);
+}
+
+#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
+
+int main()
+{
+ test<input_iterator<const int*>, output_iterator<int*> >();
+ test<input_iterator<const int*>, input_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*>, input_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*>, input_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*>, input_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*, input_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*>();
+
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+ test1<input_iterator<std::unique_ptr<int>*>, output_iterator<std::unique_ptr<int>*> >();
+ test1<input_iterator<std::unique_ptr<int>*>, input_iterator<std::unique_ptr<int>*> >();
+ test1<input_iterator<std::unique_ptr<int>*>, forward_iterator<std::unique_ptr<int>*> >();
+ test1<input_iterator<std::unique_ptr<int>*>, bidirectional_iterator<std::unique_ptr<int>*> >();
+ test1<input_iterator<std::unique_ptr<int>*>, random_access_iterator<std::unique_ptr<int>*> >();
+ test1<input_iterator<std::unique_ptr<int>*>, std::unique_ptr<int>*>();
+
+ test1<forward_iterator<std::unique_ptr<int>*>, output_iterator<std::unique_ptr<int>*> >();
+ test1<forward_iterator<std::unique_ptr<int>*>, input_iterator<std::unique_ptr<int>*> >();
+ test1<forward_iterator<std::unique_ptr<int>*>, forward_iterator<std::unique_ptr<int>*> >();
+ test1<forward_iterator<std::unique_ptr<int>*>, bidirectional_iterator<std::unique_ptr<int>*> >();
+ test1<forward_iterator<std::unique_ptr<int>*>, random_access_iterator<std::unique_ptr<int>*> >();
+ test1<forward_iterator<std::unique_ptr<int>*>, std::unique_ptr<int>*>();
+
+ test1<bidirectional_iterator<std::unique_ptr<int>*>, output_iterator<std::unique_ptr<int>*> >();
+ test1<bidirectional_iterator<std::unique_ptr<int>*>, input_iterator<std::unique_ptr<int>*> >();
+ test1<bidirectional_iterator<std::unique_ptr<int>*>, forward_iterator<std::unique_ptr<int>*> >();
+ test1<bidirectional_iterator<std::unique_ptr<int>*>, bidirectional_iterator<std::unique_ptr<int>*> >();
+ test1<bidirectional_iterator<std::unique_ptr<int>*>, random_access_iterator<std::unique_ptr<int>*> >();
+ test1<bidirectional_iterator<std::unique_ptr<int>*>, std::unique_ptr<int>*>();
+
+ test1<random_access_iterator<std::unique_ptr<int>*>, output_iterator<std::unique_ptr<int>*> >();
+ test1<random_access_iterator<std::unique_ptr<int>*>, input_iterator<std::unique_ptr<int>*> >();
+ test1<random_access_iterator<std::unique_ptr<int>*>, forward_iterator<std::unique_ptr<int>*> >();
+ test1<random_access_iterator<std::unique_ptr<int>*>, bidirectional_iterator<std::unique_ptr<int>*> >();
+ test1<random_access_iterator<std::unique_ptr<int>*>, random_access_iterator<std::unique_ptr<int>*> >();
+ test1<random_access_iterator<std::unique_ptr<int>*>, std::unique_ptr<int>*>();
+
+ test1<std::unique_ptr<int>*, output_iterator<std::unique_ptr<int>*> >();
+ test1<std::unique_ptr<int>*, input_iterator<std::unique_ptr<int>*> >();
+ test1<std::unique_ptr<int>*, forward_iterator<std::unique_ptr<int>*> >();
+ test1<std::unique_ptr<int>*, bidirectional_iterator<std::unique_ptr<int>*> >();
+ test1<std::unique_ptr<int>*, random_access_iterator<std::unique_ptr<int>*> >();
+ test1<std::unique_ptr<int>*, std::unique_ptr<int>*>();
+#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
+}
diff --git a/libcxx/test/std/algorithms/alg.modifying.operations/alg.move/move_backward.pass.cpp b/libcxx/test/std/algorithms/alg.modifying.operations/alg.move/move_backward.pass.cpp
new file mode 100644
index 00000000000..02b6b16eca0
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.modifying.operations/alg.move/move_backward.pass.cpp
@@ -0,0 +1,88 @@
+//===----------------------------------------------------------------------===//
+//
+// 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<BidirectionalIterator InIter, BidirectionalIterator OutIter>
+// requires OutputIterator<OutIter, RvalueOf<InIter::reference>::type>
+// OutIter
+// move_backward(InIter first, InIter last, OutIter result);
+
+#include <algorithm>
+#include <cassert>
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+#include <memory>
+#endif
+
+#include "test_iterators.h"
+
+template <class InIter, class OutIter>
+void
+test()
+{
+ const unsigned N = 1000;
+ int ia[N];
+ for (unsigned i = 0; i < N; ++i)
+ ia[i] = i;
+ int ib[N] = {0};
+
+ OutIter r = std::move_backward(InIter(ia), InIter(ia+N), OutIter(ib+N));
+ assert(base(r) == ib);
+ for (unsigned i = 0; i < N; ++i)
+ assert(ia[i] == ib[i]);
+}
+
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+
+template <class InIter, class OutIter>
+void
+test1()
+{
+ const unsigned N = 100;
+ std::unique_ptr<int> ia[N];
+ for (unsigned i = 0; i < N; ++i)
+ ia[i].reset(new int(i));
+ std::unique_ptr<int> ib[N];
+
+ OutIter r = std::move_backward(InIter(ia), InIter(ia+N), OutIter(ib+N));
+ assert(base(r) == ib);
+ for (unsigned i = 0; i < N; ++i)
+ assert(*ib[i] == i);
+}
+
+#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
+
+int main()
+{
+ 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*>, bidirectional_iterator<int*> >();
+ test<random_access_iterator<const int*>, random_access_iterator<int*> >();
+ test<random_access_iterator<const int*>, int*>();
+
+ test<const int*, bidirectional_iterator<int*> >();
+ test<const int*, random_access_iterator<int*> >();
+ test<const int*, int*>();
+
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+ test1<bidirectional_iterator<std::unique_ptr<int>*>, bidirectional_iterator<std::unique_ptr<int>*> >();
+ test1<bidirectional_iterator<std::unique_ptr<int>*>, random_access_iterator<std::unique_ptr<int>*> >();
+ test1<bidirectional_iterator<std::unique_ptr<int>*>, std::unique_ptr<int>*>();
+
+ test1<random_access_iterator<std::unique_ptr<int>*>, bidirectional_iterator<std::unique_ptr<int>*> >();
+ test1<random_access_iterator<std::unique_ptr<int>*>, random_access_iterator<std::unique_ptr<int>*> >();
+ test1<random_access_iterator<std::unique_ptr<int>*>, std::unique_ptr<int>*>();
+
+ test1<std::unique_ptr<int>*, bidirectional_iterator<std::unique_ptr<int>*> >();
+ test1<std::unique_ptr<int>*, random_access_iterator<std::unique_ptr<int>*> >();
+ test1<std::unique_ptr<int>*, std::unique_ptr<int>*>();
+#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
+}
diff --git a/libcxx/test/std/algorithms/alg.modifying.operations/alg.partitions/is_partitioned.pass.cpp b/libcxx/test/std/algorithms/alg.modifying.operations/alg.partitions/is_partitioned.pass.cpp
new file mode 100644
index 00000000000..6098a203d82
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.modifying.operations/alg.partitions/is_partitioned.pass.cpp
@@ -0,0 +1,58 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 <class InputIterator, class Predicate>
+// bool
+// is_partitioned(InputIterator first, InputIterator last, Predicate pred);
+
+#include <algorithm>
+#include <cassert>
+
+#include "test_iterators.h"
+
+struct is_odd
+{
+ bool operator()(const int& i) const {return i & 1;}
+};
+
+int main()
+{
+ {
+ const int ia[] = {1, 2, 3, 4, 5, 6};
+ assert(!std::is_partitioned(input_iterator<const int*>(std::begin(ia)),
+ input_iterator<const int*>(std::end(ia)),
+ is_odd()));
+ }
+ {
+ const int ia[] = {1, 3, 5, 2, 4, 6};
+ assert( std::is_partitioned(input_iterator<const int*>(std::begin(ia)),
+ input_iterator<const int*>(std::end(ia)),
+ is_odd()));
+ }
+ {
+ const int ia[] = {2, 4, 6, 1, 3, 5};
+ assert(!std::is_partitioned(input_iterator<const int*>(std::begin(ia)),
+ input_iterator<const int*>(std::end(ia)),
+ is_odd()));
+ }
+ {
+ const int ia[] = {1, 3, 5, 2, 4, 6, 7};
+ assert(!std::is_partitioned(input_iterator<const int*>(std::begin(ia)),
+ input_iterator<const int*>(std::end(ia)),
+ is_odd()));
+ }
+ {
+ const int ia[] = {1, 3, 5, 2, 4, 6, 7};
+ assert( std::is_partitioned(input_iterator<const int*>(std::begin(ia)),
+ input_iterator<const int*>(std::begin(ia)),
+ is_odd()));
+ }
+}
diff --git a/libcxx/test/std/algorithms/alg.modifying.operations/alg.partitions/partition.pass.cpp b/libcxx/test/std/algorithms/alg.modifying.operations/alg.partitions/partition.pass.cpp
new file mode 100644
index 00000000000..8eddfbc4d04
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.modifying.operations/alg.partitions/partition.pass.cpp
@@ -0,0 +1,104 @@
+//===----------------------------------------------------------------------===//
+//
+// 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<BidirectionalIterator Iter, Predicate<auto, Iter::value_type> Pred>
+// requires ShuffleIterator<Iter>
+// && CopyConstructible<Pred>
+// Iter
+// partition(Iter first, Iter last, Pred pred);
+
+#include <algorithm>
+#include <cassert>
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+#include <memory>
+#endif
+
+#include "test_iterators.h"
+
+struct is_odd
+{
+ bool operator()(const int& i) const {return i & 1;}
+};
+
+template <class Iter>
+void
+test()
+{
+ // check mixed
+ int ia[] = {1, 2, 3, 4, 5, 6, 7, 8 ,9};
+ const unsigned sa = sizeof(ia)/sizeof(ia[0]);
+ Iter r = std::partition(Iter(ia), Iter(ia + sa), is_odd());
+ assert(base(r) == ia + 5);
+ for (int* i = ia; i < base(r); ++i)
+ assert(is_odd()(*i));
+ for (int* i = base(r); i < ia+sa; ++i)
+ assert(!is_odd()(*i));
+ // check empty
+ r = std::partition(Iter(ia), Iter(ia), is_odd());
+ assert(base(r) == ia);
+ // check all false
+ for (unsigned i = 0; i < sa; ++i)
+ ia[i] = 2*i;
+ r = std::partition(Iter(ia), Iter(ia+sa), is_odd());
+ assert(base(r) == ia);
+ // check all true
+ for (unsigned i = 0; i < sa; ++i)
+ ia[i] = 2*i+1;
+ r = std::partition(Iter(ia), Iter(ia+sa), is_odd());
+ assert(base(r) == ia+sa);
+ // check all true but last
+ for (unsigned i = 0; i < sa; ++i)
+ ia[i] = 2*i+1;
+ ia[sa-1] = 10;
+ r = std::partition(Iter(ia), Iter(ia+sa), is_odd());
+ assert(base(r) == ia+sa-1);
+ for (int* i = ia; i < base(r); ++i)
+ assert(is_odd()(*i));
+ for (int* i = base(r); i < ia+sa; ++i)
+ assert(!is_odd()(*i));
+ // check all true but first
+ for (unsigned i = 0; i < sa; ++i)
+ ia[i] = 2*i+1;
+ ia[0] = 10;
+ r = std::partition(Iter(ia), Iter(ia+sa), is_odd());
+ assert(base(r) == ia+sa-1);
+ for (int* i = ia; i < base(r); ++i)
+ assert(is_odd()(*i));
+ for (int* i = base(r); i < ia+sa; ++i)
+ assert(!is_odd()(*i));
+ // check all false but last
+ for (unsigned i = 0; i < sa; ++i)
+ ia[i] = 2*i;
+ ia[sa-1] = 11;
+ r = std::partition(Iter(ia), Iter(ia+sa), is_odd());
+ assert(base(r) == ia+1);
+ for (int* i = ia; i < base(r); ++i)
+ assert(is_odd()(*i));
+ for (int* i = base(r); i < ia+sa; ++i)
+ assert(!is_odd()(*i));
+ // check all false but first
+ for (unsigned i = 0; i < sa; ++i)
+ ia[i] = 2*i;
+ ia[0] = 11;
+ r = std::partition(Iter(ia), Iter(ia+sa), is_odd());
+ assert(base(r) == ia+1);
+ for (int* i = ia; i < base(r); ++i)
+ assert(is_odd()(*i));
+ for (int* i = base(r); i < ia+sa; ++i)
+ assert(!is_odd()(*i));
+}
+
+int main()
+{
+ test<bidirectional_iterator<int*> >();
+ test<random_access_iterator<int*> >();
+ test<int*>();
+}
diff --git a/libcxx/test/std/algorithms/alg.modifying.operations/alg.partitions/partition_copy.pass.cpp b/libcxx/test/std/algorithms/alg.modifying.operations/alg.partitions/partition_copy.pass.cpp
new file mode 100644
index 00000000000..67e1cccaf73
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.modifying.operations/alg.partitions/partition_copy.pass.cpp
@@ -0,0 +1,50 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 <class InputIterator, class OutputIterator1,
+// class OutputIterator2, class Predicate>
+// pair<OutputIterator1, OutputIterator2>
+// partition_copy(InputIterator first, InputIterator last,
+// OutputIterator1 out_true, OutputIterator2 out_false,
+// Predicate pred);
+
+#include <algorithm>
+#include <cassert>
+
+#include "test_iterators.h"
+
+struct is_odd
+{
+ bool operator()(const int& i) const {return i & 1;}
+};
+
+int main()
+{
+ {
+ const int ia[] = {1, 2, 3, 4, 6, 8, 5, 7};
+ int r1[10] = {0};
+ int r2[10] = {0};
+ typedef std::pair<output_iterator<int*>, int*> P;
+ P p = std::partition_copy(input_iterator<const int*>(std::begin(ia)),
+ input_iterator<const int*>(std::end(ia)),
+ output_iterator<int*>(r1), r2, is_odd());
+ assert(p.first.base() == r1 + 4);
+ assert(r1[0] == 1);
+ assert(r1[1] == 3);
+ assert(r1[2] == 5);
+ assert(r1[3] == 7);
+ assert(p.second == r2 + 4);
+ assert(r2[0] == 2);
+ assert(r2[1] == 4);
+ assert(r2[2] == 6);
+ assert(r2[3] == 8);
+ }
+}
diff --git a/libcxx/test/std/algorithms/alg.modifying.operations/alg.partitions/partition_point.pass.cpp b/libcxx/test/std/algorithms/alg.modifying.operations/alg.partitions/partition_point.pass.cpp
new file mode 100644
index 00000000000..f5b832c6639
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.modifying.operations/alg.partitions/partition_point.pass.cpp
@@ -0,0 +1,76 @@
+//===----------------------------------------------------------------------===//
+//
+// 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<class ForwardIterator, class Predicate>
+// ForwardIterator
+// partition_point(ForwardIterator first, ForwardIterator last, Predicate pred);
+
+#include <algorithm>
+#include <cassert>
+
+#include "test_iterators.h"
+
+struct is_odd
+{
+ bool operator()(const int& i) const {return i & 1;}
+};
+
+int main()
+{
+ {
+ const int ia[] = {2, 4, 6, 8, 10};
+ assert(std::partition_point(forward_iterator<const int*>(std::begin(ia)),
+ forward_iterator<const int*>(std::end(ia)),
+ is_odd()) == forward_iterator<const int*>(ia));
+ }
+ {
+ const int ia[] = {1, 2, 4, 6, 8};
+ assert(std::partition_point(forward_iterator<const int*>(std::begin(ia)),
+ forward_iterator<const int*>(std::end(ia)),
+ is_odd()) == forward_iterator<const int*>(ia + 1));
+ }
+ {
+ const int ia[] = {1, 3, 2, 4, 6};
+ assert(std::partition_point(forward_iterator<const int*>(std::begin(ia)),
+ forward_iterator<const int*>(std::end(ia)),
+ is_odd()) == forward_iterator<const int*>(ia + 2));
+ }
+ {
+ const int ia[] = {1, 3, 5, 2, 4, 6};
+ assert(std::partition_point(forward_iterator<const int*>(std::begin(ia)),
+ forward_iterator<const int*>(std::end(ia)),
+ is_odd()) == forward_iterator<const int*>(ia + 3));
+ }
+ {
+ const int ia[] = {1, 3, 5, 7, 2, 4};
+ assert(std::partition_point(forward_iterator<const int*>(std::begin(ia)),
+ forward_iterator<const int*>(std::end(ia)),
+ is_odd()) == forward_iterator<const int*>(ia + 4));
+ }
+ {
+ const int ia[] = {1, 3, 5, 7, 9, 2};
+ assert(std::partition_point(forward_iterator<const int*>(std::begin(ia)),
+ forward_iterator<const int*>(std::end(ia)),
+ is_odd()) == forward_iterator<const int*>(ia + 5));
+ }
+ {
+ const int ia[] = {1, 3, 5, 7, 9, 11};
+ assert(std::partition_point(forward_iterator<const int*>(std::begin(ia)),
+ forward_iterator<const int*>(std::end(ia)),
+ is_odd()) == forward_iterator<const int*>(ia + 6));
+ }
+ {
+ const int ia[] = {1, 3, 5, 2, 4, 6, 7};
+ assert(std::partition_point(forward_iterator<const int*>(std::begin(ia)),
+ forward_iterator<const int*>(std::begin(ia)),
+ is_odd()) == forward_iterator<const int*>(ia));
+ }
+}
diff --git a/libcxx/test/std/algorithms/alg.modifying.operations/alg.partitions/stable_partition.pass.cpp b/libcxx/test/std/algorithms/alg.modifying.operations/alg.partitions/stable_partition.pass.cpp
new file mode 100644
index 00000000000..7810dec2fe1
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.modifying.operations/alg.partitions/stable_partition.pass.cpp
@@ -0,0 +1,314 @@
+//===----------------------------------------------------------------------===//
+//
+// 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<BidirectionalIterator Iter, Predicate<auto, Iter::value_type> Pred>
+// requires ShuffleIterator<Iter>
+// && CopyConstructible<Pred>
+// Iter
+// stable_partition(Iter first, Iter last, Pred pred);
+
+#include <algorithm>
+#include <cassert>
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+#include <memory>
+#endif
+
+#include "test_iterators.h"
+
+struct is_odd
+{
+ bool operator()(const int& i) const {return i & 1;}
+};
+
+struct odd_first
+{
+ bool operator()(const std::pair<int,int>& p) const
+ {return p.first & 1;}
+};
+
+template <class Iter>
+void
+test()
+{
+ { // check mixed
+ typedef std::pair<int,int> P;
+ P array[] =
+ {
+ P(0, 1),
+ P(0, 2),
+ P(1, 1),
+ P(1, 2),
+ P(2, 1),
+ P(2, 2),
+ P(3, 1),
+ P(3, 2),
+ P(4, 1),
+ P(4, 2)
+ };
+ const unsigned size = sizeof(array)/sizeof(array[0]);
+ Iter r = std::stable_partition(Iter(array), Iter(array+size), odd_first());
+ assert(base(r) == array + 4);
+ assert(array[0] == P(1, 1));
+ assert(array[1] == P(1, 2));
+ assert(array[2] == P(3, 1));
+ assert(array[3] == P(3, 2));
+ assert(array[4] == P(0, 1));
+ assert(array[5] == P(0, 2));
+ assert(array[6] == P(2, 1));
+ assert(array[7] == P(2, 2));
+ assert(array[8] == P(4, 1));
+ assert(array[9] == P(4, 2));
+ }
+ {
+ typedef std::pair<int,int> P;
+ P array[] =
+ {
+ P(0, 1),
+ P(0, 2),
+ P(1, 1),
+ P(1, 2),
+ P(2, 1),
+ P(2, 2),
+ P(3, 1),
+ P(3, 2),
+ P(4, 1),
+ P(4, 2)
+ };
+ const unsigned size = sizeof(array)/sizeof(array[0]);
+ Iter r = std::stable_partition(Iter(array), Iter(array+size), odd_first());
+ assert(base(r) == array + 4);
+ assert(array[0] == P(1, 1));
+ assert(array[1] == P(1, 2));
+ assert(array[2] == P(3, 1));
+ assert(array[3] == P(3, 2));
+ assert(array[4] == P(0, 1));
+ assert(array[5] == P(0, 2));
+ assert(array[6] == P(2, 1));
+ assert(array[7] == P(2, 2));
+ assert(array[8] == P(4, 1));
+ assert(array[9] == P(4, 2));
+ // check empty
+ r = std::stable_partition(Iter(array), Iter(array), odd_first());
+ assert(base(r) == array);
+ // check one true
+ r = std::stable_partition(Iter(array), Iter(array+1), odd_first());
+ assert(base(r) == array+1);
+ assert(array[0] == P(1, 1));
+ // check one false
+ r = std::stable_partition(Iter(array+4), Iter(array+5), odd_first());
+ assert(base(r) == array+4);
+ assert(array[4] == P(0, 1));
+ }
+ { // check all false
+ typedef std::pair<int,int> P;
+ P array[] =
+ {
+ P(0, 1),
+ P(0, 2),
+ P(2, 1),
+ P(2, 2),
+ P(4, 1),
+ P(4, 2),
+ P(6, 1),
+ P(6, 2),
+ P(8, 1),
+ P(8, 2)
+ };
+ const unsigned size = sizeof(array)/sizeof(array[0]);
+ Iter r = std::stable_partition(Iter(array), Iter(array+size), odd_first());
+ assert(base(r) == array);
+ assert(array[0] == P(0, 1));
+ assert(array[1] == P(0, 2));
+ assert(array[2] == P(2, 1));
+ assert(array[3] == P(2, 2));
+ assert(array[4] == P(4, 1));
+ assert(array[5] == P(4, 2));
+ assert(array[6] == P(6, 1));
+ assert(array[7] == P(6, 2));
+ assert(array[8] == P(8, 1));
+ assert(array[9] == P(8, 2));
+ }
+ { // check all true
+ typedef std::pair<int,int> P;
+ P array[] =
+ {
+ P(1, 1),
+ P(1, 2),
+ P(3, 1),
+ P(3, 2),
+ P(5, 1),
+ P(5, 2),
+ P(7, 1),
+ P(7, 2),
+ P(9, 1),
+ P(9, 2)
+ };
+ const unsigned size = sizeof(array)/sizeof(array[0]);
+ Iter r = std::stable_partition(Iter(array), Iter(array+size), odd_first());
+ assert(base(r) == array + size);
+ assert(array[0] == P(1, 1));
+ assert(array[1] == P(1, 2));
+ assert(array[2] == P(3, 1));
+ assert(array[3] == P(3, 2));
+ assert(array[4] == P(5, 1));
+ assert(array[5] == P(5, 2));
+ assert(array[6] == P(7, 1));
+ assert(array[7] == P(7, 2));
+ assert(array[8] == P(9, 1));
+ assert(array[9] == P(9, 2));
+ }
+ { // check all false but first true
+ typedef std::pair<int,int> P;
+ P array[] =
+ {
+ P(1, 1),
+ P(0, 2),
+ P(2, 1),
+ P(2, 2),
+ P(4, 1),
+ P(4, 2),
+ P(6, 1),
+ P(6, 2),
+ P(8, 1),
+ P(8, 2)
+ };
+ const unsigned size = sizeof(array)/sizeof(array[0]);
+ Iter r = std::stable_partition(Iter(array), Iter(array+size), odd_first());
+ assert(base(r) == array + 1);
+ assert(array[0] == P(1, 1));
+ assert(array[1] == P(0, 2));
+ assert(array[2] == P(2, 1));
+ assert(array[3] == P(2, 2));
+ assert(array[4] == P(4, 1));
+ assert(array[5] == P(4, 2));
+ assert(array[6] == P(6, 1));
+ assert(array[7] == P(6, 2));
+ assert(array[8] == P(8, 1));
+ assert(array[9] == P(8, 2));
+ }
+ { // check all false but last true
+ typedef std::pair<int,int> P;
+ P array[] =
+ {
+ P(0, 1),
+ P(0, 2),
+ P(2, 1),
+ P(2, 2),
+ P(4, 1),
+ P(4, 2),
+ P(6, 1),
+ P(6, 2),
+ P(8, 1),
+ P(1, 2)
+ };
+ const unsigned size = sizeof(array)/sizeof(array[0]);
+ Iter r = std::stable_partition(Iter(array), Iter(array+size), odd_first());
+ assert(base(r) == array + 1);
+ assert(array[0] == P(1, 2));
+ assert(array[1] == P(0, 1));
+ assert(array[2] == P(0, 2));
+ assert(array[3] == P(2, 1));
+ assert(array[4] == P(2, 2));
+ assert(array[5] == P(4, 1));
+ assert(array[6] == P(4, 2));
+ assert(array[7] == P(6, 1));
+ assert(array[8] == P(6, 2));
+ assert(array[9] == P(8, 1));
+ }
+ { // check all true but first false
+ typedef std::pair<int,int> P;
+ P array[] =
+ {
+ P(0, 1),
+ P(1, 2),
+ P(3, 1),
+ P(3, 2),
+ P(5, 1),
+ P(5, 2),
+ P(7, 1),
+ P(7, 2),
+ P(9, 1),
+ P(9, 2)
+ };
+ const unsigned size = sizeof(array)/sizeof(array[0]);
+ Iter r = std::stable_partition(Iter(array), Iter(array+size), odd_first());
+ assert(base(r) == array + size-1);
+ assert(array[0] == P(1, 2));
+ assert(array[1] == P(3, 1));
+ assert(array[2] == P(3, 2));
+ assert(array[3] == P(5, 1));
+ assert(array[4] == P(5, 2));
+ assert(array[5] == P(7, 1));
+ assert(array[6] == P(7, 2));
+ assert(array[7] == P(9, 1));
+ assert(array[8] == P(9, 2));
+ assert(array[9] == P(0, 1));
+ }
+ { // check all true but last false
+ typedef std::pair<int,int> P;
+ P array[] =
+ {
+ P(1, 1),
+ P(1, 2),
+ P(3, 1),
+ P(3, 2),
+ P(5, 1),
+ P(5, 2),
+ P(7, 1),
+ P(7, 2),
+ P(9, 1),
+ P(0, 2)
+ };
+ const unsigned size = sizeof(array)/sizeof(array[0]);
+ Iter r = std::stable_partition(Iter(array), Iter(array+size), odd_first());
+ assert(base(r) == array + size-1);
+ assert(array[0] == P(1, 1));
+ assert(array[1] == P(1, 2));
+ assert(array[2] == P(3, 1));
+ assert(array[3] == P(3, 2));
+ assert(array[4] == P(5, 1));
+ assert(array[5] == P(5, 2));
+ assert(array[6] == P(7, 1));
+ assert(array[7] == P(7, 2));
+ assert(array[8] == P(9, 1));
+ assert(array[9] == P(0, 2));
+ }
+}
+
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+
+struct is_null
+{
+ template <class P>
+ bool operator()(const P& p) {return p == 0;}
+};
+
+template <class Iter>
+void
+test1()
+{
+ const unsigned size = 5;
+ std::unique_ptr<int> array[size];
+ Iter r = std::stable_partition(Iter(array), Iter(array+size), is_null());
+}
+
+#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
+
+int main()
+{
+ test<bidirectional_iterator<std::pair<int,int>*> >();
+ test<random_access_iterator<std::pair<int,int>*> >();
+ test<std::pair<int,int>*>();
+
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+ test1<bidirectional_iterator<std::unique_ptr<int>*> >();
+#endif
+}
diff --git a/libcxx/test/std/algorithms/alg.modifying.operations/alg.random.shuffle/random_shuffle.pass.cpp b/libcxx/test/std/algorithms/alg.modifying.operations/alg.random.shuffle/random_shuffle.pass.cpp
new file mode 100644
index 00000000000..a14ccf9e5e6
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.modifying.operations/alg.random.shuffle/random_shuffle.pass.cpp
@@ -0,0 +1,30 @@
+//===----------------------------------------------------------------------===//
+//
+// 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<RandomAccessIterator Iter>
+// requires ShuffleIterator<Iter>
+// void
+// random_shuffle(Iter first, Iter last);
+
+#include <algorithm>
+#include <cassert>
+
+int main()
+{
+ int ia[] = {1, 2, 3, 4};
+ int ia1[] = {1, 4, 3, 2};
+ int ia2[] = {4, 1, 2, 3};
+ const unsigned sa = sizeof(ia)/sizeof(ia[0]);
+ std::random_shuffle(ia, ia+sa);
+ assert(std::equal(ia, ia+sa, ia1));
+ std::random_shuffle(ia, ia+sa);
+ assert(std::equal(ia, ia+sa, ia2));
+}
diff --git a/libcxx/test/std/algorithms/alg.modifying.operations/alg.random.shuffle/random_shuffle_rand.pass.cpp b/libcxx/test/std/algorithms/alg.modifying.operations/alg.random.shuffle/random_shuffle_rand.pass.cpp
new file mode 100644
index 00000000000..b944c89e351
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.modifying.operations/alg.random.shuffle/random_shuffle_rand.pass.cpp
@@ -0,0 +1,37 @@
+//===----------------------------------------------------------------------===//
+//
+// 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<RandomAccessIterator Iter, Callable<auto, Iter::difference_type> Rand>
+// requires ShuffleIterator<Iter>
+// && Convertible<Rand::result_type, Iter::difference_type>
+// void
+// random_shuffle(Iter first, Iter last, Rand&& rand);
+
+#include <algorithm>
+#include <cassert>
+
+struct gen
+{
+ int operator()(int n)
+ {
+ return n-1;
+ }
+};
+
+int main()
+{
+ int ia[] = {1, 2, 3, 4};
+ int ia1[] = {4, 1, 2, 3};
+ const unsigned sa = sizeof(ia)/sizeof(ia[0]);
+ gen r;
+ std::random_shuffle(ia, ia+sa, r);
+ assert(std::equal(ia, ia+sa, ia1));
+}
diff --git a/libcxx/test/std/algorithms/alg.modifying.operations/alg.random.shuffle/random_shuffle_urng.pass.cpp b/libcxx/test/std/algorithms/alg.modifying.operations/alg.random.shuffle/random_shuffle_urng.pass.cpp
new file mode 100644
index 00000000000..343ae90101f
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.modifying.operations/alg.random.shuffle/random_shuffle_urng.pass.cpp
@@ -0,0 +1,31 @@
+//===----------------------------------------------------------------------===//
+//
+// 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<class RandomAccessIterator, class UniformRandomNumberGenerator>
+// void shuffle(RandomAccessIterator first, RandomAccessIterator last,
+// UniformRandomNumberGenerator& g);
+
+#include <algorithm>
+#include <random>
+#include <cassert>
+
+int main()
+{
+ int ia[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
+ int ia1[] = {2, 7, 1, 4, 3, 6, 5, 10, 9, 8};
+ int ia2[] = {1, 8, 3, 4, 6, 9, 5, 7, 2, 10};
+ const unsigned sa = sizeof(ia)/sizeof(ia[0]);
+ std::minstd_rand g;
+ std::shuffle(ia, ia+sa, g);
+ assert(std::equal(ia, ia+sa, ia1));
+ std::shuffle(ia, ia+sa, g);
+ assert(std::equal(ia, ia+sa, ia2));
+}
diff --git a/libcxx/test/std/algorithms/alg.modifying.operations/alg.remove/remove.pass.cpp b/libcxx/test/std/algorithms/alg.modifying.operations/alg.remove/remove.pass.cpp
new file mode 100644
index 00000000000..80f86568c4d
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.modifying.operations/alg.remove/remove.pass.cpp
@@ -0,0 +1,83 @@
+//===----------------------------------------------------------------------===//
+//
+// 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, class T>
+// requires OutputIterator<Iter, RvalueOf<Iter::reference>::type>
+// && HasEqualTo<Iter::value_type, T>
+// Iter
+// remove(Iter first, Iter last, const T& value);
+
+#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, 1, 2, 3, 4, 2, 3, 4, 2};
+ const unsigned sa = sizeof(ia)/sizeof(ia[0]);
+ Iter r = std::remove(Iter(ia), Iter(ia+sa), 2);
+ assert(base(r) == ia + sa-3);
+ assert(ia[0] == 0);
+ assert(ia[1] == 1);
+ assert(ia[2] == 3);
+ assert(ia[3] == 4);
+ assert(ia[4] == 3);
+ assert(ia[5] == 4);
+}
+
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+
+template <class Iter>
+void
+test1()
+{
+ const unsigned sa = 9;
+ std::unique_ptr<int> ia[sa];
+ ia[0].reset(new int(0));
+ ia[1].reset(new int(1));
+ ia[3].reset(new int(3));
+ ia[4].reset(new int(4));
+ ia[6].reset(new int(3));
+ ia[7].reset(new int(4));
+ Iter r = std::remove(Iter(ia), Iter(ia+sa), std::unique_ptr<int>());
+ assert(base(r) == ia + sa-3);
+ assert(*ia[0] == 0);
+ assert(*ia[1] == 1);
+ assert(*ia[2] == 3);
+ assert(*ia[3] == 4);
+ assert(*ia[4] == 3);
+ assert(*ia[5] == 4);
+}
+
+#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<std::unique_ptr<int>*> >();
+ test1<bidirectional_iterator<std::unique_ptr<int>*> >();
+ test1<random_access_iterator<std::unique_ptr<int>*> >();
+ test1<std::unique_ptr<int>*>();
+
+#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
+}
diff --git a/libcxx/test/std/algorithms/alg.modifying.operations/alg.remove/remove_copy.pass.cpp b/libcxx/test/std/algorithms/alg.modifying.operations/alg.remove/remove_copy.pass.cpp
new file mode 100644
index 00000000000..bf5f79cf835
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.modifying.operations/alg.remove/remove_copy.pass.cpp
@@ -0,0 +1,70 @@
+//===----------------------------------------------------------------------===//
+//
+// 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, OutputIterator<auto, InIter::reference> OutIter, class T>
+// requires HasEqualTo<InIter::value_type, T>
+// OutIter
+// remove_copy(InIter first, InIter last, OutIter result, const T& value);
+
+#include <algorithm>
+#include <cassert>
+
+#include "test_iterators.h"
+
+template <class InIter, class OutIter>
+void
+test()
+{
+ int ia[] = {0, 1, 2, 3, 4, 2, 3, 4, 2};
+ const unsigned sa = sizeof(ia)/sizeof(ia[0]);
+ int ib[sa];
+ OutIter r = std::remove_copy(InIter(ia), InIter(ia+sa), OutIter(ib), 2);
+ assert(base(r) == ib + sa-3);
+ assert(ib[0] == 0);
+ assert(ib[1] == 1);
+ assert(ib[2] == 3);
+ assert(ib[3] == 4);
+ assert(ib[4] == 3);
+ assert(ib[5] == 4);
+}
+
+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.remove/remove_copy_if.pass.cpp b/libcxx/test/std/algorithms/alg.modifying.operations/alg.remove/remove_copy_if.pass.cpp
new file mode 100644
index 00000000000..de3f0a74104
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.modifying.operations/alg.remove/remove_copy_if.pass.cpp
@@ -0,0 +1,73 @@
+//===----------------------------------------------------------------------===//
+//
+// 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, OutputIterator<auto, InIter::reference> OutIter,
+// Predicate<auto, InIter::value_type> Pred>
+// requires CopyConstructible<Pred>
+// OutIter
+// remove_copy_if(InIter first, InIter last, OutIter result, Pred pred);
+
+#include <algorithm>
+#include <functional>
+#include <cassert>
+
+#include "test_iterators.h"
+
+template <class InIter, class OutIter>
+void
+test()
+{
+ int ia[] = {0, 1, 2, 3, 4, 2, 3, 4, 2};
+ const unsigned sa = sizeof(ia)/sizeof(ia[0]);
+ int ib[sa];
+ OutIter r = std::remove_copy_if(InIter(ia), InIter(ia+sa), OutIter(ib),
+ std::bind2nd(std::equal_to<int>(), 2));
+ assert(base(r) == ib + sa-3);
+ assert(ib[0] == 0);
+ assert(ib[1] == 1);
+ assert(ib[2] == 3);
+ assert(ib[3] == 4);
+ assert(ib[4] == 3);
+ assert(ib[5] == 4);
+}
+
+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.remove/remove_if.pass.cpp b/libcxx/test/std/algorithms/alg.modifying.operations/alg.remove/remove_if.pass.cpp
new file mode 100644
index 00000000000..b234431295a
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.modifying.operations/alg.remove/remove_if.pass.cpp
@@ -0,0 +1,98 @@
+//===----------------------------------------------------------------------===//
+//
+// 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, Predicate<auto, Iter::value_type> Pred>
+// requires OutputIterator<Iter, RvalueOf<Iter::reference>::type>
+// && CopyConstructible<Pred>
+// Iter
+// remove_if(Iter first, Iter last, Pred pred);
+
+#include <algorithm>
+#include <functional>
+#include <cassert>
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+#include <memory>
+#endif
+
+#include "test_iterators.h"
+#include "counting_predicates.hpp"
+
+bool equal2 ( int i ) { return i == 2; }
+
+template <class Iter>
+void
+test()
+{
+ int ia[] = {0, 1, 2, 3, 4, 2, 3, 4, 2};
+ const unsigned sa = sizeof(ia)/sizeof(ia[0]);
+// int* r = std::remove_if(ia, ia+sa, std::bind2nd(std::equal_to<int>(), 2));
+ unary_counting_predicate<bool(*)(int), int> cp(equal2);
+ int* r = std::remove_if(ia, ia+sa, std::ref(cp));
+ assert(r == ia + sa-3);
+ assert(ia[0] == 0);
+ assert(ia[1] == 1);
+ assert(ia[2] == 3);
+ assert(ia[3] == 4);
+ assert(ia[4] == 3);
+ assert(ia[5] == 4);
+ assert(cp.count() == sa);
+}
+
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+
+struct pred
+{
+ bool operator()(const std::unique_ptr<int>& i) {return *i == 2;}
+};
+
+template <class Iter>
+void
+test1()
+{
+ const unsigned sa = 9;
+ std::unique_ptr<int> ia[sa];
+ ia[0].reset(new int(0));
+ ia[1].reset(new int(1));
+ ia[2].reset(new int(2));
+ ia[3].reset(new int(3));
+ ia[4].reset(new int(4));
+ ia[5].reset(new int(2));
+ ia[6].reset(new int(3));
+ ia[7].reset(new int(4));
+ ia[8].reset(new int(2));
+ Iter r = std::remove_if(Iter(ia), Iter(ia+sa), pred());
+ assert(base(r) == ia + sa-3);
+ assert(*ia[0] == 0);
+ assert(*ia[1] == 1);
+ assert(*ia[2] == 3);
+ assert(*ia[3] == 4);
+ assert(*ia[4] == 3);
+ assert(*ia[5] == 4);
+}
+
+#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<std::unique_ptr<int>*> >();
+ test1<bidirectional_iterator<std::unique_ptr<int>*> >();
+ test1<random_access_iterator<std::unique_ptr<int>*> >();
+ test1<std::unique_ptr<int>*>();
+
+#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
+}
diff --git a/libcxx/test/std/algorithms/alg.modifying.operations/alg.replace/replace.pass.cpp b/libcxx/test/std/algorithms/alg.modifying.operations/alg.replace/replace.pass.cpp
new file mode 100644
index 00000000000..f6033351ffc
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.modifying.operations/alg.replace/replace.pass.cpp
@@ -0,0 +1,44 @@
+//===----------------------------------------------------------------------===//
+//
+// 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, class T>
+// requires OutputIterator<Iter, Iter::reference>
+// && OutputIterator<Iter, const T&>
+// && HasEqualTo<Iter::value_type, T>
+// void
+// replace(Iter first, Iter last, const T& old_value, const T& new_value);
+
+#include <algorithm>
+#include <cassert>
+
+#include "test_iterators.h"
+
+template <class Iter>
+void
+test()
+{
+ int ia[] = {0, 1, 2, 3, 4};
+ const unsigned sa = sizeof(ia)/sizeof(ia[0]);
+ std::replace(Iter(ia), Iter(ia+sa), 2, 5);
+ assert(ia[0] == 0);
+ assert(ia[1] == 1);
+ assert(ia[2] == 5);
+ assert(ia[3] == 3);
+ assert(ia[4] == 4);
+}
+
+int main()
+{
+ test<forward_iterator<int*> >();
+ test<bidirectional_iterator<int*> >();
+ test<random_access_iterator<int*> >();
+ test<int*>();
+}
diff --git a/libcxx/test/std/algorithms/alg.modifying.operations/alg.replace/replace_copy.pass.cpp b/libcxx/test/std/algorithms/alg.modifying.operations/alg.replace/replace_copy.pass.cpp
new file mode 100644
index 00000000000..3c4d0e50817
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.modifying.operations/alg.replace/replace_copy.pass.cpp
@@ -0,0 +1,72 @@
+//===----------------------------------------------------------------------===//
+//
+// 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, typename OutIter, class T>
+// requires OutputIterator<OutIter, InIter::reference>
+// && OutputIterator<OutIter, const T&>
+// && HasEqualTo<InIter::value_type, T>
+// OutIter
+// replace_copy(InIter first, InIter last, OutIter result, const T& old_value,
+// const T& new_value);
+
+#include <algorithm>
+#include <cassert>
+
+#include "test_iterators.h"
+
+template <class InIter, class OutIter>
+void
+test()
+{
+ int ia[] = {0, 1, 2, 3, 4};
+ const unsigned sa = sizeof(ia)/sizeof(ia[0]);
+ int ib[sa] = {0};
+ OutIter r = std::replace_copy(InIter(ia), InIter(ia+sa), OutIter(ib), 2, 5);
+ assert(base(r) == ib + sa);
+ assert(ib[0] == 0);
+ assert(ib[1] == 1);
+ assert(ib[2] == 5);
+ assert(ib[3] == 3);
+ assert(ib[4] == 4);
+}
+
+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.replace/replace_copy_if.pass.cpp b/libcxx/test/std/algorithms/alg.modifying.operations/alg.replace/replace_copy_if.pass.cpp
new file mode 100644
index 00000000000..1eff3d39e20
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.modifying.operations/alg.replace/replace_copy_if.pass.cpp
@@ -0,0 +1,74 @@
+//===----------------------------------------------------------------------===//
+//
+// 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, typename OutIter,
+// Predicate<auto, InIter::value_type> Pred, class T>
+// requires OutputIterator<OutIter, InIter::reference>
+// && OutputIterator<OutIter, const T&>
+// && CopyConstructible<Pred>
+// OutIter
+// replace_copy_if(InIter first, InIter last, OutIter result, Pred pred, const T& new_value);
+
+#include <algorithm>
+#include <functional>
+#include <cassert>
+
+#include "test_iterators.h"
+
+template <class InIter, class OutIter>
+void
+test()
+{
+ int ia[] = {0, 1, 2, 3, 4};
+ const unsigned sa = sizeof(ia)/sizeof(ia[0]);
+ int ib[sa] = {0};
+ OutIter r = std::replace_copy_if(InIter(ia), InIter(ia+sa), OutIter(ib),
+ std::bind2nd(std::equal_to<int>(), 2), 5);
+ assert(base(r) == ib + sa);
+ assert(ib[0] == 0);
+ assert(ib[1] == 1);
+ assert(ib[2] == 5);
+ assert(ib[3] == 3);
+ assert(ib[4] == 4);
+}
+
+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.replace/replace_if.pass.cpp b/libcxx/test/std/algorithms/alg.modifying.operations/alg.replace/replace_if.pass.cpp
new file mode 100644
index 00000000000..8d6ab04e14d
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.modifying.operations/alg.replace/replace_if.pass.cpp
@@ -0,0 +1,45 @@
+//===----------------------------------------------------------------------===//
+//
+// 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, Predicate<auto, Iter::value_type> Pred, class T>
+// requires OutputIterator<Iter, Iter::reference>
+// && OutputIterator<Iter, const T&>
+// && CopyConstructible<Pred>
+// void
+// replace_if(Iter first, Iter last, Pred pred, const T& new_value);
+
+#include <algorithm>
+#include <functional>
+#include <cassert>
+
+#include "test_iterators.h"
+
+template <class Iter>
+void
+test()
+{
+ int ia[] = {0, 1, 2, 3, 4};
+ const unsigned sa = sizeof(ia)/sizeof(ia[0]);
+ std::replace_if(Iter(ia), Iter(ia+sa), std::bind2nd(std::equal_to<int>(), 2), 5);
+ assert(ia[0] == 0);
+ assert(ia[1] == 1);
+ assert(ia[2] == 5);
+ assert(ia[3] == 3);
+ assert(ia[4] == 4);
+}
+
+int main()
+{
+ test<forward_iterator<int*> >();
+ test<bidirectional_iterator<int*> >();
+ test<random_access_iterator<int*> >();
+ test<int*>();
+}
diff --git a/libcxx/test/std/algorithms/alg.modifying.operations/alg.reverse/reverse.pass.cpp b/libcxx/test/std/algorithms/alg.modifying.operations/alg.reverse/reverse.pass.cpp
new file mode 100644
index 00000000000..6c49605b661
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.modifying.operations/alg.reverse/reverse.pass.cpp
@@ -0,0 +1,60 @@
+//===----------------------------------------------------------------------===//
+//
+// 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<BidirectionalIterator Iter>
+// requires HasSwap<Iter::reference, Iter::reference>
+// void
+// reverse(Iter first, Iter last);
+
+#include <algorithm>
+#include <cassert>
+
+#include "test_iterators.h"
+
+template <class Iter>
+void
+test()
+{
+ int ia[] = {0};
+ const unsigned sa = sizeof(ia)/sizeof(ia[0]);
+ std::reverse(Iter(ia), Iter(ia));
+ assert(ia[0] == 0);
+ std::reverse(Iter(ia), Iter(ia+sa));
+ assert(ia[0] == 0);
+
+ int ib[] = {0, 1};
+ const unsigned sb = sizeof(ib)/sizeof(ib[0]);
+ std::reverse(Iter(ib), Iter(ib+sb));
+ assert(ib[0] == 1);
+ assert(ib[1] == 0);
+
+ int ic[] = {0, 1, 2};
+ const unsigned sc = sizeof(ic)/sizeof(ic[0]);
+ std::reverse(Iter(ic), Iter(ic+sc));
+ assert(ic[0] == 2);
+ assert(ic[1] == 1);
+ assert(ic[2] == 0);
+
+ int id[] = {0, 1, 2, 3};
+ const unsigned sd = sizeof(id)/sizeof(id[0]);
+ std::reverse(Iter(id), Iter(id+sd));
+ assert(id[0] == 3);
+ assert(id[1] == 2);
+ assert(id[2] == 1);
+ assert(id[3] == 0);
+}
+
+int main()
+{
+ test<bidirectional_iterator<int*> >();
+ test<random_access_iterator<int*> >();
+ test<int*>();
+}
diff --git a/libcxx/test/std/algorithms/alg.modifying.operations/alg.reverse/reverse_copy.pass.cpp b/libcxx/test/std/algorithms/alg.modifying.operations/alg.reverse/reverse_copy.pass.cpp
new file mode 100644
index 00000000000..70840d187bf
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.modifying.operations/alg.reverse/reverse_copy.pass.cpp
@@ -0,0 +1,81 @@
+//===----------------------------------------------------------------------===//
+//
+// 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<BidirectionalIterator InIter, OutputIterator<auto, InIter::reference> OutIter>
+// OutIter
+// reverse_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::reverse_copy(InIter(ia), InIter(ia), OutIter(ja));
+ assert(base(r) == ja);
+ assert(ja[0] == -1);
+ r = std::reverse_copy(InIter(ia), InIter(ia+sa), OutIter(ja));
+ assert(ja[0] == 0);
+
+ const int ib[] = {0, 1};
+ const unsigned sb = sizeof(ib)/sizeof(ib[0]);
+ int jb[sb] = {-1};
+ r = std::reverse_copy(InIter(ib), InIter(ib+sb), OutIter(jb));
+ assert(base(r) == jb+sb);
+ assert(jb[0] == 1);
+ assert(jb[1] == 0);
+
+ const int ic[] = {0, 1, 2};
+ const unsigned sc = sizeof(ic)/sizeof(ic[0]);
+ int jc[sc] = {-1};
+ r = std::reverse_copy(InIter(ic), InIter(ic+sc), OutIter(jc));
+ assert(base(r) == jc+sc);
+ assert(jc[0] == 2);
+ assert(jc[1] == 1);
+ assert(jc[2] == 0);
+
+ int id[] = {0, 1, 2, 3};
+ const unsigned sd = sizeof(id)/sizeof(id[0]);
+ int jd[sd] = {-1};
+ r = std::reverse_copy(InIter(id), InIter(id+sd), OutIter(jd));
+ assert(base(r) == jd+sd);
+ assert(jd[0] == 3);
+ assert(jd[1] == 2);
+ assert(jd[2] == 1);
+ assert(jd[3] == 0);
+}
+
+int main()
+{
+ 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.rotate/rotate.pass.cpp b/libcxx/test/std/algorithms/alg.modifying.operations/alg.rotate/rotate.pass.cpp
new file mode 100644
index 00000000000..b7da7354ca2
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.modifying.operations/alg.rotate/rotate.pass.cpp
@@ -0,0 +1,439 @@
+//===----------------------------------------------------------------------===//
+//
+// 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<ShuffleIterator Iter>
+// Iter
+// rotate(Iter first, Iter middle, 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::rotate(Iter(ia), Iter(ia), Iter(ia));
+ assert(base(r) == ia);
+ assert(ia[0] == 0);
+ r = std::rotate(Iter(ia), Iter(ia), Iter(ia+sa));
+ assert(base(r) == ia+sa);
+ assert(ia[0] == 0);
+ r = std::rotate(Iter(ia), Iter(ia+sa), Iter(ia+sa));
+ assert(base(r) == ia);
+ assert(ia[0] == 0);
+
+ int ib[] = {0, 1};
+ const unsigned sb = sizeof(ib)/sizeof(ib[0]);
+ r = std::rotate(Iter(ib), Iter(ib), Iter(ib+sb));
+ assert(base(r) == ib+sb);
+ assert(ib[0] == 0);
+ assert(ib[1] == 1);
+ r = std::rotate(Iter(ib), Iter(ib+1), Iter(ib+sb));
+ assert(base(r) == ib+1);
+ assert(ib[0] == 1);
+ assert(ib[1] == 0);
+ r = std::rotate(Iter(ib), Iter(ib+sb), Iter(ib+sb));
+ assert(base(r) == ib);
+ assert(ib[0] == 1);
+ assert(ib[1] == 0);
+
+ int ic[] = {0, 1, 2};
+ const unsigned sc = sizeof(ic)/sizeof(ic[0]);
+ r = std::rotate(Iter(ic), Iter(ic), Iter(ic+sc));
+ assert(base(r) == ic+sc);
+ assert(ic[0] == 0);
+ assert(ic[1] == 1);
+ assert(ic[2] == 2);
+ r = std::rotate(Iter(ic), Iter(ic+1), Iter(ic+sc));
+ assert(base(r) == ic+2);
+ assert(ic[0] == 1);
+ assert(ic[1] == 2);
+ assert(ic[2] == 0);
+ r = std::rotate(Iter(ic), Iter(ic+2), Iter(ic+sc));
+ assert(base(r) == ic+1);
+ assert(ic[0] == 0);
+ assert(ic[1] == 1);
+ assert(ic[2] == 2);
+ r = std::rotate(Iter(ic), Iter(ic+sc), Iter(ic+sc));
+ assert(base(r) == ic);
+ assert(ic[0] == 0);
+ assert(ic[1] == 1);
+ assert(ic[2] == 2);
+
+ int id[] = {0, 1, 2, 3};
+ const unsigned sd = sizeof(id)/sizeof(id[0]);
+ r = std::rotate(Iter(id), Iter(id), Iter(id+sd));
+ assert(base(r) == id+sd);
+ assert(id[0] == 0);
+ assert(id[1] == 1);
+ assert(id[2] == 2);
+ assert(id[3] == 3);
+ r = std::rotate(Iter(id), Iter(id+1), Iter(id+sd));
+ assert(base(r) == id+3);
+ assert(id[0] == 1);
+ assert(id[1] == 2);
+ assert(id[2] == 3);
+ assert(id[3] == 0);
+ r = std::rotate(Iter(id), Iter(id+2), Iter(id+sd));
+ assert(base(r) == id+2);
+ assert(id[0] == 3);
+ assert(id[1] == 0);
+ assert(id[2] == 1);
+ assert(id[3] == 2);
+ r = std::rotate(Iter(id), Iter(id+3), Iter(id+sd));
+ assert(base(r) == id+1);
+ assert(id[0] == 2);
+ assert(id[1] == 3);
+ assert(id[2] == 0);
+ assert(id[3] == 1);
+ r = std::rotate(Iter(id), Iter(id+sd), Iter(id+sd));
+ assert(base(r) == id);
+ assert(id[0] == 2);
+ assert(id[1] == 3);
+ assert(id[2] == 0);
+ assert(id[3] == 1);
+
+ int ie[] = {0, 1, 2, 3, 4};
+ const unsigned se = sizeof(ie)/sizeof(ie[0]);
+ r = std::rotate(Iter(ie), Iter(ie), Iter(ie+se));
+ assert(base(r) == ie+se);
+ assert(ie[0] == 0);
+ assert(ie[1] == 1);
+ assert(ie[2] == 2);
+ assert(ie[3] == 3);
+ assert(ie[4] == 4);
+ r = std::rotate(Iter(ie), Iter(ie+1), Iter(ie+se));
+ assert(base(r) == ie+4);
+ assert(ie[0] == 1);
+ assert(ie[1] == 2);
+ assert(ie[2] == 3);
+ assert(ie[3] == 4);
+ assert(ie[4] == 0);
+ r = std::rotate(Iter(ie), Iter(ie+2), Iter(ie+se));
+ assert(base(r) == ie+3);
+ assert(ie[0] == 3);
+ assert(ie[1] == 4);
+ assert(ie[2] == 0);
+ assert(ie[3] == 1);
+ assert(ie[4] == 2);
+ r = std::rotate(Iter(ie), Iter(ie+3), Iter(ie+se));
+ assert(base(r) == ie+2);
+ assert(ie[0] == 1);
+ assert(ie[1] == 2);
+ assert(ie[2] == 3);
+ assert(ie[3] == 4);
+ assert(ie[4] == 0);
+ r = std::rotate(Iter(ie), Iter(ie+4), Iter(ie+se));
+ assert(base(r) == ie+1);
+ assert(ie[0] == 0);
+ assert(ie[1] == 1);
+ assert(ie[2] == 2);
+ assert(ie[3] == 3);
+ assert(ie[4] == 4);
+ r = std::rotate(Iter(ie), Iter(ie+se), Iter(ie+se));
+ assert(base(r) == ie);
+ assert(ie[0] == 0);
+ assert(ie[1] == 1);
+ assert(ie[2] == 2);
+ assert(ie[3] == 3);
+ assert(ie[4] == 4);
+
+ int ig[] = {0, 1, 2, 3, 4, 5};
+ const unsigned sg = sizeof(ig)/sizeof(ig[0]);
+ r = std::rotate(Iter(ig), Iter(ig), Iter(ig+sg));
+ assert(base(r) == ig+sg);
+ assert(ig[0] == 0);
+ assert(ig[1] == 1);
+ assert(ig[2] == 2);
+ assert(ig[3] == 3);
+ assert(ig[4] == 4);
+ assert(ig[5] == 5);
+ r = std::rotate(Iter(ig), Iter(ig+1), Iter(ig+sg));
+ assert(base(r) == ig+5);
+ assert(ig[0] == 1);
+ assert(ig[1] == 2);
+ assert(ig[2] == 3);
+ assert(ig[3] == 4);
+ assert(ig[4] == 5);
+ assert(ig[5] == 0);
+ r = std::rotate(Iter(ig), Iter(ig+2), Iter(ig+sg));
+ assert(base(r) == ig+4);
+ assert(ig[0] == 3);
+ assert(ig[1] == 4);
+ assert(ig[2] == 5);
+ assert(ig[3] == 0);
+ assert(ig[4] == 1);
+ assert(ig[5] == 2);
+ r = std::rotate(Iter(ig), Iter(ig+3), Iter(ig+sg));
+ assert(base(r) == ig+3);
+ assert(ig[0] == 0);
+ assert(ig[1] == 1);
+ assert(ig[2] == 2);
+ assert(ig[3] == 3);
+ assert(ig[4] == 4);
+ assert(ig[5] == 5);
+ r = std::rotate(Iter(ig), Iter(ig+4), Iter(ig+sg));
+ assert(base(r) == ig+2);
+ assert(ig[0] == 4);
+ assert(ig[1] == 5);
+ assert(ig[2] == 0);
+ assert(ig[3] == 1);
+ assert(ig[4] == 2);
+ assert(ig[5] == 3);
+ r = std::rotate(Iter(ig), Iter(ig+5), Iter(ig+sg));
+ assert(base(r) == ig+1);
+ assert(ig[0] == 3);
+ assert(ig[1] == 4);
+ assert(ig[2] == 5);
+ assert(ig[3] == 0);
+ assert(ig[4] == 1);
+ assert(ig[5] == 2);
+ r = std::rotate(Iter(ig), Iter(ig+sg), Iter(ig+sg));
+ assert(base(r) == ig);
+ assert(ig[0] == 3);
+ assert(ig[1] == 4);
+ assert(ig[2] == 5);
+ assert(ig[3] == 0);
+ assert(ig[4] == 1);
+ assert(ig[5] == 2);
+}
+
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+
+template <class Iter>
+void
+test1()
+{
+ std::unique_ptr<int> ia[1];
+ const unsigned sa = sizeof(ia)/sizeof(ia[0]);
+ for (int i = 0; i < sa; ++i)
+ ia[i].reset(new int(i));
+ Iter r = std::rotate(Iter(ia), Iter(ia), Iter(ia));
+ assert(base(r) == ia);
+ assert(*ia[0] == 0);
+ r = std::rotate(Iter(ia), Iter(ia), Iter(ia+sa));
+ assert(base(r) == ia+sa);
+ assert(*ia[0] == 0);
+ r = std::rotate(Iter(ia), Iter(ia+sa), Iter(ia+sa));
+ assert(base(r) == ia);
+ assert(*ia[0] == 0);
+
+ std::unique_ptr<int> ib[2];
+ const unsigned sb = sizeof(ib)/sizeof(ib[0]);
+ for (int i = 0; i < sb; ++i)
+ ib[i].reset(new int(i));
+ r = std::rotate(Iter(ib), Iter(ib), Iter(ib+sb));
+ assert(base(r) == ib+sb);
+ assert(*ib[0] == 0);
+ assert(*ib[1] == 1);
+ r = std::rotate(Iter(ib), Iter(ib+1), Iter(ib+sb));
+ assert(base(r) == ib+1);
+ assert(*ib[0] == 1);
+ assert(*ib[1] == 0);
+ r = std::rotate(Iter(ib), Iter(ib+sb), Iter(ib+sb));
+ assert(base(r) == ib);
+ assert(*ib[0] == 1);
+ assert(*ib[1] == 0);
+
+ std::unique_ptr<int> ic[3];
+ const unsigned sc = sizeof(ic)/sizeof(ic[0]);
+ for (int i = 0; i < sc; ++i)
+ ic[i].reset(new int(i));
+ r = std::rotate(Iter(ic), Iter(ic), Iter(ic+sc));
+ assert(base(r) == ic+sc);
+ assert(*ic[0] == 0);
+ assert(*ic[1] == 1);
+ assert(*ic[2] == 2);
+ r = std::rotate(Iter(ic), Iter(ic+1), Iter(ic+sc));
+ assert(base(r) == ic+2);
+ assert(*ic[0] == 1);
+ assert(*ic[1] == 2);
+ assert(*ic[2] == 0);
+ r = std::rotate(Iter(ic), Iter(ic+2), Iter(ic+sc));
+ assert(base(r) == ic+1);
+ assert(*ic[0] == 0);
+ assert(*ic[1] == 1);
+ assert(*ic[2] == 2);
+ r = std::rotate(Iter(ic), Iter(ic+sc), Iter(ic+sc));
+ assert(base(r) == ic);
+ assert(*ic[0] == 0);
+ assert(*ic[1] == 1);
+ assert(*ic[2] == 2);
+
+ std::unique_ptr<int> id[4];
+ const unsigned sd = sizeof(id)/sizeof(id[0]);
+ for (int i = 0; i < sd; ++i)
+ id[i].reset(new int(i));
+ r = std::rotate(Iter(id), Iter(id), Iter(id+sd));
+ assert(base(r) == id+sd);
+ assert(*id[0] == 0);
+ assert(*id[1] == 1);
+ assert(*id[2] == 2);
+ assert(*id[3] == 3);
+ r = std::rotate(Iter(id), Iter(id+1), Iter(id+sd));
+ assert(base(r) == id+3);
+ assert(*id[0] == 1);
+ assert(*id[1] == 2);
+ assert(*id[2] == 3);
+ assert(*id[3] == 0);
+ r = std::rotate(Iter(id), Iter(id+2), Iter(id+sd));
+ assert(base(r) == id+2);
+ assert(*id[0] == 3);
+ assert(*id[1] == 0);
+ assert(*id[2] == 1);
+ assert(*id[3] == 2);
+ r = std::rotate(Iter(id), Iter(id+3), Iter(id+sd));
+ assert(base(r) == id+1);
+ assert(*id[0] == 2);
+ assert(*id[1] == 3);
+ assert(*id[2] == 0);
+ assert(*id[3] == 1);
+ r = std::rotate(Iter(id), Iter(id+sd), Iter(id+sd));
+ assert(base(r) == id);
+ assert(*id[0] == 2);
+ assert(*id[1] == 3);
+ assert(*id[2] == 0);
+ assert(*id[3] == 1);
+
+ std::unique_ptr<int> ie[5];
+ const unsigned se = sizeof(ie)/sizeof(ie[0]);
+ for (int i = 0; i < se; ++i)
+ ie[i].reset(new int(i));
+ r = std::rotate(Iter(ie), Iter(ie), Iter(ie+se));
+ assert(base(r) == ie+se);
+ assert(*ie[0] == 0);
+ assert(*ie[1] == 1);
+ assert(*ie[2] == 2);
+ assert(*ie[3] == 3);
+ assert(*ie[4] == 4);
+ r = std::rotate(Iter(ie), Iter(ie+1), Iter(ie+se));
+ assert(base(r) == ie+4);
+ assert(*ie[0] == 1);
+ assert(*ie[1] == 2);
+ assert(*ie[2] == 3);
+ assert(*ie[3] == 4);
+ assert(*ie[4] == 0);
+ r = std::rotate(Iter(ie), Iter(ie+2), Iter(ie+se));
+ assert(base(r) == ie+3);
+ assert(*ie[0] == 3);
+ assert(*ie[1] == 4);
+ assert(*ie[2] == 0);
+ assert(*ie[3] == 1);
+ assert(*ie[4] == 2);
+ r = std::rotate(Iter(ie), Iter(ie+3), Iter(ie+se));
+ assert(base(r) == ie+2);
+ assert(*ie[0] == 1);
+ assert(*ie[1] == 2);
+ assert(*ie[2] == 3);
+ assert(*ie[3] == 4);
+ assert(*ie[4] == 0);
+ r = std::rotate(Iter(ie), Iter(ie+4), Iter(ie+se));
+ assert(base(r) == ie+1);
+ assert(*ie[0] == 0);
+ assert(*ie[1] == 1);
+ assert(*ie[2] == 2);
+ assert(*ie[3] == 3);
+ assert(*ie[4] == 4);
+ r = std::rotate(Iter(ie), Iter(ie+se), Iter(ie+se));
+ assert(base(r) == ie);
+ assert(*ie[0] == 0);
+ assert(*ie[1] == 1);
+ assert(*ie[2] == 2);
+ assert(*ie[3] == 3);
+ assert(*ie[4] == 4);
+
+ std::unique_ptr<int> ig[6];
+ const unsigned sg = sizeof(ig)/sizeof(ig[0]);
+ for (int i = 0; i < sg; ++i)
+ ig[i].reset(new int(i));
+ r = std::rotate(Iter(ig), Iter(ig), Iter(ig+sg));
+ assert(base(r) == ig+sg);
+ assert(*ig[0] == 0);
+ assert(*ig[1] == 1);
+ assert(*ig[2] == 2);
+ assert(*ig[3] == 3);
+ assert(*ig[4] == 4);
+ assert(*ig[5] == 5);
+ r = std::rotate(Iter(ig), Iter(ig+1), Iter(ig+sg));
+ assert(base(r) == ig+5);
+ assert(*ig[0] == 1);
+ assert(*ig[1] == 2);
+ assert(*ig[2] == 3);
+ assert(*ig[3] == 4);
+ assert(*ig[4] == 5);
+ assert(*ig[5] == 0);
+ r = std::rotate(Iter(ig), Iter(ig+2), Iter(ig+sg));
+ assert(base(r) == ig+4);
+ assert(*ig[0] == 3);
+ assert(*ig[1] == 4);
+ assert(*ig[2] == 5);
+ assert(*ig[3] == 0);
+ assert(*ig[4] == 1);
+ assert(*ig[5] == 2);
+ r = std::rotate(Iter(ig), Iter(ig+3), Iter(ig+sg));
+ assert(base(r) == ig+3);
+ assert(*ig[0] == 0);
+ assert(*ig[1] == 1);
+ assert(*ig[2] == 2);
+ assert(*ig[3] == 3);
+ assert(*ig[4] == 4);
+ assert(*ig[5] == 5);
+ r = std::rotate(Iter(ig), Iter(ig+4), Iter(ig+sg));
+ assert(base(r) == ig+2);
+ assert(*ig[0] == 4);
+ assert(*ig[1] == 5);
+ assert(*ig[2] == 0);
+ assert(*ig[3] == 1);
+ assert(*ig[4] == 2);
+ assert(*ig[5] == 3);
+ r = std::rotate(Iter(ig), Iter(ig+5), Iter(ig+sg));
+ assert(base(r) == ig+1);
+ assert(*ig[0] == 3);
+ assert(*ig[1] == 4);
+ assert(*ig[2] == 5);
+ assert(*ig[3] == 0);
+ assert(*ig[4] == 1);
+ assert(*ig[5] == 2);
+ r = std::rotate(Iter(ig), Iter(ig+sg), Iter(ig+sg));
+ assert(base(r) == ig);
+ assert(*ig[0] == 3);
+ assert(*ig[1] == 4);
+ assert(*ig[2] == 5);
+ assert(*ig[3] == 0);
+ assert(*ig[4] == 1);
+ assert(*ig[5] == 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<std::unique_ptr<int>*> >();
+ test1<bidirectional_iterator<std::unique_ptr<int>*> >();
+ test1<random_access_iterator<std::unique_ptr<int>*> >();
+ test1<std::unique_ptr<int>*>();
+
+#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
+}
diff --git a/libcxx/test/std/algorithms/alg.modifying.operations/alg.rotate/rotate_copy.pass.cpp b/libcxx/test/std/algorithms/alg.modifying.operations/alg.rotate/rotate_copy.pass.cpp
new file mode 100644
index 00000000000..f2ad535a2f9
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.modifying.operations/alg.rotate/rotate_copy.pass.cpp
@@ -0,0 +1,134 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 InIter, OutputIterator<auto, InIter::reference> OutIter>
+// OutIter
+// rotate_copy(InIter first, InIter middle, InIter last, OutIter result);
+
+#include <algorithm>
+#include <cassert>
+
+#include "test_iterators.h"
+
+template <class InIter, class OutIter>
+void
+test()
+{
+ int ia[] = {0, 1, 2, 3};
+ const unsigned sa = sizeof(ia)/sizeof(ia[0]);
+ int ib[sa] = {0};
+
+ OutIter r = std::rotate_copy(InIter(ia), InIter(ia), InIter(ia), OutIter(ib));
+ assert(base(r) == ib);
+
+ r = std::rotate_copy(InIter(ia), InIter(ia), InIter(ia+1), OutIter(ib));
+ assert(base(r) == ib+1);
+ assert(ib[0] == 0);
+
+ r = std::rotate_copy(InIter(ia), InIter(ia+1), InIter(ia+1), OutIter(ib));
+ assert(base(r) == ib+1);
+ assert(ib[0] == 0);
+
+ r = std::rotate_copy(InIter(ia), InIter(ia), InIter(ia+2), OutIter(ib));
+ assert(base(r) == ib+2);
+ assert(ib[0] == 0);
+ assert(ib[1] == 1);
+
+ r = std::rotate_copy(InIter(ia), InIter(ia+1), InIter(ia+2), OutIter(ib));
+ assert(base(r) == ib+2);
+ assert(ib[0] == 1);
+ assert(ib[1] == 0);
+
+ r = std::rotate_copy(InIter(ia), InIter(ia+2), InIter(ia+2), OutIter(ib));
+ assert(base(r) == ib+2);
+ assert(ib[0] == 0);
+ assert(ib[1] == 1);
+
+ r = std::rotate_copy(InIter(ia), InIter(ia), InIter(ia+3), OutIter(ib));
+ assert(base(r) == ib+3);
+ assert(ib[0] == 0);
+ assert(ib[1] == 1);
+ assert(ib[2] == 2);
+
+ r = std::rotate_copy(InIter(ia), InIter(ia+1), InIter(ia+3), OutIter(ib));
+ assert(base(r) == ib+3);
+ assert(ib[0] == 1);
+ assert(ib[1] == 2);
+ assert(ib[2] == 0);
+
+ r = std::rotate_copy(InIter(ia), InIter(ia+2), InIter(ia+3), OutIter(ib));
+ assert(base(r) == ib+3);
+ assert(ib[0] == 2);
+ assert(ib[1] == 0);
+ assert(ib[2] == 1);
+
+ r = std::rotate_copy(InIter(ia), InIter(ia+3), InIter(ia+3), OutIter(ib));
+ assert(base(r) == ib+3);
+ assert(ib[0] == 0);
+ assert(ib[1] == 1);
+ assert(ib[2] == 2);
+
+ r = std::rotate_copy(InIter(ia), InIter(ia), InIter(ia+4), OutIter(ib));
+ assert(base(r) == ib+4);
+ assert(ib[0] == 0);
+ assert(ib[1] == 1);
+ assert(ib[2] == 2);
+ assert(ib[3] == 3);
+
+ r = std::rotate_copy(InIter(ia), InIter(ia+1), InIter(ia+4), OutIter(ib));
+ assert(base(r) == ib+4);
+ assert(ib[0] == 1);
+ assert(ib[1] == 2);
+ assert(ib[2] == 3);
+ assert(ib[3] == 0);
+
+ r = std::rotate_copy(InIter(ia), InIter(ia+2), InIter(ia+4), OutIter(ib));
+ assert(base(r) == ib+4);
+ assert(ib[0] == 2);
+ assert(ib[1] == 3);
+ assert(ib[2] == 0);
+ assert(ib[3] == 1);
+
+ r = std::rotate_copy(InIter(ia), InIter(ia+3), InIter(ia+4), OutIter(ib));
+ assert(base(r) == ib+4);
+ assert(ib[0] == 3);
+ assert(ib[1] == 0);
+ assert(ib[2] == 1);
+ assert(ib[3] == 2);
+
+ r = std::rotate_copy(InIter(ia), InIter(ia+4), InIter(ia+4), OutIter(ib));
+ assert(base(r) == ib+4);
+ assert(ib[0] == 0);
+ assert(ib[1] == 1);
+ assert(ib[2] == 2);
+ assert(ib[3] == 3);
+}
+
+int main()
+{
+ 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.swap/iter_swap.pass.cpp b/libcxx/test/std/algorithms/alg.modifying.operations/alg.swap/iter_swap.pass.cpp
new file mode 100644
index 00000000000..d68efd994bb
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.modifying.operations/alg.swap/iter_swap.pass.cpp
@@ -0,0 +1,27 @@
+//===----------------------------------------------------------------------===//
+//
+// 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<Iterator Iter1, Iterator Iter2>
+// requires HasSwap<Iter1::reference, Iter2::reference>
+// void
+// iter_swap(Iter1 a, Iter2 b);
+
+#include <algorithm>
+#include <cassert>
+
+int main()
+{
+ int i = 1;
+ int j = 2;
+ std::iter_swap(&i, &j);
+ assert(i == 2);
+ assert(j == 1);
+}
diff --git a/libcxx/test/std/algorithms/alg.modifying.operations/alg.swap/swap_ranges.pass.cpp b/libcxx/test/std/algorithms/alg.modifying.operations/alg.swap/swap_ranges.pass.cpp
new file mode 100644
index 00000000000..24fc47eafc7
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.modifying.operations/alg.swap/swap_ranges.pass.cpp
@@ -0,0 +1,110 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 Iter1, ForwardIterator Iter2>
+// requires HasSwap<Iter1::reference, Iter2::reference>
+// Iter2
+// swap_ranges(Iter1 first1, Iter1 last1, Iter2 first2);
+
+#include <algorithm>
+#include <cassert>
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+#include <memory>
+#endif
+
+#include "test_iterators.h"
+
+template<class Iter1, class Iter2>
+void
+test()
+{
+ int i[3] = {1, 2, 3};
+ int j[3] = {4, 5, 6};
+ Iter2 r = std::swap_ranges(Iter1(i), Iter1(i+3), Iter2(j));
+ assert(base(r) == j+3);
+ assert(i[0] == 4);
+ assert(i[1] == 5);
+ assert(i[2] == 6);
+ assert(j[0] == 1);
+ assert(j[1] == 2);
+ assert(j[2] == 3);
+}
+
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+
+template<class Iter1, class Iter2>
+void
+test1()
+{
+ std::unique_ptr<int> i[3];
+ for (int k = 0; k < 3; ++k)
+ i[k].reset(new int(k+1));
+ std::unique_ptr<int> j[3];
+ for (int k = 0; k < 3; ++k)
+ j[k].reset(new int(k+4));
+ Iter2 r = std::swap_ranges(Iter1(i), Iter1(i+3), Iter2(j));
+ assert(base(r) == j+3);
+ assert(*i[0] == 4);
+ assert(*i[1] == 5);
+ assert(*i[2] == 6);
+ assert(*j[0] == 1);
+ assert(*j[1] == 2);
+ assert(*j[2] == 3);
+}
+
+#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
+
+int main()
+{
+ test<forward_iterator<int*>, forward_iterator<int*> >();
+ test<forward_iterator<int*>, bidirectional_iterator<int*> >();
+ test<forward_iterator<int*>, random_access_iterator<int*> >();
+ test<forward_iterator<int*>, int*>();
+
+ test<bidirectional_iterator<int*>, forward_iterator<int*> >();
+ test<bidirectional_iterator<int*>, bidirectional_iterator<int*> >();
+ test<bidirectional_iterator<int*>, random_access_iterator<int*> >();
+ test<bidirectional_iterator<int*>, int*>();
+
+ test<random_access_iterator<int*>, forward_iterator<int*> >();
+ test<random_access_iterator<int*>, bidirectional_iterator<int*> >();
+ test<random_access_iterator<int*>, random_access_iterator<int*> >();
+ test<random_access_iterator<int*>, int*>();
+
+ test<int*, forward_iterator<int*> >();
+ test<int*, bidirectional_iterator<int*> >();
+ test<int*, random_access_iterator<int*> >();
+ test<int*, int*>();
+
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+
+ test1<forward_iterator<std::unique_ptr<int>*>, forward_iterator<std::unique_ptr<int>*> >();
+ test1<forward_iterator<std::unique_ptr<int>*>, bidirectional_iterator<std::unique_ptr<int>*> >();
+ test1<forward_iterator<std::unique_ptr<int>*>, random_access_iterator<std::unique_ptr<int>*> >();
+ test1<forward_iterator<std::unique_ptr<int>*>, std::unique_ptr<int>*>();
+
+ test1<bidirectional_iterator<std::unique_ptr<int>*>, forward_iterator<std::unique_ptr<int>*> >();
+ test1<bidirectional_iterator<std::unique_ptr<int>*>, bidirectional_iterator<std::unique_ptr<int>*> >();
+ test1<bidirectional_iterator<std::unique_ptr<int>*>, random_access_iterator<std::unique_ptr<int>*> >();
+ test1<bidirectional_iterator<std::unique_ptr<int>*>, std::unique_ptr<int>*>();
+
+ test1<random_access_iterator<std::unique_ptr<int>*>, forward_iterator<std::unique_ptr<int>*> >();
+ test1<random_access_iterator<std::unique_ptr<int>*>, bidirectional_iterator<std::unique_ptr<int>*> >();
+ test1<random_access_iterator<std::unique_ptr<int>*>, random_access_iterator<std::unique_ptr<int>*> >();
+ test1<random_access_iterator<std::unique_ptr<int>*>, std::unique_ptr<int>*>();
+
+ test1<std::unique_ptr<int>*, forward_iterator<std::unique_ptr<int>*> >();
+ test1<std::unique_ptr<int>*, bidirectional_iterator<std::unique_ptr<int>*> >();
+ test1<std::unique_ptr<int>*, random_access_iterator<std::unique_ptr<int>*> >();
+ test1<std::unique_ptr<int>*, std::unique_ptr<int>*>();
+
+#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
+}
diff --git a/libcxx/test/std/algorithms/alg.modifying.operations/alg.transform/binary_transform.pass.cpp b/libcxx/test/std/algorithms/alg.modifying.operations/alg.transform/binary_transform.pass.cpp
new file mode 100644
index 00000000000..8491ea59eff
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.modifying.operations/alg.transform/binary_transform.pass.cpp
@@ -0,0 +1,217 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 InIter1, InputIterator InIter2, class OutIter,
+// Callable<auto, const InIter1::value_type&, const InIter2::value_type&> BinaryOp>
+// requires OutputIterator<OutIter, BinaryOp::result_type> && CopyConstructible<BinaryOp>
+// OutIter
+// transform(InIter1 first1, InIter1 last1, InIter2 first2, OutIter result, BinaryOp binary_op);
+
+#include <algorithm>
+#include <functional>
+#include <cassert>
+
+#include "test_iterators.h"
+
+template<class InIter1, class InIter2, class OutIter>
+void
+test()
+{
+ int ia[] = {0, 1, 2, 3, 4};
+ const unsigned sa = sizeof(ia)/sizeof(ia[0]);
+ int ib[sa] = {1, 2, 3, 4, 5};
+ OutIter r = std::transform(InIter1(ib), InIter1(ib+sa), InIter2(ia),
+ OutIter(ib), std::minus<int>());
+ assert(base(r) == ib + sa);
+ assert(ib[0] == 1);
+ assert(ib[1] == 1);
+ assert(ib[2] == 1);
+ assert(ib[3] == 1);
+ assert(ib[4] == 1);
+}
+
+int main()
+{
+ test<input_iterator<const int*>, input_iterator<const int*>, output_iterator<int*> >();
+ test<input_iterator<const int*>, input_iterator<const int*>, input_iterator<int*> >();
+ test<input_iterator<const int*>, input_iterator<const int*>, forward_iterator<int*> >();
+ test<input_iterator<const int*>, input_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<input_iterator<const int*>, input_iterator<const int*>, random_access_iterator<int*> >();
+ test<input_iterator<const int*>, input_iterator<const int*>, int*>();
+
+ test<input_iterator<const int*>, forward_iterator<const int*>, output_iterator<int*> >();
+ test<input_iterator<const int*>, forward_iterator<const int*>, input_iterator<int*> >();
+ test<input_iterator<const int*>, forward_iterator<const int*>, forward_iterator<int*> >();
+ test<input_iterator<const int*>, forward_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<input_iterator<const int*>, forward_iterator<const int*>, random_access_iterator<int*> >();
+ test<input_iterator<const int*>, forward_iterator<const int*>, int*>();
+
+ test<input_iterator<const int*>, bidirectional_iterator<const int*>, output_iterator<int*> >();
+ test<input_iterator<const int*>, bidirectional_iterator<const int*>, input_iterator<int*> >();
+ test<input_iterator<const int*>, bidirectional_iterator<const int*>, forward_iterator<int*> >();
+ test<input_iterator<const int*>, bidirectional_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<input_iterator<const int*>, bidirectional_iterator<const int*>, random_access_iterator<int*> >();
+ test<input_iterator<const int*>, bidirectional_iterator<const int*>, int*>();
+
+ test<input_iterator<const int*>, random_access_iterator<const int*>, output_iterator<int*> >();
+ test<input_iterator<const int*>, random_access_iterator<const int*>, input_iterator<int*> >();
+ test<input_iterator<const int*>, random_access_iterator<const int*>, forward_iterator<int*> >();
+ test<input_iterator<const int*>, random_access_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<input_iterator<const int*>, random_access_iterator<const int*>, random_access_iterator<int*> >();
+ test<input_iterator<const int*>, random_access_iterator<const int*>, int*>();
+
+ test<input_iterator<const int*>, const int*, output_iterator<int*> >();
+ test<input_iterator<const int*>, const int*, input_iterator<int*> >();
+ test<input_iterator<const int*>, const int*, forward_iterator<int*> >();
+ test<input_iterator<const int*>, const int*, bidirectional_iterator<int*> >();
+ test<input_iterator<const int*>, const int*, random_access_iterator<int*> >();
+ test<input_iterator<const int*>, const int*, int*>();
+
+ test<forward_iterator<const int*>, input_iterator<const int*>, output_iterator<int*> >();
+ test<forward_iterator<const int*>, input_iterator<const int*>, input_iterator<int*> >();
+ test<forward_iterator<const int*>, input_iterator<const int*>, forward_iterator<int*> >();
+ test<forward_iterator<const int*>, input_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<forward_iterator<const int*>, input_iterator<const int*>, random_access_iterator<int*> >();
+ test<forward_iterator<const int*>, input_iterator<const int*>, int*>();
+
+ test<forward_iterator<const int*>, forward_iterator<const int*>, output_iterator<int*> >();
+ test<forward_iterator<const int*>, forward_iterator<const int*>, input_iterator<int*> >();
+ test<forward_iterator<const int*>, forward_iterator<const int*>, forward_iterator<int*> >();
+ test<forward_iterator<const int*>, forward_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<forward_iterator<const int*>, forward_iterator<const int*>, random_access_iterator<int*> >();
+ test<forward_iterator<const int*>, forward_iterator<const int*>, int*>();
+
+ test<forward_iterator<const int*>, bidirectional_iterator<const int*>, output_iterator<int*> >();
+ test<forward_iterator<const int*>, bidirectional_iterator<const int*>, input_iterator<int*> >();
+ test<forward_iterator<const int*>, bidirectional_iterator<const int*>, forward_iterator<int*> >();
+ test<forward_iterator<const int*>, bidirectional_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<forward_iterator<const int*>, bidirectional_iterator<const int*>, random_access_iterator<int*> >();
+ test<forward_iterator<const int*>, bidirectional_iterator<const int*>, int*>();
+
+ test<forward_iterator<const int*>, random_access_iterator<const int*>, output_iterator<int*> >();
+ test<forward_iterator<const int*>, random_access_iterator<const int*>, input_iterator<int*> >();
+ test<forward_iterator<const int*>, random_access_iterator<const int*>, forward_iterator<int*> >();
+ test<forward_iterator<const int*>, random_access_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<forward_iterator<const int*>, random_access_iterator<const int*>, random_access_iterator<int*> >();
+ test<forward_iterator<const int*>, random_access_iterator<const int*>, int*>();
+
+ test<forward_iterator<const int*>, const int*, output_iterator<int*> >();
+ test<forward_iterator<const int*>, const int*, input_iterator<int*> >();
+ test<forward_iterator<const int*>, const int*, forward_iterator<int*> >();
+ test<forward_iterator<const int*>, const int*, bidirectional_iterator<int*> >();
+ test<forward_iterator<const int*>, const int*, random_access_iterator<int*> >();
+ test<forward_iterator<const int*>, const int*, int*>();
+
+ test<bidirectional_iterator<const int*>, input_iterator<const int*>, output_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, input_iterator<const int*>, input_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, input_iterator<const int*>, forward_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, input_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, input_iterator<const int*>, random_access_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, input_iterator<const int*>, int*>();
+
+ test<bidirectional_iterator<const int*>, forward_iterator<const int*>, output_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, forward_iterator<const int*>, input_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, forward_iterator<const int*>, forward_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, forward_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, forward_iterator<const int*>, random_access_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, forward_iterator<const int*>, int*>();
+
+ test<bidirectional_iterator<const int*>, bidirectional_iterator<const int*>, output_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, bidirectional_iterator<const int*>, input_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, bidirectional_iterator<const int*>, forward_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, bidirectional_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, bidirectional_iterator<const int*>, random_access_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, bidirectional_iterator<const int*>, int*>();
+
+ test<bidirectional_iterator<const int*>, random_access_iterator<const int*>, output_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, random_access_iterator<const int*>, input_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, random_access_iterator<const int*>, forward_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, random_access_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, random_access_iterator<const int*>, random_access_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, random_access_iterator<const int*>, int*>();
+
+ test<bidirectional_iterator<const int*>, const int*, output_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, const int*, input_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, const int*, forward_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, const int*, bidirectional_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, const int*, random_access_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, const int*, int*>();
+
+ test<random_access_iterator<const int*>, input_iterator<const int*>, output_iterator<int*> >();
+ test<random_access_iterator<const int*>, input_iterator<const int*>, input_iterator<int*> >();
+ test<random_access_iterator<const int*>, input_iterator<const int*>, forward_iterator<int*> >();
+ test<random_access_iterator<const int*>, input_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<random_access_iterator<const int*>, input_iterator<const int*>, random_access_iterator<int*> >();
+ test<random_access_iterator<const int*>, input_iterator<const int*>, int*>();
+
+ test<random_access_iterator<const int*>, forward_iterator<const int*>, output_iterator<int*> >();
+ test<random_access_iterator<const int*>, forward_iterator<const int*>, input_iterator<int*> >();
+ test<random_access_iterator<const int*>, forward_iterator<const int*>, forward_iterator<int*> >();
+ test<random_access_iterator<const int*>, forward_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<random_access_iterator<const int*>, forward_iterator<const int*>, random_access_iterator<int*> >();
+ test<random_access_iterator<const int*>, forward_iterator<const int*>, int*>();
+
+ test<random_access_iterator<const int*>, bidirectional_iterator<const int*>, output_iterator<int*> >();
+ test<random_access_iterator<const int*>, bidirectional_iterator<const int*>, input_iterator<int*> >();
+ test<random_access_iterator<const int*>, bidirectional_iterator<const int*>, forward_iterator<int*> >();
+ test<random_access_iterator<const int*>, bidirectional_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<random_access_iterator<const int*>, bidirectional_iterator<const int*>, random_access_iterator<int*> >();
+ test<random_access_iterator<const int*>, bidirectional_iterator<const int*>, int*>();
+
+ test<random_access_iterator<const int*>, random_access_iterator<const int*>, output_iterator<int*> >();
+ test<random_access_iterator<const int*>, random_access_iterator<const int*>, input_iterator<int*> >();
+ test<random_access_iterator<const int*>, random_access_iterator<const int*>, forward_iterator<int*> >();
+ test<random_access_iterator<const int*>, random_access_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<random_access_iterator<const int*>, random_access_iterator<const int*>, random_access_iterator<int*> >();
+ test<random_access_iterator<const int*>, random_access_iterator<const int*>, int*>();
+
+ test<random_access_iterator<const int*>, const int*, output_iterator<int*> >();
+ test<random_access_iterator<const int*>, const int*, input_iterator<int*> >();
+ test<random_access_iterator<const int*>, const int*, forward_iterator<int*> >();
+ test<random_access_iterator<const int*>, const int*, bidirectional_iterator<int*> >();
+ test<random_access_iterator<const int*>, const int*, random_access_iterator<int*> >();
+ test<random_access_iterator<const int*>, const int*, int*>();
+
+ test<const int*, input_iterator<const int*>, output_iterator<int*> >();
+ test<const int*, input_iterator<const int*>, input_iterator<int*> >();
+ test<const int*, input_iterator<const int*>, forward_iterator<int*> >();
+ test<const int*, input_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<const int*, input_iterator<const int*>, random_access_iterator<int*> >();
+ test<const int*, input_iterator<const int*>, int*>();
+
+ test<const int*, forward_iterator<const int*>, output_iterator<int*> >();
+ test<const int*, forward_iterator<const int*>, input_iterator<int*> >();
+ test<const int*, forward_iterator<const int*>, forward_iterator<int*> >();
+ test<const int*, forward_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<const int*, forward_iterator<const int*>, random_access_iterator<int*> >();
+ test<const int*, forward_iterator<const int*>, int*>();
+
+ test<const int*, bidirectional_iterator<const int*>, output_iterator<int*> >();
+ test<const int*, bidirectional_iterator<const int*>, input_iterator<int*> >();
+ test<const int*, bidirectional_iterator<const int*>, forward_iterator<int*> >();
+ test<const int*, bidirectional_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<const int*, bidirectional_iterator<const int*>, random_access_iterator<int*> >();
+ test<const int*, bidirectional_iterator<const int*>, int*>();
+
+ test<const int*, random_access_iterator<const int*>, output_iterator<int*> >();
+ test<const int*, random_access_iterator<const int*>, input_iterator<int*> >();
+ test<const int*, random_access_iterator<const int*>, forward_iterator<int*> >();
+ test<const int*, random_access_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<const int*, random_access_iterator<const int*>, random_access_iterator<int*> >();
+ test<const int*, random_access_iterator<const int*>, int*>();
+
+ test<const int*, const int*, output_iterator<int*> >();
+ test<const int*, const int*, input_iterator<int*> >();
+ test<const int*, const int*, forward_iterator<int*> >();
+ test<const int*, const int*, bidirectional_iterator<int*> >();
+ test<const int*, const int*, random_access_iterator<int*> >();
+ test<const int*, const int*, int*>();
+}
diff --git a/libcxx/test/std/algorithms/alg.modifying.operations/alg.transform/unary_transform.pass.cpp b/libcxx/test/std/algorithms/alg.modifying.operations/alg.transform/unary_transform.pass.cpp
new file mode 100644
index 00000000000..68556fd9881
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.modifying.operations/alg.transform/unary_transform.pass.cpp
@@ -0,0 +1,77 @@
+//===----------------------------------------------------------------------===//
+//
+// 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,
+// Callable<auto, const InIter::value_type&> Op>
+// requires OutputIterator<OutIter, Op::result_type> && CopyConstructible<Op>
+// OutIter
+// transform(InIter first, InIter last, OutIter result, Op op);
+
+#include <algorithm>
+#include <functional>
+#include <cassert>
+
+#include "test_iterators.h"
+
+template <class InIter, class OutIter>
+void
+test()
+{
+ int ia[] = {0, 1, 2, 3, 4};
+ const unsigned sa = sizeof(ia)/sizeof(ia[0]);
+ int ib[sa] = {0};
+ OutIter r = std::transform(InIter(ia), InIter(ia+sa), OutIter(ib),
+ std::bind2nd(std::plus<int>(), 1));
+ assert(base(r) == ib + sa);
+ assert(ib[0] == 1);
+ assert(ib[1] == 2);
+ assert(ib[2] == 3);
+ assert(ib[3] == 4);
+ assert(ib[4] == 5);
+}
+
+int main()
+{
+ test<input_iterator<const int*>, output_iterator<int*> >();
+ test<input_iterator<const int*>, input_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*>, input_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*>, input_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*>, input_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*, input_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.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
+}
diff --git a/libcxx/test/std/algorithms/alg.modifying.operations/nothing_to_do.pass.cpp b/libcxx/test/std/algorithms/alg.modifying.operations/nothing_to_do.pass.cpp
new file mode 100644
index 00000000000..b58f5c55b64
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.modifying.operations/nothing_to_do.pass.cpp
@@ -0,0 +1,12 @@
+//===----------------------------------------------------------------------===//
+//
+// 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.
+//
+//===----------------------------------------------------------------------===//
+
+int main()
+{
+}
diff --git a/libcxx/test/std/algorithms/alg.nonmodifying/alg.adjacent.find/adjacent_find.pass.cpp b/libcxx/test/std/algorithms/alg.nonmodifying/alg.adjacent.find/adjacent_find.pass.cpp
new file mode 100644
index 00000000000..ee030925d55
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.nonmodifying/alg.adjacent.find/adjacent_find.pass.cpp
@@ -0,0 +1,35 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 EqualityComparable<Iter::value_type>
+// Iter
+// adjacent_find(Iter first, Iter last);
+
+#include <algorithm>
+#include <cassert>
+
+#include "test_iterators.h"
+
+int main()
+{
+ int ia[] = {0, 1, 2, 2, 0, 1, 2, 3};
+ const unsigned sa = sizeof(ia)/sizeof(ia[0]);
+ assert(std::adjacent_find(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa)) ==
+ forward_iterator<const int*>(ia+2));
+ assert(std::adjacent_find(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia)) ==
+ forward_iterator<const int*>(ia));
+ assert(std::adjacent_find(forward_iterator<const int*>(ia+3),
+ forward_iterator<const int*>(ia + sa)) ==
+ forward_iterator<const int*>(ia+sa));
+}
diff --git a/libcxx/test/std/algorithms/alg.nonmodifying/alg.adjacent.find/adjacent_find_pred.pass.cpp b/libcxx/test/std/algorithms/alg.nonmodifying/alg.adjacent.find/adjacent_find_pred.pass.cpp
new file mode 100644
index 00000000000..4d172ff8139
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.nonmodifying/alg.adjacent.find/adjacent_find_pred.pass.cpp
@@ -0,0 +1,39 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 CopyConstructible<Pred>
+// Iter
+// adjacent_find(Iter first, Iter last, Pred pred);
+
+#include <algorithm>
+#include <functional>
+#include <cassert>
+
+#include "test_iterators.h"
+
+int main()
+{
+ int ia[] = {0, 1, 2, 2, 0, 1, 2, 3};
+ const unsigned sa = sizeof(ia)/sizeof(ia[0]);
+ assert(std::adjacent_find(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ std::equal_to<int>()) ==
+ forward_iterator<const int*>(ia+2));
+ assert(std::adjacent_find(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia),
+ std::equal_to<int>()) ==
+ forward_iterator<const int*>(ia));
+ assert(std::adjacent_find(forward_iterator<const int*>(ia+3),
+ forward_iterator<const int*>(ia + sa),
+ std::equal_to<int>()) ==
+ forward_iterator<const int*>(ia+sa));
+}
diff --git a/libcxx/test/std/algorithms/alg.nonmodifying/alg.all_of/all_of.pass.cpp b/libcxx/test/std/algorithms/alg.nonmodifying/alg.all_of/all_of.pass.cpp
new file mode 100644
index 00000000000..c3c34808819
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.nonmodifying/alg.all_of/all_of.pass.cpp
@@ -0,0 +1,47 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 <class InputIterator, class Predicate>
+// bool
+// all_of(InputIterator first, InputIterator last, Predicate pred);
+
+#include <algorithm>
+#include <cassert>
+
+#include "test_iterators.h"
+
+struct test1
+{
+ bool operator()(const int& i) const
+ {
+ return i % 2 == 0;
+ }
+};
+
+int main()
+{
+ {
+ int ia[] = {2, 4, 6, 8};
+ const unsigned sa = sizeof(ia)/sizeof(ia[0]);
+ assert(std::all_of(input_iterator<const int*>(ia),
+ input_iterator<const int*>(ia + sa), test1()) == true);
+ assert(std::all_of(input_iterator<const int*>(ia),
+ input_iterator<const int*>(ia), test1()) == true);
+ }
+ {
+ const int ia[] = {2, 4, 5, 8};
+ const unsigned sa = sizeof(ia)/sizeof(ia[0]);
+ assert(std::all_of(input_iterator<const int*>(ia),
+ input_iterator<const int*>(ia + sa), test1()) == false);
+ assert(std::all_of(input_iterator<const int*>(ia),
+ input_iterator<const int*>(ia), test1()) == true);
+ }
+}
diff --git a/libcxx/test/std/algorithms/alg.nonmodifying/alg.any_of/any_of.pass.cpp b/libcxx/test/std/algorithms/alg.nonmodifying/alg.any_of/any_of.pass.cpp
new file mode 100644
index 00000000000..d096e20d2d2
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.nonmodifying/alg.any_of/any_of.pass.cpp
@@ -0,0 +1,55 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 <class InputIterator, class Predicate>
+// bool
+// any_of(InputIterator first, InputIterator last, Predicate pred);
+
+#include <algorithm>
+#include <cassert>
+
+#include "test_iterators.h"
+
+struct test1
+{
+ bool operator()(const int& i) const
+ {
+ return i % 2 == 0;
+ }
+};
+
+int main()
+{
+ {
+ int ia[] = {2, 4, 6, 8};
+ const unsigned sa = sizeof(ia)/sizeof(ia[0]);
+ assert(std::any_of(input_iterator<const int*>(ia),
+ input_iterator<const int*>(ia + sa), test1()) == true);
+ assert(std::any_of(input_iterator<const int*>(ia),
+ input_iterator<const int*>(ia), test1()) == false);
+ }
+ {
+ const int ia[] = {2, 4, 5, 8};
+ const unsigned sa = sizeof(ia)/sizeof(ia[0]);
+ assert(std::any_of(input_iterator<const int*>(ia),
+ input_iterator<const int*>(ia + sa), test1()) == true);
+ assert(std::any_of(input_iterator<const int*>(ia),
+ input_iterator<const int*>(ia), test1()) == false);
+ }
+ {
+ const int ia[] = {1, 3, 5, 7};
+ const unsigned sa = sizeof(ia)/sizeof(ia[0]);
+ assert(std::any_of(input_iterator<const int*>(ia),
+ input_iterator<const int*>(ia + sa), test1()) == false);
+ assert(std::any_of(input_iterator<const int*>(ia),
+ input_iterator<const int*>(ia), test1()) == false);
+ }
+}
diff --git a/libcxx/test/std/algorithms/alg.nonmodifying/alg.count/count.pass.cpp b/libcxx/test/std/algorithms/alg.nonmodifying/alg.count/count.pass.cpp
new file mode 100644
index 00000000000..260e5edece5
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.nonmodifying/alg.count/count.pass.cpp
@@ -0,0 +1,32 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 Iter, class T>
+// requires HasEqualTo<Iter::value_type, T>
+// Iter::difference_type
+// count(Iter first, Iter last, const T& value);
+
+#include <algorithm>
+#include <cassert>
+
+#include "test_iterators.h"
+
+int main()
+{
+ int ia[] = {0, 1, 2, 2, 0, 1, 2, 3};
+ const unsigned sa = sizeof(ia)/sizeof(ia[0]);
+ assert(std::count(input_iterator<const int*>(ia),
+ input_iterator<const int*>(ia + sa), 2) == 3);
+ assert(std::count(input_iterator<const int*>(ia),
+ input_iterator<const int*>(ia + sa), 7) == 0);
+ assert(std::count(input_iterator<const int*>(ia),
+ input_iterator<const int*>(ia), 2) == 0);
+}
diff --git a/libcxx/test/std/algorithms/alg.nonmodifying/alg.count/count_if.pass.cpp b/libcxx/test/std/algorithms/alg.nonmodifying/alg.count/count_if.pass.cpp
new file mode 100644
index 00000000000..025bc06a618
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.nonmodifying/alg.count/count_if.pass.cpp
@@ -0,0 +1,36 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 Iter, Predicate<auto, Iter::value_type> Pred>
+// requires CopyConstructible<Pred>
+// Iter::difference_type
+// count_if(Iter first, Iter last, Pred pred);
+
+#include <algorithm>
+#include <functional>
+#include <cassert>
+
+#include "test_iterators.h"
+
+int main()
+{
+ int ia[] = {0, 1, 2, 2, 0, 1, 2, 3};
+ const unsigned sa = sizeof(ia)/sizeof(ia[0]);
+ assert(std::count_if(input_iterator<const int*>(ia),
+ input_iterator<const int*>(ia + sa),
+ std::bind2nd(std::equal_to<int>(),2)) == 3);
+ assert(std::count_if(input_iterator<const int*>(ia),
+ input_iterator<const int*>(ia + sa),
+ std::bind2nd(std::equal_to<int>(),7)) == 0);
+ assert(std::count_if(input_iterator<const int*>(ia),
+ input_iterator<const int*>(ia),
+ std::bind2nd(std::equal_to<int>(),2)) == 0);
+}
diff --git a/libcxx/test/std/algorithms/alg.nonmodifying/alg.equal/equal.pass.cpp b/libcxx/test/std/algorithms/alg.nonmodifying/alg.equal/equal.pass.cpp
new file mode 100644
index 00000000000..234879149ae
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.nonmodifying/alg.equal/equal.pass.cpp
@@ -0,0 +1,66 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 Iter1, InputIterator Iter2>
+// requires HasEqualTo<Iter1::value_type, Iter2::value_type>
+// bool
+// equal(Iter1 first1, Iter1 last1, Iter2 first2);
+
+#include <algorithm>
+#include <cassert>
+
+#include "test_iterators.h"
+
+#if _LIBCPP_STD_VER > 11
+#define HAS_FOUR_ITERATOR_VERSION
+#endif
+
+int main()
+{
+ int ia[] = {0, 1, 2, 3, 4, 5};
+ const unsigned s = sizeof(ia)/sizeof(ia[0]);
+ int ib[s] = {0, 1, 2, 5, 4, 5};
+ assert(std::equal(input_iterator<const int*>(ia),
+ input_iterator<const int*>(ia+s),
+ input_iterator<const int*>(ia)));
+#ifdef HAS_FOUR_ITERATOR_VERSION
+ assert(std::equal(input_iterator<const int*>(ia),
+ input_iterator<const int*>(ia+s),
+ input_iterator<const int*>(ia),
+ input_iterator<const int*>(ia+s)));
+ assert(std::equal(random_access_iterator<const int*>(ia),
+ random_access_iterator<const int*>(ia+s),
+ random_access_iterator<const int*>(ia),
+ random_access_iterator<const int*>(ia+s)));
+#endif
+ assert(!std::equal(input_iterator<const int*>(ia),
+ input_iterator<const int*>(ia+s),
+ input_iterator<const int*>(ib)));
+#ifdef HAS_FOUR_ITERATOR_VERSION
+ assert(!std::equal(input_iterator<const int*>(ia),
+ input_iterator<const int*>(ia+s),
+ input_iterator<const int*>(ib),
+ input_iterator<const int*>(ib+s)));
+ assert(!std::equal(random_access_iterator<const int*>(ia),
+ random_access_iterator<const int*>(ia+s),
+ random_access_iterator<const int*>(ib),
+ random_access_iterator<const int*>(ib+s)));
+ assert(!std::equal(input_iterator<const int*>(ia),
+ input_iterator<const int*>(ia+s),
+ input_iterator<const int*>(ia),
+ input_iterator<const int*>(ia+s-1)));
+ assert(!std::equal(random_access_iterator<const int*>(ia),
+ random_access_iterator<const int*>(ia+s),
+ random_access_iterator<const int*>(ia),
+ random_access_iterator<const int*>(ia+s-1)));
+
+#endif
+}
diff --git a/libcxx/test/std/algorithms/alg.nonmodifying/alg.equal/equal_pred.pass.cpp b/libcxx/test/std/algorithms/alg.nonmodifying/alg.equal/equal_pred.pass.cpp
new file mode 100644
index 00000000000..047f72062eb
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.nonmodifying/alg.equal/equal_pred.pass.cpp
@@ -0,0 +1,87 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 Iter1, InputIterator Iter2,
+// Predicate<auto, Iter1::value_type, Iter2::value_type> Pred>
+// requires CopyConstructible<Pred>
+// bool
+// equal(Iter1 first1, Iter1 last1, Iter2 first2, Pred pred);
+
+#include <algorithm>
+#include <functional>
+#include <cassert>
+
+#include "test_iterators.h"
+
+#if _LIBCPP_STD_VER > 11
+#define HAS_FOUR_ITERATOR_VERSION
+#endif
+
+int comparison_count = 0;
+template <typename T>
+bool counting_equals ( const T &a, const T &b ) {
+ ++comparison_count;
+ return a == b;
+}
+
+int main()
+{
+ int ia[] = {0, 1, 2, 3, 4, 5};
+ const unsigned s = sizeof(ia)/sizeof(ia[0]);
+ int ib[s] = {0, 1, 2, 5, 4, 5};
+ assert(std::equal(input_iterator<const int*>(ia),
+ input_iterator<const int*>(ia+s),
+ input_iterator<const int*>(ia),
+ std::equal_to<int>()));
+#ifdef HAS_FOUR_ITERATOR_VERSION
+ assert(std::equal(input_iterator<const int*>(ia),
+ input_iterator<const int*>(ia+s),
+ input_iterator<const int*>(ia),
+ input_iterator<const int*>(ia+s),
+ std::equal_to<int>()));
+ assert(std::equal(random_access_iterator<const int*>(ia),
+ random_access_iterator<const int*>(ia+s),
+ random_access_iterator<const int*>(ia),
+ random_access_iterator<const int*>(ia+s),
+ std::equal_to<int>()));
+
+ comparison_count = 0;
+ assert(!std::equal(input_iterator<const int*>(ia),
+ input_iterator<const int*>(ia+s),
+ input_iterator<const int*>(ia),
+ input_iterator<const int*>(ia+s-1),
+ counting_equals<int>));
+ assert(comparison_count > 0);
+ comparison_count = 0;
+ assert(!std::equal(random_access_iterator<const int*>(ia),
+ random_access_iterator<const int*>(ia+s),
+ random_access_iterator<const int*>(ia),
+ random_access_iterator<const int*>(ia+s-1),
+ counting_equals<int>));
+ assert(comparison_count == 0);
+#endif
+ assert(!std::equal(input_iterator<const int*>(ia),
+ input_iterator<const int*>(ia+s),
+ input_iterator<const int*>(ib),
+ std::equal_to<int>()));
+#ifdef HAS_FOUR_ITERATOR_VERSION
+ assert(!std::equal(input_iterator<const int*>(ia),
+ input_iterator<const int*>(ia+s),
+ input_iterator<const int*>(ib),
+ input_iterator<const int*>(ib+s),
+ std::equal_to<int>()));
+ assert(!std::equal(random_access_iterator<const int*>(ia),
+ random_access_iterator<const int*>(ia+s),
+ random_access_iterator<const int*>(ib),
+ random_access_iterator<const int*>(ib+s),
+ std::equal_to<int>()));
+#endif
+}
diff --git a/libcxx/test/std/algorithms/alg.nonmodifying/alg.find.end/find_end.pass.cpp b/libcxx/test/std/algorithms/alg.nonmodifying/alg.find.end/find_end.pass.cpp
new file mode 100644
index 00000000000..e95162b4ad7
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.nonmodifying/alg.find.end/find_end.pass.cpp
@@ -0,0 +1,57 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 Iter1, ForwardIterator Iter2>
+// requires HasEqualTo<Iter1::value_type, Iter2::value_type>
+// Iter1
+// find_end(Iter1 first1, Iter1 last1, Iter2 first2, Iter2 last2);
+
+#include <algorithm>
+#include <cassert>
+
+#include "test_iterators.h"
+
+template <class Iter1, class Iter2>
+void
+test()
+{
+ int ia[] = {0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 0, 1, 2, 3, 0, 1, 2, 0, 1, 0};
+ const unsigned sa = sizeof(ia)/sizeof(ia[0]);
+ int b[] = {0};
+ assert(std::find_end(Iter1(ia), Iter1(ia+sa), Iter2(b), Iter2(b+1)) == Iter1(ia+sa-1));
+ int c[] = {0, 1};
+ assert(std::find_end(Iter1(ia), Iter1(ia+sa), Iter2(c), Iter2(c+2)) == Iter1(ia+18));
+ int d[] = {0, 1, 2};
+ assert(std::find_end(Iter1(ia), Iter1(ia+sa), Iter2(d), Iter2(d+3)) == Iter1(ia+15));
+ int e[] = {0, 1, 2, 3};
+ assert(std::find_end(Iter1(ia), Iter1(ia+sa), Iter2(e), Iter2(e+4)) == Iter1(ia+11));
+ int f[] = {0, 1, 2, 3, 4};
+ assert(std::find_end(Iter1(ia), Iter1(ia+sa), Iter2(f), Iter2(f+5)) == Iter1(ia+6));
+ int g[] = {0, 1, 2, 3, 4, 5};
+ assert(std::find_end(Iter1(ia), Iter1(ia+sa), Iter2(g), Iter2(g+6)) == Iter1(ia));
+ int h[] = {0, 1, 2, 3, 4, 5, 6};
+ assert(std::find_end(Iter1(ia), Iter1(ia+sa), Iter2(h), Iter2(h+7)) == Iter1(ia+sa));
+ assert(std::find_end(Iter1(ia), Iter1(ia+sa), Iter2(b), Iter2(b)) == Iter1(ia+sa));
+ assert(std::find_end(Iter1(ia), Iter1(ia), Iter2(b), Iter2(b+1)) == Iter1(ia));
+}
+
+int main()
+{
+ test<forward_iterator<const int*>, forward_iterator<const int*> >();
+ test<forward_iterator<const int*>, bidirectional_iterator<const int*> >();
+ test<forward_iterator<const int*>, random_access_iterator<const int*> >();
+ test<bidirectional_iterator<const int*>, forward_iterator<const int*> >();
+ test<bidirectional_iterator<const int*>, bidirectional_iterator<const int*> >();
+ test<bidirectional_iterator<const int*>, random_access_iterator<const int*> >();
+ test<random_access_iterator<const int*>, forward_iterator<const int*> >();
+ test<random_access_iterator<const int*>, bidirectional_iterator<const int*> >();
+ test<random_access_iterator<const int*>, random_access_iterator<const int*> >();
+}
diff --git a/libcxx/test/std/algorithms/alg.nonmodifying/alg.find.end/find_end_pred.pass.cpp b/libcxx/test/std/algorithms/alg.nonmodifying/alg.find.end/find_end_pred.pass.cpp
new file mode 100644
index 00000000000..411858d5b76
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.nonmodifying/alg.find.end/find_end_pred.pass.cpp
@@ -0,0 +1,86 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 Iter1, ForwardIterator Iter2,
+// Predicate<auto, Iter1::value_type, Iter2::value_type> Pred>
+// requires CopyConstructible<Pred>
+// Iter1
+// find_end(Iter1 first1, Iter1 last1, Iter2 first2, Iter2 last2, 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 Iter1, class Iter2>
+void
+test()
+{
+ int ia[] = {0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 0, 1, 2, 3, 0, 1, 2, 0, 1, 0};
+ const unsigned sa = sizeof(ia)/sizeof(ia[0]);
+ int b[] = {0};
+ count_equal::count = 0;
+ assert(std::find_end(Iter1(ia), Iter1(ia+sa), Iter2(b), Iter2(b+1), count_equal()) == Iter1(ia+sa-1));
+ assert(count_equal::count <= 1*(sa-1+1));
+ int c[] = {0, 1};
+ count_equal::count = 0;
+ assert(std::find_end(Iter1(ia), Iter1(ia+sa), Iter2(c), Iter2(c+2), count_equal()) == Iter1(ia+18));
+ assert(count_equal::count <= 2*(sa-2+1));
+ int d[] = {0, 1, 2};
+ count_equal::count = 0;
+ assert(std::find_end(Iter1(ia), Iter1(ia+sa), Iter2(d), Iter2(d+3), count_equal()) == Iter1(ia+15));
+ assert(count_equal::count <= 3*(sa-3+1));
+ int e[] = {0, 1, 2, 3};
+ count_equal::count = 0;
+ assert(std::find_end(Iter1(ia), Iter1(ia+sa), Iter2(e), Iter2(e+4), count_equal()) == Iter1(ia+11));
+ assert(count_equal::count <= 4*(sa-4+1));
+ int f[] = {0, 1, 2, 3, 4};
+ count_equal::count = 0;
+ assert(std::find_end(Iter1(ia), Iter1(ia+sa), Iter2(f), Iter2(f+5), count_equal()) == Iter1(ia+6));
+ assert(count_equal::count <= 5*(sa-5+1));
+ int g[] = {0, 1, 2, 3, 4, 5};
+ count_equal::count = 0;
+ assert(std::find_end(Iter1(ia), Iter1(ia+sa), Iter2(g), Iter2(g+6), count_equal()) == Iter1(ia));
+ assert(count_equal::count <= 6*(sa-6+1));
+ int h[] = {0, 1, 2, 3, 4, 5, 6};
+ count_equal::count = 0;
+ assert(std::find_end(Iter1(ia), Iter1(ia+sa), Iter2(h), Iter2(h+7), count_equal()) == Iter1(ia+sa));
+ assert(count_equal::count <= 7*(sa-7+1));
+ count_equal::count = 0;
+ assert(std::find_end(Iter1(ia), Iter1(ia+sa), Iter2(b), Iter2(b), count_equal()) == Iter1(ia+sa));
+ assert(count_equal::count <= 0);
+ count_equal::count = 0;
+ assert(std::find_end(Iter1(ia), Iter1(ia), Iter2(b), Iter2(b+1), count_equal()) == Iter1(ia));
+ assert(count_equal::count <= 0);
+}
+
+int main()
+{
+ test<forward_iterator<const int*>, forward_iterator<const int*> >();
+ test<forward_iterator<const int*>, bidirectional_iterator<const int*> >();
+ test<forward_iterator<const int*>, random_access_iterator<const int*> >();
+ test<bidirectional_iterator<const int*>, forward_iterator<const int*> >();
+ test<bidirectional_iterator<const int*>, bidirectional_iterator<const int*> >();
+ test<bidirectional_iterator<const int*>, random_access_iterator<const int*> >();
+ test<random_access_iterator<const int*>, forward_iterator<const int*> >();
+ test<random_access_iterator<const int*>, bidirectional_iterator<const int*> >();
+ test<random_access_iterator<const int*>, random_access_iterator<const int*> >();
+}
diff --git a/libcxx/test/std/algorithms/alg.nonmodifying/alg.find.first.of/find_first_of.pass.cpp b/libcxx/test/std/algorithms/alg.nonmodifying/alg.find.first.of/find_first_of.pass.cpp
new file mode 100644
index 00000000000..966207671fc
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.nonmodifying/alg.find.first.of/find_first_of.pass.cpp
@@ -0,0 +1,49 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 Iter1, ForwardIterator Iter2>
+// requires HasEqualTo<Iter1::value_type, Iter2::value_type>
+// Iter1
+// find_first_of(Iter1 first1, Iter1 last1, Iter2 first2, Iter2 last2);
+
+#include <algorithm>
+#include <cassert>
+
+#include "test_iterators.h"
+
+int main()
+{
+ int ia[] = {0, 1, 2, 3, 0, 1, 2, 3};
+ const unsigned sa = sizeof(ia)/sizeof(ia[0]);
+ int ib[] = {1, 3, 5, 7};
+ const unsigned sb = sizeof(ib)/sizeof(ib[0]);
+ assert(std::find_first_of(input_iterator<const int*>(ia),
+ input_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ forward_iterator<const int*>(ib + sb)) ==
+ input_iterator<const int*>(ia+1));
+ int ic[] = {7};
+ assert(std::find_first_of(input_iterator<const int*>(ia),
+ input_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ic),
+ forward_iterator<const int*>(ic + 1)) ==
+ input_iterator<const int*>(ia+sa));
+ assert(std::find_first_of(input_iterator<const int*>(ia),
+ input_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ic),
+ forward_iterator<const int*>(ic)) ==
+ input_iterator<const int*>(ia+sa));
+ assert(std::find_first_of(input_iterator<const int*>(ia),
+ input_iterator<const int*>(ia),
+ forward_iterator<const int*>(ic),
+ forward_iterator<const int*>(ic+1)) ==
+ input_iterator<const int*>(ia));
+}
diff --git a/libcxx/test/std/algorithms/alg.nonmodifying/alg.find.first.of/find_first_of_pred.pass.cpp b/libcxx/test/std/algorithms/alg.nonmodifying/alg.find.first.of/find_first_of_pred.pass.cpp
new file mode 100644
index 00000000000..d1d954ca0ca
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.nonmodifying/alg.find.first.of/find_first_of_pred.pass.cpp
@@ -0,0 +1,55 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 Iter1, ForwardIterator Iter2,
+// Predicate<auto, Iter1::value_type, Iter2::value_type> Pred>
+// requires CopyConstructible<Pred>
+// Iter1
+// find_first_of(Iter1 first1, Iter1 last1, Iter2 first2, Iter2 last2, Pred pred);
+
+#include <algorithm>
+#include <functional>
+#include <cassert>
+
+#include "test_iterators.h"
+
+int main()
+{
+ int ia[] = {0, 1, 2, 3, 0, 1, 2, 3};
+ const unsigned sa = sizeof(ia)/sizeof(ia[0]);
+ int ib[] = {1, 3, 5, 7};
+ const unsigned sb = sizeof(ib)/sizeof(ib[0]);
+ assert(std::find_first_of(input_iterator<const int*>(ia),
+ input_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ forward_iterator<const int*>(ib + sb),
+ std::equal_to<int>()) ==
+ input_iterator<const int*>(ia+1));
+ int ic[] = {7};
+ assert(std::find_first_of(input_iterator<const int*>(ia),
+ input_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ic),
+ forward_iterator<const int*>(ic + 1),
+ std::equal_to<int>()) ==
+ input_iterator<const int*>(ia+sa));
+ assert(std::find_first_of(input_iterator<const int*>(ia),
+ input_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ic),
+ forward_iterator<const int*>(ic),
+ std::equal_to<int>()) ==
+ input_iterator<const int*>(ia+sa));
+ assert(std::find_first_of(input_iterator<const int*>(ia),
+ input_iterator<const int*>(ia),
+ forward_iterator<const int*>(ic),
+ forward_iterator<const int*>(ic+1),
+ std::equal_to<int>()) ==
+ input_iterator<const int*>(ia));
+}
diff --git a/libcxx/test/std/algorithms/alg.nonmodifying/alg.find/find.pass.cpp b/libcxx/test/std/algorithms/alg.nonmodifying/alg.find/find.pass.cpp
new file mode 100644
index 00000000000..09f0f41215c
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.nonmodifying/alg.find/find.pass.cpp
@@ -0,0 +1,31 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 Iter, class T>
+// requires HasEqualTo<Iter::value_type, T>
+// Iter
+// find(Iter first, Iter last, const T& value);
+
+#include <algorithm>
+#include <cassert>
+
+#include "test_iterators.h"
+
+int main()
+{
+ int ia[] = {0, 1, 2, 3, 4, 5};
+ const unsigned s = sizeof(ia)/sizeof(ia[0]);
+ input_iterator<const int*> r = std::find(input_iterator<const int*>(ia),
+ input_iterator<const int*>(ia+s), 3);
+ assert(*r == 3);
+ r = std::find(input_iterator<const int*>(ia), input_iterator<const int*>(ia+s), 10);
+ assert(r == input_iterator<const int*>(ia+s));
+}
diff --git a/libcxx/test/std/algorithms/alg.nonmodifying/alg.find/find_if.pass.cpp b/libcxx/test/std/algorithms/alg.nonmodifying/alg.find/find_if.pass.cpp
new file mode 100644
index 00000000000..bde6ff389d0
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.nonmodifying/alg.find/find_if.pass.cpp
@@ -0,0 +1,35 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 Iter, Predicate<auto, Iter::value_type> Pred>
+// requires CopyConstructible<Pred>
+// Iter
+// find_if(Iter first, Iter last, Pred pred);
+
+#include <algorithm>
+#include <functional>
+#include <cassert>
+
+#include "test_iterators.h"
+
+int main()
+{
+ int ia[] = {0, 1, 2, 3, 4, 5};
+ const unsigned s = sizeof(ia)/sizeof(ia[0]);
+ input_iterator<const int*> r = std::find_if(input_iterator<const int*>(ia),
+ input_iterator<const int*>(ia+s),
+ std::bind2nd(std::equal_to<int>(), 3));
+ assert(*r == 3);
+ r = std::find_if(input_iterator<const int*>(ia),
+ input_iterator<const int*>(ia+s),
+ std::bind2nd(std::equal_to<int>(), 10));
+ assert(r == input_iterator<const int*>(ia+s));
+}
diff --git a/libcxx/test/std/algorithms/alg.nonmodifying/alg.find/find_if_not.pass.cpp b/libcxx/test/std/algorithms/alg.nonmodifying/alg.find/find_if_not.pass.cpp
new file mode 100644
index 00000000000..661e643f07d
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.nonmodifying/alg.find/find_if_not.pass.cpp
@@ -0,0 +1,35 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 Iter, Predicate<auto, Iter::value_type> Pred>
+// requires CopyConstructible<Pred>
+// Iter
+// find_if_not(Iter first, Iter last, Pred pred);
+
+#include <algorithm>
+#include <functional>
+#include <cassert>
+
+#include "test_iterators.h"
+
+int main()
+{
+ int ia[] = {0, 1, 2, 3, 4, 5};
+ const unsigned s = sizeof(ia)/sizeof(ia[0]);
+ input_iterator<const int*> r = std::find_if_not(input_iterator<const int*>(ia),
+ input_iterator<const int*>(ia+s),
+ std::bind2nd(std::not_equal_to<int>(), 3));
+ assert(*r == 3);
+ r = std::find_if_not(input_iterator<const int*>(ia),
+ input_iterator<const int*>(ia+s),
+ std::bind2nd(std::not_equal_to<int>(), 10));
+ assert(r == input_iterator<const int*>(ia+s));
+}
diff --git a/libcxx/test/std/algorithms/alg.nonmodifying/alg.foreach/test.pass.cpp b/libcxx/test/std/algorithms/alg.nonmodifying/alg.foreach/test.pass.cpp
new file mode 100644
index 00000000000..bf80c2c6edd
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.nonmodifying/alg.foreach/test.pass.cpp
@@ -0,0 +1,39 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 Iter, Callable<auto, Iter::reference> Function>
+// requires CopyConstructible<Function>
+// Function
+// for_each(Iter first, Iter last, Function f);
+
+#include <algorithm>
+#include <cassert>
+
+#include "test_iterators.h"
+
+struct for_each_test
+{
+ for_each_test(int c) : count(c) {}
+ int count;
+ void operator()(int& i) {++i; ++count;}
+};
+
+int main()
+{
+ int ia[] = {0, 1, 2, 3, 4, 5};
+ const unsigned s = sizeof(ia)/sizeof(ia[0]);
+ for_each_test f = std::for_each(input_iterator<int*>(ia),
+ input_iterator<int*>(ia+s),
+ for_each_test(0));
+ assert(f.count == s);
+ for (unsigned i = 0; i < s; ++i)
+ assert(ia[i] == i+1);
+}
diff --git a/libcxx/test/std/algorithms/alg.nonmodifying/alg.is_permutation/is_permutation.pass.cpp b/libcxx/test/std/algorithms/alg.nonmodifying/alg.is_permutation/is_permutation.pass.cpp
new file mode 100644
index 00000000000..028aec5e7f2
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.nonmodifying/alg.is_permutation/is_permutation.pass.cpp
@@ -0,0 +1,605 @@
+//===----------------------------------------------------------------------===//
+//
+// 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<class ForwardIterator1, class ForwardIterator2>
+// bool
+// is_permutation(ForwardIterator1 first1, ForwardIterator1 last1,
+// ForwardIterator2 first2);
+
+#include <algorithm>
+#include <cassert>
+
+#include "test_iterators.h"
+
+#if _LIBCPP_STD_VER > 11
+#define HAS_FOUR_ITERATOR_VERSION
+#endif
+
+int main()
+{
+ {
+ const int ia[] = {0};
+ const int ib[] = {0};
+ const unsigned sa = sizeof(ia)/sizeof(ia[0]);
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + 0),
+ forward_iterator<const int*>(ib)) == true);
+#ifdef HAS_FOUR_ITERATOR_VERSION
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + 0),
+ forward_iterator<const int*>(ib),
+ forward_iterator<const int*>(ib + 0)) == true);
+#endif
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib)) == true);
+#ifdef HAS_FOUR_ITERATOR_VERSION
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ forward_iterator<const int*>(ib + sa)) == true);
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ forward_iterator<const int*>(ib + sa - 1)) == false);
+#endif
+ }
+ {
+ const int ia[] = {0};
+ const int ib[] = {1};
+ const unsigned sa = sizeof(ia)/sizeof(ia[0]);
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib)) == false);
+#ifdef HAS_FOUR_ITERATOR_VERSION
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ forward_iterator<const int*>(ib + sa)) == false);
+#endif
+ }
+
+ {
+ const int ia[] = {0, 0};
+ const int ib[] = {0, 0};
+ const unsigned sa = sizeof(ia)/sizeof(ia[0]);
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib)) == true);
+#ifdef HAS_FOUR_ITERATOR_VERSION
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ forward_iterator<const int*>(ib + sa)) == true);
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ forward_iterator<const int*>(ib + sa - 1)) == false);
+#endif
+ }
+ {
+ const int ia[] = {0, 0};
+ const int ib[] = {0, 1};
+ const unsigned sa = sizeof(ia)/sizeof(ia[0]);
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib)) == false);
+#ifdef HAS_FOUR_ITERATOR_VERSION
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ forward_iterator<const int*>(ib + sa)) == false);
+#endif
+ }
+ {
+ const int ia[] = {0, 0};
+ const int ib[] = {1, 0};
+ const unsigned sa = sizeof(ia)/sizeof(ia[0]);
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib)) == false);
+#ifdef HAS_FOUR_ITERATOR_VERSION
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ forward_iterator<const int*>(ib + sa)) == false);
+#endif
+ }
+ {
+ const int ia[] = {0, 0};
+ const int ib[] = {1, 1};
+ const unsigned sa = sizeof(ia)/sizeof(ia[0]);
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib)) == false);
+#ifdef HAS_FOUR_ITERATOR_VERSION
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ forward_iterator<const int*>(ib + sa)) == false);
+#endif
+ }
+ {
+ const int ia[] = {0, 1};
+ const int ib[] = {0, 0};
+ const unsigned sa = sizeof(ia)/sizeof(ia[0]);
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib)) == false);
+#ifdef HAS_FOUR_ITERATOR_VERSION
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ forward_iterator<const int*>(ib + sa)) == false);
+#endif
+ }
+ {
+ const int ia[] = {0, 1};
+ const int ib[] = {0, 1};
+ const unsigned sa = sizeof(ia)/sizeof(ia[0]);
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib)) == true);
+#ifdef HAS_FOUR_ITERATOR_VERSION
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ forward_iterator<const int*>(ib + sa)) == true);
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ forward_iterator<const int*>(ib + sa - 1)) == false);
+#endif
+ }
+ {
+ const int ia[] = {0, 1};
+ const int ib[] = {1, 0};
+ const unsigned sa = sizeof(ia)/sizeof(ia[0]);
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib)) == true);
+#ifdef HAS_FOUR_ITERATOR_VERSION
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ forward_iterator<const int*>(ib + sa)) == true);
+#endif
+ }
+ {
+ const int ia[] = {0, 1};
+ const int ib[] = {1, 1};
+ const unsigned sa = sizeof(ia)/sizeof(ia[0]);
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib)) == false);
+#ifdef HAS_FOUR_ITERATOR_VERSION
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ forward_iterator<const int*>(ib + sa)) == false);
+#endif
+ }
+ {
+ const int ia[] = {1, 0};
+ const int ib[] = {0, 0};
+ const unsigned sa = sizeof(ia)/sizeof(ia[0]);
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib)) == false);
+#ifdef HAS_FOUR_ITERATOR_VERSION
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ forward_iterator<const int*>(ib + sa)) == false);
+#endif
+ }
+ {
+ const int ia[] = {1, 0};
+ const int ib[] = {0, 1};
+ const unsigned sa = sizeof(ia)/sizeof(ia[0]);
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib)) == true);
+#ifdef HAS_FOUR_ITERATOR_VERSION
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ forward_iterator<const int*>(ib + sa)) == true);
+#endif
+ }
+ {
+ const int ia[] = {1, 0};
+ const int ib[] = {1, 0};
+ const unsigned sa = sizeof(ia)/sizeof(ia[0]);
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib)) == true);
+#ifdef HAS_FOUR_ITERATOR_VERSION
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ forward_iterator<const int*>(ib + sa)) == true);
+#endif
+ }
+ {
+ const int ia[] = {1, 0};
+ const int ib[] = {1, 1};
+ const unsigned sa = sizeof(ia)/sizeof(ia[0]);
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib)) == false);
+#ifdef HAS_FOUR_ITERATOR_VERSION
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ forward_iterator<const int*>(ib + sa)) == false);
+#endif
+ }
+ {
+ const int ia[] = {1, 1};
+ const int ib[] = {0, 0};
+ const unsigned sa = sizeof(ia)/sizeof(ia[0]);
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib)) == false);
+#ifdef HAS_FOUR_ITERATOR_VERSION
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ forward_iterator<const int*>(ib + sa)) == false);
+#endif
+ }
+ {
+ const int ia[] = {1, 1};
+ const int ib[] = {0, 1};
+ const unsigned sa = sizeof(ia)/sizeof(ia[0]);
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib)) == false);
+#ifdef HAS_FOUR_ITERATOR_VERSION
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ forward_iterator<const int*>(ib + sa)) == false);
+#endif
+ }
+ {
+ const int ia[] = {1, 1};
+ const int ib[] = {1, 0};
+ const unsigned sa = sizeof(ia)/sizeof(ia[0]);
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib)) == false);
+#ifdef HAS_FOUR_ITERATOR_VERSION
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ forward_iterator<const int*>(ib + sa)) == false);
+#endif
+ }
+ {
+ const int ia[] = {1, 1};
+ const int ib[] = {1, 1};
+ const unsigned sa = sizeof(ia)/sizeof(ia[0]);
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib)) == true);
+#ifdef HAS_FOUR_ITERATOR_VERSION
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ forward_iterator<const int*>(ib + sa)) == true);
+#endif
+ }
+
+ {
+ const int ia[] = {0, 0, 0};
+ const int ib[] = {1, 0, 0};
+ const unsigned sa = sizeof(ia)/sizeof(ia[0]);
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib)) == false);
+#ifdef HAS_FOUR_ITERATOR_VERSION
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ forward_iterator<const int*>(ib + sa)) == false);
+#endif
+ }
+ {
+ const int ia[] = {0, 0, 0};
+ const int ib[] = {1, 0, 1};
+ const unsigned sa = sizeof(ia)/sizeof(ia[0]);
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib)) == false);
+#ifdef HAS_FOUR_ITERATOR_VERSION
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ forward_iterator<const int*>(ib + sa)) == false);
+#endif
+ }
+ {
+ const int ia[] = {0, 0, 0};
+ const int ib[] = {1, 0, 2};
+ const unsigned sa = sizeof(ia)/sizeof(ia[0]);
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib)) == false);
+#ifdef HAS_FOUR_ITERATOR_VERSION
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ forward_iterator<const int*>(ib + sa)) == false);
+#endif
+ }
+ {
+ const int ia[] = {0, 0, 0};
+ const int ib[] = {1, 1, 0};
+ const unsigned sa = sizeof(ia)/sizeof(ia[0]);
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib)) == false);
+#ifdef HAS_FOUR_ITERATOR_VERSION
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ forward_iterator<const int*>(ib + sa)) == false);
+#endif
+ }
+ {
+ const int ia[] = {0, 0, 0};
+ const int ib[] = {1, 1, 1};
+ const unsigned sa = sizeof(ia)/sizeof(ia[0]);
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib)) == false);
+#ifdef HAS_FOUR_ITERATOR_VERSION
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ forward_iterator<const int*>(ib + sa)) == false);
+#endif
+ }
+ {
+ const int ia[] = {0, 0, 0};
+ const int ib[] = {1, 1, 2};
+ const unsigned sa = sizeof(ia)/sizeof(ia[0]);
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib)) == false);
+#ifdef HAS_FOUR_ITERATOR_VERSION
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ forward_iterator<const int*>(ib + sa)) == false);
+#endif
+ }
+ {
+ const int ia[] = {0, 0, 0};
+ const int ib[] = {1, 2, 0};
+ const unsigned sa = sizeof(ia)/sizeof(ia[0]);
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib)) == false);
+#ifdef HAS_FOUR_ITERATOR_VERSION
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ forward_iterator<const int*>(ib + sa)) == false);
+#endif
+ }
+ {
+ const int ia[] = {0, 0, 0};
+ const int ib[] = {1, 2, 1};
+ const unsigned sa = sizeof(ia)/sizeof(ia[0]);
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib)) == false);
+#ifdef HAS_FOUR_ITERATOR_VERSION
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ forward_iterator<const int*>(ib + sa)) == false);
+#endif
+ }
+ {
+ const int ia[] = {0, 0, 0};
+ const int ib[] = {1, 2, 2};
+ const unsigned sa = sizeof(ia)/sizeof(ia[0]);
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib)) == false);
+#ifdef HAS_FOUR_ITERATOR_VERSION
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ forward_iterator<const int*>(ib + sa)) == false);
+#endif
+ }
+ {
+ const int ia[] = {0, 0, 1};
+ const int ib[] = {1, 0, 0};
+ const unsigned sa = sizeof(ia)/sizeof(ia[0]);
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib)) == true);
+#ifdef HAS_FOUR_ITERATOR_VERSION
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ forward_iterator<const int*>(ib + sa)) == true);
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ forward_iterator<const int*>(ib + sa - 1)) == false);
+#endif
+ }
+ {
+ const int ia[] = {0, 0, 1};
+ const int ib[] = {1, 0, 1};
+ const unsigned sa = sizeof(ia)/sizeof(ia[0]);
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib)) == false);
+#ifdef HAS_FOUR_ITERATOR_VERSION
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ forward_iterator<const int*>(ib + sa)) == false);
+#endif
+ }
+ {
+ const int ia[] = {0, 1, 2};
+ const int ib[] = {1, 0, 2};
+ const unsigned sa = sizeof(ia)/sizeof(ia[0]);
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib)) == true);
+#ifdef HAS_FOUR_ITERATOR_VERSION
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ forward_iterator<const int*>(ib + sa)) == true);
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ forward_iterator<const int*>(ib + sa - 1)) == false);
+#endif
+ }
+ {
+ const int ia[] = {0, 1, 2};
+ const int ib[] = {1, 2, 0};
+ const unsigned sa = sizeof(ia)/sizeof(ia[0]);
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib)) == true);
+#ifdef HAS_FOUR_ITERATOR_VERSION
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ forward_iterator<const int*>(ib + sa)) == true);
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ forward_iterator<const int*>(ib + sa - 1)) == false);
+#endif
+ }
+ {
+ const int ia[] = {0, 1, 2};
+ const int ib[] = {2, 1, 0};
+ const unsigned sa = sizeof(ia)/sizeof(ia[0]);
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib)) == true);
+#ifdef HAS_FOUR_ITERATOR_VERSION
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ forward_iterator<const int*>(ib + sa)) == true);
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ forward_iterator<const int*>(ib + sa - 1)) == false);
+#endif
+ }
+ {
+ const int ia[] = {0, 1, 2};
+ const int ib[] = {2, 0, 1};
+ const unsigned sa = sizeof(ia)/sizeof(ia[0]);
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib)) == true);
+#ifdef HAS_FOUR_ITERATOR_VERSION
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ forward_iterator<const int*>(ib + sa)) == true);
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ forward_iterator<const int*>(ib + sa - 1)) == false);
+#endif
+ }
+ {
+ const int ia[] = {0, 0, 1};
+ const int ib[] = {1, 0, 1};
+ const unsigned sa = sizeof(ia)/sizeof(ia[0]);
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib)) == false);
+#ifdef HAS_FOUR_ITERATOR_VERSION
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ forward_iterator<const int*>(ib + sa)) == false);
+#endif
+ }
+ {
+ const int ia[] = {0, 0, 1};
+ const int ib[] = {1, 0, 0};
+ const unsigned sa = sizeof(ia)/sizeof(ia[0]);
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib)) == true);
+#ifdef HAS_FOUR_ITERATOR_VERSION
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ forward_iterator<const int*>(ib + sa)) == true);
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib + 1),
+ forward_iterator<const int*>(ib + sa)) == false);
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ forward_iterator<const int*>(ib + sa - 1)) == false);
+#endif
+ }
+ {
+ const int ia[] = {0, 1, 2, 3, 0, 5, 6, 2, 4, 4};
+ const int ib[] = {4, 2, 3, 0, 1, 4, 0, 5, 6, 2};
+ const unsigned sa = sizeof(ia)/sizeof(ia[0]);
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib)) == true);
+#ifdef HAS_FOUR_ITERATOR_VERSION
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ forward_iterator<const int*>(ib + sa)) == true);
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib + 1 ),
+ forward_iterator<const int*>(ib + sa)) == false);
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ forward_iterator<const int*>(ib + sa - 1)) == false);
+#endif
+ }
+ {
+ const int ia[] = {0, 1, 2, 3, 0, 5, 6, 2, 4, 4};
+ const int ib[] = {4, 2, 3, 0, 1, 4, 0, 5, 6, 0};
+ const unsigned sa = sizeof(ia)/sizeof(ia[0]);
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib)) == false);
+#ifdef HAS_FOUR_ITERATOR_VERSION
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ forward_iterator<const int*>(ib + sa)) == false);
+#endif
+ }
+}
diff --git a/libcxx/test/std/algorithms/alg.nonmodifying/alg.is_permutation/is_permutation_pred.pass.cpp b/libcxx/test/std/algorithms/alg.nonmodifying/alg.is_permutation/is_permutation_pred.pass.cpp
new file mode 100644
index 00000000000..ceb897da514
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.nonmodifying/alg.is_permutation/is_permutation_pred.pass.cpp
@@ -0,0 +1,729 @@
+//===----------------------------------------------------------------------===//
+//
+// 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<class ForwardIterator1, class ForwardIterator2, class BinaryPredicate>
+// bool
+// is_permutation(ForwardIterator1 first1, ForwardIterator1 last1,
+// ForwardIterator2 first2, BinaryPredicate pred);
+
+#include <algorithm>
+#include <functional>
+#include <cassert>
+
+#include "test_iterators.h"
+
+#if _LIBCPP_STD_VER > 11
+#define HAS_FOUR_ITERATOR_VERSION
+#endif
+
+int comparison_count = 0;
+template <typename T>
+bool counting_equals ( const T &a, const T &b ) {
+ ++comparison_count;
+ return a == b;
+ }
+
+
+int main()
+{
+ {
+ const int ia[] = {0};
+ const int ib[] = {0};
+ const unsigned sa = sizeof(ia)/sizeof(ia[0]);
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + 0),
+ forward_iterator<const int*>(ib),
+ std::equal_to<const int>()) == true);
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ std::equal_to<const int>()) == true);
+#ifdef HAS_FOUR_ITERATOR_VERSION
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ forward_iterator<const int*>(ib + sa),
+ std::equal_to<const int>()) == true);
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ forward_iterator<const int*>(ib + sa - 1),
+ std::equal_to<const int>()) == false);
+#endif
+ }
+ {
+ const int ia[] = {0};
+ const int ib[] = {1};
+ const unsigned sa = sizeof(ia)/sizeof(ia[0]);
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ std::equal_to<const int>()) == false);
+#ifdef HAS_FOUR_ITERATOR_VERSION
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ forward_iterator<const int*>(ib + sa),
+ std::equal_to<const int>()) == false);
+#endif
+ }
+
+ {
+ const int ia[] = {0, 0};
+ const int ib[] = {0, 0};
+ const unsigned sa = sizeof(ia)/sizeof(ia[0]);
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ std::equal_to<const int>()) == true);
+#ifdef HAS_FOUR_ITERATOR_VERSION
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ forward_iterator<const int*>(ib + sa),
+ std::equal_to<const int>()) == true);
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ forward_iterator<const int*>(ib + sa - 1),
+ std::equal_to<const int>()) == false);
+#endif
+ }
+ {
+ const int ia[] = {0, 0};
+ const int ib[] = {0, 1};
+ const unsigned sa = sizeof(ia)/sizeof(ia[0]);
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ std::equal_to<const int>()) == false);
+#ifdef HAS_FOUR_ITERATOR_VERSION
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ forward_iterator<const int*>(ib + sa),
+ std::equal_to<const int>()) == false);
+#endif
+ }
+ {
+ const int ia[] = {0, 0};
+ const int ib[] = {1, 0};
+ const unsigned sa = sizeof(ia)/sizeof(ia[0]);
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ std::equal_to<const int>()) == false);
+#ifdef HAS_FOUR_ITERATOR_VERSION
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ forward_iterator<const int*>(ib + sa),
+ std::equal_to<const int>()) == false);
+#endif
+ }
+ {
+ const int ia[] = {0, 0};
+ const int ib[] = {1, 1};
+ const unsigned sa = sizeof(ia)/sizeof(ia[0]);
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ std::equal_to<const int>()) == false);
+#ifdef HAS_FOUR_ITERATOR_VERSION
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ forward_iterator<const int*>(ib + sa),
+ std::equal_to<const int>()) == false);
+#endif
+ }
+ {
+ const int ia[] = {0, 1};
+ const int ib[] = {0, 0};
+ const unsigned sa = sizeof(ia)/sizeof(ia[0]);
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ std::equal_to<const int>()) == false);
+#ifdef HAS_FOUR_ITERATOR_VERSION
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ forward_iterator<const int*>(ib + sa),
+ std::equal_to<const int>()) == false);
+#endif
+ }
+ {
+ const int ia[] = {0, 1};
+ const int ib[] = {0, 1};
+ const unsigned sa = sizeof(ia)/sizeof(ia[0]);
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ std::equal_to<const int>()) == true);
+#ifdef HAS_FOUR_ITERATOR_VERSION
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ forward_iterator<const int*>(ib + sa),
+ std::equal_to<const int>()) == true);
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ forward_iterator<const int*>(ib + sa - 1),
+ std::equal_to<const int>()) == false);
+#endif
+ }
+ {
+ const int ia[] = {0, 1};
+ const int ib[] = {1, 0};
+ const unsigned sa = sizeof(ia)/sizeof(ia[0]);
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ std::equal_to<const int>()) == true);
+#ifdef HAS_FOUR_ITERATOR_VERSION
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ forward_iterator<const int*>(ib + sa),
+ std::equal_to<const int>()) == true);
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ forward_iterator<const int*>(ib + sa - 1),
+ std::equal_to<const int>()) == false);
+#endif
+ }
+ {
+ const int ia[] = {0, 1};
+ const int ib[] = {1, 1};
+ const unsigned sa = sizeof(ia)/sizeof(ia[0]);
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ std::equal_to<const int>()) == false);
+#ifdef HAS_FOUR_ITERATOR_VERSION
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ forward_iterator<const int*>(ib + sa),
+ std::equal_to<const int>()) == false);
+#endif
+ }
+ {
+ const int ia[] = {1, 0};
+ const int ib[] = {0, 0};
+ const unsigned sa = sizeof(ia)/sizeof(ia[0]);
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ std::equal_to<const int>()) == false);
+#ifdef HAS_FOUR_ITERATOR_VERSION
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ forward_iterator<const int*>(ib + sa),
+ std::equal_to<const int>()) == false);
+#endif
+ }
+ {
+ const int ia[] = {1, 0};
+ const int ib[] = {0, 1};
+ const unsigned sa = sizeof(ia)/sizeof(ia[0]);
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ std::equal_to<const int>()) == true);
+#ifdef HAS_FOUR_ITERATOR_VERSION
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ forward_iterator<const int*>(ib + sa),
+ std::equal_to<const int>()) == true);
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ forward_iterator<const int*>(ib + sa - 1),
+ std::equal_to<const int>()) == false);
+#endif
+ }
+ {
+ const int ia[] = {1, 0};
+ const int ib[] = {1, 0};
+ const unsigned sa = sizeof(ia)/sizeof(ia[0]);
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ std::equal_to<const int>()) == true);
+#ifdef HAS_FOUR_ITERATOR_VERSION
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ forward_iterator<const int*>(ib + sa),
+ std::equal_to<const int>()) == true);
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ forward_iterator<const int*>(ib + sa - 1),
+ std::equal_to<const int>()) == false);
+#endif
+ }
+ {
+ const int ia[] = {1, 0};
+ const int ib[] = {1, 1};
+ const unsigned sa = sizeof(ia)/sizeof(ia[0]);
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ std::equal_to<const int>()) == false);
+#ifdef HAS_FOUR_ITERATOR_VERSION
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ forward_iterator<const int*>(ib + sa),
+ std::equal_to<const int>()) == false);
+#endif
+ }
+ {
+ const int ia[] = {1, 1};
+ const int ib[] = {0, 0};
+ const unsigned sa = sizeof(ia)/sizeof(ia[0]);
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ std::equal_to<const int>()) == false);
+#ifdef HAS_FOUR_ITERATOR_VERSION
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ forward_iterator<const int*>(ib + sa),
+ std::equal_to<const int>()) == false);
+#endif
+ }
+ {
+ const int ia[] = {1, 1};
+ const int ib[] = {0, 1};
+ const unsigned sa = sizeof(ia)/sizeof(ia[0]);
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ std::equal_to<const int>()) == false);
+#ifdef HAS_FOUR_ITERATOR_VERSION
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ forward_iterator<const int*>(ib + sa),
+ std::equal_to<const int>()) == false);
+#endif
+ }
+ {
+ const int ia[] = {1, 1};
+ const int ib[] = {1, 0};
+ const unsigned sa = sizeof(ia)/sizeof(ia[0]);
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ std::equal_to<const int>()) == false);
+#ifdef HAS_FOUR_ITERATOR_VERSION
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ forward_iterator<const int*>(ib + sa),
+ std::equal_to<const int>()) == false);
+#endif
+ }
+ {
+ const int ia[] = {1, 1};
+ const int ib[] = {1, 1};
+ const unsigned sa = sizeof(ia)/sizeof(ia[0]);
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ std::equal_to<const int>()) == true);
+#ifdef HAS_FOUR_ITERATOR_VERSION
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ forward_iterator<const int*>(ib + sa),
+ std::equal_to<const int>()) == true);
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ forward_iterator<const int*>(ib + sa - 1),
+ std::equal_to<const int>()) == false);
+#endif
+ }
+
+ {
+ const int ia[] = {0, 0, 0};
+ const int ib[] = {1, 0, 0};
+ const unsigned sa = sizeof(ia)/sizeof(ia[0]);
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ std::equal_to<const int>()) == false);
+#ifdef HAS_FOUR_ITERATOR_VERSION
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ forward_iterator<const int*>(ib + sa),
+ std::equal_to<const int>()) == false);
+#endif
+ }
+ {
+ const int ia[] = {0, 0, 0};
+ const int ib[] = {1, 0, 1};
+ const unsigned sa = sizeof(ia)/sizeof(ia[0]);
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ std::equal_to<const int>()) == false);
+#ifdef HAS_FOUR_ITERATOR_VERSION
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ forward_iterator<const int*>(ib + sa),
+ std::equal_to<const int>()) == false);
+#endif
+ }
+ {
+ const int ia[] = {0, 0, 0};
+ const int ib[] = {1, 0, 2};
+ const unsigned sa = sizeof(ia)/sizeof(ia[0]);
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ std::equal_to<const int>()) == false);
+#ifdef HAS_FOUR_ITERATOR_VERSION
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ forward_iterator<const int*>(ib + sa),
+ std::equal_to<const int>()) == false);
+#endif
+ }
+ {
+ const int ia[] = {0, 0, 0};
+ const int ib[] = {1, 1, 0};
+ const unsigned sa = sizeof(ia)/sizeof(ia[0]);
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ std::equal_to<const int>()) == false);
+#ifdef HAS_FOUR_ITERATOR_VERSION
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ forward_iterator<const int*>(ib + sa),
+ std::equal_to<const int>()) == false);
+#endif
+ }
+ {
+ const int ia[] = {0, 0, 0};
+ const int ib[] = {1, 1, 1};
+ const unsigned sa = sizeof(ia)/sizeof(ia[0]);
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ std::equal_to<const int>()) == false);
+#ifdef HAS_FOUR_ITERATOR_VERSION
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ forward_iterator<const int*>(ib + sa),
+ std::equal_to<const int>()) == false);
+#endif
+ }
+ {
+ const int ia[] = {0, 0, 0};
+ const int ib[] = {1, 1, 2};
+ const unsigned sa = sizeof(ia)/sizeof(ia[0]);
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ std::equal_to<const int>()) == false);
+#ifdef HAS_FOUR_ITERATOR_VERSION
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ forward_iterator<const int*>(ib + sa),
+ std::equal_to<const int>()) == false);
+#endif
+ }
+ {
+ const int ia[] = {0, 0, 0};
+ const int ib[] = {1, 2, 0};
+ const unsigned sa = sizeof(ia)/sizeof(ia[0]);
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ std::equal_to<const int>()) == false);
+#ifdef HAS_FOUR_ITERATOR_VERSION
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ forward_iterator<const int*>(ib + sa),
+ std::equal_to<const int>()) == false);
+#endif
+ }
+ {
+ const int ia[] = {0, 0, 0};
+ const int ib[] = {1, 2, 1};
+ const unsigned sa = sizeof(ia)/sizeof(ia[0]);
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ std::equal_to<const int>()) == false);
+#ifdef HAS_FOUR_ITERATOR_VERSION
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ forward_iterator<const int*>(ib + sa),
+ std::equal_to<const int>()) == false);
+#endif
+ }
+ {
+ const int ia[] = {0, 0, 0};
+ const int ib[] = {1, 2, 2};
+ const unsigned sa = sizeof(ia)/sizeof(ia[0]);
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ std::equal_to<const int>()) == false);
+#ifdef HAS_FOUR_ITERATOR_VERSION
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ forward_iterator<const int*>(ib + sa),
+ std::equal_to<const int>()) == false);
+#endif
+ }
+ {
+ const int ia[] = {0, 0, 1};
+ const int ib[] = {1, 0, 0};
+ const unsigned sa = sizeof(ia)/sizeof(ia[0]);
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ std::equal_to<const int>()) == true);
+#ifdef HAS_FOUR_ITERATOR_VERSION
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ forward_iterator<const int*>(ib + sa),
+ std::equal_to<const int>()) == true);
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ forward_iterator<const int*>(ib + sa - 1),
+ std::equal_to<const int>()) == false);
+#endif
+ }
+ {
+ const int ia[] = {0, 0, 1};
+ const int ib[] = {1, 0, 1};
+ const unsigned sa = sizeof(ia)/sizeof(ia[0]);
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ std::equal_to<const int>()) == false);
+#ifdef HAS_FOUR_ITERATOR_VERSION
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ forward_iterator<const int*>(ib + sa),
+ std::equal_to<const int>()) == false);
+#endif
+ }
+ {
+ const int ia[] = {0, 1, 2};
+ const int ib[] = {1, 0, 2};
+ const unsigned sa = sizeof(ia)/sizeof(ia[0]);
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ std::equal_to<const int>()) == true);
+#ifdef HAS_FOUR_ITERATOR_VERSION
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ forward_iterator<const int*>(ib + sa),
+ std::equal_to<const int>()) == true);
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ forward_iterator<const int*>(ib + sa - 1),
+ std::equal_to<const int>()) == false);
+#endif
+ }
+ {
+ const int ia[] = {0, 1, 2};
+ const int ib[] = {1, 2, 0};
+ const unsigned sa = sizeof(ia)/sizeof(ia[0]);
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ std::equal_to<const int>()) == true);
+#ifdef HAS_FOUR_ITERATOR_VERSION
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ forward_iterator<const int*>(ib + sa),
+ std::equal_to<const int>()) == true);
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ forward_iterator<const int*>(ib + sa - 1),
+ std::equal_to<const int>()) == false);
+#endif
+ }
+ {
+ const int ia[] = {0, 1, 2};
+ const int ib[] = {2, 1, 0};
+ const unsigned sa = sizeof(ia)/sizeof(ia[0]);
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ std::equal_to<const int>()) == true);
+#ifdef HAS_FOUR_ITERATOR_VERSION
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ forward_iterator<const int*>(ib + sa),
+ std::equal_to<const int>()) == true);
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ forward_iterator<const int*>(ib + sa - 1),
+ std::equal_to<const int>()) == false);
+#endif
+ }
+ {
+ const int ia[] = {0, 1, 2};
+ const int ib[] = {2, 0, 1};
+ const unsigned sa = sizeof(ia)/sizeof(ia[0]);
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ std::equal_to<const int>()) == true);
+#ifdef HAS_FOUR_ITERATOR_VERSION
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ forward_iterator<const int*>(ib + sa),
+ std::equal_to<const int>()) == true);
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ forward_iterator<const int*>(ib + sa - 1),
+ std::equal_to<const int>()) == false);
+#endif
+ }
+ {
+ const int ia[] = {0, 0, 1};
+ const int ib[] = {1, 0, 1};
+ const unsigned sa = sizeof(ia)/sizeof(ia[0]);
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ std::equal_to<const int>()) == false);
+#ifdef HAS_FOUR_ITERATOR_VERSION
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ forward_iterator<const int*>(ib + sa),
+ std::equal_to<const int>()) == false);
+#endif
+ }
+ {
+ const int ia[] = {0, 0, 1};
+ const int ib[] = {1, 0, 0};
+ const unsigned sa = sizeof(ia)/sizeof(ia[0]);
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ std::equal_to<const int>()) == true);
+#ifdef HAS_FOUR_ITERATOR_VERSION
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ forward_iterator<const int*>(ib + sa),
+ std::equal_to<const int>()) == true);
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib + 1),
+ forward_iterator<const int*>(ib + sa),
+ std::equal_to<const int>()) == false);
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ forward_iterator<const int*>(ib + sa - 1),
+ std::equal_to<const int>()) == false);
+#endif
+ }
+ {
+ const int ia[] = {0, 1, 2, 3, 0, 5, 6, 2, 4, 4};
+ const int ib[] = {4, 2, 3, 0, 1, 4, 0, 5, 6, 2};
+ const unsigned sa = sizeof(ia)/sizeof(ia[0]);
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ std::equal_to<const int>()) == true);
+#ifdef HAS_FOUR_ITERATOR_VERSION
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ forward_iterator<const int*>(ib + sa),
+ std::equal_to<const int>()) == true);
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib + 1),
+ forward_iterator<const int*>(ib + sa),
+ std::equal_to<const int>()) == false);
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ forward_iterator<const int*>(ib + sa - 1),
+ std::equal_to<const int>()) == false);
+ comparison_count = 0;
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ forward_iterator<const int*>(ib + sa - 1),
+ counting_equals<const int>) == false);
+ assert ( comparison_count > 0 );
+ comparison_count = 0;
+ assert(std::is_permutation(random_access_iterator<const int*>(ia),
+ random_access_iterator<const int*>(ia + sa),
+ random_access_iterator<const int*>(ib),
+ random_access_iterator<const int*>(ib + sa - 1),
+ counting_equals<const int>) == false);
+ assert ( comparison_count == 0 );
+#endif
+ }
+ {
+ const int ia[] = {0, 1, 2, 3, 0, 5, 6, 2, 4, 4};
+ const int ib[] = {4, 2, 3, 0, 1, 4, 0, 5, 6, 0};
+ const unsigned sa = sizeof(ia)/sizeof(ia[0]);
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ std::equal_to<const int>()) == false);
+#ifdef HAS_FOUR_ITERATOR_VERSION
+ assert(std::is_permutation(forward_iterator<const int*>(ia),
+ forward_iterator<const int*>(ia + sa),
+ forward_iterator<const int*>(ib),
+ forward_iterator<const int*>(ib + sa),
+ std::equal_to<const int>()) == false);
+#endif
+ }
+}
diff --git a/libcxx/test/std/algorithms/alg.nonmodifying/alg.none_of/none_of.pass.cpp b/libcxx/test/std/algorithms/alg.nonmodifying/alg.none_of/none_of.pass.cpp
new file mode 100644
index 00000000000..f4ea161891b
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.nonmodifying/alg.none_of/none_of.pass.cpp
@@ -0,0 +1,55 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 <class InputIterator, class Predicate>
+// bool
+// none_of(InputIterator first, InputIterator last, Predicate pred);
+
+#include <algorithm>
+#include <cassert>
+
+#include "test_iterators.h"
+
+struct test1
+{
+ bool operator()(const int& i) const
+ {
+ return i % 2 == 0;
+ }
+};
+
+int main()
+{
+ {
+ int ia[] = {2, 4, 6, 8};
+ const unsigned sa = sizeof(ia)/sizeof(ia[0]);
+ assert(std::none_of(input_iterator<const int*>(ia),
+ input_iterator<const int*>(ia + sa), test1()) == false);
+ assert(std::none_of(input_iterator<const int*>(ia),
+ input_iterator<const int*>(ia), test1()) == true);
+ }
+ {
+ const int ia[] = {2, 4, 5, 8};
+ const unsigned sa = sizeof(ia)/sizeof(ia[0]);
+ assert(std::none_of(input_iterator<const int*>(ia),
+ input_iterator<const int*>(ia + sa), test1()) == false);
+ assert(std::none_of(input_iterator<const int*>(ia),
+ input_iterator<const int*>(ia), test1()) == true);
+ }
+ {
+ const int ia[] = {1, 3, 5, 7};
+ const unsigned sa = sizeof(ia)/sizeof(ia[0]);
+ assert(std::none_of(input_iterator<const int*>(ia),
+ input_iterator<const int*>(ia + sa), test1()) == true);
+ assert(std::none_of(input_iterator<const int*>(ia),
+ input_iterator<const int*>(ia), test1()) == true);
+ }
+}
diff --git a/libcxx/test/std/algorithms/alg.nonmodifying/alg.search/search.pass.cpp b/libcxx/test/std/algorithms/alg.nonmodifying/alg.search/search.pass.cpp
new file mode 100644
index 00000000000..e5c2dd29d11
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.nonmodifying/alg.search/search.pass.cpp
@@ -0,0 +1,72 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 Iter1, ForwardIterator Iter2>
+// requires HasEqualTo<Iter1::value_type, Iter2::value_type>
+// Iter1
+// search(Iter1 first1, Iter1 last1, Iter2 first2, Iter2 last2);
+
+#include <algorithm>
+#include <cassert>
+
+#include "test_iterators.h"
+
+template <class Iter1, class Iter2>
+void
+test()
+{
+ int ia[] = {0, 1, 2, 3, 4, 5};
+ const unsigned sa = sizeof(ia)/sizeof(ia[0]);
+ assert(std::search(Iter1(ia), Iter1(ia+sa), Iter2(ia), Iter2(ia)) == Iter1(ia));
+ assert(std::search(Iter1(ia), Iter1(ia+sa), Iter2(ia), Iter2(ia+1)) == Iter1(ia));
+ assert(std::search(Iter1(ia), Iter1(ia+sa), Iter2(ia+1), Iter2(ia+2)) == Iter1(ia+1));
+ assert(std::search(Iter1(ia), Iter1(ia+sa), Iter2(ia+2), Iter2(ia+2)) == Iter1(ia));
+ assert(std::search(Iter1(ia), Iter1(ia+sa), Iter2(ia+2), Iter2(ia+3)) == Iter1(ia+2));
+ assert(std::search(Iter1(ia), Iter1(ia+sa), Iter2(ia+2), Iter2(ia+3)) == Iter1(ia+2));
+ assert(std::search(Iter1(ia), Iter1(ia), Iter2(ia+2), Iter2(ia+3)) == Iter1(ia));
+ assert(std::search(Iter1(ia), Iter1(ia+sa), Iter2(ia+sa-1), Iter2(ia+sa)) == Iter1(ia+sa-1));
+ assert(std::search(Iter1(ia), Iter1(ia+sa), Iter2(ia+sa-3), Iter2(ia+sa)) == Iter1(ia+sa-3));
+ assert(std::search(Iter1(ia), Iter1(ia+sa), Iter2(ia), Iter2(ia+sa)) == Iter1(ia));
+ assert(std::search(Iter1(ia), Iter1(ia+sa-1), Iter2(ia), Iter2(ia+sa)) == Iter1(ia+sa-1));
+ assert(std::search(Iter1(ia), Iter1(ia+1), Iter2(ia), Iter2(ia+sa)) == Iter1(ia+1));
+ int ib[] = {0, 1, 2, 0, 1, 2, 3, 0, 1, 2, 3, 4};
+ const unsigned sb = sizeof(ib)/sizeof(ib[0]);
+ int ic[] = {1};
+ assert(std::search(Iter1(ib), Iter1(ib+sb), Iter2(ic), Iter2(ic+1)) == Iter1(ib+1));
+ int id[] = {1, 2};
+ assert(std::search(Iter1(ib), Iter1(ib+sb), Iter2(id), Iter2(id+2)) == Iter1(ib+1));
+ int ie[] = {1, 2, 3};
+ assert(std::search(Iter1(ib), Iter1(ib+sb), Iter2(ie), Iter2(ie+3)) == Iter1(ib+4));
+ int ig[] = {1, 2, 3, 4};
+ assert(std::search(Iter1(ib), Iter1(ib+sb), Iter2(ig), Iter2(ig+4)) == Iter1(ib+8));
+ int ih[] = {0, 1, 1, 1, 1, 2, 3, 0, 1, 2, 3, 4};
+ const unsigned sh = sizeof(ih)/sizeof(ih[0]);
+ int ii[] = {1, 1, 2};
+ assert(std::search(Iter1(ih), Iter1(ih+sh), Iter2(ii), Iter2(ii+3)) == Iter1(ih+3));
+ int ij[] = {0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0};
+ const unsigned sj = sizeof(ij)/sizeof(ij[0]);
+ int ik[] = {0, 0, 0, 0, 1, 1, 1, 1, 0, 0};
+ const unsigned sk = sizeof(ik)/sizeof(ik[0]);
+ assert(std::search(Iter1(ij), Iter1(ij+sj), Iter2(ik), Iter2(ik+sk)) == Iter1(ij+6));
+}
+
+int main()
+{
+ test<forward_iterator<const int*>, forward_iterator<const int*> >();
+ test<forward_iterator<const int*>, bidirectional_iterator<const int*> >();
+ test<forward_iterator<const int*>, random_access_iterator<const int*> >();
+ test<bidirectional_iterator<const int*>, forward_iterator<const int*> >();
+ test<bidirectional_iterator<const int*>, bidirectional_iterator<const int*> >();
+ test<bidirectional_iterator<const int*>, random_access_iterator<const int*> >();
+ test<random_access_iterator<const int*>, forward_iterator<const int*> >();
+ test<random_access_iterator<const int*>, bidirectional_iterator<const int*> >();
+ test<random_access_iterator<const int*>, random_access_iterator<const int*> >();
+}
diff --git a/libcxx/test/std/algorithms/alg.nonmodifying/alg.search/search_n.pass.cpp b/libcxx/test/std/algorithms/alg.nonmodifying/alg.search/search_n.pass.cpp
new file mode 100644
index 00000000000..b834da210d3
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.nonmodifying/alg.search/search_n.pass.cpp
@@ -0,0 +1,73 @@
+//===----------------------------------------------------------------------===//
+//
+// 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<class ForwardIterator, class Size, class T>
+// ForwardIterator
+// search_n(ForwardIterator first, ForwardIterator last, Size count,
+// const T& value);
+
+#include <algorithm>
+#include <cassert>
+
+#include "test_iterators.h"
+
+template <class Iter>
+void
+test()
+{
+ int ia[] = {0, 1, 2, 3, 4, 5};
+ const unsigned sa = sizeof(ia)/sizeof(ia[0]);
+ assert(std::search_n(Iter(ia), Iter(ia+sa), 0, 0) == Iter(ia));
+ assert(std::search_n(Iter(ia), Iter(ia+sa), 1, 0) == Iter(ia+0));
+ assert(std::search_n(Iter(ia), Iter(ia+sa), 2, 0) == Iter(ia+sa));
+ assert(std::search_n(Iter(ia), Iter(ia+sa), sa, 0) == Iter(ia+sa));
+ assert(std::search_n(Iter(ia), Iter(ia+sa), 0, 3) == Iter(ia));
+ assert(std::search_n(Iter(ia), Iter(ia+sa), 1, 3) == Iter(ia+3));
+ assert(std::search_n(Iter(ia), Iter(ia+sa), 2, 3) == Iter(ia+sa));
+ assert(std::search_n(Iter(ia), Iter(ia+sa), sa, 3) == Iter(ia+sa));
+ assert(std::search_n(Iter(ia), Iter(ia+sa), 0, 5) == Iter(ia));
+ assert(std::search_n(Iter(ia), Iter(ia+sa), 1, 5) == Iter(ia+5));
+ assert(std::search_n(Iter(ia), Iter(ia+sa), 2, 5) == Iter(ia+sa));
+ assert(std::search_n(Iter(ia), Iter(ia+sa), sa, 5) == Iter(ia+sa));
+
+ int ib[] = {0, 0, 1, 1, 2, 2};
+ const unsigned sb = sizeof(ib)/sizeof(ib[0]);
+ assert(std::search_n(Iter(ib), Iter(ib+sb), 0, 0) == Iter(ib));
+ assert(std::search_n(Iter(ib), Iter(ib+sb), 1, 0) == Iter(ib+0));
+ assert(std::search_n(Iter(ib), Iter(ib+sb), 2, 0) == Iter(ib+0));
+ assert(std::search_n(Iter(ib), Iter(ib+sb), 3, 0) == Iter(ib+sb));
+ assert(std::search_n(Iter(ib), Iter(ib+sb), sb, 0) == Iter(ib+sb));
+ assert(std::search_n(Iter(ib), Iter(ib+sb), 0, 1) == Iter(ib));
+ assert(std::search_n(Iter(ib), Iter(ib+sb), 1, 1) == Iter(ib+2));
+ assert(std::search_n(Iter(ib), Iter(ib+sb), 2, 1) == Iter(ib+2));
+ assert(std::search_n(Iter(ib), Iter(ib+sb), 3, 1) == Iter(ib+sb));
+ assert(std::search_n(Iter(ib), Iter(ib+sb), sb, 1) == Iter(ib+sb));
+ assert(std::search_n(Iter(ib), Iter(ib+sb), 0, 2) == Iter(ib));
+ assert(std::search_n(Iter(ib), Iter(ib+sb), 1, 2) == Iter(ib+4));
+ assert(std::search_n(Iter(ib), Iter(ib+sb), 2, 2) == Iter(ib+4));
+ assert(std::search_n(Iter(ib), Iter(ib+sb), 3, 2) == Iter(ib+sb));
+ assert(std::search_n(Iter(ib), Iter(ib+sb), sb, 2) == Iter(ib+sb));
+
+ int ic[] = {0, 0, 0};
+ const unsigned sc = sizeof(ic)/sizeof(ic[0]);
+ assert(std::search_n(Iter(ic), Iter(ic+sc), 0, 0) == Iter(ic));
+ assert(std::search_n(Iter(ic), Iter(ic+sc), 1, 0) == Iter(ic));
+ assert(std::search_n(Iter(ic), Iter(ic+sc), 2, 0) == Iter(ic));
+ assert(std::search_n(Iter(ic), Iter(ic+sc), 3, 0) == Iter(ic));
+ assert(std::search_n(Iter(ic), Iter(ic+sc), 4, 0) == Iter(ic+sc));
+}
+
+int main()
+{
+ test<forward_iterator<const int*> >();
+ test<bidirectional_iterator<const int*> >();
+ test<random_access_iterator<const int*> >();
+}
diff --git a/libcxx/test/std/algorithms/alg.nonmodifying/alg.search/search_n_pred.pass.cpp b/libcxx/test/std/algorithms/alg.nonmodifying/alg.search/search_n_pred.pass.cpp
new file mode 100644
index 00000000000..6004b0e0a81
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.nonmodifying/alg.search/search_n_pred.pass.cpp
@@ -0,0 +1,148 @@
+//===----------------------------------------------------------------------===//
+//
+// 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<class ForwardIterator, class Size, class T, class BinaryPredicate>
+// ForwardIterator
+// search_n(ForwardIterator first, ForwardIterator last, Size count,
+// const T& value, BinaryPredicate 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 Iter>
+void
+test()
+{
+ int ia[] = {0, 1, 2, 3, 4, 5};
+ const unsigned sa = sizeof(ia)/sizeof(ia[0]);
+ count_equal::count = 0;
+ assert(std::search_n(Iter(ia), Iter(ia+sa), 0, 0, count_equal()) == Iter(ia));
+ assert(count_equal::count <= sa);
+ count_equal::count = 0;
+ assert(std::search_n(Iter(ia), Iter(ia+sa), 1, 0, count_equal()) == Iter(ia+0));
+ assert(count_equal::count <= sa);
+ count_equal::count = 0;
+ assert(std::search_n(Iter(ia), Iter(ia+sa), 2, 0, count_equal()) == Iter(ia+sa));
+ assert(count_equal::count <= sa);
+ count_equal::count = 0;
+ assert(std::search_n(Iter(ia), Iter(ia+sa), sa, 0, count_equal()) == Iter(ia+sa));
+ assert(count_equal::count <= sa);
+ count_equal::count = 0;
+ assert(std::search_n(Iter(ia), Iter(ia+sa), 0, 3, count_equal()) == Iter(ia));
+ assert(count_equal::count <= sa);
+ count_equal::count = 0;
+ assert(std::search_n(Iter(ia), Iter(ia+sa), 1, 3, count_equal()) == Iter(ia+3));
+ assert(count_equal::count <= sa);
+ count_equal::count = 0;
+ assert(std::search_n(Iter(ia), Iter(ia+sa), 2, 3, count_equal()) == Iter(ia+sa));
+ assert(count_equal::count <= sa);
+ count_equal::count = 0;
+ assert(std::search_n(Iter(ia), Iter(ia+sa), sa, 3, count_equal()) == Iter(ia+sa));
+ assert(count_equal::count <= sa);
+ count_equal::count = 0;
+ assert(std::search_n(Iter(ia), Iter(ia+sa), 0, 5, count_equal()) == Iter(ia));
+ assert(count_equal::count <= sa);
+ count_equal::count = 0;
+ assert(std::search_n(Iter(ia), Iter(ia+sa), 1, 5, count_equal()) == Iter(ia+5));
+ assert(count_equal::count <= sa);
+ count_equal::count = 0;
+ assert(std::search_n(Iter(ia), Iter(ia+sa), 2, 5, count_equal()) == Iter(ia+sa));
+ assert(count_equal::count <= sa);
+ count_equal::count = 0;
+ assert(std::search_n(Iter(ia), Iter(ia+sa), sa, 5, count_equal()) == Iter(ia+sa));
+ assert(count_equal::count <= sa);
+ count_equal::count = 0;
+
+ int ib[] = {0, 0, 1, 1, 2, 2};
+ const unsigned sb = sizeof(ib)/sizeof(ib[0]);
+ assert(std::search_n(Iter(ib), Iter(ib+sb), 0, 0, count_equal()) == Iter(ib));
+ assert(count_equal::count <= sb);
+ count_equal::count = 0;
+ assert(std::search_n(Iter(ib), Iter(ib+sb), 1, 0, count_equal()) == Iter(ib+0));
+ assert(count_equal::count <= sb);
+ count_equal::count = 0;
+ assert(std::search_n(Iter(ib), Iter(ib+sb), 2, 0, count_equal()) == Iter(ib+0));
+ assert(count_equal::count <= sb);
+ count_equal::count = 0;
+ assert(std::search_n(Iter(ib), Iter(ib+sb), 3, 0, count_equal()) == Iter(ib+sb));
+ assert(count_equal::count <= sb);
+ count_equal::count = 0;
+ assert(std::search_n(Iter(ib), Iter(ib+sb), sb, 0, count_equal()) == Iter(ib+sb));
+ assert(count_equal::count <= sb);
+ count_equal::count = 0;
+ assert(std::search_n(Iter(ib), Iter(ib+sb), 0, 1, count_equal()) == Iter(ib));
+ assert(count_equal::count <= sb);
+ count_equal::count = 0;
+ assert(std::search_n(Iter(ib), Iter(ib+sb), 1, 1, count_equal()) == Iter(ib+2));
+ assert(count_equal::count <= sb);
+ count_equal::count = 0;
+ assert(std::search_n(Iter(ib), Iter(ib+sb), 2, 1, count_equal()) == Iter(ib+2));
+ assert(count_equal::count <= sb);
+ count_equal::count = 0;
+ assert(std::search_n(Iter(ib), Iter(ib+sb), 3, 1, count_equal()) == Iter(ib+sb));
+ assert(count_equal::count <= sb);
+ count_equal::count = 0;
+ assert(std::search_n(Iter(ib), Iter(ib+sb), sb, 1, count_equal()) == Iter(ib+sb));
+ assert(count_equal::count <= sb);
+ count_equal::count = 0;
+ assert(std::search_n(Iter(ib), Iter(ib+sb), 0, 2, count_equal()) == Iter(ib));
+ assert(count_equal::count <= sb);
+ count_equal::count = 0;
+ assert(std::search_n(Iter(ib), Iter(ib+sb), 1, 2, count_equal()) == Iter(ib+4));
+ assert(count_equal::count <= sb);
+ count_equal::count = 0;
+ assert(std::search_n(Iter(ib), Iter(ib+sb), 2, 2, count_equal()) == Iter(ib+4));
+ assert(count_equal::count <= sb);
+ count_equal::count = 0;
+ assert(std::search_n(Iter(ib), Iter(ib+sb), 3, 2, count_equal()) == Iter(ib+sb));
+ assert(count_equal::count <= sb);
+ count_equal::count = 0;
+ assert(std::search_n(Iter(ib), Iter(ib+sb), sb, 2, count_equal()) == Iter(ib+sb));
+ assert(count_equal::count <= sb);
+ count_equal::count = 0;
+
+ int ic[] = {0, 0, 0};
+ const unsigned sc = sizeof(ic)/sizeof(ic[0]);
+ assert(std::search_n(Iter(ic), Iter(ic+sc), 0, 0, count_equal()) == Iter(ic));
+ assert(count_equal::count <= sc);
+ count_equal::count = 0;
+ assert(std::search_n(Iter(ic), Iter(ic+sc), 1, 0, count_equal()) == Iter(ic));
+ assert(count_equal::count <= sc);
+ count_equal::count = 0;
+ assert(std::search_n(Iter(ic), Iter(ic+sc), 2, 0, count_equal()) == Iter(ic));
+ assert(count_equal::count <= sc);
+ count_equal::count = 0;
+ assert(std::search_n(Iter(ic), Iter(ic+sc), 3, 0, count_equal()) == Iter(ic));
+ assert(count_equal::count <= sc);
+ count_equal::count = 0;
+ assert(std::search_n(Iter(ic), Iter(ic+sc), 4, 0, count_equal()) == Iter(ic+sc));
+ assert(count_equal::count <= sc);
+ count_equal::count = 0;
+}
+
+int main()
+{
+ test<forward_iterator<const int*> >();
+ test<bidirectional_iterator<const int*> >();
+ test<random_access_iterator<const int*> >();
+}
diff --git a/libcxx/test/std/algorithms/alg.nonmodifying/alg.search/search_pred.pass.cpp b/libcxx/test/std/algorithms/alg.nonmodifying/alg.search/search_pred.pass.cpp
new file mode 100644
index 00000000000..192da03d67b
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.nonmodifying/alg.search/search_pred.pass.cpp
@@ -0,0 +1,111 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 Iter1, ForwardIterator Iter2>
+// requires HasEqualTo<Iter1::value_type, Iter2::value_type>
+// Iter1
+// search(Iter1 first1, Iter1 last1, Iter2 first2, Iter2 last2);
+
+#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 Iter1, class Iter2>
+void
+test()
+{
+ int ia[] = {0, 1, 2, 3, 4, 5};
+ const unsigned sa = sizeof(ia)/sizeof(ia[0]);
+ count_equal::count = 0;
+ assert(std::search(Iter1(ia), Iter1(ia+sa), Iter2(ia), Iter2(ia), count_equal()) == Iter1(ia));
+ assert(count_equal::count <= 0);
+ count_equal::count = 0;
+ assert(std::search(Iter1(ia), Iter1(ia+sa), Iter2(ia), Iter2(ia+1), count_equal()) == Iter1(ia));
+ assert(count_equal::count <= sa);
+ count_equal::count = 0;
+ assert(std::search(Iter1(ia), Iter1(ia+sa), Iter2(ia+1), Iter2(ia+2), count_equal()) == Iter1(ia+1));
+ assert(count_equal::count <= sa);
+ count_equal::count = 0;
+ assert(std::search(Iter1(ia), Iter1(ia+sa), Iter2(ia+2), Iter2(ia+2), count_equal()) == Iter1(ia));
+ assert(count_equal::count <= 0);
+ count_equal::count = 0;
+ assert(std::search(Iter1(ia), Iter1(ia+sa), Iter2(ia+2), Iter2(ia+3), count_equal()) == Iter1(ia+2));
+ assert(count_equal::count <= sa);
+ count_equal::count = 0;
+ assert(std::search(Iter1(ia), Iter1(ia+sa), Iter2(ia+2), Iter2(ia+3), count_equal()) == Iter1(ia+2));
+ assert(count_equal::count <= sa);
+ count_equal::count = 0;
+ assert(std::search(Iter1(ia), Iter1(ia), Iter2(ia+2), Iter2(ia+3), count_equal()) == Iter1(ia));
+ assert(count_equal::count <= 0);
+ count_equal::count = 0;
+ assert(std::search(Iter1(ia), Iter1(ia+sa), Iter2(ia+sa-1), Iter2(ia+sa), count_equal()) == Iter1(ia+sa-1));
+ assert(count_equal::count <= sa);
+ count_equal::count = 0;
+ assert(std::search(Iter1(ia), Iter1(ia+sa), Iter2(ia+sa-3), Iter2(ia+sa), count_equal()) == Iter1(ia+sa-3));
+ assert(count_equal::count <= sa*3);
+ count_equal::count = 0;
+ assert(std::search(Iter1(ia), Iter1(ia+sa), Iter2(ia), Iter2(ia+sa), count_equal()) == Iter1(ia));
+ assert(count_equal::count <= sa*sa);
+ count_equal::count = 0;
+ assert(std::search(Iter1(ia), Iter1(ia+sa-1), Iter2(ia), Iter2(ia+sa), count_equal()) == Iter1(ia+sa-1));
+ assert(count_equal::count <= (sa-1)*sa);
+ count_equal::count = 0;
+ assert(std::search(Iter1(ia), Iter1(ia+1), Iter2(ia), Iter2(ia+sa), count_equal()) == Iter1(ia+1));
+ assert(count_equal::count <= sa);
+ count_equal::count = 0;
+ int ib[] = {0, 1, 2, 0, 1, 2, 3, 0, 1, 2, 3, 4};
+ const unsigned sb = sizeof(ib)/sizeof(ib[0]);
+ int ic[] = {1};
+ assert(std::search(Iter1(ib), Iter1(ib+sb), Iter2(ic), Iter2(ic+1), count_equal()) == Iter1(ib+1));
+ assert(count_equal::count <= sb);
+ count_equal::count = 0;
+ int id[] = {1, 2};
+ assert(std::search(Iter1(ib), Iter1(ib+sb), Iter2(id), Iter2(id+2), count_equal()) == Iter1(ib+1));
+ assert(count_equal::count <= sb*2);
+ count_equal::count = 0;
+ int ie[] = {1, 2, 3};
+ assert(std::search(Iter1(ib), Iter1(ib+sb), Iter2(ie), Iter2(ie+3), count_equal()) == Iter1(ib+4));
+ assert(count_equal::count <= sb*3);
+ count_equal::count = 0;
+ int ig[] = {1, 2, 3, 4};
+ assert(std::search(Iter1(ib), Iter1(ib+sb), Iter2(ig), Iter2(ig+4), count_equal()) == Iter1(ib+8));
+ assert(count_equal::count <= sb*4);
+ count_equal::count = 0;
+ int ih[] = {0, 1, 1, 1, 1, 2, 3, 0, 1, 2, 3, 4};
+ const unsigned sh = sizeof(ih)/sizeof(ih[0]);
+ int ii[] = {1, 1, 2};
+ assert(std::search(Iter1(ih), Iter1(ih+sh), Iter2(ii), Iter2(ii+3), count_equal()) == Iter1(ih+3));
+ assert(count_equal::count <= sh*3);
+}
+
+int main()
+{
+ test<forward_iterator<const int*>, forward_iterator<const int*> >();
+ test<forward_iterator<const int*>, bidirectional_iterator<const int*> >();
+ test<forward_iterator<const int*>, random_access_iterator<const int*> >();
+ test<bidirectional_iterator<const int*>, forward_iterator<const int*> >();
+ test<bidirectional_iterator<const int*>, bidirectional_iterator<const int*> >();
+ test<bidirectional_iterator<const int*>, random_access_iterator<const int*> >();
+ test<random_access_iterator<const int*>, forward_iterator<const int*> >();
+ test<random_access_iterator<const int*>, bidirectional_iterator<const int*> >();
+ test<random_access_iterator<const int*>, random_access_iterator<const int*> >();
+}
diff --git a/libcxx/test/std/algorithms/alg.nonmodifying/mismatch/mismatch.pass.cpp b/libcxx/test/std/algorithms/alg.nonmodifying/mismatch/mismatch.pass.cpp
new file mode 100644
index 00000000000..0cf06bbfba7
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.nonmodifying/mismatch/mismatch.pass.cpp
@@ -0,0 +1,53 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 Iter1, InputIterator Iter2>
+// requires HasEqualTo<Iter1::value_type, Iter2::value_type>
+// pair<Iter1, Iter2>
+// mismatch(Iter1 first1, Iter1 last1, Iter2 first2);
+
+#include <algorithm>
+#include <cassert>
+
+#include "test_iterators.h"
+
+#if _LIBCPP_STD_VER > 11
+#define HAS_FOUR_ITERATOR_VERSION
+#endif
+
+int main()
+{
+ int ia[] = {0, 1, 2, 2, 0, 1, 2, 3};
+ const unsigned sa = sizeof(ia)/sizeof(ia[0]);
+ int ib[] = {0, 1, 2, 3, 0, 1, 2, 3};
+ const unsigned sb = sizeof(ib)/sizeof(ib[0]);
+
+ typedef input_iterator<const int*> II;
+ typedef random_access_iterator<const int*> RAI;
+
+ assert(std::mismatch(II(ia), II(ia + sa), II(ib))
+ == (std::pair<II, II>(II(ia+3), II(ib+3))));
+
+ assert(std::mismatch(RAI(ia), RAI(ia + sa), RAI(ib))
+ == (std::pair<RAI, RAI>(RAI(ia+3), RAI(ib+3))));
+
+#ifdef HAS_FOUR_ITERATOR_VERSION
+ assert(std::mismatch(II(ia), II(ia + sa), II(ib), II(ib+sb))
+ == (std::pair<II, II>(II(ia+3), II(ib+3))));
+
+ assert(std::mismatch(RAI(ia), RAI(ia + sa), RAI(ib), RAI(ib+sb))
+ == (std::pair<RAI, RAI>(RAI(ia+3), RAI(ib+3))));
+
+
+ assert(std::mismatch(II(ia), II(ia + sa), II(ib), II(ib+2))
+ == (std::pair<II, II>(II(ia+2), II(ib+2))));
+#endif
+}
diff --git a/libcxx/test/std/algorithms/alg.nonmodifying/mismatch/mismatch_pred.pass.cpp b/libcxx/test/std/algorithms/alg.nonmodifying/mismatch/mismatch_pred.pass.cpp
new file mode 100644
index 00000000000..ce0326c660f
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.nonmodifying/mismatch/mismatch_pred.pass.cpp
@@ -0,0 +1,71 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 Iter1, InputIterator Iter2,
+// Predicate<auto, Iter1::value_type, Iter2::value_type> Pred>
+// requires CopyConstructible<Pred>
+// pair<Iter1, Iter2>
+// mismatch(Iter1 first1, Iter1 last1, Iter2 first2, Pred pred);
+
+#include <algorithm>
+#include <functional>
+#include <cassert>
+
+#include "test_iterators.h"
+#include "counting_predicates.hpp"
+
+#if _LIBCPP_STD_VER > 11
+#define HAS_FOUR_ITERATOR_VERSION
+#endif
+
+int main()
+{
+ int ia[] = {0, 1, 2, 2, 0, 1, 2, 3};
+ const unsigned sa = sizeof(ia)/sizeof(ia[0]);
+ int ib[] = {0, 1, 2, 3, 0, 1, 2, 3};
+ const unsigned sb = sizeof(ib)/sizeof(ib[0]);
+
+ typedef input_iterator<const int*> II;
+ typedef random_access_iterator<const int*> RAI;
+ typedef std::equal_to<int> EQ;
+
+ assert(std::mismatch(II(ia), II(ia + sa), II(ib), EQ())
+ == (std::pair<II, II>(II(ia+3), II(ib+3))));
+ assert(std::mismatch(RAI(ia), RAI(ia + sa), RAI(ib), EQ())
+ == (std::pair<RAI, RAI>(RAI(ia+3), RAI(ib+3))));
+
+ binary_counting_predicate<EQ, int> bcp((EQ()));
+ assert(std::mismatch(RAI(ia), RAI(ia + sa), RAI(ib), std::ref(bcp))
+ == (std::pair<RAI, RAI>(RAI(ia+3), RAI(ib+3))));
+ assert(bcp.count() > 0 && bcp.count() < sa);
+ bcp.reset();
+
+#ifdef HAS_FOUR_ITERATOR_VERSION
+ assert(std::mismatch(II(ia), II(ia + sa), II(ib), II(ib + sb), EQ())
+ == (std::pair<II, II>(II(ia+3), II(ib+3))));
+ assert(std::mismatch(RAI(ia), RAI(ia + sa), RAI(ib), RAI(ib + sb), EQ())
+ == (std::pair<RAI, RAI>(RAI(ia+3), RAI(ib+3))));
+
+ assert(std::mismatch(II(ia), II(ia + sa), II(ib), II(ib + sb), std::ref(bcp))
+ == (std::pair<II, II>(II(ia+3), II(ib+3))));
+ assert(bcp.count() > 0 && bcp.count() < std::min(sa, sb));
+#endif
+
+ assert(std::mismatch(ia, ia + sa, ib, EQ()) ==
+ (std::pair<int*,int*>(ia+3,ib+3)));
+
+#ifdef HAS_FOUR_ITERATOR_VERSION
+ assert(std::mismatch(ia, ia + sa, ib, ib + sb, EQ()) ==
+ (std::pair<int*,int*>(ia+3,ib+3)));
+ assert(std::mismatch(ia, ia + sa, ib, ib + 2, EQ()) ==
+ (std::pair<int*,int*>(ia+2,ib+2)));
+#endif
+}
diff --git a/libcxx/test/std/algorithms/alg.nonmodifying/nothing_to_do.pass.cpp b/libcxx/test/std/algorithms/alg.nonmodifying/nothing_to_do.pass.cpp
new file mode 100644
index 00000000000..b58f5c55b64
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.nonmodifying/nothing_to_do.pass.cpp
@@ -0,0 +1,12 @@
+//===----------------------------------------------------------------------===//
+//
+// 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.
+//
+//===----------------------------------------------------------------------===//
+
+int main()
+{
+}
diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.binary.search/binary.search/binary_search.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.binary.search/binary.search/binary_search.pass.cpp
new file mode 100644
index 00000000000..253e0e38690
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.sorting/alg.binary.search/binary.search/binary_search.pass.cpp
@@ -0,0 +1,63 @@
+//===----------------------------------------------------------------------===//
+//
+// 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, class T>
+// requires HasLess<T, Iter::value_type>
+// && HasLess<Iter::value_type, T>
+// bool
+// binary_search(Iter first, Iter last, const T& value);
+
+#include <algorithm>
+#include <vector>
+#include <cassert>
+
+#include "test_iterators.h"
+
+template <class Iter, class T>
+void
+test(Iter first, Iter last, const T& value, bool x)
+{
+ assert(std::binary_search(first, last, value) == x);
+}
+
+template <class Iter>
+void
+test()
+{
+ const unsigned N = 1000;
+ const unsigned M = 10;
+ std::vector<int> v(N);
+ int x = 0;
+ for (int i = 0; i < v.size(); ++i)
+ {
+ v[i] = x;
+ if (++x == M)
+ x = 0;
+ }
+ std::sort(v.begin(), v.end());
+ for (x = 0; x < M; ++x)
+ test(Iter(v.data()), Iter(v.data()+v.size()), x, true);
+ test(Iter(v.data()), Iter(v.data()+v.size()), -1, false);
+ test(Iter(v.data()), Iter(v.data()+v.size()), M, false);
+}
+
+int main()
+{
+ int d[] = {0, 2, 4, 6};
+ for (int* e = d; e <= d+4; ++e)
+ for (int x = -1; x <= 7; ++x)
+ test(d, e, x, (x % 2 == 0) && ((e-d)*2 > x));
+
+ test<forward_iterator<const int*> >();
+ test<bidirectional_iterator<const int*> >();
+ test<random_access_iterator<const int*> >();
+ test<const int*>();
+}
diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.binary.search/binary.search/binary_search_comp.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.binary.search/binary.search/binary_search_comp.pass.cpp
new file mode 100644
index 00000000000..1d2840921e8
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.sorting/alg.binary.search/binary.search/binary_search_comp.pass.cpp
@@ -0,0 +1,64 @@
+//===----------------------------------------------------------------------===//
+//
+// 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, class T, CopyConstructible Compare>
+// requires Predicate<Compare, T, Iter::value_type>
+// && Predicate<Compare, Iter::value_type, T>
+// bool
+// binary_search(Iter first, Iter last, const T& value, Compare comp);
+
+#include <algorithm>
+#include <vector>
+#include <functional>
+#include <cassert>
+
+#include "test_iterators.h"
+
+template <class Iter, class T>
+void
+test(Iter first, Iter last, const T& value, bool x)
+{
+ assert(std::binary_search(first, last, value, std::greater<int>()) == x);
+}
+
+template <class Iter>
+void
+test()
+{
+ const unsigned N = 1000;
+ const unsigned M = 10;
+ std::vector<int> v(N);
+ int x = 0;
+ for (int i = 0; i < v.size(); ++i)
+ {
+ v[i] = x;
+ if (++x == M)
+ x = 0;
+ }
+ std::sort(v.begin(), v.end(), std::greater<int>());
+ for (x = 0; x < M; ++x)
+ test(Iter(v.data()), Iter(v.data()+v.size()), x, true);
+ test(Iter(v.data()), Iter(v.data()+v.size()), -1, false);
+ test(Iter(v.data()), Iter(v.data()+v.size()), M, false);
+}
+
+int main()
+{
+ int d[] = {6, 4, 2, 0};
+ for (int* e = d; e <= d+4; ++e)
+ for (int x = -1; x <= 7; ++x)
+ test(d, e, x, (x % 2 == 0) && e != d && (-2*(e-d) + 8 <= x));
+
+ test<forward_iterator<const int*> >();
+ test<bidirectional_iterator<const int*> >();
+ test<random_access_iterator<const int*> >();
+ test<const int*>();
+}
diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.binary.search/equal.range/equal_range.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.binary.search/equal.range/equal_range.pass.cpp
new file mode 100644
index 00000000000..ce659c1b50f
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.sorting/alg.binary.search/equal.range/equal_range.pass.cpp
@@ -0,0 +1,69 @@
+//===----------------------------------------------------------------------===//
+//
+// 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, class T>
+// requires HasLess<T, Iter::value_type>
+// && HasLess<Iter::value_type, T>
+// pair<Iter, Iter>
+// equal_range(Iter first, Iter last, const T& value);
+
+#include <algorithm>
+#include <vector>
+#include <cassert>
+
+#include "test_iterators.h"
+
+template <class Iter, class T>
+void
+test(Iter first, Iter last, const T& value)
+{
+ std::pair<Iter, Iter> i = std::equal_range(first, last, value);
+ for (Iter j = first; j != i.first; ++j)
+ assert(*j < value);
+ for (Iter j = i.first; j != last; ++j)
+ assert(!(*j < value));
+ for (Iter j = first; j != i.second; ++j)
+ assert(!(value < *j));
+ for (Iter j = i.second; j != last; ++j)
+ assert(value < *j);
+}
+
+template <class Iter>
+void
+test()
+{
+ const unsigned N = 1000;
+ const unsigned M = 10;
+ std::vector<int> v(N);
+ int x = 0;
+ for (int i = 0; i < v.size(); ++i)
+ {
+ v[i] = x;
+ if (++x == M)
+ x = 0;
+ }
+ std::sort(v.begin(), v.end());
+ for (x = 0; x <= M; ++x)
+ test(Iter(v.data()), Iter(v.data()+v.size()), x);
+}
+
+int main()
+{
+ int d[] = {0, 1, 2, 3};
+ for (int* e = d; e <= d+4; ++e)
+ for (int x = -1; x <= 4; ++x)
+ test(d, e, x);
+
+ test<forward_iterator<const int*> >();
+ test<bidirectional_iterator<const int*> >();
+ test<random_access_iterator<const int*> >();
+ test<const int*>();
+}
diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.binary.search/equal.range/equal_range_comp.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.binary.search/equal.range/equal_range_comp.pass.cpp
new file mode 100644
index 00000000000..2b29e2c8435
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.sorting/alg.binary.search/equal.range/equal_range_comp.pass.cpp
@@ -0,0 +1,70 @@
+//===----------------------------------------------------------------------===//
+//
+// 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, class T, CopyConstructible Compare>
+// requires Predicate<Compare, T, Iter::value_type>
+// && Predicate<Compare, Iter::value_type, T>
+// pair<Iter, Iter>
+// equal_range(Iter first, Iter last, const T& value, Compare comp);
+
+#include <algorithm>
+#include <functional>
+#include <vector>
+#include <cassert>
+
+#include "test_iterators.h"
+
+template <class Iter, class T>
+void
+test(Iter first, Iter last, const T& value)
+{
+ std::pair<Iter, Iter> i = std::equal_range(first, last, value, std::greater<int>());
+ for (Iter j = first; j != i.first; ++j)
+ assert(std::greater<int>()(*j, value));
+ for (Iter j = i.first; j != last; ++j)
+ assert(!std::greater<int>()(*j, value));
+ for (Iter j = first; j != i.second; ++j)
+ assert(!std::greater<int>()(value, *j));
+ for (Iter j = i.second; j != last; ++j)
+ assert(std::greater<int>()(value, *j));
+}
+
+template <class Iter>
+void
+test()
+{
+ const unsigned N = 1000;
+ const unsigned M = 10;
+ std::vector<int> v(N);
+ int x = 0;
+ for (int i = 0; i < v.size(); ++i)
+ {
+ v[i] = x;
+ if (++x == M)
+ x = 0;
+ }
+ std::sort(v.begin(), v.end(), std::greater<int>());
+ for (x = 0; x <= M; ++x)
+ test(Iter(v.data()), Iter(v.data()+v.size()), x);
+}
+
+int main()
+{
+ int d[] = {3, 2, 1, 0};
+ for (int* e = d; e <= d+4; ++e)
+ for (int x = -1; x <= 4; ++x)
+ test(d, e, x);
+
+ test<forward_iterator<const int*> >();
+ test<bidirectional_iterator<const int*> >();
+ test<random_access_iterator<const int*> >();
+ test<const int*>();
+}
diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.binary.search/lower.bound/lower_bound.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.binary.search/lower.bound/lower_bound.pass.cpp
new file mode 100644
index 00000000000..ce4f7ced5e6
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.sorting/alg.binary.search/lower.bound/lower_bound.pass.cpp
@@ -0,0 +1,64 @@
+//===----------------------------------------------------------------------===//
+//
+// 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, class T>
+// requires HasLess<Iter::value_type, T>
+// Iter
+// lower_bound(Iter first, Iter last, const T& value);
+
+#include <algorithm>
+#include <vector>
+#include <cassert>
+
+#include "test_iterators.h"
+
+template <class Iter, class T>
+void
+test(Iter first, Iter last, const T& value)
+{
+ Iter i = std::lower_bound(first, last, value);
+ for (Iter j = first; j != i; ++j)
+ assert(*j < value);
+ for (Iter j = i; j != last; ++j)
+ assert(!(*j < value));
+}
+
+template <class Iter>
+void
+test()
+{
+ const unsigned N = 1000;
+ const unsigned M = 10;
+ std::vector<int> v(N);
+ int x = 0;
+ for (int i = 0; i < v.size(); ++i)
+ {
+ v[i] = x;
+ if (++x == M)
+ x = 0;
+ }
+ std::sort(v.begin(), v.end());
+ for (x = 0; x <= M; ++x)
+ test(Iter(v.data()), Iter(v.data()+v.size()), x);
+}
+
+int main()
+{
+ int d[] = {0, 1, 2, 3};
+ for (int* e = d; e <= d+4; ++e)
+ for (int x = -1; x <= 4; ++x)
+ test(d, e, x);
+
+ test<forward_iterator<const int*> >();
+ test<bidirectional_iterator<const int*> >();
+ test<random_access_iterator<const int*> >();
+ test<const int*>();
+}
diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.binary.search/lower.bound/lower_bound_comp.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.binary.search/lower.bound/lower_bound_comp.pass.cpp
new file mode 100644
index 00000000000..ae65c59e315
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.sorting/alg.binary.search/lower.bound/lower_bound_comp.pass.cpp
@@ -0,0 +1,65 @@
+//===----------------------------------------------------------------------===//
+//
+// 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, class T>
+// requires HasLess<Iter::value_type, T>
+// Iter
+// lower_bound(Iter first, Iter last, const T& value);
+
+#include <algorithm>
+#include <functional>
+#include <vector>
+#include <cassert>
+
+#include "test_iterators.h"
+
+template <class Iter, class T>
+void
+test(Iter first, Iter last, const T& value)
+{
+ Iter i = std::lower_bound(first, last, value, std::greater<int>());
+ for (Iter j = first; j != i; ++j)
+ assert(std::greater<int>()(*j, value));
+ for (Iter j = i; j != last; ++j)
+ assert(!std::greater<int>()(*j, value));
+}
+
+template <class Iter>
+void
+test()
+{
+ const unsigned N = 1000;
+ const unsigned M = 10;
+ std::vector<int> v(N);
+ int x = 0;
+ for (int i = 0; i < v.size(); ++i)
+ {
+ v[i] = x;
+ if (++x == M)
+ x = 0;
+ }
+ std::sort(v.begin(), v.end(), std::greater<int>());
+ for (x = 0; x <= M; ++x)
+ test(Iter(v.data()), Iter(v.data()+v.size()), x);
+}
+
+int main()
+{
+ int d[] = {3, 2, 1, 0};
+ for (int* e = d; e <= d+4; ++e)
+ for (int x = -1; x <= 4; ++x)
+ test(d, e, x);
+
+ test<forward_iterator<const int*> >();
+ test<bidirectional_iterator<const int*> >();
+ test<random_access_iterator<const int*> >();
+ test<const int*>();
+}
diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.binary.search/nothing_to_do.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.binary.search/nothing_to_do.pass.cpp
new file mode 100644
index 00000000000..b58f5c55b64
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.sorting/alg.binary.search/nothing_to_do.pass.cpp
@@ -0,0 +1,12 @@
+//===----------------------------------------------------------------------===//
+//
+// 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.
+//
+//===----------------------------------------------------------------------===//
+
+int main()
+{
+}
diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.binary.search/upper.bound/upper_bound.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.binary.search/upper.bound/upper_bound.pass.cpp
new file mode 100644
index 00000000000..3659e08fb28
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.sorting/alg.binary.search/upper.bound/upper_bound.pass.cpp
@@ -0,0 +1,64 @@
+//===----------------------------------------------------------------------===//
+//
+// 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, class T>
+// requires HasLess<T, Iter::value_type>
+// Iter
+// upper_bound(Iter first, Iter last, const T& value);
+
+#include <algorithm>
+#include <vector>
+#include <cassert>
+
+#include "test_iterators.h"
+
+template <class Iter, class T>
+void
+test(Iter first, Iter last, const T& value)
+{
+ Iter i = std::upper_bound(first, last, value);
+ for (Iter j = first; j != i; ++j)
+ assert(!(value < *j));
+ for (Iter j = i; j != last; ++j)
+ assert(value < *j);
+}
+
+template <class Iter>
+void
+test()
+{
+ const unsigned N = 1000;
+ const unsigned M = 10;
+ std::vector<int> v(N);
+ int x = 0;
+ for (int i = 0; i < v.size(); ++i)
+ {
+ v[i] = x;
+ if (++x == M)
+ x = 0;
+ }
+ std::sort(v.begin(), v.end());
+ for (x = 0; x <= M; ++x)
+ test(Iter(v.data()), Iter(v.data()+v.size()), x);
+}
+
+int main()
+{
+ int d[] = {0, 1, 2, 3};
+ for (int* e = d; e <= d+4; ++e)
+ for (int x = -1; x <= 4; ++x)
+ test(d, e, x);
+
+ test<forward_iterator<const int*> >();
+ test<bidirectional_iterator<const int*> >();
+ test<random_access_iterator<const int*> >();
+ test<const int*>();
+}
diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.binary.search/upper.bound/upper_bound_comp.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.binary.search/upper.bound/upper_bound_comp.pass.cpp
new file mode 100644
index 00000000000..dd5fcfc2852
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.sorting/alg.binary.search/upper.bound/upper_bound_comp.pass.cpp
@@ -0,0 +1,65 @@
+//===----------------------------------------------------------------------===//
+//
+// 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, class T, Predicate<auto, T, Iter::value_type> Compare>
+// requires CopyConstructible<Compare>
+// Iter
+// upper_bound(Iter first, Iter last, const T& value, Compare comp);
+
+#include <algorithm>
+#include <functional>
+#include <vector>
+#include <cassert>
+
+#include "test_iterators.h"
+
+template <class Iter, class T>
+void
+test(Iter first, Iter last, const T& value)
+{
+ Iter i = std::upper_bound(first, last, value, std::greater<int>());
+ for (Iter j = first; j != i; ++j)
+ assert(!std::greater<int>()(value, *j));
+ for (Iter j = i; j != last; ++j)
+ assert(std::greater<int>()(value, *j));
+}
+
+template <class Iter>
+void
+test()
+{
+ const unsigned N = 1000;
+ const unsigned M = 10;
+ std::vector<int> v(N);
+ int x = 0;
+ for (int i = 0; i < v.size(); ++i)
+ {
+ v[i] = x;
+ if (++x == M)
+ x = 0;
+ }
+ std::sort(v.begin(), v.end(), std::greater<int>());
+ for (x = 0; x <= M; ++x)
+ test(Iter(v.data()), Iter(v.data()+v.size()), x);
+}
+
+int main()
+{
+ int d[] = {3, 2, 1, 0};
+ for (int* e = d; e <= d+4; ++e)
+ for (int x = -1; x <= 4; ++x)
+ test(d, e, x);
+
+ test<forward_iterator<const int*> >();
+ test<bidirectional_iterator<const int*> >();
+ test<random_access_iterator<const int*> >();
+ test<const int*>();
+}
diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.heap.operations/is.heap/is_heap.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.heap.operations/is.heap/is_heap.pass.cpp
new file mode 100644
index 00000000000..f16b2c3c61a
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.sorting/alg.heap.operations/is.heap/is_heap.pass.cpp
@@ -0,0 +1,521 @@
+//===----------------------------------------------------------------------===//
+//
+// 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<RandomAccessIterator Iter>
+// requires LessThanComparable<Iter::value_type>
+// bool
+// is_heap(Iter first, Iter last);
+
+#include <algorithm>
+#include <cassert>
+
+void test()
+{
+ int i1[] = {0, 0};
+ assert(std::is_heap(i1, i1));
+ assert(std::is_heap(i1, i1+1) == (std::is_heap_until(i1, i1+1) == i1+1));
+ int i2[] = {0, 1};
+ int i3[] = {1, 0};
+ assert(std::is_heap(i1, i1+2) == (std::is_heap_until(i1, i1+2) == i1+2));
+ assert(std::is_heap(i2, i2+2) == (std::is_heap_until(i2, i2+2) == i2+2));
+ assert(std::is_heap(i3, i3+2) == (std::is_heap_until(i3, i3+2) == i3+2));
+ int i4[] = {0, 0, 0};
+ int i5[] = {0, 0, 1};
+ int i6[] = {0, 1, 0};
+ int i7[] = {0, 1, 1};
+ int i8[] = {1, 0, 0};
+ int i9[] = {1, 0, 1};
+ int i10[] = {1, 1, 0};
+ assert(std::is_heap(i4, i4+3) == (std::is_heap_until(i4, i4+3) == i4+3));
+ assert(std::is_heap(i5, i5+3) == (std::is_heap_until(i5, i5+3) == i5+3));
+ assert(std::is_heap(i6, i6+3) == (std::is_heap_until(i6, i6+3) == i6+3));
+ assert(std::is_heap(i7, i7+3) == (std::is_heap_until(i7, i7+3) == i7+3));
+ assert(std::is_heap(i8, i8+3) == (std::is_heap_until(i8, i8+3) == i8+3));
+ assert(std::is_heap(i9, i9+3) == (std::is_heap_until(i9, i9+3) == i9+3));
+ assert(std::is_heap(i10, i10+3) == (std::is_heap_until(i10, i10+3) == i10+3));
+ int i11[] = {0, 0, 0, 0};
+ int i12[] = {0, 0, 0, 1};
+ int i13[] = {0, 0, 1, 0};
+ int i14[] = {0, 0, 1, 1};
+ int i15[] = {0, 1, 0, 0};
+ int i16[] = {0, 1, 0, 1};
+ int i17[] = {0, 1, 1, 0};
+ int i18[] = {0, 1, 1, 1};
+ int i19[] = {1, 0, 0, 0};
+ int i20[] = {1, 0, 0, 1};
+ int i21[] = {1, 0, 1, 0};
+ int i22[] = {1, 0, 1, 1};
+ int i23[] = {1, 1, 0, 0};
+ int i24[] = {1, 1, 0, 1};
+ int i25[] = {1, 1, 1, 0};
+ assert(std::is_heap(i11, i11+4) == (std::is_heap_until(i11, i11+4) == i11+4));
+ assert(std::is_heap(i12, i12+4) == (std::is_heap_until(i12, i12+4) == i12+4));
+ assert(std::is_heap(i13, i13+4) == (std::is_heap_until(i13, i13+4) == i13+4));
+ assert(std::is_heap(i14, i14+4) == (std::is_heap_until(i14, i14+4) == i14+4));
+ assert(std::is_heap(i15, i15+4) == (std::is_heap_until(i15, i15+4) == i15+4));
+ assert(std::is_heap(i16, i16+4) == (std::is_heap_until(i16, i16+4) == i16+4));
+ assert(std::is_heap(i17, i17+4) == (std::is_heap_until(i17, i17+4) == i17+4));
+ assert(std::is_heap(i18, i18+4) == (std::is_heap_until(i18, i18+4) == i18+4));
+ assert(std::is_heap(i19, i19+4) == (std::is_heap_until(i19, i19+4) == i19+4));
+ assert(std::is_heap(i20, i20+4) == (std::is_heap_until(i20, i20+4) == i20+4));
+ assert(std::is_heap(i21, i21+4) == (std::is_heap_until(i21, i21+4) == i21+4));
+ assert(std::is_heap(i22, i22+4) == (std::is_heap_until(i22, i22+4) == i22+4));
+ assert(std::is_heap(i23, i23+4) == (std::is_heap_until(i23, i23+4) == i23+4));
+ assert(std::is_heap(i24, i24+4) == (std::is_heap_until(i24, i24+4) == i24+4));
+ assert(std::is_heap(i25, i25+4) == (std::is_heap_until(i25, i25+4) == i25+4));
+ int i26[] = {0, 0, 0, 0, 0};
+ int i27[] = {0, 0, 0, 0, 1};
+ int i28[] = {0, 0, 0, 1, 0};
+ int i29[] = {0, 0, 0, 1, 1};
+ int i30[] = {0, 0, 1, 0, 0};
+ int i31[] = {0, 0, 1, 0, 1};
+ int i32[] = {0, 0, 1, 1, 0};
+ int i33[] = {0, 0, 1, 1, 1};
+ int i34[] = {0, 1, 0, 0, 0};
+ int i35[] = {0, 1, 0, 0, 1};
+ int i36[] = {0, 1, 0, 1, 0};
+ int i37[] = {0, 1, 0, 1, 1};
+ int i38[] = {0, 1, 1, 0, 0};
+ int i39[] = {0, 1, 1, 0, 1};
+ int i40[] = {0, 1, 1, 1, 0};
+ int i41[] = {0, 1, 1, 1, 1};
+ int i42[] = {1, 0, 0, 0, 0};
+ int i43[] = {1, 0, 0, 0, 1};
+ int i44[] = {1, 0, 0, 1, 0};
+ int i45[] = {1, 0, 0, 1, 1};
+ int i46[] = {1, 0, 1, 0, 0};
+ int i47[] = {1, 0, 1, 0, 1};
+ int i48[] = {1, 0, 1, 1, 0};
+ int i49[] = {1, 0, 1, 1, 1};
+ int i50[] = {1, 1, 0, 0, 0};
+ int i51[] = {1, 1, 0, 0, 1};
+ int i52[] = {1, 1, 0, 1, 0};
+ int i53[] = {1, 1, 0, 1, 1};
+ int i54[] = {1, 1, 1, 0, 0};
+ int i55[] = {1, 1, 1, 0, 1};
+ int i56[] = {1, 1, 1, 1, 0};
+ assert(std::is_heap(i26, i26+5) == (std::is_heap_until(i26, i26+5) == i26+5));
+ assert(std::is_heap(i27, i27+5) == (std::is_heap_until(i27, i27+5) == i27+5));
+ assert(std::is_heap(i28, i28+5) == (std::is_heap_until(i28, i28+5) == i28+5));
+ assert(std::is_heap(i29, i29+5) == (std::is_heap_until(i29, i29+5) == i29+5));
+ assert(std::is_heap(i30, i30+5) == (std::is_heap_until(i30, i30+5) == i30+5));
+ assert(std::is_heap(i31, i31+5) == (std::is_heap_until(i31, i31+5) == i31+5));
+ assert(std::is_heap(i32, i32+5) == (std::is_heap_until(i32, i32+5) == i32+5));
+ assert(std::is_heap(i33, i33+5) == (std::is_heap_until(i33, i33+5) == i33+5));
+ assert(std::is_heap(i34, i34+5) == (std::is_heap_until(i34, i34+5) == i34+5));
+ assert(std::is_heap(i35, i35+5) == (std::is_heap_until(i35, i35+5) == i35+5));
+ assert(std::is_heap(i36, i36+5) == (std::is_heap_until(i36, i36+5) == i36+5));
+ assert(std::is_heap(i37, i37+5) == (std::is_heap_until(i37, i37+5) == i37+5));
+ assert(std::is_heap(i38, i38+5) == (std::is_heap_until(i38, i38+5) == i38+5));
+ assert(std::is_heap(i39, i39+5) == (std::is_heap_until(i39, i39+5) == i39+5));
+ assert(std::is_heap(i40, i40+5) == (std::is_heap_until(i40, i40+5) == i40+5));
+ assert(std::is_heap(i41, i41+5) == (std::is_heap_until(i41, i41+5) == i41+5));
+ assert(std::is_heap(i42, i42+5) == (std::is_heap_until(i42, i42+5) == i42+5));
+ assert(std::is_heap(i43, i43+5) == (std::is_heap_until(i43, i43+5) == i43+5));
+ assert(std::is_heap(i44, i44+5) == (std::is_heap_until(i44, i44+5) == i44+5));
+ assert(std::is_heap(i45, i45+5) == (std::is_heap_until(i45, i45+5) == i45+5));
+ assert(std::is_heap(i46, i46+5) == (std::is_heap_until(i46, i46+5) == i46+5));
+ assert(std::is_heap(i47, i47+5) == (std::is_heap_until(i47, i47+5) == i47+5));
+ assert(std::is_heap(i48, i48+5) == (std::is_heap_until(i48, i48+5) == i48+5));
+ assert(std::is_heap(i49, i49+5) == (std::is_heap_until(i49, i49+5) == i49+5));
+ assert(std::is_heap(i50, i50+5) == (std::is_heap_until(i50, i50+5) == i50+5));
+ assert(std::is_heap(i51, i51+5) == (std::is_heap_until(i51, i51+5) == i51+5));
+ assert(std::is_heap(i52, i52+5) == (std::is_heap_until(i52, i52+5) == i52+5));
+ assert(std::is_heap(i53, i53+5) == (std::is_heap_until(i53, i53+5) == i53+5));
+ assert(std::is_heap(i54, i54+5) == (std::is_heap_until(i54, i54+5) == i54+5));
+ assert(std::is_heap(i55, i55+5) == (std::is_heap_until(i55, i55+5) == i55+5));
+ assert(std::is_heap(i56, i56+5) == (std::is_heap_until(i56, i56+5) == i56+5));
+ int i57[] = {0, 0, 0, 0, 0, 0};
+ int i58[] = {0, 0, 0, 0, 0, 1};
+ int i59[] = {0, 0, 0, 0, 1, 0};
+ int i60[] = {0, 0, 0, 0, 1, 1};
+ int i61[] = {0, 0, 0, 1, 0, 0};
+ int i62[] = {0, 0, 0, 1, 0, 1};
+ int i63[] = {0, 0, 0, 1, 1, 0};
+ int i64[] = {0, 0, 0, 1, 1, 1};
+ int i65[] = {0, 0, 1, 0, 0, 0};
+ int i66[] = {0, 0, 1, 0, 0, 1};
+ int i67[] = {0, 0, 1, 0, 1, 0};
+ int i68[] = {0, 0, 1, 0, 1, 1};
+ int i69[] = {0, 0, 1, 1, 0, 0};
+ int i70[] = {0, 0, 1, 1, 0, 1};
+ int i71[] = {0, 0, 1, 1, 1, 0};
+ int i72[] = {0, 0, 1, 1, 1, 1};
+ int i73[] = {0, 1, 0, 0, 0, 0};
+ int i74[] = {0, 1, 0, 0, 0, 1};
+ int i75[] = {0, 1, 0, 0, 1, 0};
+ int i76[] = {0, 1, 0, 0, 1, 1};
+ int i77[] = {0, 1, 0, 1, 0, 0};
+ int i78[] = {0, 1, 0, 1, 0, 1};
+ int i79[] = {0, 1, 0, 1, 1, 0};
+ int i80[] = {0, 1, 0, 1, 1, 1};
+ int i81[] = {0, 1, 1, 0, 0, 0};
+ int i82[] = {0, 1, 1, 0, 0, 1};
+ int i83[] = {0, 1, 1, 0, 1, 0};
+ int i84[] = {0, 1, 1, 0, 1, 1};
+ int i85[] = {0, 1, 1, 1, 0, 0};
+ int i86[] = {0, 1, 1, 1, 0, 1};
+ int i87[] = {0, 1, 1, 1, 1, 0};
+ int i88[] = {0, 1, 1, 1, 1, 1};
+ int i89[] = {1, 0, 0, 0, 0, 0};
+ int i90[] = {1, 0, 0, 0, 0, 1};
+ int i91[] = {1, 0, 0, 0, 1, 0};
+ int i92[] = {1, 0, 0, 0, 1, 1};
+ int i93[] = {1, 0, 0, 1, 0, 0};
+ int i94[] = {1, 0, 0, 1, 0, 1};
+ int i95[] = {1, 0, 0, 1, 1, 0};
+ int i96[] = {1, 0, 0, 1, 1, 1};
+ int i97[] = {1, 0, 1, 0, 0, 0};
+ int i98[] = {1, 0, 1, 0, 0, 1};
+ int i99[] = {1, 0, 1, 0, 1, 0};
+ int i100[] = {1, 0, 1, 0, 1, 1};
+ int i101[] = {1, 0, 1, 1, 0, 0};
+ int i102[] = {1, 0, 1, 1, 0, 1};
+ int i103[] = {1, 0, 1, 1, 1, 0};
+ int i104[] = {1, 0, 1, 1, 1, 1};
+ int i105[] = {1, 1, 0, 0, 0, 0};
+ int i106[] = {1, 1, 0, 0, 0, 1};
+ int i107[] = {1, 1, 0, 0, 1, 0};
+ int i108[] = {1, 1, 0, 0, 1, 1};
+ int i109[] = {1, 1, 0, 1, 0, 0};
+ int i110[] = {1, 1, 0, 1, 0, 1};
+ int i111[] = {1, 1, 0, 1, 1, 0};
+ int i112[] = {1, 1, 0, 1, 1, 1};
+ int i113[] = {1, 1, 1, 0, 0, 0};
+ int i114[] = {1, 1, 1, 0, 0, 1};
+ int i115[] = {1, 1, 1, 0, 1, 0};
+ int i116[] = {1, 1, 1, 0, 1, 1};
+ int i117[] = {1, 1, 1, 1, 0, 0};
+ int i118[] = {1, 1, 1, 1, 0, 1};
+ int i119[] = {1, 1, 1, 1, 1, 0};
+ assert(std::is_heap(i57, i57+6) == (std::is_heap_until(i57, i57+6) == i57+6));
+ assert(std::is_heap(i58, i58+6) == (std::is_heap_until(i58, i58+6) == i58+6));
+ assert(std::is_heap(i59, i59+6) == (std::is_heap_until(i59, i59+6) == i59+6));
+ assert(std::is_heap(i60, i60+6) == (std::is_heap_until(i60, i60+6) == i60+6));
+ assert(std::is_heap(i61, i61+6) == (std::is_heap_until(i61, i61+6) == i61+6));
+ assert(std::is_heap(i62, i62+6) == (std::is_heap_until(i62, i62+6) == i62+6));
+ assert(std::is_heap(i63, i63+6) == (std::is_heap_until(i63, i63+6) == i63+6));
+ assert(std::is_heap(i64, i64+6) == (std::is_heap_until(i64, i64+6) == i64+6));
+ assert(std::is_heap(i65, i65+6) == (std::is_heap_until(i65, i65+6) == i65+6));
+ assert(std::is_heap(i66, i66+6) == (std::is_heap_until(i66, i66+6) == i66+6));
+ assert(std::is_heap(i67, i67+6) == (std::is_heap_until(i67, i67+6) == i67+6));
+ assert(std::is_heap(i68, i68+6) == (std::is_heap_until(i68, i68+6) == i68+6));
+ assert(std::is_heap(i69, i69+6) == (std::is_heap_until(i69, i69+6) == i69+6));
+ assert(std::is_heap(i70, i70+6) == (std::is_heap_until(i70, i70+6) == i70+6));
+ assert(std::is_heap(i71, i71+6) == (std::is_heap_until(i71, i71+6) == i71+6));
+ assert(std::is_heap(i72, i72+6) == (std::is_heap_until(i72, i72+6) == i72+6));
+ assert(std::is_heap(i73, i73+6) == (std::is_heap_until(i73, i73+6) == i73+6));
+ assert(std::is_heap(i74, i74+6) == (std::is_heap_until(i74, i74+6) == i74+6));
+ assert(std::is_heap(i75, i75+6) == (std::is_heap_until(i75, i75+6) == i75+6));
+ assert(std::is_heap(i76, i76+6) == (std::is_heap_until(i76, i76+6) == i76+6));
+ assert(std::is_heap(i77, i77+6) == (std::is_heap_until(i77, i77+6) == i77+6));
+ assert(std::is_heap(i78, i78+6) == (std::is_heap_until(i78, i78+6) == i78+6));
+ assert(std::is_heap(i79, i79+6) == (std::is_heap_until(i79, i79+6) == i79+6));
+ assert(std::is_heap(i80, i80+6) == (std::is_heap_until(i80, i80+6) == i80+6));
+ assert(std::is_heap(i81, i81+6) == (std::is_heap_until(i81, i81+6) == i81+6));
+ assert(std::is_heap(i82, i82+6) == (std::is_heap_until(i82, i82+6) == i82+6));
+ assert(std::is_heap(i83, i83+6) == (std::is_heap_until(i83, i83+6) == i83+6));
+ assert(std::is_heap(i84, i84+6) == (std::is_heap_until(i84, i84+6) == i84+6));
+ assert(std::is_heap(i85, i85+6) == (std::is_heap_until(i85, i85+6) == i85+6));
+ assert(std::is_heap(i86, i86+6) == (std::is_heap_until(i86, i86+6) == i86+6));
+ assert(std::is_heap(i87, i87+6) == (std::is_heap_until(i87, i87+6) == i87+6));
+ assert(std::is_heap(i88, i88+6) == (std::is_heap_until(i88, i88+6) == i88+6));
+ assert(std::is_heap(i89, i89+6) == (std::is_heap_until(i89, i89+6) == i89+6));
+ assert(std::is_heap(i90, i90+6) == (std::is_heap_until(i90, i90+6) == i90+6));
+ assert(std::is_heap(i91, i91+6) == (std::is_heap_until(i91, i91+6) == i91+6));
+ assert(std::is_heap(i92, i92+6) == (std::is_heap_until(i92, i92+6) == i92+6));
+ assert(std::is_heap(i93, i93+6) == (std::is_heap_until(i93, i93+6) == i93+6));
+ assert(std::is_heap(i94, i94+6) == (std::is_heap_until(i94, i94+6) == i94+6));
+ assert(std::is_heap(i95, i95+6) == (std::is_heap_until(i95, i95+6) == i95+6));
+ assert(std::is_heap(i96, i96+6) == (std::is_heap_until(i96, i96+6) == i96+6));
+ assert(std::is_heap(i97, i97+6) == (std::is_heap_until(i97, i97+6) == i97+6));
+ assert(std::is_heap(i98, i98+6) == (std::is_heap_until(i98, i98+6) == i98+6));
+ assert(std::is_heap(i99, i99+6) == (std::is_heap_until(i99, i99+6) == i99+6));
+ assert(std::is_heap(i100, i100+6) == (std::is_heap_until(i100, i100+6) == i100+6));
+ assert(std::is_heap(i101, i101+6) == (std::is_heap_until(i101, i101+6) == i101+6));
+ assert(std::is_heap(i102, i102+6) == (std::is_heap_until(i102, i102+6) == i102+6));
+ assert(std::is_heap(i103, i103+6) == (std::is_heap_until(i103, i103+6) == i103+6));
+ assert(std::is_heap(i104, i104+6) == (std::is_heap_until(i104, i104+6) == i104+6));
+ assert(std::is_heap(i105, i105+6) == (std::is_heap_until(i105, i105+6) == i105+6));
+ assert(std::is_heap(i106, i106+6) == (std::is_heap_until(i106, i106+6) == i106+6));
+ assert(std::is_heap(i107, i107+6) == (std::is_heap_until(i107, i107+6) == i107+6));
+ assert(std::is_heap(i108, i108+6) == (std::is_heap_until(i108, i108+6) == i108+6));
+ assert(std::is_heap(i109, i109+6) == (std::is_heap_until(i109, i109+6) == i109+6));
+ assert(std::is_heap(i110, i110+6) == (std::is_heap_until(i110, i110+6) == i110+6));
+ assert(std::is_heap(i111, i111+6) == (std::is_heap_until(i111, i111+6) == i111+6));
+ assert(std::is_heap(i112, i112+6) == (std::is_heap_until(i112, i112+6) == i112+6));
+ assert(std::is_heap(i113, i113+6) == (std::is_heap_until(i113, i113+6) == i113+6));
+ assert(std::is_heap(i114, i114+6) == (std::is_heap_until(i114, i114+6) == i114+6));
+ assert(std::is_heap(i115, i115+6) == (std::is_heap_until(i115, i115+6) == i115+6));
+ assert(std::is_heap(i116, i116+6) == (std::is_heap_until(i116, i116+6) == i116+6));
+ assert(std::is_heap(i117, i117+6) == (std::is_heap_until(i117, i117+6) == i117+6));
+ assert(std::is_heap(i118, i118+6) == (std::is_heap_until(i118, i118+6) == i118+6));
+ assert(std::is_heap(i119, i119+6) == (std::is_heap_until(i119, i119+6) == i119+6));
+ int i120[] = {0, 0, 0, 0, 0, 0, 0};
+ int i121[] = {0, 0, 0, 0, 0, 0, 1};
+ int i122[] = {0, 0, 0, 0, 0, 1, 0};
+ int i123[] = {0, 0, 0, 0, 0, 1, 1};
+ int i124[] = {0, 0, 0, 0, 1, 0, 0};
+ int i125[] = {0, 0, 0, 0, 1, 0, 1};
+ int i126[] = {0, 0, 0, 0, 1, 1, 0};
+ int i127[] = {0, 0, 0, 0, 1, 1, 1};
+ int i128[] = {0, 0, 0, 1, 0, 0, 0};
+ int i129[] = {0, 0, 0, 1, 0, 0, 1};
+ int i130[] = {0, 0, 0, 1, 0, 1, 0};
+ int i131[] = {0, 0, 0, 1, 0, 1, 1};
+ int i132[] = {0, 0, 0, 1, 1, 0, 0};
+ int i133[] = {0, 0, 0, 1, 1, 0, 1};
+ int i134[] = {0, 0, 0, 1, 1, 1, 0};
+ int i135[] = {0, 0, 0, 1, 1, 1, 1};
+ int i136[] = {0, 0, 1, 0, 0, 0, 0};
+ int i137[] = {0, 0, 1, 0, 0, 0, 1};
+ int i138[] = {0, 0, 1, 0, 0, 1, 0};
+ int i139[] = {0, 0, 1, 0, 0, 1, 1};
+ int i140[] = {0, 0, 1, 0, 1, 0, 0};
+ int i141[] = {0, 0, 1, 0, 1, 0, 1};
+ int i142[] = {0, 0, 1, 0, 1, 1, 0};
+ int i143[] = {0, 0, 1, 0, 1, 1, 1};
+ int i144[] = {0, 0, 1, 1, 0, 0, 0};
+ int i145[] = {0, 0, 1, 1, 0, 0, 1};
+ int i146[] = {0, 0, 1, 1, 0, 1, 0};
+ int i147[] = {0, 0, 1, 1, 0, 1, 1};
+ int i148[] = {0, 0, 1, 1, 1, 0, 0};
+ int i149[] = {0, 0, 1, 1, 1, 0, 1};
+ int i150[] = {0, 0, 1, 1, 1, 1, 0};
+ int i151[] = {0, 0, 1, 1, 1, 1, 1};
+ int i152[] = {0, 1, 0, 0, 0, 0, 0};
+ int i153[] = {0, 1, 0, 0, 0, 0, 1};
+ int i154[] = {0, 1, 0, 0, 0, 1, 0};
+ int i155[] = {0, 1, 0, 0, 0, 1, 1};
+ int i156[] = {0, 1, 0, 0, 1, 0, 0};
+ int i157[] = {0, 1, 0, 0, 1, 0, 1};
+ int i158[] = {0, 1, 0, 0, 1, 1, 0};
+ int i159[] = {0, 1, 0, 0, 1, 1, 1};
+ int i160[] = {0, 1, 0, 1, 0, 0, 0};
+ int i161[] = {0, 1, 0, 1, 0, 0, 1};
+ int i162[] = {0, 1, 0, 1, 0, 1, 0};
+ int i163[] = {0, 1, 0, 1, 0, 1, 1};
+ int i164[] = {0, 1, 0, 1, 1, 0, 0};
+ int i165[] = {0, 1, 0, 1, 1, 0, 1};
+ int i166[] = {0, 1, 0, 1, 1, 1, 0};
+ int i167[] = {0, 1, 0, 1, 1, 1, 1};
+ int i168[] = {0, 1, 1, 0, 0, 0, 0};
+ int i169[] = {0, 1, 1, 0, 0, 0, 1};
+ int i170[] = {0, 1, 1, 0, 0, 1, 0};
+ int i171[] = {0, 1, 1, 0, 0, 1, 1};
+ int i172[] = {0, 1, 1, 0, 1, 0, 0};
+ int i173[] = {0, 1, 1, 0, 1, 0, 1};
+ int i174[] = {0, 1, 1, 0, 1, 1, 0};
+ int i175[] = {0, 1, 1, 0, 1, 1, 1};
+ int i176[] = {0, 1, 1, 1, 0, 0, 0};
+ int i177[] = {0, 1, 1, 1, 0, 0, 1};
+ int i178[] = {0, 1, 1, 1, 0, 1, 0};
+ int i179[] = {0, 1, 1, 1, 0, 1, 1};
+ int i180[] = {0, 1, 1, 1, 1, 0, 0};
+ int i181[] = {0, 1, 1, 1, 1, 0, 1};
+ int i182[] = {0, 1, 1, 1, 1, 1, 0};
+ int i183[] = {0, 1, 1, 1, 1, 1, 1};
+ int i184[] = {1, 0, 0, 0, 0, 0, 0};
+ int i185[] = {1, 0, 0, 0, 0, 0, 1};
+ int i186[] = {1, 0, 0, 0, 0, 1, 0};
+ int i187[] = {1, 0, 0, 0, 0, 1, 1};
+ int i188[] = {1, 0, 0, 0, 1, 0, 0};
+ int i189[] = {1, 0, 0, 0, 1, 0, 1};
+ int i190[] = {1, 0, 0, 0, 1, 1, 0};
+ int i191[] = {1, 0, 0, 0, 1, 1, 1};
+ int i192[] = {1, 0, 0, 1, 0, 0, 0};
+ int i193[] = {1, 0, 0, 1, 0, 0, 1};
+ int i194[] = {1, 0, 0, 1, 0, 1, 0};
+ int i195[] = {1, 0, 0, 1, 0, 1, 1};
+ int i196[] = {1, 0, 0, 1, 1, 0, 0};
+ int i197[] = {1, 0, 0, 1, 1, 0, 1};
+ int i198[] = {1, 0, 0, 1, 1, 1, 0};
+ int i199[] = {1, 0, 0, 1, 1, 1, 1};
+ int i200[] = {1, 0, 1, 0, 0, 0, 0};
+ int i201[] = {1, 0, 1, 0, 0, 0, 1};
+ int i202[] = {1, 0, 1, 0, 0, 1, 0};
+ int i203[] = {1, 0, 1, 0, 0, 1, 1};
+ int i204[] = {1, 0, 1, 0, 1, 0, 0};
+ int i205[] = {1, 0, 1, 0, 1, 0, 1};
+ int i206[] = {1, 0, 1, 0, 1, 1, 0};
+ int i207[] = {1, 0, 1, 0, 1, 1, 1};
+ int i208[] = {1, 0, 1, 1, 0, 0, 0};
+ int i209[] = {1, 0, 1, 1, 0, 0, 1};
+ int i210[] = {1, 0, 1, 1, 0, 1, 0};
+ int i211[] = {1, 0, 1, 1, 0, 1, 1};
+ int i212[] = {1, 0, 1, 1, 1, 0, 0};
+ int i213[] = {1, 0, 1, 1, 1, 0, 1};
+ int i214[] = {1, 0, 1, 1, 1, 1, 0};
+ int i215[] = {1, 0, 1, 1, 1, 1, 1};
+ int i216[] = {1, 1, 0, 0, 0, 0, 0};
+ int i217[] = {1, 1, 0, 0, 0, 0, 1};
+ int i218[] = {1, 1, 0, 0, 0, 1, 0};
+ int i219[] = {1, 1, 0, 0, 0, 1, 1};
+ int i220[] = {1, 1, 0, 0, 1, 0, 0};
+ int i221[] = {1, 1, 0, 0, 1, 0, 1};
+ int i222[] = {1, 1, 0, 0, 1, 1, 0};
+ int i223[] = {1, 1, 0, 0, 1, 1, 1};
+ int i224[] = {1, 1, 0, 1, 0, 0, 0};
+ int i225[] = {1, 1, 0, 1, 0, 0, 1};
+ int i226[] = {1, 1, 0, 1, 0, 1, 0};
+ int i227[] = {1, 1, 0, 1, 0, 1, 1};
+ int i228[] = {1, 1, 0, 1, 1, 0, 0};
+ int i229[] = {1, 1, 0, 1, 1, 0, 1};
+ int i230[] = {1, 1, 0, 1, 1, 1, 0};
+ int i231[] = {1, 1, 0, 1, 1, 1, 1};
+ int i232[] = {1, 1, 1, 0, 0, 0, 0};
+ int i233[] = {1, 1, 1, 0, 0, 0, 1};
+ int i234[] = {1, 1, 1, 0, 0, 1, 0};
+ int i235[] = {1, 1, 1, 0, 0, 1, 1};
+ int i236[] = {1, 1, 1, 0, 1, 0, 0};
+ int i237[] = {1, 1, 1, 0, 1, 0, 1};
+ int i238[] = {1, 1, 1, 0, 1, 1, 0};
+ int i239[] = {1, 1, 1, 0, 1, 1, 1};
+ int i240[] = {1, 1, 1, 1, 0, 0, 0};
+ int i241[] = {1, 1, 1, 1, 0, 0, 1};
+ int i242[] = {1, 1, 1, 1, 0, 1, 0};
+ int i243[] = {1, 1, 1, 1, 0, 1, 1};
+ int i244[] = {1, 1, 1, 1, 1, 0, 0};
+ int i245[] = {1, 1, 1, 1, 1, 0, 1};
+ int i246[] = {1, 1, 1, 1, 1, 1, 0};
+ assert(std::is_heap(i120, i120+7) == (std::is_heap_until(i120, i120+7) == i120+7));
+ assert(std::is_heap(i121, i121+7) == (std::is_heap_until(i121, i121+7) == i121+7));
+ assert(std::is_heap(i122, i122+7) == (std::is_heap_until(i122, i122+7) == i122+7));
+ assert(std::is_heap(i123, i123+7) == (std::is_heap_until(i123, i123+7) == i123+7));
+ assert(std::is_heap(i124, i124+7) == (std::is_heap_until(i124, i124+7) == i124+7));
+ assert(std::is_heap(i125, i125+7) == (std::is_heap_until(i125, i125+7) == i125+7));
+ assert(std::is_heap(i126, i126+7) == (std::is_heap_until(i126, i126+7) == i126+7));
+ assert(std::is_heap(i127, i127+7) == (std::is_heap_until(i127, i127+7) == i127+7));
+ assert(std::is_heap(i128, i128+7) == (std::is_heap_until(i128, i128+7) == i128+7));
+ assert(std::is_heap(i129, i129+7) == (std::is_heap_until(i129, i129+7) == i129+7));
+ assert(std::is_heap(i130, i130+7) == (std::is_heap_until(i130, i130+7) == i130+7));
+ assert(std::is_heap(i131, i131+7) == (std::is_heap_until(i131, i131+7) == i131+7));
+ assert(std::is_heap(i132, i132+7) == (std::is_heap_until(i132, i132+7) == i132+7));
+ assert(std::is_heap(i133, i133+7) == (std::is_heap_until(i133, i133+7) == i133+7));
+ assert(std::is_heap(i134, i134+7) == (std::is_heap_until(i134, i134+7) == i134+7));
+ assert(std::is_heap(i135, i135+7) == (std::is_heap_until(i135, i135+7) == i135+7));
+ assert(std::is_heap(i136, i136+7) == (std::is_heap_until(i136, i136+7) == i136+7));
+ assert(std::is_heap(i137, i137+7) == (std::is_heap_until(i137, i137+7) == i137+7));
+ assert(std::is_heap(i138, i138+7) == (std::is_heap_until(i138, i138+7) == i138+7));
+ assert(std::is_heap(i139, i139+7) == (std::is_heap_until(i139, i139+7) == i139+7));
+ assert(std::is_heap(i140, i140+7) == (std::is_heap_until(i140, i140+7) == i140+7));
+ assert(std::is_heap(i141, i141+7) == (std::is_heap_until(i141, i141+7) == i141+7));
+ assert(std::is_heap(i142, i142+7) == (std::is_heap_until(i142, i142+7) == i142+7));
+ assert(std::is_heap(i143, i143+7) == (std::is_heap_until(i143, i143+7) == i143+7));
+ assert(std::is_heap(i144, i144+7) == (std::is_heap_until(i144, i144+7) == i144+7));
+ assert(std::is_heap(i145, i145+7) == (std::is_heap_until(i145, i145+7) == i145+7));
+ assert(std::is_heap(i146, i146+7) == (std::is_heap_until(i146, i146+7) == i146+7));
+ assert(std::is_heap(i147, i147+7) == (std::is_heap_until(i147, i147+7) == i147+7));
+ assert(std::is_heap(i148, i148+7) == (std::is_heap_until(i148, i148+7) == i148+7));
+ assert(std::is_heap(i149, i149+7) == (std::is_heap_until(i149, i149+7) == i149+7));
+ assert(std::is_heap(i150, i150+7) == (std::is_heap_until(i150, i150+7) == i150+7));
+ assert(std::is_heap(i151, i151+7) == (std::is_heap_until(i151, i151+7) == i151+7));
+ assert(std::is_heap(i152, i152+7) == (std::is_heap_until(i152, i152+7) == i152+7));
+ assert(std::is_heap(i153, i153+7) == (std::is_heap_until(i153, i153+7) == i153+7));
+ assert(std::is_heap(i154, i154+7) == (std::is_heap_until(i154, i154+7) == i154+7));
+ assert(std::is_heap(i155, i155+7) == (std::is_heap_until(i155, i155+7) == i155+7));
+ assert(std::is_heap(i156, i156+7) == (std::is_heap_until(i156, i156+7) == i156+7));
+ assert(std::is_heap(i157, i157+7) == (std::is_heap_until(i157, i157+7) == i157+7));
+ assert(std::is_heap(i158, i158+7) == (std::is_heap_until(i158, i158+7) == i158+7));
+ assert(std::is_heap(i159, i159+7) == (std::is_heap_until(i159, i159+7) == i159+7));
+ assert(std::is_heap(i160, i160+7) == (std::is_heap_until(i160, i160+7) == i160+7));
+ assert(std::is_heap(i161, i161+7) == (std::is_heap_until(i161, i161+7) == i161+7));
+ assert(std::is_heap(i162, i162+7) == (std::is_heap_until(i162, i162+7) == i162+7));
+ assert(std::is_heap(i163, i163+7) == (std::is_heap_until(i163, i163+7) == i163+7));
+ assert(std::is_heap(i164, i164+7) == (std::is_heap_until(i164, i164+7) == i164+7));
+ assert(std::is_heap(i165, i165+7) == (std::is_heap_until(i165, i165+7) == i165+7));
+ assert(std::is_heap(i166, i166+7) == (std::is_heap_until(i166, i166+7) == i166+7));
+ assert(std::is_heap(i167, i167+7) == (std::is_heap_until(i167, i167+7) == i167+7));
+ assert(std::is_heap(i168, i168+7) == (std::is_heap_until(i168, i168+7) == i168+7));
+ assert(std::is_heap(i169, i169+7) == (std::is_heap_until(i169, i169+7) == i169+7));
+ assert(std::is_heap(i170, i170+7) == (std::is_heap_until(i170, i170+7) == i170+7));
+ assert(std::is_heap(i171, i171+7) == (std::is_heap_until(i171, i171+7) == i171+7));
+ assert(std::is_heap(i172, i172+7) == (std::is_heap_until(i172, i172+7) == i172+7));
+ assert(std::is_heap(i173, i173+7) == (std::is_heap_until(i173, i173+7) == i173+7));
+ assert(std::is_heap(i174, i174+7) == (std::is_heap_until(i174, i174+7) == i174+7));
+ assert(std::is_heap(i175, i175+7) == (std::is_heap_until(i175, i175+7) == i175+7));
+ assert(std::is_heap(i176, i176+7) == (std::is_heap_until(i176, i176+7) == i176+7));
+ assert(std::is_heap(i177, i177+7) == (std::is_heap_until(i177, i177+7) == i177+7));
+ assert(std::is_heap(i178, i178+7) == (std::is_heap_until(i178, i178+7) == i178+7));
+ assert(std::is_heap(i179, i179+7) == (std::is_heap_until(i179, i179+7) == i179+7));
+ assert(std::is_heap(i180, i180+7) == (std::is_heap_until(i180, i180+7) == i180+7));
+ assert(std::is_heap(i181, i181+7) == (std::is_heap_until(i181, i181+7) == i181+7));
+ assert(std::is_heap(i182, i182+7) == (std::is_heap_until(i182, i182+7) == i182+7));
+ assert(std::is_heap(i183, i183+7) == (std::is_heap_until(i183, i183+7) == i183+7));
+ assert(std::is_heap(i184, i184+7) == (std::is_heap_until(i184, i184+7) == i184+7));
+ assert(std::is_heap(i185, i185+7) == (std::is_heap_until(i185, i185+7) == i185+7));
+ assert(std::is_heap(i186, i186+7) == (std::is_heap_until(i186, i186+7) == i186+7));
+ assert(std::is_heap(i187, i187+7) == (std::is_heap_until(i187, i187+7) == i187+7));
+ assert(std::is_heap(i188, i188+7) == (std::is_heap_until(i188, i188+7) == i188+7));
+ assert(std::is_heap(i189, i189+7) == (std::is_heap_until(i189, i189+7) == i189+7));
+ assert(std::is_heap(i190, i190+7) == (std::is_heap_until(i190, i190+7) == i190+7));
+ assert(std::is_heap(i191, i191+7) == (std::is_heap_until(i191, i191+7) == i191+7));
+ assert(std::is_heap(i192, i192+7) == (std::is_heap_until(i192, i192+7) == i192+7));
+ assert(std::is_heap(i193, i193+7) == (std::is_heap_until(i193, i193+7) == i193+7));
+ assert(std::is_heap(i194, i194+7) == (std::is_heap_until(i194, i194+7) == i194+7));
+ assert(std::is_heap(i195, i195+7) == (std::is_heap_until(i195, i195+7) == i195+7));
+ assert(std::is_heap(i196, i196+7) == (std::is_heap_until(i196, i196+7) == i196+7));
+ assert(std::is_heap(i197, i197+7) == (std::is_heap_until(i197, i197+7) == i197+7));
+ assert(std::is_heap(i198, i198+7) == (std::is_heap_until(i198, i198+7) == i198+7));
+ assert(std::is_heap(i199, i199+7) == (std::is_heap_until(i199, i199+7) == i199+7));
+ assert(std::is_heap(i200, i200+7) == (std::is_heap_until(i200, i200+7) == i200+7));
+ assert(std::is_heap(i201, i201+7) == (std::is_heap_until(i201, i201+7) == i201+7));
+ assert(std::is_heap(i202, i202+7) == (std::is_heap_until(i202, i202+7) == i202+7));
+ assert(std::is_heap(i203, i203+7) == (std::is_heap_until(i203, i203+7) == i203+7));
+ assert(std::is_heap(i204, i204+7) == (std::is_heap_until(i204, i204+7) == i204+7));
+ assert(std::is_heap(i205, i205+7) == (std::is_heap_until(i205, i205+7) == i205+7));
+ assert(std::is_heap(i206, i206+7) == (std::is_heap_until(i206, i206+7) == i206+7));
+ assert(std::is_heap(i207, i207+7) == (std::is_heap_until(i207, i207+7) == i207+7));
+ assert(std::is_heap(i208, i208+7) == (std::is_heap_until(i208, i208+7) == i208+7));
+ assert(std::is_heap(i209, i209+7) == (std::is_heap_until(i209, i209+7) == i209+7));
+ assert(std::is_heap(i210, i210+7) == (std::is_heap_until(i210, i210+7) == i210+7));
+ assert(std::is_heap(i211, i211+7) == (std::is_heap_until(i211, i211+7) == i211+7));
+ assert(std::is_heap(i212, i212+7) == (std::is_heap_until(i212, i212+7) == i212+7));
+ assert(std::is_heap(i213, i213+7) == (std::is_heap_until(i213, i213+7) == i213+7));
+ assert(std::is_heap(i214, i214+7) == (std::is_heap_until(i214, i214+7) == i214+7));
+ assert(std::is_heap(i215, i215+7) == (std::is_heap_until(i215, i215+7) == i215+7));
+ assert(std::is_heap(i216, i216+7) == (std::is_heap_until(i216, i216+7) == i216+7));
+ assert(std::is_heap(i217, i217+7) == (std::is_heap_until(i217, i217+7) == i217+7));
+ assert(std::is_heap(i218, i218+7) == (std::is_heap_until(i218, i218+7) == i218+7));
+ assert(std::is_heap(i219, i219+7) == (std::is_heap_until(i219, i219+7) == i219+7));
+ assert(std::is_heap(i220, i220+7) == (std::is_heap_until(i220, i220+7) == i220+7));
+ assert(std::is_heap(i221, i221+7) == (std::is_heap_until(i221, i221+7) == i221+7));
+ assert(std::is_heap(i222, i222+7) == (std::is_heap_until(i222, i222+7) == i222+7));
+ assert(std::is_heap(i223, i223+7) == (std::is_heap_until(i223, i223+7) == i223+7));
+ assert(std::is_heap(i224, i224+7) == (std::is_heap_until(i224, i224+7) == i224+7));
+ assert(std::is_heap(i225, i225+7) == (std::is_heap_until(i225, i225+7) == i225+7));
+ assert(std::is_heap(i226, i226+7) == (std::is_heap_until(i226, i226+7) == i226+7));
+ assert(std::is_heap(i227, i227+7) == (std::is_heap_until(i227, i227+7) == i227+7));
+ assert(std::is_heap(i228, i228+7) == (std::is_heap_until(i228, i228+7) == i228+7));
+ assert(std::is_heap(i229, i229+7) == (std::is_heap_until(i229, i229+7) == i229+7));
+ assert(std::is_heap(i230, i230+7) == (std::is_heap_until(i230, i230+7) == i230+7));
+ assert(std::is_heap(i231, i231+7) == (std::is_heap_until(i231, i231+7) == i231+7));
+ assert(std::is_heap(i232, i232+7) == (std::is_heap_until(i232, i232+7) == i232+7));
+ assert(std::is_heap(i233, i233+7) == (std::is_heap_until(i233, i233+7) == i233+7));
+ assert(std::is_heap(i234, i234+7) == (std::is_heap_until(i234, i234+7) == i234+7));
+ assert(std::is_heap(i235, i235+7) == (std::is_heap_until(i235, i235+7) == i235+7));
+ assert(std::is_heap(i236, i236+7) == (std::is_heap_until(i236, i236+7) == i236+7));
+ assert(std::is_heap(i237, i237+7) == (std::is_heap_until(i237, i237+7) == i237+7));
+ assert(std::is_heap(i238, i238+7) == (std::is_heap_until(i238, i238+7) == i238+7));
+ assert(std::is_heap(i239, i239+7) == (std::is_heap_until(i239, i239+7) == i239+7));
+ assert(std::is_heap(i240, i240+7) == (std::is_heap_until(i240, i240+7) == i240+7));
+ assert(std::is_heap(i241, i241+7) == (std::is_heap_until(i241, i241+7) == i241+7));
+ assert(std::is_heap(i242, i242+7) == (std::is_heap_until(i242, i242+7) == i242+7));
+ assert(std::is_heap(i243, i243+7) == (std::is_heap_until(i243, i243+7) == i243+7));
+ assert(std::is_heap(i244, i244+7) == (std::is_heap_until(i244, i244+7) == i244+7));
+ assert(std::is_heap(i245, i245+7) == (std::is_heap_until(i245, i245+7) == i245+7));
+ assert(std::is_heap(i246, i246+7) == (std::is_heap_until(i246, i246+7) == i246+7));
+}
+
+int main()
+{
+ test();
+}
diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.heap.operations/is.heap/is_heap_comp.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.heap.operations/is.heap/is_heap_comp.pass.cpp
new file mode 100644
index 00000000000..af55cc499ed
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.sorting/alg.heap.operations/is.heap/is_heap_comp.pass.cpp
@@ -0,0 +1,522 @@
+//===----------------------------------------------------------------------===//
+//
+// 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<RandomAccessIterator Iter>
+// requires LessThanComparable<Iter::value_type>
+// bool
+// is_heap(Iter first, Iter last);
+
+#include <algorithm>
+#include <functional>
+#include <cassert>
+
+void test()
+{
+ int i1[] = {0, 0};
+ assert(std::is_heap(i1, i1, std::greater<int>()));
+ assert(std::is_heap(i1, i1+1, std::greater<int>()) == (std::is_heap_until(i1, i1+1, std::greater<int>()) == i1+1));
+ int i2[] = {0, 1};
+ int i3[] = {1, 0};
+ assert(std::is_heap(i1, i1+2, std::greater<int>()) == (std::is_heap_until(i1, i1+2, std::greater<int>()) == i1+2));
+ assert(std::is_heap(i2, i2+2, std::greater<int>()) == (std::is_heap_until(i2, i2+2, std::greater<int>()) == i2+2));
+ assert(std::is_heap(i3, i3+2, std::greater<int>()) == (std::is_heap_until(i3, i3+2, std::greater<int>()) == i3+2));
+ int i4[] = {0, 0, 0};
+ int i5[] = {0, 0, 1};
+ int i6[] = {0, 1, 0};
+ int i7[] = {0, 1, 1};
+ int i8[] = {1, 0, 0};
+ int i9[] = {1, 0, 1};
+ int i10[] = {1, 1, 0};
+ assert(std::is_heap(i4, i4+3, std::greater<int>()) == (std::is_heap_until(i4, i4+3, std::greater<int>()) == i4+3));
+ assert(std::is_heap(i5, i5+3, std::greater<int>()) == (std::is_heap_until(i5, i5+3, std::greater<int>()) == i5+3));
+ assert(std::is_heap(i6, i6+3, std::greater<int>()) == (std::is_heap_until(i6, i6+3, std::greater<int>()) == i6+3));
+ assert(std::is_heap(i7, i7+3, std::greater<int>()) == (std::is_heap_until(i7, i7+3, std::greater<int>()) == i7+3));
+ assert(std::is_heap(i8, i8+3, std::greater<int>()) == (std::is_heap_until(i8, i8+3, std::greater<int>()) == i8+3));
+ assert(std::is_heap(i9, i9+3, std::greater<int>()) == (std::is_heap_until(i9, i9+3, std::greater<int>()) == i9+3));
+ assert(std::is_heap(i10, i10+3, std::greater<int>()) == (std::is_heap_until(i10, i10+3, std::greater<int>()) == i10+3));
+ int i11[] = {0, 0, 0, 0};
+ int i12[] = {0, 0, 0, 1};
+ int i13[] = {0, 0, 1, 0};
+ int i14[] = {0, 0, 1, 1};
+ int i15[] = {0, 1, 0, 0};
+ int i16[] = {0, 1, 0, 1};
+ int i17[] = {0, 1, 1, 0};
+ int i18[] = {0, 1, 1, 1};
+ int i19[] = {1, 0, 0, 0};
+ int i20[] = {1, 0, 0, 1};
+ int i21[] = {1, 0, 1, 0};
+ int i22[] = {1, 0, 1, 1};
+ int i23[] = {1, 1, 0, 0};
+ int i24[] = {1, 1, 0, 1};
+ int i25[] = {1, 1, 1, 0};
+ assert(std::is_heap(i11, i11+4, std::greater<int>()) == (std::is_heap_until(i11, i11+4, std::greater<int>()) == i11+4));
+ assert(std::is_heap(i12, i12+4, std::greater<int>()) == (std::is_heap_until(i12, i12+4, std::greater<int>()) == i12+4));
+ assert(std::is_heap(i13, i13+4, std::greater<int>()) == (std::is_heap_until(i13, i13+4, std::greater<int>()) == i13+4));
+ assert(std::is_heap(i14, i14+4, std::greater<int>()) == (std::is_heap_until(i14, i14+4, std::greater<int>()) == i14+4));
+ assert(std::is_heap(i15, i15+4, std::greater<int>()) == (std::is_heap_until(i15, i15+4, std::greater<int>()) == i15+4));
+ assert(std::is_heap(i16, i16+4, std::greater<int>()) == (std::is_heap_until(i16, i16+4, std::greater<int>()) == i16+4));
+ assert(std::is_heap(i17, i17+4, std::greater<int>()) == (std::is_heap_until(i17, i17+4, std::greater<int>()) == i17+4));
+ assert(std::is_heap(i18, i18+4, std::greater<int>()) == (std::is_heap_until(i18, i18+4, std::greater<int>()) == i18+4));
+ assert(std::is_heap(i19, i19+4, std::greater<int>()) == (std::is_heap_until(i19, i19+4, std::greater<int>()) == i19+4));
+ assert(std::is_heap(i20, i20+4, std::greater<int>()) == (std::is_heap_until(i20, i20+4, std::greater<int>()) == i20+4));
+ assert(std::is_heap(i21, i21+4, std::greater<int>()) == (std::is_heap_until(i21, i21+4, std::greater<int>()) == i21+4));
+ assert(std::is_heap(i22, i22+4, std::greater<int>()) == (std::is_heap_until(i22, i22+4, std::greater<int>()) == i22+4));
+ assert(std::is_heap(i23, i23+4, std::greater<int>()) == (std::is_heap_until(i23, i23+4, std::greater<int>()) == i23+4));
+ assert(std::is_heap(i24, i24+4, std::greater<int>()) == (std::is_heap_until(i24, i24+4, std::greater<int>()) == i24+4));
+ assert(std::is_heap(i25, i25+4, std::greater<int>()) == (std::is_heap_until(i25, i25+4, std::greater<int>()) == i25+4));
+ int i26[] = {0, 0, 0, 0, 0};
+ int i27[] = {0, 0, 0, 0, 1};
+ int i28[] = {0, 0, 0, 1, 0};
+ int i29[] = {0, 0, 0, 1, 1};
+ int i30[] = {0, 0, 1, 0, 0};
+ int i31[] = {0, 0, 1, 0, 1};
+ int i32[] = {0, 0, 1, 1, 0};
+ int i33[] = {0, 0, 1, 1, 1};
+ int i34[] = {0, 1, 0, 0, 0};
+ int i35[] = {0, 1, 0, 0, 1};
+ int i36[] = {0, 1, 0, 1, 0};
+ int i37[] = {0, 1, 0, 1, 1};
+ int i38[] = {0, 1, 1, 0, 0};
+ int i39[] = {0, 1, 1, 0, 1};
+ int i40[] = {0, 1, 1, 1, 0};
+ int i41[] = {0, 1, 1, 1, 1};
+ int i42[] = {1, 0, 0, 0, 0};
+ int i43[] = {1, 0, 0, 0, 1};
+ int i44[] = {1, 0, 0, 1, 0};
+ int i45[] = {1, 0, 0, 1, 1};
+ int i46[] = {1, 0, 1, 0, 0};
+ int i47[] = {1, 0, 1, 0, 1};
+ int i48[] = {1, 0, 1, 1, 0};
+ int i49[] = {1, 0, 1, 1, 1};
+ int i50[] = {1, 1, 0, 0, 0};
+ int i51[] = {1, 1, 0, 0, 1};
+ int i52[] = {1, 1, 0, 1, 0};
+ int i53[] = {1, 1, 0, 1, 1};
+ int i54[] = {1, 1, 1, 0, 0};
+ int i55[] = {1, 1, 1, 0, 1};
+ int i56[] = {1, 1, 1, 1, 0};
+ assert(std::is_heap(i26, i26+5, std::greater<int>()) == (std::is_heap_until(i26, i26+5, std::greater<int>()) == i26+5));
+ assert(std::is_heap(i27, i27+5, std::greater<int>()) == (std::is_heap_until(i27, i27+5, std::greater<int>()) == i27+5));
+ assert(std::is_heap(i28, i28+5, std::greater<int>()) == (std::is_heap_until(i28, i28+5, std::greater<int>()) == i28+5));
+ assert(std::is_heap(i29, i29+5, std::greater<int>()) == (std::is_heap_until(i29, i29+5, std::greater<int>()) == i29+5));
+ assert(std::is_heap(i30, i30+5, std::greater<int>()) == (std::is_heap_until(i30, i30+5, std::greater<int>()) == i30+5));
+ assert(std::is_heap(i31, i31+5, std::greater<int>()) == (std::is_heap_until(i31, i31+5, std::greater<int>()) == i31+5));
+ assert(std::is_heap(i32, i32+5, std::greater<int>()) == (std::is_heap_until(i32, i32+5, std::greater<int>()) == i32+5));
+ assert(std::is_heap(i33, i33+5, std::greater<int>()) == (std::is_heap_until(i33, i33+5, std::greater<int>()) == i33+5));
+ assert(std::is_heap(i34, i34+5, std::greater<int>()) == (std::is_heap_until(i34, i34+5, std::greater<int>()) == i34+5));
+ assert(std::is_heap(i35, i35+5, std::greater<int>()) == (std::is_heap_until(i35, i35+5, std::greater<int>()) == i35+5));
+ assert(std::is_heap(i36, i36+5, std::greater<int>()) == (std::is_heap_until(i36, i36+5, std::greater<int>()) == i36+5));
+ assert(std::is_heap(i37, i37+5, std::greater<int>()) == (std::is_heap_until(i37, i37+5, std::greater<int>()) == i37+5));
+ assert(std::is_heap(i38, i38+5, std::greater<int>()) == (std::is_heap_until(i38, i38+5, std::greater<int>()) == i38+5));
+ assert(std::is_heap(i39, i39+5, std::greater<int>()) == (std::is_heap_until(i39, i39+5, std::greater<int>()) == i39+5));
+ assert(std::is_heap(i40, i40+5, std::greater<int>()) == (std::is_heap_until(i40, i40+5, std::greater<int>()) == i40+5));
+ assert(std::is_heap(i41, i41+5, std::greater<int>()) == (std::is_heap_until(i41, i41+5, std::greater<int>()) == i41+5));
+ assert(std::is_heap(i42, i42+5, std::greater<int>()) == (std::is_heap_until(i42, i42+5, std::greater<int>()) == i42+5));
+ assert(std::is_heap(i43, i43+5, std::greater<int>()) == (std::is_heap_until(i43, i43+5, std::greater<int>()) == i43+5));
+ assert(std::is_heap(i44, i44+5, std::greater<int>()) == (std::is_heap_until(i44, i44+5, std::greater<int>()) == i44+5));
+ assert(std::is_heap(i45, i45+5, std::greater<int>()) == (std::is_heap_until(i45, i45+5, std::greater<int>()) == i45+5));
+ assert(std::is_heap(i46, i46+5, std::greater<int>()) == (std::is_heap_until(i46, i46+5, std::greater<int>()) == i46+5));
+ assert(std::is_heap(i47, i47+5, std::greater<int>()) == (std::is_heap_until(i47, i47+5, std::greater<int>()) == i47+5));
+ assert(std::is_heap(i48, i48+5, std::greater<int>()) == (std::is_heap_until(i48, i48+5, std::greater<int>()) == i48+5));
+ assert(std::is_heap(i49, i49+5, std::greater<int>()) == (std::is_heap_until(i49, i49+5, std::greater<int>()) == i49+5));
+ assert(std::is_heap(i50, i50+5, std::greater<int>()) == (std::is_heap_until(i50, i50+5, std::greater<int>()) == i50+5));
+ assert(std::is_heap(i51, i51+5, std::greater<int>()) == (std::is_heap_until(i51, i51+5, std::greater<int>()) == i51+5));
+ assert(std::is_heap(i52, i52+5, std::greater<int>()) == (std::is_heap_until(i52, i52+5, std::greater<int>()) == i52+5));
+ assert(std::is_heap(i53, i53+5, std::greater<int>()) == (std::is_heap_until(i53, i53+5, std::greater<int>()) == i53+5));
+ assert(std::is_heap(i54, i54+5, std::greater<int>()) == (std::is_heap_until(i54, i54+5, std::greater<int>()) == i54+5));
+ assert(std::is_heap(i55, i55+5, std::greater<int>()) == (std::is_heap_until(i55, i55+5, std::greater<int>()) == i55+5));
+ assert(std::is_heap(i56, i56+5, std::greater<int>()) == (std::is_heap_until(i56, i56+5, std::greater<int>()) == i56+5));
+ int i57[] = {0, 0, 0, 0, 0, 0};
+ int i58[] = {0, 0, 0, 0, 0, 1};
+ int i59[] = {0, 0, 0, 0, 1, 0};
+ int i60[] = {0, 0, 0, 0, 1, 1};
+ int i61[] = {0, 0, 0, 1, 0, 0};
+ int i62[] = {0, 0, 0, 1, 0, 1};
+ int i63[] = {0, 0, 0, 1, 1, 0};
+ int i64[] = {0, 0, 0, 1, 1, 1};
+ int i65[] = {0, 0, 1, 0, 0, 0};
+ int i66[] = {0, 0, 1, 0, 0, 1};
+ int i67[] = {0, 0, 1, 0, 1, 0};
+ int i68[] = {0, 0, 1, 0, 1, 1};
+ int i69[] = {0, 0, 1, 1, 0, 0};
+ int i70[] = {0, 0, 1, 1, 0, 1};
+ int i71[] = {0, 0, 1, 1, 1, 0};
+ int i72[] = {0, 0, 1, 1, 1, 1};
+ int i73[] = {0, 1, 0, 0, 0, 0};
+ int i74[] = {0, 1, 0, 0, 0, 1};
+ int i75[] = {0, 1, 0, 0, 1, 0};
+ int i76[] = {0, 1, 0, 0, 1, 1};
+ int i77[] = {0, 1, 0, 1, 0, 0};
+ int i78[] = {0, 1, 0, 1, 0, 1};
+ int i79[] = {0, 1, 0, 1, 1, 0};
+ int i80[] = {0, 1, 0, 1, 1, 1};
+ int i81[] = {0, 1, 1, 0, 0, 0};
+ int i82[] = {0, 1, 1, 0, 0, 1};
+ int i83[] = {0, 1, 1, 0, 1, 0};
+ int i84[] = {0, 1, 1, 0, 1, 1};
+ int i85[] = {0, 1, 1, 1, 0, 0};
+ int i86[] = {0, 1, 1, 1, 0, 1};
+ int i87[] = {0, 1, 1, 1, 1, 0};
+ int i88[] = {0, 1, 1, 1, 1, 1};
+ int i89[] = {1, 0, 0, 0, 0, 0};
+ int i90[] = {1, 0, 0, 0, 0, 1};
+ int i91[] = {1, 0, 0, 0, 1, 0};
+ int i92[] = {1, 0, 0, 0, 1, 1};
+ int i93[] = {1, 0, 0, 1, 0, 0};
+ int i94[] = {1, 0, 0, 1, 0, 1};
+ int i95[] = {1, 0, 0, 1, 1, 0};
+ int i96[] = {1, 0, 0, 1, 1, 1};
+ int i97[] = {1, 0, 1, 0, 0, 0};
+ int i98[] = {1, 0, 1, 0, 0, 1};
+ int i99[] = {1, 0, 1, 0, 1, 0};
+ int i100[] = {1, 0, 1, 0, 1, 1};
+ int i101[] = {1, 0, 1, 1, 0, 0};
+ int i102[] = {1, 0, 1, 1, 0, 1};
+ int i103[] = {1, 0, 1, 1, 1, 0};
+ int i104[] = {1, 0, 1, 1, 1, 1};
+ int i105[] = {1, 1, 0, 0, 0, 0};
+ int i106[] = {1, 1, 0, 0, 0, 1};
+ int i107[] = {1, 1, 0, 0, 1, 0};
+ int i108[] = {1, 1, 0, 0, 1, 1};
+ int i109[] = {1, 1, 0, 1, 0, 0};
+ int i110[] = {1, 1, 0, 1, 0, 1};
+ int i111[] = {1, 1, 0, 1, 1, 0};
+ int i112[] = {1, 1, 0, 1, 1, 1};
+ int i113[] = {1, 1, 1, 0, 0, 0};
+ int i114[] = {1, 1, 1, 0, 0, 1};
+ int i115[] = {1, 1, 1, 0, 1, 0};
+ int i116[] = {1, 1, 1, 0, 1, 1};
+ int i117[] = {1, 1, 1, 1, 0, 0};
+ int i118[] = {1, 1, 1, 1, 0, 1};
+ int i119[] = {1, 1, 1, 1, 1, 0};
+ assert(std::is_heap(i57, i57+6, std::greater<int>()) == (std::is_heap_until(i57, i57+6, std::greater<int>()) == i57+6));
+ assert(std::is_heap(i58, i58+6, std::greater<int>()) == (std::is_heap_until(i58, i58+6, std::greater<int>()) == i58+6));
+ assert(std::is_heap(i59, i59+6, std::greater<int>()) == (std::is_heap_until(i59, i59+6, std::greater<int>()) == i59+6));
+ assert(std::is_heap(i60, i60+6, std::greater<int>()) == (std::is_heap_until(i60, i60+6, std::greater<int>()) == i60+6));
+ assert(std::is_heap(i61, i61+6, std::greater<int>()) == (std::is_heap_until(i61, i61+6, std::greater<int>()) == i61+6));
+ assert(std::is_heap(i62, i62+6, std::greater<int>()) == (std::is_heap_until(i62, i62+6, std::greater<int>()) == i62+6));
+ assert(std::is_heap(i63, i63+6, std::greater<int>()) == (std::is_heap_until(i63, i63+6, std::greater<int>()) == i63+6));
+ assert(std::is_heap(i64, i64+6, std::greater<int>()) == (std::is_heap_until(i64, i64+6, std::greater<int>()) == i64+6));
+ assert(std::is_heap(i65, i65+6, std::greater<int>()) == (std::is_heap_until(i65, i65+6, std::greater<int>()) == i65+6));
+ assert(std::is_heap(i66, i66+6, std::greater<int>()) == (std::is_heap_until(i66, i66+6, std::greater<int>()) == i66+6));
+ assert(std::is_heap(i67, i67+6, std::greater<int>()) == (std::is_heap_until(i67, i67+6, std::greater<int>()) == i67+6));
+ assert(std::is_heap(i68, i68+6, std::greater<int>()) == (std::is_heap_until(i68, i68+6, std::greater<int>()) == i68+6));
+ assert(std::is_heap(i69, i69+6, std::greater<int>()) == (std::is_heap_until(i69, i69+6, std::greater<int>()) == i69+6));
+ assert(std::is_heap(i70, i70+6, std::greater<int>()) == (std::is_heap_until(i70, i70+6, std::greater<int>()) == i70+6));
+ assert(std::is_heap(i71, i71+6, std::greater<int>()) == (std::is_heap_until(i71, i71+6, std::greater<int>()) == i71+6));
+ assert(std::is_heap(i72, i72+6, std::greater<int>()) == (std::is_heap_until(i72, i72+6, std::greater<int>()) == i72+6));
+ assert(std::is_heap(i73, i73+6, std::greater<int>()) == (std::is_heap_until(i73, i73+6, std::greater<int>()) == i73+6));
+ assert(std::is_heap(i74, i74+6, std::greater<int>()) == (std::is_heap_until(i74, i74+6, std::greater<int>()) == i74+6));
+ assert(std::is_heap(i75, i75+6, std::greater<int>()) == (std::is_heap_until(i75, i75+6, std::greater<int>()) == i75+6));
+ assert(std::is_heap(i76, i76+6, std::greater<int>()) == (std::is_heap_until(i76, i76+6, std::greater<int>()) == i76+6));
+ assert(std::is_heap(i77, i77+6, std::greater<int>()) == (std::is_heap_until(i77, i77+6, std::greater<int>()) == i77+6));
+ assert(std::is_heap(i78, i78+6, std::greater<int>()) == (std::is_heap_until(i78, i78+6, std::greater<int>()) == i78+6));
+ assert(std::is_heap(i79, i79+6, std::greater<int>()) == (std::is_heap_until(i79, i79+6, std::greater<int>()) == i79+6));
+ assert(std::is_heap(i80, i80+6, std::greater<int>()) == (std::is_heap_until(i80, i80+6, std::greater<int>()) == i80+6));
+ assert(std::is_heap(i81, i81+6, std::greater<int>()) == (std::is_heap_until(i81, i81+6, std::greater<int>()) == i81+6));
+ assert(std::is_heap(i82, i82+6, std::greater<int>()) == (std::is_heap_until(i82, i82+6, std::greater<int>()) == i82+6));
+ assert(std::is_heap(i83, i83+6, std::greater<int>()) == (std::is_heap_until(i83, i83+6, std::greater<int>()) == i83+6));
+ assert(std::is_heap(i84, i84+6, std::greater<int>()) == (std::is_heap_until(i84, i84+6, std::greater<int>()) == i84+6));
+ assert(std::is_heap(i85, i85+6, std::greater<int>()) == (std::is_heap_until(i85, i85+6, std::greater<int>()) == i85+6));
+ assert(std::is_heap(i86, i86+6, std::greater<int>()) == (std::is_heap_until(i86, i86+6, std::greater<int>()) == i86+6));
+ assert(std::is_heap(i87, i87+6, std::greater<int>()) == (std::is_heap_until(i87, i87+6, std::greater<int>()) == i87+6));
+ assert(std::is_heap(i88, i88+6, std::greater<int>()) == (std::is_heap_until(i88, i88+6, std::greater<int>()) == i88+6));
+ assert(std::is_heap(i89, i89+6, std::greater<int>()) == (std::is_heap_until(i89, i89+6, std::greater<int>()) == i89+6));
+ assert(std::is_heap(i90, i90+6, std::greater<int>()) == (std::is_heap_until(i90, i90+6, std::greater<int>()) == i90+6));
+ assert(std::is_heap(i91, i91+6, std::greater<int>()) == (std::is_heap_until(i91, i91+6, std::greater<int>()) == i91+6));
+ assert(std::is_heap(i92, i92+6, std::greater<int>()) == (std::is_heap_until(i92, i92+6, std::greater<int>()) == i92+6));
+ assert(std::is_heap(i93, i93+6, std::greater<int>()) == (std::is_heap_until(i93, i93+6, std::greater<int>()) == i93+6));
+ assert(std::is_heap(i94, i94+6, std::greater<int>()) == (std::is_heap_until(i94, i94+6, std::greater<int>()) == i94+6));
+ assert(std::is_heap(i95, i95+6, std::greater<int>()) == (std::is_heap_until(i95, i95+6, std::greater<int>()) == i95+6));
+ assert(std::is_heap(i96, i96+6, std::greater<int>()) == (std::is_heap_until(i96, i96+6, std::greater<int>()) == i96+6));
+ assert(std::is_heap(i97, i97+6, std::greater<int>()) == (std::is_heap_until(i97, i97+6, std::greater<int>()) == i97+6));
+ assert(std::is_heap(i98, i98+6, std::greater<int>()) == (std::is_heap_until(i98, i98+6, std::greater<int>()) == i98+6));
+ assert(std::is_heap(i99, i99+6, std::greater<int>()) == (std::is_heap_until(i99, i99+6, std::greater<int>()) == i99+6));
+ assert(std::is_heap(i100, i100+6, std::greater<int>()) == (std::is_heap_until(i100, i100+6, std::greater<int>()) == i100+6));
+ assert(std::is_heap(i101, i101+6, std::greater<int>()) == (std::is_heap_until(i101, i101+6, std::greater<int>()) == i101+6));
+ assert(std::is_heap(i102, i102+6, std::greater<int>()) == (std::is_heap_until(i102, i102+6, std::greater<int>()) == i102+6));
+ assert(std::is_heap(i103, i103+6, std::greater<int>()) == (std::is_heap_until(i103, i103+6, std::greater<int>()) == i103+6));
+ assert(std::is_heap(i104, i104+6, std::greater<int>()) == (std::is_heap_until(i104, i104+6, std::greater<int>()) == i104+6));
+ assert(std::is_heap(i105, i105+6, std::greater<int>()) == (std::is_heap_until(i105, i105+6, std::greater<int>()) == i105+6));
+ assert(std::is_heap(i106, i106+6, std::greater<int>()) == (std::is_heap_until(i106, i106+6, std::greater<int>()) == i106+6));
+ assert(std::is_heap(i107, i107+6, std::greater<int>()) == (std::is_heap_until(i107, i107+6, std::greater<int>()) == i107+6));
+ assert(std::is_heap(i108, i108+6, std::greater<int>()) == (std::is_heap_until(i108, i108+6, std::greater<int>()) == i108+6));
+ assert(std::is_heap(i109, i109+6, std::greater<int>()) == (std::is_heap_until(i109, i109+6, std::greater<int>()) == i109+6));
+ assert(std::is_heap(i110, i110+6, std::greater<int>()) == (std::is_heap_until(i110, i110+6, std::greater<int>()) == i110+6));
+ assert(std::is_heap(i111, i111+6, std::greater<int>()) == (std::is_heap_until(i111, i111+6, std::greater<int>()) == i111+6));
+ assert(std::is_heap(i112, i112+6, std::greater<int>()) == (std::is_heap_until(i112, i112+6, std::greater<int>()) == i112+6));
+ assert(std::is_heap(i113, i113+6, std::greater<int>()) == (std::is_heap_until(i113, i113+6, std::greater<int>()) == i113+6));
+ assert(std::is_heap(i114, i114+6, std::greater<int>()) == (std::is_heap_until(i114, i114+6, std::greater<int>()) == i114+6));
+ assert(std::is_heap(i115, i115+6, std::greater<int>()) == (std::is_heap_until(i115, i115+6, std::greater<int>()) == i115+6));
+ assert(std::is_heap(i116, i116+6, std::greater<int>()) == (std::is_heap_until(i116, i116+6, std::greater<int>()) == i116+6));
+ assert(std::is_heap(i117, i117+6, std::greater<int>()) == (std::is_heap_until(i117, i117+6, std::greater<int>()) == i117+6));
+ assert(std::is_heap(i118, i118+6, std::greater<int>()) == (std::is_heap_until(i118, i118+6, std::greater<int>()) == i118+6));
+ assert(std::is_heap(i119, i119+6, std::greater<int>()) == (std::is_heap_until(i119, i119+6, std::greater<int>()) == i119+6));
+ int i120[] = {0, 0, 0, 0, 0, 0, 0};
+ int i121[] = {0, 0, 0, 0, 0, 0, 1};
+ int i122[] = {0, 0, 0, 0, 0, 1, 0};
+ int i123[] = {0, 0, 0, 0, 0, 1, 1};
+ int i124[] = {0, 0, 0, 0, 1, 0, 0};
+ int i125[] = {0, 0, 0, 0, 1, 0, 1};
+ int i126[] = {0, 0, 0, 0, 1, 1, 0};
+ int i127[] = {0, 0, 0, 0, 1, 1, 1};
+ int i128[] = {0, 0, 0, 1, 0, 0, 0};
+ int i129[] = {0, 0, 0, 1, 0, 0, 1};
+ int i130[] = {0, 0, 0, 1, 0, 1, 0};
+ int i131[] = {0, 0, 0, 1, 0, 1, 1};
+ int i132[] = {0, 0, 0, 1, 1, 0, 0};
+ int i133[] = {0, 0, 0, 1, 1, 0, 1};
+ int i134[] = {0, 0, 0, 1, 1, 1, 0};
+ int i135[] = {0, 0, 0, 1, 1, 1, 1};
+ int i136[] = {0, 0, 1, 0, 0, 0, 0};
+ int i137[] = {0, 0, 1, 0, 0, 0, 1};
+ int i138[] = {0, 0, 1, 0, 0, 1, 0};
+ int i139[] = {0, 0, 1, 0, 0, 1, 1};
+ int i140[] = {0, 0, 1, 0, 1, 0, 0};
+ int i141[] = {0, 0, 1, 0, 1, 0, 1};
+ int i142[] = {0, 0, 1, 0, 1, 1, 0};
+ int i143[] = {0, 0, 1, 0, 1, 1, 1};
+ int i144[] = {0, 0, 1, 1, 0, 0, 0};
+ int i145[] = {0, 0, 1, 1, 0, 0, 1};
+ int i146[] = {0, 0, 1, 1, 0, 1, 0};
+ int i147[] = {0, 0, 1, 1, 0, 1, 1};
+ int i148[] = {0, 0, 1, 1, 1, 0, 0};
+ int i149[] = {0, 0, 1, 1, 1, 0, 1};
+ int i150[] = {0, 0, 1, 1, 1, 1, 0};
+ int i151[] = {0, 0, 1, 1, 1, 1, 1};
+ int i152[] = {0, 1, 0, 0, 0, 0, 0};
+ int i153[] = {0, 1, 0, 0, 0, 0, 1};
+ int i154[] = {0, 1, 0, 0, 0, 1, 0};
+ int i155[] = {0, 1, 0, 0, 0, 1, 1};
+ int i156[] = {0, 1, 0, 0, 1, 0, 0};
+ int i157[] = {0, 1, 0, 0, 1, 0, 1};
+ int i158[] = {0, 1, 0, 0, 1, 1, 0};
+ int i159[] = {0, 1, 0, 0, 1, 1, 1};
+ int i160[] = {0, 1, 0, 1, 0, 0, 0};
+ int i161[] = {0, 1, 0, 1, 0, 0, 1};
+ int i162[] = {0, 1, 0, 1, 0, 1, 0};
+ int i163[] = {0, 1, 0, 1, 0, 1, 1};
+ int i164[] = {0, 1, 0, 1, 1, 0, 0};
+ int i165[] = {0, 1, 0, 1, 1, 0, 1};
+ int i166[] = {0, 1, 0, 1, 1, 1, 0};
+ int i167[] = {0, 1, 0, 1, 1, 1, 1};
+ int i168[] = {0, 1, 1, 0, 0, 0, 0};
+ int i169[] = {0, 1, 1, 0, 0, 0, 1};
+ int i170[] = {0, 1, 1, 0, 0, 1, 0};
+ int i171[] = {0, 1, 1, 0, 0, 1, 1};
+ int i172[] = {0, 1, 1, 0, 1, 0, 0};
+ int i173[] = {0, 1, 1, 0, 1, 0, 1};
+ int i174[] = {0, 1, 1, 0, 1, 1, 0};
+ int i175[] = {0, 1, 1, 0, 1, 1, 1};
+ int i176[] = {0, 1, 1, 1, 0, 0, 0};
+ int i177[] = {0, 1, 1, 1, 0, 0, 1};
+ int i178[] = {0, 1, 1, 1, 0, 1, 0};
+ int i179[] = {0, 1, 1, 1, 0, 1, 1};
+ int i180[] = {0, 1, 1, 1, 1, 0, 0};
+ int i181[] = {0, 1, 1, 1, 1, 0, 1};
+ int i182[] = {0, 1, 1, 1, 1, 1, 0};
+ int i183[] = {0, 1, 1, 1, 1, 1, 1};
+ int i184[] = {1, 0, 0, 0, 0, 0, 0};
+ int i185[] = {1, 0, 0, 0, 0, 0, 1};
+ int i186[] = {1, 0, 0, 0, 0, 1, 0};
+ int i187[] = {1, 0, 0, 0, 0, 1, 1};
+ int i188[] = {1, 0, 0, 0, 1, 0, 0};
+ int i189[] = {1, 0, 0, 0, 1, 0, 1};
+ int i190[] = {1, 0, 0, 0, 1, 1, 0};
+ int i191[] = {1, 0, 0, 0, 1, 1, 1};
+ int i192[] = {1, 0, 0, 1, 0, 0, 0};
+ int i193[] = {1, 0, 0, 1, 0, 0, 1};
+ int i194[] = {1, 0, 0, 1, 0, 1, 0};
+ int i195[] = {1, 0, 0, 1, 0, 1, 1};
+ int i196[] = {1, 0, 0, 1, 1, 0, 0};
+ int i197[] = {1, 0, 0, 1, 1, 0, 1};
+ int i198[] = {1, 0, 0, 1, 1, 1, 0};
+ int i199[] = {1, 0, 0, 1, 1, 1, 1};
+ int i200[] = {1, 0, 1, 0, 0, 0, 0};
+ int i201[] = {1, 0, 1, 0, 0, 0, 1};
+ int i202[] = {1, 0, 1, 0, 0, 1, 0};
+ int i203[] = {1, 0, 1, 0, 0, 1, 1};
+ int i204[] = {1, 0, 1, 0, 1, 0, 0};
+ int i205[] = {1, 0, 1, 0, 1, 0, 1};
+ int i206[] = {1, 0, 1, 0, 1, 1, 0};
+ int i207[] = {1, 0, 1, 0, 1, 1, 1};
+ int i208[] = {1, 0, 1, 1, 0, 0, 0};
+ int i209[] = {1, 0, 1, 1, 0, 0, 1};
+ int i210[] = {1, 0, 1, 1, 0, 1, 0};
+ int i211[] = {1, 0, 1, 1, 0, 1, 1};
+ int i212[] = {1, 0, 1, 1, 1, 0, 0};
+ int i213[] = {1, 0, 1, 1, 1, 0, 1};
+ int i214[] = {1, 0, 1, 1, 1, 1, 0};
+ int i215[] = {1, 0, 1, 1, 1, 1, 1};
+ int i216[] = {1, 1, 0, 0, 0, 0, 0};
+ int i217[] = {1, 1, 0, 0, 0, 0, 1};
+ int i218[] = {1, 1, 0, 0, 0, 1, 0};
+ int i219[] = {1, 1, 0, 0, 0, 1, 1};
+ int i220[] = {1, 1, 0, 0, 1, 0, 0};
+ int i221[] = {1, 1, 0, 0, 1, 0, 1};
+ int i222[] = {1, 1, 0, 0, 1, 1, 0};
+ int i223[] = {1, 1, 0, 0, 1, 1, 1};
+ int i224[] = {1, 1, 0, 1, 0, 0, 0};
+ int i225[] = {1, 1, 0, 1, 0, 0, 1};
+ int i226[] = {1, 1, 0, 1, 0, 1, 0};
+ int i227[] = {1, 1, 0, 1, 0, 1, 1};
+ int i228[] = {1, 1, 0, 1, 1, 0, 0};
+ int i229[] = {1, 1, 0, 1, 1, 0, 1};
+ int i230[] = {1, 1, 0, 1, 1, 1, 0};
+ int i231[] = {1, 1, 0, 1, 1, 1, 1};
+ int i232[] = {1, 1, 1, 0, 0, 0, 0};
+ int i233[] = {1, 1, 1, 0, 0, 0, 1};
+ int i234[] = {1, 1, 1, 0, 0, 1, 0};
+ int i235[] = {1, 1, 1, 0, 0, 1, 1};
+ int i236[] = {1, 1, 1, 0, 1, 0, 0};
+ int i237[] = {1, 1, 1, 0, 1, 0, 1};
+ int i238[] = {1, 1, 1, 0, 1, 1, 0};
+ int i239[] = {1, 1, 1, 0, 1, 1, 1};
+ int i240[] = {1, 1, 1, 1, 0, 0, 0};
+ int i241[] = {1, 1, 1, 1, 0, 0, 1};
+ int i242[] = {1, 1, 1, 1, 0, 1, 0};
+ int i243[] = {1, 1, 1, 1, 0, 1, 1};
+ int i244[] = {1, 1, 1, 1, 1, 0, 0};
+ int i245[] = {1, 1, 1, 1, 1, 0, 1};
+ int i246[] = {1, 1, 1, 1, 1, 1, 0};
+ assert(std::is_heap(i120, i120+7, std::greater<int>()) == (std::is_heap_until(i120, i120+7, std::greater<int>()) == i120+7));
+ assert(std::is_heap(i121, i121+7, std::greater<int>()) == (std::is_heap_until(i121, i121+7, std::greater<int>()) == i121+7));
+ assert(std::is_heap(i122, i122+7, std::greater<int>()) == (std::is_heap_until(i122, i122+7, std::greater<int>()) == i122+7));
+ assert(std::is_heap(i123, i123+7, std::greater<int>()) == (std::is_heap_until(i123, i123+7, std::greater<int>()) == i123+7));
+ assert(std::is_heap(i124, i124+7, std::greater<int>()) == (std::is_heap_until(i124, i124+7, std::greater<int>()) == i124+7));
+ assert(std::is_heap(i125, i125+7, std::greater<int>()) == (std::is_heap_until(i125, i125+7, std::greater<int>()) == i125+7));
+ assert(std::is_heap(i126, i126+7, std::greater<int>()) == (std::is_heap_until(i126, i126+7, std::greater<int>()) == i126+7));
+ assert(std::is_heap(i127, i127+7, std::greater<int>()) == (std::is_heap_until(i127, i127+7, std::greater<int>()) == i127+7));
+ assert(std::is_heap(i128, i128+7, std::greater<int>()) == (std::is_heap_until(i128, i128+7, std::greater<int>()) == i128+7));
+ assert(std::is_heap(i129, i129+7, std::greater<int>()) == (std::is_heap_until(i129, i129+7, std::greater<int>()) == i129+7));
+ assert(std::is_heap(i130, i130+7, std::greater<int>()) == (std::is_heap_until(i130, i130+7, std::greater<int>()) == i130+7));
+ assert(std::is_heap(i131, i131+7, std::greater<int>()) == (std::is_heap_until(i131, i131+7, std::greater<int>()) == i131+7));
+ assert(std::is_heap(i132, i132+7, std::greater<int>()) == (std::is_heap_until(i132, i132+7, std::greater<int>()) == i132+7));
+ assert(std::is_heap(i133, i133+7, std::greater<int>()) == (std::is_heap_until(i133, i133+7, std::greater<int>()) == i133+7));
+ assert(std::is_heap(i134, i134+7, std::greater<int>()) == (std::is_heap_until(i134, i134+7, std::greater<int>()) == i134+7));
+ assert(std::is_heap(i135, i135+7, std::greater<int>()) == (std::is_heap_until(i135, i135+7, std::greater<int>()) == i135+7));
+ assert(std::is_heap(i136, i136+7, std::greater<int>()) == (std::is_heap_until(i136, i136+7, std::greater<int>()) == i136+7));
+ assert(std::is_heap(i137, i137+7, std::greater<int>()) == (std::is_heap_until(i137, i137+7, std::greater<int>()) == i137+7));
+ assert(std::is_heap(i138, i138+7, std::greater<int>()) == (std::is_heap_until(i138, i138+7, std::greater<int>()) == i138+7));
+ assert(std::is_heap(i139, i139+7, std::greater<int>()) == (std::is_heap_until(i139, i139+7, std::greater<int>()) == i139+7));
+ assert(std::is_heap(i140, i140+7, std::greater<int>()) == (std::is_heap_until(i140, i140+7, std::greater<int>()) == i140+7));
+ assert(std::is_heap(i141, i141+7, std::greater<int>()) == (std::is_heap_until(i141, i141+7, std::greater<int>()) == i141+7));
+ assert(std::is_heap(i142, i142+7, std::greater<int>()) == (std::is_heap_until(i142, i142+7, std::greater<int>()) == i142+7));
+ assert(std::is_heap(i143, i143+7, std::greater<int>()) == (std::is_heap_until(i143, i143+7, std::greater<int>()) == i143+7));
+ assert(std::is_heap(i144, i144+7, std::greater<int>()) == (std::is_heap_until(i144, i144+7, std::greater<int>()) == i144+7));
+ assert(std::is_heap(i145, i145+7, std::greater<int>()) == (std::is_heap_until(i145, i145+7, std::greater<int>()) == i145+7));
+ assert(std::is_heap(i146, i146+7, std::greater<int>()) == (std::is_heap_until(i146, i146+7, std::greater<int>()) == i146+7));
+ assert(std::is_heap(i147, i147+7, std::greater<int>()) == (std::is_heap_until(i147, i147+7, std::greater<int>()) == i147+7));
+ assert(std::is_heap(i148, i148+7, std::greater<int>()) == (std::is_heap_until(i148, i148+7, std::greater<int>()) == i148+7));
+ assert(std::is_heap(i149, i149+7, std::greater<int>()) == (std::is_heap_until(i149, i149+7, std::greater<int>()) == i149+7));
+ assert(std::is_heap(i150, i150+7, std::greater<int>()) == (std::is_heap_until(i150, i150+7, std::greater<int>()) == i150+7));
+ assert(std::is_heap(i151, i151+7, std::greater<int>()) == (std::is_heap_until(i151, i151+7, std::greater<int>()) == i151+7));
+ assert(std::is_heap(i152, i152+7, std::greater<int>()) == (std::is_heap_until(i152, i152+7, std::greater<int>()) == i152+7));
+ assert(std::is_heap(i153, i153+7, std::greater<int>()) == (std::is_heap_until(i153, i153+7, std::greater<int>()) == i153+7));
+ assert(std::is_heap(i154, i154+7, std::greater<int>()) == (std::is_heap_until(i154, i154+7, std::greater<int>()) == i154+7));
+ assert(std::is_heap(i155, i155+7, std::greater<int>()) == (std::is_heap_until(i155, i155+7, std::greater<int>()) == i155+7));
+ assert(std::is_heap(i156, i156+7, std::greater<int>()) == (std::is_heap_until(i156, i156+7, std::greater<int>()) == i156+7));
+ assert(std::is_heap(i157, i157+7, std::greater<int>()) == (std::is_heap_until(i157, i157+7, std::greater<int>()) == i157+7));
+ assert(std::is_heap(i158, i158+7, std::greater<int>()) == (std::is_heap_until(i158, i158+7, std::greater<int>()) == i158+7));
+ assert(std::is_heap(i159, i159+7, std::greater<int>()) == (std::is_heap_until(i159, i159+7, std::greater<int>()) == i159+7));
+ assert(std::is_heap(i160, i160+7, std::greater<int>()) == (std::is_heap_until(i160, i160+7, std::greater<int>()) == i160+7));
+ assert(std::is_heap(i161, i161+7, std::greater<int>()) == (std::is_heap_until(i161, i161+7, std::greater<int>()) == i161+7));
+ assert(std::is_heap(i162, i162+7, std::greater<int>()) == (std::is_heap_until(i162, i162+7, std::greater<int>()) == i162+7));
+ assert(std::is_heap(i163, i163+7, std::greater<int>()) == (std::is_heap_until(i163, i163+7, std::greater<int>()) == i163+7));
+ assert(std::is_heap(i164, i164+7, std::greater<int>()) == (std::is_heap_until(i164, i164+7, std::greater<int>()) == i164+7));
+ assert(std::is_heap(i165, i165+7, std::greater<int>()) == (std::is_heap_until(i165, i165+7, std::greater<int>()) == i165+7));
+ assert(std::is_heap(i166, i166+7, std::greater<int>()) == (std::is_heap_until(i166, i166+7, std::greater<int>()) == i166+7));
+ assert(std::is_heap(i167, i167+7, std::greater<int>()) == (std::is_heap_until(i167, i167+7, std::greater<int>()) == i167+7));
+ assert(std::is_heap(i168, i168+7, std::greater<int>()) == (std::is_heap_until(i168, i168+7, std::greater<int>()) == i168+7));
+ assert(std::is_heap(i169, i169+7, std::greater<int>()) == (std::is_heap_until(i169, i169+7, std::greater<int>()) == i169+7));
+ assert(std::is_heap(i170, i170+7, std::greater<int>()) == (std::is_heap_until(i170, i170+7, std::greater<int>()) == i170+7));
+ assert(std::is_heap(i171, i171+7, std::greater<int>()) == (std::is_heap_until(i171, i171+7, std::greater<int>()) == i171+7));
+ assert(std::is_heap(i172, i172+7, std::greater<int>()) == (std::is_heap_until(i172, i172+7, std::greater<int>()) == i172+7));
+ assert(std::is_heap(i173, i173+7, std::greater<int>()) == (std::is_heap_until(i173, i173+7, std::greater<int>()) == i173+7));
+ assert(std::is_heap(i174, i174+7, std::greater<int>()) == (std::is_heap_until(i174, i174+7, std::greater<int>()) == i174+7));
+ assert(std::is_heap(i175, i175+7, std::greater<int>()) == (std::is_heap_until(i175, i175+7, std::greater<int>()) == i175+7));
+ assert(std::is_heap(i176, i176+7, std::greater<int>()) == (std::is_heap_until(i176, i176+7, std::greater<int>()) == i176+7));
+ assert(std::is_heap(i177, i177+7, std::greater<int>()) == (std::is_heap_until(i177, i177+7, std::greater<int>()) == i177+7));
+ assert(std::is_heap(i178, i178+7, std::greater<int>()) == (std::is_heap_until(i178, i178+7, std::greater<int>()) == i178+7));
+ assert(std::is_heap(i179, i179+7, std::greater<int>()) == (std::is_heap_until(i179, i179+7, std::greater<int>()) == i179+7));
+ assert(std::is_heap(i180, i180+7, std::greater<int>()) == (std::is_heap_until(i180, i180+7, std::greater<int>()) == i180+7));
+ assert(std::is_heap(i181, i181+7, std::greater<int>()) == (std::is_heap_until(i181, i181+7, std::greater<int>()) == i181+7));
+ assert(std::is_heap(i182, i182+7, std::greater<int>()) == (std::is_heap_until(i182, i182+7, std::greater<int>()) == i182+7));
+ assert(std::is_heap(i183, i183+7, std::greater<int>()) == (std::is_heap_until(i183, i183+7, std::greater<int>()) == i183+7));
+ assert(std::is_heap(i184, i184+7, std::greater<int>()) == (std::is_heap_until(i184, i184+7, std::greater<int>()) == i184+7));
+ assert(std::is_heap(i185, i185+7, std::greater<int>()) == (std::is_heap_until(i185, i185+7, std::greater<int>()) == i185+7));
+ assert(std::is_heap(i186, i186+7, std::greater<int>()) == (std::is_heap_until(i186, i186+7, std::greater<int>()) == i186+7));
+ assert(std::is_heap(i187, i187+7, std::greater<int>()) == (std::is_heap_until(i187, i187+7, std::greater<int>()) == i187+7));
+ assert(std::is_heap(i188, i188+7, std::greater<int>()) == (std::is_heap_until(i188, i188+7, std::greater<int>()) == i188+7));
+ assert(std::is_heap(i189, i189+7, std::greater<int>()) == (std::is_heap_until(i189, i189+7, std::greater<int>()) == i189+7));
+ assert(std::is_heap(i190, i190+7, std::greater<int>()) == (std::is_heap_until(i190, i190+7, std::greater<int>()) == i190+7));
+ assert(std::is_heap(i191, i191+7, std::greater<int>()) == (std::is_heap_until(i191, i191+7, std::greater<int>()) == i191+7));
+ assert(std::is_heap(i192, i192+7, std::greater<int>()) == (std::is_heap_until(i192, i192+7, std::greater<int>()) == i192+7));
+ assert(std::is_heap(i193, i193+7, std::greater<int>()) == (std::is_heap_until(i193, i193+7, std::greater<int>()) == i193+7));
+ assert(std::is_heap(i194, i194+7, std::greater<int>()) == (std::is_heap_until(i194, i194+7, std::greater<int>()) == i194+7));
+ assert(std::is_heap(i195, i195+7, std::greater<int>()) == (std::is_heap_until(i195, i195+7, std::greater<int>()) == i195+7));
+ assert(std::is_heap(i196, i196+7, std::greater<int>()) == (std::is_heap_until(i196, i196+7, std::greater<int>()) == i196+7));
+ assert(std::is_heap(i197, i197+7, std::greater<int>()) == (std::is_heap_until(i197, i197+7, std::greater<int>()) == i197+7));
+ assert(std::is_heap(i198, i198+7, std::greater<int>()) == (std::is_heap_until(i198, i198+7, std::greater<int>()) == i198+7));
+ assert(std::is_heap(i199, i199+7, std::greater<int>()) == (std::is_heap_until(i199, i199+7, std::greater<int>()) == i199+7));
+ assert(std::is_heap(i200, i200+7, std::greater<int>()) == (std::is_heap_until(i200, i200+7, std::greater<int>()) == i200+7));
+ assert(std::is_heap(i201, i201+7, std::greater<int>()) == (std::is_heap_until(i201, i201+7, std::greater<int>()) == i201+7));
+ assert(std::is_heap(i202, i202+7, std::greater<int>()) == (std::is_heap_until(i202, i202+7, std::greater<int>()) == i202+7));
+ assert(std::is_heap(i203, i203+7, std::greater<int>()) == (std::is_heap_until(i203, i203+7, std::greater<int>()) == i203+7));
+ assert(std::is_heap(i204, i204+7, std::greater<int>()) == (std::is_heap_until(i204, i204+7, std::greater<int>()) == i204+7));
+ assert(std::is_heap(i205, i205+7, std::greater<int>()) == (std::is_heap_until(i205, i205+7, std::greater<int>()) == i205+7));
+ assert(std::is_heap(i206, i206+7, std::greater<int>()) == (std::is_heap_until(i206, i206+7, std::greater<int>()) == i206+7));
+ assert(std::is_heap(i207, i207+7, std::greater<int>()) == (std::is_heap_until(i207, i207+7, std::greater<int>()) == i207+7));
+ assert(std::is_heap(i208, i208+7, std::greater<int>()) == (std::is_heap_until(i208, i208+7, std::greater<int>()) == i208+7));
+ assert(std::is_heap(i209, i209+7, std::greater<int>()) == (std::is_heap_until(i209, i209+7, std::greater<int>()) == i209+7));
+ assert(std::is_heap(i210, i210+7, std::greater<int>()) == (std::is_heap_until(i210, i210+7, std::greater<int>()) == i210+7));
+ assert(std::is_heap(i211, i211+7, std::greater<int>()) == (std::is_heap_until(i211, i211+7, std::greater<int>()) == i211+7));
+ assert(std::is_heap(i212, i212+7, std::greater<int>()) == (std::is_heap_until(i212, i212+7, std::greater<int>()) == i212+7));
+ assert(std::is_heap(i213, i213+7, std::greater<int>()) == (std::is_heap_until(i213, i213+7, std::greater<int>()) == i213+7));
+ assert(std::is_heap(i214, i214+7, std::greater<int>()) == (std::is_heap_until(i214, i214+7, std::greater<int>()) == i214+7));
+ assert(std::is_heap(i215, i215+7, std::greater<int>()) == (std::is_heap_until(i215, i215+7, std::greater<int>()) == i215+7));
+ assert(std::is_heap(i216, i216+7, std::greater<int>()) == (std::is_heap_until(i216, i216+7, std::greater<int>()) == i216+7));
+ assert(std::is_heap(i217, i217+7, std::greater<int>()) == (std::is_heap_until(i217, i217+7, std::greater<int>()) == i217+7));
+ assert(std::is_heap(i218, i218+7, std::greater<int>()) == (std::is_heap_until(i218, i218+7, std::greater<int>()) == i218+7));
+ assert(std::is_heap(i219, i219+7, std::greater<int>()) == (std::is_heap_until(i219, i219+7, std::greater<int>()) == i219+7));
+ assert(std::is_heap(i220, i220+7, std::greater<int>()) == (std::is_heap_until(i220, i220+7, std::greater<int>()) == i220+7));
+ assert(std::is_heap(i221, i221+7, std::greater<int>()) == (std::is_heap_until(i221, i221+7, std::greater<int>()) == i221+7));
+ assert(std::is_heap(i222, i222+7, std::greater<int>()) == (std::is_heap_until(i222, i222+7, std::greater<int>()) == i222+7));
+ assert(std::is_heap(i223, i223+7, std::greater<int>()) == (std::is_heap_until(i223, i223+7, std::greater<int>()) == i223+7));
+ assert(std::is_heap(i224, i224+7, std::greater<int>()) == (std::is_heap_until(i224, i224+7, std::greater<int>()) == i224+7));
+ assert(std::is_heap(i225, i225+7, std::greater<int>()) == (std::is_heap_until(i225, i225+7, std::greater<int>()) == i225+7));
+ assert(std::is_heap(i226, i226+7, std::greater<int>()) == (std::is_heap_until(i226, i226+7, std::greater<int>()) == i226+7));
+ assert(std::is_heap(i227, i227+7, std::greater<int>()) == (std::is_heap_until(i227, i227+7, std::greater<int>()) == i227+7));
+ assert(std::is_heap(i228, i228+7, std::greater<int>()) == (std::is_heap_until(i228, i228+7, std::greater<int>()) == i228+7));
+ assert(std::is_heap(i229, i229+7, std::greater<int>()) == (std::is_heap_until(i229, i229+7, std::greater<int>()) == i229+7));
+ assert(std::is_heap(i230, i230+7, std::greater<int>()) == (std::is_heap_until(i230, i230+7, std::greater<int>()) == i230+7));
+ assert(std::is_heap(i231, i231+7, std::greater<int>()) == (std::is_heap_until(i231, i231+7, std::greater<int>()) == i231+7));
+ assert(std::is_heap(i232, i232+7, std::greater<int>()) == (std::is_heap_until(i232, i232+7, std::greater<int>()) == i232+7));
+ assert(std::is_heap(i233, i233+7, std::greater<int>()) == (std::is_heap_until(i233, i233+7, std::greater<int>()) == i233+7));
+ assert(std::is_heap(i234, i234+7, std::greater<int>()) == (std::is_heap_until(i234, i234+7, std::greater<int>()) == i234+7));
+ assert(std::is_heap(i235, i235+7, std::greater<int>()) == (std::is_heap_until(i235, i235+7, std::greater<int>()) == i235+7));
+ assert(std::is_heap(i236, i236+7, std::greater<int>()) == (std::is_heap_until(i236, i236+7, std::greater<int>()) == i236+7));
+ assert(std::is_heap(i237, i237+7, std::greater<int>()) == (std::is_heap_until(i237, i237+7, std::greater<int>()) == i237+7));
+ assert(std::is_heap(i238, i238+7, std::greater<int>()) == (std::is_heap_until(i238, i238+7, std::greater<int>()) == i238+7));
+ assert(std::is_heap(i239, i239+7, std::greater<int>()) == (std::is_heap_until(i239, i239+7, std::greater<int>()) == i239+7));
+ assert(std::is_heap(i240, i240+7, std::greater<int>()) == (std::is_heap_until(i240, i240+7, std::greater<int>()) == i240+7));
+ assert(std::is_heap(i241, i241+7, std::greater<int>()) == (std::is_heap_until(i241, i241+7, std::greater<int>()) == i241+7));
+ assert(std::is_heap(i242, i242+7, std::greater<int>()) == (std::is_heap_until(i242, i242+7, std::greater<int>()) == i242+7));
+ assert(std::is_heap(i243, i243+7, std::greater<int>()) == (std::is_heap_until(i243, i243+7, std::greater<int>()) == i243+7));
+ assert(std::is_heap(i244, i244+7, std::greater<int>()) == (std::is_heap_until(i244, i244+7, std::greater<int>()) == i244+7));
+ assert(std::is_heap(i245, i245+7, std::greater<int>()) == (std::is_heap_until(i245, i245+7, std::greater<int>()) == i245+7));
+ assert(std::is_heap(i246, i246+7, std::greater<int>()) == (std::is_heap_until(i246, i246+7, std::greater<int>()) == i246+7));
+}
+
+int main()
+{
+ test();
+}
diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.heap.operations/is.heap/is_heap_until.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.heap.operations/is.heap/is_heap_until.pass.cpp
new file mode 100644
index 00000000000..082c0445182
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.sorting/alg.heap.operations/is.heap/is_heap_until.pass.cpp
@@ -0,0 +1,521 @@
+//===----------------------------------------------------------------------===//
+//
+// 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<RandomAccessIterator Iter>
+// requires LessThanComparable<Iter::value_type>
+// Iter
+// is_heap_until(Iter first, Iter last);
+
+#include <algorithm>
+#include <cassert>
+
+void test()
+{
+ int i1[] = {0, 0};
+ assert(std::is_heap_until(i1, i1) == i1);
+ assert(std::is_heap_until(i1, i1+1) == i1+1);
+ int i2[] = {0, 1};
+ int i3[] = {1, 0};
+ assert(std::is_heap_until(i1, i1+2) == i1+2);
+ assert(std::is_heap_until(i2, i2+2) == i2+1);
+ assert(std::is_heap_until(i3, i3+2) == i3+2);
+ int i4[] = {0, 0, 0};
+ int i5[] = {0, 0, 1};
+ int i6[] = {0, 1, 0};
+ int i7[] = {0, 1, 1};
+ int i8[] = {1, 0, 0};
+ int i9[] = {1, 0, 1};
+ int i10[] = {1, 1, 0};
+ assert(std::is_heap_until(i4, i4+3) == i4+3);
+ assert(std::is_heap_until(i5, i5+3) == i5+2);
+ assert(std::is_heap_until(i6, i6+3) == i6+1);
+ assert(std::is_heap_until(i7, i7+3) == i7+1);
+ assert(std::is_heap_until(i8, i8+3) == i8+3);
+ assert(std::is_heap_until(i9, i9+3) == i9+3);
+ assert(std::is_heap_until(i10, i10+3) == i10+3);
+ int i11[] = {0, 0, 0, 0};
+ int i12[] = {0, 0, 0, 1};
+ int i13[] = {0, 0, 1, 0};
+ int i14[] = {0, 0, 1, 1};
+ int i15[] = {0, 1, 0, 0};
+ int i16[] = {0, 1, 0, 1};
+ int i17[] = {0, 1, 1, 0};
+ int i18[] = {0, 1, 1, 1};
+ int i19[] = {1, 0, 0, 0};
+ int i20[] = {1, 0, 0, 1};
+ int i21[] = {1, 0, 1, 0};
+ int i22[] = {1, 0, 1, 1};
+ int i23[] = {1, 1, 0, 0};
+ int i24[] = {1, 1, 0, 1};
+ int i25[] = {1, 1, 1, 0};
+ assert(std::is_heap_until(i11, i11+4) == i11+4);
+ assert(std::is_heap_until(i12, i12+4) == i12+3);
+ assert(std::is_heap_until(i13, i13+4) == i13+2);
+ assert(std::is_heap_until(i14, i14+4) == i14+2);
+ assert(std::is_heap_until(i15, i15+4) == i15+1);
+ assert(std::is_heap_until(i16, i16+4) == i16+1);
+ assert(std::is_heap_until(i17, i17+4) == i17+1);
+ assert(std::is_heap_until(i18, i18+4) == i18+1);
+ assert(std::is_heap_until(i19, i19+4) == i19+4);
+ assert(std::is_heap_until(i20, i20+4) == i20+3);
+ assert(std::is_heap_until(i21, i21+4) == i21+4);
+ assert(std::is_heap_until(i22, i22+4) == i22+3);
+ assert(std::is_heap_until(i23, i23+4) == i23+4);
+ assert(std::is_heap_until(i24, i24+4) == i24+4);
+ assert(std::is_heap_until(i25, i25+4) == i25+4);
+ int i26[] = {0, 0, 0, 0, 0};
+ int i27[] = {0, 0, 0, 0, 1};
+ int i28[] = {0, 0, 0, 1, 0};
+ int i29[] = {0, 0, 0, 1, 1};
+ int i30[] = {0, 0, 1, 0, 0};
+ int i31[] = {0, 0, 1, 0, 1};
+ int i32[] = {0, 0, 1, 1, 0};
+ int i33[] = {0, 0, 1, 1, 1};
+ int i34[] = {0, 1, 0, 0, 0};
+ int i35[] = {0, 1, 0, 0, 1};
+ int i36[] = {0, 1, 0, 1, 0};
+ int i37[] = {0, 1, 0, 1, 1};
+ int i38[] = {0, 1, 1, 0, 0};
+ int i39[] = {0, 1, 1, 0, 1};
+ int i40[] = {0, 1, 1, 1, 0};
+ int i41[] = {0, 1, 1, 1, 1};
+ int i42[] = {1, 0, 0, 0, 0};
+ int i43[] = {1, 0, 0, 0, 1};
+ int i44[] = {1, 0, 0, 1, 0};
+ int i45[] = {1, 0, 0, 1, 1};
+ int i46[] = {1, 0, 1, 0, 0};
+ int i47[] = {1, 0, 1, 0, 1};
+ int i48[] = {1, 0, 1, 1, 0};
+ int i49[] = {1, 0, 1, 1, 1};
+ int i50[] = {1, 1, 0, 0, 0};
+ int i51[] = {1, 1, 0, 0, 1};
+ int i52[] = {1, 1, 0, 1, 0};
+ int i53[] = {1, 1, 0, 1, 1};
+ int i54[] = {1, 1, 1, 0, 0};
+ int i55[] = {1, 1, 1, 0, 1};
+ int i56[] = {1, 1, 1, 1, 0};
+ assert(std::is_heap_until(i26, i26+5) == i26+5);
+ assert(std::is_heap_until(i27, i27+5) == i27+4);
+ assert(std::is_heap_until(i28, i28+5) == i28+3);
+ assert(std::is_heap_until(i29, i29+5) == i29+3);
+ assert(std::is_heap_until(i30, i30+5) == i30+2);
+ assert(std::is_heap_until(i31, i31+5) == i31+2);
+ assert(std::is_heap_until(i32, i32+5) == i32+2);
+ assert(std::is_heap_until(i33, i33+5) == i33+2);
+ assert(std::is_heap_until(i34, i34+5) == i34+1);
+ assert(std::is_heap_until(i35, i35+5) == i35+1);
+ assert(std::is_heap_until(i36, i36+5) == i36+1);
+ assert(std::is_heap_until(i37, i37+5) == i37+1);
+ assert(std::is_heap_until(i38, i38+5) == i38+1);
+ assert(std::is_heap_until(i39, i39+5) == i39+1);
+ assert(std::is_heap_until(i40, i40+5) == i40+1);
+ assert(std::is_heap_until(i41, i41+5) == i41+1);
+ assert(std::is_heap_until(i42, i42+5) == i42+5);
+ assert(std::is_heap_until(i43, i43+5) == i43+4);
+ assert(std::is_heap_until(i44, i44+5) == i44+3);
+ assert(std::is_heap_until(i45, i45+5) == i45+3);
+ assert(std::is_heap_until(i46, i46+5) == i46+5);
+ assert(std::is_heap_until(i47, i47+5) == i47+4);
+ assert(std::is_heap_until(i48, i48+5) == i48+3);
+ assert(std::is_heap_until(i49, i49+5) == i49+3);
+ assert(std::is_heap_until(i50, i50+5) == i50+5);
+ assert(std::is_heap_until(i51, i51+5) == i51+5);
+ assert(std::is_heap_until(i52, i52+5) == i52+5);
+ assert(std::is_heap_until(i53, i53+5) == i53+5);
+ assert(std::is_heap_until(i54, i54+5) == i54+5);
+ assert(std::is_heap_until(i55, i55+5) == i55+5);
+ assert(std::is_heap_until(i56, i56+5) == i56+5);
+ int i57[] = {0, 0, 0, 0, 0, 0};
+ int i58[] = {0, 0, 0, 0, 0, 1};
+ int i59[] = {0, 0, 0, 0, 1, 0};
+ int i60[] = {0, 0, 0, 0, 1, 1};
+ int i61[] = {0, 0, 0, 1, 0, 0};
+ int i62[] = {0, 0, 0, 1, 0, 1};
+ int i63[] = {0, 0, 0, 1, 1, 0};
+ int i64[] = {0, 0, 0, 1, 1, 1};
+ int i65[] = {0, 0, 1, 0, 0, 0};
+ int i66[] = {0, 0, 1, 0, 0, 1};
+ int i67[] = {0, 0, 1, 0, 1, 0};
+ int i68[] = {0, 0, 1, 0, 1, 1};
+ int i69[] = {0, 0, 1, 1, 0, 0};
+ int i70[] = {0, 0, 1, 1, 0, 1};
+ int i71[] = {0, 0, 1, 1, 1, 0};
+ int i72[] = {0, 0, 1, 1, 1, 1};
+ int i73[] = {0, 1, 0, 0, 0, 0};
+ int i74[] = {0, 1, 0, 0, 0, 1};
+ int i75[] = {0, 1, 0, 0, 1, 0};
+ int i76[] = {0, 1, 0, 0, 1, 1};
+ int i77[] = {0, 1, 0, 1, 0, 0};
+ int i78[] = {0, 1, 0, 1, 0, 1};
+ int i79[] = {0, 1, 0, 1, 1, 0};
+ int i80[] = {0, 1, 0, 1, 1, 1};
+ int i81[] = {0, 1, 1, 0, 0, 0};
+ int i82[] = {0, 1, 1, 0, 0, 1};
+ int i83[] = {0, 1, 1, 0, 1, 0};
+ int i84[] = {0, 1, 1, 0, 1, 1};
+ int i85[] = {0, 1, 1, 1, 0, 0};
+ int i86[] = {0, 1, 1, 1, 0, 1};
+ int i87[] = {0, 1, 1, 1, 1, 0};
+ int i88[] = {0, 1, 1, 1, 1, 1};
+ int i89[] = {1, 0, 0, 0, 0, 0};
+ int i90[] = {1, 0, 0, 0, 0, 1};
+ int i91[] = {1, 0, 0, 0, 1, 0};
+ int i92[] = {1, 0, 0, 0, 1, 1};
+ int i93[] = {1, 0, 0, 1, 0, 0};
+ int i94[] = {1, 0, 0, 1, 0, 1};
+ int i95[] = {1, 0, 0, 1, 1, 0};
+ int i96[] = {1, 0, 0, 1, 1, 1};
+ int i97[] = {1, 0, 1, 0, 0, 0};
+ int i98[] = {1, 0, 1, 0, 0, 1};
+ int i99[] = {1, 0, 1, 0, 1, 0};
+ int i100[] = {1, 0, 1, 0, 1, 1};
+ int i101[] = {1, 0, 1, 1, 0, 0};
+ int i102[] = {1, 0, 1, 1, 0, 1};
+ int i103[] = {1, 0, 1, 1, 1, 0};
+ int i104[] = {1, 0, 1, 1, 1, 1};
+ int i105[] = {1, 1, 0, 0, 0, 0};
+ int i106[] = {1, 1, 0, 0, 0, 1};
+ int i107[] = {1, 1, 0, 0, 1, 0};
+ int i108[] = {1, 1, 0, 0, 1, 1};
+ int i109[] = {1, 1, 0, 1, 0, 0};
+ int i110[] = {1, 1, 0, 1, 0, 1};
+ int i111[] = {1, 1, 0, 1, 1, 0};
+ int i112[] = {1, 1, 0, 1, 1, 1};
+ int i113[] = {1, 1, 1, 0, 0, 0};
+ int i114[] = {1, 1, 1, 0, 0, 1};
+ int i115[] = {1, 1, 1, 0, 1, 0};
+ int i116[] = {1, 1, 1, 0, 1, 1};
+ int i117[] = {1, 1, 1, 1, 0, 0};
+ int i118[] = {1, 1, 1, 1, 0, 1};
+ int i119[] = {1, 1, 1, 1, 1, 0};
+ assert(std::is_heap_until(i57, i57+6) == i57+6);
+ assert(std::is_heap_until(i58, i58+6) == i58+5);
+ assert(std::is_heap_until(i59, i59+6) == i59+4);
+ assert(std::is_heap_until(i60, i60+6) == i60+4);
+ assert(std::is_heap_until(i61, i61+6) == i61+3);
+ assert(std::is_heap_until(i62, i62+6) == i62+3);
+ assert(std::is_heap_until(i63, i63+6) == i63+3);
+ assert(std::is_heap_until(i64, i64+6) == i64+3);
+ assert(std::is_heap_until(i65, i65+6) == i65+2);
+ assert(std::is_heap_until(i66, i66+6) == i66+2);
+ assert(std::is_heap_until(i67, i67+6) == i67+2);
+ assert(std::is_heap_until(i68, i68+6) == i68+2);
+ assert(std::is_heap_until(i69, i69+6) == i69+2);
+ assert(std::is_heap_until(i70, i70+6) == i70+2);
+ assert(std::is_heap_until(i71, i71+6) == i71+2);
+ assert(std::is_heap_until(i72, i72+6) == i72+2);
+ assert(std::is_heap_until(i73, i73+6) == i73+1);
+ assert(std::is_heap_until(i74, i74+6) == i74+1);
+ assert(std::is_heap_until(i75, i75+6) == i75+1);
+ assert(std::is_heap_until(i76, i76+6) == i76+1);
+ assert(std::is_heap_until(i77, i77+6) == i77+1);
+ assert(std::is_heap_until(i78, i78+6) == i78+1);
+ assert(std::is_heap_until(i79, i79+6) == i79+1);
+ assert(std::is_heap_until(i80, i80+6) == i80+1);
+ assert(std::is_heap_until(i81, i81+6) == i81+1);
+ assert(std::is_heap_until(i82, i82+6) == i82+1);
+ assert(std::is_heap_until(i83, i83+6) == i83+1);
+ assert(std::is_heap_until(i84, i84+6) == i84+1);
+ assert(std::is_heap_until(i85, i85+6) == i85+1);
+ assert(std::is_heap_until(i86, i86+6) == i86+1);
+ assert(std::is_heap_until(i87, i87+6) == i87+1);
+ assert(std::is_heap_until(i88, i88+6) == i88+1);
+ assert(std::is_heap_until(i89, i89+6) == i89+6);
+ assert(std::is_heap_until(i90, i90+6) == i90+5);
+ assert(std::is_heap_until(i91, i91+6) == i91+4);
+ assert(std::is_heap_until(i92, i92+6) == i92+4);
+ assert(std::is_heap_until(i93, i93+6) == i93+3);
+ assert(std::is_heap_until(i94, i94+6) == i94+3);
+ assert(std::is_heap_until(i95, i95+6) == i95+3);
+ assert(std::is_heap_until(i96, i96+6) == i96+3);
+ assert(std::is_heap_until(i97, i97+6) == i97+6);
+ assert(std::is_heap_until(i98, i98+6) == i98+6);
+ assert(std::is_heap_until(i99, i99+6) == i99+4);
+ assert(std::is_heap_until(i100, i100+6) == i100+4);
+ assert(std::is_heap_until(i101, i101+6) == i101+3);
+ assert(std::is_heap_until(i102, i102+6) == i102+3);
+ assert(std::is_heap_until(i103, i103+6) == i103+3);
+ assert(std::is_heap_until(i104, i104+6) == i104+3);
+ assert(std::is_heap_until(i105, i105+6) == i105+6);
+ assert(std::is_heap_until(i106, i106+6) == i106+5);
+ assert(std::is_heap_until(i107, i107+6) == i107+6);
+ assert(std::is_heap_until(i108, i108+6) == i108+5);
+ assert(std::is_heap_until(i109, i109+6) == i109+6);
+ assert(std::is_heap_until(i110, i110+6) == i110+5);
+ assert(std::is_heap_until(i111, i111+6) == i111+6);
+ assert(std::is_heap_until(i112, i112+6) == i112+5);
+ assert(std::is_heap_until(i113, i113+6) == i113+6);
+ assert(std::is_heap_until(i114, i114+6) == i114+6);
+ assert(std::is_heap_until(i115, i115+6) == i115+6);
+ assert(std::is_heap_until(i116, i116+6) == i116+6);
+ assert(std::is_heap_until(i117, i117+6) == i117+6);
+ assert(std::is_heap_until(i118, i118+6) == i118+6);
+ assert(std::is_heap_until(i119, i119+6) == i119+6);
+ int i120[] = {0, 0, 0, 0, 0, 0, 0};
+ int i121[] = {0, 0, 0, 0, 0, 0, 1};
+ int i122[] = {0, 0, 0, 0, 0, 1, 0};
+ int i123[] = {0, 0, 0, 0, 0, 1, 1};
+ int i124[] = {0, 0, 0, 0, 1, 0, 0};
+ int i125[] = {0, 0, 0, 0, 1, 0, 1};
+ int i126[] = {0, 0, 0, 0, 1, 1, 0};
+ int i127[] = {0, 0, 0, 0, 1, 1, 1};
+ int i128[] = {0, 0, 0, 1, 0, 0, 0};
+ int i129[] = {0, 0, 0, 1, 0, 0, 1};
+ int i130[] = {0, 0, 0, 1, 0, 1, 0};
+ int i131[] = {0, 0, 0, 1, 0, 1, 1};
+ int i132[] = {0, 0, 0, 1, 1, 0, 0};
+ int i133[] = {0, 0, 0, 1, 1, 0, 1};
+ int i134[] = {0, 0, 0, 1, 1, 1, 0};
+ int i135[] = {0, 0, 0, 1, 1, 1, 1};
+ int i136[] = {0, 0, 1, 0, 0, 0, 0};
+ int i137[] = {0, 0, 1, 0, 0, 0, 1};
+ int i138[] = {0, 0, 1, 0, 0, 1, 0};
+ int i139[] = {0, 0, 1, 0, 0, 1, 1};
+ int i140[] = {0, 0, 1, 0, 1, 0, 0};
+ int i141[] = {0, 0, 1, 0, 1, 0, 1};
+ int i142[] = {0, 0, 1, 0, 1, 1, 0};
+ int i143[] = {0, 0, 1, 0, 1, 1, 1};
+ int i144[] = {0, 0, 1, 1, 0, 0, 0};
+ int i145[] = {0, 0, 1, 1, 0, 0, 1};
+ int i146[] = {0, 0, 1, 1, 0, 1, 0};
+ int i147[] = {0, 0, 1, 1, 0, 1, 1};
+ int i148[] = {0, 0, 1, 1, 1, 0, 0};
+ int i149[] = {0, 0, 1, 1, 1, 0, 1};
+ int i150[] = {0, 0, 1, 1, 1, 1, 0};
+ int i151[] = {0, 0, 1, 1, 1, 1, 1};
+ int i152[] = {0, 1, 0, 0, 0, 0, 0};
+ int i153[] = {0, 1, 0, 0, 0, 0, 1};
+ int i154[] = {0, 1, 0, 0, 0, 1, 0};
+ int i155[] = {0, 1, 0, 0, 0, 1, 1};
+ int i156[] = {0, 1, 0, 0, 1, 0, 0};
+ int i157[] = {0, 1, 0, 0, 1, 0, 1};
+ int i158[] = {0, 1, 0, 0, 1, 1, 0};
+ int i159[] = {0, 1, 0, 0, 1, 1, 1};
+ int i160[] = {0, 1, 0, 1, 0, 0, 0};
+ int i161[] = {0, 1, 0, 1, 0, 0, 1};
+ int i162[] = {0, 1, 0, 1, 0, 1, 0};
+ int i163[] = {0, 1, 0, 1, 0, 1, 1};
+ int i164[] = {0, 1, 0, 1, 1, 0, 0};
+ int i165[] = {0, 1, 0, 1, 1, 0, 1};
+ int i166[] = {0, 1, 0, 1, 1, 1, 0};
+ int i167[] = {0, 1, 0, 1, 1, 1, 1};
+ int i168[] = {0, 1, 1, 0, 0, 0, 0};
+ int i169[] = {0, 1, 1, 0, 0, 0, 1};
+ int i170[] = {0, 1, 1, 0, 0, 1, 0};
+ int i171[] = {0, 1, 1, 0, 0, 1, 1};
+ int i172[] = {0, 1, 1, 0, 1, 0, 0};
+ int i173[] = {0, 1, 1, 0, 1, 0, 1};
+ int i174[] = {0, 1, 1, 0, 1, 1, 0};
+ int i175[] = {0, 1, 1, 0, 1, 1, 1};
+ int i176[] = {0, 1, 1, 1, 0, 0, 0};
+ int i177[] = {0, 1, 1, 1, 0, 0, 1};
+ int i178[] = {0, 1, 1, 1, 0, 1, 0};
+ int i179[] = {0, 1, 1, 1, 0, 1, 1};
+ int i180[] = {0, 1, 1, 1, 1, 0, 0};
+ int i181[] = {0, 1, 1, 1, 1, 0, 1};
+ int i182[] = {0, 1, 1, 1, 1, 1, 0};
+ int i183[] = {0, 1, 1, 1, 1, 1, 1};
+ int i184[] = {1, 0, 0, 0, 0, 0, 0};
+ int i185[] = {1, 0, 0, 0, 0, 0, 1};
+ int i186[] = {1, 0, 0, 0, 0, 1, 0};
+ int i187[] = {1, 0, 0, 0, 0, 1, 1};
+ int i188[] = {1, 0, 0, 0, 1, 0, 0};
+ int i189[] = {1, 0, 0, 0, 1, 0, 1};
+ int i190[] = {1, 0, 0, 0, 1, 1, 0};
+ int i191[] = {1, 0, 0, 0, 1, 1, 1};
+ int i192[] = {1, 0, 0, 1, 0, 0, 0};
+ int i193[] = {1, 0, 0, 1, 0, 0, 1};
+ int i194[] = {1, 0, 0, 1, 0, 1, 0};
+ int i195[] = {1, 0, 0, 1, 0, 1, 1};
+ int i196[] = {1, 0, 0, 1, 1, 0, 0};
+ int i197[] = {1, 0, 0, 1, 1, 0, 1};
+ int i198[] = {1, 0, 0, 1, 1, 1, 0};
+ int i199[] = {1, 0, 0, 1, 1, 1, 1};
+ int i200[] = {1, 0, 1, 0, 0, 0, 0};
+ int i201[] = {1, 0, 1, 0, 0, 0, 1};
+ int i202[] = {1, 0, 1, 0, 0, 1, 0};
+ int i203[] = {1, 0, 1, 0, 0, 1, 1};
+ int i204[] = {1, 0, 1, 0, 1, 0, 0};
+ int i205[] = {1, 0, 1, 0, 1, 0, 1};
+ int i206[] = {1, 0, 1, 0, 1, 1, 0};
+ int i207[] = {1, 0, 1, 0, 1, 1, 1};
+ int i208[] = {1, 0, 1, 1, 0, 0, 0};
+ int i209[] = {1, 0, 1, 1, 0, 0, 1};
+ int i210[] = {1, 0, 1, 1, 0, 1, 0};
+ int i211[] = {1, 0, 1, 1, 0, 1, 1};
+ int i212[] = {1, 0, 1, 1, 1, 0, 0};
+ int i213[] = {1, 0, 1, 1, 1, 0, 1};
+ int i214[] = {1, 0, 1, 1, 1, 1, 0};
+ int i215[] = {1, 0, 1, 1, 1, 1, 1};
+ int i216[] = {1, 1, 0, 0, 0, 0, 0};
+ int i217[] = {1, 1, 0, 0, 0, 0, 1};
+ int i218[] = {1, 1, 0, 0, 0, 1, 0};
+ int i219[] = {1, 1, 0, 0, 0, 1, 1};
+ int i220[] = {1, 1, 0, 0, 1, 0, 0};
+ int i221[] = {1, 1, 0, 0, 1, 0, 1};
+ int i222[] = {1, 1, 0, 0, 1, 1, 0};
+ int i223[] = {1, 1, 0, 0, 1, 1, 1};
+ int i224[] = {1, 1, 0, 1, 0, 0, 0};
+ int i225[] = {1, 1, 0, 1, 0, 0, 1};
+ int i226[] = {1, 1, 0, 1, 0, 1, 0};
+ int i227[] = {1, 1, 0, 1, 0, 1, 1};
+ int i228[] = {1, 1, 0, 1, 1, 0, 0};
+ int i229[] = {1, 1, 0, 1, 1, 0, 1};
+ int i230[] = {1, 1, 0, 1, 1, 1, 0};
+ int i231[] = {1, 1, 0, 1, 1, 1, 1};
+ int i232[] = {1, 1, 1, 0, 0, 0, 0};
+ int i233[] = {1, 1, 1, 0, 0, 0, 1};
+ int i234[] = {1, 1, 1, 0, 0, 1, 0};
+ int i235[] = {1, 1, 1, 0, 0, 1, 1};
+ int i236[] = {1, 1, 1, 0, 1, 0, 0};
+ int i237[] = {1, 1, 1, 0, 1, 0, 1};
+ int i238[] = {1, 1, 1, 0, 1, 1, 0};
+ int i239[] = {1, 1, 1, 0, 1, 1, 1};
+ int i240[] = {1, 1, 1, 1, 0, 0, 0};
+ int i241[] = {1, 1, 1, 1, 0, 0, 1};
+ int i242[] = {1, 1, 1, 1, 0, 1, 0};
+ int i243[] = {1, 1, 1, 1, 0, 1, 1};
+ int i244[] = {1, 1, 1, 1, 1, 0, 0};
+ int i245[] = {1, 1, 1, 1, 1, 0, 1};
+ int i246[] = {1, 1, 1, 1, 1, 1, 0};
+ assert(std::is_heap_until(i120, i120+7) == i120+7);
+ assert(std::is_heap_until(i121, i121+7) == i121+6);
+ assert(std::is_heap_until(i122, i122+7) == i122+5);
+ assert(std::is_heap_until(i123, i123+7) == i123+5);
+ assert(std::is_heap_until(i124, i124+7) == i124+4);
+ assert(std::is_heap_until(i125, i125+7) == i125+4);
+ assert(std::is_heap_until(i126, i126+7) == i126+4);
+ assert(std::is_heap_until(i127, i127+7) == i127+4);
+ assert(std::is_heap_until(i128, i128+7) == i128+3);
+ assert(std::is_heap_until(i129, i129+7) == i129+3);
+ assert(std::is_heap_until(i130, i130+7) == i130+3);
+ assert(std::is_heap_until(i131, i131+7) == i131+3);
+ assert(std::is_heap_until(i132, i132+7) == i132+3);
+ assert(std::is_heap_until(i133, i133+7) == i133+3);
+ assert(std::is_heap_until(i134, i134+7) == i134+3);
+ assert(std::is_heap_until(i135, i135+7) == i135+3);
+ assert(std::is_heap_until(i136, i136+7) == i136+2);
+ assert(std::is_heap_until(i137, i137+7) == i137+2);
+ assert(std::is_heap_until(i138, i138+7) == i138+2);
+ assert(std::is_heap_until(i139, i139+7) == i139+2);
+ assert(std::is_heap_until(i140, i140+7) == i140+2);
+ assert(std::is_heap_until(i141, i141+7) == i141+2);
+ assert(std::is_heap_until(i142, i142+7) == i142+2);
+ assert(std::is_heap_until(i143, i143+7) == i143+2);
+ assert(std::is_heap_until(i144, i144+7) == i144+2);
+ assert(std::is_heap_until(i145, i145+7) == i145+2);
+ assert(std::is_heap_until(i146, i146+7) == i146+2);
+ assert(std::is_heap_until(i147, i147+7) == i147+2);
+ assert(std::is_heap_until(i148, i148+7) == i148+2);
+ assert(std::is_heap_until(i149, i149+7) == i149+2);
+ assert(std::is_heap_until(i150, i150+7) == i150+2);
+ assert(std::is_heap_until(i151, i151+7) == i151+2);
+ assert(std::is_heap_until(i152, i152+7) == i152+1);
+ assert(std::is_heap_until(i153, i153+7) == i153+1);
+ assert(std::is_heap_until(i154, i154+7) == i154+1);
+ assert(std::is_heap_until(i155, i155+7) == i155+1);
+ assert(std::is_heap_until(i156, i156+7) == i156+1);
+ assert(std::is_heap_until(i157, i157+7) == i157+1);
+ assert(std::is_heap_until(i158, i158+7) == i158+1);
+ assert(std::is_heap_until(i159, i159+7) == i159+1);
+ assert(std::is_heap_until(i160, i160+7) == i160+1);
+ assert(std::is_heap_until(i161, i161+7) == i161+1);
+ assert(std::is_heap_until(i162, i162+7) == i162+1);
+ assert(std::is_heap_until(i163, i163+7) == i163+1);
+ assert(std::is_heap_until(i164, i164+7) == i164+1);
+ assert(std::is_heap_until(i165, i165+7) == i165+1);
+ assert(std::is_heap_until(i166, i166+7) == i166+1);
+ assert(std::is_heap_until(i167, i167+7) == i167+1);
+ assert(std::is_heap_until(i168, i168+7) == i168+1);
+ assert(std::is_heap_until(i169, i169+7) == i169+1);
+ assert(std::is_heap_until(i170, i170+7) == i170+1);
+ assert(std::is_heap_until(i171, i171+7) == i171+1);
+ assert(std::is_heap_until(i172, i172+7) == i172+1);
+ assert(std::is_heap_until(i173, i173+7) == i173+1);
+ assert(std::is_heap_until(i174, i174+7) == i174+1);
+ assert(std::is_heap_until(i175, i175+7) == i175+1);
+ assert(std::is_heap_until(i176, i176+7) == i176+1);
+ assert(std::is_heap_until(i177, i177+7) == i177+1);
+ assert(std::is_heap_until(i178, i178+7) == i178+1);
+ assert(std::is_heap_until(i179, i179+7) == i179+1);
+ assert(std::is_heap_until(i180, i180+7) == i180+1);
+ assert(std::is_heap_until(i181, i181+7) == i181+1);
+ assert(std::is_heap_until(i182, i182+7) == i182+1);
+ assert(std::is_heap_until(i183, i183+7) == i183+1);
+ assert(std::is_heap_until(i184, i184+7) == i184+7);
+ assert(std::is_heap_until(i185, i185+7) == i185+6);
+ assert(std::is_heap_until(i186, i186+7) == i186+5);
+ assert(std::is_heap_until(i187, i187+7) == i187+5);
+ assert(std::is_heap_until(i188, i188+7) == i188+4);
+ assert(std::is_heap_until(i189, i189+7) == i189+4);
+ assert(std::is_heap_until(i190, i190+7) == i190+4);
+ assert(std::is_heap_until(i191, i191+7) == i191+4);
+ assert(std::is_heap_until(i192, i192+7) == i192+3);
+ assert(std::is_heap_until(i193, i193+7) == i193+3);
+ assert(std::is_heap_until(i194, i194+7) == i194+3);
+ assert(std::is_heap_until(i195, i195+7) == i195+3);
+ assert(std::is_heap_until(i196, i196+7) == i196+3);
+ assert(std::is_heap_until(i197, i197+7) == i197+3);
+ assert(std::is_heap_until(i198, i198+7) == i198+3);
+ assert(std::is_heap_until(i199, i199+7) == i199+3);
+ assert(std::is_heap_until(i200, i200+7) == i200+7);
+ assert(std::is_heap_until(i201, i201+7) == i201+7);
+ assert(std::is_heap_until(i202, i202+7) == i202+7);
+ assert(std::is_heap_until(i203, i203+7) == i203+7);
+ assert(std::is_heap_until(i204, i204+7) == i204+4);
+ assert(std::is_heap_until(i205, i205+7) == i205+4);
+ assert(std::is_heap_until(i206, i206+7) == i206+4);
+ assert(std::is_heap_until(i207, i207+7) == i207+4);
+ assert(std::is_heap_until(i208, i208+7) == i208+3);
+ assert(std::is_heap_until(i209, i209+7) == i209+3);
+ assert(std::is_heap_until(i210, i210+7) == i210+3);
+ assert(std::is_heap_until(i211, i211+7) == i211+3);
+ assert(std::is_heap_until(i212, i212+7) == i212+3);
+ assert(std::is_heap_until(i213, i213+7) == i213+3);
+ assert(std::is_heap_until(i214, i214+7) == i214+3);
+ assert(std::is_heap_until(i215, i215+7) == i215+3);
+ assert(std::is_heap_until(i216, i216+7) == i216+7);
+ assert(std::is_heap_until(i217, i217+7) == i217+6);
+ assert(std::is_heap_until(i218, i218+7) == i218+5);
+ assert(std::is_heap_until(i219, i219+7) == i219+5);
+ assert(std::is_heap_until(i220, i220+7) == i220+7);
+ assert(std::is_heap_until(i221, i221+7) == i221+6);
+ assert(std::is_heap_until(i222, i222+7) == i222+5);
+ assert(std::is_heap_until(i223, i223+7) == i223+5);
+ assert(std::is_heap_until(i224, i224+7) == i224+7);
+ assert(std::is_heap_until(i225, i225+7) == i225+6);
+ assert(std::is_heap_until(i226, i226+7) == i226+5);
+ assert(std::is_heap_until(i227, i227+7) == i227+5);
+ assert(std::is_heap_until(i228, i228+7) == i228+7);
+ assert(std::is_heap_until(i229, i229+7) == i229+6);
+ assert(std::is_heap_until(i230, i230+7) == i230+5);
+ assert(std::is_heap_until(i231, i231+7) == i231+5);
+ assert(std::is_heap_until(i232, i232+7) == i232+7);
+ assert(std::is_heap_until(i233, i233+7) == i233+7);
+ assert(std::is_heap_until(i234, i234+7) == i234+7);
+ assert(std::is_heap_until(i235, i235+7) == i235+7);
+ assert(std::is_heap_until(i236, i236+7) == i236+7);
+ assert(std::is_heap_until(i237, i237+7) == i237+7);
+ assert(std::is_heap_until(i238, i238+7) == i238+7);
+ assert(std::is_heap_until(i239, i239+7) == i239+7);
+ assert(std::is_heap_until(i240, i240+7) == i240+7);
+ assert(std::is_heap_until(i241, i241+7) == i241+7);
+ assert(std::is_heap_until(i242, i242+7) == i242+7);
+ assert(std::is_heap_until(i243, i243+7) == i243+7);
+ assert(std::is_heap_until(i244, i244+7) == i244+7);
+ assert(std::is_heap_until(i245, i245+7) == i245+7);
+ assert(std::is_heap_until(i246, i246+7) == i246+7);
+}
+
+int main()
+{
+ test();
+}
diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.heap.operations/is.heap/is_heap_until_comp.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.heap.operations/is.heap/is_heap_until_comp.pass.cpp
new file mode 100644
index 00000000000..657c177fee5
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.sorting/alg.heap.operations/is.heap/is_heap_until_comp.pass.cpp
@@ -0,0 +1,522 @@
+//===----------------------------------------------------------------------===//
+//
+// 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<RandomAccessIterator Iter, StrictWeakOrder<auto, Iter::value_type> Compare>
+// requires CopyConstructible<Compare>
+// Iter
+// is_heap_until(Iter first, Iter last, Compare comp);
+
+#include <algorithm>
+#include <functional>
+#include <cassert>
+
+void test()
+{
+ int i1[] = {0, 0};
+ assert(std::is_heap_until(i1, i1, std::greater<int>()) == i1);
+ assert(std::is_heap_until(i1, i1+1, std::greater<int>()) == i1+1);
+ int i2[] = {0, 1};
+ int i3[] = {1, 0};
+ assert(std::is_heap_until(i1, i1+2, std::greater<int>()) == i1+2);
+ assert(std::is_heap_until(i2, i2+2, std::greater<int>()) == i2+2);
+ assert(std::is_heap_until(i3, i3+2, std::greater<int>()) == i3+1);
+ int i4[] = {0, 0, 0};
+ int i5[] = {0, 0, 1};
+ int i6[] = {0, 1, 0};
+ int i7[] = {0, 1, 1};
+ int i8[] = {1, 0, 0};
+ int i9[] = {1, 0, 1};
+ int i10[] = {1, 1, 0};
+ assert(std::is_heap_until(i4, i4+3, std::greater<int>()) == i4+3);
+ assert(std::is_heap_until(i5, i5+3, std::greater<int>()) == i5+3);
+ assert(std::is_heap_until(i6, i6+3, std::greater<int>()) == i6+3);
+ assert(std::is_heap_until(i7, i7+3, std::greater<int>()) == i7+3);
+ assert(std::is_heap_until(i8, i8+3, std::greater<int>()) == i8+1);
+ assert(std::is_heap_until(i9, i9+3, std::greater<int>()) == i9+1);
+ assert(std::is_heap_until(i10, i10+3, std::greater<int>()) == i10+2);
+ int i11[] = {0, 0, 0, 0};
+ int i12[] = {0, 0, 0, 1};
+ int i13[] = {0, 0, 1, 0};
+ int i14[] = {0, 0, 1, 1};
+ int i15[] = {0, 1, 0, 0};
+ int i16[] = {0, 1, 0, 1};
+ int i17[] = {0, 1, 1, 0};
+ int i18[] = {0, 1, 1, 1};
+ int i19[] = {1, 0, 0, 0};
+ int i20[] = {1, 0, 0, 1};
+ int i21[] = {1, 0, 1, 0};
+ int i22[] = {1, 0, 1, 1};
+ int i23[] = {1, 1, 0, 0};
+ int i24[] = {1, 1, 0, 1};
+ int i25[] = {1, 1, 1, 0};
+ assert(std::is_heap_until(i11, i11+4, std::greater<int>()) == i11+4);
+ assert(std::is_heap_until(i12, i12+4, std::greater<int>()) == i12+4);
+ assert(std::is_heap_until(i13, i13+4, std::greater<int>()) == i13+4);
+ assert(std::is_heap_until(i14, i14+4, std::greater<int>()) == i14+4);
+ assert(std::is_heap_until(i15, i15+4, std::greater<int>()) == i15+3);
+ assert(std::is_heap_until(i16, i16+4, std::greater<int>()) == i16+4);
+ assert(std::is_heap_until(i17, i17+4, std::greater<int>()) == i17+3);
+ assert(std::is_heap_until(i18, i18+4, std::greater<int>()) == i18+4);
+ assert(std::is_heap_until(i19, i19+4, std::greater<int>()) == i19+1);
+ assert(std::is_heap_until(i20, i20+4, std::greater<int>()) == i20+1);
+ assert(std::is_heap_until(i21, i21+4, std::greater<int>()) == i21+1);
+ assert(std::is_heap_until(i22, i22+4, std::greater<int>()) == i22+1);
+ assert(std::is_heap_until(i23, i23+4, std::greater<int>()) == i23+2);
+ assert(std::is_heap_until(i24, i24+4, std::greater<int>()) == i24+2);
+ assert(std::is_heap_until(i25, i25+4, std::greater<int>()) == i25+3);
+ int i26[] = {0, 0, 0, 0, 0};
+ int i27[] = {0, 0, 0, 0, 1};
+ int i28[] = {0, 0, 0, 1, 0};
+ int i29[] = {0, 0, 0, 1, 1};
+ int i30[] = {0, 0, 1, 0, 0};
+ int i31[] = {0, 0, 1, 0, 1};
+ int i32[] = {0, 0, 1, 1, 0};
+ int i33[] = {0, 0, 1, 1, 1};
+ int i34[] = {0, 1, 0, 0, 0};
+ int i35[] = {0, 1, 0, 0, 1};
+ int i36[] = {0, 1, 0, 1, 0};
+ int i37[] = {0, 1, 0, 1, 1};
+ int i38[] = {0, 1, 1, 0, 0};
+ int i39[] = {0, 1, 1, 0, 1};
+ int i40[] = {0, 1, 1, 1, 0};
+ int i41[] = {0, 1, 1, 1, 1};
+ int i42[] = {1, 0, 0, 0, 0};
+ int i43[] = {1, 0, 0, 0, 1};
+ int i44[] = {1, 0, 0, 1, 0};
+ int i45[] = {1, 0, 0, 1, 1};
+ int i46[] = {1, 0, 1, 0, 0};
+ int i47[] = {1, 0, 1, 0, 1};
+ int i48[] = {1, 0, 1, 1, 0};
+ int i49[] = {1, 0, 1, 1, 1};
+ int i50[] = {1, 1, 0, 0, 0};
+ int i51[] = {1, 1, 0, 0, 1};
+ int i52[] = {1, 1, 0, 1, 0};
+ int i53[] = {1, 1, 0, 1, 1};
+ int i54[] = {1, 1, 1, 0, 0};
+ int i55[] = {1, 1, 1, 0, 1};
+ int i56[] = {1, 1, 1, 1, 0};
+ assert(std::is_heap_until(i26, i26+5, std::greater<int>()) == i26+5);
+ assert(std::is_heap_until(i27, i27+5, std::greater<int>()) == i27+5);
+ assert(std::is_heap_until(i28, i28+5, std::greater<int>()) == i28+5);
+ assert(std::is_heap_until(i29, i29+5, std::greater<int>()) == i29+5);
+ assert(std::is_heap_until(i30, i30+5, std::greater<int>()) == i30+5);
+ assert(std::is_heap_until(i31, i31+5, std::greater<int>()) == i31+5);
+ assert(std::is_heap_until(i32, i32+5, std::greater<int>()) == i32+5);
+ assert(std::is_heap_until(i33, i33+5, std::greater<int>()) == i33+5);
+ assert(std::is_heap_until(i34, i34+5, std::greater<int>()) == i34+3);
+ assert(std::is_heap_until(i35, i35+5, std::greater<int>()) == i35+3);
+ assert(std::is_heap_until(i36, i36+5, std::greater<int>()) == i36+4);
+ assert(std::is_heap_until(i37, i37+5, std::greater<int>()) == i37+5);
+ assert(std::is_heap_until(i38, i38+5, std::greater<int>()) == i38+3);
+ assert(std::is_heap_until(i39, i39+5, std::greater<int>()) == i39+3);
+ assert(std::is_heap_until(i40, i40+5, std::greater<int>()) == i40+4);
+ assert(std::is_heap_until(i41, i41+5, std::greater<int>()) == i41+5);
+ assert(std::is_heap_until(i42, i42+5, std::greater<int>()) == i42+1);
+ assert(std::is_heap_until(i43, i43+5, std::greater<int>()) == i43+1);
+ assert(std::is_heap_until(i44, i44+5, std::greater<int>()) == i44+1);
+ assert(std::is_heap_until(i45, i45+5, std::greater<int>()) == i45+1);
+ assert(std::is_heap_until(i46, i46+5, std::greater<int>()) == i46+1);
+ assert(std::is_heap_until(i47, i47+5, std::greater<int>()) == i47+1);
+ assert(std::is_heap_until(i48, i48+5, std::greater<int>()) == i48+1);
+ assert(std::is_heap_until(i49, i49+5, std::greater<int>()) == i49+1);
+ assert(std::is_heap_until(i50, i50+5, std::greater<int>()) == i50+2);
+ assert(std::is_heap_until(i51, i51+5, std::greater<int>()) == i51+2);
+ assert(std::is_heap_until(i52, i52+5, std::greater<int>()) == i52+2);
+ assert(std::is_heap_until(i53, i53+5, std::greater<int>()) == i53+2);
+ assert(std::is_heap_until(i54, i54+5, std::greater<int>()) == i54+3);
+ assert(std::is_heap_until(i55, i55+5, std::greater<int>()) == i55+3);
+ assert(std::is_heap_until(i56, i56+5, std::greater<int>()) == i56+4);
+ int i57[] = {0, 0, 0, 0, 0, 0};
+ int i58[] = {0, 0, 0, 0, 0, 1};
+ int i59[] = {0, 0, 0, 0, 1, 0};
+ int i60[] = {0, 0, 0, 0, 1, 1};
+ int i61[] = {0, 0, 0, 1, 0, 0};
+ int i62[] = {0, 0, 0, 1, 0, 1};
+ int i63[] = {0, 0, 0, 1, 1, 0};
+ int i64[] = {0, 0, 0, 1, 1, 1};
+ int i65[] = {0, 0, 1, 0, 0, 0};
+ int i66[] = {0, 0, 1, 0, 0, 1};
+ int i67[] = {0, 0, 1, 0, 1, 0};
+ int i68[] = {0, 0, 1, 0, 1, 1};
+ int i69[] = {0, 0, 1, 1, 0, 0};
+ int i70[] = {0, 0, 1, 1, 0, 1};
+ int i71[] = {0, 0, 1, 1, 1, 0};
+ int i72[] = {0, 0, 1, 1, 1, 1};
+ int i73[] = {0, 1, 0, 0, 0, 0};
+ int i74[] = {0, 1, 0, 0, 0, 1};
+ int i75[] = {0, 1, 0, 0, 1, 0};
+ int i76[] = {0, 1, 0, 0, 1, 1};
+ int i77[] = {0, 1, 0, 1, 0, 0};
+ int i78[] = {0, 1, 0, 1, 0, 1};
+ int i79[] = {0, 1, 0, 1, 1, 0};
+ int i80[] = {0, 1, 0, 1, 1, 1};
+ int i81[] = {0, 1, 1, 0, 0, 0};
+ int i82[] = {0, 1, 1, 0, 0, 1};
+ int i83[] = {0, 1, 1, 0, 1, 0};
+ int i84[] = {0, 1, 1, 0, 1, 1};
+ int i85[] = {0, 1, 1, 1, 0, 0};
+ int i86[] = {0, 1, 1, 1, 0, 1};
+ int i87[] = {0, 1, 1, 1, 1, 0};
+ int i88[] = {0, 1, 1, 1, 1, 1};
+ int i89[] = {1, 0, 0, 0, 0, 0};
+ int i90[] = {1, 0, 0, 0, 0, 1};
+ int i91[] = {1, 0, 0, 0, 1, 0};
+ int i92[] = {1, 0, 0, 0, 1, 1};
+ int i93[] = {1, 0, 0, 1, 0, 0};
+ int i94[] = {1, 0, 0, 1, 0, 1};
+ int i95[] = {1, 0, 0, 1, 1, 0};
+ int i96[] = {1, 0, 0, 1, 1, 1};
+ int i97[] = {1, 0, 1, 0, 0, 0};
+ int i98[] = {1, 0, 1, 0, 0, 1};
+ int i99[] = {1, 0, 1, 0, 1, 0};
+ int i100[] = {1, 0, 1, 0, 1, 1};
+ int i101[] = {1, 0, 1, 1, 0, 0};
+ int i102[] = {1, 0, 1, 1, 0, 1};
+ int i103[] = {1, 0, 1, 1, 1, 0};
+ int i104[] = {1, 0, 1, 1, 1, 1};
+ int i105[] = {1, 1, 0, 0, 0, 0};
+ int i106[] = {1, 1, 0, 0, 0, 1};
+ int i107[] = {1, 1, 0, 0, 1, 0};
+ int i108[] = {1, 1, 0, 0, 1, 1};
+ int i109[] = {1, 1, 0, 1, 0, 0};
+ int i110[] = {1, 1, 0, 1, 0, 1};
+ int i111[] = {1, 1, 0, 1, 1, 0};
+ int i112[] = {1, 1, 0, 1, 1, 1};
+ int i113[] = {1, 1, 1, 0, 0, 0};
+ int i114[] = {1, 1, 1, 0, 0, 1};
+ int i115[] = {1, 1, 1, 0, 1, 0};
+ int i116[] = {1, 1, 1, 0, 1, 1};
+ int i117[] = {1, 1, 1, 1, 0, 0};
+ int i118[] = {1, 1, 1, 1, 0, 1};
+ int i119[] = {1, 1, 1, 1, 1, 0};
+ assert(std::is_heap_until(i57, i57+6, std::greater<int>()) == i57+6);
+ assert(std::is_heap_until(i58, i58+6, std::greater<int>()) == i58+6);
+ assert(std::is_heap_until(i59, i59+6, std::greater<int>()) == i59+6);
+ assert(std::is_heap_until(i60, i60+6, std::greater<int>()) == i60+6);
+ assert(std::is_heap_until(i61, i61+6, std::greater<int>()) == i61+6);
+ assert(std::is_heap_until(i62, i62+6, std::greater<int>()) == i62+6);
+ assert(std::is_heap_until(i63, i63+6, std::greater<int>()) == i63+6);
+ assert(std::is_heap_until(i64, i64+6, std::greater<int>()) == i64+6);
+ assert(std::is_heap_until(i65, i65+6, std::greater<int>()) == i65+5);
+ assert(std::is_heap_until(i66, i66+6, std::greater<int>()) == i66+6);
+ assert(std::is_heap_until(i67, i67+6, std::greater<int>()) == i67+5);
+ assert(std::is_heap_until(i68, i68+6, std::greater<int>()) == i68+6);
+ assert(std::is_heap_until(i69, i69+6, std::greater<int>()) == i69+5);
+ assert(std::is_heap_until(i70, i70+6, std::greater<int>()) == i70+6);
+ assert(std::is_heap_until(i71, i71+6, std::greater<int>()) == i71+5);
+ assert(std::is_heap_until(i72, i72+6, std::greater<int>()) == i72+6);
+ assert(std::is_heap_until(i73, i73+6, std::greater<int>()) == i73+3);
+ assert(std::is_heap_until(i74, i74+6, std::greater<int>()) == i74+3);
+ assert(std::is_heap_until(i75, i75+6, std::greater<int>()) == i75+3);
+ assert(std::is_heap_until(i76, i76+6, std::greater<int>()) == i76+3);
+ assert(std::is_heap_until(i77, i77+6, std::greater<int>()) == i77+4);
+ assert(std::is_heap_until(i78, i78+6, std::greater<int>()) == i78+4);
+ assert(std::is_heap_until(i79, i79+6, std::greater<int>()) == i79+6);
+ assert(std::is_heap_until(i80, i80+6, std::greater<int>()) == i80+6);
+ assert(std::is_heap_until(i81, i81+6, std::greater<int>()) == i81+3);
+ assert(std::is_heap_until(i82, i82+6, std::greater<int>()) == i82+3);
+ assert(std::is_heap_until(i83, i83+6, std::greater<int>()) == i83+3);
+ assert(std::is_heap_until(i84, i84+6, std::greater<int>()) == i84+3);
+ assert(std::is_heap_until(i85, i85+6, std::greater<int>()) == i85+4);
+ assert(std::is_heap_until(i86, i86+6, std::greater<int>()) == i86+4);
+ assert(std::is_heap_until(i87, i87+6, std::greater<int>()) == i87+5);
+ assert(std::is_heap_until(i88, i88+6, std::greater<int>()) == i88+6);
+ assert(std::is_heap_until(i89, i89+6, std::greater<int>()) == i89+1);
+ assert(std::is_heap_until(i90, i90+6, std::greater<int>()) == i90+1);
+ assert(std::is_heap_until(i91, i91+6, std::greater<int>()) == i91+1);
+ assert(std::is_heap_until(i92, i92+6, std::greater<int>()) == i92+1);
+ assert(std::is_heap_until(i93, i93+6, std::greater<int>()) == i93+1);
+ assert(std::is_heap_until(i94, i94+6, std::greater<int>()) == i94+1);
+ assert(std::is_heap_until(i95, i95+6, std::greater<int>()) == i95+1);
+ assert(std::is_heap_until(i96, i96+6, std::greater<int>()) == i96+1);
+ assert(std::is_heap_until(i97, i97+6, std::greater<int>()) == i97+1);
+ assert(std::is_heap_until(i98, i98+6, std::greater<int>()) == i98+1);
+ assert(std::is_heap_until(i99, i99+6, std::greater<int>()) == i99+1);
+ assert(std::is_heap_until(i100, i100+6, std::greater<int>()) == i100+1);
+ assert(std::is_heap_until(i101, i101+6, std::greater<int>()) == i101+1);
+ assert(std::is_heap_until(i102, i102+6, std::greater<int>()) == i102+1);
+ assert(std::is_heap_until(i103, i103+6, std::greater<int>()) == i103+1);
+ assert(std::is_heap_until(i104, i104+6, std::greater<int>()) == i104+1);
+ assert(std::is_heap_until(i105, i105+6, std::greater<int>()) == i105+2);
+ assert(std::is_heap_until(i106, i106+6, std::greater<int>()) == i106+2);
+ assert(std::is_heap_until(i107, i107+6, std::greater<int>()) == i107+2);
+ assert(std::is_heap_until(i108, i108+6, std::greater<int>()) == i108+2);
+ assert(std::is_heap_until(i109, i109+6, std::greater<int>()) == i109+2);
+ assert(std::is_heap_until(i110, i110+6, std::greater<int>()) == i110+2);
+ assert(std::is_heap_until(i111, i111+6, std::greater<int>()) == i111+2);
+ assert(std::is_heap_until(i112, i112+6, std::greater<int>()) == i112+2);
+ assert(std::is_heap_until(i113, i113+6, std::greater<int>()) == i113+3);
+ assert(std::is_heap_until(i114, i114+6, std::greater<int>()) == i114+3);
+ assert(std::is_heap_until(i115, i115+6, std::greater<int>()) == i115+3);
+ assert(std::is_heap_until(i116, i116+6, std::greater<int>()) == i116+3);
+ assert(std::is_heap_until(i117, i117+6, std::greater<int>()) == i117+4);
+ assert(std::is_heap_until(i118, i118+6, std::greater<int>()) == i118+4);
+ assert(std::is_heap_until(i119, i119+6, std::greater<int>()) == i119+5);
+ int i120[] = {0, 0, 0, 0, 0, 0, 0};
+ int i121[] = {0, 0, 0, 0, 0, 0, 1};
+ int i122[] = {0, 0, 0, 0, 0, 1, 0};
+ int i123[] = {0, 0, 0, 0, 0, 1, 1};
+ int i124[] = {0, 0, 0, 0, 1, 0, 0};
+ int i125[] = {0, 0, 0, 0, 1, 0, 1};
+ int i126[] = {0, 0, 0, 0, 1, 1, 0};
+ int i127[] = {0, 0, 0, 0, 1, 1, 1};
+ int i128[] = {0, 0, 0, 1, 0, 0, 0};
+ int i129[] = {0, 0, 0, 1, 0, 0, 1};
+ int i130[] = {0, 0, 0, 1, 0, 1, 0};
+ int i131[] = {0, 0, 0, 1, 0, 1, 1};
+ int i132[] = {0, 0, 0, 1, 1, 0, 0};
+ int i133[] = {0, 0, 0, 1, 1, 0, 1};
+ int i134[] = {0, 0, 0, 1, 1, 1, 0};
+ int i135[] = {0, 0, 0, 1, 1, 1, 1};
+ int i136[] = {0, 0, 1, 0, 0, 0, 0};
+ int i137[] = {0, 0, 1, 0, 0, 0, 1};
+ int i138[] = {0, 0, 1, 0, 0, 1, 0};
+ int i139[] = {0, 0, 1, 0, 0, 1, 1};
+ int i140[] = {0, 0, 1, 0, 1, 0, 0};
+ int i141[] = {0, 0, 1, 0, 1, 0, 1};
+ int i142[] = {0, 0, 1, 0, 1, 1, 0};
+ int i143[] = {0, 0, 1, 0, 1, 1, 1};
+ int i144[] = {0, 0, 1, 1, 0, 0, 0};
+ int i145[] = {0, 0, 1, 1, 0, 0, 1};
+ int i146[] = {0, 0, 1, 1, 0, 1, 0};
+ int i147[] = {0, 0, 1, 1, 0, 1, 1};
+ int i148[] = {0, 0, 1, 1, 1, 0, 0};
+ int i149[] = {0, 0, 1, 1, 1, 0, 1};
+ int i150[] = {0, 0, 1, 1, 1, 1, 0};
+ int i151[] = {0, 0, 1, 1, 1, 1, 1};
+ int i152[] = {0, 1, 0, 0, 0, 0, 0};
+ int i153[] = {0, 1, 0, 0, 0, 0, 1};
+ int i154[] = {0, 1, 0, 0, 0, 1, 0};
+ int i155[] = {0, 1, 0, 0, 0, 1, 1};
+ int i156[] = {0, 1, 0, 0, 1, 0, 0};
+ int i157[] = {0, 1, 0, 0, 1, 0, 1};
+ int i158[] = {0, 1, 0, 0, 1, 1, 0};
+ int i159[] = {0, 1, 0, 0, 1, 1, 1};
+ int i160[] = {0, 1, 0, 1, 0, 0, 0};
+ int i161[] = {0, 1, 0, 1, 0, 0, 1};
+ int i162[] = {0, 1, 0, 1, 0, 1, 0};
+ int i163[] = {0, 1, 0, 1, 0, 1, 1};
+ int i164[] = {0, 1, 0, 1, 1, 0, 0};
+ int i165[] = {0, 1, 0, 1, 1, 0, 1};
+ int i166[] = {0, 1, 0, 1, 1, 1, 0};
+ int i167[] = {0, 1, 0, 1, 1, 1, 1};
+ int i168[] = {0, 1, 1, 0, 0, 0, 0};
+ int i169[] = {0, 1, 1, 0, 0, 0, 1};
+ int i170[] = {0, 1, 1, 0, 0, 1, 0};
+ int i171[] = {0, 1, 1, 0, 0, 1, 1};
+ int i172[] = {0, 1, 1, 0, 1, 0, 0};
+ int i173[] = {0, 1, 1, 0, 1, 0, 1};
+ int i174[] = {0, 1, 1, 0, 1, 1, 0};
+ int i175[] = {0, 1, 1, 0, 1, 1, 1};
+ int i176[] = {0, 1, 1, 1, 0, 0, 0};
+ int i177[] = {0, 1, 1, 1, 0, 0, 1};
+ int i178[] = {0, 1, 1, 1, 0, 1, 0};
+ int i179[] = {0, 1, 1, 1, 0, 1, 1};
+ int i180[] = {0, 1, 1, 1, 1, 0, 0};
+ int i181[] = {0, 1, 1, 1, 1, 0, 1};
+ int i182[] = {0, 1, 1, 1, 1, 1, 0};
+ int i183[] = {0, 1, 1, 1, 1, 1, 1};
+ int i184[] = {1, 0, 0, 0, 0, 0, 0};
+ int i185[] = {1, 0, 0, 0, 0, 0, 1};
+ int i186[] = {1, 0, 0, 0, 0, 1, 0};
+ int i187[] = {1, 0, 0, 0, 0, 1, 1};
+ int i188[] = {1, 0, 0, 0, 1, 0, 0};
+ int i189[] = {1, 0, 0, 0, 1, 0, 1};
+ int i190[] = {1, 0, 0, 0, 1, 1, 0};
+ int i191[] = {1, 0, 0, 0, 1, 1, 1};
+ int i192[] = {1, 0, 0, 1, 0, 0, 0};
+ int i193[] = {1, 0, 0, 1, 0, 0, 1};
+ int i194[] = {1, 0, 0, 1, 0, 1, 0};
+ int i195[] = {1, 0, 0, 1, 0, 1, 1};
+ int i196[] = {1, 0, 0, 1, 1, 0, 0};
+ int i197[] = {1, 0, 0, 1, 1, 0, 1};
+ int i198[] = {1, 0, 0, 1, 1, 1, 0};
+ int i199[] = {1, 0, 0, 1, 1, 1, 1};
+ int i200[] = {1, 0, 1, 0, 0, 0, 0};
+ int i201[] = {1, 0, 1, 0, 0, 0, 1};
+ int i202[] = {1, 0, 1, 0, 0, 1, 0};
+ int i203[] = {1, 0, 1, 0, 0, 1, 1};
+ int i204[] = {1, 0, 1, 0, 1, 0, 0};
+ int i205[] = {1, 0, 1, 0, 1, 0, 1};
+ int i206[] = {1, 0, 1, 0, 1, 1, 0};
+ int i207[] = {1, 0, 1, 0, 1, 1, 1};
+ int i208[] = {1, 0, 1, 1, 0, 0, 0};
+ int i209[] = {1, 0, 1, 1, 0, 0, 1};
+ int i210[] = {1, 0, 1, 1, 0, 1, 0};
+ int i211[] = {1, 0, 1, 1, 0, 1, 1};
+ int i212[] = {1, 0, 1, 1, 1, 0, 0};
+ int i213[] = {1, 0, 1, 1, 1, 0, 1};
+ int i214[] = {1, 0, 1, 1, 1, 1, 0};
+ int i215[] = {1, 0, 1, 1, 1, 1, 1};
+ int i216[] = {1, 1, 0, 0, 0, 0, 0};
+ int i217[] = {1, 1, 0, 0, 0, 0, 1};
+ int i218[] = {1, 1, 0, 0, 0, 1, 0};
+ int i219[] = {1, 1, 0, 0, 0, 1, 1};
+ int i220[] = {1, 1, 0, 0, 1, 0, 0};
+ int i221[] = {1, 1, 0, 0, 1, 0, 1};
+ int i222[] = {1, 1, 0, 0, 1, 1, 0};
+ int i223[] = {1, 1, 0, 0, 1, 1, 1};
+ int i224[] = {1, 1, 0, 1, 0, 0, 0};
+ int i225[] = {1, 1, 0, 1, 0, 0, 1};
+ int i226[] = {1, 1, 0, 1, 0, 1, 0};
+ int i227[] = {1, 1, 0, 1, 0, 1, 1};
+ int i228[] = {1, 1, 0, 1, 1, 0, 0};
+ int i229[] = {1, 1, 0, 1, 1, 0, 1};
+ int i230[] = {1, 1, 0, 1, 1, 1, 0};
+ int i231[] = {1, 1, 0, 1, 1, 1, 1};
+ int i232[] = {1, 1, 1, 0, 0, 0, 0};
+ int i233[] = {1, 1, 1, 0, 0, 0, 1};
+ int i234[] = {1, 1, 1, 0, 0, 1, 0};
+ int i235[] = {1, 1, 1, 0, 0, 1, 1};
+ int i236[] = {1, 1, 1, 0, 1, 0, 0};
+ int i237[] = {1, 1, 1, 0, 1, 0, 1};
+ int i238[] = {1, 1, 1, 0, 1, 1, 0};
+ int i239[] = {1, 1, 1, 0, 1, 1, 1};
+ int i240[] = {1, 1, 1, 1, 0, 0, 0};
+ int i241[] = {1, 1, 1, 1, 0, 0, 1};
+ int i242[] = {1, 1, 1, 1, 0, 1, 0};
+ int i243[] = {1, 1, 1, 1, 0, 1, 1};
+ int i244[] = {1, 1, 1, 1, 1, 0, 0};
+ int i245[] = {1, 1, 1, 1, 1, 0, 1};
+ int i246[] = {1, 1, 1, 1, 1, 1, 0};
+ assert(std::is_heap_until(i120, i120+7, std::greater<int>()) == i120+7);
+ assert(std::is_heap_until(i121, i121+7, std::greater<int>()) == i121+7);
+ assert(std::is_heap_until(i122, i122+7, std::greater<int>()) == i122+7);
+ assert(std::is_heap_until(i123, i123+7, std::greater<int>()) == i123+7);
+ assert(std::is_heap_until(i124, i124+7, std::greater<int>()) == i124+7);
+ assert(std::is_heap_until(i125, i125+7, std::greater<int>()) == i125+7);
+ assert(std::is_heap_until(i126, i126+7, std::greater<int>()) == i126+7);
+ assert(std::is_heap_until(i127, i127+7, std::greater<int>()) == i127+7);
+ assert(std::is_heap_until(i128, i128+7, std::greater<int>()) == i128+7);
+ assert(std::is_heap_until(i129, i129+7, std::greater<int>()) == i129+7);
+ assert(std::is_heap_until(i130, i130+7, std::greater<int>()) == i130+7);
+ assert(std::is_heap_until(i131, i131+7, std::greater<int>()) == i131+7);
+ assert(std::is_heap_until(i132, i132+7, std::greater<int>()) == i132+7);
+ assert(std::is_heap_until(i133, i133+7, std::greater<int>()) == i133+7);
+ assert(std::is_heap_until(i134, i134+7, std::greater<int>()) == i134+7);
+ assert(std::is_heap_until(i135, i135+7, std::greater<int>()) == i135+7);
+ assert(std::is_heap_until(i136, i136+7, std::greater<int>()) == i136+5);
+ assert(std::is_heap_until(i137, i137+7, std::greater<int>()) == i137+5);
+ assert(std::is_heap_until(i138, i138+7, std::greater<int>()) == i138+6);
+ assert(std::is_heap_until(i139, i139+7, std::greater<int>()) == i139+7);
+ assert(std::is_heap_until(i140, i140+7, std::greater<int>()) == i140+5);
+ assert(std::is_heap_until(i141, i141+7, std::greater<int>()) == i141+5);
+ assert(std::is_heap_until(i142, i142+7, std::greater<int>()) == i142+6);
+ assert(std::is_heap_until(i143, i143+7, std::greater<int>()) == i143+7);
+ assert(std::is_heap_until(i144, i144+7, std::greater<int>()) == i144+5);
+ assert(std::is_heap_until(i145, i145+7, std::greater<int>()) == i145+5);
+ assert(std::is_heap_until(i146, i146+7, std::greater<int>()) == i146+6);
+ assert(std::is_heap_until(i147, i147+7, std::greater<int>()) == i147+7);
+ assert(std::is_heap_until(i148, i148+7, std::greater<int>()) == i148+5);
+ assert(std::is_heap_until(i149, i149+7, std::greater<int>()) == i149+5);
+ assert(std::is_heap_until(i150, i150+7, std::greater<int>()) == i150+6);
+ assert(std::is_heap_until(i151, i151+7, std::greater<int>()) == i151+7);
+ assert(std::is_heap_until(i152, i152+7, std::greater<int>()) == i152+3);
+ assert(std::is_heap_until(i153, i153+7, std::greater<int>()) == i153+3);
+ assert(std::is_heap_until(i154, i154+7, std::greater<int>()) == i154+3);
+ assert(std::is_heap_until(i155, i155+7, std::greater<int>()) == i155+3);
+ assert(std::is_heap_until(i156, i156+7, std::greater<int>()) == i156+3);
+ assert(std::is_heap_until(i157, i157+7, std::greater<int>()) == i157+3);
+ assert(std::is_heap_until(i158, i158+7, std::greater<int>()) == i158+3);
+ assert(std::is_heap_until(i159, i159+7, std::greater<int>()) == i159+3);
+ assert(std::is_heap_until(i160, i160+7, std::greater<int>()) == i160+4);
+ assert(std::is_heap_until(i161, i161+7, std::greater<int>()) == i161+4);
+ assert(std::is_heap_until(i162, i162+7, std::greater<int>()) == i162+4);
+ assert(std::is_heap_until(i163, i163+7, std::greater<int>()) == i163+4);
+ assert(std::is_heap_until(i164, i164+7, std::greater<int>()) == i164+7);
+ assert(std::is_heap_until(i165, i165+7, std::greater<int>()) == i165+7);
+ assert(std::is_heap_until(i166, i166+7, std::greater<int>()) == i166+7);
+ assert(std::is_heap_until(i167, i167+7, std::greater<int>()) == i167+7);
+ assert(std::is_heap_until(i168, i168+7, std::greater<int>()) == i168+3);
+ assert(std::is_heap_until(i169, i169+7, std::greater<int>()) == i169+3);
+ assert(std::is_heap_until(i170, i170+7, std::greater<int>()) == i170+3);
+ assert(std::is_heap_until(i171, i171+7, std::greater<int>()) == i171+3);
+ assert(std::is_heap_until(i172, i172+7, std::greater<int>()) == i172+3);
+ assert(std::is_heap_until(i173, i173+7, std::greater<int>()) == i173+3);
+ assert(std::is_heap_until(i174, i174+7, std::greater<int>()) == i174+3);
+ assert(std::is_heap_until(i175, i175+7, std::greater<int>()) == i175+3);
+ assert(std::is_heap_until(i176, i176+7, std::greater<int>()) == i176+4);
+ assert(std::is_heap_until(i177, i177+7, std::greater<int>()) == i177+4);
+ assert(std::is_heap_until(i178, i178+7, std::greater<int>()) == i178+4);
+ assert(std::is_heap_until(i179, i179+7, std::greater<int>()) == i179+4);
+ assert(std::is_heap_until(i180, i180+7, std::greater<int>()) == i180+5);
+ assert(std::is_heap_until(i181, i181+7, std::greater<int>()) == i181+5);
+ assert(std::is_heap_until(i182, i182+7, std::greater<int>()) == i182+6);
+ assert(std::is_heap_until(i183, i183+7, std::greater<int>()) == i183+7);
+ assert(std::is_heap_until(i184, i184+7, std::greater<int>()) == i184+1);
+ assert(std::is_heap_until(i185, i185+7, std::greater<int>()) == i185+1);
+ assert(std::is_heap_until(i186, i186+7, std::greater<int>()) == i186+1);
+ assert(std::is_heap_until(i187, i187+7, std::greater<int>()) == i187+1);
+ assert(std::is_heap_until(i188, i188+7, std::greater<int>()) == i188+1);
+ assert(std::is_heap_until(i189, i189+7, std::greater<int>()) == i189+1);
+ assert(std::is_heap_until(i190, i190+7, std::greater<int>()) == i190+1);
+ assert(std::is_heap_until(i191, i191+7, std::greater<int>()) == i191+1);
+ assert(std::is_heap_until(i192, i192+7, std::greater<int>()) == i192+1);
+ assert(std::is_heap_until(i193, i193+7, std::greater<int>()) == i193+1);
+ assert(std::is_heap_until(i194, i194+7, std::greater<int>()) == i194+1);
+ assert(std::is_heap_until(i195, i195+7, std::greater<int>()) == i195+1);
+ assert(std::is_heap_until(i196, i196+7, std::greater<int>()) == i196+1);
+ assert(std::is_heap_until(i197, i197+7, std::greater<int>()) == i197+1);
+ assert(std::is_heap_until(i198, i198+7, std::greater<int>()) == i198+1);
+ assert(std::is_heap_until(i199, i199+7, std::greater<int>()) == i199+1);
+ assert(std::is_heap_until(i200, i200+7, std::greater<int>()) == i200+1);
+ assert(std::is_heap_until(i201, i201+7, std::greater<int>()) == i201+1);
+ assert(std::is_heap_until(i202, i202+7, std::greater<int>()) == i202+1);
+ assert(std::is_heap_until(i203, i203+7, std::greater<int>()) == i203+1);
+ assert(std::is_heap_until(i204, i204+7, std::greater<int>()) == i204+1);
+ assert(std::is_heap_until(i205, i205+7, std::greater<int>()) == i205+1);
+ assert(std::is_heap_until(i206, i206+7, std::greater<int>()) == i206+1);
+ assert(std::is_heap_until(i207, i207+7, std::greater<int>()) == i207+1);
+ assert(std::is_heap_until(i208, i208+7, std::greater<int>()) == i208+1);
+ assert(std::is_heap_until(i209, i209+7, std::greater<int>()) == i209+1);
+ assert(std::is_heap_until(i210, i210+7, std::greater<int>()) == i210+1);
+ assert(std::is_heap_until(i211, i211+7, std::greater<int>()) == i211+1);
+ assert(std::is_heap_until(i212, i212+7, std::greater<int>()) == i212+1);
+ assert(std::is_heap_until(i213, i213+7, std::greater<int>()) == i213+1);
+ assert(std::is_heap_until(i214, i214+7, std::greater<int>()) == i214+1);
+ assert(std::is_heap_until(i215, i215+7, std::greater<int>()) == i215+1);
+ assert(std::is_heap_until(i216, i216+7, std::greater<int>()) == i216+2);
+ assert(std::is_heap_until(i217, i217+7, std::greater<int>()) == i217+2);
+ assert(std::is_heap_until(i218, i218+7, std::greater<int>()) == i218+2);
+ assert(std::is_heap_until(i219, i219+7, std::greater<int>()) == i219+2);
+ assert(std::is_heap_until(i220, i220+7, std::greater<int>()) == i220+2);
+ assert(std::is_heap_until(i221, i221+7, std::greater<int>()) == i221+2);
+ assert(std::is_heap_until(i222, i222+7, std::greater<int>()) == i222+2);
+ assert(std::is_heap_until(i223, i223+7, std::greater<int>()) == i223+2);
+ assert(std::is_heap_until(i224, i224+7, std::greater<int>()) == i224+2);
+ assert(std::is_heap_until(i225, i225+7, std::greater<int>()) == i225+2);
+ assert(std::is_heap_until(i226, i226+7, std::greater<int>()) == i226+2);
+ assert(std::is_heap_until(i227, i227+7, std::greater<int>()) == i227+2);
+ assert(std::is_heap_until(i228, i228+7, std::greater<int>()) == i228+2);
+ assert(std::is_heap_until(i229, i229+7, std::greater<int>()) == i229+2);
+ assert(std::is_heap_until(i230, i230+7, std::greater<int>()) == i230+2);
+ assert(std::is_heap_until(i231, i231+7, std::greater<int>()) == i231+2);
+ assert(std::is_heap_until(i232, i232+7, std::greater<int>()) == i232+3);
+ assert(std::is_heap_until(i233, i233+7, std::greater<int>()) == i233+3);
+ assert(std::is_heap_until(i234, i234+7, std::greater<int>()) == i234+3);
+ assert(std::is_heap_until(i235, i235+7, std::greater<int>()) == i235+3);
+ assert(std::is_heap_until(i236, i236+7, std::greater<int>()) == i236+3);
+ assert(std::is_heap_until(i237, i237+7, std::greater<int>()) == i237+3);
+ assert(std::is_heap_until(i238, i238+7, std::greater<int>()) == i238+3);
+ assert(std::is_heap_until(i239, i239+7, std::greater<int>()) == i239+3);
+ assert(std::is_heap_until(i240, i240+7, std::greater<int>()) == i240+4);
+ assert(std::is_heap_until(i241, i241+7, std::greater<int>()) == i241+4);
+ assert(std::is_heap_until(i242, i242+7, std::greater<int>()) == i242+4);
+ assert(std::is_heap_until(i243, i243+7, std::greater<int>()) == i243+4);
+ assert(std::is_heap_until(i244, i244+7, std::greater<int>()) == i244+5);
+ assert(std::is_heap_until(i245, i245+7, std::greater<int>()) == i245+5);
+ assert(std::is_heap_until(i246, i246+7, std::greater<int>()) == i246+6);
+}
+
+int main()
+{
+ test();
+}
diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.heap.operations/make.heap/make_heap.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.heap.operations/make.heap/make_heap.pass.cpp
new file mode 100644
index 00000000000..51b912768f3
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.sorting/alg.heap.operations/make.heap/make_heap.pass.cpp
@@ -0,0 +1,39 @@
+//===----------------------------------------------------------------------===//
+//
+// 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<RandomAccessIterator Iter>
+// requires ShuffleIterator<Iter> && LessThanComparable<Iter::value_type>
+// void
+// make_heap(Iter first, Iter last);
+
+#include <algorithm>
+#include <cassert>
+
+void test(unsigned N)
+{
+ int* ia = new int [N];
+ for (int i = 0; i < N; ++i)
+ ia[i] = i;
+ std::random_shuffle(ia, ia+N);
+ std::make_heap(ia, ia+N);
+ assert(std::is_heap(ia, ia+N));
+ delete [] ia;
+}
+
+int main()
+{
+ test(0);
+ test(1);
+ test(2);
+ test(3);
+ test(10);
+ test(1000);
+}
diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.heap.operations/make.heap/make_heap_comp.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.heap.operations/make.heap/make_heap_comp.pass.cpp
new file mode 100644
index 00000000000..4cde1a7d32e
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.sorting/alg.heap.operations/make.heap/make_heap_comp.pass.cpp
@@ -0,0 +1,101 @@
+//===----------------------------------------------------------------------===//
+//
+// 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<RandomAccessIterator Iter, StrictWeakOrder<auto, Iter::value_type> Compare>
+// requires ShuffleIterator<Iter> && CopyConstructible<Compare>
+// void
+// make_heap(Iter first, Iter last, Compare comp);
+
+#include <algorithm>
+#include <functional>
+#include <cassert>
+
+#include "counting_predicates.hpp"
+
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+#include <memory>
+
+struct indirect_less
+{
+ template <class P>
+ bool operator()(const P& x, const P& y)
+ {return *x < *y;}
+};
+
+#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
+
+void test(unsigned N)
+{
+ int* ia = new int [N];
+ {
+ for (int i = 0; i < N; ++i)
+ ia[i] = i;
+ std::random_shuffle(ia, ia+N);
+ std::make_heap(ia, ia+N, std::greater<int>());
+ assert(std::is_heap(ia, ia+N, std::greater<int>()));
+ }
+
+// Ascending
+ {
+ binary_counting_predicate<std::greater<int>, int, int> pred ((std::greater<int>()));
+ for (int i = 0; i < N; ++i)
+ ia[i] = i;
+ std::make_heap(ia, ia+N, std::ref(pred));
+ assert(pred.count() <= 3*N);
+ assert(std::is_heap(ia, ia+N, pred));
+ }
+
+// Descending
+ {
+ binary_counting_predicate<std::greater<int>, int, int> pred ((std::greater<int>()));
+ for (int i = 0; i < N; ++i)
+ ia[N-1-i] = i;
+ std::make_heap(ia, ia+N, std::ref(pred));
+ assert(pred.count() <= 3*N);
+ assert(std::is_heap(ia, ia+N, pred));
+ }
+
+// Random
+ {
+ binary_counting_predicate<std::greater<int>, int, int> pred ((std::greater<int>()));
+ std::random_shuffle(ia, ia+N);
+ std::make_heap(ia, ia+N, std::ref(pred));
+ assert(pred.count() <= 3*N);
+ assert(std::is_heap(ia, ia+N, pred));
+ }
+
+ delete [] ia;
+}
+
+int main()
+{
+ test(0);
+ test(1);
+ test(2);
+ test(3);
+ test(10);
+ test(1000);
+ test(10000);
+ test(100000);
+
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+ {
+ const int N = 1000;
+ std::unique_ptr<int>* ia = new std::unique_ptr<int> [N];
+ for (int i = 0; i < N; ++i)
+ ia[i].reset(new int(i));
+ std::random_shuffle(ia, ia+N);
+ std::make_heap(ia, ia+N, indirect_less());
+ assert(std::is_heap(ia, ia+N, indirect_less()));
+ delete [] ia;
+ }
+#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
+}
diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.heap.operations/nothing_to_do.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.heap.operations/nothing_to_do.pass.cpp
new file mode 100644
index 00000000000..b58f5c55b64
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.sorting/alg.heap.operations/nothing_to_do.pass.cpp
@@ -0,0 +1,12 @@
+//===----------------------------------------------------------------------===//
+//
+// 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.
+//
+//===----------------------------------------------------------------------===//
+
+int main()
+{
+}
diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.heap.operations/pop.heap/pop_heap.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.heap.operations/pop.heap/pop_heap.pass.cpp
new file mode 100644
index 00000000000..823985df6ca
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.sorting/alg.heap.operations/pop.heap/pop_heap.pass.cpp
@@ -0,0 +1,39 @@
+//===----------------------------------------------------------------------===//
+//
+// 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<RandomAccessIterator Iter>
+// requires ShuffleIterator<Iter> && LessThanComparable<Iter::value_type>
+// void
+// pop_heap(Iter first, Iter last);
+
+#include <algorithm>
+#include <cassert>
+
+void test(unsigned N)
+{
+ int* ia = new int [N];
+ for (int i = 0; i < N; ++i)
+ ia[i] = i;
+ std::random_shuffle(ia, ia+N);
+ std::make_heap(ia, ia+N);
+ for (int i = N; i > 0; --i)
+ {
+ std::pop_heap(ia, ia+i);
+ assert(std::is_heap(ia, ia+i-1));
+ }
+ std::pop_heap(ia, ia);
+ delete [] ia;
+}
+
+int main()
+{
+ test(1000);
+}
diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.heap.operations/pop.heap/pop_heap_comp.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.heap.operations/pop.heap/pop_heap_comp.pass.cpp
new file mode 100644
index 00000000000..1db4428a1c1
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.sorting/alg.heap.operations/pop.heap/pop_heap_comp.pass.cpp
@@ -0,0 +1,68 @@
+//===----------------------------------------------------------------------===//
+//
+// 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<RandomAccessIterator Iter, StrictWeakOrder<auto, Iter::value_type> Compare>
+// requires ShuffleIterator<Iter> && CopyConstructible<Compare>
+// void
+// pop_heap(Iter first, Iter last, Compare comp);
+
+#include <algorithm>
+#include <functional>
+#include <cassert>
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+#include <memory>
+
+struct indirect_less
+{
+ template <class P>
+ bool operator()(const P& x, const P& y)
+ {return *x < *y;}
+};
+
+#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
+
+void test(unsigned N)
+{
+ int* ia = new int [N];
+ for (int i = 0; i < N; ++i)
+ ia[i] = i;
+ std::random_shuffle(ia, ia+N);
+ std::make_heap(ia, ia+N, std::greater<int>());
+ for (int i = N; i > 0; --i)
+ {
+ std::pop_heap(ia, ia+i, std::greater<int>());
+ assert(std::is_heap(ia, ia+i-1, std::greater<int>()));
+ }
+ std::pop_heap(ia, ia, std::greater<int>());
+ delete [] ia;
+}
+
+int main()
+{
+ test(1000);
+
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+ {
+ const int N = 1000;
+ std::unique_ptr<int>* ia = new std::unique_ptr<int> [N];
+ for (int i = 0; i < N; ++i)
+ ia[i].reset(new int(i));
+ std::random_shuffle(ia, ia+N);
+ std::make_heap(ia, ia+N, indirect_less());
+ for (int i = N; i > 0; --i)
+ {
+ std::pop_heap(ia, ia+i, indirect_less());
+ assert(std::is_heap(ia, ia+i-1, indirect_less()));
+ }
+ delete [] ia;
+ }
+#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
+}
diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.heap.operations/push.heap/push_heap.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.heap.operations/push.heap/push_heap.pass.cpp
new file mode 100644
index 00000000000..0fc50a81207
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.sorting/alg.heap.operations/push.heap/push_heap.pass.cpp
@@ -0,0 +1,38 @@
+//===----------------------------------------------------------------------===//
+//
+// 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<RandomAccessIterator Iter>
+// requires ShuffleIterator<Iter>
+// && LessThanComparable<Iter::value_type>
+// void
+// push_heap(Iter first, Iter last);
+
+#include <algorithm>
+#include <cassert>
+
+void test(unsigned N)
+{
+ int* ia = new int [N];
+ for (int i = 0; i < N; ++i)
+ ia[i] = i;
+ std::random_shuffle(ia, ia+N);
+ for (int i = 0; i <= N; ++i)
+ {
+ std::push_heap(ia, ia+i);
+ assert(std::is_heap(ia, ia+i));
+ }
+ delete [] ia;
+}
+
+int main()
+{
+ test(1000);
+}
diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.heap.operations/push.heap/push_heap_comp.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.heap.operations/push.heap/push_heap_comp.pass.cpp
new file mode 100644
index 00000000000..217217b38ee
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.sorting/alg.heap.operations/push.heap/push_heap_comp.pass.cpp
@@ -0,0 +1,66 @@
+//===----------------------------------------------------------------------===//
+//
+// 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<RandomAccessIterator Iter>
+// requires ShuffleIterator<Iter>
+// && LessThanComparable<Iter::value_type>
+// void
+// push_heap(Iter first, Iter last);
+
+#include <algorithm>
+#include <functional>
+#include <cassert>
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+#include <memory>
+
+struct indirect_less
+{
+ template <class P>
+ bool operator()(const P& x, const P& y)
+ {return *x < *y;}
+};
+
+#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
+
+void test(unsigned N)
+{
+ int* ia = new int [N];
+ for (int i = 0; i < N; ++i)
+ ia[i] = i;
+ std::random_shuffle(ia, ia+N);
+ for (int i = 0; i <= N; ++i)
+ {
+ std::push_heap(ia, ia+i, std::greater<int>());
+ assert(std::is_heap(ia, ia+i, std::greater<int>()));
+ }
+ delete [] ia;
+}
+
+int main()
+{
+ test(1000);
+
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+ {
+ const int N = 1000;
+ std::unique_ptr<int>* ia = new std::unique_ptr<int> [N];
+ for (int i = 0; i < N; ++i)
+ ia[i].reset(new int(i));
+ std::random_shuffle(ia, ia+N);
+ for (int i = 0; i <= N; ++i)
+ {
+ std::push_heap(ia, ia+i, indirect_less());
+ assert(std::is_heap(ia, ia+i, indirect_less()));
+ }
+ delete [] ia;
+ }
+#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
+}
diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.heap.operations/sort.heap/sort_heap.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.heap.operations/sort.heap/sort_heap.pass.cpp
new file mode 100644
index 00000000000..4a08f111e6d
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.sorting/alg.heap.operations/sort.heap/sort_heap.pass.cpp
@@ -0,0 +1,40 @@
+//===----------------------------------------------------------------------===//
+//
+// 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<RandomAccessIterator Iter>
+// requires ShuffleIterator<Iter> && LessThanComparable<Iter::value_type>
+// void
+// sort_heap(Iter first, Iter last);
+
+#include <algorithm>
+#include <cassert>
+
+void test(unsigned N)
+{
+ int* ia = new int [N];
+ for (int i = 0; i < N; ++i)
+ ia[i] = i;
+ std::random_shuffle(ia, ia+N);
+ std::make_heap(ia, ia+N);
+ std::sort_heap(ia, ia+N);
+ assert(std::is_sorted(ia, ia+N));
+ delete [] ia;
+}
+
+int main()
+{
+ test(0);
+ test(1);
+ test(2);
+ test(3);
+ test(10);
+ test(1000);
+}
diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.heap.operations/sort.heap/sort_heap_comp.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.heap.operations/sort.heap/sort_heap_comp.pass.cpp
new file mode 100644
index 00000000000..7d3e2d57015
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.sorting/alg.heap.operations/sort.heap/sort_heap_comp.pass.cpp
@@ -0,0 +1,66 @@
+//===----------------------------------------------------------------------===//
+//
+// 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<RandomAccessIterator Iter, StrictWeakOrder<auto, Iter::value_type> Compare>
+// requires ShuffleIterator<Iter> && CopyConstructible<Compare>
+// void
+// sort_heap(Iter first, Iter last, Compare comp);
+
+#include <algorithm>
+#include <functional>
+#include <cassert>
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+#include <memory>
+
+struct indirect_less
+{
+ template <class P>
+ bool operator()(const P& x, const P& y)
+ {return *x < *y;}
+};
+
+#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
+
+void test(unsigned N)
+{
+ int* ia = new int [N];
+ for (int i = 0; i < N; ++i)
+ ia[i] = i;
+ std::random_shuffle(ia, ia+N);
+ std::make_heap(ia, ia+N, std::greater<int>());
+ std::sort_heap(ia, ia+N, std::greater<int>());
+ assert(std::is_sorted(ia, ia+N, std::greater<int>()));
+ delete [] ia;
+}
+
+int main()
+{
+ test(0);
+ test(1);
+ test(2);
+ test(3);
+ test(10);
+ test(1000);
+
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+ {
+ const int N = 1000;
+ std::unique_ptr<int>* ia = new std::unique_ptr<int> [N];
+ for (int i = 0; i < N; ++i)
+ ia[i].reset(new int(i));
+ std::random_shuffle(ia, ia+N);
+ std::make_heap(ia, ia+N, indirect_less());
+ std::sort_heap(ia, ia+N, indirect_less());
+ assert(std::is_sorted(ia, ia+N, indirect_less()));
+ delete [] ia;
+ }
+#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
+}
diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.lex.comparison/lexicographical_compare.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.lex.comparison/lexicographical_compare.pass.cpp
new file mode 100644
index 00000000000..71dfeefe7e4
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.sorting/alg.lex.comparison/lexicographical_compare.pass.cpp
@@ -0,0 +1,69 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 Iter1, InputIterator Iter2>
+// requires HasLess<Iter1::value_type, Iter2::value_type>
+// && HasLess<Iter2::value_type, Iter1::value_type>
+// bool
+// lexicographical_compare(Iter1 first1, Iter1 last1, Iter2 first2, Iter2 last2);
+
+#include <algorithm>
+#include <cassert>
+
+#include "test_iterators.h"
+
+template <class Iter1, class Iter2>
+void
+test()
+{
+ int ia[] = {1, 2, 3, 4};
+ const unsigned sa = sizeof(ia)/sizeof(ia[0]);
+ int ib[] = {1, 2, 3};
+ assert(!std::lexicographical_compare(Iter1(ia), Iter1(ia+sa), Iter2(ib), Iter2(ib+2)));
+ assert( std::lexicographical_compare(Iter1(ib), Iter1(ib+2), Iter2(ia), Iter2(ia+sa)));
+ assert(!std::lexicographical_compare(Iter1(ia), Iter1(ia+sa), Iter2(ib), Iter2(ib+3)));
+ assert( std::lexicographical_compare(Iter1(ib), Iter1(ib+3), Iter2(ia), Iter2(ia+sa)));
+ assert( std::lexicographical_compare(Iter1(ia), Iter1(ia+sa), Iter2(ib+1), Iter2(ib+3)));
+ assert(!std::lexicographical_compare(Iter1(ib+1), Iter1(ib+3), Iter2(ia), Iter2(ia+sa)));
+}
+
+int main()
+{
+ test<input_iterator<const int*>, input_iterator<const int*> >();
+ test<input_iterator<const int*>, forward_iterator<const int*> >();
+ test<input_iterator<const int*>, bidirectional_iterator<const int*> >();
+ test<input_iterator<const int*>, random_access_iterator<const int*> >();
+ test<input_iterator<const int*>, const int*>();
+
+ test<forward_iterator<const int*>, input_iterator<const int*> >();
+ test<forward_iterator<const int*>, forward_iterator<const int*> >();
+ test<forward_iterator<const int*>, bidirectional_iterator<const int*> >();
+ test<forward_iterator<const int*>, random_access_iterator<const int*> >();
+ test<forward_iterator<const int*>, const int*>();
+
+ test<bidirectional_iterator<const int*>, input_iterator<const int*> >();
+ test<bidirectional_iterator<const int*>, forward_iterator<const int*> >();
+ test<bidirectional_iterator<const int*>, bidirectional_iterator<const int*> >();
+ test<bidirectional_iterator<const int*>, random_access_iterator<const int*> >();
+ test<bidirectional_iterator<const int*>, const int*>();
+
+ test<random_access_iterator<const int*>, input_iterator<const int*> >();
+ test<random_access_iterator<const int*>, forward_iterator<const int*> >();
+ test<random_access_iterator<const int*>, bidirectional_iterator<const int*> >();
+ test<random_access_iterator<const int*>, random_access_iterator<const int*> >();
+ test<random_access_iterator<const int*>, const int*>();
+
+ test<const int*, input_iterator<const int*> >();
+ test<const int*, forward_iterator<const int*> >();
+ test<const int*, bidirectional_iterator<const int*> >();
+ test<const int*, random_access_iterator<const int*> >();
+ test<const int*, const int*>();
+}
diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.lex.comparison/lexicographical_compare_comp.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.lex.comparison/lexicographical_compare_comp.pass.cpp
new file mode 100644
index 00000000000..c1851560ef2
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.sorting/alg.lex.comparison/lexicographical_compare_comp.pass.cpp
@@ -0,0 +1,73 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 Iter1, InputIterator Iter2, CopyConstructible Compare>
+// requires Predicate<Compare, Iter1::value_type, Iter2::value_type>
+// && Predicate<Compare, Iter2::value_type, Iter1::value_type>
+// bool
+// lexicographical_compare(Iter1 first1, Iter1 last1,
+// Iter2 first2, Iter2 last2, Compare comp);
+
+#include <algorithm>
+#include <functional>
+#include <cassert>
+
+#include "test_iterators.h"
+
+template <class Iter1, class Iter2>
+void
+test()
+{
+ int ia[] = {1, 2, 3, 4};
+ const unsigned sa = sizeof(ia)/sizeof(ia[0]);
+ int ib[] = {1, 2, 3};
+ typedef std::greater<int> C;
+ C c;
+ assert(!std::lexicographical_compare(Iter1(ia), Iter1(ia+sa), Iter2(ib), Iter2(ib+2), c));
+ assert( std::lexicographical_compare(Iter1(ib), Iter1(ib+2), Iter2(ia), Iter2(ia+sa), c));
+ assert(!std::lexicographical_compare(Iter1(ia), Iter1(ia+sa), Iter2(ib), Iter2(ib+3), c));
+ assert( std::lexicographical_compare(Iter1(ib), Iter1(ib+3), Iter2(ia), Iter2(ia+sa), c));
+ assert(!std::lexicographical_compare(Iter1(ia), Iter1(ia+sa), Iter2(ib+1), Iter2(ib+3), c));
+ assert( std::lexicographical_compare(Iter1(ib+1), Iter1(ib+3), Iter2(ia), Iter2(ia+sa), c));
+}
+
+int main()
+{
+ test<input_iterator<const int*>, input_iterator<const int*> >();
+ test<input_iterator<const int*>, forward_iterator<const int*> >();
+ test<input_iterator<const int*>, bidirectional_iterator<const int*> >();
+ test<input_iterator<const int*>, random_access_iterator<const int*> >();
+ test<input_iterator<const int*>, const int*>();
+
+ test<forward_iterator<const int*>, input_iterator<const int*> >();
+ test<forward_iterator<const int*>, forward_iterator<const int*> >();
+ test<forward_iterator<const int*>, bidirectional_iterator<const int*> >();
+ test<forward_iterator<const int*>, random_access_iterator<const int*> >();
+ test<forward_iterator<const int*>, const int*>();
+
+ test<bidirectional_iterator<const int*>, input_iterator<const int*> >();
+ test<bidirectional_iterator<const int*>, forward_iterator<const int*> >();
+ test<bidirectional_iterator<const int*>, bidirectional_iterator<const int*> >();
+ test<bidirectional_iterator<const int*>, random_access_iterator<const int*> >();
+ test<bidirectional_iterator<const int*>, const int*>();
+
+ test<random_access_iterator<const int*>, input_iterator<const int*> >();
+ test<random_access_iterator<const int*>, forward_iterator<const int*> >();
+ test<random_access_iterator<const int*>, bidirectional_iterator<const int*> >();
+ test<random_access_iterator<const int*>, random_access_iterator<const int*> >();
+ test<random_access_iterator<const int*>, const int*>();
+
+ test<const int*, input_iterator<const int*> >();
+ test<const int*, forward_iterator<const int*> >();
+ test<const int*, bidirectional_iterator<const int*> >();
+ test<const int*, random_access_iterator<const int*> >();
+ test<const int*, const int*>();
+}
diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.merge/inplace_merge.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.merge/inplace_merge.pass.cpp
new file mode 100644
index 00000000000..01db088aa43
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.sorting/alg.merge/inplace_merge.pass.cpp
@@ -0,0 +1,79 @@
+//===----------------------------------------------------------------------===//
+//
+// 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<BidirectionalIterator Iter>
+// requires ShuffleIterator<Iter>
+// && LessThanComparable<Iter::value_type>
+// void
+// inplace_merge(Iter first, Iter middle, Iter last);
+
+#include <algorithm>
+#include <cassert>
+
+#include "test_iterators.h"
+
+template <class Iter>
+void
+test_one(unsigned N, unsigned M)
+{
+ assert(M <= N);
+ int* ia = new int[N];
+ for (unsigned i = 0; i < N; ++i)
+ ia[i] = i;
+ std::random_shuffle(ia, ia+N);
+ std::sort(ia, ia+M);
+ std::sort(ia+M, ia+N);
+ std::inplace_merge(Iter(ia), Iter(ia+M), Iter(ia+N));
+ if(N > 0)
+ {
+ assert(ia[0] == 0);
+ assert(ia[N-1] == N-1);
+ assert(std::is_sorted(ia, ia+N));
+ }
+ delete [] ia;
+}
+
+template <class Iter>
+void
+test(unsigned N)
+{
+ test_one<Iter>(N, 0);
+ test_one<Iter>(N, N/4);
+ test_one<Iter>(N, N/2);
+ test_one<Iter>(N, 3*N/4);
+ test_one<Iter>(N, N);
+}
+
+template <class Iter>
+void
+test()
+{
+ test_one<Iter>(0, 0);
+ test_one<Iter>(1, 0);
+ test_one<Iter>(1, 1);
+ test_one<Iter>(2, 0);
+ test_one<Iter>(2, 1);
+ test_one<Iter>(2, 2);
+ test_one<Iter>(3, 0);
+ test_one<Iter>(3, 1);
+ test_one<Iter>(3, 2);
+ test_one<Iter>(3, 3);
+ test<Iter>(4);
+ test<Iter>(100);
+ test<Iter>(1000);
+}
+
+int main()
+{
+ test<bidirectional_iterator<int*> >();
+ test<random_access_iterator<int*> >();
+ test<int*>();
+}
diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.merge/inplace_merge_comp.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.merge/inplace_merge_comp.pass.cpp
new file mode 100644
index 00000000000..8da8dfee719
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.sorting/alg.merge/inplace_merge_comp.pass.cpp
@@ -0,0 +1,112 @@
+//===----------------------------------------------------------------------===//
+//
+// 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<BidirectionalIterator Iter, StrictWeakOrder<auto, Iter::value_type> Compare>
+// requires ShuffleIterator<Iter>
+// && CopyConstructible<Compare>
+// void
+// inplace_merge(Iter first, Iter middle, Iter last, Compare comp);
+
+#include <algorithm>
+#include <functional>
+#include <cassert>
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+#include <memory>
+
+struct indirect_less
+{
+ template <class P>
+ bool operator()(const P& x, const P& y)
+ {return *x < *y;}
+};
+
+#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
+
+#include "test_iterators.h"
+
+template <class Iter>
+void
+test_one(unsigned N, unsigned M)
+{
+ assert(M <= N);
+ int* ia = new int[N];
+ for (unsigned i = 0; i < N; ++i)
+ ia[i] = i;
+ std::random_shuffle(ia, ia+N);
+ std::sort(ia, ia+M, std::greater<int>());
+ std::sort(ia+M, ia+N, std::greater<int>());
+ std::inplace_merge(Iter(ia), Iter(ia+M), Iter(ia+N), std::greater<int>());
+ if(N > 0)
+ {
+ assert(ia[0] == N-1);
+ assert(ia[N-1] == 0);
+ assert(std::is_sorted(ia, ia+N, std::greater<int>()));
+ }
+ delete [] ia;
+}
+
+template <class Iter>
+void
+test(unsigned N)
+{
+ test_one<Iter>(N, 0);
+ test_one<Iter>(N, N/4);
+ test_one<Iter>(N, N/2);
+ test_one<Iter>(N, 3*N/4);
+ test_one<Iter>(N, N);
+}
+
+template <class Iter>
+void
+test()
+{
+ test_one<Iter>(0, 0);
+ test_one<Iter>(1, 0);
+ test_one<Iter>(1, 1);
+ test_one<Iter>(2, 0);
+ test_one<Iter>(2, 1);
+ test_one<Iter>(2, 2);
+ test_one<Iter>(3, 0);
+ test_one<Iter>(3, 1);
+ test_one<Iter>(3, 2);
+ test_one<Iter>(3, 3);
+ test<Iter>(4);
+ test<Iter>(100);
+ test<Iter>(1000);
+}
+
+int main()
+{
+ test<bidirectional_iterator<int*> >();
+ test<random_access_iterator<int*> >();
+ test<int*>();
+
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+ {
+ unsigned N = 100;
+ unsigned M = 50;
+ std::unique_ptr<int>* ia = new std::unique_ptr<int>[N];
+ for (unsigned i = 0; i < N; ++i)
+ ia[i].reset(new int(i));
+ std::random_shuffle(ia, ia+N);
+ std::sort(ia, ia+M, indirect_less());
+ std::sort(ia+M, ia+N, indirect_less());
+ std::inplace_merge(ia, ia+M, ia+N, indirect_less());
+ if(N > 0)
+ {
+ assert(*ia[0] == 0);
+ assert(*ia[N-1] == N-1);
+ assert(std::is_sorted(ia, ia+N, indirect_less()));
+ }
+ delete [] ia;
+ }
+#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
+}
diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.merge/merge.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.merge/merge.pass.cpp
new file mode 100644
index 00000000000..de96c419c4e
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.sorting/alg.merge/merge.pass.cpp
@@ -0,0 +1,224 @@
+//===----------------------------------------------------------------------===//
+//
+// 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.
+//
+//===----------------------------------------------------------------------===//
+//
+// REQUIRES: long_tests
+
+// <algorithm>
+
+// template<InputIterator InIter1, InputIterator InIter2, typename OutIter>
+// requires OutputIterator<OutIter, InIter1::reference>
+// && OutputIterator<OutIter, InIter2::reference>
+// && HasLess<InIter2::value_type, InIter1::value_type>
+// OutIter
+// merge(InIter1 first1, InIter1 last1, InIter2 first2, InIter2 last2, OutIter result);
+
+#include <algorithm>
+#include <cassert>
+
+#include "test_iterators.h"
+
+template <class InIter1, class InIter2, class OutIter>
+void
+test()
+{
+ {
+ unsigned N = 100000;
+ int* ia = new int[N];
+ int* ib = new int[N];
+ int* ic = new int[2*N];
+ for (unsigned i = 0; i < N; ++i)
+ ia[i] = 2*i;
+ for (unsigned i = 0; i < N; ++i)
+ ib[i] = 2*i+1;
+ OutIter r = std::merge(InIter1(ia), InIter1(ia+N),
+ InIter2(ib), InIter2(ib+N), OutIter(ic));
+ assert(base(r) == ic+2*N);
+ assert(ic[0] == 0);
+ assert(ic[2*N-1] == 2*N-1);
+ assert(std::is_sorted(ic, ic+2*N));
+ delete [] ic;
+ delete [] ib;
+ delete [] ia;
+ }
+ {
+ unsigned N = 100;
+ int* ia = new int[N];
+ int* ib = new int[N];
+ int* ic = new int[2*N];
+ for (unsigned i = 0; i < 2*N; ++i)
+ ic[i] = i;
+ std::random_shuffle(ic, ic+2*N);
+ std::copy(ic, ic+N, ia);
+ std::copy(ic+N, ic+2*N, ib);
+ std::sort(ia, ia+N);
+ std::sort(ib, ib+N);
+ OutIter r = std::merge(InIter1(ia), InIter1(ia+N),
+ InIter2(ib), InIter2(ib+N), OutIter(ic));
+ assert(base(r) == ic+2*N);
+ assert(ic[0] == 0);
+ assert(ic[2*N-1] == 2*N-1);
+ assert(std::is_sorted(ic, ic+2*N));
+ delete [] ic;
+ delete [] ib;
+ delete [] ia;
+ }
+}
+
+int main()
+{
+ test<input_iterator<const int*>, input_iterator<const int*>, output_iterator<int*> >();
+ test<input_iterator<const int*>, input_iterator<const int*>, forward_iterator<int*> >();
+ test<input_iterator<const int*>, input_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<input_iterator<const int*>, input_iterator<const int*>, random_access_iterator<int*> >();
+ test<input_iterator<const int*>, input_iterator<const int*>, int*>();
+
+ test<input_iterator<const int*>, forward_iterator<const int*>, output_iterator<int*> >();
+ test<input_iterator<const int*>, forward_iterator<const int*>, forward_iterator<int*> >();
+ test<input_iterator<const int*>, forward_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<input_iterator<const int*>, forward_iterator<const int*>, random_access_iterator<int*> >();
+ test<input_iterator<const int*>, forward_iterator<const int*>, int*>();
+
+ test<input_iterator<const int*>, bidirectional_iterator<const int*>, output_iterator<int*> >();
+ test<input_iterator<const int*>, bidirectional_iterator<const int*>, forward_iterator<int*> >();
+ test<input_iterator<const int*>, bidirectional_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<input_iterator<const int*>, bidirectional_iterator<const int*>, random_access_iterator<int*> >();
+ test<input_iterator<const int*>, bidirectional_iterator<const int*>, int*>();
+
+ test<input_iterator<const int*>, random_access_iterator<const int*>, output_iterator<int*> >();
+ test<input_iterator<const int*>, random_access_iterator<const int*>, forward_iterator<int*> >();
+ test<input_iterator<const int*>, random_access_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<input_iterator<const int*>, random_access_iterator<const int*>, random_access_iterator<int*> >();
+ test<input_iterator<const int*>, random_access_iterator<const int*>, int*>();
+
+ test<input_iterator<const int*>, const int*, output_iterator<int*> >();
+ test<input_iterator<const int*>, const int*, forward_iterator<int*> >();
+ test<input_iterator<const int*>, const int*, bidirectional_iterator<int*> >();
+ test<input_iterator<const int*>, const int*, random_access_iterator<int*> >();
+ test<input_iterator<const int*>, const int*, int*>();
+
+ test<forward_iterator<const int*>, input_iterator<const int*>, output_iterator<int*> >();
+ test<forward_iterator<const int*>, input_iterator<const int*>, forward_iterator<int*> >();
+ test<forward_iterator<const int*>, input_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<forward_iterator<const int*>, input_iterator<const int*>, random_access_iterator<int*> >();
+ test<forward_iterator<const int*>, input_iterator<const int*>, int*>();
+
+ test<forward_iterator<const int*>, forward_iterator<const int*>, output_iterator<int*> >();
+ test<forward_iterator<const int*>, forward_iterator<const int*>, forward_iterator<int*> >();
+ test<forward_iterator<const int*>, forward_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<forward_iterator<const int*>, forward_iterator<const int*>, random_access_iterator<int*> >();
+ test<forward_iterator<const int*>, forward_iterator<const int*>, int*>();
+
+ test<forward_iterator<const int*>, bidirectional_iterator<const int*>, output_iterator<int*> >();
+ test<forward_iterator<const int*>, bidirectional_iterator<const int*>, forward_iterator<int*> >();
+ test<forward_iterator<const int*>, bidirectional_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<forward_iterator<const int*>, bidirectional_iterator<const int*>, random_access_iterator<int*> >();
+ test<forward_iterator<const int*>, bidirectional_iterator<const int*>, int*>();
+
+ test<forward_iterator<const int*>, random_access_iterator<const int*>, output_iterator<int*> >();
+ test<forward_iterator<const int*>, random_access_iterator<const int*>, forward_iterator<int*> >();
+ test<forward_iterator<const int*>, random_access_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<forward_iterator<const int*>, random_access_iterator<const int*>, random_access_iterator<int*> >();
+ test<forward_iterator<const int*>, random_access_iterator<const int*>, int*>();
+
+ test<forward_iterator<const int*>, const int*, output_iterator<int*> >();
+ test<forward_iterator<const int*>, const int*, forward_iterator<int*> >();
+ test<forward_iterator<const int*>, const int*, bidirectional_iterator<int*> >();
+ test<forward_iterator<const int*>, const int*, random_access_iterator<int*> >();
+ test<forward_iterator<const int*>, const int*, int*>();
+
+ test<bidirectional_iterator<const int*>, input_iterator<const int*>, output_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, input_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, input_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, input_iterator<const int*>, random_access_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, input_iterator<const int*>, int*>();
+
+ test<bidirectional_iterator<const int*>, forward_iterator<const int*>, output_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, forward_iterator<const int*>, forward_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, forward_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, forward_iterator<const int*>, random_access_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, forward_iterator<const int*>, int*>();
+
+ test<bidirectional_iterator<const int*>, bidirectional_iterator<const int*>, output_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, bidirectional_iterator<const int*>, forward_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, bidirectional_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, bidirectional_iterator<const int*>, random_access_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, bidirectional_iterator<const int*>, int*>();
+
+ test<bidirectional_iterator<const int*>, random_access_iterator<const int*>, output_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, random_access_iterator<const int*>, forward_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, random_access_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, random_access_iterator<const int*>, random_access_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, random_access_iterator<const int*>, int*>();
+
+ test<bidirectional_iterator<const int*>, const int*, output_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, const int*, forward_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, const int*, bidirectional_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, const int*, random_access_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, const int*, int*>();
+
+ test<random_access_iterator<const int*>, input_iterator<const int*>, output_iterator<int*> >();
+ test<random_access_iterator<const int*>, input_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<random_access_iterator<const int*>, input_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<random_access_iterator<const int*>, input_iterator<const int*>, random_access_iterator<int*> >();
+ test<random_access_iterator<const int*>, input_iterator<const int*>, int*>();
+
+ test<random_access_iterator<const int*>, forward_iterator<const int*>, output_iterator<int*> >();
+ test<random_access_iterator<const int*>, forward_iterator<const int*>, forward_iterator<int*> >();
+ test<random_access_iterator<const int*>, forward_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<random_access_iterator<const int*>, forward_iterator<const int*>, random_access_iterator<int*> >();
+ test<random_access_iterator<const int*>, forward_iterator<const int*>, int*>();
+
+ test<random_access_iterator<const int*>, bidirectional_iterator<const int*>, output_iterator<int*> >();
+ test<random_access_iterator<const int*>, bidirectional_iterator<const int*>, forward_iterator<int*> >();
+ test<random_access_iterator<const int*>, bidirectional_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<random_access_iterator<const int*>, bidirectional_iterator<const int*>, random_access_iterator<int*> >();
+ test<random_access_iterator<const int*>, bidirectional_iterator<const int*>, int*>();
+
+ test<random_access_iterator<const int*>, random_access_iterator<const int*>, output_iterator<int*> >();
+ test<random_access_iterator<const int*>, random_access_iterator<const int*>, forward_iterator<int*> >();
+ test<random_access_iterator<const int*>, random_access_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<random_access_iterator<const int*>, random_access_iterator<const int*>, random_access_iterator<int*> >();
+ test<random_access_iterator<const int*>, random_access_iterator<const int*>, int*>();
+
+ test<random_access_iterator<const int*>, const int*, output_iterator<int*> >();
+ test<random_access_iterator<const int*>, const int*, forward_iterator<int*> >();
+ test<random_access_iterator<const int*>, const int*, bidirectional_iterator<int*> >();
+ test<random_access_iterator<const int*>, const int*, random_access_iterator<int*> >();
+ test<random_access_iterator<const int*>, const int*, int*>();
+
+ test<const int*, input_iterator<const int*>, output_iterator<int*> >();
+ test<const int*, input_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<const int*, input_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<const int*, input_iterator<const int*>, random_access_iterator<int*> >();
+ test<const int*, input_iterator<const int*>, int*>();
+
+ test<const int*, forward_iterator<const int*>, output_iterator<int*> >();
+ test<const int*, forward_iterator<const int*>, forward_iterator<int*> >();
+ test<const int*, forward_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<const int*, forward_iterator<const int*>, random_access_iterator<int*> >();
+ test<const int*, forward_iterator<const int*>, int*>();
+
+ test<const int*, bidirectional_iterator<const int*>, output_iterator<int*> >();
+ test<const int*, bidirectional_iterator<const int*>, forward_iterator<int*> >();
+ test<const int*, bidirectional_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<const int*, bidirectional_iterator<const int*>, random_access_iterator<int*> >();
+ test<const int*, bidirectional_iterator<const int*>, int*>();
+
+ test<const int*, random_access_iterator<const int*>, output_iterator<int*> >();
+ test<const int*, random_access_iterator<const int*>, forward_iterator<int*> >();
+ test<const int*, random_access_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<const int*, random_access_iterator<const int*>, random_access_iterator<int*> >();
+ test<const int*, random_access_iterator<const int*>, int*>();
+
+ test<const int*, const int*, output_iterator<int*> >();
+ test<const int*, const int*, forward_iterator<int*> >();
+ test<const int*, const int*, bidirectional_iterator<int*> >();
+ test<const int*, const int*, random_access_iterator<int*> >();
+ test<const int*, const int*, int*>();
+}
diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.merge/merge_comp.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.merge/merge_comp.pass.cpp
new file mode 100644
index 00000000000..69bcaf1198b
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.sorting/alg.merge/merge_comp.pass.cpp
@@ -0,0 +1,229 @@
+//===----------------------------------------------------------------------===//
+//
+// 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.
+//
+//===----------------------------------------------------------------------===//
+//
+// REQUIRES: long_tests
+
+// <algorithm>
+
+// template<InputIterator InIter1, InputIterator InIter2, typename OutIter,
+// Predicate<auto, InIter2::value_type, InIter1::value_type> Compare>
+// requires OutputIterator<OutIter, InIter1::reference>
+// && OutputIterator<OutIter, InIter2::reference>
+// && CopyConstructible<Compare>
+// OutIter
+// merge(InIter1 first1, InIter1 last1,
+// InIter2 first2, InIter2 last2, OutIter result, Compare comp);
+
+#include <algorithm>
+#include <functional>
+#include <cassert>
+
+#include "test_iterators.h"
+
+template <class InIter1, class InIter2, class OutIter>
+void
+test()
+{
+ {
+ unsigned N = 100000;
+ int* ia = new int[N];
+ int* ib = new int[N];
+ int* ic = new int[2*N];
+ for (unsigned i = 0; i < N; ++i)
+ ia[i] = 2*i;
+ for (unsigned i = 0; i < N; ++i)
+ ib[i] = 2*i+1;
+ std::reverse(ia, ia+N);
+ std::reverse(ib, ib+N);
+ OutIter r = std::merge(InIter1(ia), InIter1(ia+N),
+ InIter2(ib), InIter2(ib+N), OutIter(ic), std::greater<int>());
+ assert(base(r) == ic+2*N);
+ assert(ic[0] == 2*N-1);
+ assert(ic[2*N-1] == 0);
+ assert(std::is_sorted(ic, ic+2*N, std::greater<int>()));
+ delete [] ic;
+ delete [] ib;
+ delete [] ia;
+ }
+ {
+ unsigned N = 100;
+ int* ia = new int[N];
+ int* ib = new int[N];
+ int* ic = new int[2*N];
+ for (unsigned i = 0; i < 2*N; ++i)
+ ic[i] = i;
+ std::random_shuffle(ic, ic+2*N);
+ std::copy(ic, ic+N, ia);
+ std::copy(ic+N, ic+2*N, ib);
+ std::sort(ia, ia+N, std::greater<int>());
+ std::sort(ib, ib+N, std::greater<int>());
+ OutIter r = std::merge(InIter1(ia), InIter1(ia+N),
+ InIter2(ib), InIter2(ib+N), OutIter(ic), std::greater<int>());
+ assert(base(r) == ic+2*N);
+ assert(ic[0] == 2*N-1);
+ assert(ic[2*N-1] == 0);
+ assert(std::is_sorted(ic, ic+2*N, std::greater<int>()));
+ delete [] ic;
+ delete [] ib;
+ delete [] ia;
+ }
+}
+
+int main()
+{
+ test<input_iterator<const int*>, input_iterator<const int*>, output_iterator<int*> >();
+ test<input_iterator<const int*>, input_iterator<const int*>, forward_iterator<int*> >();
+ test<input_iterator<const int*>, input_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<input_iterator<const int*>, input_iterator<const int*>, random_access_iterator<int*> >();
+ test<input_iterator<const int*>, input_iterator<const int*>, int*>();
+
+ test<input_iterator<const int*>, forward_iterator<const int*>, output_iterator<int*> >();
+ test<input_iterator<const int*>, forward_iterator<const int*>, forward_iterator<int*> >();
+ test<input_iterator<const int*>, forward_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<input_iterator<const int*>, forward_iterator<const int*>, random_access_iterator<int*> >();
+ test<input_iterator<const int*>, forward_iterator<const int*>, int*>();
+
+ test<input_iterator<const int*>, bidirectional_iterator<const int*>, output_iterator<int*> >();
+ test<input_iterator<const int*>, bidirectional_iterator<const int*>, forward_iterator<int*> >();
+ test<input_iterator<const int*>, bidirectional_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<input_iterator<const int*>, bidirectional_iterator<const int*>, random_access_iterator<int*> >();
+ test<input_iterator<const int*>, bidirectional_iterator<const int*>, int*>();
+
+ test<input_iterator<const int*>, random_access_iterator<const int*>, output_iterator<int*> >();
+ test<input_iterator<const int*>, random_access_iterator<const int*>, forward_iterator<int*> >();
+ test<input_iterator<const int*>, random_access_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<input_iterator<const int*>, random_access_iterator<const int*>, random_access_iterator<int*> >();
+ test<input_iterator<const int*>, random_access_iterator<const int*>, int*>();
+
+ test<input_iterator<const int*>, const int*, output_iterator<int*> >();
+ test<input_iterator<const int*>, const int*, forward_iterator<int*> >();
+ test<input_iterator<const int*>, const int*, bidirectional_iterator<int*> >();
+ test<input_iterator<const int*>, const int*, random_access_iterator<int*> >();
+ test<input_iterator<const int*>, const int*, int*>();
+
+ test<forward_iterator<const int*>, input_iterator<const int*>, output_iterator<int*> >();
+ test<forward_iterator<const int*>, input_iterator<const int*>, forward_iterator<int*> >();
+ test<forward_iterator<const int*>, input_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<forward_iterator<const int*>, input_iterator<const int*>, random_access_iterator<int*> >();
+ test<forward_iterator<const int*>, input_iterator<const int*>, int*>();
+
+ test<forward_iterator<const int*>, forward_iterator<const int*>, output_iterator<int*> >();
+ test<forward_iterator<const int*>, forward_iterator<const int*>, forward_iterator<int*> >();
+ test<forward_iterator<const int*>, forward_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<forward_iterator<const int*>, forward_iterator<const int*>, random_access_iterator<int*> >();
+ test<forward_iterator<const int*>, forward_iterator<const int*>, int*>();
+
+ test<forward_iterator<const int*>, bidirectional_iterator<const int*>, output_iterator<int*> >();
+ test<forward_iterator<const int*>, bidirectional_iterator<const int*>, forward_iterator<int*> >();
+ test<forward_iterator<const int*>, bidirectional_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<forward_iterator<const int*>, bidirectional_iterator<const int*>, random_access_iterator<int*> >();
+ test<forward_iterator<const int*>, bidirectional_iterator<const int*>, int*>();
+
+ test<forward_iterator<const int*>, random_access_iterator<const int*>, output_iterator<int*> >();
+ test<forward_iterator<const int*>, random_access_iterator<const int*>, forward_iterator<int*> >();
+ test<forward_iterator<const int*>, random_access_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<forward_iterator<const int*>, random_access_iterator<const int*>, random_access_iterator<int*> >();
+ test<forward_iterator<const int*>, random_access_iterator<const int*>, int*>();
+
+ test<forward_iterator<const int*>, const int*, output_iterator<int*> >();
+ test<forward_iterator<const int*>, const int*, forward_iterator<int*> >();
+ test<forward_iterator<const int*>, const int*, bidirectional_iterator<int*> >();
+ test<forward_iterator<const int*>, const int*, random_access_iterator<int*> >();
+ test<forward_iterator<const int*>, const int*, int*>();
+
+ test<bidirectional_iterator<const int*>, input_iterator<const int*>, output_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, input_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, input_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, input_iterator<const int*>, random_access_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, input_iterator<const int*>, int*>();
+
+ test<bidirectional_iterator<const int*>, forward_iterator<const int*>, output_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, forward_iterator<const int*>, forward_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, forward_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, forward_iterator<const int*>, random_access_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, forward_iterator<const int*>, int*>();
+
+ test<bidirectional_iterator<const int*>, bidirectional_iterator<const int*>, output_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, bidirectional_iterator<const int*>, forward_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, bidirectional_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, bidirectional_iterator<const int*>, random_access_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, bidirectional_iterator<const int*>, int*>();
+
+ test<bidirectional_iterator<const int*>, random_access_iterator<const int*>, output_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, random_access_iterator<const int*>, forward_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, random_access_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, random_access_iterator<const int*>, random_access_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, random_access_iterator<const int*>, int*>();
+
+ test<bidirectional_iterator<const int*>, const int*, output_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, const int*, forward_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, const int*, bidirectional_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, const int*, random_access_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, const int*, int*>();
+
+ test<random_access_iterator<const int*>, input_iterator<const int*>, output_iterator<int*> >();
+ test<random_access_iterator<const int*>, input_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<random_access_iterator<const int*>, input_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<random_access_iterator<const int*>, input_iterator<const int*>, random_access_iterator<int*> >();
+ test<random_access_iterator<const int*>, input_iterator<const int*>, int*>();
+
+ test<random_access_iterator<const int*>, forward_iterator<const int*>, output_iterator<int*> >();
+ test<random_access_iterator<const int*>, forward_iterator<const int*>, forward_iterator<int*> >();
+ test<random_access_iterator<const int*>, forward_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<random_access_iterator<const int*>, forward_iterator<const int*>, random_access_iterator<int*> >();
+ test<random_access_iterator<const int*>, forward_iterator<const int*>, int*>();
+
+ test<random_access_iterator<const int*>, bidirectional_iterator<const int*>, output_iterator<int*> >();
+ test<random_access_iterator<const int*>, bidirectional_iterator<const int*>, forward_iterator<int*> >();
+ test<random_access_iterator<const int*>, bidirectional_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<random_access_iterator<const int*>, bidirectional_iterator<const int*>, random_access_iterator<int*> >();
+ test<random_access_iterator<const int*>, bidirectional_iterator<const int*>, int*>();
+
+ test<random_access_iterator<const int*>, random_access_iterator<const int*>, output_iterator<int*> >();
+ test<random_access_iterator<const int*>, random_access_iterator<const int*>, forward_iterator<int*> >();
+ test<random_access_iterator<const int*>, random_access_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<random_access_iterator<const int*>, random_access_iterator<const int*>, random_access_iterator<int*> >();
+ test<random_access_iterator<const int*>, random_access_iterator<const int*>, int*>();
+
+ test<random_access_iterator<const int*>, const int*, output_iterator<int*> >();
+ test<random_access_iterator<const int*>, const int*, forward_iterator<int*> >();
+ test<random_access_iterator<const int*>, const int*, bidirectional_iterator<int*> >();
+ test<random_access_iterator<const int*>, const int*, random_access_iterator<int*> >();
+ test<random_access_iterator<const int*>, const int*, int*>();
+
+ test<const int*, input_iterator<const int*>, output_iterator<int*> >();
+ test<const int*, input_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<const int*, input_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<const int*, input_iterator<const int*>, random_access_iterator<int*> >();
+ test<const int*, input_iterator<const int*>, int*>();
+
+ test<const int*, forward_iterator<const int*>, output_iterator<int*> >();
+ test<const int*, forward_iterator<const int*>, forward_iterator<int*> >();
+ test<const int*, forward_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<const int*, forward_iterator<const int*>, random_access_iterator<int*> >();
+ test<const int*, forward_iterator<const int*>, int*>();
+
+ test<const int*, bidirectional_iterator<const int*>, output_iterator<int*> >();
+ test<const int*, bidirectional_iterator<const int*>, forward_iterator<int*> >();
+ test<const int*, bidirectional_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<const int*, bidirectional_iterator<const int*>, random_access_iterator<int*> >();
+ test<const int*, bidirectional_iterator<const int*>, int*>();
+
+ test<const int*, random_access_iterator<const int*>, output_iterator<int*> >();
+ test<const int*, random_access_iterator<const int*>, forward_iterator<int*> >();
+ test<const int*, random_access_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<const int*, random_access_iterator<const int*>, random_access_iterator<int*> >();
+ test<const int*, random_access_iterator<const int*>, int*>();
+
+ test<const int*, const int*, output_iterator<int*> >();
+ test<const int*, const int*, forward_iterator<int*> >();
+ test<const int*, const int*, bidirectional_iterator<int*> >();
+ test<const int*, const int*, random_access_iterator<int*> >();
+ test<const int*, const int*, int*>();
+}
diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.min.max/max.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.min.max/max.pass.cpp
new file mode 100644
index 00000000000..c560c22f2d7
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.sorting/alg.min.max/max.pass.cpp
@@ -0,0 +1,54 @@
+//===----------------------------------------------------------------------===//
+//
+// 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<LessThanComparable T>
+// const T&
+// max(const T& a, const T& b);
+
+#include <algorithm>
+#include <cassert>
+
+template <class T>
+void
+test(const T& a, const T& b, const T& x)
+{
+ assert(&std::max(a, b) == &x);
+}
+
+int main()
+{
+ {
+ int x = 0;
+ int y = 0;
+ test(x, y, x);
+ test(y, x, y);
+ }
+ {
+ int x = 0;
+ int y = 1;
+ test(x, y, y);
+ test(y, x, y);
+ }
+ {
+ int x = 1;
+ int y = 0;
+ test(x, y, x);
+ test(y, x, x);
+ }
+#if _LIBCPP_STD_VER > 11
+ {
+ constexpr int x = 1;
+ constexpr int y = 0;
+ static_assert(std::max(x, y) == x, "" );
+ static_assert(std::max(y, x) == x, "" );
+ }
+#endif
+}
diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.min.max/max_comp.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.min.max/max_comp.pass.cpp
new file mode 100644
index 00000000000..95241af5006
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.sorting/alg.min.max/max_comp.pass.cpp
@@ -0,0 +1,56 @@
+//===----------------------------------------------------------------------===//
+//
+// 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<class T, StrictWeakOrder<auto, T> Compare>
+// requires !SameType<T, Compare> && CopyConstructible<Compare>
+// const T&
+// max(const T& a, const T& b, Compare comp);
+
+#include <algorithm>
+#include <functional>
+#include <cassert>
+
+template <class T, class C>
+void
+test(const T& a, const T& b, C c, const T& x)
+{
+ assert(&std::max(a, b, c) == &x);
+}
+
+int main()
+{
+ {
+ int x = 0;
+ int y = 0;
+ test(x, y, std::greater<int>(), x);
+ test(y, x, std::greater<int>(), y);
+ }
+ {
+ int x = 0;
+ int y = 1;
+ test(x, y, std::greater<int>(), x);
+ test(y, x, std::greater<int>(), x);
+ }
+ {
+ int x = 1;
+ int y = 0;
+ test(x, y, std::greater<int>(), y);
+ test(y, x, std::greater<int>(), y);
+ }
+#if _LIBCPP_STD_VER > 11
+ {
+ constexpr int x = 1;
+ constexpr int y = 0;
+ static_assert(std::max(x, y, std::greater<int>()) == y, "" );
+ static_assert(std::max(y, x, std::greater<int>()) == y, "" );
+ }
+#endif
+}
diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.min.max/max_element.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.min.max/max_element.pass.cpp
new file mode 100644
index 00000000000..2788b193200
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.sorting/alg.min.max/max_element.pass.cpp
@@ -0,0 +1,66 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 LessThanComparable<Iter::value_type>
+// Iter
+// max_element(Iter first, Iter last);
+
+#include <algorithm>
+#include <cassert>
+
+#include "test_iterators.h"
+
+template <class Iter>
+void
+test(Iter first, Iter last)
+{
+ Iter i = std::max_element(first, last);
+ if (first != last)
+ {
+ for (Iter j = first; j != last; ++j)
+ assert(!(*i < *j));
+ }
+ else
+ assert(i == last);
+}
+
+template <class Iter>
+void
+test(unsigned N)
+{
+ int* a = new int[N];
+ for (int i = 0; i < N; ++i)
+ a[i] = i;
+ std::random_shuffle(a, a+N);
+ test(Iter(a), Iter(a+N));
+ delete [] a;
+}
+
+template <class Iter>
+void
+test()
+{
+ test<Iter>(0);
+ test<Iter>(1);
+ test<Iter>(2);
+ test<Iter>(3);
+ test<Iter>(10);
+ test<Iter>(1000);
+}
+
+int main()
+{
+ test<forward_iterator<const int*> >();
+ test<bidirectional_iterator<const int*> >();
+ test<random_access_iterator<const int*> >();
+ test<const int*>();
+}
diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.min.max/max_element_comp.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.min.max/max_element_comp.pass.cpp
new file mode 100644
index 00000000000..74e9fe6027f
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.sorting/alg.min.max/max_element_comp.pass.cpp
@@ -0,0 +1,85 @@
+//===----------------------------------------------------------------------===//
+//
+// 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, StrictWeakOrder<auto, Iter::value_type> Compare>
+// requires CopyConstructible<Compare>
+// Iter
+// max_element(Iter first, Iter last, Compare comp);
+
+#include <algorithm>
+#include <functional>
+#include <cassert>
+
+#include "test_iterators.h"
+
+template <class Iter>
+void
+test(Iter first, Iter last)
+{
+ Iter i = std::max_element(first, last, std::greater<int>());
+ if (first != last)
+ {
+ for (Iter j = first; j != last; ++j)
+ assert(!std::greater<int>()(*i, *j));
+ }
+ else
+ assert(i == last);
+}
+
+template <class Iter>
+void
+test(unsigned N)
+{
+ int* a = new int[N];
+ for (int i = 0; i < N; ++i)
+ a[i] = i;
+ std::random_shuffle(a, a+N);
+ test(Iter(a), Iter(a+N));
+ delete [] a;
+}
+
+template <class Iter>
+void
+test()
+{
+ test<Iter>(0);
+ test<Iter>(1);
+ test<Iter>(2);
+ test<Iter>(3);
+ test<Iter>(10);
+ test<Iter>(1000);
+}
+
+template <class Iter, class Pred>
+void test_eq0(Iter first, Iter last, Pred p)
+{
+ assert(first == std::max_element(first, last, p));
+}
+
+void test_eq()
+{
+ const size_t N = 10;
+ int* a = new int[N];
+ for (int i = 0; i < N; ++i)
+ a[i] = 10; // all the same
+ test_eq0(a, a+N, std::less<int>());
+ test_eq0(a, a+N, std::greater<int>());
+ delete [] a;
+}
+
+int main()
+{
+ test<forward_iterator<const int*> >();
+ test<bidirectional_iterator<const int*> >();
+ test<random_access_iterator<const int*> >();
+ test<const int*>();
+ test_eq();
+}
diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.min.max/max_init_list.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.min.max/max_init_list.pass.cpp
new file mode 100644
index 00000000000..0438412d236
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.sorting/alg.min.max/max_init_list.pass.cpp
@@ -0,0 +1,42 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 <class T>
+// T
+// max(initializer_list<T> t);
+
+#include <algorithm>
+#include <cassert>
+
+int main()
+{
+#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
+ int i = std::max({2, 3, 1});
+ assert(i == 3);
+ i = std::max({2, 1, 3});
+ assert(i == 3);
+ i = std::max({3, 1, 2});
+ assert(i == 3);
+ i = std::max({3, 2, 1});
+ assert(i == 3);
+ i = std::max({1, 2, 3});
+ assert(i == 3);
+ i = std::max({1, 3, 2});
+ assert(i == 3);
+#if _LIBCPP_STD_VER > 11
+ {
+ static_assert(std::max({1, 3, 2}) == 3, "");
+ static_assert(std::max({2, 1, 3}) == 3, "");
+ static_assert(std::max({3, 2, 1}) == 3, "");
+ }
+#endif
+#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
+}
diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.min.max/max_init_list_comp.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.min.max/max_init_list_comp.pass.cpp
new file mode 100644
index 00000000000..4dd47a73ef3
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.sorting/alg.min.max/max_init_list_comp.pass.cpp
@@ -0,0 +1,43 @@
+//===----------------------------------------------------------------------===//
+//
+// 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<class T, class Compare>
+// T
+// max(initializer_list<T> t, Compare comp);
+
+#include <algorithm>
+#include <functional>
+#include <cassert>
+
+int main()
+{
+#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
+ int i = std::max({2, 3, 1}, std::greater<int>());
+ assert(i == 1);
+ i = std::max({2, 1, 3}, std::greater<int>());
+ assert(i == 1);
+ i = std::max({3, 1, 2}, std::greater<int>());
+ assert(i == 1);
+ i = std::max({3, 2, 1}, std::greater<int>());
+ assert(i == 1);
+ i = std::max({1, 2, 3}, std::greater<int>());
+ assert(i == 1);
+ i = std::max({1, 3, 2}, std::greater<int>());
+ assert(i == 1);
+#if _LIBCPP_STD_VER > 11
+ {
+ static_assert(std::max({1, 3, 2}, std::greater<int>()) == 1, "");
+ static_assert(std::max({2, 1, 3}, std::greater<int>()) == 1, "");
+ static_assert(std::max({3, 2, 1}, std::greater<int>()) == 1, "");
+ }
+#endif
+#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
+}
diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.min.max/min.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.min.max/min.pass.cpp
new file mode 100644
index 00000000000..bbbd97bc5a4
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.sorting/alg.min.max/min.pass.cpp
@@ -0,0 +1,54 @@
+//===----------------------------------------------------------------------===//
+//
+// 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<LessThanComparable T>
+// const T&
+// min(const T& a, const T& b);
+
+#include <algorithm>
+#include <cassert>
+
+template <class T>
+void
+test(const T& a, const T& b, const T& x)
+{
+ assert(&std::min(a, b) == &x);
+}
+
+int main()
+{
+ {
+ int x = 0;
+ int y = 0;
+ test(x, y, x);
+ test(y, x, y);
+ }
+ {
+ int x = 0;
+ int y = 1;
+ test(x, y, x);
+ test(y, x, x);
+ }
+ {
+ int x = 1;
+ int y = 0;
+ test(x, y, y);
+ test(y, x, y);
+ }
+#if _LIBCPP_STD_VER > 11
+ {
+ constexpr int x = 1;
+ constexpr int y = 0;
+ static_assert(std::min(x, y) == y, "" );
+ static_assert(std::min(y, x) == y, "" );
+ }
+#endif
+}
diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.min.max/min_comp.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.min.max/min_comp.pass.cpp
new file mode 100644
index 00000000000..4ef705e7771
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.sorting/alg.min.max/min_comp.pass.cpp
@@ -0,0 +1,56 @@
+//===----------------------------------------------------------------------===//
+//
+// 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<class T, StrictWeakOrder<auto, T> Compare>
+// requires !SameType<T, Compare> && CopyConstructible<Compare>
+// const T&
+// min(const T& a, const T& b, Compare comp);
+
+#include <algorithm>
+#include <functional>
+#include <cassert>
+
+template <class T, class C>
+void
+test(const T& a, const T& b, C c, const T& x)
+{
+ assert(&std::min(a, b, c) == &x);
+}
+
+int main()
+{
+ {
+ int x = 0;
+ int y = 0;
+ test(x, y, std::greater<int>(), x);
+ test(y, x, std::greater<int>(), y);
+ }
+ {
+ int x = 0;
+ int y = 1;
+ test(x, y, std::greater<int>(), y);
+ test(y, x, std::greater<int>(), y);
+ }
+ {
+ int x = 1;
+ int y = 0;
+ test(x, y, std::greater<int>(), x);
+ test(y, x, std::greater<int>(), x);
+ }
+#if _LIBCPP_STD_VER > 11
+ {
+ constexpr int x = 1;
+ constexpr int y = 0;
+ static_assert(std::min(x, y, std::greater<int>()) == x, "" );
+ static_assert(std::min(y, x, std::greater<int>()) == x, "" );
+ }
+#endif
+}
diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.min.max/min_element.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.min.max/min_element.pass.cpp
new file mode 100644
index 00000000000..fd41f7a9ad7
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.sorting/alg.min.max/min_element.pass.cpp
@@ -0,0 +1,66 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 LessThanComparable<Iter::value_type>
+// Iter
+// min_element(Iter first, Iter last);
+
+#include <algorithm>
+#include <cassert>
+
+#include "test_iterators.h"
+
+template <class Iter>
+void
+test(Iter first, Iter last)
+{
+ Iter i = std::min_element(first, last);
+ if (first != last)
+ {
+ for (Iter j = first; j != last; ++j)
+ assert(!(*j < *i));
+ }
+ else
+ assert(i == last);
+}
+
+template <class Iter>
+void
+test(unsigned N)
+{
+ int* a = new int[N];
+ for (int i = 0; i < N; ++i)
+ a[i] = i;
+ std::random_shuffle(a, a+N);
+ test(Iter(a), Iter(a+N));
+ delete [] a;
+}
+
+template <class Iter>
+void
+test()
+{
+ test<Iter>(0);
+ test<Iter>(1);
+ test<Iter>(2);
+ test<Iter>(3);
+ test<Iter>(10);
+ test<Iter>(1000);
+}
+
+int main()
+{
+ test<forward_iterator<const int*> >();
+ test<bidirectional_iterator<const int*> >();
+ test<random_access_iterator<const int*> >();
+ test<const int*>();
+}
diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.min.max/min_element_comp.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.min.max/min_element_comp.pass.cpp
new file mode 100644
index 00000000000..2b5fdb1e0bb
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.sorting/alg.min.max/min_element_comp.pass.cpp
@@ -0,0 +1,85 @@
+//===----------------------------------------------------------------------===//
+//
+// 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, StrictWeakOrder<auto, Iter::value_type> Compare>
+// requires CopyConstructible<Compare>
+// Iter
+// min_element(Iter first, Iter last, Compare comp);
+
+#include <algorithm>
+#include <functional>
+#include <cassert>
+
+#include "test_iterators.h"
+
+template <class Iter>
+void
+test(Iter first, Iter last)
+{
+ Iter i = std::min_element(first, last, std::greater<int>());
+ if (first != last)
+ {
+ for (Iter j = first; j != last; ++j)
+ assert(!std::greater<int>()(*j, *i));
+ }
+ else
+ assert(i == last);
+}
+
+template <class Iter>
+void
+test(unsigned N)
+{
+ int* a = new int[N];
+ for (int i = 0; i < N; ++i)
+ a[i] = i;
+ std::random_shuffle(a, a+N);
+ test(Iter(a), Iter(a+N));
+ delete [] a;
+}
+
+template <class Iter>
+void
+test()
+{
+ test<Iter>(0);
+ test<Iter>(1);
+ test<Iter>(2);
+ test<Iter>(3);
+ test<Iter>(10);
+ test<Iter>(1000);
+}
+
+template <class Iter, class Pred>
+void test_eq0(Iter first, Iter last, Pred p)
+{
+ assert(first == std::min_element(first, last, p));
+}
+
+void test_eq()
+{
+ const size_t N = 10;
+ int* a = new int[N];
+ for (int i = 0; i < N; ++i)
+ a[i] = 10; // all the same
+ test_eq0(a, a+N, std::less<int>());
+ test_eq0(a, a+N, std::greater<int>());
+ delete [] a;
+}
+
+int main()
+{
+ test<forward_iterator<const int*> >();
+ test<bidirectional_iterator<const int*> >();
+ test<random_access_iterator<const int*> >();
+ test<const int*>();
+ test_eq();
+}
diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.min.max/min_init_list.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.min.max/min_init_list.pass.cpp
new file mode 100644
index 00000000000..eed4ebd4575
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.sorting/alg.min.max/min_init_list.pass.cpp
@@ -0,0 +1,42 @@
+//===----------------------------------------------------------------------===//
+//
+// 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<class T>
+// T
+// min(initializer_list<T> t);
+
+#include <algorithm>
+#include <cassert>
+
+int main()
+{
+#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
+ int i = std::min({2, 3, 1});
+ assert(i == 1);
+ i = std::min({2, 1, 3});
+ assert(i == 1);
+ i = std::min({3, 1, 2});
+ assert(i == 1);
+ i = std::min({3, 2, 1});
+ assert(i == 1);
+ i = std::min({1, 2, 3});
+ assert(i == 1);
+ i = std::min({1, 3, 2});
+ assert(i == 1);
+#if _LIBCPP_STD_VER > 11
+ {
+ static_assert(std::min({1, 3, 2}) == 1, "");
+ static_assert(std::min({2, 1, 3}) == 1, "");
+ static_assert(std::min({3, 2, 1}) == 1, "");
+ }
+#endif
+#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
+}
diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.min.max/min_init_list_comp.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.min.max/min_init_list_comp.pass.cpp
new file mode 100644
index 00000000000..5e0301b657b
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.sorting/alg.min.max/min_init_list_comp.pass.cpp
@@ -0,0 +1,43 @@
+//===----------------------------------------------------------------------===//
+//
+// 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<class T, class Compare>
+// T
+// min(initializer_list<T> t, Compare comp);
+
+#include <algorithm>
+#include <functional>
+#include <cassert>
+
+int main()
+{
+#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
+ int i = std::min({2, 3, 1}, std::greater<int>());
+ assert(i == 3);
+ i = std::min({2, 1, 3}, std::greater<int>());
+ assert(i == 3);
+ i = std::min({3, 1, 2}, std::greater<int>());
+ assert(i == 3);
+ i = std::min({3, 2, 1}, std::greater<int>());
+ assert(i == 3);
+ i = std::min({1, 2, 3}, std::greater<int>());
+ assert(i == 3);
+ i = std::min({1, 3, 2}, std::greater<int>());
+ assert(i == 3);
+#if _LIBCPP_STD_VER > 11
+ {
+ static_assert(std::min({1, 3, 2}, std::greater<int>()) == 3, "");
+ static_assert(std::min({2, 1, 3}, std::greater<int>()) == 3, "");
+ static_assert(std::min({3, 2, 1}, std::greater<int>()) == 3, "");
+ }
+#endif
+#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
+}
diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.min.max/minmax.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.min.max/minmax.pass.cpp
new file mode 100644
index 00000000000..6ac972a2547
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.sorting/alg.min.max/minmax.pass.cpp
@@ -0,0 +1,62 @@
+//===----------------------------------------------------------------------===//
+//
+// 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<LessThanComparable T>
+// pair<const T&, const T&>
+// minmax(const T& a, const T& b);
+
+#include <algorithm>
+#include <cassert>
+
+template <class T>
+void
+test(const T& a, const T& b, const T& x, const T& y)
+{
+ std::pair<const T&, const T&> p = std::minmax(a, b);
+ assert(&p.first == &x);
+ assert(&p.second == &y);
+}
+
+int main()
+{
+ {
+ int x = 0;
+ int y = 0;
+ test(x, y, x, y);
+ test(y, x, y, x);
+ }
+ {
+ int x = 0;
+ int y = 1;
+ test(x, y, x, y);
+ test(y, x, x, y);
+ }
+ {
+ int x = 1;
+ int y = 0;
+ test(x, y, y, x);
+ test(y, x, y, x);
+ }
+#if _LIBCPP_STD_VER > 11
+ {
+// Note that you can't take a reference to a local var, since
+// its address is not a compile-time constant.
+ constexpr static int x = 1;
+ constexpr static int y = 0;
+ constexpr auto p1 = std::minmax (x, y);
+ static_assert(p1.first == y, "");
+ static_assert(p1.second == x, "");
+ constexpr auto p2 = std::minmax (y, x);
+ static_assert(p2.first == y, "");
+ static_assert(p2.second == x, "");
+ }
+#endif
+}
diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.min.max/minmax_comp.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.min.max/minmax_comp.pass.cpp
new file mode 100644
index 00000000000..771c8f84a74
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.sorting/alg.min.max/minmax_comp.pass.cpp
@@ -0,0 +1,65 @@
+//===----------------------------------------------------------------------===//
+//
+// 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<class T, StrictWeakOrder<auto, T> Compare>
+// requires !SameType<T, Compare> && CopyConstructible<Compare>
+// pair<const T&, const T&>
+// minmax(const T& a, const T& b, Compare comp);
+
+#include <algorithm>
+#include <functional>
+#include <cassert>
+
+template <class T, class C>
+void
+test(const T& a, const T& b, C c, const T& x, const T& y)
+{
+ std::pair<const T&, const T&> p = std::minmax(a, b, c);
+ assert(&p.first == &x);
+ assert(&p.second == &y);
+}
+
+
+int main()
+{
+ {
+ int x = 0;
+ int y = 0;
+ test(x, y, std::greater<int>(), x, y);
+ test(y, x, std::greater<int>(), y, x);
+ }
+ {
+ int x = 0;
+ int y = 1;
+ test(x, y, std::greater<int>(), y, x);
+ test(y, x, std::greater<int>(), y, x);
+ }
+ {
+ int x = 1;
+ int y = 0;
+ test(x, y, std::greater<int>(), x, y);
+ test(y, x, std::greater<int>(), x, y);
+ }
+#if _LIBCPP_STD_VER > 11
+ {
+// Note that you can't take a reference to a local var, since
+// its address is not a compile-time constant.
+ constexpr static int x = 1;
+ constexpr static int y = 0;
+ constexpr auto p1 = std::minmax(x, y, std::greater<>());
+ static_assert(p1.first == x, "");
+ static_assert(p1.second == y, "");
+ constexpr auto p2 = std::minmax(y, x, std::greater<>());
+ static_assert(p2.first == x, "");
+ static_assert(p2.second == y, "");
+ }
+#endif
+}
diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.min.max/minmax_element.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.min.max/minmax_element.pass.cpp
new file mode 100644
index 00000000000..6cdb87dedb4
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.sorting/alg.min.max/minmax_element.pass.cpp
@@ -0,0 +1,83 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 LessThanComparable<Iter::value_type>
+// pair<Iter, Iter>
+// minmax_element(Iter first, Iter last);
+
+#include <algorithm>
+#include <cassert>
+
+#include "test_iterators.h"
+
+template <class Iter>
+void
+test(Iter first, Iter last)
+{
+ std::pair<Iter, Iter> p = std::minmax_element(first, last);
+ if (first != last)
+ {
+ for (Iter j = first; j != last; ++j)
+ {
+ assert(!(*j < *p.first));
+ assert(!(*p.second < *j));
+ }
+ }
+ else
+ {
+ assert(p.first == last);
+ assert(p.second == last);
+ }
+}
+
+template <class Iter>
+void
+test(unsigned N)
+{
+ int* a = new int[N];
+ for (int i = 0; i < N; ++i)
+ a[i] = i;
+ std::random_shuffle(a, a+N);
+ test(Iter(a), Iter(a+N));
+ delete [] a;
+}
+
+template <class Iter>
+void
+test()
+{
+ test<Iter>(0);
+ test<Iter>(1);
+ test<Iter>(2);
+ test<Iter>(3);
+ test<Iter>(10);
+ test<Iter>(1000);
+ {
+ const unsigned N = 100;
+ int* a = new int[N];
+ for (int i = 0; i < N; ++i)
+ a[i] = 5;
+ std::random_shuffle(a, a+N);
+ std::pair<Iter, Iter> p = std::minmax_element(Iter(a), Iter(a+N));
+ assert(base(p.first) == a);
+ assert(base(p.second) == a+N-1);
+ delete [] a;
+ }
+}
+
+int main()
+{
+ test<forward_iterator<const int*> >();
+ test<bidirectional_iterator<const int*> >();
+ test<random_access_iterator<const int*> >();
+ test<const int*>();
+}
diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.min.max/minmax_element_comp.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.min.max/minmax_element_comp.pass.cpp
new file mode 100644
index 00000000000..cc0e66e175c
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.sorting/alg.min.max/minmax_element_comp.pass.cpp
@@ -0,0 +1,88 @@
+//===----------------------------------------------------------------------===//
+//
+// 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, StrictWeakOrder<auto, Iter::value_type> Compare>
+// requires CopyConstructible<Compare>
+// pair<Iter, Iter>
+// minmax_element(Iter first, Iter last, Compare comp);
+
+#include <algorithm>
+#include <functional>
+#include <cassert>
+
+#include "test_iterators.h"
+
+template <class Iter>
+void
+test(Iter first, Iter last)
+{
+ typedef std::greater<int> Compare;
+ Compare comp;
+ std::pair<Iter, Iter> p = std::minmax_element(first, last, comp);
+ if (first != last)
+ {
+ for (Iter j = first; j != last; ++j)
+ {
+ assert(!comp(*j, *p.first));
+ assert(!comp(*p.second, *j));
+ }
+ }
+ else
+ {
+ assert(p.first == last);
+ assert(p.second == last);
+ }
+}
+
+template <class Iter>
+void
+test(unsigned N)
+{
+ int* a = new int[N];
+ for (int i = 0; i < N; ++i)
+ a[i] = i;
+ std::random_shuffle(a, a+N);
+ test(Iter(a), Iter(a+N));
+ delete [] a;
+}
+
+template <class Iter>
+void
+test()
+{
+ test<Iter>(0);
+ test<Iter>(1);
+ test<Iter>(2);
+ test<Iter>(3);
+ test<Iter>(10);
+ test<Iter>(1000);
+ {
+ const unsigned N = 100;
+ int* a = new int[N];
+ for (int i = 0; i < N; ++i)
+ a[i] = 5;
+ std::random_shuffle(a, a+N);
+ typedef std::greater<int> Compare;
+ Compare comp;
+ std::pair<Iter, Iter> p = std::minmax_element(Iter(a), Iter(a+N), comp);
+ assert(base(p.first) == a);
+ assert(base(p.second) == a+N-1);
+ delete [] a;
+ }
+}
+
+int main()
+{
+ test<forward_iterator<const int*> >();
+ test<bidirectional_iterator<const int*> >();
+ test<random_access_iterator<const int*> >();
+ test<const int*>();
+}
diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.min.max/minmax_init_list.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.min.max/minmax_init_list.pass.cpp
new file mode 100644
index 00000000000..0196d10dcd9
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.sorting/alg.min.max/minmax_init_list.pass.cpp
@@ -0,0 +1,39 @@
+//===----------------------------------------------------------------------===//
+//
+// 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<class T>
+// pair<T, T>
+// minmax(initializer_list<T> t);
+
+#include <algorithm>
+#include <cassert>
+
+int main()
+{
+#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
+ assert((std::minmax({1, 2, 3}) == std::pair<int, int>(1, 3)));
+ assert((std::minmax({1, 3, 2}) == std::pair<int, int>(1, 3)));
+ assert((std::minmax({2, 1, 3}) == std::pair<int, int>(1, 3)));
+ assert((std::minmax({2, 3, 1}) == std::pair<int, int>(1, 3)));
+ assert((std::minmax({3, 1, 2}) == std::pair<int, int>(1, 3)));
+ assert((std::minmax({3, 2, 1}) == std::pair<int, int>(1, 3)));
+#if _LIBCPP_STD_VER > 11
+ {
+ static_assert((std::minmax({1, 2, 3}) == std::pair<int, int>(1, 3)), "");
+ static_assert((std::minmax({1, 3, 2}) == std::pair<int, int>(1, 3)), "");
+ static_assert((std::minmax({2, 1, 3}) == std::pair<int, int>(1, 3)), "");
+ static_assert((std::minmax({2, 3, 1}) == std::pair<int, int>(1, 3)), "");
+ static_assert((std::minmax({3, 1, 2}) == std::pair<int, int>(1, 3)), "");
+ static_assert((std::minmax({3, 2, 1}) == std::pair<int, int>(1, 3)), "");
+ }
+#endif
+#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
+}
diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.min.max/minmax_init_list_comp.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.min.max/minmax_init_list_comp.pass.cpp
new file mode 100644
index 00000000000..95a8c85c1da
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.sorting/alg.min.max/minmax_init_list_comp.pass.cpp
@@ -0,0 +1,40 @@
+//===----------------------------------------------------------------------===//
+//
+// 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<class T, class Compare>
+// pair<T, T>
+// minmax(initializer_list<T> t, Compare comp);
+
+#include <algorithm>
+#include <functional>
+#include <cassert>
+
+int main()
+{
+#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
+ assert((std::minmax({1, 2, 3}, std::greater<int>()) == std::pair<int, int>(3, 1)));
+ assert((std::minmax({1, 3, 2}, std::greater<int>()) == std::pair<int, int>(3, 1)));
+ assert((std::minmax({2, 1, 3}, std::greater<int>()) == std::pair<int, int>(3, 1)));
+ assert((std::minmax({2, 3, 1}, std::greater<int>()) == std::pair<int, int>(3, 1)));
+ assert((std::minmax({3, 1, 2}, std::greater<int>()) == std::pair<int, int>(3, 1)));
+ assert((std::minmax({3, 2, 1}, std::greater<int>()) == std::pair<int, int>(3, 1)));
+#if _LIBCPP_STD_VER > 11
+ {
+ static_assert((std::minmax({1, 2, 3}, std::greater<int>()) == std::pair<int, int>(3, 1)), "");
+ static_assert((std::minmax({1, 3, 2}, std::greater<int>()) == std::pair<int, int>(3, 1)), "");
+ static_assert((std::minmax({2, 1, 3}, std::greater<int>()) == std::pair<int, int>(3, 1)), "");
+ static_assert((std::minmax({2, 3, 1}, std::greater<int>()) == std::pair<int, int>(3, 1)), "");
+ static_assert((std::minmax({3, 1, 2}, std::greater<int>()) == std::pair<int, int>(3, 1)), "");
+ static_assert((std::minmax({3, 2, 1}, std::greater<int>()) == std::pair<int, int>(3, 1)), "");
+ }
+#endif
+#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
+}
diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.nth.element/nth_element.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.nth.element/nth_element.pass.cpp
new file mode 100644
index 00000000000..dc5564eb3fc
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.sorting/alg.nth.element/nth_element.pass.cpp
@@ -0,0 +1,63 @@
+//===----------------------------------------------------------------------===//
+//
+// 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<RandomAccessIterator Iter>
+// requires ShuffleIterator<Iter>
+// && LessThanComparable<Iter::value_type>
+// void
+// nth_element(Iter first, Iter nth, Iter last);
+
+#include <algorithm>
+#include <cassert>
+
+void
+test_one(unsigned N, unsigned M)
+{
+ assert(N != 0);
+ assert(M < N);
+ int* array = new int[N];
+ for (int i = 0; i < N; ++i)
+ array[i] = i;
+ std::random_shuffle(array, array+N);
+ std::nth_element(array, array+M, array+N);
+ assert(array[M] == M);
+ std::nth_element(array, array+N, array+N); // begin, end, end
+ delete [] array;
+}
+
+void
+test(unsigned N)
+{
+ test_one(N, 0);
+ test_one(N, 1);
+ test_one(N, 2);
+ test_one(N, 3);
+ test_one(N, N/2-1);
+ test_one(N, N/2);
+ test_one(N, N/2+1);
+ test_one(N, N-3);
+ test_one(N, N-2);
+ test_one(N, N-1);
+}
+
+int main()
+{
+ int d = 0;
+ std::nth_element(&d, &d, &d);
+ assert(d == 0);
+ test(256);
+ test(257);
+ test(499);
+ test(500);
+ test(997);
+ test(1000);
+ test(1009);
+}
diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.nth.element/nth_element_comp.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.nth.element/nth_element_comp.pass.cpp
new file mode 100644
index 00000000000..cf8659038f1
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.sorting/alg.nth.element/nth_element_comp.pass.cpp
@@ -0,0 +1,86 @@
+//===----------------------------------------------------------------------===//
+//
+// 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<RandomAccessIterator Iter, StrictWeakOrder<auto, Iter::value_type> Compare>
+// requires ShuffleIterator<Iter>
+// && CopyConstructible<Compare>
+// void
+// nth_element(Iter first, Iter nth, Iter last, Compare comp);
+
+#include <algorithm>
+#include <functional>
+#include <vector>
+#include <cassert>
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+#include <memory>
+
+struct indirect_less
+{
+ template <class P>
+ bool operator()(const P& x, const P& y)
+ {return *x < *y;}
+};
+
+#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
+
+void
+test_one(unsigned N, unsigned M)
+{
+ assert(N != 0);
+ assert(M < N);
+ int* array = new int[N];
+ for (int i = 0; i < N; ++i)
+ array[i] = i;
+ std::random_shuffle(array, array+N);
+ std::nth_element(array, array+M, array+N, std::greater<int>());
+ assert(array[M] == N-M-1);
+ std::nth_element(array, array+N, array+N, std::greater<int>()); // begin, end, end
+ delete [] array;
+}
+
+void
+test(unsigned N)
+{
+ test_one(N, 0);
+ test_one(N, 1);
+ test_one(N, 2);
+ test_one(N, 3);
+ test_one(N, N/2-1);
+ test_one(N, N/2);
+ test_one(N, N/2+1);
+ test_one(N, N-3);
+ test_one(N, N-2);
+ test_one(N, N-1);
+}
+
+int main()
+{
+ int d = 0;
+ std::nth_element(&d, &d, &d);
+ assert(d == 0);
+ test(256);
+ test(257);
+ test(499);
+ test(500);
+ test(997);
+ test(1000);
+ test(1009);
+
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+ {
+ std::vector<std::unique_ptr<int> > v(1000);
+ for (int i = 0; i < v.size(); ++i)
+ v[i].reset(new int(i));
+ std::nth_element(v.begin(), v.begin() + v.size()/2, v.end(), indirect_less());
+ assert(*v[v.size()/2] == v.size()/2);
+ }
+#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
+}
diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.permutation.generators/next_permutation.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.permutation.generators/next_permutation.pass.cpp
new file mode 100644
index 00000000000..fb58c718c7e
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.sorting/alg.permutation.generators/next_permutation.pass.cpp
@@ -0,0 +1,66 @@
+//===----------------------------------------------------------------------===//
+//
+// 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<BidirectionalIterator Iter>
+// requires ShuffleIterator<Iter>
+// && LessThanComparable<Iter::value_type>
+// bool
+// next_permutation(Iter first, Iter last);
+
+#include <algorithm>
+#include <cassert>
+
+#include "test_iterators.h"
+
+#include <cstdio>
+
+int factorial(int x)
+{
+ int r = 1;
+ for (; x; --x)
+ r *= x;
+ return r;
+}
+
+template <class Iter>
+void
+test()
+{
+ int ia[] = {1, 2, 3, 4, 5, 6};
+ const int sa = sizeof(ia)/sizeof(ia[0]);
+ int prev[sa];
+ for (int e = 0; e <= sa; ++e)
+ {
+ int count = 0;
+ bool x;
+ do
+ {
+ std::copy(ia, ia+e, prev);
+ x = std::next_permutation(Iter(ia), Iter(ia+e));
+ if (e > 1)
+ {
+ if (x)
+ assert(std::lexicographical_compare(prev, prev+e, ia, ia+e));
+ else
+ assert(std::lexicographical_compare(ia, ia+e, prev, prev+e));
+ }
+ ++count;
+ } while (x);
+ assert(count == factorial(e));
+ }
+}
+
+int main()
+{
+ test<bidirectional_iterator<int*> >();
+ test<random_access_iterator<int*> >();
+ test<int*>();
+}
diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.permutation.generators/next_permutation_comp.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.permutation.generators/next_permutation_comp.pass.cpp
new file mode 100644
index 00000000000..8e87e9a4351
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.sorting/alg.permutation.generators/next_permutation_comp.pass.cpp
@@ -0,0 +1,68 @@
+//===----------------------------------------------------------------------===//
+//
+// 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<BidirectionalIterator Iter, StrictWeakOrder<auto, Iter::value_type> Compare>
+// requires ShuffleIterator<Iter>
+// && CopyConstructible<Compare>
+// bool
+// next_permutation(Iter first, Iter last, Compare comp);
+
+#include <algorithm>
+#include <functional>
+#include <cassert>
+
+#include "test_iterators.h"
+
+#include <cstdio>
+
+int factorial(int x)
+{
+ int r = 1;
+ for (; x; --x)
+ r *= x;
+ return r;
+}
+
+template <class Iter>
+void
+test()
+{
+ typedef std::greater<int> C;
+ int ia[] = {6, 5, 4, 3, 2, 1};
+ const int sa = sizeof(ia)/sizeof(ia[0]);
+ int prev[sa];
+ for (int e = 0; e <= sa; ++e)
+ {
+ int count = 0;
+ bool x;
+ do
+ {
+ std::copy(ia, ia+e, prev);
+ x = std::next_permutation(Iter(ia), Iter(ia+e), C());
+ if (e > 1)
+ {
+ if (x)
+ assert(std::lexicographical_compare(prev, prev+e, ia, ia+e, C()));
+ else
+ assert(std::lexicographical_compare(ia, ia+e, prev, prev+e, C()));
+ }
+ ++count;
+ } while (x);
+ assert(count == factorial(e));
+ }
+}
+
+int main()
+{
+ test<bidirectional_iterator<int*> >();
+ test<random_access_iterator<int*> >();
+ test<int*>();
+}
diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.permutation.generators/prev_permutation.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.permutation.generators/prev_permutation.pass.cpp
new file mode 100644
index 00000000000..d2fa2cb98b0
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.sorting/alg.permutation.generators/prev_permutation.pass.cpp
@@ -0,0 +1,66 @@
+//===----------------------------------------------------------------------===//
+//
+// 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<BidirectionalIterator Iter>
+// requires ShuffleIterator<Iter>
+// && LessThanComparable<Iter::value_type>
+// bool
+// prev_permutation(Iter first, Iter last);
+
+#include <algorithm>
+#include <cassert>
+
+#include "test_iterators.h"
+
+#include <cstdio>
+
+int factorial(int x)
+{
+ int r = 1;
+ for (; x; --x)
+ r *= x;
+ return r;
+}
+
+template <class Iter>
+void
+test()
+{
+ int ia[] = {6, 5, 4, 3, 2, 1};
+ const int sa = sizeof(ia)/sizeof(ia[0]);
+ int prev[sa];
+ for (int e = 0; e <= sa; ++e)
+ {
+ int count = 0;
+ bool x;
+ do
+ {
+ std::copy(ia, ia+e, prev);
+ x = std::prev_permutation(Iter(ia), Iter(ia+e));
+ if (e > 1)
+ {
+ if (x)
+ assert(std::lexicographical_compare(ia, ia+e, prev, prev+e));
+ else
+ assert(std::lexicographical_compare(prev, prev+e, ia, ia+e));
+ }
+ ++count;
+ } while (x);
+ assert(count == factorial(e));
+ }
+}
+
+int main()
+{
+ test<bidirectional_iterator<int*> >();
+ test<random_access_iterator<int*> >();
+ test<int*>();
+}
diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.permutation.generators/prev_permutation_comp.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.permutation.generators/prev_permutation_comp.pass.cpp
new file mode 100644
index 00000000000..51b7aa8c11b
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.sorting/alg.permutation.generators/prev_permutation_comp.pass.cpp
@@ -0,0 +1,68 @@
+//===----------------------------------------------------------------------===//
+//
+// 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<BidirectionalIterator Iter, StrictWeakOrder<auto, Iter::value_type> Compare>
+// requires ShuffleIterator<Iter>
+// && CopyConstructible<Compare>
+// bool
+// prev_permutation(Iter first, Iter last, Compare comp);
+
+#include <algorithm>
+#include <functional>
+#include <cassert>
+
+#include "test_iterators.h"
+
+#include <cstdio>
+
+int factorial(int x)
+{
+ int r = 1;
+ for (; x; --x)
+ r *= x;
+ return r;
+}
+
+template <class Iter>
+void
+test()
+{
+ typedef std::greater<int> C;
+ int ia[] = {1, 2, 3, 4, 5, 6};
+ const int sa = sizeof(ia)/sizeof(ia[0]);
+ int prev[sa];
+ for (int e = 0; e <= sa; ++e)
+ {
+ int count = 0;
+ bool x;
+ do
+ {
+ std::copy(ia, ia+e, prev);
+ x = std::prev_permutation(Iter(ia), Iter(ia+e), C());
+ if (e > 1)
+ {
+ if (x)
+ assert(std::lexicographical_compare(ia, ia+e, prev, prev+e, C()));
+ else
+ assert(std::lexicographical_compare(prev, prev+e, ia, ia+e, C()));
+ }
+ ++count;
+ } while (x);
+ assert(count == factorial(e));
+ }
+}
+
+int main()
+{
+ test<bidirectional_iterator<int*> >();
+ test<random_access_iterator<int*> >();
+ test<int*>();
+}
diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.set.operations/includes/includes.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.set.operations/includes/includes.pass.cpp
new file mode 100644
index 00000000000..8db8177fb9c
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.sorting/alg.set.operations/includes/includes.pass.cpp
@@ -0,0 +1,84 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 Iter1, InputIterator Iter2>
+// requires HasLess<Iter1::value_type, Iter2::value_type>
+// && HasLess<Iter2::value_type, Iter1::value_type>
+// bool
+// includes(Iter1 first1, Iter1 last1, Iter2 first2, Iter2 last2);
+
+#include <algorithm>
+#include <cassert>
+
+#include "test_iterators.h"
+
+template <class Iter1, class Iter2>
+void
+test()
+{
+ int ia[] = {1, 2, 2, 3, 3, 3, 4, 4, 4, 4};
+ const unsigned sa = sizeof(ia)/sizeof(ia[0]);
+ int ib[] = {2, 4};
+ const unsigned sb = sizeof(ib)/sizeof(ib[0]);
+ int ic[] = {1, 2};
+ const unsigned sc = sizeof(ic)/sizeof(ic[0]);
+ int id[] = {3, 3, 3, 3};
+ const unsigned sd = sizeof(id)/sizeof(id[0]);
+
+ assert(std::includes(Iter1(ia), Iter1(ia), Iter2(ib), Iter2(ib)));
+ assert(!std::includes(Iter1(ia), Iter1(ia), Iter2(ib), Iter2(ib+1)));
+ assert(std::includes(Iter1(ia), Iter1(ia+1), Iter2(ib), Iter2(ib)));
+ assert(std::includes(Iter1(ia), Iter1(ia+sa), Iter2(ia), Iter2(ia+sa)));
+
+ assert(std::includes(Iter1(ia), Iter1(ia+sa), Iter2(ib), Iter2(ib+sb)));
+ assert(!std::includes(Iter1(ib), Iter1(ib+sb), Iter2(ia), Iter2(ia+sa)));
+
+ assert(std::includes(Iter1(ia), Iter1(ia+2), Iter2(ic), Iter2(ic+2)));
+ assert(!std::includes(Iter1(ia), Iter1(ia+2), Iter2(ib), Iter2(ib+2)));
+
+ assert(std::includes(Iter1(ia), Iter1(ia+sa), Iter2(id), Iter2(id+1)));
+ assert(std::includes(Iter1(ia), Iter1(ia+sa), Iter2(id), Iter2(id+2)));
+ assert(std::includes(Iter1(ia), Iter1(ia+sa), Iter2(id), Iter2(id+3)));
+ assert(!std::includes(Iter1(ia), Iter1(ia+sa), Iter2(id), Iter2(id+4)));
+}
+
+int main()
+{
+ test<input_iterator<const int*>, input_iterator<const int*> >();
+ test<input_iterator<const int*>, forward_iterator<const int*> >();
+ test<input_iterator<const int*>, bidirectional_iterator<const int*> >();
+ test<input_iterator<const int*>, random_access_iterator<const int*> >();
+ test<input_iterator<const int*>, const int*>();
+
+ test<forward_iterator<const int*>, input_iterator<const int*> >();
+ test<forward_iterator<const int*>, forward_iterator<const int*> >();
+ test<forward_iterator<const int*>, bidirectional_iterator<const int*> >();
+ test<forward_iterator<const int*>, random_access_iterator<const int*> >();
+ test<forward_iterator<const int*>, const int*>();
+
+ test<bidirectional_iterator<const int*>, input_iterator<const int*> >();
+ test<bidirectional_iterator<const int*>, forward_iterator<const int*> >();
+ test<bidirectional_iterator<const int*>, bidirectional_iterator<const int*> >();
+ test<bidirectional_iterator<const int*>, random_access_iterator<const int*> >();
+ test<bidirectional_iterator<const int*>, const int*>();
+
+ test<random_access_iterator<const int*>, input_iterator<const int*> >();
+ test<random_access_iterator<const int*>, forward_iterator<const int*> >();
+ test<random_access_iterator<const int*>, bidirectional_iterator<const int*> >();
+ test<random_access_iterator<const int*>, random_access_iterator<const int*> >();
+ test<random_access_iterator<const int*>, const int*>();
+
+ test<const int*, input_iterator<const int*> >();
+ test<const int*, forward_iterator<const int*> >();
+ test<const int*, bidirectional_iterator<const int*> >();
+ test<const int*, random_access_iterator<const int*> >();
+ test<const int*, const int*>();
+}
diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.set.operations/includes/includes_comp.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.set.operations/includes/includes_comp.pass.cpp
new file mode 100644
index 00000000000..7e1aef4749a
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.sorting/alg.set.operations/includes/includes_comp.pass.cpp
@@ -0,0 +1,85 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 Iter1, InputIterator Iter2, typename Compare>
+// requires Predicate<Compare, Iter1::value_type, Iter2::value_type>
+// && Predicate<Compare, Iter2::value_type, Iter1::value_type>
+// bool
+// includes(Iter1 first1, Iter1 last1, Iter2 first2, Iter2 last2, Compare comp);
+
+#include <algorithm>
+#include <functional>
+#include <cassert>
+
+#include "test_iterators.h"
+
+template <class Iter1, class Iter2>
+void
+test()
+{
+ int ia[] = {1, 2, 2, 3, 3, 3, 4, 4, 4, 4};
+ const unsigned sa = sizeof(ia)/sizeof(ia[0]);
+ int ib[] = {2, 4};
+ const unsigned sb = sizeof(ib)/sizeof(ib[0]);
+ int ic[] = {1, 2};
+ const unsigned sc = sizeof(ic)/sizeof(ic[0]);
+ int id[] = {3, 3, 3, 3};
+ const unsigned sd = sizeof(id)/sizeof(id[0]);
+
+ assert(std::includes(Iter1(ia), Iter1(ia), Iter2(ib), Iter2(ib), std::less<int>()));
+ assert(!std::includes(Iter1(ia), Iter1(ia), Iter2(ib), Iter2(ib+1), std::less<int>()));
+ assert(std::includes(Iter1(ia), Iter1(ia+1), Iter2(ib), Iter2(ib), std::less<int>()));
+ assert(std::includes(Iter1(ia), Iter1(ia+sa), Iter2(ia), Iter2(ia+sa), std::less<int>()));
+
+ assert(std::includes(Iter1(ia), Iter1(ia+sa), Iter2(ib), Iter2(ib+sb), std::less<int>()));
+ assert(!std::includes(Iter1(ib), Iter1(ib+sb), Iter2(ia), Iter2(ia+sa), std::less<int>()));
+
+ assert(std::includes(Iter1(ia), Iter1(ia+2), Iter2(ic), Iter2(ic+2), std::less<int>()));
+ assert(!std::includes(Iter1(ia), Iter1(ia+2), Iter2(ib), Iter2(ib+2), std::less<int>()));
+
+ assert(std::includes(Iter1(ia), Iter1(ia+sa), Iter2(id), Iter2(id+1), std::less<int>()));
+ assert(std::includes(Iter1(ia), Iter1(ia+sa), Iter2(id), Iter2(id+2), std::less<int>()));
+ assert(std::includes(Iter1(ia), Iter1(ia+sa), Iter2(id), Iter2(id+3), std::less<int>()));
+ assert(!std::includes(Iter1(ia), Iter1(ia+sa), Iter2(id), Iter2(id+4), std::less<int>()));
+}
+
+int main()
+{
+ test<input_iterator<const int*>, input_iterator<const int*> >();
+ test<input_iterator<const int*>, forward_iterator<const int*> >();
+ test<input_iterator<const int*>, bidirectional_iterator<const int*> >();
+ test<input_iterator<const int*>, random_access_iterator<const int*> >();
+ test<input_iterator<const int*>, const int*>();
+
+ test<forward_iterator<const int*>, input_iterator<const int*> >();
+ test<forward_iterator<const int*>, forward_iterator<const int*> >();
+ test<forward_iterator<const int*>, bidirectional_iterator<const int*> >();
+ test<forward_iterator<const int*>, random_access_iterator<const int*> >();
+ test<forward_iterator<const int*>, const int*>();
+
+ test<bidirectional_iterator<const int*>, input_iterator<const int*> >();
+ test<bidirectional_iterator<const int*>, forward_iterator<const int*> >();
+ test<bidirectional_iterator<const int*>, bidirectional_iterator<const int*> >();
+ test<bidirectional_iterator<const int*>, random_access_iterator<const int*> >();
+ test<bidirectional_iterator<const int*>, const int*>();
+
+ test<random_access_iterator<const int*>, input_iterator<const int*> >();
+ test<random_access_iterator<const int*>, forward_iterator<const int*> >();
+ test<random_access_iterator<const int*>, bidirectional_iterator<const int*> >();
+ test<random_access_iterator<const int*>, random_access_iterator<const int*> >();
+ test<random_access_iterator<const int*>, const int*>();
+
+ test<const int*, input_iterator<const int*> >();
+ test<const int*, forward_iterator<const int*> >();
+ test<const int*, bidirectional_iterator<const int*> >();
+ test<const int*, random_access_iterator<const int*> >();
+ test<const int*, const int*>();
+}
diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.set.operations/nothing_to_do.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.set.operations/nothing_to_do.pass.cpp
new file mode 100644
index 00000000000..b58f5c55b64
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.sorting/alg.set.operations/nothing_to_do.pass.cpp
@@ -0,0 +1,12 @@
+//===----------------------------------------------------------------------===//
+//
+// 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.
+//
+//===----------------------------------------------------------------------===//
+
+int main()
+{
+}
diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.set.operations/set.difference/set_difference.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.set.operations/set.difference/set_difference.pass.cpp
new file mode 100644
index 00000000000..c2c20c295ca
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.sorting/alg.set.operations/set.difference/set_difference.pass.cpp
@@ -0,0 +1,200 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 InIter1, InputIterator InIter2, typename OutIter>
+// requires OutputIterator<OutIter, InIter1::reference>
+// && OutputIterator<OutIter, InIter2::reference>
+// && HasLess<InIter2::value_type, InIter1::value_type>
+// && HasLess<InIter1::value_type, InIter2::value_type>
+// OutIter
+// set_difference(InIter1 first1, InIter1 last1, InIter2 first2, InIter2 last2,
+// OutIter result);
+
+#include <algorithm>
+#include <cassert>
+
+#include "test_iterators.h"
+
+template <class Iter1, class Iter2, class OutIter>
+void
+test()
+{
+ int ia[] = {1, 2, 2, 3, 3, 3, 4, 4, 4, 4};
+ const int sa = sizeof(ia)/sizeof(ia[0]);
+ int ib[] = {2, 4, 4, 6};
+ const int sb = sizeof(ib)/sizeof(ib[0]);
+ int ic[20];
+ int ir[] = {1, 2, 3, 3, 3, 4, 4};
+ const int sr = sizeof(ir)/sizeof(ir[0]);
+ OutIter ce = std::set_difference(Iter1(ia), Iter1(ia+sa),
+ Iter2(ib), Iter2(ib+sb), OutIter(ic));
+ assert(base(ce) - ic == sr);
+ assert(std::lexicographical_compare(ic, base(ce), ir, ir+sr) == 0);
+ int irr[] = {6};
+ const int srr = sizeof(irr)/sizeof(irr[0]);
+ ce = std::set_difference(Iter1(ib), Iter1(ib+sb),
+ Iter2(ia), Iter2(ia+sa), OutIter(ic));
+ assert(base(ce) - ic == srr);
+ assert(std::lexicographical_compare(ic, base(ce), irr, irr+srr) == 0);
+}
+
+int main()
+{
+ test<input_iterator<const int*>, input_iterator<const int*>, output_iterator<int*> >();
+ test<input_iterator<const int*>, input_iterator<const int*>, forward_iterator<int*> >();
+ test<input_iterator<const int*>, input_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<input_iterator<const int*>, input_iterator<const int*>, random_access_iterator<int*> >();
+ test<input_iterator<const int*>, input_iterator<const int*>, int*>();
+
+ test<input_iterator<const int*>, forward_iterator<const int*>, output_iterator<int*> >();
+ test<input_iterator<const int*>, forward_iterator<const int*>, forward_iterator<int*> >();
+ test<input_iterator<const int*>, forward_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<input_iterator<const int*>, forward_iterator<const int*>, random_access_iterator<int*> >();
+ test<input_iterator<const int*>, forward_iterator<const int*>, int*>();
+
+ test<input_iterator<const int*>, bidirectional_iterator<const int*>, output_iterator<int*> >();
+ test<input_iterator<const int*>, bidirectional_iterator<const int*>, forward_iterator<int*> >();
+ test<input_iterator<const int*>, bidirectional_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<input_iterator<const int*>, bidirectional_iterator<const int*>, random_access_iterator<int*> >();
+ test<input_iterator<const int*>, bidirectional_iterator<const int*>, int*>();
+
+ test<input_iterator<const int*>, random_access_iterator<const int*>, output_iterator<int*> >();
+ test<input_iterator<const int*>, random_access_iterator<const int*>, forward_iterator<int*> >();
+ test<input_iterator<const int*>, random_access_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<input_iterator<const int*>, random_access_iterator<const int*>, random_access_iterator<int*> >();
+ test<input_iterator<const int*>, random_access_iterator<const int*>, int*>();
+
+ test<input_iterator<const int*>, const int*, output_iterator<int*> >();
+ test<input_iterator<const int*>, const int*, forward_iterator<int*> >();
+ test<input_iterator<const int*>, const int*, bidirectional_iterator<int*> >();
+ test<input_iterator<const int*>, const int*, random_access_iterator<int*> >();
+ test<input_iterator<const int*>, const int*, int*>();
+
+ test<forward_iterator<const int*>, input_iterator<const int*>, output_iterator<int*> >();
+ test<forward_iterator<const int*>, input_iterator<const int*>, forward_iterator<int*> >();
+ test<forward_iterator<const int*>, input_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<forward_iterator<const int*>, input_iterator<const int*>, random_access_iterator<int*> >();
+ test<forward_iterator<const int*>, input_iterator<const int*>, int*>();
+
+ test<forward_iterator<const int*>, forward_iterator<const int*>, output_iterator<int*> >();
+ test<forward_iterator<const int*>, forward_iterator<const int*>, forward_iterator<int*> >();
+ test<forward_iterator<const int*>, forward_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<forward_iterator<const int*>, forward_iterator<const int*>, random_access_iterator<int*> >();
+ test<forward_iterator<const int*>, forward_iterator<const int*>, int*>();
+
+ test<forward_iterator<const int*>, bidirectional_iterator<const int*>, output_iterator<int*> >();
+ test<forward_iterator<const int*>, bidirectional_iterator<const int*>, forward_iterator<int*> >();
+ test<forward_iterator<const int*>, bidirectional_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<forward_iterator<const int*>, bidirectional_iterator<const int*>, random_access_iterator<int*> >();
+ test<forward_iterator<const int*>, bidirectional_iterator<const int*>, int*>();
+
+ test<forward_iterator<const int*>, random_access_iterator<const int*>, output_iterator<int*> >();
+ test<forward_iterator<const int*>, random_access_iterator<const int*>, forward_iterator<int*> >();
+ test<forward_iterator<const int*>, random_access_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<forward_iterator<const int*>, random_access_iterator<const int*>, random_access_iterator<int*> >();
+ test<forward_iterator<const int*>, random_access_iterator<const int*>, int*>();
+
+ test<forward_iterator<const int*>, const int*, output_iterator<int*> >();
+ test<forward_iterator<const int*>, const int*, forward_iterator<int*> >();
+ test<forward_iterator<const int*>, const int*, bidirectional_iterator<int*> >();
+ test<forward_iterator<const int*>, const int*, random_access_iterator<int*> >();
+ test<forward_iterator<const int*>, const int*, int*>();
+
+ test<bidirectional_iterator<const int*>, input_iterator<const int*>, output_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, input_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, input_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, input_iterator<const int*>, random_access_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, input_iterator<const int*>, int*>();
+
+ test<bidirectional_iterator<const int*>, forward_iterator<const int*>, output_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, forward_iterator<const int*>, forward_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, forward_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, forward_iterator<const int*>, random_access_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, forward_iterator<const int*>, int*>();
+
+ test<bidirectional_iterator<const int*>, bidirectional_iterator<const int*>, output_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, bidirectional_iterator<const int*>, forward_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, bidirectional_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, bidirectional_iterator<const int*>, random_access_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, bidirectional_iterator<const int*>, int*>();
+
+ test<bidirectional_iterator<const int*>, random_access_iterator<const int*>, output_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, random_access_iterator<const int*>, forward_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, random_access_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, random_access_iterator<const int*>, random_access_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, random_access_iterator<const int*>, int*>();
+
+ test<bidirectional_iterator<const int*>, const int*, output_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, const int*, forward_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, const int*, bidirectional_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, const int*, random_access_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, const int*, int*>();
+
+ test<random_access_iterator<const int*>, input_iterator<const int*>, output_iterator<int*> >();
+ test<random_access_iterator<const int*>, input_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<random_access_iterator<const int*>, input_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<random_access_iterator<const int*>, input_iterator<const int*>, random_access_iterator<int*> >();
+ test<random_access_iterator<const int*>, input_iterator<const int*>, int*>();
+
+ test<random_access_iterator<const int*>, forward_iterator<const int*>, output_iterator<int*> >();
+ test<random_access_iterator<const int*>, forward_iterator<const int*>, forward_iterator<int*> >();
+ test<random_access_iterator<const int*>, forward_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<random_access_iterator<const int*>, forward_iterator<const int*>, random_access_iterator<int*> >();
+ test<random_access_iterator<const int*>, forward_iterator<const int*>, int*>();
+
+ test<random_access_iterator<const int*>, bidirectional_iterator<const int*>, output_iterator<int*> >();
+ test<random_access_iterator<const int*>, bidirectional_iterator<const int*>, forward_iterator<int*> >();
+ test<random_access_iterator<const int*>, bidirectional_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<random_access_iterator<const int*>, bidirectional_iterator<const int*>, random_access_iterator<int*> >();
+ test<random_access_iterator<const int*>, bidirectional_iterator<const int*>, int*>();
+
+ test<random_access_iterator<const int*>, random_access_iterator<const int*>, output_iterator<int*> >();
+ test<random_access_iterator<const int*>, random_access_iterator<const int*>, forward_iterator<int*> >();
+ test<random_access_iterator<const int*>, random_access_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<random_access_iterator<const int*>, random_access_iterator<const int*>, random_access_iterator<int*> >();
+ test<random_access_iterator<const int*>, random_access_iterator<const int*>, int*>();
+
+ test<random_access_iterator<const int*>, const int*, output_iterator<int*> >();
+ test<random_access_iterator<const int*>, const int*, forward_iterator<int*> >();
+ test<random_access_iterator<const int*>, const int*, bidirectional_iterator<int*> >();
+ test<random_access_iterator<const int*>, const int*, random_access_iterator<int*> >();
+ test<random_access_iterator<const int*>, const int*, int*>();
+
+ test<const int*, input_iterator<const int*>, output_iterator<int*> >();
+ test<const int*, input_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<const int*, input_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<const int*, input_iterator<const int*>, random_access_iterator<int*> >();
+ test<const int*, input_iterator<const int*>, int*>();
+
+ test<const int*, forward_iterator<const int*>, output_iterator<int*> >();
+ test<const int*, forward_iterator<const int*>, forward_iterator<int*> >();
+ test<const int*, forward_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<const int*, forward_iterator<const int*>, random_access_iterator<int*> >();
+ test<const int*, forward_iterator<const int*>, int*>();
+
+ test<const int*, bidirectional_iterator<const int*>, output_iterator<int*> >();
+ test<const int*, bidirectional_iterator<const int*>, forward_iterator<int*> >();
+ test<const int*, bidirectional_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<const int*, bidirectional_iterator<const int*>, random_access_iterator<int*> >();
+ test<const int*, bidirectional_iterator<const int*>, int*>();
+
+ test<const int*, random_access_iterator<const int*>, output_iterator<int*> >();
+ test<const int*, random_access_iterator<const int*>, forward_iterator<int*> >();
+ test<const int*, random_access_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<const int*, random_access_iterator<const int*>, random_access_iterator<int*> >();
+ test<const int*, random_access_iterator<const int*>, int*>();
+
+ test<const int*, const int*, output_iterator<int*> >();
+ test<const int*, const int*, forward_iterator<int*> >();
+ test<const int*, const int*, bidirectional_iterator<int*> >();
+ test<const int*, const int*, random_access_iterator<int*> >();
+ test<const int*, const int*, int*>();
+}
diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.set.operations/set.difference/set_difference_comp.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.set.operations/set.difference/set_difference_comp.pass.cpp
new file mode 100644
index 00000000000..2b5a6a9f56b
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.sorting/alg.set.operations/set.difference/set_difference_comp.pass.cpp
@@ -0,0 +1,202 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 InIter1, InputIterator InIter2, typename OutIter,
+// CopyConstructible Compare>
+// requires OutputIterator<OutIter, InIter1::reference>
+// && OutputIterator<OutIter, InIter2::reference>
+// && Predicate<Compare, InIter1::value_type, InIter2::value_type>
+// && Predicate<Compare, InIter2::value_type, InIter1::value_type>
+// OutIter
+// set_difference(InIter1 first1, InIter1 last1, InIter2 first2, InIter2 last2,
+// OutIter result, Compare comp);
+
+#include <algorithm>
+#include <functional>
+#include <cassert>
+
+#include "test_iterators.h"
+
+template <class Iter1, class Iter2, class OutIter>
+void
+test()
+{
+ int ia[] = {1, 2, 2, 3, 3, 3, 4, 4, 4, 4};
+ const int sa = sizeof(ia)/sizeof(ia[0]);
+ int ib[] = {2, 4, 4, 6};
+ const int sb = sizeof(ib)/sizeof(ib[0]);
+ int ic[20];
+ int ir[] = {1, 2, 3, 3, 3, 4, 4};
+ const int sr = sizeof(ir)/sizeof(ir[0]);
+ OutIter ce = std::set_difference(Iter1(ia), Iter1(ia+sa),
+ Iter2(ib), Iter2(ib+sb), OutIter(ic), std::less<int>());
+ assert(base(ce) - ic == sr);
+ assert(std::lexicographical_compare(ic, base(ce), ir, ir+sr) == 0);
+ int irr[] = {6};
+ const int srr = sizeof(irr)/sizeof(irr[0]);
+ ce = std::set_difference(Iter1(ib), Iter1(ib+sb),
+ Iter2(ia), Iter2(ia+sa), OutIter(ic), std::less<int>());
+ assert(base(ce) - ic == srr);
+ assert(std::lexicographical_compare(ic, base(ce), irr, irr+srr) == 0);
+}
+
+int main()
+{
+ test<input_iterator<const int*>, input_iterator<const int*>, output_iterator<int*> >();
+ test<input_iterator<const int*>, input_iterator<const int*>, forward_iterator<int*> >();
+ test<input_iterator<const int*>, input_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<input_iterator<const int*>, input_iterator<const int*>, random_access_iterator<int*> >();
+ test<input_iterator<const int*>, input_iterator<const int*>, int*>();
+
+ test<input_iterator<const int*>, forward_iterator<const int*>, output_iterator<int*> >();
+ test<input_iterator<const int*>, forward_iterator<const int*>, forward_iterator<int*> >();
+ test<input_iterator<const int*>, forward_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<input_iterator<const int*>, forward_iterator<const int*>, random_access_iterator<int*> >();
+ test<input_iterator<const int*>, forward_iterator<const int*>, int*>();
+
+ test<input_iterator<const int*>, bidirectional_iterator<const int*>, output_iterator<int*> >();
+ test<input_iterator<const int*>, bidirectional_iterator<const int*>, forward_iterator<int*> >();
+ test<input_iterator<const int*>, bidirectional_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<input_iterator<const int*>, bidirectional_iterator<const int*>, random_access_iterator<int*> >();
+ test<input_iterator<const int*>, bidirectional_iterator<const int*>, int*>();
+
+ test<input_iterator<const int*>, random_access_iterator<const int*>, output_iterator<int*> >();
+ test<input_iterator<const int*>, random_access_iterator<const int*>, forward_iterator<int*> >();
+ test<input_iterator<const int*>, random_access_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<input_iterator<const int*>, random_access_iterator<const int*>, random_access_iterator<int*> >();
+ test<input_iterator<const int*>, random_access_iterator<const int*>, int*>();
+
+ test<input_iterator<const int*>, const int*, output_iterator<int*> >();
+ test<input_iterator<const int*>, const int*, forward_iterator<int*> >();
+ test<input_iterator<const int*>, const int*, bidirectional_iterator<int*> >();
+ test<input_iterator<const int*>, const int*, random_access_iterator<int*> >();
+ test<input_iterator<const int*>, const int*, int*>();
+
+ test<forward_iterator<const int*>, input_iterator<const int*>, output_iterator<int*> >();
+ test<forward_iterator<const int*>, input_iterator<const int*>, forward_iterator<int*> >();
+ test<forward_iterator<const int*>, input_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<forward_iterator<const int*>, input_iterator<const int*>, random_access_iterator<int*> >();
+ test<forward_iterator<const int*>, input_iterator<const int*>, int*>();
+
+ test<forward_iterator<const int*>, forward_iterator<const int*>, output_iterator<int*> >();
+ test<forward_iterator<const int*>, forward_iterator<const int*>, forward_iterator<int*> >();
+ test<forward_iterator<const int*>, forward_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<forward_iterator<const int*>, forward_iterator<const int*>, random_access_iterator<int*> >();
+ test<forward_iterator<const int*>, forward_iterator<const int*>, int*>();
+
+ test<forward_iterator<const int*>, bidirectional_iterator<const int*>, output_iterator<int*> >();
+ test<forward_iterator<const int*>, bidirectional_iterator<const int*>, forward_iterator<int*> >();
+ test<forward_iterator<const int*>, bidirectional_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<forward_iterator<const int*>, bidirectional_iterator<const int*>, random_access_iterator<int*> >();
+ test<forward_iterator<const int*>, bidirectional_iterator<const int*>, int*>();
+
+ test<forward_iterator<const int*>, random_access_iterator<const int*>, output_iterator<int*> >();
+ test<forward_iterator<const int*>, random_access_iterator<const int*>, forward_iterator<int*> >();
+ test<forward_iterator<const int*>, random_access_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<forward_iterator<const int*>, random_access_iterator<const int*>, random_access_iterator<int*> >();
+ test<forward_iterator<const int*>, random_access_iterator<const int*>, int*>();
+
+ test<forward_iterator<const int*>, const int*, output_iterator<int*> >();
+ test<forward_iterator<const int*>, const int*, forward_iterator<int*> >();
+ test<forward_iterator<const int*>, const int*, bidirectional_iterator<int*> >();
+ test<forward_iterator<const int*>, const int*, random_access_iterator<int*> >();
+ test<forward_iterator<const int*>, const int*, int*>();
+
+ test<bidirectional_iterator<const int*>, input_iterator<const int*>, output_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, input_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, input_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, input_iterator<const int*>, random_access_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, input_iterator<const int*>, int*>();
+
+ test<bidirectional_iterator<const int*>, forward_iterator<const int*>, output_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, forward_iterator<const int*>, forward_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, forward_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, forward_iterator<const int*>, random_access_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, forward_iterator<const int*>, int*>();
+
+ test<bidirectional_iterator<const int*>, bidirectional_iterator<const int*>, output_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, bidirectional_iterator<const int*>, forward_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, bidirectional_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, bidirectional_iterator<const int*>, random_access_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, bidirectional_iterator<const int*>, int*>();
+
+ test<bidirectional_iterator<const int*>, random_access_iterator<const int*>, output_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, random_access_iterator<const int*>, forward_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, random_access_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, random_access_iterator<const int*>, random_access_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, random_access_iterator<const int*>, int*>();
+
+ test<bidirectional_iterator<const int*>, const int*, output_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, const int*, forward_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, const int*, bidirectional_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, const int*, random_access_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, const int*, int*>();
+
+ test<random_access_iterator<const int*>, input_iterator<const int*>, output_iterator<int*> >();
+ test<random_access_iterator<const int*>, input_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<random_access_iterator<const int*>, input_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<random_access_iterator<const int*>, input_iterator<const int*>, random_access_iterator<int*> >();
+ test<random_access_iterator<const int*>, input_iterator<const int*>, int*>();
+
+ test<random_access_iterator<const int*>, forward_iterator<const int*>, output_iterator<int*> >();
+ test<random_access_iterator<const int*>, forward_iterator<const int*>, forward_iterator<int*> >();
+ test<random_access_iterator<const int*>, forward_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<random_access_iterator<const int*>, forward_iterator<const int*>, random_access_iterator<int*> >();
+ test<random_access_iterator<const int*>, forward_iterator<const int*>, int*>();
+
+ test<random_access_iterator<const int*>, bidirectional_iterator<const int*>, output_iterator<int*> >();
+ test<random_access_iterator<const int*>, bidirectional_iterator<const int*>, forward_iterator<int*> >();
+ test<random_access_iterator<const int*>, bidirectional_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<random_access_iterator<const int*>, bidirectional_iterator<const int*>, random_access_iterator<int*> >();
+ test<random_access_iterator<const int*>, bidirectional_iterator<const int*>, int*>();
+
+ test<random_access_iterator<const int*>, random_access_iterator<const int*>, output_iterator<int*> >();
+ test<random_access_iterator<const int*>, random_access_iterator<const int*>, forward_iterator<int*> >();
+ test<random_access_iterator<const int*>, random_access_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<random_access_iterator<const int*>, random_access_iterator<const int*>, random_access_iterator<int*> >();
+ test<random_access_iterator<const int*>, random_access_iterator<const int*>, int*>();
+
+ test<random_access_iterator<const int*>, const int*, output_iterator<int*> >();
+ test<random_access_iterator<const int*>, const int*, forward_iterator<int*> >();
+ test<random_access_iterator<const int*>, const int*, bidirectional_iterator<int*> >();
+ test<random_access_iterator<const int*>, const int*, random_access_iterator<int*> >();
+ test<random_access_iterator<const int*>, const int*, int*>();
+
+ test<const int*, input_iterator<const int*>, output_iterator<int*> >();
+ test<const int*, input_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<const int*, input_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<const int*, input_iterator<const int*>, random_access_iterator<int*> >();
+ test<const int*, input_iterator<const int*>, int*>();
+
+ test<const int*, forward_iterator<const int*>, output_iterator<int*> >();
+ test<const int*, forward_iterator<const int*>, forward_iterator<int*> >();
+ test<const int*, forward_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<const int*, forward_iterator<const int*>, random_access_iterator<int*> >();
+ test<const int*, forward_iterator<const int*>, int*>();
+
+ test<const int*, bidirectional_iterator<const int*>, output_iterator<int*> >();
+ test<const int*, bidirectional_iterator<const int*>, forward_iterator<int*> >();
+ test<const int*, bidirectional_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<const int*, bidirectional_iterator<const int*>, random_access_iterator<int*> >();
+ test<const int*, bidirectional_iterator<const int*>, int*>();
+
+ test<const int*, random_access_iterator<const int*>, output_iterator<int*> >();
+ test<const int*, random_access_iterator<const int*>, forward_iterator<int*> >();
+ test<const int*, random_access_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<const int*, random_access_iterator<const int*>, random_access_iterator<int*> >();
+ test<const int*, random_access_iterator<const int*>, int*>();
+
+ test<const int*, const int*, output_iterator<int*> >();
+ test<const int*, const int*, forward_iterator<int*> >();
+ test<const int*, const int*, bidirectional_iterator<int*> >();
+ test<const int*, const int*, random_access_iterator<int*> >();
+ test<const int*, const int*, int*>();
+}
diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.set.operations/set.intersection/set_intersection.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.set.operations/set.intersection/set_intersection.pass.cpp
new file mode 100644
index 00000000000..f371890d8e7
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.sorting/alg.set.operations/set.intersection/set_intersection.pass.cpp
@@ -0,0 +1,198 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 InIter1, InputIterator InIter2, typename OutIter>
+// requires OutputIterator<OutIter, InIter1::reference>
+// && OutputIterator<OutIter, InIter2::reference>
+// && HasLess<InIter2::value_type, InIter1::value_type>
+// && HasLess<InIter1::value_type, InIter2::value_type>
+// OutIter
+// set_intersection(InIter1 first1, InIter1 last1, InIter2 first2, InIter2 last2,
+// OutIter result);
+
+#include <algorithm>
+#include <cassert>
+
+#include "test_iterators.h"
+
+template <class Iter1, class Iter2, class OutIter>
+void
+test()
+{
+ int ia[] = {1, 2, 2, 3, 3, 3, 4, 4, 4, 4};
+ const int sa = sizeof(ia)/sizeof(ia[0]);
+ int ib[] = {2, 4, 4, 6};
+ const int sb = sizeof(ib)/sizeof(ib[0]);
+ int ic[20];
+ int ir[] = {2, 4, 4};
+ const int sr = sizeof(ir)/sizeof(ir[0]);
+ OutIter ce = std::set_intersection(Iter1(ia), Iter1(ia+sa),
+ Iter2(ib), Iter2(ib+sb), OutIter(ic));
+ assert(base(ce) - ic == sr);
+ assert(std::lexicographical_compare(ic, base(ce), ir, ir+sr) == 0);
+ ce = std::set_intersection(Iter1(ib), Iter1(ib+sb),
+ Iter2(ia), Iter2(ia+sa), OutIter(ic));
+ assert(base(ce) - ic == sr);
+ assert(std::lexicographical_compare(ic, base(ce), ir, ir+sr) == 0);
+}
+
+int main()
+{
+ test<input_iterator<const int*>, input_iterator<const int*>, output_iterator<int*> >();
+ test<input_iterator<const int*>, input_iterator<const int*>, forward_iterator<int*> >();
+ test<input_iterator<const int*>, input_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<input_iterator<const int*>, input_iterator<const int*>, random_access_iterator<int*> >();
+ test<input_iterator<const int*>, input_iterator<const int*>, int*>();
+
+ test<input_iterator<const int*>, forward_iterator<const int*>, output_iterator<int*> >();
+ test<input_iterator<const int*>, forward_iterator<const int*>, forward_iterator<int*> >();
+ test<input_iterator<const int*>, forward_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<input_iterator<const int*>, forward_iterator<const int*>, random_access_iterator<int*> >();
+ test<input_iterator<const int*>, forward_iterator<const int*>, int*>();
+
+ test<input_iterator<const int*>, bidirectional_iterator<const int*>, output_iterator<int*> >();
+ test<input_iterator<const int*>, bidirectional_iterator<const int*>, forward_iterator<int*> >();
+ test<input_iterator<const int*>, bidirectional_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<input_iterator<const int*>, bidirectional_iterator<const int*>, random_access_iterator<int*> >();
+ test<input_iterator<const int*>, bidirectional_iterator<const int*>, int*>();
+
+ test<input_iterator<const int*>, random_access_iterator<const int*>, output_iterator<int*> >();
+ test<input_iterator<const int*>, random_access_iterator<const int*>, forward_iterator<int*> >();
+ test<input_iterator<const int*>, random_access_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<input_iterator<const int*>, random_access_iterator<const int*>, random_access_iterator<int*> >();
+ test<input_iterator<const int*>, random_access_iterator<const int*>, int*>();
+
+ test<input_iterator<const int*>, const int*, output_iterator<int*> >();
+ test<input_iterator<const int*>, const int*, forward_iterator<int*> >();
+ test<input_iterator<const int*>, const int*, bidirectional_iterator<int*> >();
+ test<input_iterator<const int*>, const int*, random_access_iterator<int*> >();
+ test<input_iterator<const int*>, const int*, int*>();
+
+ test<forward_iterator<const int*>, input_iterator<const int*>, output_iterator<int*> >();
+ test<forward_iterator<const int*>, input_iterator<const int*>, forward_iterator<int*> >();
+ test<forward_iterator<const int*>, input_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<forward_iterator<const int*>, input_iterator<const int*>, random_access_iterator<int*> >();
+ test<forward_iterator<const int*>, input_iterator<const int*>, int*>();
+
+ test<forward_iterator<const int*>, forward_iterator<const int*>, output_iterator<int*> >();
+ test<forward_iterator<const int*>, forward_iterator<const int*>, forward_iterator<int*> >();
+ test<forward_iterator<const int*>, forward_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<forward_iterator<const int*>, forward_iterator<const int*>, random_access_iterator<int*> >();
+ test<forward_iterator<const int*>, forward_iterator<const int*>, int*>();
+
+ test<forward_iterator<const int*>, bidirectional_iterator<const int*>, output_iterator<int*> >();
+ test<forward_iterator<const int*>, bidirectional_iterator<const int*>, forward_iterator<int*> >();
+ test<forward_iterator<const int*>, bidirectional_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<forward_iterator<const int*>, bidirectional_iterator<const int*>, random_access_iterator<int*> >();
+ test<forward_iterator<const int*>, bidirectional_iterator<const int*>, int*>();
+
+ test<forward_iterator<const int*>, random_access_iterator<const int*>, output_iterator<int*> >();
+ test<forward_iterator<const int*>, random_access_iterator<const int*>, forward_iterator<int*> >();
+ test<forward_iterator<const int*>, random_access_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<forward_iterator<const int*>, random_access_iterator<const int*>, random_access_iterator<int*> >();
+ test<forward_iterator<const int*>, random_access_iterator<const int*>, int*>();
+
+ test<forward_iterator<const int*>, const int*, output_iterator<int*> >();
+ test<forward_iterator<const int*>, const int*, forward_iterator<int*> >();
+ test<forward_iterator<const int*>, const int*, bidirectional_iterator<int*> >();
+ test<forward_iterator<const int*>, const int*, random_access_iterator<int*> >();
+ test<forward_iterator<const int*>, const int*, int*>();
+
+ test<bidirectional_iterator<const int*>, input_iterator<const int*>, output_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, input_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, input_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, input_iterator<const int*>, random_access_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, input_iterator<const int*>, int*>();
+
+ test<bidirectional_iterator<const int*>, forward_iterator<const int*>, output_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, forward_iterator<const int*>, forward_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, forward_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, forward_iterator<const int*>, random_access_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, forward_iterator<const int*>, int*>();
+
+ test<bidirectional_iterator<const int*>, bidirectional_iterator<const int*>, output_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, bidirectional_iterator<const int*>, forward_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, bidirectional_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, bidirectional_iterator<const int*>, random_access_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, bidirectional_iterator<const int*>, int*>();
+
+ test<bidirectional_iterator<const int*>, random_access_iterator<const int*>, output_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, random_access_iterator<const int*>, forward_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, random_access_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, random_access_iterator<const int*>, random_access_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, random_access_iterator<const int*>, int*>();
+
+ test<bidirectional_iterator<const int*>, const int*, output_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, const int*, forward_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, const int*, bidirectional_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, const int*, random_access_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, const int*, int*>();
+
+ test<random_access_iterator<const int*>, input_iterator<const int*>, output_iterator<int*> >();
+ test<random_access_iterator<const int*>, input_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<random_access_iterator<const int*>, input_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<random_access_iterator<const int*>, input_iterator<const int*>, random_access_iterator<int*> >();
+ test<random_access_iterator<const int*>, input_iterator<const int*>, int*>();
+
+ test<random_access_iterator<const int*>, forward_iterator<const int*>, output_iterator<int*> >();
+ test<random_access_iterator<const int*>, forward_iterator<const int*>, forward_iterator<int*> >();
+ test<random_access_iterator<const int*>, forward_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<random_access_iterator<const int*>, forward_iterator<const int*>, random_access_iterator<int*> >();
+ test<random_access_iterator<const int*>, forward_iterator<const int*>, int*>();
+
+ test<random_access_iterator<const int*>, bidirectional_iterator<const int*>, output_iterator<int*> >();
+ test<random_access_iterator<const int*>, bidirectional_iterator<const int*>, forward_iterator<int*> >();
+ test<random_access_iterator<const int*>, bidirectional_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<random_access_iterator<const int*>, bidirectional_iterator<const int*>, random_access_iterator<int*> >();
+ test<random_access_iterator<const int*>, bidirectional_iterator<const int*>, int*>();
+
+ test<random_access_iterator<const int*>, random_access_iterator<const int*>, output_iterator<int*> >();
+ test<random_access_iterator<const int*>, random_access_iterator<const int*>, forward_iterator<int*> >();
+ test<random_access_iterator<const int*>, random_access_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<random_access_iterator<const int*>, random_access_iterator<const int*>, random_access_iterator<int*> >();
+ test<random_access_iterator<const int*>, random_access_iterator<const int*>, int*>();
+
+ test<random_access_iterator<const int*>, const int*, output_iterator<int*> >();
+ test<random_access_iterator<const int*>, const int*, forward_iterator<int*> >();
+ test<random_access_iterator<const int*>, const int*, bidirectional_iterator<int*> >();
+ test<random_access_iterator<const int*>, const int*, random_access_iterator<int*> >();
+ test<random_access_iterator<const int*>, const int*, int*>();
+
+ test<const int*, input_iterator<const int*>, output_iterator<int*> >();
+ test<const int*, input_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<const int*, input_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<const int*, input_iterator<const int*>, random_access_iterator<int*> >();
+ test<const int*, input_iterator<const int*>, int*>();
+
+ test<const int*, forward_iterator<const int*>, output_iterator<int*> >();
+ test<const int*, forward_iterator<const int*>, forward_iterator<int*> >();
+ test<const int*, forward_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<const int*, forward_iterator<const int*>, random_access_iterator<int*> >();
+ test<const int*, forward_iterator<const int*>, int*>();
+
+ test<const int*, bidirectional_iterator<const int*>, output_iterator<int*> >();
+ test<const int*, bidirectional_iterator<const int*>, forward_iterator<int*> >();
+ test<const int*, bidirectional_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<const int*, bidirectional_iterator<const int*>, random_access_iterator<int*> >();
+ test<const int*, bidirectional_iterator<const int*>, int*>();
+
+ test<const int*, random_access_iterator<const int*>, output_iterator<int*> >();
+ test<const int*, random_access_iterator<const int*>, forward_iterator<int*> >();
+ test<const int*, random_access_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<const int*, random_access_iterator<const int*>, random_access_iterator<int*> >();
+ test<const int*, random_access_iterator<const int*>, int*>();
+
+ test<const int*, const int*, output_iterator<int*> >();
+ test<const int*, const int*, forward_iterator<int*> >();
+ test<const int*, const int*, bidirectional_iterator<int*> >();
+ test<const int*, const int*, random_access_iterator<int*> >();
+ test<const int*, const int*, int*>();
+}
diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.set.operations/set.intersection/set_intersection_comp.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.set.operations/set.intersection/set_intersection_comp.pass.cpp
new file mode 100644
index 00000000000..035522b5462
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.sorting/alg.set.operations/set.intersection/set_intersection_comp.pass.cpp
@@ -0,0 +1,200 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 InIter1, InputIterator InIter2, typename OutIter,
+// CopyConstructible Compare>
+// requires OutputIterator<OutIter, InIter1::reference>
+// && OutputIterator<OutIter, InIter2::reference>
+// && Predicate<Compare, InIter1::value_type, InIter2::value_type>
+// && Predicate<Compare, InIter2::value_type, InIter1::value_type>
+// OutIter
+// set_intersection(InIter1 first1, InIter1 last1, InIter2 first2, InIter2 last2,
+// OutIter result, Compare comp);
+
+#include <algorithm>
+#include <functional>
+#include <cassert>
+
+#include "test_iterators.h"
+
+template <class Iter1, class Iter2, class OutIter>
+void
+test()
+{
+ int ia[] = {1, 2, 2, 3, 3, 3, 4, 4, 4, 4};
+ const int sa = sizeof(ia)/sizeof(ia[0]);
+ int ib[] = {2, 4, 4, 6};
+ const int sb = sizeof(ib)/sizeof(ib[0]);
+ int ic[20];
+ int ir[] = {2, 4, 4};
+ const int sr = sizeof(ir)/sizeof(ir[0]);
+ OutIter ce = std::set_intersection(Iter1(ia), Iter1(ia+sa),
+ Iter2(ib), Iter2(ib+sb), OutIter(ic), std::less<int>());
+ assert(base(ce) - ic == sr);
+ assert(std::lexicographical_compare(ic, base(ce), ir, ir+sr) == 0);
+ ce = std::set_intersection(Iter1(ib), Iter1(ib+sb),
+ Iter2(ia), Iter2(ia+sa), OutIter(ic), std::less<int>());
+ assert(base(ce) - ic == sr);
+ assert(std::lexicographical_compare(ic, base(ce), ir, ir+sr) == 0);
+}
+
+int main()
+{
+ test<input_iterator<const int*>, input_iterator<const int*>, output_iterator<int*> >();
+ test<input_iterator<const int*>, input_iterator<const int*>, forward_iterator<int*> >();
+ test<input_iterator<const int*>, input_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<input_iterator<const int*>, input_iterator<const int*>, random_access_iterator<int*> >();
+ test<input_iterator<const int*>, input_iterator<const int*>, int*>();
+
+ test<input_iterator<const int*>, forward_iterator<const int*>, output_iterator<int*> >();
+ test<input_iterator<const int*>, forward_iterator<const int*>, forward_iterator<int*> >();
+ test<input_iterator<const int*>, forward_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<input_iterator<const int*>, forward_iterator<const int*>, random_access_iterator<int*> >();
+ test<input_iterator<const int*>, forward_iterator<const int*>, int*>();
+
+ test<input_iterator<const int*>, bidirectional_iterator<const int*>, output_iterator<int*> >();
+ test<input_iterator<const int*>, bidirectional_iterator<const int*>, forward_iterator<int*> >();
+ test<input_iterator<const int*>, bidirectional_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<input_iterator<const int*>, bidirectional_iterator<const int*>, random_access_iterator<int*> >();
+ test<input_iterator<const int*>, bidirectional_iterator<const int*>, int*>();
+
+ test<input_iterator<const int*>, random_access_iterator<const int*>, output_iterator<int*> >();
+ test<input_iterator<const int*>, random_access_iterator<const int*>, forward_iterator<int*> >();
+ test<input_iterator<const int*>, random_access_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<input_iterator<const int*>, random_access_iterator<const int*>, random_access_iterator<int*> >();
+ test<input_iterator<const int*>, random_access_iterator<const int*>, int*>();
+
+ test<input_iterator<const int*>, const int*, output_iterator<int*> >();
+ test<input_iterator<const int*>, const int*, forward_iterator<int*> >();
+ test<input_iterator<const int*>, const int*, bidirectional_iterator<int*> >();
+ test<input_iterator<const int*>, const int*, random_access_iterator<int*> >();
+ test<input_iterator<const int*>, const int*, int*>();
+
+ test<forward_iterator<const int*>, input_iterator<const int*>, output_iterator<int*> >();
+ test<forward_iterator<const int*>, input_iterator<const int*>, forward_iterator<int*> >();
+ test<forward_iterator<const int*>, input_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<forward_iterator<const int*>, input_iterator<const int*>, random_access_iterator<int*> >();
+ test<forward_iterator<const int*>, input_iterator<const int*>, int*>();
+
+ test<forward_iterator<const int*>, forward_iterator<const int*>, output_iterator<int*> >();
+ test<forward_iterator<const int*>, forward_iterator<const int*>, forward_iterator<int*> >();
+ test<forward_iterator<const int*>, forward_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<forward_iterator<const int*>, forward_iterator<const int*>, random_access_iterator<int*> >();
+ test<forward_iterator<const int*>, forward_iterator<const int*>, int*>();
+
+ test<forward_iterator<const int*>, bidirectional_iterator<const int*>, output_iterator<int*> >();
+ test<forward_iterator<const int*>, bidirectional_iterator<const int*>, forward_iterator<int*> >();
+ test<forward_iterator<const int*>, bidirectional_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<forward_iterator<const int*>, bidirectional_iterator<const int*>, random_access_iterator<int*> >();
+ test<forward_iterator<const int*>, bidirectional_iterator<const int*>, int*>();
+
+ test<forward_iterator<const int*>, random_access_iterator<const int*>, output_iterator<int*> >();
+ test<forward_iterator<const int*>, random_access_iterator<const int*>, forward_iterator<int*> >();
+ test<forward_iterator<const int*>, random_access_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<forward_iterator<const int*>, random_access_iterator<const int*>, random_access_iterator<int*> >();
+ test<forward_iterator<const int*>, random_access_iterator<const int*>, int*>();
+
+ test<forward_iterator<const int*>, const int*, output_iterator<int*> >();
+ test<forward_iterator<const int*>, const int*, forward_iterator<int*> >();
+ test<forward_iterator<const int*>, const int*, bidirectional_iterator<int*> >();
+ test<forward_iterator<const int*>, const int*, random_access_iterator<int*> >();
+ test<forward_iterator<const int*>, const int*, int*>();
+
+ test<bidirectional_iterator<const int*>, input_iterator<const int*>, output_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, input_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, input_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, input_iterator<const int*>, random_access_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, input_iterator<const int*>, int*>();
+
+ test<bidirectional_iterator<const int*>, forward_iterator<const int*>, output_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, forward_iterator<const int*>, forward_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, forward_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, forward_iterator<const int*>, random_access_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, forward_iterator<const int*>, int*>();
+
+ test<bidirectional_iterator<const int*>, bidirectional_iterator<const int*>, output_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, bidirectional_iterator<const int*>, forward_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, bidirectional_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, bidirectional_iterator<const int*>, random_access_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, bidirectional_iterator<const int*>, int*>();
+
+ test<bidirectional_iterator<const int*>, random_access_iterator<const int*>, output_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, random_access_iterator<const int*>, forward_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, random_access_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, random_access_iterator<const int*>, random_access_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, random_access_iterator<const int*>, int*>();
+
+ test<bidirectional_iterator<const int*>, const int*, output_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, const int*, forward_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, const int*, bidirectional_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, const int*, random_access_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, const int*, int*>();
+
+ test<random_access_iterator<const int*>, input_iterator<const int*>, output_iterator<int*> >();
+ test<random_access_iterator<const int*>, input_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<random_access_iterator<const int*>, input_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<random_access_iterator<const int*>, input_iterator<const int*>, random_access_iterator<int*> >();
+ test<random_access_iterator<const int*>, input_iterator<const int*>, int*>();
+
+ test<random_access_iterator<const int*>, forward_iterator<const int*>, output_iterator<int*> >();
+ test<random_access_iterator<const int*>, forward_iterator<const int*>, forward_iterator<int*> >();
+ test<random_access_iterator<const int*>, forward_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<random_access_iterator<const int*>, forward_iterator<const int*>, random_access_iterator<int*> >();
+ test<random_access_iterator<const int*>, forward_iterator<const int*>, int*>();
+
+ test<random_access_iterator<const int*>, bidirectional_iterator<const int*>, output_iterator<int*> >();
+ test<random_access_iterator<const int*>, bidirectional_iterator<const int*>, forward_iterator<int*> >();
+ test<random_access_iterator<const int*>, bidirectional_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<random_access_iterator<const int*>, bidirectional_iterator<const int*>, random_access_iterator<int*> >();
+ test<random_access_iterator<const int*>, bidirectional_iterator<const int*>, int*>();
+
+ test<random_access_iterator<const int*>, random_access_iterator<const int*>, output_iterator<int*> >();
+ test<random_access_iterator<const int*>, random_access_iterator<const int*>, forward_iterator<int*> >();
+ test<random_access_iterator<const int*>, random_access_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<random_access_iterator<const int*>, random_access_iterator<const int*>, random_access_iterator<int*> >();
+ test<random_access_iterator<const int*>, random_access_iterator<const int*>, int*>();
+
+ test<random_access_iterator<const int*>, const int*, output_iterator<int*> >();
+ test<random_access_iterator<const int*>, const int*, forward_iterator<int*> >();
+ test<random_access_iterator<const int*>, const int*, bidirectional_iterator<int*> >();
+ test<random_access_iterator<const int*>, const int*, random_access_iterator<int*> >();
+ test<random_access_iterator<const int*>, const int*, int*>();
+
+ test<const int*, input_iterator<const int*>, output_iterator<int*> >();
+ test<const int*, input_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<const int*, input_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<const int*, input_iterator<const int*>, random_access_iterator<int*> >();
+ test<const int*, input_iterator<const int*>, int*>();
+
+ test<const int*, forward_iterator<const int*>, output_iterator<int*> >();
+ test<const int*, forward_iterator<const int*>, forward_iterator<int*> >();
+ test<const int*, forward_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<const int*, forward_iterator<const int*>, random_access_iterator<int*> >();
+ test<const int*, forward_iterator<const int*>, int*>();
+
+ test<const int*, bidirectional_iterator<const int*>, output_iterator<int*> >();
+ test<const int*, bidirectional_iterator<const int*>, forward_iterator<int*> >();
+ test<const int*, bidirectional_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<const int*, bidirectional_iterator<const int*>, random_access_iterator<int*> >();
+ test<const int*, bidirectional_iterator<const int*>, int*>();
+
+ test<const int*, random_access_iterator<const int*>, output_iterator<int*> >();
+ test<const int*, random_access_iterator<const int*>, forward_iterator<int*> >();
+ test<const int*, random_access_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<const int*, random_access_iterator<const int*>, random_access_iterator<int*> >();
+ test<const int*, random_access_iterator<const int*>, int*>();
+
+ test<const int*, const int*, output_iterator<int*> >();
+ test<const int*, const int*, forward_iterator<int*> >();
+ test<const int*, const int*, bidirectional_iterator<int*> >();
+ test<const int*, const int*, random_access_iterator<int*> >();
+ test<const int*, const int*, int*>();
+}
diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.set.operations/set.symmetric.difference/set_symmetric_difference.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.set.operations/set.symmetric.difference/set_symmetric_difference.pass.cpp
new file mode 100644
index 00000000000..ea3812a7f1c
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.sorting/alg.set.operations/set.symmetric.difference/set_symmetric_difference.pass.cpp
@@ -0,0 +1,199 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 InIter1, InputIterator InIter2, typename OutIter>
+// requires OutputIterator<OutIter, InIter1::reference>
+// && OutputIterator<OutIter, InIter2::reference>
+// && HasLess<InIter2::value_type, InIter1::value_type>
+// && HasLess<InIter1::value_type, InIter2::value_type>
+// OutIter
+// set_symmetric_difference(InIter1 first1, InIter1 last1,
+// InIter2 first2, InIter2 last2,
+// OutIter result);
+
+#include <algorithm>
+#include <cassert>
+
+#include "test_iterators.h"
+
+template <class Iter1, class Iter2, class OutIter>
+void
+test()
+{
+ int ia[] = {1, 2, 2, 3, 3, 3, 4, 4, 4, 4};
+ const int sa = sizeof(ia)/sizeof(ia[0]);
+ int ib[] = {2, 4, 4, 6};
+ const int sb = sizeof(ib)/sizeof(ib[0]);
+ int ic[20];
+ int ir[] = {1, 2, 3, 3, 3, 4, 4, 6};
+ const int sr = sizeof(ir)/sizeof(ir[0]);
+ OutIter ce = std::set_symmetric_difference(Iter1(ia), Iter1(ia+sa),
+ Iter2(ib), Iter2(ib+sb), OutIter(ic));
+ assert(base(ce) - ic == sr);
+ assert(std::lexicographical_compare(ic, base(ce), ir, ir+sr) == 0);
+ ce = std::set_symmetric_difference(Iter1(ib), Iter1(ib+sb),
+ Iter2(ia), Iter2(ia+sa), OutIter(ic));
+ assert(base(ce) - ic == sr);
+ assert(std::lexicographical_compare(ic, base(ce), ir, ir+sr) == 0);
+}
+
+int main()
+{
+ test<input_iterator<const int*>, input_iterator<const int*>, output_iterator<int*> >();
+ test<input_iterator<const int*>, input_iterator<const int*>, forward_iterator<int*> >();
+ test<input_iterator<const int*>, input_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<input_iterator<const int*>, input_iterator<const int*>, random_access_iterator<int*> >();
+ test<input_iterator<const int*>, input_iterator<const int*>, int*>();
+
+ test<input_iterator<const int*>, forward_iterator<const int*>, output_iterator<int*> >();
+ test<input_iterator<const int*>, forward_iterator<const int*>, forward_iterator<int*> >();
+ test<input_iterator<const int*>, forward_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<input_iterator<const int*>, forward_iterator<const int*>, random_access_iterator<int*> >();
+ test<input_iterator<const int*>, forward_iterator<const int*>, int*>();
+
+ test<input_iterator<const int*>, bidirectional_iterator<const int*>, output_iterator<int*> >();
+ test<input_iterator<const int*>, bidirectional_iterator<const int*>, forward_iterator<int*> >();
+ test<input_iterator<const int*>, bidirectional_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<input_iterator<const int*>, bidirectional_iterator<const int*>, random_access_iterator<int*> >();
+ test<input_iterator<const int*>, bidirectional_iterator<const int*>, int*>();
+
+ test<input_iterator<const int*>, random_access_iterator<const int*>, output_iterator<int*> >();
+ test<input_iterator<const int*>, random_access_iterator<const int*>, forward_iterator<int*> >();
+ test<input_iterator<const int*>, random_access_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<input_iterator<const int*>, random_access_iterator<const int*>, random_access_iterator<int*> >();
+ test<input_iterator<const int*>, random_access_iterator<const int*>, int*>();
+
+ test<input_iterator<const int*>, const int*, output_iterator<int*> >();
+ test<input_iterator<const int*>, const int*, forward_iterator<int*> >();
+ test<input_iterator<const int*>, const int*, bidirectional_iterator<int*> >();
+ test<input_iterator<const int*>, const int*, random_access_iterator<int*> >();
+ test<input_iterator<const int*>, const int*, int*>();
+
+ test<forward_iterator<const int*>, input_iterator<const int*>, output_iterator<int*> >();
+ test<forward_iterator<const int*>, input_iterator<const int*>, forward_iterator<int*> >();
+ test<forward_iterator<const int*>, input_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<forward_iterator<const int*>, input_iterator<const int*>, random_access_iterator<int*> >();
+ test<forward_iterator<const int*>, input_iterator<const int*>, int*>();
+
+ test<forward_iterator<const int*>, forward_iterator<const int*>, output_iterator<int*> >();
+ test<forward_iterator<const int*>, forward_iterator<const int*>, forward_iterator<int*> >();
+ test<forward_iterator<const int*>, forward_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<forward_iterator<const int*>, forward_iterator<const int*>, random_access_iterator<int*> >();
+ test<forward_iterator<const int*>, forward_iterator<const int*>, int*>();
+
+ test<forward_iterator<const int*>, bidirectional_iterator<const int*>, output_iterator<int*> >();
+ test<forward_iterator<const int*>, bidirectional_iterator<const int*>, forward_iterator<int*> >();
+ test<forward_iterator<const int*>, bidirectional_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<forward_iterator<const int*>, bidirectional_iterator<const int*>, random_access_iterator<int*> >();
+ test<forward_iterator<const int*>, bidirectional_iterator<const int*>, int*>();
+
+ test<forward_iterator<const int*>, random_access_iterator<const int*>, output_iterator<int*> >();
+ test<forward_iterator<const int*>, random_access_iterator<const int*>, forward_iterator<int*> >();
+ test<forward_iterator<const int*>, random_access_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<forward_iterator<const int*>, random_access_iterator<const int*>, random_access_iterator<int*> >();
+ test<forward_iterator<const int*>, random_access_iterator<const int*>, int*>();
+
+ test<forward_iterator<const int*>, const int*, output_iterator<int*> >();
+ test<forward_iterator<const int*>, const int*, forward_iterator<int*> >();
+ test<forward_iterator<const int*>, const int*, bidirectional_iterator<int*> >();
+ test<forward_iterator<const int*>, const int*, random_access_iterator<int*> >();
+ test<forward_iterator<const int*>, const int*, int*>();
+
+ test<bidirectional_iterator<const int*>, input_iterator<const int*>, output_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, input_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, input_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, input_iterator<const int*>, random_access_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, input_iterator<const int*>, int*>();
+
+ test<bidirectional_iterator<const int*>, forward_iterator<const int*>, output_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, forward_iterator<const int*>, forward_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, forward_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, forward_iterator<const int*>, random_access_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, forward_iterator<const int*>, int*>();
+
+ test<bidirectional_iterator<const int*>, bidirectional_iterator<const int*>, output_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, bidirectional_iterator<const int*>, forward_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, bidirectional_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, bidirectional_iterator<const int*>, random_access_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, bidirectional_iterator<const int*>, int*>();
+
+ test<bidirectional_iterator<const int*>, random_access_iterator<const int*>, output_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, random_access_iterator<const int*>, forward_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, random_access_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, random_access_iterator<const int*>, random_access_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, random_access_iterator<const int*>, int*>();
+
+ test<bidirectional_iterator<const int*>, const int*, output_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, const int*, forward_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, const int*, bidirectional_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, const int*, random_access_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, const int*, int*>();
+
+ test<random_access_iterator<const int*>, input_iterator<const int*>, output_iterator<int*> >();
+ test<random_access_iterator<const int*>, input_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<random_access_iterator<const int*>, input_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<random_access_iterator<const int*>, input_iterator<const int*>, random_access_iterator<int*> >();
+ test<random_access_iterator<const int*>, input_iterator<const int*>, int*>();
+
+ test<random_access_iterator<const int*>, forward_iterator<const int*>, output_iterator<int*> >();
+ test<random_access_iterator<const int*>, forward_iterator<const int*>, forward_iterator<int*> >();
+ test<random_access_iterator<const int*>, forward_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<random_access_iterator<const int*>, forward_iterator<const int*>, random_access_iterator<int*> >();
+ test<random_access_iterator<const int*>, forward_iterator<const int*>, int*>();
+
+ test<random_access_iterator<const int*>, bidirectional_iterator<const int*>, output_iterator<int*> >();
+ test<random_access_iterator<const int*>, bidirectional_iterator<const int*>, forward_iterator<int*> >();
+ test<random_access_iterator<const int*>, bidirectional_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<random_access_iterator<const int*>, bidirectional_iterator<const int*>, random_access_iterator<int*> >();
+ test<random_access_iterator<const int*>, bidirectional_iterator<const int*>, int*>();
+
+ test<random_access_iterator<const int*>, random_access_iterator<const int*>, output_iterator<int*> >();
+ test<random_access_iterator<const int*>, random_access_iterator<const int*>, forward_iterator<int*> >();
+ test<random_access_iterator<const int*>, random_access_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<random_access_iterator<const int*>, random_access_iterator<const int*>, random_access_iterator<int*> >();
+ test<random_access_iterator<const int*>, random_access_iterator<const int*>, int*>();
+
+ test<random_access_iterator<const int*>, const int*, output_iterator<int*> >();
+ test<random_access_iterator<const int*>, const int*, forward_iterator<int*> >();
+ test<random_access_iterator<const int*>, const int*, bidirectional_iterator<int*> >();
+ test<random_access_iterator<const int*>, const int*, random_access_iterator<int*> >();
+ test<random_access_iterator<const int*>, const int*, int*>();
+
+ test<const int*, input_iterator<const int*>, output_iterator<int*> >();
+ test<const int*, input_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<const int*, input_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<const int*, input_iterator<const int*>, random_access_iterator<int*> >();
+ test<const int*, input_iterator<const int*>, int*>();
+
+ test<const int*, forward_iterator<const int*>, output_iterator<int*> >();
+ test<const int*, forward_iterator<const int*>, forward_iterator<int*> >();
+ test<const int*, forward_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<const int*, forward_iterator<const int*>, random_access_iterator<int*> >();
+ test<const int*, forward_iterator<const int*>, int*>();
+
+ test<const int*, bidirectional_iterator<const int*>, output_iterator<int*> >();
+ test<const int*, bidirectional_iterator<const int*>, forward_iterator<int*> >();
+ test<const int*, bidirectional_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<const int*, bidirectional_iterator<const int*>, random_access_iterator<int*> >();
+ test<const int*, bidirectional_iterator<const int*>, int*>();
+
+ test<const int*, random_access_iterator<const int*>, output_iterator<int*> >();
+ test<const int*, random_access_iterator<const int*>, forward_iterator<int*> >();
+ test<const int*, random_access_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<const int*, random_access_iterator<const int*>, random_access_iterator<int*> >();
+ test<const int*, random_access_iterator<const int*>, int*>();
+
+ test<const int*, const int*, output_iterator<int*> >();
+ test<const int*, const int*, forward_iterator<int*> >();
+ test<const int*, const int*, bidirectional_iterator<int*> >();
+ test<const int*, const int*, random_access_iterator<int*> >();
+ test<const int*, const int*, int*>();
+}
diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.set.operations/set.symmetric.difference/set_symmetric_difference_comp.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.set.operations/set.symmetric.difference/set_symmetric_difference_comp.pass.cpp
new file mode 100644
index 00000000000..ba1f61a1067
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.sorting/alg.set.operations/set.symmetric.difference/set_symmetric_difference_comp.pass.cpp
@@ -0,0 +1,203 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 InIter1, InputIterator InIter2, typename OutIter,
+// CopyConstructible Compare>
+// requires OutputIterator<OutIter, InIter1::reference>
+// && OutputIterator<OutIter, InIter2::reference>
+// && Predicate<Compare, InIter1::value_type, InIter2::value_type>
+// && Predicate<Compare, InIter2::value_type, InIter1::value_type>
+// OutIter
+// set_symmetric_difference(InIter1 first1, InIter1 last1,
+// InIter2 first2, InIter2 last2,
+// OutIter result, Compare comp);
+
+#include <algorithm>
+#include <functional>
+#include <cassert>
+
+#include "test_iterators.h"
+
+template <class Iter1, class Iter2, class OutIter>
+void
+test()
+{
+ int ia[] = {1, 2, 2, 3, 3, 3, 4, 4, 4, 4};
+ const int sa = sizeof(ia)/sizeof(ia[0]);
+ int ib[] = {2, 4, 4, 6};
+ const int sb = sizeof(ib)/sizeof(ib[0]);
+ int ic[20];
+ int ir[] = {1, 2, 3, 3, 3, 4, 4, 6};
+ const int sr = sizeof(ir)/sizeof(ir[0]);
+ OutIter ce = std::set_symmetric_difference(Iter1(ia), Iter1(ia+sa),
+ Iter2(ib), Iter2(ib+sb),
+ OutIter(ic), std::less<int>());
+ assert(base(ce) - ic == sr);
+ assert(std::lexicographical_compare(ic, base(ce), ir, ir+sr) == 0);
+ ce = std::set_symmetric_difference(Iter1(ib), Iter1(ib+sb),
+ Iter2(ia), Iter2(ia+sa),
+ OutIter(ic), std::less<int>());
+ assert(base(ce) - ic == sr);
+ assert(std::lexicographical_compare(ic, base(ce), ir, ir+sr) == 0);
+}
+
+int main()
+{
+ test<input_iterator<const int*>, input_iterator<const int*>, output_iterator<int*> >();
+ test<input_iterator<const int*>, input_iterator<const int*>, forward_iterator<int*> >();
+ test<input_iterator<const int*>, input_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<input_iterator<const int*>, input_iterator<const int*>, random_access_iterator<int*> >();
+ test<input_iterator<const int*>, input_iterator<const int*>, int*>();
+
+ test<input_iterator<const int*>, forward_iterator<const int*>, output_iterator<int*> >();
+ test<input_iterator<const int*>, forward_iterator<const int*>, forward_iterator<int*> >();
+ test<input_iterator<const int*>, forward_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<input_iterator<const int*>, forward_iterator<const int*>, random_access_iterator<int*> >();
+ test<input_iterator<const int*>, forward_iterator<const int*>, int*>();
+
+ test<input_iterator<const int*>, bidirectional_iterator<const int*>, output_iterator<int*> >();
+ test<input_iterator<const int*>, bidirectional_iterator<const int*>, forward_iterator<int*> >();
+ test<input_iterator<const int*>, bidirectional_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<input_iterator<const int*>, bidirectional_iterator<const int*>, random_access_iterator<int*> >();
+ test<input_iterator<const int*>, bidirectional_iterator<const int*>, int*>();
+
+ test<input_iterator<const int*>, random_access_iterator<const int*>, output_iterator<int*> >();
+ test<input_iterator<const int*>, random_access_iterator<const int*>, forward_iterator<int*> >();
+ test<input_iterator<const int*>, random_access_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<input_iterator<const int*>, random_access_iterator<const int*>, random_access_iterator<int*> >();
+ test<input_iterator<const int*>, random_access_iterator<const int*>, int*>();
+
+ test<input_iterator<const int*>, const int*, output_iterator<int*> >();
+ test<input_iterator<const int*>, const int*, forward_iterator<int*> >();
+ test<input_iterator<const int*>, const int*, bidirectional_iterator<int*> >();
+ test<input_iterator<const int*>, const int*, random_access_iterator<int*> >();
+ test<input_iterator<const int*>, const int*, int*>();
+
+ test<forward_iterator<const int*>, input_iterator<const int*>, output_iterator<int*> >();
+ test<forward_iterator<const int*>, input_iterator<const int*>, forward_iterator<int*> >();
+ test<forward_iterator<const int*>, input_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<forward_iterator<const int*>, input_iterator<const int*>, random_access_iterator<int*> >();
+ test<forward_iterator<const int*>, input_iterator<const int*>, int*>();
+
+ test<forward_iterator<const int*>, forward_iterator<const int*>, output_iterator<int*> >();
+ test<forward_iterator<const int*>, forward_iterator<const int*>, forward_iterator<int*> >();
+ test<forward_iterator<const int*>, forward_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<forward_iterator<const int*>, forward_iterator<const int*>, random_access_iterator<int*> >();
+ test<forward_iterator<const int*>, forward_iterator<const int*>, int*>();
+
+ test<forward_iterator<const int*>, bidirectional_iterator<const int*>, output_iterator<int*> >();
+ test<forward_iterator<const int*>, bidirectional_iterator<const int*>, forward_iterator<int*> >();
+ test<forward_iterator<const int*>, bidirectional_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<forward_iterator<const int*>, bidirectional_iterator<const int*>, random_access_iterator<int*> >();
+ test<forward_iterator<const int*>, bidirectional_iterator<const int*>, int*>();
+
+ test<forward_iterator<const int*>, random_access_iterator<const int*>, output_iterator<int*> >();
+ test<forward_iterator<const int*>, random_access_iterator<const int*>, forward_iterator<int*> >();
+ test<forward_iterator<const int*>, random_access_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<forward_iterator<const int*>, random_access_iterator<const int*>, random_access_iterator<int*> >();
+ test<forward_iterator<const int*>, random_access_iterator<const int*>, int*>();
+
+ test<forward_iterator<const int*>, const int*, output_iterator<int*> >();
+ test<forward_iterator<const int*>, const int*, forward_iterator<int*> >();
+ test<forward_iterator<const int*>, const int*, bidirectional_iterator<int*> >();
+ test<forward_iterator<const int*>, const int*, random_access_iterator<int*> >();
+ test<forward_iterator<const int*>, const int*, int*>();
+
+ test<bidirectional_iterator<const int*>, input_iterator<const int*>, output_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, input_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, input_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, input_iterator<const int*>, random_access_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, input_iterator<const int*>, int*>();
+
+ test<bidirectional_iterator<const int*>, forward_iterator<const int*>, output_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, forward_iterator<const int*>, forward_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, forward_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, forward_iterator<const int*>, random_access_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, forward_iterator<const int*>, int*>();
+
+ test<bidirectional_iterator<const int*>, bidirectional_iterator<const int*>, output_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, bidirectional_iterator<const int*>, forward_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, bidirectional_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, bidirectional_iterator<const int*>, random_access_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, bidirectional_iterator<const int*>, int*>();
+
+ test<bidirectional_iterator<const int*>, random_access_iterator<const int*>, output_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, random_access_iterator<const int*>, forward_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, random_access_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, random_access_iterator<const int*>, random_access_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, random_access_iterator<const int*>, int*>();
+
+ test<bidirectional_iterator<const int*>, const int*, output_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, const int*, forward_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, const int*, bidirectional_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, const int*, random_access_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, const int*, int*>();
+
+ test<random_access_iterator<const int*>, input_iterator<const int*>, output_iterator<int*> >();
+ test<random_access_iterator<const int*>, input_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<random_access_iterator<const int*>, input_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<random_access_iterator<const int*>, input_iterator<const int*>, random_access_iterator<int*> >();
+ test<random_access_iterator<const int*>, input_iterator<const int*>, int*>();
+
+ test<random_access_iterator<const int*>, forward_iterator<const int*>, output_iterator<int*> >();
+ test<random_access_iterator<const int*>, forward_iterator<const int*>, forward_iterator<int*> >();
+ test<random_access_iterator<const int*>, forward_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<random_access_iterator<const int*>, forward_iterator<const int*>, random_access_iterator<int*> >();
+ test<random_access_iterator<const int*>, forward_iterator<const int*>, int*>();
+
+ test<random_access_iterator<const int*>, bidirectional_iterator<const int*>, output_iterator<int*> >();
+ test<random_access_iterator<const int*>, bidirectional_iterator<const int*>, forward_iterator<int*> >();
+ test<random_access_iterator<const int*>, bidirectional_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<random_access_iterator<const int*>, bidirectional_iterator<const int*>, random_access_iterator<int*> >();
+ test<random_access_iterator<const int*>, bidirectional_iterator<const int*>, int*>();
+
+ test<random_access_iterator<const int*>, random_access_iterator<const int*>, output_iterator<int*> >();
+ test<random_access_iterator<const int*>, random_access_iterator<const int*>, forward_iterator<int*> >();
+ test<random_access_iterator<const int*>, random_access_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<random_access_iterator<const int*>, random_access_iterator<const int*>, random_access_iterator<int*> >();
+ test<random_access_iterator<const int*>, random_access_iterator<const int*>, int*>();
+
+ test<random_access_iterator<const int*>, const int*, output_iterator<int*> >();
+ test<random_access_iterator<const int*>, const int*, forward_iterator<int*> >();
+ test<random_access_iterator<const int*>, const int*, bidirectional_iterator<int*> >();
+ test<random_access_iterator<const int*>, const int*, random_access_iterator<int*> >();
+ test<random_access_iterator<const int*>, const int*, int*>();
+
+ test<const int*, input_iterator<const int*>, output_iterator<int*> >();
+ test<const int*, input_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<const int*, input_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<const int*, input_iterator<const int*>, random_access_iterator<int*> >();
+ test<const int*, input_iterator<const int*>, int*>();
+
+ test<const int*, forward_iterator<const int*>, output_iterator<int*> >();
+ test<const int*, forward_iterator<const int*>, forward_iterator<int*> >();
+ test<const int*, forward_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<const int*, forward_iterator<const int*>, random_access_iterator<int*> >();
+ test<const int*, forward_iterator<const int*>, int*>();
+
+ test<const int*, bidirectional_iterator<const int*>, output_iterator<int*> >();
+ test<const int*, bidirectional_iterator<const int*>, forward_iterator<int*> >();
+ test<const int*, bidirectional_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<const int*, bidirectional_iterator<const int*>, random_access_iterator<int*> >();
+ test<const int*, bidirectional_iterator<const int*>, int*>();
+
+ test<const int*, random_access_iterator<const int*>, output_iterator<int*> >();
+ test<const int*, random_access_iterator<const int*>, forward_iterator<int*> >();
+ test<const int*, random_access_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<const int*, random_access_iterator<const int*>, random_access_iterator<int*> >();
+ test<const int*, random_access_iterator<const int*>, int*>();
+
+ test<const int*, const int*, output_iterator<int*> >();
+ test<const int*, const int*, forward_iterator<int*> >();
+ test<const int*, const int*, bidirectional_iterator<int*> >();
+ test<const int*, const int*, random_access_iterator<int*> >();
+ test<const int*, const int*, int*>();
+}
diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.set.operations/set.union/set_union.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.set.operations/set.union/set_union.pass.cpp
new file mode 100644
index 00000000000..46578501d77
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.sorting/alg.set.operations/set.union/set_union.pass.cpp
@@ -0,0 +1,198 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 InIter1, InputIterator InIter2, typename OutIter>
+// requires OutputIterator<OutIter, InIter1::reference>
+// && OutputIterator<OutIter, InIter2::reference>
+// && HasLess<InIter2::value_type, InIter1::value_type>
+// && HasLess<InIter1::value_type, InIter2::value_type>
+// OutIter
+// set_union(InIter1 first1, InIter1 last1,
+// InIter2 first2, InIter2 last2, OutIter result);
+
+#include <algorithm>
+#include <cassert>
+
+#include "test_iterators.h"
+
+template <class Iter1, class Iter2, class OutIter>
+void
+test()
+{
+ int ia[] = {1, 2, 2, 3, 3, 3, 4, 4, 4, 4};
+ const int sa = sizeof(ia)/sizeof(ia[0]);
+ int ib[] = {2, 4, 4, 6};
+ const int sb = sizeof(ib)/sizeof(ib[0]);
+ int ic[20];
+ int ir[] = {1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 6};
+ const int sr = sizeof(ir)/sizeof(ir[0]);
+ OutIter ce = std::set_union(Iter1(ia), Iter1(ia+sa),
+ Iter2(ib), Iter2(ib+sb), OutIter(ic));
+ assert(base(ce) - ic == sr);
+ assert(std::lexicographical_compare(ic, base(ce), ir, ir+sr) == 0);
+ ce = std::set_union(Iter1(ib), Iter1(ib+sb),
+ Iter2(ia), Iter2(ia+sa), OutIter(ic));
+ assert(base(ce) - ic == sr);
+ assert(std::lexicographical_compare(ic, base(ce), ir, ir+sr) == 0);
+}
+
+int main()
+{
+ test<input_iterator<const int*>, input_iterator<const int*>, output_iterator<int*> >();
+ test<input_iterator<const int*>, input_iterator<const int*>, forward_iterator<int*> >();
+ test<input_iterator<const int*>, input_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<input_iterator<const int*>, input_iterator<const int*>, random_access_iterator<int*> >();
+ test<input_iterator<const int*>, input_iterator<const int*>, int*>();
+
+ test<input_iterator<const int*>, forward_iterator<const int*>, output_iterator<int*> >();
+ test<input_iterator<const int*>, forward_iterator<const int*>, forward_iterator<int*> >();
+ test<input_iterator<const int*>, forward_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<input_iterator<const int*>, forward_iterator<const int*>, random_access_iterator<int*> >();
+ test<input_iterator<const int*>, forward_iterator<const int*>, int*>();
+
+ test<input_iterator<const int*>, bidirectional_iterator<const int*>, output_iterator<int*> >();
+ test<input_iterator<const int*>, bidirectional_iterator<const int*>, forward_iterator<int*> >();
+ test<input_iterator<const int*>, bidirectional_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<input_iterator<const int*>, bidirectional_iterator<const int*>, random_access_iterator<int*> >();
+ test<input_iterator<const int*>, bidirectional_iterator<const int*>, int*>();
+
+ test<input_iterator<const int*>, random_access_iterator<const int*>, output_iterator<int*> >();
+ test<input_iterator<const int*>, random_access_iterator<const int*>, forward_iterator<int*> >();
+ test<input_iterator<const int*>, random_access_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<input_iterator<const int*>, random_access_iterator<const int*>, random_access_iterator<int*> >();
+ test<input_iterator<const int*>, random_access_iterator<const int*>, int*>();
+
+ test<input_iterator<const int*>, const int*, output_iterator<int*> >();
+ test<input_iterator<const int*>, const int*, forward_iterator<int*> >();
+ test<input_iterator<const int*>, const int*, bidirectional_iterator<int*> >();
+ test<input_iterator<const int*>, const int*, random_access_iterator<int*> >();
+ test<input_iterator<const int*>, const int*, int*>();
+
+ test<forward_iterator<const int*>, input_iterator<const int*>, output_iterator<int*> >();
+ test<forward_iterator<const int*>, input_iterator<const int*>, forward_iterator<int*> >();
+ test<forward_iterator<const int*>, input_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<forward_iterator<const int*>, input_iterator<const int*>, random_access_iterator<int*> >();
+ test<forward_iterator<const int*>, input_iterator<const int*>, int*>();
+
+ test<forward_iterator<const int*>, forward_iterator<const int*>, output_iterator<int*> >();
+ test<forward_iterator<const int*>, forward_iterator<const int*>, forward_iterator<int*> >();
+ test<forward_iterator<const int*>, forward_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<forward_iterator<const int*>, forward_iterator<const int*>, random_access_iterator<int*> >();
+ test<forward_iterator<const int*>, forward_iterator<const int*>, int*>();
+
+ test<forward_iterator<const int*>, bidirectional_iterator<const int*>, output_iterator<int*> >();
+ test<forward_iterator<const int*>, bidirectional_iterator<const int*>, forward_iterator<int*> >();
+ test<forward_iterator<const int*>, bidirectional_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<forward_iterator<const int*>, bidirectional_iterator<const int*>, random_access_iterator<int*> >();
+ test<forward_iterator<const int*>, bidirectional_iterator<const int*>, int*>();
+
+ test<forward_iterator<const int*>, random_access_iterator<const int*>, output_iterator<int*> >();
+ test<forward_iterator<const int*>, random_access_iterator<const int*>, forward_iterator<int*> >();
+ test<forward_iterator<const int*>, random_access_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<forward_iterator<const int*>, random_access_iterator<const int*>, random_access_iterator<int*> >();
+ test<forward_iterator<const int*>, random_access_iterator<const int*>, int*>();
+
+ test<forward_iterator<const int*>, const int*, output_iterator<int*> >();
+ test<forward_iterator<const int*>, const int*, forward_iterator<int*> >();
+ test<forward_iterator<const int*>, const int*, bidirectional_iterator<int*> >();
+ test<forward_iterator<const int*>, const int*, random_access_iterator<int*> >();
+ test<forward_iterator<const int*>, const int*, int*>();
+
+ test<bidirectional_iterator<const int*>, input_iterator<const int*>, output_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, input_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, input_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, input_iterator<const int*>, random_access_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, input_iterator<const int*>, int*>();
+
+ test<bidirectional_iterator<const int*>, forward_iterator<const int*>, output_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, forward_iterator<const int*>, forward_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, forward_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, forward_iterator<const int*>, random_access_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, forward_iterator<const int*>, int*>();
+
+ test<bidirectional_iterator<const int*>, bidirectional_iterator<const int*>, output_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, bidirectional_iterator<const int*>, forward_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, bidirectional_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, bidirectional_iterator<const int*>, random_access_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, bidirectional_iterator<const int*>, int*>();
+
+ test<bidirectional_iterator<const int*>, random_access_iterator<const int*>, output_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, random_access_iterator<const int*>, forward_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, random_access_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, random_access_iterator<const int*>, random_access_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, random_access_iterator<const int*>, int*>();
+
+ test<bidirectional_iterator<const int*>, const int*, output_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, const int*, forward_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, const int*, bidirectional_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, const int*, random_access_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, const int*, int*>();
+
+ test<random_access_iterator<const int*>, input_iterator<const int*>, output_iterator<int*> >();
+ test<random_access_iterator<const int*>, input_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<random_access_iterator<const int*>, input_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<random_access_iterator<const int*>, input_iterator<const int*>, random_access_iterator<int*> >();
+ test<random_access_iterator<const int*>, input_iterator<const int*>, int*>();
+
+ test<random_access_iterator<const int*>, forward_iterator<const int*>, output_iterator<int*> >();
+ test<random_access_iterator<const int*>, forward_iterator<const int*>, forward_iterator<int*> >();
+ test<random_access_iterator<const int*>, forward_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<random_access_iterator<const int*>, forward_iterator<const int*>, random_access_iterator<int*> >();
+ test<random_access_iterator<const int*>, forward_iterator<const int*>, int*>();
+
+ test<random_access_iterator<const int*>, bidirectional_iterator<const int*>, output_iterator<int*> >();
+ test<random_access_iterator<const int*>, bidirectional_iterator<const int*>, forward_iterator<int*> >();
+ test<random_access_iterator<const int*>, bidirectional_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<random_access_iterator<const int*>, bidirectional_iterator<const int*>, random_access_iterator<int*> >();
+ test<random_access_iterator<const int*>, bidirectional_iterator<const int*>, int*>();
+
+ test<random_access_iterator<const int*>, random_access_iterator<const int*>, output_iterator<int*> >();
+ test<random_access_iterator<const int*>, random_access_iterator<const int*>, forward_iterator<int*> >();
+ test<random_access_iterator<const int*>, random_access_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<random_access_iterator<const int*>, random_access_iterator<const int*>, random_access_iterator<int*> >();
+ test<random_access_iterator<const int*>, random_access_iterator<const int*>, int*>();
+
+ test<random_access_iterator<const int*>, const int*, output_iterator<int*> >();
+ test<random_access_iterator<const int*>, const int*, forward_iterator<int*> >();
+ test<random_access_iterator<const int*>, const int*, bidirectional_iterator<int*> >();
+ test<random_access_iterator<const int*>, const int*, random_access_iterator<int*> >();
+ test<random_access_iterator<const int*>, const int*, int*>();
+
+ test<const int*, input_iterator<const int*>, output_iterator<int*> >();
+ test<const int*, input_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<const int*, input_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<const int*, input_iterator<const int*>, random_access_iterator<int*> >();
+ test<const int*, input_iterator<const int*>, int*>();
+
+ test<const int*, forward_iterator<const int*>, output_iterator<int*> >();
+ test<const int*, forward_iterator<const int*>, forward_iterator<int*> >();
+ test<const int*, forward_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<const int*, forward_iterator<const int*>, random_access_iterator<int*> >();
+ test<const int*, forward_iterator<const int*>, int*>();
+
+ test<const int*, bidirectional_iterator<const int*>, output_iterator<int*> >();
+ test<const int*, bidirectional_iterator<const int*>, forward_iterator<int*> >();
+ test<const int*, bidirectional_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<const int*, bidirectional_iterator<const int*>, random_access_iterator<int*> >();
+ test<const int*, bidirectional_iterator<const int*>, int*>();
+
+ test<const int*, random_access_iterator<const int*>, output_iterator<int*> >();
+ test<const int*, random_access_iterator<const int*>, forward_iterator<int*> >();
+ test<const int*, random_access_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<const int*, random_access_iterator<const int*>, random_access_iterator<int*> >();
+ test<const int*, random_access_iterator<const int*>, int*>();
+
+ test<const int*, const int*, output_iterator<int*> >();
+ test<const int*, const int*, forward_iterator<int*> >();
+ test<const int*, const int*, bidirectional_iterator<int*> >();
+ test<const int*, const int*, random_access_iterator<int*> >();
+ test<const int*, const int*, int*>();
+}
diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.set.operations/set.union/set_union_comp.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.set.operations/set.union/set_union_comp.pass.cpp
new file mode 100644
index 00000000000..3d63e3fb9c4
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.sorting/alg.set.operations/set.union/set_union_comp.pass.cpp
@@ -0,0 +1,200 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 InIter1, InputIterator InIter2, typename OutIter,
+// CopyConstructible Compare>
+// requires OutputIterator<OutIter, InIter1::reference>
+// && OutputIterator<OutIter, InIter2::reference>
+// && Predicate<Compare, InIter1::value_type, InIter2::value_type>
+// && Predicate<Compare, InIter2::value_type, InIter1::value_type>
+// OutIter
+// set_union(InIter1 first1, InIter1 last1, InIter2 first2, InIter2 last2,
+// OutIter result, Compare comp);
+
+#include <algorithm>
+#include <functional>
+#include <cassert>
+
+#include "test_iterators.h"
+
+template <class Iter1, class Iter2, class OutIter>
+void
+test()
+{
+ int ia[] = {1, 2, 2, 3, 3, 3, 4, 4, 4, 4};
+ const int sa = sizeof(ia)/sizeof(ia[0]);
+ int ib[] = {2, 4, 4, 6};
+ const int sb = sizeof(ib)/sizeof(ib[0]);
+ int ic[20];
+ int ir[] = {1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 6};
+ const int sr = sizeof(ir)/sizeof(ir[0]);
+ OutIter ce = std::set_union(Iter1(ia), Iter1(ia+sa),
+ Iter2(ib), Iter2(ib+sb), OutIter(ic), std::less<int>());
+ assert(base(ce) - ic == sr);
+ assert(std::lexicographical_compare(ic, base(ce), ir, ir+sr) == 0);
+ ce = std::set_union(Iter1(ib), Iter1(ib+sb),
+ Iter2(ia), Iter2(ia+sa), OutIter(ic), std::less<int>());
+ assert(base(ce) - ic == sr);
+ assert(std::lexicographical_compare(ic, base(ce), ir, ir+sr) == 0);
+}
+
+int main()
+{
+ test<input_iterator<const int*>, input_iterator<const int*>, output_iterator<int*> >();
+ test<input_iterator<const int*>, input_iterator<const int*>, forward_iterator<int*> >();
+ test<input_iterator<const int*>, input_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<input_iterator<const int*>, input_iterator<const int*>, random_access_iterator<int*> >();
+ test<input_iterator<const int*>, input_iterator<const int*>, int*>();
+
+ test<input_iterator<const int*>, forward_iterator<const int*>, output_iterator<int*> >();
+ test<input_iterator<const int*>, forward_iterator<const int*>, forward_iterator<int*> >();
+ test<input_iterator<const int*>, forward_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<input_iterator<const int*>, forward_iterator<const int*>, random_access_iterator<int*> >();
+ test<input_iterator<const int*>, forward_iterator<const int*>, int*>();
+
+ test<input_iterator<const int*>, bidirectional_iterator<const int*>, output_iterator<int*> >();
+ test<input_iterator<const int*>, bidirectional_iterator<const int*>, forward_iterator<int*> >();
+ test<input_iterator<const int*>, bidirectional_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<input_iterator<const int*>, bidirectional_iterator<const int*>, random_access_iterator<int*> >();
+ test<input_iterator<const int*>, bidirectional_iterator<const int*>, int*>();
+
+ test<input_iterator<const int*>, random_access_iterator<const int*>, output_iterator<int*> >();
+ test<input_iterator<const int*>, random_access_iterator<const int*>, forward_iterator<int*> >();
+ test<input_iterator<const int*>, random_access_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<input_iterator<const int*>, random_access_iterator<const int*>, random_access_iterator<int*> >();
+ test<input_iterator<const int*>, random_access_iterator<const int*>, int*>();
+
+ test<input_iterator<const int*>, const int*, output_iterator<int*> >();
+ test<input_iterator<const int*>, const int*, forward_iterator<int*> >();
+ test<input_iterator<const int*>, const int*, bidirectional_iterator<int*> >();
+ test<input_iterator<const int*>, const int*, random_access_iterator<int*> >();
+ test<input_iterator<const int*>, const int*, int*>();
+
+ test<forward_iterator<const int*>, input_iterator<const int*>, output_iterator<int*> >();
+ test<forward_iterator<const int*>, input_iterator<const int*>, forward_iterator<int*> >();
+ test<forward_iterator<const int*>, input_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<forward_iterator<const int*>, input_iterator<const int*>, random_access_iterator<int*> >();
+ test<forward_iterator<const int*>, input_iterator<const int*>, int*>();
+
+ test<forward_iterator<const int*>, forward_iterator<const int*>, output_iterator<int*> >();
+ test<forward_iterator<const int*>, forward_iterator<const int*>, forward_iterator<int*> >();
+ test<forward_iterator<const int*>, forward_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<forward_iterator<const int*>, forward_iterator<const int*>, random_access_iterator<int*> >();
+ test<forward_iterator<const int*>, forward_iterator<const int*>, int*>();
+
+ test<forward_iterator<const int*>, bidirectional_iterator<const int*>, output_iterator<int*> >();
+ test<forward_iterator<const int*>, bidirectional_iterator<const int*>, forward_iterator<int*> >();
+ test<forward_iterator<const int*>, bidirectional_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<forward_iterator<const int*>, bidirectional_iterator<const int*>, random_access_iterator<int*> >();
+ test<forward_iterator<const int*>, bidirectional_iterator<const int*>, int*>();
+
+ test<forward_iterator<const int*>, random_access_iterator<const int*>, output_iterator<int*> >();
+ test<forward_iterator<const int*>, random_access_iterator<const int*>, forward_iterator<int*> >();
+ test<forward_iterator<const int*>, random_access_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<forward_iterator<const int*>, random_access_iterator<const int*>, random_access_iterator<int*> >();
+ test<forward_iterator<const int*>, random_access_iterator<const int*>, int*>();
+
+ test<forward_iterator<const int*>, const int*, output_iterator<int*> >();
+ test<forward_iterator<const int*>, const int*, forward_iterator<int*> >();
+ test<forward_iterator<const int*>, const int*, bidirectional_iterator<int*> >();
+ test<forward_iterator<const int*>, const int*, random_access_iterator<int*> >();
+ test<forward_iterator<const int*>, const int*, int*>();
+
+ test<bidirectional_iterator<const int*>, input_iterator<const int*>, output_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, input_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, input_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, input_iterator<const int*>, random_access_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, input_iterator<const int*>, int*>();
+
+ test<bidirectional_iterator<const int*>, forward_iterator<const int*>, output_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, forward_iterator<const int*>, forward_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, forward_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, forward_iterator<const int*>, random_access_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, forward_iterator<const int*>, int*>();
+
+ test<bidirectional_iterator<const int*>, bidirectional_iterator<const int*>, output_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, bidirectional_iterator<const int*>, forward_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, bidirectional_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, bidirectional_iterator<const int*>, random_access_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, bidirectional_iterator<const int*>, int*>();
+
+ test<bidirectional_iterator<const int*>, random_access_iterator<const int*>, output_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, random_access_iterator<const int*>, forward_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, random_access_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, random_access_iterator<const int*>, random_access_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, random_access_iterator<const int*>, int*>();
+
+ test<bidirectional_iterator<const int*>, const int*, output_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, const int*, forward_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, const int*, bidirectional_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, const int*, random_access_iterator<int*> >();
+ test<bidirectional_iterator<const int*>, const int*, int*>();
+
+ test<random_access_iterator<const int*>, input_iterator<const int*>, output_iterator<int*> >();
+ test<random_access_iterator<const int*>, input_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<random_access_iterator<const int*>, input_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<random_access_iterator<const int*>, input_iterator<const int*>, random_access_iterator<int*> >();
+ test<random_access_iterator<const int*>, input_iterator<const int*>, int*>();
+
+ test<random_access_iterator<const int*>, forward_iterator<const int*>, output_iterator<int*> >();
+ test<random_access_iterator<const int*>, forward_iterator<const int*>, forward_iterator<int*> >();
+ test<random_access_iterator<const int*>, forward_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<random_access_iterator<const int*>, forward_iterator<const int*>, random_access_iterator<int*> >();
+ test<random_access_iterator<const int*>, forward_iterator<const int*>, int*>();
+
+ test<random_access_iterator<const int*>, bidirectional_iterator<const int*>, output_iterator<int*> >();
+ test<random_access_iterator<const int*>, bidirectional_iterator<const int*>, forward_iterator<int*> >();
+ test<random_access_iterator<const int*>, bidirectional_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<random_access_iterator<const int*>, bidirectional_iterator<const int*>, random_access_iterator<int*> >();
+ test<random_access_iterator<const int*>, bidirectional_iterator<const int*>, int*>();
+
+ test<random_access_iterator<const int*>, random_access_iterator<const int*>, output_iterator<int*> >();
+ test<random_access_iterator<const int*>, random_access_iterator<const int*>, forward_iterator<int*> >();
+ test<random_access_iterator<const int*>, random_access_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<random_access_iterator<const int*>, random_access_iterator<const int*>, random_access_iterator<int*> >();
+ test<random_access_iterator<const int*>, random_access_iterator<const int*>, int*>();
+
+ test<random_access_iterator<const int*>, const int*, output_iterator<int*> >();
+ test<random_access_iterator<const int*>, const int*, forward_iterator<int*> >();
+ test<random_access_iterator<const int*>, const int*, bidirectional_iterator<int*> >();
+ test<random_access_iterator<const int*>, const int*, random_access_iterator<int*> >();
+ test<random_access_iterator<const int*>, const int*, int*>();
+
+ test<const int*, input_iterator<const int*>, output_iterator<int*> >();
+ test<const int*, input_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<const int*, input_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<const int*, input_iterator<const int*>, random_access_iterator<int*> >();
+ test<const int*, input_iterator<const int*>, int*>();
+
+ test<const int*, forward_iterator<const int*>, output_iterator<int*> >();
+ test<const int*, forward_iterator<const int*>, forward_iterator<int*> >();
+ test<const int*, forward_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<const int*, forward_iterator<const int*>, random_access_iterator<int*> >();
+ test<const int*, forward_iterator<const int*>, int*>();
+
+ test<const int*, bidirectional_iterator<const int*>, output_iterator<int*> >();
+ test<const int*, bidirectional_iterator<const int*>, forward_iterator<int*> >();
+ test<const int*, bidirectional_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<const int*, bidirectional_iterator<const int*>, random_access_iterator<int*> >();
+ test<const int*, bidirectional_iterator<const int*>, int*>();
+
+ test<const int*, random_access_iterator<const int*>, output_iterator<int*> >();
+ test<const int*, random_access_iterator<const int*>, forward_iterator<int*> >();
+ test<const int*, random_access_iterator<const int*>, bidirectional_iterator<int*> >();
+ test<const int*, random_access_iterator<const int*>, random_access_iterator<int*> >();
+ test<const int*, random_access_iterator<const int*>, int*>();
+
+ test<const int*, const int*, output_iterator<int*> >();
+ test<const int*, const int*, forward_iterator<int*> >();
+ test<const int*, const int*, bidirectional_iterator<int*> >();
+ test<const int*, const int*, random_access_iterator<int*> >();
+ test<const int*, const int*, int*>();
+}
diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.sort/is.sorted/is_sorted.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.sort/is.sorted/is_sorted.pass.cpp
new file mode 100644
index 00000000000..dd6b5c1766a
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.sorting/alg.sort/is.sorted/is_sorted.pass.cpp
@@ -0,0 +1,183 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 LessThanComparable<Iter::value_type>
+// bool
+// is_sorted(Iter first, Iter last);
+
+#include <algorithm>
+#include <cassert>
+
+#include "test_iterators.h"
+
+template <class Iter>
+void
+test()
+{
+ {
+ int a[] = {0};
+ unsigned sa = sizeof(a) / sizeof(a[0]);
+ assert(std::is_sorted(Iter(a), Iter(a)));
+ assert(std::is_sorted(Iter(a), Iter(a+sa)));
+ }
+
+ {
+ int a[] = {0, 0};
+ unsigned sa = sizeof(a) / sizeof(a[0]);
+ assert(std::is_sorted(Iter(a), Iter(a+sa)));
+ }
+ {
+ int a[] = {0, 1};
+ unsigned sa = sizeof(a) / sizeof(a[0]);
+ assert(std::is_sorted(Iter(a), Iter(a+sa)));
+ }
+ {
+ int a[] = {1, 0};
+ unsigned sa = sizeof(a) / sizeof(a[0]);
+ assert(!std::is_sorted(Iter(a), Iter(a+sa)));
+ }
+ {
+ int a[] = {1, 1};
+ unsigned sa = sizeof(a) / sizeof(a[0]);
+ assert(std::is_sorted(Iter(a), Iter(a+sa)));
+ }
+
+ {
+ int a[] = {0, 0, 0};
+ unsigned sa = sizeof(a) / sizeof(a[0]);
+ assert(std::is_sorted(Iter(a), Iter(a+sa)));
+ }
+ {
+ int a[] = {0, 0, 1};
+ unsigned sa = sizeof(a) / sizeof(a[0]);
+ assert(std::is_sorted(Iter(a), Iter(a+sa)));
+ }
+ {
+ int a[] = {0, 1, 0};
+ unsigned sa = sizeof(a) / sizeof(a[0]);
+ assert(!std::is_sorted(Iter(a), Iter(a+sa)));
+ }
+ {
+ int a[] = {0, 1, 1};
+ unsigned sa = sizeof(a) / sizeof(a[0]);
+ assert(std::is_sorted(Iter(a), Iter(a+sa)));
+ }
+ {
+ int a[] = {1, 0, 0};
+ unsigned sa = sizeof(a) / sizeof(a[0]);
+ assert(!std::is_sorted(Iter(a), Iter(a+sa)));
+ }
+ {
+ int a[] = {1, 0, 1};
+ unsigned sa = sizeof(a) / sizeof(a[0]);
+ assert(!std::is_sorted(Iter(a), Iter(a+sa)));
+ }
+ {
+ int a[] = {1, 1, 0};
+ unsigned sa = sizeof(a) / sizeof(a[0]);
+ assert(!std::is_sorted(Iter(a), Iter(a+sa)));
+ }
+ {
+ int a[] = {1, 1, 1};
+ unsigned sa = sizeof(a) / sizeof(a[0]);
+ assert(std::is_sorted(Iter(a), Iter(a+sa)));
+ }
+
+ {
+ int a[] = {0, 0, 0, 0};
+ unsigned sa = sizeof(a) / sizeof(a[0]);
+ assert(std::is_sorted(Iter(a), Iter(a+sa)));
+ }
+ {
+ int a[] = {0, 0, 0, 1};
+ unsigned sa = sizeof(a) / sizeof(a[0]);
+ assert(std::is_sorted(Iter(a), Iter(a+sa)));
+ }
+ {
+ int a[] = {0, 0, 1, 0};
+ unsigned sa = sizeof(a) / sizeof(a[0]);
+ assert(!std::is_sorted(Iter(a), Iter(a+sa)));
+ }
+ {
+ int a[] = {0, 0, 1, 1};
+ unsigned sa = sizeof(a) / sizeof(a[0]);
+ assert(std::is_sorted(Iter(a), Iter(a+sa)));
+ }
+ {
+ int a[] = {0, 1, 0, 0};
+ unsigned sa = sizeof(a) / sizeof(a[0]);
+ assert(!std::is_sorted(Iter(a), Iter(a+sa)));
+ }
+ {
+ int a[] = {0, 1, 0, 1};
+ unsigned sa = sizeof(a) / sizeof(a[0]);
+ assert(!std::is_sorted(Iter(a), Iter(a+sa)));
+ }
+ {
+ int a[] = {0, 1, 1, 0};
+ unsigned sa = sizeof(a) / sizeof(a[0]);
+ assert(!std::is_sorted(Iter(a), Iter(a+sa)));
+ }
+ {
+ int a[] = {0, 1, 1, 1};
+ unsigned sa = sizeof(a) / sizeof(a[0]);
+ assert(std::is_sorted(Iter(a), Iter(a+sa)));
+ }
+ {
+ int a[] = {1, 0, 0, 0};
+ unsigned sa = sizeof(a) / sizeof(a[0]);
+ assert(!std::is_sorted(Iter(a), Iter(a+sa)));
+ }
+ {
+ int a[] = {1, 0, 0, 1};
+ unsigned sa = sizeof(a) / sizeof(a[0]);
+ assert(!std::is_sorted(Iter(a), Iter(a+sa)));
+ }
+ {
+ int a[] = {1, 0, 1, 0};
+ unsigned sa = sizeof(a) / sizeof(a[0]);
+ assert(!std::is_sorted(Iter(a), Iter(a+sa)));
+ }
+ {
+ int a[] = {1, 0, 1, 1};
+ unsigned sa = sizeof(a) / sizeof(a[0]);
+ assert(!std::is_sorted(Iter(a), Iter(a+sa)));
+ }
+ {
+ int a[] = {1, 1, 0, 0};
+ unsigned sa = sizeof(a) / sizeof(a[0]);
+ assert(!std::is_sorted(Iter(a), Iter(a+sa)));
+ }
+ {
+ int a[] = {1, 1, 0, 1};
+ unsigned sa = sizeof(a) / sizeof(a[0]);
+ assert(!std::is_sorted(Iter(a), Iter(a+sa)));
+ }
+ {
+ int a[] = {1, 1, 1, 0};
+ unsigned sa = sizeof(a) / sizeof(a[0]);
+ assert(!std::is_sorted(Iter(a), Iter(a+sa)));
+ }
+ {
+ int a[] = {1, 1, 1, 1};
+ unsigned sa = sizeof(a) / sizeof(a[0]);
+ assert(std::is_sorted(Iter(a), Iter(a+sa)));
+ }
+}
+
+int main()
+{
+ test<forward_iterator<const int*> >();
+ test<bidirectional_iterator<const int*> >();
+ test<random_access_iterator<const int*> >();
+ test<const int*>();
+}
diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.sort/is.sorted/is_sorted_comp.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.sort/is.sorted/is_sorted_comp.pass.cpp
new file mode 100644
index 00000000000..d5a34e2f2cb
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.sorting/alg.sort/is.sorted/is_sorted_comp.pass.cpp
@@ -0,0 +1,184 @@
+//===----------------------------------------------------------------------===//
+//
+// 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, StrictWeakOrder<auto, Iter::value_type> Compare>
+// requires CopyConstructible<Compare>
+// bool
+// is_sorted(Iter first, Iter last, Compare comp);
+
+#include <algorithm>
+#include <functional>
+#include <cassert>
+
+#include "test_iterators.h"
+
+template <class Iter>
+void
+test()
+{
+ {
+ int a[] = {0};
+ unsigned sa = sizeof(a) / sizeof(a[0]);
+ assert(std::is_sorted(Iter(a), Iter(a)));
+ assert(std::is_sorted(Iter(a), Iter(a+sa), std::greater<int>()));
+ }
+
+ {
+ int a[] = {0, 0};
+ unsigned sa = sizeof(a) / sizeof(a[0]);
+ assert(std::is_sorted(Iter(a), Iter(a+sa), std::greater<int>()));
+ }
+ {
+ int a[] = {0, 1};
+ unsigned sa = sizeof(a) / sizeof(a[0]);
+ assert(!std::is_sorted(Iter(a), Iter(a+sa), std::greater<int>()));
+ }
+ {
+ int a[] = {1, 0};
+ unsigned sa = sizeof(a) / sizeof(a[0]);
+ assert(std::is_sorted(Iter(a), Iter(a+sa), std::greater<int>()));
+ }
+ {
+ int a[] = {1, 1};
+ unsigned sa = sizeof(a) / sizeof(a[0]);
+ assert(std::is_sorted(Iter(a), Iter(a+sa), std::greater<int>()));
+ }
+
+ {
+ int a[] = {0, 0, 0};
+ unsigned sa = sizeof(a) / sizeof(a[0]);
+ assert(std::is_sorted(Iter(a), Iter(a+sa), std::greater<int>()));
+ }
+ {
+ int a[] = {0, 0, 1};
+ unsigned sa = sizeof(a) / sizeof(a[0]);
+ assert(!std::is_sorted(Iter(a), Iter(a+sa), std::greater<int>()));
+ }
+ {
+ int a[] = {0, 1, 0};
+ unsigned sa = sizeof(a) / sizeof(a[0]);
+ assert(!std::is_sorted(Iter(a), Iter(a+sa), std::greater<int>()));
+ }
+ {
+ int a[] = {0, 1, 1};
+ unsigned sa = sizeof(a) / sizeof(a[0]);
+ assert(!std::is_sorted(Iter(a), Iter(a+sa), std::greater<int>()));
+ }
+ {
+ int a[] = {1, 0, 0};
+ unsigned sa = sizeof(a) / sizeof(a[0]);
+ assert(std::is_sorted(Iter(a), Iter(a+sa), std::greater<int>()));
+ }
+ {
+ int a[] = {1, 0, 1};
+ unsigned sa = sizeof(a) / sizeof(a[0]);
+ assert(!std::is_sorted(Iter(a), Iter(a+sa), std::greater<int>()));
+ }
+ {
+ int a[] = {1, 1, 0};
+ unsigned sa = sizeof(a) / sizeof(a[0]);
+ assert(std::is_sorted(Iter(a), Iter(a+sa), std::greater<int>()));
+ }
+ {
+ int a[] = {1, 1, 1};
+ unsigned sa = sizeof(a) / sizeof(a[0]);
+ assert(std::is_sorted(Iter(a), Iter(a+sa), std::greater<int>()));
+ }
+
+ {
+ int a[] = {0, 0, 0, 0};
+ unsigned sa = sizeof(a) / sizeof(a[0]);
+ assert(std::is_sorted(Iter(a), Iter(a+sa), std::greater<int>()));
+ }
+ {
+ int a[] = {0, 0, 0, 1};
+ unsigned sa = sizeof(a) / sizeof(a[0]);
+ assert(!std::is_sorted(Iter(a), Iter(a+sa), std::greater<int>()));
+ }
+ {
+ int a[] = {0, 0, 1, 0};
+ unsigned sa = sizeof(a) / sizeof(a[0]);
+ assert(!std::is_sorted(Iter(a), Iter(a+sa), std::greater<int>()));
+ }
+ {
+ int a[] = {0, 0, 1, 1};
+ unsigned sa = sizeof(a) / sizeof(a[0]);
+ assert(!std::is_sorted(Iter(a), Iter(a+sa), std::greater<int>()));
+ }
+ {
+ int a[] = {0, 1, 0, 0};
+ unsigned sa = sizeof(a) / sizeof(a[0]);
+ assert(!std::is_sorted(Iter(a), Iter(a+sa), std::greater<int>()));
+ }
+ {
+ int a[] = {0, 1, 0, 1};
+ unsigned sa = sizeof(a) / sizeof(a[0]);
+ assert(!std::is_sorted(Iter(a), Iter(a+sa), std::greater<int>()));
+ }
+ {
+ int a[] = {0, 1, 1, 0};
+ unsigned sa = sizeof(a) / sizeof(a[0]);
+ assert(!std::is_sorted(Iter(a), Iter(a+sa), std::greater<int>()));
+ }
+ {
+ int a[] = {0, 1, 1, 1};
+ unsigned sa = sizeof(a) / sizeof(a[0]);
+ assert(!std::is_sorted(Iter(a), Iter(a+sa), std::greater<int>()));
+ }
+ {
+ int a[] = {1, 0, 0, 0};
+ unsigned sa = sizeof(a) / sizeof(a[0]);
+ assert(std::is_sorted(Iter(a), Iter(a+sa), std::greater<int>()));
+ }
+ {
+ int a[] = {1, 0, 0, 1};
+ unsigned sa = sizeof(a) / sizeof(a[0]);
+ assert(!std::is_sorted(Iter(a), Iter(a+sa), std::greater<int>()));
+ }
+ {
+ int a[] = {1, 0, 1, 0};
+ unsigned sa = sizeof(a) / sizeof(a[0]);
+ assert(!std::is_sorted(Iter(a), Iter(a+sa), std::greater<int>()));
+ }
+ {
+ int a[] = {1, 0, 1, 1};
+ unsigned sa = sizeof(a) / sizeof(a[0]);
+ assert(!std::is_sorted(Iter(a), Iter(a+sa), std::greater<int>()));
+ }
+ {
+ int a[] = {1, 1, 0, 0};
+ unsigned sa = sizeof(a) / sizeof(a[0]);
+ assert(std::is_sorted(Iter(a), Iter(a+sa), std::greater<int>()));
+ }
+ {
+ int a[] = {1, 1, 0, 1};
+ unsigned sa = sizeof(a) / sizeof(a[0]);
+ assert(!std::is_sorted(Iter(a), Iter(a+sa), std::greater<int>()));
+ }
+ {
+ int a[] = {1, 1, 1, 0};
+ unsigned sa = sizeof(a) / sizeof(a[0]);
+ assert(std::is_sorted(Iter(a), Iter(a+sa), std::greater<int>()));
+ }
+ {
+ int a[] = {1, 1, 1, 1};
+ unsigned sa = sizeof(a) / sizeof(a[0]);
+ assert(std::is_sorted(Iter(a), Iter(a+sa), std::greater<int>()));
+ }
+}
+
+int main()
+{
+ test<forward_iterator<const int*> >();
+ test<bidirectional_iterator<const int*> >();
+ test<random_access_iterator<const int*> >();
+ test<const int*>();
+}
diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.sort/is.sorted/is_sorted_until.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.sort/is.sorted/is_sorted_until.pass.cpp
new file mode 100644
index 00000000000..bef01027472
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.sorting/alg.sort/is.sorted/is_sorted_until.pass.cpp
@@ -0,0 +1,183 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 LessThanComparable<Iter::value_type>
+// Iter
+// is_sorted_until(Iter first, Iter last);
+
+#include <algorithm>
+#include <cassert>
+
+#include "test_iterators.h"
+
+template <class Iter>
+void
+test()
+{
+ {
+ int a[] = {0};
+ unsigned sa = sizeof(a) / sizeof(a[0]);
+ assert(std::is_sorted_until(Iter(a), Iter(a)) == Iter(a));
+ assert(std::is_sorted_until(Iter(a), Iter(a+sa)) == Iter(a+sa));
+ }
+
+ {
+ int a[] = {0, 0};
+ unsigned sa = sizeof(a) / sizeof(a[0]);
+ assert(std::is_sorted_until(Iter(a), Iter(a+sa)) == Iter(a+sa));
+ }
+ {
+ int a[] = {0, 1};
+ unsigned sa = sizeof(a) / sizeof(a[0]);
+ assert(std::is_sorted_until(Iter(a), Iter(a+sa)) == Iter(a+sa));
+ }
+ {
+ int a[] = {1, 0};
+ unsigned sa = sizeof(a) / sizeof(a[0]);
+ assert(std::is_sorted_until(Iter(a), Iter(a+sa)) == Iter(a+1));
+ }
+ {
+ int a[] = {1, 1};
+ unsigned sa = sizeof(a) / sizeof(a[0]);
+ assert(std::is_sorted_until(Iter(a), Iter(a+sa)) == Iter(a+sa));
+ }
+
+ {
+ int a[] = {0, 0, 0};
+ unsigned sa = sizeof(a) / sizeof(a[0]);
+ assert(std::is_sorted_until(Iter(a), Iter(a+sa)) == Iter(a+sa));
+ }
+ {
+ int a[] = {0, 0, 1};
+ unsigned sa = sizeof(a) / sizeof(a[0]);
+ assert(std::is_sorted_until(Iter(a), Iter(a+sa)) == Iter(a+sa));
+ }
+ {
+ int a[] = {0, 1, 0};
+ unsigned sa = sizeof(a) / sizeof(a[0]);
+ assert(std::is_sorted_until(Iter(a), Iter(a+sa)) == Iter(a+2));
+ }
+ {
+ int a[] = {0, 1, 1};
+ unsigned sa = sizeof(a) / sizeof(a[0]);
+ assert(std::is_sorted_until(Iter(a), Iter(a+sa)) == Iter(a+sa));
+ }
+ {
+ int a[] = {1, 0, 0};
+ unsigned sa = sizeof(a) / sizeof(a[0]);
+ assert(std::is_sorted_until(Iter(a), Iter(a+sa)) == Iter(a+1));
+ }
+ {
+ int a[] = {1, 0, 1};
+ unsigned sa = sizeof(a) / sizeof(a[0]);
+ assert(std::is_sorted_until(Iter(a), Iter(a+sa)) == Iter(a+1));
+ }
+ {
+ int a[] = {1, 1, 0};
+ unsigned sa = sizeof(a) / sizeof(a[0]);
+ assert(std::is_sorted_until(Iter(a), Iter(a+sa)) == Iter(a+2));
+ }
+ {
+ int a[] = {1, 1, 1};
+ unsigned sa = sizeof(a) / sizeof(a[0]);
+ assert(std::is_sorted_until(Iter(a), Iter(a+sa)) == Iter(a+sa));
+ }
+
+ {
+ int a[] = {0, 0, 0, 0};
+ unsigned sa = sizeof(a) / sizeof(a[0]);
+ assert(std::is_sorted_until(Iter(a), Iter(a+sa)) == Iter(a+sa));
+ }
+ {
+ int a[] = {0, 0, 0, 1};
+ unsigned sa = sizeof(a) / sizeof(a[0]);
+ assert(std::is_sorted_until(Iter(a), Iter(a+sa)) == Iter(a+sa));
+ }
+ {
+ int a[] = {0, 0, 1, 0};
+ unsigned sa = sizeof(a) / sizeof(a[0]);
+ assert(std::is_sorted_until(Iter(a), Iter(a+sa)) == Iter(a+3));
+ }
+ {
+ int a[] = {0, 0, 1, 1};
+ unsigned sa = sizeof(a) / sizeof(a[0]);
+ assert(std::is_sorted_until(Iter(a), Iter(a+sa)) == Iter(a+sa));
+ }
+ {
+ int a[] = {0, 1, 0, 0};
+ unsigned sa = sizeof(a) / sizeof(a[0]);
+ assert(std::is_sorted_until(Iter(a), Iter(a+sa)) == Iter(a+2));
+ }
+ {
+ int a[] = {0, 1, 0, 1};
+ unsigned sa = sizeof(a) / sizeof(a[0]);
+ assert(std::is_sorted_until(Iter(a), Iter(a+sa)) == Iter(a+2));
+ }
+ {
+ int a[] = {0, 1, 1, 0};
+ unsigned sa = sizeof(a) / sizeof(a[0]);
+ assert(std::is_sorted_until(Iter(a), Iter(a+sa)) == Iter(a+3));
+ }
+ {
+ int a[] = {0, 1, 1, 1};
+ unsigned sa = sizeof(a) / sizeof(a[0]);
+ assert(std::is_sorted_until(Iter(a), Iter(a+sa)) == Iter(a+sa));
+ }
+ {
+ int a[] = {1, 0, 0, 0};
+ unsigned sa = sizeof(a) / sizeof(a[0]);
+ assert(std::is_sorted_until(Iter(a), Iter(a+sa)) == Iter(a+1));
+ }
+ {
+ int a[] = {1, 0, 0, 1};
+ unsigned sa = sizeof(a) / sizeof(a[0]);
+ assert(std::is_sorted_until(Iter(a), Iter(a+sa)) == Iter(a+1));
+ }
+ {
+ int a[] = {1, 0, 1, 0};
+ unsigned sa = sizeof(a) / sizeof(a[0]);
+ assert(std::is_sorted_until(Iter(a), Iter(a+sa)) == Iter(a+1));
+ }
+ {
+ int a[] = {1, 0, 1, 1};
+ unsigned sa = sizeof(a) / sizeof(a[0]);
+ assert(std::is_sorted_until(Iter(a), Iter(a+sa)) == Iter(a+1));
+ }
+ {
+ int a[] = {1, 1, 0, 0};
+ unsigned sa = sizeof(a) / sizeof(a[0]);
+ assert(std::is_sorted_until(Iter(a), Iter(a+sa)) == Iter(a+2));
+ }
+ {
+ int a[] = {1, 1, 0, 1};
+ unsigned sa = sizeof(a) / sizeof(a[0]);
+ assert(std::is_sorted_until(Iter(a), Iter(a+sa)) == Iter(a+2));
+ }
+ {
+ int a[] = {1, 1, 1, 0};
+ unsigned sa = sizeof(a) / sizeof(a[0]);
+ assert(std::is_sorted_until(Iter(a), Iter(a+sa)) == Iter(a+3));
+ }
+ {
+ int a[] = {1, 1, 1, 1};
+ unsigned sa = sizeof(a) / sizeof(a[0]);
+ assert(std::is_sorted_until(Iter(a), Iter(a+sa)) == Iter(a+sa));
+ }
+}
+
+int main()
+{
+ test<forward_iterator<const int*> >();
+ test<bidirectional_iterator<const int*> >();
+ test<random_access_iterator<const int*> >();
+ test<const int*>();
+}
diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.sort/is.sorted/is_sorted_until_comp.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.sort/is.sorted/is_sorted_until_comp.pass.cpp
new file mode 100644
index 00000000000..68ed29c6f4b
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.sorting/alg.sort/is.sorted/is_sorted_until_comp.pass.cpp
@@ -0,0 +1,184 @@
+//===----------------------------------------------------------------------===//
+//
+// 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, StrictWeakOrder<auto, Iter::value_type> Compare>
+// requires CopyConstructible<Compare>
+// Iter
+// is_sorted_until(Iter first, Iter last, Compare comp);
+
+#include <algorithm>
+#include <functional>
+#include <cassert>
+
+#include "test_iterators.h"
+
+template <class Iter>
+void
+test()
+{
+ {
+ int a[] = {0};
+ unsigned sa = sizeof(a) / sizeof(a[0]);
+ assert(std::is_sorted_until(Iter(a), Iter(a), std::greater<int>()) == Iter(a));
+ assert(std::is_sorted_until(Iter(a), Iter(a+sa), std::greater<int>()) == Iter(a+sa));
+ }
+
+ {
+ int a[] = {0, 0};
+ unsigned sa = sizeof(a) / sizeof(a[0]);
+ assert(std::is_sorted_until(Iter(a), Iter(a+sa), std::greater<int>()) == Iter(a+sa));
+ }
+ {
+ int a[] = {0, 1};
+ unsigned sa = sizeof(a) / sizeof(a[0]);
+ assert(std::is_sorted_until(Iter(a), Iter(a+sa), std::greater<int>()) == Iter(a+1));
+ }
+ {
+ int a[] = {1, 0};
+ unsigned sa = sizeof(a) / sizeof(a[0]);
+ assert(std::is_sorted_until(Iter(a), Iter(a+sa), std::greater<int>()) == Iter(a+sa));
+ }
+ {
+ int a[] = {1, 1};
+ unsigned sa = sizeof(a) / sizeof(a[0]);
+ assert(std::is_sorted_until(Iter(a), Iter(a+sa), std::greater<int>()) == Iter(a+sa));
+ }
+
+ {
+ int a[] = {0, 0, 0};
+ unsigned sa = sizeof(a) / sizeof(a[0]);
+ assert(std::is_sorted_until(Iter(a), Iter(a+sa), std::greater<int>()) == Iter(a+sa));
+ }
+ {
+ int a[] = {0, 0, 1};
+ unsigned sa = sizeof(a) / sizeof(a[0]);
+ assert(std::is_sorted_until(Iter(a), Iter(a+sa), std::greater<int>()) == Iter(a+2));
+ }
+ {
+ int a[] = {0, 1, 0};
+ unsigned sa = sizeof(a) / sizeof(a[0]);
+ assert(std::is_sorted_until(Iter(a), Iter(a+sa), std::greater<int>()) == Iter(a+1));
+ }
+ {
+ int a[] = {0, 1, 1};
+ unsigned sa = sizeof(a) / sizeof(a[0]);
+ assert(std::is_sorted_until(Iter(a), Iter(a+sa), std::greater<int>()) == Iter(a+1));
+ }
+ {
+ int a[] = {1, 0, 0};
+ unsigned sa = sizeof(a) / sizeof(a[0]);
+ assert(std::is_sorted_until(Iter(a), Iter(a+sa), std::greater<int>()) == Iter(a+sa));
+ }
+ {
+ int a[] = {1, 0, 1};
+ unsigned sa = sizeof(a) / sizeof(a[0]);
+ assert(std::is_sorted_until(Iter(a), Iter(a+sa), std::greater<int>()) == Iter(a+2));
+ }
+ {
+ int a[] = {1, 1, 0};
+ unsigned sa = sizeof(a) / sizeof(a[0]);
+ assert(std::is_sorted_until(Iter(a), Iter(a+sa), std::greater<int>()) == Iter(a+sa));
+ }
+ {
+ int a[] = {1, 1, 1};
+ unsigned sa = sizeof(a) / sizeof(a[0]);
+ assert(std::is_sorted_until(Iter(a), Iter(a+sa), std::greater<int>()) == Iter(a+sa));
+ }
+
+ {
+ int a[] = {0, 0, 0, 0};
+ unsigned sa = sizeof(a) / sizeof(a[0]);
+ assert(std::is_sorted_until(Iter(a), Iter(a+sa), std::greater<int>()) == Iter(a+sa));
+ }
+ {
+ int a[] = {0, 0, 0, 1};
+ unsigned sa = sizeof(a) / sizeof(a[0]);
+ assert(std::is_sorted_until(Iter(a), Iter(a+sa), std::greater<int>()) == Iter(a+3));
+ }
+ {
+ int a[] = {0, 0, 1, 0};
+ unsigned sa = sizeof(a) / sizeof(a[0]);
+ assert(std::is_sorted_until(Iter(a), Iter(a+sa), std::greater<int>()) == Iter(a+2));
+ }
+ {
+ int a[] = {0, 0, 1, 1};
+ unsigned sa = sizeof(a) / sizeof(a[0]);
+ assert(std::is_sorted_until(Iter(a), Iter(a+sa), std::greater<int>()) == Iter(a+2));
+ }
+ {
+ int a[] = {0, 1, 0, 0};
+ unsigned sa = sizeof(a) / sizeof(a[0]);
+ assert(std::is_sorted_until(Iter(a), Iter(a+sa), std::greater<int>()) == Iter(a+1));
+ }
+ {
+ int a[] = {0, 1, 0, 1};
+ unsigned sa = sizeof(a) / sizeof(a[0]);
+ assert(std::is_sorted_until(Iter(a), Iter(a+sa), std::greater<int>()) == Iter(a+1));
+ }
+ {
+ int a[] = {0, 1, 1, 0};
+ unsigned sa = sizeof(a) / sizeof(a[0]);
+ assert(std::is_sorted_until(Iter(a), Iter(a+sa), std::greater<int>()) == Iter(a+1));
+ }
+ {
+ int a[] = {0, 1, 1, 1};
+ unsigned sa = sizeof(a) / sizeof(a[0]);
+ assert(std::is_sorted_until(Iter(a), Iter(a+sa), std::greater<int>()) == Iter(a+1));
+ }
+ {
+ int a[] = {1, 0, 0, 0};
+ unsigned sa = sizeof(a) / sizeof(a[0]);
+ assert(std::is_sorted_until(Iter(a), Iter(a+sa), std::greater<int>()) == Iter(a+sa));
+ }
+ {
+ int a[] = {1, 0, 0, 1};
+ unsigned sa = sizeof(a) / sizeof(a[0]);
+ assert(std::is_sorted_until(Iter(a), Iter(a+sa), std::greater<int>()) == Iter(a+3));
+ }
+ {
+ int a[] = {1, 0, 1, 0};
+ unsigned sa = sizeof(a) / sizeof(a[0]);
+ assert(std::is_sorted_until(Iter(a), Iter(a+sa), std::greater<int>()) == Iter(a+2));
+ }
+ {
+ int a[] = {1, 0, 1, 1};
+ unsigned sa = sizeof(a) / sizeof(a[0]);
+ assert(std::is_sorted_until(Iter(a), Iter(a+sa), std::greater<int>()) == Iter(a+2));
+ }
+ {
+ int a[] = {1, 1, 0, 0};
+ unsigned sa = sizeof(a) / sizeof(a[0]);
+ assert(std::is_sorted_until(Iter(a), Iter(a+sa), std::greater<int>()) == Iter(a+sa));
+ }
+ {
+ int a[] = {1, 1, 0, 1};
+ unsigned sa = sizeof(a) / sizeof(a[0]);
+ assert(std::is_sorted_until(Iter(a), Iter(a+sa), std::greater<int>()) == Iter(a+3));
+ }
+ {
+ int a[] = {1, 1, 1, 0};
+ unsigned sa = sizeof(a) / sizeof(a[0]);
+ assert(std::is_sorted_until(Iter(a), Iter(a+sa), std::greater<int>()) == Iter(a+sa));
+ }
+ {
+ int a[] = {1, 1, 1, 1};
+ unsigned sa = sizeof(a) / sizeof(a[0]);
+ assert(std::is_sorted_until(Iter(a), Iter(a+sa), std::greater<int>()) == Iter(a+sa));
+ }
+}
+
+int main()
+{
+ test<forward_iterator<const int*> >();
+ test<bidirectional_iterator<const int*> >();
+ test<random_access_iterator<const int*> >();
+ test<const int*>();
+}
diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.sort/nothing_to_do.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.sort/nothing_to_do.pass.cpp
new file mode 100644
index 00000000000..b58f5c55b64
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.sorting/alg.sort/nothing_to_do.pass.cpp
@@ -0,0 +1,12 @@
+//===----------------------------------------------------------------------===//
+//
+// 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.
+//
+//===----------------------------------------------------------------------===//
+
+int main()
+{
+}
diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.sort/partial.sort.copy/partial_sort_copy.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.sort/partial.sort.copy/partial_sort_copy.pass.cpp
new file mode 100644
index 00000000000..5f298fde7b3
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.sorting/alg.sort/partial.sort.copy/partial_sort_copy.pass.cpp
@@ -0,0 +1,86 @@
+//===----------------------------------------------------------------------===//
+//
+// 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, RandomAccessIterator RAIter>
+// requires ShuffleIterator<RAIter>
+// && OutputIterator<RAIter, InIter::reference>
+// && HasLess<InIter::value_type, RAIter::value_type>
+// && LessThanComparable<RAIter::value_type>
+// RAIter
+// partial_sort_copy(InIter first, InIter last, RAIter result_first, RAIter result_last);
+
+#include <algorithm>
+#include <cassert>
+
+#include "test_iterators.h"
+
+template <class Iter>
+void
+test_larger_sorts(unsigned N, unsigned M)
+{
+ int* input = new int[N];
+ int* output = new int[M];
+ for (int i = 0; i < N; ++i)
+ input[i] = i;
+ std::random_shuffle(input, input+N);
+ int* r = std::partial_sort_copy(Iter(input), Iter(input+N), output, output+M);
+ int* e = output + std::min(N, M);
+ assert(r == e);
+ int i = 0;
+ for (int* x = output; x < e; ++x, ++i)
+ assert(*x == i);
+ delete [] output;
+ delete [] input;
+}
+
+template <class Iter>
+void
+test_larger_sorts(unsigned N)
+{
+ test_larger_sorts<Iter>(N, 0);
+ test_larger_sorts<Iter>(N, 1);
+ test_larger_sorts<Iter>(N, 2);
+ test_larger_sorts<Iter>(N, 3);
+ test_larger_sorts<Iter>(N, N/2-1);
+ test_larger_sorts<Iter>(N, N/2);
+ test_larger_sorts<Iter>(N, N/2+1);
+ test_larger_sorts<Iter>(N, N-2);
+ test_larger_sorts<Iter>(N, N-1);
+ test_larger_sorts<Iter>(N, N);
+ test_larger_sorts<Iter>(N, N+1000);
+}
+
+template <class Iter>
+void
+test()
+{
+ test_larger_sorts<Iter>(0, 100);
+ test_larger_sorts<Iter>(10);
+ test_larger_sorts<Iter>(256);
+ test_larger_sorts<Iter>(257);
+ test_larger_sorts<Iter>(499);
+ test_larger_sorts<Iter>(500);
+ test_larger_sorts<Iter>(997);
+ test_larger_sorts<Iter>(1000);
+ test_larger_sorts<Iter>(1009);
+}
+
+int main()
+{
+ int i = 0;
+ std::partial_sort_copy(&i, &i, &i, &i+5);
+ assert(i == 0);
+ test<input_iterator<const int*> >();
+ test<forward_iterator<const int*> >();
+ test<bidirectional_iterator<const int*> >();
+ test<random_access_iterator<const int*> >();
+ test<const int*>();
+}
diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.sort/partial.sort.copy/partial_sort_copy_comp.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.sort/partial.sort.copy/partial_sort_copy_comp.pass.cpp
new file mode 100644
index 00000000000..df8fb9eacac
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.sorting/alg.sort/partial.sort.copy/partial_sort_copy_comp.pass.cpp
@@ -0,0 +1,90 @@
+//===----------------------------------------------------------------------===//
+//
+// 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, RandomAccessIterator RAIter, class Compare>
+// requires ShuffleIterator<RAIter>
+// && OutputIterator<RAIter, InIter::reference>
+// && Predicate<Compare, InIter::value_type, RAIter::value_type>
+// && StrictWeakOrder<Compare, RAIter::value_type>}
+// && CopyConstructible<Compare>
+// RAIter
+// partial_sort_copy(InIter first, InIter last,
+// RAIter result_first, RAIter result_last, Compare comp);
+
+#include <algorithm>
+#include <functional>
+#include <cassert>
+
+#include "test_iterators.h"
+
+template <class Iter>
+void
+test_larger_sorts(unsigned N, unsigned M)
+{
+ int* input = new int[N];
+ int* output = new int[M];
+ for (int i = 0; i < N; ++i)
+ input[i] = i;
+ std::random_shuffle(input, input+N);
+ int* r = std::partial_sort_copy(Iter(input), Iter(input+N), output, output+M,
+ std::greater<int>());
+ int* e = output + std::min(N, M);
+ assert(r == e);
+ int i = 0;
+ for (int* x = output; x < e; ++x, ++i)
+ assert(*x == N-i-1);
+ delete [] output;
+ delete [] input;
+}
+
+template <class Iter>
+void
+test_larger_sorts(unsigned N)
+{
+ test_larger_sorts<Iter>(N, 0);
+ test_larger_sorts<Iter>(N, 1);
+ test_larger_sorts<Iter>(N, 2);
+ test_larger_sorts<Iter>(N, 3);
+ test_larger_sorts<Iter>(N, N/2-1);
+ test_larger_sorts<Iter>(N, N/2);
+ test_larger_sorts<Iter>(N, N/2+1);
+ test_larger_sorts<Iter>(N, N-2);
+ test_larger_sorts<Iter>(N, N-1);
+ test_larger_sorts<Iter>(N, N);
+ test_larger_sorts<Iter>(N, N+1000);
+}
+
+template <class Iter>
+void
+test()
+{
+ test_larger_sorts<Iter>(0, 100);
+ test_larger_sorts<Iter>(10);
+ test_larger_sorts<Iter>(256);
+ test_larger_sorts<Iter>(257);
+ test_larger_sorts<Iter>(499);
+ test_larger_sorts<Iter>(500);
+ test_larger_sorts<Iter>(997);
+ test_larger_sorts<Iter>(1000);
+ test_larger_sorts<Iter>(1009);
+}
+
+int main()
+{
+ int i = 0;
+ std::partial_sort_copy(&i, &i, &i, &i+5);
+ assert(i == 0);
+ test<input_iterator<const int*> >();
+ test<forward_iterator<const int*> >();
+ test<bidirectional_iterator<const int*> >();
+ test<random_access_iterator<const int*> >();
+ test<const int*>();
+}
diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.sort/partial.sort/partial_sort.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.sort/partial.sort/partial_sort.pass.cpp
new file mode 100644
index 00000000000..7bb43461cba
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.sorting/alg.sort/partial.sort/partial_sort.pass.cpp
@@ -0,0 +1,63 @@
+//===----------------------------------------------------------------------===//
+//
+// 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<RandomAccessIterator Iter>
+// requires ShuffleIterator<Iter>
+// && LessThanComparable<Iter::value_type>
+// void
+// partial_sort(Iter first, Iter middle, Iter last);
+
+#include <algorithm>
+#include <cassert>
+
+void
+test_larger_sorts(unsigned N, unsigned M)
+{
+ assert(N != 0);
+ int* array = new int[N];
+ for (int i = 0; i < N; ++i)
+ array[i] = i;
+ std::random_shuffle(array, array+N);
+ std::partial_sort(array, array+M, array+N);
+ for (int i = 0; i < M; ++i)
+ assert(array[i] == i);
+ delete [] array;
+}
+
+void
+test_larger_sorts(unsigned N)
+{
+ test_larger_sorts(N, 0);
+ test_larger_sorts(N, 1);
+ test_larger_sorts(N, 2);
+ test_larger_sorts(N, 3);
+ test_larger_sorts(N, N/2-1);
+ test_larger_sorts(N, N/2);
+ test_larger_sorts(N, N/2+1);
+ test_larger_sorts(N, N-2);
+ test_larger_sorts(N, N-1);
+ test_larger_sorts(N, N);
+}
+
+int main()
+{
+ int i = 0;
+ std::partial_sort(&i, &i, &i);
+ assert(i == 0);
+ test_larger_sorts(10);
+ test_larger_sorts(256);
+ test_larger_sorts(257);
+ test_larger_sorts(499);
+ test_larger_sorts(500);
+ test_larger_sorts(997);
+ test_larger_sorts(1000);
+ test_larger_sorts(1009);
+}
diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.sort/partial.sort/partial_sort_comp.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.sort/partial.sort/partial_sort_comp.pass.cpp
new file mode 100644
index 00000000000..d822f6c388c
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.sorting/alg.sort/partial.sort/partial_sort_comp.pass.cpp
@@ -0,0 +1,87 @@
+//===----------------------------------------------------------------------===//
+//
+// 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<RandomAccessIterator Iter, StrictWeakOrder<auto, Iter::value_type> Compare>
+// requires ShuffleIterator<Iter>
+// && CopyConstructible<Compare>
+// void
+// partial_sort(Iter first, Iter middle, Iter last, Compare comp);
+
+#include <algorithm>
+#include <vector>
+#include <functional>
+#include <cassert>
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+#include <memory>
+
+struct indirect_less
+{
+ template <class P>
+ bool operator()(const P& x, const P& y)
+ {return *x < *y;}
+};
+
+#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
+
+void
+test_larger_sorts(unsigned N, unsigned M)
+{
+ assert(N != 0);
+ int* array = new int[N];
+ for (int i = 0; i < N; ++i)
+ array[i] = i;
+ std::random_shuffle(array, array+N);
+ std::partial_sort(array, array+M, array+N, std::greater<int>());
+ for (int i = 0; i < M; ++i)
+ assert(array[i] == N-i-1);
+ delete [] array;
+}
+
+void
+test_larger_sorts(unsigned N)
+{
+ test_larger_sorts(N, 0);
+ test_larger_sorts(N, 1);
+ test_larger_sorts(N, 2);
+ test_larger_sorts(N, 3);
+ test_larger_sorts(N, N/2-1);
+ test_larger_sorts(N, N/2);
+ test_larger_sorts(N, N/2+1);
+ test_larger_sorts(N, N-2);
+ test_larger_sorts(N, N-1);
+ test_larger_sorts(N, N);
+}
+
+int main()
+{
+ int i = 0;
+ std::partial_sort(&i, &i, &i);
+ assert(i == 0);
+ test_larger_sorts(10);
+ test_larger_sorts(256);
+ test_larger_sorts(257);
+ test_larger_sorts(499);
+ test_larger_sorts(500);
+ test_larger_sorts(997);
+ test_larger_sorts(1000);
+ test_larger_sorts(1009);
+
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+ {
+ std::vector<std::unique_ptr<int> > v(1000);
+ for (int i = 0; i < v.size(); ++i)
+ v[i].reset(new int(i));
+ std::partial_sort(v.begin(), v.begin() + v.size()/2, v.end(), indirect_less());
+ for (int i = 0; i < v.size()/2; ++i)
+ assert(*v[i] == i);
+ }
+#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
+}
diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.sort/sort/sort.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.sort/sort/sort.pass.cpp
new file mode 100644
index 00000000000..2ea697a63b2
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.sorting/alg.sort/sort/sort.pass.cpp
@@ -0,0 +1,150 @@
+//===----------------------------------------------------------------------===//
+//
+// 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<RandomAccessIterator Iter>
+// requires ShuffleIterator<Iter>
+// && LessThanComparable<Iter::value_type>
+// void
+// sort(Iter first, Iter last);
+
+#include <algorithm>
+#include <cassert>
+
+template <class RI>
+void
+test_sort_helper(RI f, RI l)
+{
+ typedef typename std::iterator_traits<RI>::value_type value_type;
+ if (f != l)
+ {
+ long len = l - f;
+ value_type* save(new value_type[len]);
+ do
+ {
+ std::copy(f, l, save);
+ std::sort(save, save+len);
+ assert(std::is_sorted(save, save+len));
+ } while (std::next_permutation(f, l));
+ delete [] save;
+ }
+}
+
+template <class RI>
+void
+test_sort_driver_driver(RI f, RI l, int start, RI real_last)
+{
+ for (RI i = l; i > f + start;)
+ {
+ *--i = start;
+ if (f == i)
+ {
+ test_sort_helper(f, real_last);
+ }
+ if (start > 0)
+ test_sort_driver_driver(f, i, start-1, real_last);
+ }
+}
+
+template <class RI>
+void
+test_sort_driver(RI f, RI l, int start)
+{
+ test_sort_driver_driver(f, l, start, l);
+}
+
+template <unsigned sa>
+void
+test_sort_()
+{
+ int ia[sa];
+ for (int i = 0; i < sa; ++i)
+ {
+ test_sort_driver(ia, ia+sa, i);
+ }
+}
+
+void
+test_larger_sorts(unsigned N, unsigned M)
+{
+ assert(N != 0);
+ assert(M != 0);
+ // create array length N filled with M different numbers
+ int* array = new int[N];
+ int x = 0;
+ for (int i = 0; i < N; ++i)
+ {
+ array[i] = x;
+ if (++x == M)
+ x = 0;
+ }
+ // test saw tooth pattern
+ std::sort(array, array+N);
+ assert(std::is_sorted(array, array+N));
+ // test random pattern
+ std::random_shuffle(array, array+N);
+ std::sort(array, array+N);
+ assert(std::is_sorted(array, array+N));
+ // test sorted pattern
+ std::sort(array, array+N);
+ assert(std::is_sorted(array, array+N));
+ // test reverse sorted pattern
+ std::reverse(array, array+N);
+ std::sort(array, array+N);
+ assert(std::is_sorted(array, array+N));
+ // test swap ranges 2 pattern
+ std::swap_ranges(array, array+N/2, array+N/2);
+ std::sort(array, array+N);
+ assert(std::is_sorted(array, array+N));
+ // test reverse swap ranges 2 pattern
+ std::reverse(array, array+N);
+ std::swap_ranges(array, array+N/2, array+N/2);
+ std::sort(array, array+N);
+ assert(std::is_sorted(array, array+N));
+ delete [] array;
+}
+
+void
+test_larger_sorts(unsigned N)
+{
+ test_larger_sorts(N, 1);
+ test_larger_sorts(N, 2);
+ test_larger_sorts(N, 3);
+ test_larger_sorts(N, N/2-1);
+ test_larger_sorts(N, N/2);
+ test_larger_sorts(N, N/2+1);
+ test_larger_sorts(N, N-2);
+ test_larger_sorts(N, N-1);
+ test_larger_sorts(N, N);
+}
+
+int main()
+{
+ // test null range
+ int d = 0;
+ std::sort(&d, &d);
+ // exhaustively test all possibilities up to length 8
+ test_sort_<1>();
+ test_sort_<2>();
+ test_sort_<3>();
+ test_sort_<4>();
+ test_sort_<5>();
+ test_sort_<6>();
+ test_sort_<7>();
+ test_sort_<8>();
+
+ test_larger_sorts(256);
+ test_larger_sorts(257);
+ test_larger_sorts(499);
+ test_larger_sorts(500);
+ test_larger_sorts(997);
+ test_larger_sorts(1000);
+ test_larger_sorts(1009);
+}
diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.sort/sort/sort_comp.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.sort/sort/sort_comp.pass.cpp
new file mode 100644
index 00000000000..d6c4f046784
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.sorting/alg.sort/sort/sort_comp.pass.cpp
@@ -0,0 +1,57 @@
+//===----------------------------------------------------------------------===//
+//
+// 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<RandomAccessIterator Iter, StrictWeakOrder<auto, Iter::value_type> Compare>
+// requires ShuffleIterator<Iter>
+// && CopyConstructible<Compare>
+// void
+// sort(Iter first, Iter last, Compare comp);
+
+#include <algorithm>
+#include <functional>
+#include <vector>
+#include <cassert>
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+#include <memory>
+
+struct indirect_less
+{
+ template <class P>
+ bool operator()(const P& x, const P& y)
+ {return *x < *y;}
+};
+
+#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
+
+int main()
+{
+ {
+ std::vector<int> v(1000);
+ for (int i = 0; i < v.size(); ++i)
+ v[i] = i;
+ std::sort(v.begin(), v.end(), std::greater<int>());
+ std::reverse(v.begin(), v.end());
+ assert(std::is_sorted(v.begin(), v.end()));
+ }
+
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+ {
+ std::vector<std::unique_ptr<int> > v(1000);
+ for (int i = 0; i < v.size(); ++i)
+ v[i].reset(new int(i));
+ std::sort(v.begin(), v.end(), indirect_less());
+ assert(std::is_sorted(v.begin(), v.end(), indirect_less()));
+ assert(*v[0] == 0);
+ assert(*v[1] == 1);
+ assert(*v[2] == 2);
+ }
+#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
+}
diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.sort/stable.sort/stable_sort.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.sort/stable.sort/stable_sort.pass.cpp
new file mode 100644
index 00000000000..5faa1682135
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.sorting/alg.sort/stable.sort/stable_sort.pass.cpp
@@ -0,0 +1,150 @@
+//===----------------------------------------------------------------------===//
+//
+// 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<RandomAccessIterator Iter>
+// requires ShuffleIterator<Iter>
+// && LessThanComparable<Iter::value_type>
+// void
+// stable_sort(Iter first, Iter last);
+
+#include <algorithm>
+#include <cassert>
+
+template <class RI>
+void
+test_sort_helper(RI f, RI l)
+{
+ typedef typename std::iterator_traits<RI>::value_type value_type;
+ if (f != l)
+ {
+ long len = l - f;
+ value_type* save(new value_type[len]);
+ do
+ {
+ std::copy(f, l, save);
+ std::stable_sort(save, save+len);
+ assert(std::is_sorted(save, save+len));
+ } while (std::next_permutation(f, l));
+ delete [] save;
+ }
+}
+
+template <class RI>
+void
+test_sort_driver_driver(RI f, RI l, int start, RI real_last)
+{
+ for (RI i = l; i > f + start;)
+ {
+ *--i = start;
+ if (f == i)
+ {
+ test_sort_helper(f, real_last);
+ }
+ if (start > 0)
+ test_sort_driver_driver(f, i, start-1, real_last);
+ }
+}
+
+template <class RI>
+void
+test_sort_driver(RI f, RI l, int start)
+{
+ test_sort_driver_driver(f, l, start, l);
+}
+
+template <unsigned sa>
+void
+test_sort_()
+{
+ int ia[sa];
+ for (int i = 0; i < sa; ++i)
+ {
+ test_sort_driver(ia, ia+sa, i);
+ }
+}
+
+void
+test_larger_sorts(unsigned N, unsigned M)
+{
+ assert(N != 0);
+ assert(M != 0);
+ // create array length N filled with M different numbers
+ int* array = new int[N];
+ int x = 0;
+ for (int i = 0; i < N; ++i)
+ {
+ array[i] = x;
+ if (++x == M)
+ x = 0;
+ }
+ // test saw tooth pattern
+ std::stable_sort(array, array+N);
+ assert(std::is_sorted(array, array+N));
+ // test random pattern
+ std::random_shuffle(array, array+N);
+ std::stable_sort(array, array+N);
+ assert(std::is_sorted(array, array+N));
+ // test sorted pattern
+ std::stable_sort(array, array+N);
+ assert(std::is_sorted(array, array+N));
+ // test reverse sorted pattern
+ std::reverse(array, array+N);
+ std::stable_sort(array, array+N);
+ assert(std::is_sorted(array, array+N));
+ // test swap ranges 2 pattern
+ std::swap_ranges(array, array+N/2, array+N/2);
+ std::stable_sort(array, array+N);
+ assert(std::is_sorted(array, array+N));
+ // test reverse swap ranges 2 pattern
+ std::reverse(array, array+N);
+ std::swap_ranges(array, array+N/2, array+N/2);
+ std::stable_sort(array, array+N);
+ assert(std::is_sorted(array, array+N));
+ delete [] array;
+}
+
+void
+test_larger_sorts(unsigned N)
+{
+ test_larger_sorts(N, 1);
+ test_larger_sorts(N, 2);
+ test_larger_sorts(N, 3);
+ test_larger_sorts(N, N/2-1);
+ test_larger_sorts(N, N/2);
+ test_larger_sorts(N, N/2+1);
+ test_larger_sorts(N, N-2);
+ test_larger_sorts(N, N-1);
+ test_larger_sorts(N, N);
+}
+
+int main()
+{
+ // test null range
+ int d = 0;
+ std::stable_sort(&d, &d);
+ // exhaustively test all possibilities up to length 8
+ test_sort_<1>();
+ test_sort_<2>();
+ test_sort_<3>();
+ test_sort_<4>();
+ test_sort_<5>();
+ test_sort_<6>();
+ test_sort_<7>();
+ test_sort_<8>();
+
+ test_larger_sorts(256);
+ test_larger_sorts(257);
+ test_larger_sorts(499);
+ test_larger_sorts(500);
+ test_larger_sorts(997);
+ test_larger_sorts(1000);
+ test_larger_sorts(1009);
+}
diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.sort/stable.sort/stable_sort_comp.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.sort/stable.sort/stable_sort_comp.pass.cpp
new file mode 100644
index 00000000000..68e817ebeb3
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.sorting/alg.sort/stable.sort/stable_sort_comp.pass.cpp
@@ -0,0 +1,83 @@
+//===----------------------------------------------------------------------===//
+//
+// 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<RandomAccessIterator Iter, StrictWeakOrder<auto, Iter::value_type> Compare>
+// requires ShuffleIterator<Iter>
+// && CopyConstructible<Compare>
+// void
+// stable_sort(Iter first, Iter last, Compare comp);
+
+#include <algorithm>
+#include <functional>
+#include <vector>
+#include <cassert>
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+#include <memory>
+
+struct indirect_less
+{
+ template <class P>
+ bool operator()(const P& x, const P& y)
+ {return *x < *y;}
+};
+
+#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
+
+struct first_only
+{
+ bool operator()(const std::pair<int, int>& x, const std::pair<int, int>& y)
+ {
+ return x.first < y.first;
+ }
+};
+
+void test()
+{
+ typedef std::pair<int, int> P;
+ const int N = 1000;
+ const int M = 10;
+ std::vector<P> v(N);
+ int x = 0;
+ int ver = 0;
+ for (int i = 0; i < N; ++i)
+ {
+ v[i] = P(x, ver);
+ if (++x == M)
+ {
+ x = 0;
+ ++ver;
+ }
+ }
+ for (int i = 0; i < N - M; i += M)
+ {
+ std::random_shuffle(v.begin() + i, v.begin() + i + M);
+ }
+ std::stable_sort(v.begin(), v.end(), first_only());
+ assert(std::is_sorted(v.begin(), v.end()));
+}
+
+int main()
+{
+ test();
+
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+ {
+ std::vector<std::unique_ptr<int> > v(1000);
+ for (int i = 0; i < v.size(); ++i)
+ v[i].reset(new int(i));
+ std::stable_sort(v.begin(), v.end(), indirect_less());
+ assert(std::is_sorted(v.begin(), v.end(), indirect_less()));
+ assert(*v[0] == 0);
+ assert(*v[1] == 1);
+ assert(*v[2] == 2);
+ }
+#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
+}
diff --git a/libcxx/test/std/algorithms/alg.sorting/nothing_to_do.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/nothing_to_do.pass.cpp
new file mode 100644
index 00000000000..b58f5c55b64
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.sorting/nothing_to_do.pass.cpp
@@ -0,0 +1,12 @@
+//===----------------------------------------------------------------------===//
+//
+// 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.
+//
+//===----------------------------------------------------------------------===//
+
+int main()
+{
+}
diff --git a/libcxx/test/std/algorithms/algorithms.general/nothing_to_do.pass.cpp b/libcxx/test/std/algorithms/algorithms.general/nothing_to_do.pass.cpp
new file mode 100644
index 00000000000..b58f5c55b64
--- /dev/null
+++ b/libcxx/test/std/algorithms/algorithms.general/nothing_to_do.pass.cpp
@@ -0,0 +1,12 @@
+//===----------------------------------------------------------------------===//
+//
+// 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.
+//
+//===----------------------------------------------------------------------===//
+
+int main()
+{
+}
diff --git a/libcxx/test/std/algorithms/version.pass.cpp b/libcxx/test/std/algorithms/version.pass.cpp
new file mode 100644
index 00000000000..20f0637e641
--- /dev/null
+++ b/libcxx/test/std/algorithms/version.pass.cpp
@@ -0,0 +1,20 @@
+//===----------------------------------------------------------------------===//
+//
+// 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>
+
+#include <algorithm>
+
+#ifndef _LIBCPP_VERSION
+#error _LIBCPP_VERSION not defined
+#endif
+
+int main()
+{
+}
OpenPOWER on IntegriCloud