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 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: c++03, c++11, c++14
13 // template<class T, size_t cnt> valarray(const T(&)[cnt], size_t) -> valarray<T>;
17 #include "test_macros.h"
22 // From (initializer_list<T>)
23 std::valarray v
= {1, 2, 3, 4, 5};
24 ASSERT_SAME_TYPE(decltype(v
), std::valarray
<int>);
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>);
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*>);
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>>);
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>>);
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>>);
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>>);