From 61b9a7258a7693d7f3674a5a1daf7b036ff1d382 Mon Sep 17 00:00:00 2001 From: Dimitry Andric Date: Sun, 6 Sep 2015 18:46:46 +0000 Subject: Import libc++ 3.7.0 release (r246257). --- .../numeric.ops/accumulate/accumulate.pass.cpp | 53 +++++++++ .../numeric.ops/accumulate/accumulate_op.pass.cpp | 55 ++++++++++ .../adjacent_difference.pass.cpp | 115 ++++++++++++++++++++ .../adjacent_difference_op.pass.cpp | 118 +++++++++++++++++++++ .../inner.product/inner_product.pass.cpp | 82 ++++++++++++++ .../inner.product/inner_product_comp.pass.cpp | 85 +++++++++++++++ .../numeric.ops/numeric.iota/iota.pass.cpp | 38 +++++++ .../numeric.ops/partial.sum/partial_sum.pass.cpp | 70 ++++++++++++ .../partial.sum/partial_sum_op.pass.cpp | 72 +++++++++++++ test/std/numerics/numeric.ops/version.pass.cpp | 20 ++++ 10 files changed, 708 insertions(+) create mode 100644 test/std/numerics/numeric.ops/accumulate/accumulate.pass.cpp create mode 100644 test/std/numerics/numeric.ops/accumulate/accumulate_op.pass.cpp create mode 100644 test/std/numerics/numeric.ops/adjacent.difference/adjacent_difference.pass.cpp create mode 100644 test/std/numerics/numeric.ops/adjacent.difference/adjacent_difference_op.pass.cpp create mode 100644 test/std/numerics/numeric.ops/inner.product/inner_product.pass.cpp create mode 100644 test/std/numerics/numeric.ops/inner.product/inner_product_comp.pass.cpp create mode 100644 test/std/numerics/numeric.ops/numeric.iota/iota.pass.cpp create mode 100644 test/std/numerics/numeric.ops/partial.sum/partial_sum.pass.cpp create mode 100644 test/std/numerics/numeric.ops/partial.sum/partial_sum_op.pass.cpp create mode 100644 test/std/numerics/numeric.ops/version.pass.cpp (limited to 'test/std/numerics/numeric.ops') diff --git a/test/std/numerics/numeric.ops/accumulate/accumulate.pass.cpp b/test/std/numerics/numeric.ops/accumulate/accumulate.pass.cpp new file mode 100644 index 0000000000000..aae97ef41175a --- /dev/null +++ b/test/std/numerics/numeric.ops/accumulate/accumulate.pass.cpp @@ -0,0 +1,53 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template +// requires HasPlus +// && HasAssign::result_type> +// T +// accumulate(Iter first, Iter last, T init); + +#include +#include + +#include "test_iterators.h" + +template +void +test(Iter first, Iter last, T init, T x) +{ + assert(std::accumulate(first, last, init) == x); +} + +template +void +test() +{ + int ia[] = {1, 2, 3, 4, 5, 6}; + unsigned sa = sizeof(ia) / sizeof(ia[0]); + test(Iter(ia), Iter(ia), 0, 0); + test(Iter(ia), Iter(ia), 10, 10); + test(Iter(ia), Iter(ia+1), 0, 1); + test(Iter(ia), Iter(ia+1), 10, 11); + test(Iter(ia), Iter(ia+2), 0, 3); + test(Iter(ia), Iter(ia+2), 10, 13); + test(Iter(ia), Iter(ia+sa), 0, 21); + test(Iter(ia), Iter(ia+sa), 10, 31); +} + +int main() +{ + test >(); + test >(); + test >(); + test >(); + test(); +} diff --git a/test/std/numerics/numeric.ops/accumulate/accumulate_op.pass.cpp b/test/std/numerics/numeric.ops/accumulate/accumulate_op.pass.cpp new file mode 100644 index 0000000000000..19a872868bf66 --- /dev/null +++ b/test/std/numerics/numeric.ops/accumulate/accumulate_op.pass.cpp @@ -0,0 +1,55 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template BinaryOperation> +// requires HasAssign +// && CopyConstructible +// T +// accumulate(Iter first, Iter last, T init, BinaryOperation binary_op); + +#include +#include +#include + +#include "test_iterators.h" + +template +void +test(Iter first, Iter last, T init, T x) +{ + assert(std::accumulate(first, last, init, std::multiplies()) == x); +} + +template +void +test() +{ + int ia[] = {1, 2, 3, 4, 5, 6}; + unsigned sa = sizeof(ia) / sizeof(ia[0]); + test(Iter(ia), Iter(ia), 1, 1); + test(Iter(ia), Iter(ia), 10, 10); + test(Iter(ia), Iter(ia+1), 1, 1); + test(Iter(ia), Iter(ia+1), 10, 10); + test(Iter(ia), Iter(ia+2), 1, 2); + test(Iter(ia), Iter(ia+2), 10, 20); + test(Iter(ia), Iter(ia+sa), 1, 720); + test(Iter(ia), Iter(ia+sa), 10, 7200); +} + +int main() +{ + test >(); + test >(); + test >(); + test >(); + test(); +} diff --git a/test/std/numerics/numeric.ops/adjacent.difference/adjacent_difference.pass.cpp b/test/std/numerics/numeric.ops/adjacent.difference/adjacent_difference.pass.cpp new file mode 100644 index 0000000000000..46741e1e41b7b --- /dev/null +++ b/test/std/numerics/numeric.ops/adjacent.difference/adjacent_difference.pass.cpp @@ -0,0 +1,115 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// + +// template OutIter> +// requires HasMinus +// && Constructible +// && OutputIterator::result_type> +// && MoveAssignable +// OutIter +// adjacent_difference(InIter first, InIter last, OutIter result); + +#include +#include + +#include "test_iterators.h" + +template +void +test() +{ + int ia[] = {15, 10, 6, 3, 1}; + int ir[] = {15, -5, -4, -3, -2}; + const unsigned s = sizeof(ia) / sizeof(ia[0]); + int ib[s] = {0}; + OutIter r = std::adjacent_difference(InIter(ia), InIter(ia+s), OutIter(ib)); + assert(base(r) == ib + s); + for (unsigned i = 0; i < s; ++i) + assert(ib[i] == ir[i]); +} + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + +class Y; + +class X +{ + int i_; + + X& operator=(const X&); +public: + explicit X(int i) : i_(i) {} + X(const X& x) : i_(x.i_) {} + X& operator=(X&& x) + { + i_ = x.i_; + x.i_ = -1; + return *this; + } + + friend X operator-(const X& x, const X& y) {return X(x.i_ - y.i_);} + + friend class Y; +}; + +class Y +{ + int i_; + + Y& operator=(const Y&); +public: + explicit Y(int i) : i_(i) {} + Y(const Y& y) : i_(y.i_) {} + void operator=(const X& x) {i_ = x.i_;} +}; + +#endif + +int main() +{ + test, output_iterator >(); + test, forward_iterator >(); + test, bidirectional_iterator >(); + test, random_access_iterator >(); + test, int*>(); + + test, output_iterator >(); + test, forward_iterator >(); + test, bidirectional_iterator >(); + test, random_access_iterator >(); + test, int*>(); + + test, output_iterator >(); + test, forward_iterator >(); + test, bidirectional_iterator >(); + test, random_access_iterator >(); + test, int*>(); + + test, output_iterator >(); + test, forward_iterator >(); + test, bidirectional_iterator >(); + test, random_access_iterator >(); + test, int*>(); + + test >(); + test >(); + test >(); + test >(); + test(); + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + X x[3] = {X(1), X(2), X(3)}; + Y y[3] = {Y(1), Y(2), Y(3)}; + std::adjacent_difference(x, x+3, y); +#endif +} diff --git a/test/std/numerics/numeric.ops/adjacent.difference/adjacent_difference_op.pass.cpp b/test/std/numerics/numeric.ops/adjacent.difference/adjacent_difference_op.pass.cpp new file mode 100644 index 0000000000000..fb0bbdc2836da --- /dev/null +++ b/test/std/numerics/numeric.ops/adjacent.difference/adjacent_difference_op.pass.cpp @@ -0,0 +1,118 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// + +// template OutIter, +// Callable BinaryOperation> +// requires Constructible +// && OutputIterator +// && MoveAssignable +// && CopyConstructible +// OutIter +// adjacent_difference(InIter first, InIter last, OutIter result, BinaryOperation binary_op); + +#include +#include +#include + +#include "test_iterators.h" + +template +void +test() +{ + int ia[] = {15, 10, 6, 3, 1}; + int ir[] = {15, 25, 16, 9, 4}; + const unsigned s = sizeof(ia) / sizeof(ia[0]); + int ib[s] = {0}; + OutIter r = std::adjacent_difference(InIter(ia), InIter(ia+s), OutIter(ib), + std::plus()); + assert(base(r) == ib + s); + for (unsigned i = 0; i < s; ++i) + assert(ib[i] == ir[i]); +} + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + +class Y; + +class X +{ + int i_; + + X& operator=(const X&); +public: + explicit X(int i) : i_(i) {} + X(const X& x) : i_(x.i_) {} + X& operator=(X&& x) + { + i_ = x.i_; + x.i_ = -1; + return *this; + } + + friend X operator-(const X& x, const X& y) {return X(x.i_ - y.i_);} + + friend class Y; +}; + +class Y +{ + int i_; + + Y& operator=(const Y&); +public: + explicit Y(int i) : i_(i) {} + Y(const Y& y) : i_(y.i_) {} + void operator=(const X& x) {i_ = x.i_;} +}; + +#endif + + +int main() +{ + test, output_iterator >(); + test, forward_iterator >(); + test, bidirectional_iterator >(); + test, random_access_iterator >(); + test, int*>(); + + test, output_iterator >(); + test, forward_iterator >(); + test, bidirectional_iterator >(); + test, random_access_iterator >(); + test, int*>(); + + test, output_iterator >(); + test, forward_iterator >(); + test, bidirectional_iterator >(); + test, random_access_iterator >(); + test, int*>(); + + test, output_iterator >(); + test, forward_iterator >(); + test, bidirectional_iterator >(); + test, random_access_iterator >(); + test, int*>(); + + test >(); + test >(); + test >(); + test >(); + test(); + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + X x[3] = {X(1), X(2), X(3)}; + Y y[3] = {Y(1), Y(2), Y(3)}; + std::adjacent_difference(x, x+3, y, std::minus()); +#endif +} diff --git a/test/std/numerics/numeric.ops/inner.product/inner_product.pass.cpp b/test/std/numerics/numeric.ops/inner.product/inner_product.pass.cpp new file mode 100644 index 0000000000000..68a8c49b82ba3 --- /dev/null +++ b/test/std/numerics/numeric.ops/inner.product/inner_product.pass.cpp @@ -0,0 +1,82 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// + +// template +// requires HasMultiply +// && HasPlus::result_type> +// && HasAssign::result_type>::result_type> +// T +// inner_product(Iter1 first1, Iter1 last1, Iter2 first2, T init); + +#include +#include + +#include "test_iterators.h" + +template +void +test(Iter1 first1, Iter1 last1, Iter2 first2, T init, T x) +{ + assert(std::inner_product(first1, last1, first2, init) == x); +} + +template +void +test() +{ + int a[] = {1, 2, 3, 4, 5, 6}; + int b[] = {6, 5, 4, 3, 2, 1}; + unsigned sa = sizeof(a) / sizeof(a[0]); + test(Iter1(a), Iter1(a), Iter2(b), 0, 0); + test(Iter1(a), Iter1(a), Iter2(b), 10, 10); + test(Iter1(a), Iter1(a+1), Iter2(b), 0, 6); + test(Iter1(a), Iter1(a+1), Iter2(b), 10, 16); + test(Iter1(a), Iter1(a+2), Iter2(b), 0, 16); + test(Iter1(a), Iter1(a+2), Iter2(b), 10, 26); + test(Iter1(a), Iter1(a+sa), Iter2(b), 0, 56); + test(Iter1(a), Iter1(a+sa), Iter2(b), 10, 66); +} + +int main() +{ + test, input_iterator >(); + test, forward_iterator >(); + test, bidirectional_iterator >(); + test, random_access_iterator >(); + test, const int*>(); + + test, input_iterator >(); + test, forward_iterator >(); + test, bidirectional_iterator >(); + test, random_access_iterator >(); + test, const int*>(); + + test, input_iterator >(); + test, forward_iterator >(); + test, bidirectional_iterator >(); + test, random_access_iterator >(); + test, const int*>(); + + test, input_iterator >(); + test, forward_iterator >(); + test, bidirectional_iterator >(); + test, random_access_iterator >(); + test, const int*>(); + + test >(); + test >(); + test >(); + test >(); + test(); +} diff --git a/test/std/numerics/numeric.ops/inner.product/inner_product_comp.pass.cpp b/test/std/numerics/numeric.ops/inner.product/inner_product_comp.pass.cpp new file mode 100644 index 0000000000000..31dbbd0bec502 --- /dev/null +++ b/test/std/numerics/numeric.ops/inner.product/inner_product_comp.pass.cpp @@ -0,0 +1,85 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template BinaryOperation2> +// requires Callable +// && HasAssign +// && CopyConstructible +// && CopyConstructible +// T +// inner_product(Iter1 first1, Iter1 last1, Iter2 first2, +// T init, BinaryOperation1 binary_op1, BinaryOperation2 binary_op2); + +#include +#include +#include + +#include "test_iterators.h" + +template +void +test(Iter1 first1, Iter1 last1, Iter2 first2, T init, T x) +{ + assert(std::inner_product(first1, last1, first2, init, + std::multiplies(), std::plus()) == x); +} + +template +void +test() +{ + int a[] = {1, 2, 3, 4, 5, 6}; + int b[] = {6, 5, 4, 3, 2, 1}; + unsigned sa = sizeof(a) / sizeof(a[0]); + test(Iter1(a), Iter1(a), Iter2(b), 1, 1); + test(Iter1(a), Iter1(a), Iter2(b), 10, 10); + test(Iter1(a), Iter1(a+1), Iter2(b), 1, 7); + test(Iter1(a), Iter1(a+1), Iter2(b), 10, 70); + test(Iter1(a), Iter1(a+2), Iter2(b), 1, 49); + test(Iter1(a), Iter1(a+2), Iter2(b), 10, 490); + test(Iter1(a), Iter1(a+sa), Iter2(b), 1, 117649); + test(Iter1(a), Iter1(a+sa), Iter2(b), 10, 1176490); +} + +int main() +{ + test, input_iterator >(); + test, forward_iterator >(); + test, bidirectional_iterator >(); + test, random_access_iterator >(); + test, const int*>(); + + test, input_iterator >(); + test, forward_iterator >(); + test, bidirectional_iterator >(); + test, random_access_iterator >(); + test, const int*>(); + + test, input_iterator >(); + test, forward_iterator >(); + test, bidirectional_iterator >(); + test, random_access_iterator >(); + test, const int*>(); + + test, input_iterator >(); + test, forward_iterator >(); + test, bidirectional_iterator >(); + test, random_access_iterator >(); + test, const int*>(); + + test >(); + test >(); + test >(); + test >(); + test(); +} diff --git a/test/std/numerics/numeric.ops/numeric.iota/iota.pass.cpp b/test/std/numerics/numeric.ops/numeric.iota/iota.pass.cpp new file mode 100644 index 0000000000000..eb7c8373ad582 --- /dev/null +++ b/test/std/numerics/numeric.ops/numeric.iota/iota.pass.cpp @@ -0,0 +1,38 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template +// void iota(ForwardIterator first, ForwardIterator last, T value); + +#include +#include + +#include "test_iterators.h" + +template +void +test() +{ + int ia[] = {1, 2, 3, 4, 5}; + int ir[] = {5, 6, 7, 8, 9}; + const unsigned s = sizeof(ia) / sizeof(ia[0]); + std::iota(InIter(ia), InIter(ia+s), 5); + for (unsigned i = 0; i < s; ++i) + assert(ia[i] == ir[i]); +} + +int main() +{ + test >(); + test >(); + test >(); + test(); +} diff --git a/test/std/numerics/numeric.ops/partial.sum/partial_sum.pass.cpp b/test/std/numerics/numeric.ops/partial.sum/partial_sum.pass.cpp new file mode 100644 index 0000000000000..cb468e019bb1f --- /dev/null +++ b/test/std/numerics/numeric.ops/partial.sum/partial_sum.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. +// +//===----------------------------------------------------------------------===// + +// + +// template OutIter> +// requires HasPlus +// && HasAssign::result_type> +// && Constructible +// OutIter +// partial_sum(InIter first, InIter last, OutIter result); + +#include +#include + +#include "test_iterators.h" + +template +void +test() +{ + int ia[] = {1, 2, 3, 4, 5}; + int ir[] = {1, 3, 6, 10, 15}; + const unsigned s = sizeof(ia) / sizeof(ia[0]); + int ib[s] = {0}; + OutIter r = std::partial_sum(InIter(ia), InIter(ia+s), OutIter(ib)); + assert(base(r) == ib + s); + for (unsigned i = 0; i < s; ++i) + assert(ib[i] == ir[i]); +} + +int main() +{ + test, output_iterator >(); + test, forward_iterator >(); + test, bidirectional_iterator >(); + test, random_access_iterator >(); + test, int*>(); + + test, output_iterator >(); + test, forward_iterator >(); + test, bidirectional_iterator >(); + test, random_access_iterator >(); + test, int*>(); + + test, output_iterator >(); + test, forward_iterator >(); + test, bidirectional_iterator >(); + test, random_access_iterator >(); + test, int*>(); + + test, output_iterator >(); + test, forward_iterator >(); + test, bidirectional_iterator >(); + test, random_access_iterator >(); + test, int*>(); + + test >(); + test >(); + test >(); + test >(); + test(); +} diff --git a/test/std/numerics/numeric.ops/partial.sum/partial_sum_op.pass.cpp b/test/std/numerics/numeric.ops/partial.sum/partial_sum_op.pass.cpp new file mode 100644 index 0000000000000..d8f2a93e41cec --- /dev/null +++ b/test/std/numerics/numeric.ops/partial.sum/partial_sum_op.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. +// +//===----------------------------------------------------------------------===// + +// + +// template OutIter, +// Callable BinaryOperation> +// requires HasAssign +// && Constructible +// && CopyConstructible +// OutIter +// partial_sum(InIter first, InIter last, OutIter result, BinaryOperation binary_op); + +#include +#include +#include + +#include "test_iterators.h" + +template +void +test() +{ + int ia[] = {1, 2, 3, 4, 5}; + int ir[] = {1, -1, -4, -8, -13}; + const unsigned s = sizeof(ia) / sizeof(ia[0]); + int ib[s] = {0}; + OutIter r = std::partial_sum(InIter(ia), InIter(ia+s), OutIter(ib), std::minus()); + assert(base(r) == ib + s); + for (unsigned i = 0; i < s; ++i) + assert(ib[i] == ir[i]); +} + +int main() +{ + test, output_iterator >(); + test, forward_iterator >(); + test, bidirectional_iterator >(); + test, random_access_iterator >(); + test, int*>(); + + test, output_iterator >(); + test, forward_iterator >(); + test, bidirectional_iterator >(); + test, random_access_iterator >(); + test, int*>(); + + test, output_iterator >(); + test, forward_iterator >(); + test, bidirectional_iterator >(); + test, random_access_iterator >(); + test, int*>(); + + test, output_iterator >(); + test, forward_iterator >(); + test, bidirectional_iterator >(); + test, random_access_iterator >(); + test, int*>(); + + test >(); + test >(); + test >(); + test >(); + test(); +} diff --git a/test/std/numerics/numeric.ops/version.pass.cpp b/test/std/numerics/numeric.ops/version.pass.cpp new file mode 100644 index 0000000000000..fb6e0a1063cee --- /dev/null +++ b/test/std/numerics/numeric.ops/version.pass.cpp @@ -0,0 +1,20 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +#include + +#ifndef _LIBCPP_VERSION +#error _LIBCPP_VERSION not defined +#endif + +int main() +{ +} -- cgit v1.2.3