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 // valarray apply(value_type f(value_type)) const;
18 #include "test_macros.h"
22 T
f(T t
) {return t
+ 5;}
27 T a1
[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
28 T a2
[] = {6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
29 const unsigned N1
= sizeof(a1
)/sizeof(a1
[0]);
30 std::valarray
<T
> v1(a1
, N1
);
31 std::valarray
<T
> v2
= v1
.apply(f
);
32 assert(v2
.size() == N1
);
33 for (unsigned i
= 0; i
< N1
; ++i
)
34 assert(v2
[i
] == a2
[i
]);
37 const unsigned N1
= 0;
39 std::valarray
<T
> v2
= v1
.apply(f
);
40 assert(v2
.size() == N1
);
43 T a1
[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
44 T a2
[] = {7, 9, 11, 13, 15, 17, 19, 21, 23, 25};
45 const unsigned N1
= sizeof(a1
)/sizeof(a1
[0]);
46 std::valarray
<T
> v1(a1
, N1
);
47 std::valarray
<T
> v2
= (v1
+v1
).apply(f
);
48 assert(v2
.size() == N1
);
49 for (unsigned i
= 0; i
< N1
; ++i
)
50 assert(v2
[i
] == a2
[i
]);