[flang][cuda] Do not apply implicit data attribute on dummy arg with VALUE (#119927)
[llvm-project.git] / libcxx / test / std / numerics / numarray / valarray.range / begin-end.pass.cpp
blobd5ec017e04a860259e6190313b58c39d867d5d33
1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 // <valarray>
11 // template<class T> class valarray;
13 // template <class T> unspecified begin(valarray<T>& v);
14 // template <class T> unspecified begin(const valarray<T>& v);
15 // template <class T> unspecified end(valarray<T>& v);
16 // template <class T> unspecified end(const valarray<T>& v);
18 #include <valarray>
19 #include <cassert>
20 #include <iterator>
21 #include <type_traits>
23 #include "test_macros.h"
25 int main(int, char**)
28 int a[] = {1, 2, 3, 4, 5};
29 std::valarray<int> v(a, 5);
30 const std::valarray<int>& cv = v;
31 using It = decltype(std::begin(v));
32 using CIt = decltype(std::begin(cv));
33 static_assert(std::is_base_of<std::random_access_iterator_tag, std::iterator_traits<It>::iterator_category>::value, "");
34 static_assert(std::is_base_of<std::random_access_iterator_tag, std::iterator_traits<CIt>::iterator_category>::value, "");
35 ASSERT_SAME_TYPE(decltype(*std::begin(v)), int&);
36 ASSERT_SAME_TYPE(decltype(*std::begin(cv)), const int&);
37 assert(&*std::begin(v) == &v[0]);
38 assert(&*std::begin(cv) == &cv[0]);
39 *std::begin(v) = 10;
40 assert(v[0] == 10);
42 ASSERT_SAME_TYPE(decltype(std::end(v)), It);
43 ASSERT_SAME_TYPE(decltype(std::end(cv)), CIt);
44 assert(&*std::prev(std::end(v)) == &v[4]);
45 assert(&*std::prev(std::end(cv)) == &cv[4]);
47 #if TEST_STD_VER >= 11
49 int a[] = {1, 2, 3, 4, 5};
50 std::valarray<int> v(a, 5);
51 int sum = 0;
52 for (int& i : v) {
53 sum += i;
55 assert(sum == 15);
58 int a[] = {1, 2, 3, 4, 5};
59 const std::valarray<int> cv(a, 5);
60 int sum = 0;
61 for (const int& i : cv) {
62 sum += i;
64 assert(sum == 15);
66 #endif
68 return 0;