//===----------------------------------------------------------------------===// // // 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; }