1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
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);
21 #include <type_traits>
23 #include "test_macros.h"
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]);
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);
58 int a
[] = {1, 2, 3, 4, 5};
59 const std::valarray
<int> cv(a
, 5);
61 for (const int& i
: cv
) {