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 | //===----------------------------------------------------------------------===// |
8 | |
9 | // UNSUPPORTED: c++03, c++11, c++14 |
10 | |
11 | // <valarray> |
12 | |
13 | // template<class T, size_t cnt> valarray(const T(&)[cnt], size_t) -> valarray<T>; |
14 | |
15 | #include <valarray> |
16 | |
17 | #include "test_macros.h" |
18 | |
19 | int main(int, char**) |
20 | { |
21 | { |
22 | // From (initializer_list<T>) |
23 | std::valarray v = {1, 2, 3, 4, 5}; |
24 | ASSERT_SAME_TYPE(decltype(v), std::valarray<int>); |
25 | } |
26 | |
27 | { |
28 | // From (const T(&)[N], size_t) |
29 | long a[] = {1, 2, 3, 4, 5}; |
30 | std::valarray v(a, 5); |
31 | ASSERT_SAME_TYPE(decltype(v), std::valarray<long>); |
32 | } |
33 | |
34 | { |
35 | // From (const T&, size_t) |
36 | long a[] = {1, 2, 3, 4, 5}; |
37 | std::valarray v(&a[0], 5); |
38 | // Surprising but true. |
39 | ASSERT_SAME_TYPE(decltype(v), std::valarray<long*>); |
40 | } |
41 | |
42 | { |
43 | // From (slice_array<T>) |
44 | std::valarray<long> v{1,2,3,4,5}; |
45 | std::valarray v2 = v[std::slice(2,3,1)]; |
46 | static_assert(std::is_same_v<decltype(v2), std::valarray<long>>); |
47 | } |
48 | |
49 | { |
50 | // From (gslice_array<T>) |
51 | std::valarray<long> v{1,2,3,4,5}; |
52 | std::valarray v2 = v[std::gslice(0, {5}, {1})]; |
53 | static_assert(std::is_same_v<decltype(v2), std::valarray<long>>); |
54 | } |
55 | |
56 | { |
57 | // From (mask_array<T>) |
58 | std::valarray<long> v = {1, 2, 3, 4, 5}; |
59 | std::valarray<bool> m = {true, false, true, false, true}; |
60 | std::valarray v2 = v[m]; |
61 | static_assert(std::is_same_v<decltype(v2), std::valarray<long>>); |
62 | } |
63 | |
64 | { |
65 | // From (indirect_array<T>) |
66 | std::valarray<long> v = {1, 2, 3, 4, 5}; |
67 | std::valarray<std::size_t> i = {1, 2, 3}; |
68 | std::valarray v2 = v[i]; |
69 | static_assert(std::is_same_v<decltype(v2), std::valarray<long>>); |
70 | } |
71 | |
72 | return 0; |
73 | } |
74 | |