diff options
author | Eric Fiselier <eric@efcs.ca> | 2014-12-20 01:40:03 +0000 |
---|---|---|
committer | Eric Fiselier <eric@efcs.ca> | 2014-12-20 01:40:03 +0000 |
commit | 5a83710e371fe68a06e6e3876c6a2c8b820a8976 (patch) | |
tree | afde4c82ad6704681781c5cd49baa3fbd05c85db /libcxx/test/std/algorithms/alg.modifying.operations | |
parent | f11e8eab527fba316c64112f6e05de1a79693a3e (diff) | |
download | bcm5719-llvm-5a83710e371fe68a06e6e3876c6a2c8b820a8976.tar.gz bcm5719-llvm-5a83710e371fe68a06e6e3876c6a2c8b820a8976.zip |
Move test into test/std subdirectory.
llvm-svn: 224658
Diffstat (limited to 'libcxx/test/std/algorithms/alg.modifying.operations')
39 files changed, 3918 insertions, 0 deletions
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() +{ +} |