diff --git a/libcxx/test/std/numerics/numarray/valarray.range/begin-end.pass.cpp b/libcxx/test/std/numerics/numarray/valarray.range/begin-end.pass.cpp new file mode 100644 --- /dev/null +++ b/libcxx/test/std/numerics/numarray/valarray.range/begin-end.pass.cpp @@ -0,0 +1,69 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +// + +// template class valarray; + +// template unspecified begin(valarray& v); +// template unspecified begin(const valarray& v); +// template unspecified end(valarray& v); +// template unspecified end(const valarray& v); + +#include +#include +#include +#include + +#include "test_macros.h" + +int main(int, char**) +{ + { + int a[] = {1, 2, 3, 4, 5}; + std::valarray v(a, 5); + const std::valarray& cv = v; + using It = decltype(std::begin(v)); + using CIt = decltype(std::begin(cv)); + static_assert(std::is_base_of::iterator_category>::value, ""); + static_assert(std::is_base_of::iterator_category>::value, ""); + ASSERT_SAME_TYPE(decltype(*std::begin(v)), int&); + ASSERT_SAME_TYPE(decltype(*std::begin(cv)), const int&); + assert(&*std::begin(v) == &v[0]); + assert(&*std::begin(cv) == &cv[0]); + *std::begin(v) = 10; + assert(v[0] == 10); + + ASSERT_SAME_TYPE(decltype(std::end(v)), It); + ASSERT_SAME_TYPE(decltype(std::end(cv)), CIt); + assert(&*std::prev(std::end(v)) == &v[4]); + assert(&*std::prev(std::end(cv)) == &cv[4]); + } +#if TEST_STD_VER >= 11 + { + int a[] = {1, 2, 3, 4, 5}; + std::valarray v(a, 5); + int sum = 0; + for (int& i : v) { + sum += i; + } + assert(sum == 15); + } + { + int a[] = {1, 2, 3, 4, 5}; + const std::valarray cv(a, 5); + int sum = 0; + for (const int& i : cv) { + sum += i; + } + assert(sum == 15); + } +#endif + + return 0; +} diff --git a/libcxx/test/std/numerics/numarray/valarray.range/begin_const.pass.cpp b/libcxx/test/std/numerics/numarray/valarray.range/begin_const.pass.cpp deleted file mode 100644 --- a/libcxx/test/std/numerics/numarray/valarray.range/begin_const.pass.cpp +++ /dev/null @@ -1,33 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -// - -// template class valarray; - -// template -// unspecified1 -// begin(const valarray& v); - -#include -#include - -#include "test_macros.h" - -int main(int, char**) -{ - { - typedef int T; - T a[] = {1, 2, 3, 4, 5}; - const unsigned N = sizeof(a)/sizeof(a[0]); - const std::valarray v(a, N); - assert(v[0] == 1); - } - - return 0; -} diff --git a/libcxx/test/std/numerics/numarray/valarray.range/begin_non_const.pass.cpp b/libcxx/test/std/numerics/numarray/valarray.range/begin_non_const.pass.cpp deleted file mode 100644 --- a/libcxx/test/std/numerics/numarray/valarray.range/begin_non_const.pass.cpp +++ /dev/null @@ -1,34 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -// - -// template class valarray; - -// template -// unspecified1 -// begin(valarray& v); - -#include -#include - -#include "test_macros.h" - -int main(int, char**) -{ - { - typedef int T; - T a[] = {1, 2, 3, 4, 5}; - const unsigned N = sizeof(a)/sizeof(a[0]); - std::valarray v(a, N); - *begin(v) = 10; - assert(v[0] == 10); - } - - return 0; -} diff --git a/libcxx/test/std/numerics/numarray/valarray.range/end_const.pass.cpp b/libcxx/test/std/numerics/numarray/valarray.range/end_const.pass.cpp deleted file mode 100644 --- a/libcxx/test/std/numerics/numarray/valarray.range/end_const.pass.cpp +++ /dev/null @@ -1,35 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -// - -// template class valarray; - -// template -// unspecified1 -// end(const valarray& v); - -#include -#include -#include - -#include "test_macros.h" - -int main(int, char**) -{ - { - typedef int T; - T a[] = {1, 2, 3, 4, 5}; - const unsigned N = sizeof(a)/sizeof(a[0]); - const std::valarray v(a, N); - assert(v[v.size()-1] == 5); - assert(static_cast(end(v) - begin(v)) == v.size()); - } - - return 0; -} diff --git a/libcxx/test/std/numerics/numarray/valarray.range/end_non_const.pass.cpp b/libcxx/test/std/numerics/numarray/valarray.range/end_non_const.pass.cpp deleted file mode 100644 --- a/libcxx/test/std/numerics/numarray/valarray.range/end_non_const.pass.cpp +++ /dev/null @@ -1,36 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -// - -// template class valarray; - -// template -// unspecified1 -// end(valarray& v); - -#include -#include -#include - -#include "test_macros.h" - -int main(int, char**) -{ - { - typedef int T; - T a[] = {1, 2, 3, 4, 5}; - const unsigned N = sizeof(a)/sizeof(a[0]); - std::valarray v(a, N); - *(end(v) - 1) = 10; - assert(v[v.size()-1] == 10); - assert(static_cast(end(v) - begin(v)) == v.size()); - } - - return 0; -}