Revert "[libc] Use best-fit binary trie to make malloc logarithmic" (#117065)
[llvm-project.git] / libcxx / test / std / numerics / numarray / template.valarray / valarray.members / apply_cref.pass.cpp
blob5703b993958812121adbadc97c476b5c7538c57b
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 // valarray apply(value_type f(const value_type&)) const;
15 #include <valarray>
16 #include <cassert>
18 #include "test_macros.h"
20 typedef int T;
22 T f(const T& t) {return t + 5;}
24 int main(int, char**)
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;
38 std::valarray<T> v1;
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]);
53 return 0;