Initial commit

This commit is contained in:
Yervant7
2024-01-16 19:28:29 -03:00
commit 8c0524dc0f
9054 changed files with 1081727 additions and 0 deletions
@@ -0,0 +1,29 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// <valarray>
// template<class T>
// class valarray
// {
// public:
// typedef T value_type;
// ...
#include <valarray>
#include <type_traits>
#include "test_macros.h"
int main(int, char**)
{
static_assert((std::is_same<std::valarray<int>::value_type, int>::value), "");
static_assert((std::is_same<std::valarray<double>::value_type, double>::value), "");
return 0;
}
@@ -0,0 +1,36 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// <valarray>
// template<class T> class valarray;
// value_type& operator[](size_t i);
#include <valarray>
#include <cassert>
#include "test_macros.h"
int main(int, char**)
{
{
typedef int T;
T a[] = {5, 4, 3, 2, 1};
const unsigned N = sizeof(a)/sizeof(a[0]);
std::valarray<T> v(a, N);
for (unsigned i = 0; i < N; ++i)
{
assert(v[i] == a[i]);
v[i] = i;
assert(v[i] == static_cast<int>(i));
}
}
return 0;
}
@@ -0,0 +1,34 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// <valarray>
// template<class T> class valarray;
// const value_type& operator[](size_t i) const;
#include <valarray>
#include <cassert>
#include "test_macros.h"
int main(int, char**)
{
{
typedef int T;
T a[] = {5, 4, 3, 2, 1};
const unsigned N = sizeof(a)/sizeof(a[0]);
const std::valarray<T> v(a, N);
for (unsigned i = 0; i < N; ++i)
{
assert(v[i] == a[i]);
}
}
return 0;
}
@@ -0,0 +1,89 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// <valarray>
// template<class T> class valarray;
// valarray& operator=(const valarray& v);
#include <valarray>
#include <cassert>
#include <cstddef>
#include "test_macros.h"
struct S
{
S() : x_(0) { default_ctor_called = true; }
S(int x) : x_(x) {}
int x_;
static bool default_ctor_called;
};
bool S::default_ctor_called = false;
bool operator==(const S& lhs, const S& rhs)
{
return lhs.x_ == rhs.x_;
}
int main(int, char**)
{
{
typedef int T;
T a[] = {1, 2, 3, 4, 5};
const unsigned N = sizeof(a)/sizeof(a[0]);
std::valarray<T> v(a, N);
std::valarray<T> v2;
v2 = v;
assert(v2.size() == v.size());
for (std::size_t i = 0; i < v2.size(); ++i)
assert(v2[i] == v[i]);
}
{
typedef double T;
T a[] = {1, 2.5, 3, 4.25, 5};
const unsigned N = sizeof(a)/sizeof(a[0]);
std::valarray<T> v(a, N);
std::valarray<T> v2;
v2 = v;
assert(v2.size() == v.size());
for (std::size_t i = 0; i < v2.size(); ++i)
assert(v2[i] == v[i]);
}
{
typedef std::valarray<double> T;
T a[] = {T(1), T(2), T(3), T(4), T(5)};
const unsigned N = sizeof(a)/sizeof(a[0]);
std::valarray<T> v(a, N);
std::valarray<T> v2(a, N-2);
v2 = v;
assert(v2.size() == v.size());
for (unsigned i = 0; i < N; ++i)
{
assert(v2[i].size() == v[i].size());
for (std::size_t j = 0; j < v[i].size(); ++j)
assert(v2[i][j] == v[i][j]);
}
}
{
typedef S T;
T a[] = {T(1), T(2), T(3), T(4), T(5)};
const unsigned N = sizeof(a)/sizeof(a[0]);
std::valarray<T> v(a, N);
std::valarray<T> v2;
v2 = v;
assert(v2.size() == v.size());
for (std::size_t i = 0; i < v2.size(); ++i)
assert(v2[i] == v[i]);
assert(!S::default_ctor_called);
}
return 0;
}
@@ -0,0 +1,61 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// <valarray>
// template<class T> class valarray;
// valarray& operator=(const gslice_array<value_type>& ga);
#include <valarray>
#include <cassert>
#include "test_macros.h"
int main(int, char**)
{
int a[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35,
36, 37, 38, 39, 40};
std::valarray<int> v1(a, sizeof(a)/sizeof(a[0]));
std::size_t sz[] = {2, 4, 3};
std::size_t st[] = {19, 4, 1};
typedef std::valarray<std::size_t> sizes;
typedef std::valarray<std::size_t> strides;
std::valarray<int> v(24);
v = v1[std::gslice(3, sizes(sz, sizeof(sz)/sizeof(sz[0])),
strides(st, sizeof(st)/sizeof(st[0])))];
assert(v.size() == 24);
assert(v[ 0] == 3);
assert(v[ 1] == 4);
assert(v[ 2] == 5);
assert(v[ 3] == 7);
assert(v[ 4] == 8);
assert(v[ 5] == 9);
assert(v[ 6] == 11);
assert(v[ 7] == 12);
assert(v[ 8] == 13);
assert(v[ 9] == 15);
assert(v[10] == 16);
assert(v[11] == 17);
assert(v[12] == 22);
assert(v[13] == 23);
assert(v[14] == 24);
assert(v[15] == 26);
assert(v[16] == 27);
assert(v[17] == 28);
assert(v[18] == 30);
assert(v[19] == 31);
assert(v[20] == 32);
assert(v[21] == 34);
assert(v[22] == 35);
assert(v[23] == 36);
return 0;
}
@@ -0,0 +1,61 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// <valarray>
// template<class T> class valarray;
// valarray& operator=(const indirect_array<value_type>& ia);
#include <valarray>
#include <cassert>
#include "test_macros.h"
int main(int, char**)
{
int a[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35,
36, 37, 38, 39, 40};
const std::size_t N1 = sizeof(a)/sizeof(a[0]);
std::size_t s[] = { 3, 4, 5, 7, 8, 9, 11, 12, 13, 15, 16, 17,
22, 23, 24, 26, 27, 28, 30, 31, 32, 34, 35, 36};
const std::size_t S = sizeof(s)/sizeof(s[0]);
std::valarray<int> v1(a, N1);
std::valarray<std::size_t> ia(s, S);
std::valarray<int> v(24);
v = v1[ia];
assert(v.size() == 24);
assert(v[ 0] == 3);
assert(v[ 1] == 4);
assert(v[ 2] == 5);
assert(v[ 3] == 7);
assert(v[ 4] == 8);
assert(v[ 5] == 9);
assert(v[ 6] == 11);
assert(v[ 7] == 12);
assert(v[ 8] == 13);
assert(v[ 9] == 15);
assert(v[10] == 16);
assert(v[11] == 17);
assert(v[12] == 22);
assert(v[13] == 23);
assert(v[14] == 24);
assert(v[15] == 26);
assert(v[16] == 27);
assert(v[17] == 28);
assert(v[18] == 30);
assert(v[19] == 31);
assert(v[20] == 32);
assert(v[21] == 34);
assert(v[22] == 35);
assert(v[23] == 36);
return 0;
}
@@ -0,0 +1,87 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03
// <valarray>
// template<class T> class valarray;
// valarray& operator=(initializer_list<value_type> il);
#include <valarray>
#include <cassert>
#include <cstddef>
#include "test_macros.h"
struct S
{
S() : x_(0) { default_ctor_called = true; }
S(int x) : x_(x) {}
int x_;
static bool default_ctor_called;
};
bool S::default_ctor_called = false;
bool operator==(const S& lhs, const S& rhs)
{
return lhs.x_ == rhs.x_;
}
int main(int, char**)
{
{
typedef int T;
T a[] = {1, 2, 3, 4, 5};
const unsigned N = sizeof(a)/sizeof(a[0]);
std::valarray<T> v2;
v2 = {1, 2, 3, 4, 5};
assert(v2.size() == N);
for (std::size_t i = 0; i < v2.size(); ++i)
assert(v2[i] == a[i]);
}
{
typedef double T;
T a[] = {1, 2.5, 3, 4.25, 5};
const unsigned N = sizeof(a)/sizeof(a[0]);
std::valarray<T> v2;
v2 = {1, 2.5, 3, 4.25, 5};
assert(v2.size() == N);
for (std::size_t i = 0; i < v2.size(); ++i)
assert(v2[i] == a[i]);
}
{
typedef std::valarray<double> T;
T a[] = {T(1), T(2), T(3), T(4), T(5)};
const unsigned N = sizeof(a)/sizeof(a[0]);
std::valarray<T> v2(a, N-2);
v2 = {T(1), T(2), T(3), T(4), T(5)};
assert(v2.size() == N);
for (unsigned i = 0; i < N; ++i)
{
assert(v2[i].size() == a[i].size());
for (std::size_t j = 0; j < a[i].size(); ++j)
assert(v2[i][j] == a[i][j]);
}
}
{
typedef S T;
T a[] = {T(1), T(2), T(3), T(4), T(5)};
const unsigned N = sizeof(a)/sizeof(a[0]);
std::valarray<T> v2;
v2 = {T(1), T(2), T(3), T(4), T(5)};
assert(v2.size() == N);
for (std::size_t i = 0; i < v2.size(); ++i)
assert(v2[i] == a[i]);
assert(!S::default_ctor_called);
}
return 0;
}
@@ -0,0 +1,38 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// <valarray>
// template<class T> class valarray;
// valarray& operator=(const mask_array<value_type>& ma);
#include <valarray>
#include <cassert>
#include "test_macros.h"
int main(int, char**)
{
int a1[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
const std::size_t N1 = sizeof(a1)/sizeof(a1[0]);
bool b[N1] = {true, false, false, true, true, false,
false, true, false, false, false, true};
std::valarray<int> v1(a1, N1);
std::valarray<bool> vb(b, N1);
std::valarray<int> v2(5);
v2 = v1[vb];
assert(v2.size() == 5);
assert(v2[ 0] == 0);
assert(v2[ 1] == 3);
assert(v2[ 2] == 4);
assert(v2[ 3] == 7);
assert(v2[ 4] == 11);
return 0;
}
@@ -0,0 +1,67 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03
// <valarray>
// template<class T> class valarray;
// valarray& operator=(valarray&& v);
#include <valarray>
#include <cassert>
#include <cstddef>
#include "test_macros.h"
int main(int, char**)
{
{
typedef int T;
T a[] = {1, 2, 3, 4, 5};
const unsigned N = sizeof(a)/sizeof(a[0]);
std::valarray<T> v(a, N);
std::valarray<T> v2;
v2 = std::move(v);
assert(v2.size() == N);
assert(v.size() == 0);
for (std::size_t i = 0; i < v2.size(); ++i)
assert(v2[i] == a[i]);
}
{
typedef double T;
T a[] = {1, 2.5, 3, 4.25, 5};
const unsigned N = sizeof(a)/sizeof(a[0]);
std::valarray<T> v(a, N);
std::valarray<T> v2;
v2 = std::move(v);
assert(v2.size() == N);
assert(v.size() == 0);
for (std::size_t i = 0; i < v2.size(); ++i)
assert(v2[i] == a[i]);
}
{
typedef std::valarray<double> T;
T a[] = {T(1), T(2), T(3), T(4), T(5)};
const unsigned N = sizeof(a)/sizeof(a[0]);
std::valarray<T> v(a, N);
std::valarray<T> v2(a, N-2);
v2 = std::move(v);
assert(v2.size() == N);
assert(v.size() == 0);
for (unsigned i = 0; i < N; ++i)
{
assert(v2[i].size() == a[i].size());
for (std::size_t j = 0; j < a[i].size(); ++j)
assert(v2[i][j] == a[i][j]);
}
}
return 0;
}
@@ -0,0 +1,34 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// <valarray>
// template<class T> class valarray;
// valarray& operator=(const slice_array<value_type>& sa);
#include <valarray>
#include <cassert>
#include "test_macros.h"
int main(int, char**)
{
int a[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
std::valarray<int> v1(a, sizeof(a)/sizeof(a[0]));
std::valarray<int> v(5);
v = v1[std::slice(1, 5, 3)];
assert(v.size() == 5);
assert(v[0] == 1);
assert(v[1] == 4);
assert(v[2] == 7);
assert(v[3] == 10);
assert(v[4] == 13);
return 0;
}
@@ -0,0 +1,26 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// <valarray>
// template<class T> class valarray;
// valarray& operator=(const value_type& x);
// Validate whether the container can be copy-assigned with an ADL-hijacking operator&
#include <valarray>
#include "test_macros.h"
#include "operator_hijacker.h"
void test() {
std::valarray<operator_hijacker> vo;
std::valarray<operator_hijacker> v;
v = vo;
}
@@ -0,0 +1,35 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// <valarray>
// template<class T> class valarray;
// valarray& operator=(const value_type& x);
#include <valarray>
#include <cassert>
#include <cstddef>
#include "test_macros.h"
int main(int, char**)
{
{
typedef int T;
T a[] = {1, 2, 3, 4, 5};
const unsigned N = sizeof(a)/sizeof(a[0]);
std::valarray<T> v(a, N);
v = 7;
assert(v.size() == N);
for (std::size_t i = 0; i < v.size(); ++i)
assert(v[i] == 7);
}
return 0;
}
@@ -0,0 +1,40 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// <valarray>
// template<class T> class valarray;
// valarray& operator&=(const valarray& v);
#include <valarray>
#include <cassert>
#include <cstddef>
#include "test_macros.h"
int main(int, char**)
{
{
typedef int T;
T a1[] = {1, 2, 3, 4, 5};
T a2[] = {6, 7, 8, 9, 10};
T a3[] = {0, 2, 0, 0, 0};
const unsigned N = sizeof(a1)/sizeof(a1[0]);
std::valarray<T> v1(a1, N);
std::valarray<T> v2(a2, N);
std::valarray<T> v3(a3, N);
v1 &= v2;
assert(v1.size() == v2.size());
assert(v1.size() == v3.size());
for (std::size_t i = 0; i < v1.size(); ++i)
assert(v1[i] == v3[i]);
}
return 0;
}
@@ -0,0 +1,37 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// <valarray>
// template<class T> class valarray;
// valarray& operator&=(const value_type& x);
#include <valarray>
#include <cassert>
#include <cstddef>
#include "test_macros.h"
int main(int, char**)
{
{
typedef int T;
T a1[] = { 1, 2, 3, 4, 5};
T a2[] = { 1, 2, 3, 0, 1};
const unsigned N = sizeof(a1)/sizeof(a1[0]);
std::valarray<T> v1(a1, N);
std::valarray<T> v2(a2, N);
v1 &= 3;
assert(v1.size() == v2.size());
for (std::size_t i = 0; i < v1.size(); ++i)
assert(v1[i] == v2[i]);
}
return 0;
}
@@ -0,0 +1,40 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// <valarray>
// template<class T> class valarray;
// valarray& operator/=(const valarray& v);
#include <valarray>
#include <cassert>
#include <cstddef>
#include "test_macros.h"
int main(int, char**)
{
{
typedef int T;
T a1[] = {1, 2, 3, 4, 5};
T a2[] = {6, 7, 8, 9, 10};
T a3[] = {6, 14, 24, 36, 50};
const unsigned N = sizeof(a1)/sizeof(a1[0]);
std::valarray<T> v1(a1, N);
std::valarray<T> v2(a2, N);
std::valarray<T> v3(a3, N);
v3 /= v2;
assert(v1.size() == v2.size());
assert(v1.size() == v3.size());
for (std::size_t i = 0; i < v1.size(); ++i)
assert(v1[i] == v3[i]);
}
return 0;
}
@@ -0,0 +1,37 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// <valarray>
// template<class T> class valarray;
// valarray& operator/=(const value_type& x);
#include <valarray>
#include <cassert>
#include <cstddef>
#include "test_macros.h"
int main(int, char**)
{
{
typedef int T;
T a1[] = {1, 2, 3, 4, 5};
T a2[] = {6, 12, 18, 24, 30};
const unsigned N = sizeof(a1)/sizeof(a1[0]);
std::valarray<T> v1(a1, N);
std::valarray<T> v2(a2, N);
v2 /= 6;
assert(v1.size() == v2.size());
for (std::size_t i = 0; i < v1.size(); ++i)
assert(v1[i] == v2[i]);
}
return 0;
}
@@ -0,0 +1,40 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// <valarray>
// template<class T> class valarray;
// valarray& operator-=(const valarray& v);
#include <valarray>
#include <cassert>
#include <cstddef>
#include "test_macros.h"
int main(int, char**)
{
{
typedef int T;
T a1[] = {1, 2, 3, 4, 5};
T a2[] = {6, 7, 8, 9, 10};
T a3[] = {7, 9, 11, 13, 15};
const unsigned N = sizeof(a1)/sizeof(a1[0]);
std::valarray<T> v1(a1, N);
std::valarray<T> v2(a2, N);
std::valarray<T> v3(a3, N);
v3 -= v2;
assert(v1.size() == v2.size());
assert(v1.size() == v3.size());
for (std::size_t i = 0; i < v1.size(); ++i)
assert(v1[i] == v3[i]);
}
return 0;
}
@@ -0,0 +1,37 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// <valarray>
// template<class T> class valarray;
// valarray& operator-=(const value_type& x);
#include <valarray>
#include <cassert>
#include <cstddef>
#include "test_macros.h"
int main(int, char**)
{
{
typedef int T;
T a1[] = { 1, 2, 3, 4, 5};
T a2[] = {-2, -1, 0, 1, 2};
const unsigned N = sizeof(a1)/sizeof(a1[0]);
std::valarray<T> v1(a1, N);
std::valarray<T> v2(a2, N);
v1 -= 3;
assert(v1.size() == v2.size());
for (std::size_t i = 0; i < v1.size(); ++i)
assert(v1[i] == v2[i]);
}
return 0;
}
@@ -0,0 +1,40 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// <valarray>
// template<class T> class valarray;
// valarray& operator%=(const valarray& v);
#include <valarray>
#include <cassert>
#include <cstddef>
#include "test_macros.h"
int main(int, char**)
{
{
typedef int T;
T a1[] = {1, 2, 3, 4, 5};
T a2[] = {6, 7, 8, 9, 10};
T a3[] = {0, 1, 2, 1, 0};
const unsigned N = sizeof(a1)/sizeof(a1[0]);
std::valarray<T> v1(a1, N);
std::valarray<T> v2(a2, N);
std::valarray<T> v3(a3, N);
v2 %= v1;
assert(v1.size() == v2.size());
assert(v1.size() == v3.size());
for (std::size_t i = 0; i < v1.size(); ++i)
assert(v2[i] == v3[i]);
}
return 0;
}
@@ -0,0 +1,37 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// <valarray>
// template<class T> class valarray;
// valarray& operator%=(const value_type& x);
#include <valarray>
#include <cassert>
#include <cstddef>
#include "test_macros.h"
int main(int, char**)
{
{
typedef int T;
T a1[] = {1, 2, 3, 4, 5};
T a2[] = {1, 2, 0, 1, 2};
const unsigned N = sizeof(a1)/sizeof(a1[0]);
std::valarray<T> v1(a1, N);
std::valarray<T> v2(a2, N);
v1 %= 3;
assert(v1.size() == v2.size());
for (std::size_t i = 0; i < v1.size(); ++i)
assert(v1[i] == v2[i]);
}
return 0;
}
@@ -0,0 +1,40 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// <valarray>
// template<class T> class valarray;
// valarray& operator|=(const valarray& v);
#include <valarray>
#include <cassert>
#include <cstddef>
#include "test_macros.h"
int main(int, char**)
{
{
typedef int T;
T a1[] = {1, 2, 3, 4, 5};
T a2[] = {6, 7, 8, 9, 10};
T a3[] = {7, 7, 11, 13, 15};
const unsigned N = sizeof(a1)/sizeof(a1[0]);
std::valarray<T> v1(a1, N);
std::valarray<T> v2(a2, N);
std::valarray<T> v3(a3, N);
v1 |= v2;
assert(v1.size() == v2.size());
assert(v1.size() == v3.size());
for (std::size_t i = 0; i < v1.size(); ++i)
assert(v1[i] == v3[i]);
}
return 0;
}
@@ -0,0 +1,37 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// <valarray>
// template<class T> class valarray;
// valarray& operator|=(const value_type& x);
#include <valarray>
#include <cassert>
#include <cstddef>
#include "test_macros.h"
int main(int, char**)
{
{
typedef int T;
T a1[] = { 1, 2, 3, 4, 5};
T a2[] = { 3, 3, 3, 7, 7};
const unsigned N = sizeof(a1)/sizeof(a1[0]);
std::valarray<T> v1(a1, N);
std::valarray<T> v2(a2, N);
v1 |= 3;
assert(v1.size() == v2.size());
for (std::size_t i = 0; i < v1.size(); ++i)
assert(v1[i] == v2[i]);
}
return 0;
}
@@ -0,0 +1,40 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// <valarray>
// template<class T> class valarray;
// valarray& operator+=(const valarray& v);
#include <valarray>
#include <cassert>
#include <cstddef>
#include "test_macros.h"
int main(int, char**)
{
{
typedef int T;
T a1[] = {1, 2, 3, 4, 5};
T a2[] = {6, 7, 8, 9, 10};
T a3[] = {7, 9, 11, 13, 15};
const unsigned N = sizeof(a1)/sizeof(a1[0]);
std::valarray<T> v1(a1, N);
std::valarray<T> v2(a2, N);
std::valarray<T> v3(a3, N);
v1 += v2;
assert(v1.size() == v2.size());
assert(v1.size() == v3.size());
for (std::size_t i = 0; i < v1.size(); ++i)
assert(v1[i] == v3[i]);
}
return 0;
}
@@ -0,0 +1,37 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// <valarray>
// template<class T> class valarray;
// valarray& operator+=(const value_type& x);
#include <valarray>
#include <cassert>
#include <cstddef>
#include "test_macros.h"
int main(int, char**)
{
{
typedef int T;
T a1[] = {1, 2, 3, 4, 5};
T a2[] = {4, 5, 6, 7, 8};
const unsigned N = sizeof(a1)/sizeof(a1[0]);
std::valarray<T> v1(a1, N);
std::valarray<T> v2(a2, N);
v1 += 3;
assert(v1.size() == v2.size());
for (std::size_t i = 0; i < v1.size(); ++i)
assert(v1[i] == v2[i]);
}
return 0;
}
@@ -0,0 +1,40 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// <valarray>
// template<class T> class valarray;
// valarray& operator<<=(const valarray& v);
#include <valarray>
#include <cassert>
#include <cstddef>
#include "test_macros.h"
int main(int, char**)
{
{
typedef int T;
T a1[] = { 1, 2, 3, 4, 5};
T a2[] = { 6, 7, 8, 9, 10};
T a3[] = {64, 256, 768, 2048, 5120};
const unsigned N = sizeof(a1)/sizeof(a1[0]);
std::valarray<T> v1(a1, N);
std::valarray<T> v2(a2, N);
std::valarray<T> v3(a3, N);
v1 <<= v2;
assert(v1.size() == v2.size());
assert(v1.size() == v3.size());
for (std::size_t i = 0; i < v1.size(); ++i)
assert(v1[i] == v3[i]);
}
return 0;
}
@@ -0,0 +1,37 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// <valarray>
// template<class T> class valarray;
// valarray& operator<<=(const value_type& x);
#include <valarray>
#include <cassert>
#include <cstddef>
#include "test_macros.h"
int main(int, char**)
{
{
typedef int T;
T a1[] = { 1, 2, 3, 4, 5};
T a2[] = { 8, 16, 24, 32, 40};
const unsigned N = sizeof(a1)/sizeof(a1[0]);
std::valarray<T> v1(a1, N);
std::valarray<T> v2(a2, N);
v1 <<= 3;
assert(v1.size() == v2.size());
for (std::size_t i = 0; i < v1.size(); ++i)
assert(v1[i] == v2[i]);
}
return 0;
}
@@ -0,0 +1,40 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// <valarray>
// template<class T> class valarray;
// valarray& operator>>=(const valarray& v);
#include <valarray>
#include <cassert>
#include <cstddef>
#include "test_macros.h"
int main(int, char**)
{
{
typedef int T;
T a1[] = { 1, 2, 3, 4, 5};
T a2[] = { 6, 7, 8, 9, 10};
T a3[] = {64, 256, 768, 2048, 5120};
const unsigned N = sizeof(a1)/sizeof(a1[0]);
std::valarray<T> v1(a1, N);
std::valarray<T> v2(a2, N);
std::valarray<T> v3(a3, N);
v3 >>= v2;
assert(v1.size() == v2.size());
assert(v1.size() == v3.size());
for (std::size_t i = 0; i < v1.size(); ++i)
assert(v1[i] == v3[i]);
}
return 0;
}
@@ -0,0 +1,37 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// <valarray>
// template<class T> class valarray;
// valarray& operator>>=(const value_type& x);
#include <valarray>
#include <cassert>
#include <cstddef>
#include "test_macros.h"
int main(int, char**)
{
{
typedef int T;
T a1[] = { 1, 2, 3, 4, 5};
T a2[] = { 8, 16, 24, 32, 40};
const unsigned N = sizeof(a1)/sizeof(a1[0]);
std::valarray<T> v1(a1, N);
std::valarray<T> v2(a2, N);
v2 >>= 3;
assert(v1.size() == v2.size());
for (std::size_t i = 0; i < v1.size(); ++i)
assert(v1[i] == v2[i]);
}
return 0;
}
@@ -0,0 +1,40 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// <valarray>
// template<class T> class valarray;
// valarray& operator*=(const valarray& v);
#include <valarray>
#include <cassert>
#include <cstddef>
#include "test_macros.h"
int main(int, char**)
{
{
typedef int T;
T a1[] = {1, 2, 3, 4, 5};
T a2[] = {6, 7, 8, 9, 10};
T a3[] = {6, 14, 24, 36, 50};
const unsigned N = sizeof(a1)/sizeof(a1[0]);
std::valarray<T> v1(a1, N);
std::valarray<T> v2(a2, N);
std::valarray<T> v3(a3, N);
v1 *= v2;
assert(v1.size() == v2.size());
assert(v1.size() == v3.size());
for (std::size_t i = 0; i < v1.size(); ++i)
assert(v1[i] == v3[i]);
}
return 0;
}
@@ -0,0 +1,37 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// <valarray>
// template<class T> class valarray;
// valarray& operator*=(const value_type& x);
#include <valarray>
#include <cassert>
#include <cstddef>
#include "test_macros.h"
int main(int, char**)
{
{
typedef int T;
T a1[] = {1, 2, 3, 4, 5};
T a2[] = {6, 12, 18, 24, 30};
const unsigned N = sizeof(a1)/sizeof(a1[0]);
std::valarray<T> v1(a1, N);
std::valarray<T> v2(a2, N);
v1 *= 6;
assert(v1.size() == v2.size());
for (std::size_t i = 0; i < v1.size(); ++i)
assert(v1[i] == v2[i]);
}
return 0;
}
@@ -0,0 +1,40 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// <valarray>
// template<class T> class valarray;
// valarray& operator^=(const valarray& v);
#include <valarray>
#include <cassert>
#include <cstddef>
#include "test_macros.h"
int main(int, char**)
{
{
typedef int T;
T a1[] = {1, 2, 3, 4, 5};
T a2[] = {6, 7, 8, 9, 10};
T a3[] = {7, 5, 11, 13, 15};
const unsigned N = sizeof(a1)/sizeof(a1[0]);
std::valarray<T> v1(a1, N);
std::valarray<T> v2(a2, N);
std::valarray<T> v3(a3, N);
v1 ^= v2;
assert(v1.size() == v2.size());
assert(v1.size() == v3.size());
for (std::size_t i = 0; i < v1.size(); ++i)
assert(v1[i] == v3[i]);
}
return 0;
}
@@ -0,0 +1,37 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// <valarray>
// template<class T> class valarray;
// valarray& operator^=(const value_type& x);
#include <valarray>
#include <cassert>
#include <cstddef>
#include "test_macros.h"
int main(int, char**)
{
{
typedef int T;
T a1[] = { 1, 2, 3, 4, 5};
T a2[] = { 2, 1, 0, 7, 6};
const unsigned N = sizeof(a1)/sizeof(a1[0]);
std::valarray<T> v1(a1, N);
std::valarray<T> v2(a2, N);
v1 ^= 3;
assert(v1.size() == v2.size());
for (std::size_t i = 0; i < v1.size(); ++i)
assert(v1[i] == v2[i]);
}
return 0;
}
@@ -0,0 +1,59 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// <valarray>
// template<class T> class valarray;
// valarray(const valarray<value_type>& v);
#include <valarray>
#include <cassert>
#include <cstddef>
#include "test_macros.h"
int main(int, char**)
{
{
typedef int T;
T a[] = {1, 2, 3, 4, 5};
const unsigned N = sizeof(a)/sizeof(a[0]);
std::valarray<T> v(a, N);
std::valarray<T> v2 = v;
assert(v2.size() == v.size());
for (std::size_t i = 0; i < v2.size(); ++i)
assert(v2[i] == v[i]);
}
{
typedef double T;
T a[] = {1, 2.5, 3, 4.25, 5};
const unsigned N = sizeof(a)/sizeof(a[0]);
std::valarray<T> v(a, N);
std::valarray<T> v2 = v;
assert(v2.size() == v.size());
for (std::size_t i = 0; i < v2.size(); ++i)
assert(v2[i] == v[i]);
}
{
typedef std::valarray<double> T;
T a[] = {T(1), T(2), T(3), T(4), T(5)};
const unsigned N = sizeof(a)/sizeof(a[0]);
std::valarray<T> v(a, N);
std::valarray<T> v2 = v;
assert(v2.size() == v.size());
for (unsigned i = 0; i < N; ++i)
{
assert(v2[i].size() == v[i].size());
for (std::size_t j = 0; j < v[i].size(); ++j)
assert(v2[i][j] == v[i][j]);
}
}
return 0;
}
@@ -0,0 +1,73 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14
// <valarray>
// template<class T, size_t cnt> valarray(const T(&)[cnt], size_t) -> valarray<T>;
#include <valarray>
#include "test_macros.h"
int main(int, char**)
{
{
// From (initializer_list<T>)
std::valarray v = {1, 2, 3, 4, 5};
ASSERT_SAME_TYPE(decltype(v), std::valarray<int>);
}
{
// From (const T(&)[N], size_t)
long a[] = {1, 2, 3, 4, 5};
std::valarray v(a, 5);
ASSERT_SAME_TYPE(decltype(v), std::valarray<long>);
}
{
// From (const T&, size_t)
long a[] = {1, 2, 3, 4, 5};
std::valarray v(&a[0], 5);
// Surprising but true.
ASSERT_SAME_TYPE(decltype(v), std::valarray<long*>);
}
{
// From (slice_array<T>)
std::valarray<long> v{1,2,3,4,5};
std::valarray v2 = v[std::slice(2,3,1)];
static_assert(std::is_same_v<decltype(v2), std::valarray<long>>);
}
{
// From (gslice_array<T>)
std::valarray<long> v{1,2,3,4,5};
std::valarray v2 = v[std::gslice(0, {5}, {1})];
static_assert(std::is_same_v<decltype(v2), std::valarray<long>>);
}
{
// From (mask_array<T>)
std::valarray<long> v = {1, 2, 3, 4, 5};
std::valarray<bool> m = {true, false, true, false, true};
std::valarray v2 = v[m];
static_assert(std::is_same_v<decltype(v2), std::valarray<long>>);
}
{
// From (indirect_array<T>)
std::valarray<long> v = {1, 2, 3, 4, 5};
std::valarray<size_t> i = {1, 2, 3};
std::valarray v2 = v[i];
static_assert(std::is_same_v<decltype(v2), std::valarray<long>>);
}
return 0;
}
@@ -0,0 +1,52 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// <valarray>
// template<class T> class valarray;
// valarray();
#include <valarray>
#include <cassert>
#include "test_macros.h"
struct S {
S() { ctor_called = true; }
static bool ctor_called;
};
bool S::ctor_called = false;
int main(int, char**)
{
{
std::valarray<int> v;
assert(v.size() == 0);
}
{
std::valarray<float> v;
assert(v.size() == 0);
}
{
std::valarray<double> v;
assert(v.size() == 0);
}
{
std::valarray<std::valarray<double> > v;
assert(v.size() == 0);
}
{
std::valarray<S> v;
assert(v.size() == 0);
assert(!S::ctor_called);
}
return 0;
}
@@ -0,0 +1,60 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// <valarray>
// template<class T> class valarray;
// valarray(const gslice_array<value_type>& sa);
#include <valarray>
#include <cassert>
#include "test_macros.h"
int main(int, char**)
{
int a[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35,
36, 37, 38, 39, 40};
std::valarray<int> v1(a, sizeof(a)/sizeof(a[0]));
std::size_t sz[] = {2, 4, 3};
std::size_t st[] = {19, 4, 1};
typedef std::valarray<std::size_t> sizes;
typedef std::valarray<std::size_t> strides;
std::valarray<int> v(v1[std::gslice(3, sizes(sz, sizeof(sz)/sizeof(sz[0])),
strides(st, sizeof(st)/sizeof(st[0])))]);
assert(v.size() == 24);
assert(v[ 0] == 3);
assert(v[ 1] == 4);
assert(v[ 2] == 5);
assert(v[ 3] == 7);
assert(v[ 4] == 8);
assert(v[ 5] == 9);
assert(v[ 6] == 11);
assert(v[ 7] == 12);
assert(v[ 8] == 13);
assert(v[ 9] == 15);
assert(v[10] == 16);
assert(v[11] == 17);
assert(v[12] == 22);
assert(v[13] == 23);
assert(v[14] == 24);
assert(v[15] == 26);
assert(v[16] == 27);
assert(v[17] == 28);
assert(v[18] == 30);
assert(v[19] == 31);
assert(v[20] == 32);
assert(v[21] == 34);
assert(v[22] == 35);
assert(v[23] == 36);
return 0;
}
@@ -0,0 +1,60 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// <valarray>
// template<class T> class valarray;
// valarray(const indirect_array<value_type>& ia);
#include <valarray>
#include <cassert>
#include "test_macros.h"
int main(int, char**)
{
int a[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35,
36, 37, 38, 39, 40};
const std::size_t N1 = sizeof(a)/sizeof(a[0]);
std::size_t s[] = { 3, 4, 5, 7, 8, 9, 11, 12, 13, 15, 16, 17,
22, 23, 24, 26, 27, 28, 30, 31, 32, 34, 35, 36};
const std::size_t S = sizeof(s)/sizeof(s[0]);
std::valarray<int> v1(a, N1);
std::valarray<std::size_t> ia(s, S);
std::valarray<int> v(v1[ia]);
assert(v.size() == 24);
assert(v[ 0] == 3);
assert(v[ 1] == 4);
assert(v[ 2] == 5);
assert(v[ 3] == 7);
assert(v[ 4] == 8);
assert(v[ 5] == 9);
assert(v[ 6] == 11);
assert(v[ 7] == 12);
assert(v[ 8] == 13);
assert(v[ 9] == 15);
assert(v[10] == 16);
assert(v[11] == 17);
assert(v[12] == 22);
assert(v[13] == 23);
assert(v[14] == 24);
assert(v[15] == 26);
assert(v[16] == 27);
assert(v[17] == 28);
assert(v[18] == 30);
assert(v[19] == 31);
assert(v[20] == 32);
assert(v[21] == 34);
assert(v[22] == 35);
assert(v[23] == 36);
return 0;
}
@@ -0,0 +1,44 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03
// <valarray>
// template<class T> class valarray;
// valarray(initializer_list<value_type>);
#include <valarray>
#include <cassert>
#include "test_macros.h"
int main(int, char**)
{
{
typedef int T;
T a[] = {1, 2, 3, 4, 5};
const unsigned N = sizeof(a)/sizeof(a[0]);
std::valarray<T> v = {1, 2, 3, 4, 5};
assert(v.size() == N);
for (unsigned i = 0; i < N; ++i)
assert(v[i] == a[i]);
}
{
typedef double T;
T a[] = {1, 2, 3, 4, 5};
const unsigned N = sizeof(a)/sizeof(a[0]);
std::valarray<T> v = {1, 2, 3, 4, 5};
assert(v.size() == N);
for (unsigned i = 0; i < N; ++i)
assert(v[i] == a[i]);
}
return 0;
}
@@ -0,0 +1,37 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// <valarray>
// template<class T> class valarray;
// valarray(const mask_array<value_type>& ma);
#include <valarray>
#include <cassert>
#include "test_macros.h"
int main(int, char**)
{
int a1[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
const std::size_t N1 = sizeof(a1)/sizeof(a1[0]);
bool b[N1] = {true, false, false, true, true, false,
false, true, false, false, false, true};
std::valarray<int> v1(a1, N1);
std::valarray<bool> vb(b, N1);
std::valarray<int> v2(v1[vb]);
assert(v2.size() == 5);
assert(v2[ 0] == 0);
assert(v2[ 1] == 3);
assert(v2[ 2] == 4);
assert(v2[ 3] == 7);
assert(v2[ 4] == 11);
return 0;
}
@@ -0,0 +1,65 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03
// <valarray>
// template<class T> class valarray;
// valarray(const valarray<value_type>& v);
#include <valarray>
#include <utility>
#include <cassert>
#include <cstddef>
#include "test_macros.h"
int main(int, char**)
{
{
typedef int T;
T a[] = {1, 2, 3, 4, 5};
const unsigned N = sizeof(a)/sizeof(a[0]);
std::valarray<T> v(a, N);
std::valarray<T> v2 = std::move(v);
assert(v2.size() == N);
assert(v.size() == 0);
for (std::size_t i = 0; i < v2.size(); ++i)
assert(v2[i] == a[i]);
}
{
typedef double T;
T a[] = {1, 2.5, 3, 4.25, 5};
const unsigned N = sizeof(a)/sizeof(a[0]);
std::valarray<T> v(a, N);
std::valarray<T> v2 = std::move(v);
assert(v2.size() == N);
assert(v.size() == 0);
for (std::size_t i = 0; i < v2.size(); ++i)
assert(v2[i] == a[i]);
}
{
typedef std::valarray<double> T;
T a[] = {T(1), T(2), T(3), T(4), T(5)};
const unsigned N = sizeof(a)/sizeof(a[0]);
std::valarray<T> v(a, N);
std::valarray<T> v2 = std::move(v);
assert(v2.size() == N);
assert(v.size() == 0);
for (unsigned i = 0; i < N; ++i)
{
assert(v2[i].size() == a[i].size());
for (std::size_t j = 0; j < v2[i].size(); ++j)
assert(v2[i][j] == a[i][j]);
}
}
return 0;
}
@@ -0,0 +1,56 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// <valarray>
// template<class T> class valarray;
// valarray(const value_type* p, size_t n);
#include <valarray>
#include <cassert>
#include <cstddef>
#include "test_macros.h"
int main(int, char**)
{
{
typedef int T;
T a[] = {1, 2, 3, 4, 5};
const unsigned N = sizeof(a)/sizeof(a[0]);
std::valarray<T> v(a, N);
assert(v.size() == N);
for (unsigned i = 0; i < N; ++i)
assert(v[i] == a[i]);
}
{
typedef double T;
T a[] = {1, 2.5, 3, 4.25, 5};
const unsigned N = sizeof(a)/sizeof(a[0]);
std::valarray<T> v(a, N);
assert(v.size() == N);
for (unsigned i = 0; i < N; ++i)
assert(v[i] == a[i]);
}
{
typedef std::valarray<double> T;
T a[] = {T(1), T(2), T(3), T(4), T(5)};
const unsigned N = sizeof(a)/sizeof(a[0]);
std::valarray<T> v(a, N);
assert(v.size() == N);
for (unsigned i = 0; i < N; ++i)
{
assert(v[i].size() == a[i].size());
for (std::size_t j = 0; j < v[i].size(); ++j)
assert(v[i][j] == a[i][j]);
}
}
return 0;
}
@@ -0,0 +1,58 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// <valarray>
// template<class T> class valarray;
// explicit valarray(size_t);
#include <valarray>
#include <cassert>
#include "test_macros.h"
struct S {
S() : x(1) {}
~S() { ++cnt_dtor; }
int x;
static size_t cnt_dtor;
};
size_t S::cnt_dtor = 0;
int main(int, char**)
{
{
std::valarray<int> v(100);
assert(v.size() == 100);
for (int i = 0; i < 100; ++i)
assert(v[i] == 0);
}
{
std::valarray<double> v(100);
assert(v.size() == 100);
for (int i = 0; i < 100; ++i)
assert(v[i] == 0);
}
{
std::valarray<std::valarray<double> > v(100);
assert(v.size() == 100);
for (int i = 0; i < 100; ++i)
assert(v[i].size() == 0);
}
{
std::valarray<S> v(100);
assert(v.size() == 100);
for (int i = 0; i < 100; ++i)
assert(v[i].x == 1);
}
assert(S::cnt_dtor == 100);
return 0;
}
@@ -0,0 +1,33 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// <valarray>
// template<class T> class valarray;
// valarray(const slice_array<value_type>& sa);
#include <valarray>
#include <cassert>
#include "test_macros.h"
int main(int, char**)
{
int a[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
std::valarray<int> v1(a, sizeof(a)/sizeof(a[0]));
std::valarray<int> v(v1[std::slice(1, 5, 3)]);
assert(v.size() == 5);
assert(v[0] == 1);
assert(v[1] == 4);
assert(v[2] == 7);
assert(v[3] == 10);
assert(v[4] == 13);
return 0;
}
@@ -0,0 +1,42 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// <valarray>
// template<class T> class valarray;
// valarray(const value_type& x, size_t n);
#include <valarray>
#include <cassert>
#include "test_macros.h"
int main(int, char**)
{
{
std::valarray<int> v(5, 100);
assert(v.size() == 100);
for (int i = 0; i < 100; ++i)
assert(v[i] == 5);
}
{
std::valarray<double> v(2.5, 100);
assert(v.size() == 100);
for (int i = 0; i < 100; ++i)
assert(v[i] == 2.5);
}
{
std::valarray<std::valarray<double> > v(std::valarray<double>(10), 100);
assert(v.size() == 100);
for (int i = 0; i < 100; ++i)
assert(v[i].size() == 10);
}
return 0;
}
@@ -0,0 +1,54 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// <valarray>
// template<class T> class valarray;
// valarray apply(value_type f(const value_type&)) const;
#include <valarray>
#include <cassert>
#include "test_macros.h"
typedef int T;
T f(const T& t) {return t + 5;}
int main(int, char**)
{
{
T a1[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
T a2[] = {6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
const unsigned N1 = sizeof(a1)/sizeof(a1[0]);
std::valarray<T> v1(a1, N1);
std::valarray<T> v2 = v1.apply(f);
assert(v2.size() == N1);
for (unsigned i = 0; i < N1; ++i)
assert(v2[i] == a2[i]);
}
{
const unsigned N1 = 0;
std::valarray<T> v1;
std::valarray<T> v2 = v1.apply(f);
assert(v2.size() == N1);
}
{
T a1[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
T a2[] = {7, 9, 11, 13, 15, 17, 19, 21, 23, 25};
const unsigned N1 = sizeof(a1)/sizeof(a1[0]);
std::valarray<T> v1(a1, N1);
std::valarray<T> v2 = (v1+v1).apply(f);
assert(v2.size() == N1);
for (unsigned i = 0; i < N1; ++i)
assert(v2[i] == a2[i]);
}
return 0;
}
@@ -0,0 +1,54 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// <valarray>
// template<class T> class valarray;
// valarray apply(value_type f(value_type)) const;
#include <valarray>
#include <cassert>
#include "test_macros.h"
typedef int T;
T f(T t) {return t + 5;}
int main(int, char**)
{
{
T a1[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
T a2[] = {6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
const unsigned N1 = sizeof(a1)/sizeof(a1[0]);
std::valarray<T> v1(a1, N1);
std::valarray<T> v2 = v1.apply(f);
assert(v2.size() == N1);
for (unsigned i = 0; i < N1; ++i)
assert(v2[i] == a2[i]);
}
{
const unsigned N1 = 0;
std::valarray<T> v1;
std::valarray<T> v2 = v1.apply(f);
assert(v2.size() == N1);
}
{
T a1[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
T a2[] = {7, 9, 11, 13, 15, 17, 19, 21, 23, 25};
const unsigned N1 = sizeof(a1)/sizeof(a1[0]);
std::valarray<T> v1(a1, N1);
std::valarray<T> v2 = (v1+v1).apply(f);
assert(v2.size() == N1);
for (unsigned i = 0; i < N1; ++i)
assert(v2[i] == a2[i]);
}
return 0;
}
@@ -0,0 +1,130 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// <valarray>
// template<class T> class valarray;
// valarray cshift(int i) const;
#include <valarray>
#include <cassert>
#include "test_macros.h"
int main(int, char**)
{
{
typedef int T;
T a1[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
T a2[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
const unsigned N1 = sizeof(a1)/sizeof(a1[0]);
std::valarray<T> v1(a1, N1);
std::valarray<T> v2 = v1.cshift(0);
assert(v2.size() == N1);
for (unsigned i = 0; i < N1; ++i)
assert(v2[i] == a2[i]);
}
{
typedef int T;
T a1[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
T a2[] = {4, 5, 6, 7, 8, 9, 10, 1, 2, 3};
const unsigned N1 = sizeof(a1)/sizeof(a1[0]);
std::valarray<T> v1(a1, N1);
std::valarray<T> v2 = v1.cshift(3);
assert(v2.size() == N1);
for (unsigned i = 0; i < N1; ++i)
assert(v2[i] == a2[i]);
}
{
typedef int T;
T a1[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
T a2[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
const unsigned N1 = sizeof(a1)/sizeof(a1[0]);
std::valarray<T> v1(a1, N1);
std::valarray<T> v2 = v1.cshift(10);
assert(v2.size() == N1);
for (unsigned i = 0; i < N1; ++i)
assert(v2[i] == a2[i]);
}
{
typedef int T;
T a1[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
T a2[] = {8, 9, 10, 1, 2, 3, 4, 5, 6, 7};
const unsigned N1 = sizeof(a1)/sizeof(a1[0]);
std::valarray<T> v1(a1, N1);
std::valarray<T> v2 = v1.cshift(17);
assert(v2.size() == N1);
for (unsigned i = 0; i < N1; ++i)
assert(v2[i] == a2[i]);
}
{
typedef int T;
T a1[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
T a2[] = {8, 9, 10, 1, 2, 3, 4, 5, 6, 7};
const unsigned N1 = sizeof(a1)/sizeof(a1[0]);
std::valarray<T> v1(a1, N1);
std::valarray<T> v2 = v1.cshift(-3);
assert(v2.size() == N1);
for (unsigned i = 0; i < N1; ++i)
assert(v2[i] == a2[i]);
}
{
typedef int T;
T a1[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
T a2[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
const unsigned N1 = sizeof(a1)/sizeof(a1[0]);
std::valarray<T> v1(a1, N1);
std::valarray<T> v2 = v1.cshift(-10);
assert(v2.size() == N1);
for (unsigned i = 0; i < N1; ++i)
assert(v2[i] == a2[i]);
}
{
typedef int T;
T a1[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
T a2[] = {4, 5, 6, 7, 8, 9, 10, 1, 2, 3};
const unsigned N1 = sizeof(a1)/sizeof(a1[0]);
std::valarray<T> v1(a1, N1);
std::valarray<T> v2 = v1.cshift(-17);
assert(v2.size() == N1);
for (unsigned i = 0; i < N1; ++i)
assert(v2[i] == a2[i]);
}
{
typedef int T;
const unsigned N1 = 0;
std::valarray<T> v1;
std::valarray<T> v2 = v1.cshift(-17);
assert(v2.size() == N1);
}
{
typedef int T;
T a1[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
T a2[] = {8, 10, 12, 14, 16, 18, 20, 2, 4, 6};
const unsigned N1 = sizeof(a1)/sizeof(a1[0]);
std::valarray<T> v1(a1, N1);
std::valarray<T> v2 = (v1 + v1).cshift(3);
assert(v2.size() == N1);
for (unsigned i = 0; i < N1; ++i)
assert(v2[i] == a2[i]);
}
{
typedef int T;
T a1[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
T a2[] = {16, 18, 20, 2, 4, 6, 8, 10, 12, 14};
const unsigned N1 = sizeof(a1)/sizeof(a1[0]);
std::valarray<T> v1(a1, N1);
std::valarray<T> v2 = (v1 + v1).cshift(-3);
assert(v2.size() == N1);
for (unsigned i = 0; i < N1; ++i)
assert(v2[i] == a2[i]);
}
return 0;
}
@@ -0,0 +1,38 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// <valarray>
// template<class T> class valarray;
// value_type max() const;
#include <valarray>
#include <cassert>
#include "test_macros.h"
int main(int, char**)
{
{
typedef double T;
T a1[] = {1.5, 2.5, -3, 4, -5.5};
const unsigned N1 = sizeof(a1)/sizeof(a1[0]);
std::valarray<T> v1(a1, N1);
assert(v1.max() == 4.0);
}
{
typedef double T;
T a1[] = {1.5, 2.5, -3, 4, -5.5};
const unsigned N1 = sizeof(a1)/sizeof(a1[0]);
std::valarray<T> v1(a1, N1);
assert((2*v1).max() == 8.0);
}
return 0;
}
@@ -0,0 +1,38 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// <valarray>
// template<class T> class valarray;
// value_type min() const;
#include <valarray>
#include <cassert>
#include "test_macros.h"
int main(int, char**)
{
{
typedef double T;
T a1[] = {1.5, 2.5, -3, 4, 5.5};
const unsigned N1 = sizeof(a1)/sizeof(a1[0]);
std::valarray<T> v1(a1, N1);
assert(v1.min() == -3.0);
}
{
typedef double T;
T a1[] = {1.5, 2.5, -3, 4, 5.5};
const unsigned N1 = sizeof(a1)/sizeof(a1[0]);
std::valarray<T> v1(a1, N1);
assert((2*v1).min() == -6.0);
}
return 0;
}
@@ -0,0 +1,45 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// <valarray>
// template<class T> class valarray;
// void resize(size_t n, value_type x = value_type());
#include <valarray>
#include <cassert>
#include <cstddef>
#include "test_macros.h"
int main(int, char**)
{
{
typedef int T;
T a1[] = {1, 2, 3, 4, 5};
const unsigned N1 = sizeof(a1)/sizeof(a1[0]);
std::valarray<T> v1(a1, N1);
v1.resize(8);
assert(v1.size() == 8);
for (std::size_t i = 0; i < v1.size(); ++i)
assert(v1[i] == 0);
v1.resize(0);
assert(v1.size() == 0);
v1.resize(80);
assert(v1.size() == 80);
for (std::size_t i = 0; i < v1.size(); ++i)
assert(v1[i] == 0);
v1.resize(40);
assert(v1.size() == 40);
for (std::size_t i = 0; i < v1.size(); ++i)
assert(v1[i] == 0);
}
return 0;
}
@@ -0,0 +1,130 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// <valarray>
// template<class T> class valarray;
// valarray shift(int i) const;
#include <valarray>
#include <cassert>
#include "test_macros.h"
int main(int, char**)
{
{
typedef int T;
T a1[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
T a2[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
const unsigned N1 = sizeof(a1)/sizeof(a1[0]);
std::valarray<T> v1(a1, N1);
std::valarray<T> v2 = v1.shift(0);
assert(v2.size() == N1);
for (unsigned i = 0; i < N1; ++i)
assert(v2[i] == a2[i]);
}
{
typedef int T;
T a1[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
T a2[] = {2, 3, 4, 5, 6, 7, 8, 9, 10, 0};
const unsigned N1 = sizeof(a1)/sizeof(a1[0]);
std::valarray<T> v1(a1, N1);
std::valarray<T> v2 = v1.shift(1);
assert(v2.size() == N1);
for (unsigned i = 0; i < N1; ++i)
assert(v2[i] == a2[i]);
}
{
typedef int T;
T a1[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
T a2[] = {10, 0, 0, 0, 0, 0, 0, 0, 0, 0};
const unsigned N1 = sizeof(a1)/sizeof(a1[0]);
std::valarray<T> v1(a1, N1);
std::valarray<T> v2 = v1.shift(9);
assert(v2.size() == N1);
for (unsigned i = 0; i < N1; ++i)
assert(v2[i] == a2[i]);
}
{
typedef int T;
T a1[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
T a2[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
const unsigned N1 = sizeof(a1)/sizeof(a1[0]);
std::valarray<T> v1(a1, N1);
std::valarray<T> v2 = v1.shift(90);
assert(v2.size() == N1);
for (unsigned i = 0; i < N1; ++i)
assert(v2[i] == a2[i]);
}
{
typedef int T;
T a1[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
T a2[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
const unsigned N1 = sizeof(a1)/sizeof(a1[0]);
std::valarray<T> v1(a1, N1);
std::valarray<T> v2 = v1.shift(-1);
assert(v2.size() == N1);
for (unsigned i = 0; i < N1; ++i)
assert(v2[i] == a2[i]);
}
{
typedef int T;
T a1[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
T a2[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 1};
const unsigned N1 = sizeof(a1)/sizeof(a1[0]);
std::valarray<T> v1(a1, N1);
std::valarray<T> v2 = v1.shift(-9);
assert(v2.size() == N1);
for (unsigned i = 0; i < N1; ++i)
assert(v2[i] == a2[i]);
}
{
typedef int T;
T a1[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
T a2[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
const unsigned N1 = sizeof(a1)/sizeof(a1[0]);
std::valarray<T> v1(a1, N1);
std::valarray<T> v2 = v1.shift(-90);
assert(v2.size() == N1);
for (unsigned i = 0; i < N1; ++i)
assert(v2[i] == a2[i]);
}
{
typedef int T;
const unsigned N1 = 0;
std::valarray<T> v1;
std::valarray<T> v2 = v1.shift(-90);
assert(v2.size() == N1);
}
{
typedef int T;
T a1[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
T a2[] = {8, 10, 12, 14, 16, 18, 20, 0, 0, 0};
const unsigned N1 = sizeof(a1)/sizeof(a1[0]);
std::valarray<T> v1(a1, N1);
std::valarray<T> v2 = (v1 + v1).shift(3);
assert(v2.size() == N1);
for (unsigned i = 0; i < N1; ++i)
assert(v2[i] == a2[i]);
}
{
typedef int T;
T a1[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
T a2[] = {0, 0, 0, 2, 4, 6, 8, 10, 12, 14};
const unsigned N1 = sizeof(a1)/sizeof(a1[0]);
std::valarray<T> v1(a1, N1);
std::valarray<T> v2 = (v1 + v1).shift(-3);
assert(v2.size() == N1);
for (unsigned i = 0; i < N1; ++i)
assert(v2[i] == a2[i]);
}
return 0;
}
@@ -0,0 +1,44 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// <valarray>
// template<class T> class valarray;
// size_t size() const;
#include <valarray>
#include <cassert>
#include "test_macros.h"
int main(int, char**)
{
{
typedef int T;
T a1[] = {1, 2, 3, 4, 5};
const unsigned N1 = sizeof(a1)/sizeof(a1[0]);
std::valarray<T> v1(a1, N1);
assert(v1.size() == N1);
}
{
typedef int T;
T a1[] = {1, 2, 3, 4, 5};
const unsigned N1 = 0;
std::valarray<T> v1(a1, N1);
assert(v1.size() == N1);
}
{
typedef int T;
const unsigned N1 = 0;
std::valarray<T> v1;
assert(v1.size() == N1);
}
return 0;
}
@@ -0,0 +1,31 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// <valarray>
// template<class T> class valarray;
// value_type sum() const;
#include <valarray>
#include <cassert>
#include "test_macros.h"
int main(int, char**)
{
{
typedef double T;
T a1[] = {1.5, 2.5, 3, 4, 5.5};
const unsigned N1 = sizeof(a1)/sizeof(a1[0]);
std::valarray<T> v1(a1, N1);
assert(v1.sum() == 16.5);
}
return 0;
}
@@ -0,0 +1,89 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// <valarray>
// template<class T> class valarray;
// void swap(valarray& v);
#include <valarray>
#include <cassert>
#include <cstddef>
#include "test_macros.h"
int main(int, char**)
{
{
typedef int T;
T a1[] = {1, 2, 3, 4, 5};
T a2[] = {6, 7, 8, 9, 10, 11, 12};
const unsigned N1 = sizeof(a1)/sizeof(a1[0]);
const unsigned N2 = sizeof(a2)/sizeof(a2[0]);
std::valarray<T> v1(a1, N1);
std::valarray<T> v2(a2, N2);
std::valarray<T> v1_save = v1;
std::valarray<T> v2_save = v2;
v1.swap(v2);
assert(v1.size() == v2_save.size());
for (std::size_t i = 0; i < v1.size(); ++i)
assert(v1[i] == v2_save[i]);
assert(v2.size() == v1_save.size());
for (std::size_t i = 0; i < v2.size(); ++i)
assert(v2[i] == v1_save[i]);
}
{
typedef int T;
T a1[] = {1, 2, 3, 4, 5};
const unsigned N1 = sizeof(a1)/sizeof(a1[0]);
std::valarray<T> v1(a1, N1);
std::valarray<T> v2;
std::valarray<T> v1_save = v1;
std::valarray<T> v2_save = v2;
v1.swap(v2);
assert(v1.size() == v2_save.size());
for (std::size_t i = 0; i < v1.size(); ++i)
assert(v1[i] == v2_save[i]);
assert(v2.size() == v1_save.size());
for (std::size_t i = 0; i < v2.size(); ++i)
assert(v2[i] == v1_save[i]);
}
{
typedef int T;
T a2[] = {6, 7, 8, 9, 10, 11, 12};
const unsigned N2 = sizeof(a2)/sizeof(a2[0]);
std::valarray<T> v1;
std::valarray<T> v2(a2, N2);
std::valarray<T> v1_save = v1;
std::valarray<T> v2_save = v2;
v1.swap(v2);
assert(v1.size() == v2_save.size());
for (std::size_t i = 0; i < v1.size(); ++i)
assert(v1[i] == v2_save[i]);
assert(v2.size() == v1_save.size());
for (std::size_t i = 0; i < v2.size(); ++i)
assert(v2[i] == v1_save[i]);
}
{
typedef int T;
std::valarray<T> v1;
std::valarray<T> v2;
std::valarray<T> v1_save = v1;
std::valarray<T> v2_save = v2;
v1.swap(v2);
assert(v1.size() == v2_save.size());
for (std::size_t i = 0; i < v1.size(); ++i)
assert(v1[i] == v2_save[i]);
assert(v2.size() == v1_save.size());
for (std::size_t i = 0; i < v2.size(); ++i)
assert(v2[i] == v1_save[i]);
}
return 0;
}
@@ -0,0 +1,82 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// <valarray>
// template<class T> class valarray;
// gslice_array<value_type> operator[](const gslice& gs);
#include <valarray>
#include <cassert>
#include "test_macros.h"
int main(int, char**)
{
{
int a1[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35,
36, 37, 38, 39, 40};
int a2[] = { -0, -1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -11,
-12, -13, -14, -15, -16, -17, -18, -19, -20, -21, -22, -23};
std::valarray<int> v1(a1, sizeof(a1)/sizeof(a1[0]));
std::valarray<int> v2(a2, sizeof(a2)/sizeof(a2[0]));
std::size_t sz[] = {2, 4, 3};
std::size_t st[] = {19, 4, 1};
typedef std::valarray<std::size_t> sizes;
typedef std::valarray<std::size_t> strides;
v1[std::gslice(3, sizes(sz, sizeof(sz)/sizeof(sz[0])),
strides(st, sizeof(st)/sizeof(st[0])))] = v2;
assert(v1.size() == 41);
assert(v1[ 0] == 0);
assert(v1[ 1] == 1);
assert(v1[ 2] == 2);
assert(v1[ 3] == 0);
assert(v1[ 4] == -1);
assert(v1[ 5] == -2);
assert(v1[ 6] == 6);
assert(v1[ 7] == -3);
assert(v1[ 8] == -4);
assert(v1[ 9] == -5);
assert(v1[10] == 10);
assert(v1[11] == -6);
assert(v1[12] == -7);
assert(v1[13] == -8);
assert(v1[14] == 14);
assert(v1[15] == -9);
assert(v1[16] == -10);
assert(v1[17] == -11);
assert(v1[18] == 18);
assert(v1[19] == 19);
assert(v1[20] == 20);
assert(v1[21] == 21);
assert(v1[22] == -12);
assert(v1[23] == -13);
assert(v1[24] == -14);
assert(v1[25] == 25);
assert(v1[26] == -15);
assert(v1[27] == -16);
assert(v1[28] == -17);
assert(v1[29] == 29);
assert(v1[30] == -18);
assert(v1[31] == -19);
assert(v1[32] == -20);
assert(v1[33] == 33);
assert(v1[34] == -21);
assert(v1[35] == -22);
assert(v1[36] == -23);
assert(v1[37] == 37);
assert(v1[38] == 38);
assert(v1[39] == 39);
assert(v1[40] == 40);
}
return 0;
}
@@ -0,0 +1,99 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// <valarray>
// template<class T> class valarray;
// valarray operator[](const gslice& gs) const;
#include <valarray>
#include <cassert>
#include "test_macros.h"
int main(int, char**)
{
{
int a[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35,
36, 37, 38, 39, 40};
std::valarray<int> v1(a, sizeof(a)/sizeof(a[0]));
std::size_t sz[] = {2, 4, 3};
std::size_t st[] = {19, 4, 1};
typedef std::valarray<std::size_t> sizes;
typedef std::valarray<std::size_t> strides;
std::valarray<int> v(v1[std::gslice(3, sizes(sz, sizeof(sz)/sizeof(sz[0])),
strides(st, sizeof(st)/sizeof(st[0])))]);
assert(v.size() == 24);
assert(v[ 0] == 3);
assert(v[ 1] == 4);
assert(v[ 2] == 5);
assert(v[ 3] == 7);
assert(v[ 4] == 8);
assert(v[ 5] == 9);
assert(v[ 6] == 11);
assert(v[ 7] == 12);
assert(v[ 8] == 13);
assert(v[ 9] == 15);
assert(v[10] == 16);
assert(v[11] == 17);
assert(v[12] == 22);
assert(v[13] == 23);
assert(v[14] == 24);
assert(v[15] == 26);
assert(v[16] == 27);
assert(v[17] == 28);
assert(v[18] == 30);
assert(v[19] == 31);
assert(v[20] == 32);
assert(v[21] == 34);
assert(v[22] == 35);
assert(v[23] == 36);
}
{
int a[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35,
36, 37, 38, 39, 40};
std::valarray<int> v1(a, sizeof(a)/sizeof(a[0]));
std::size_t sz[] = {2, 4, 3};
std::size_t st[] = {19, 4, 1};
typedef std::valarray<std::size_t> sizes;
typedef std::valarray<std::size_t> strides;
std::valarray<int> v((v1 + 0)[std::gslice(3, sizes(sz, sizeof(sz)/sizeof(sz[0])),
strides(st, sizeof(st)/sizeof(st[0])))]);
assert(v.size() == 24);
assert(v[ 0] == 3);
assert(v[ 1] == 4);
assert(v[ 2] == 5);
assert(v[ 3] == 7);
assert(v[ 4] == 8);
assert(v[ 5] == 9);
assert(v[ 6] == 11);
assert(v[ 7] == 12);
assert(v[ 8] == 13);
assert(v[ 9] == 15);
assert(v[10] == 16);
assert(v[11] == 17);
assert(v[12] == 22);
assert(v[13] == 23);
assert(v[14] == 24);
assert(v[15] == 26);
assert(v[16] == 27);
assert(v[17] == 28);
assert(v[18] == 30);
assert(v[19] == 31);
assert(v[20] == 32);
assert(v[21] == 34);
assert(v[22] == 35);
assert(v[23] == 36);
}
return 0;
}
@@ -0,0 +1,74 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// <valarray>
// template<class T> class valarray;
// valarray operator[](const valarray<size_t>& vs) const;
#include <valarray>
#include <cassert>
#include "test_macros.h"
int main(int, char**)
{
{
int a[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35,
36, 37, 38, 39, 40};
const std::size_t N1 = sizeof(a)/sizeof(a[0]);
std::size_t s[] = { 3, 4, 5, 7, 8, 9, 11, 12, 13, 15, 16, 17,
22, 23, 24, 26, 27, 28, 30, 31, 32, 34, 35, 36};
const std::size_t S = sizeof(s)/sizeof(s[0]);
const std::valarray<int> v1(a, N1);
std::valarray<std::size_t> ia(s, S);
std::valarray<int> v = v1[ia];
assert(v.size() == 24);
assert(v[ 0] == 3);
assert(v[ 1] == 4);
assert(v[ 2] == 5);
assert(v[ 3] == 7);
assert(v[ 4] == 8);
assert(v[ 5] == 9);
assert(v[ 6] == 11);
assert(v[ 7] == 12);
assert(v[ 8] == 13);
assert(v[ 9] == 15);
assert(v[10] == 16);
assert(v[11] == 17);
assert(v[12] == 22);
assert(v[13] == 23);
assert(v[14] == 24);
assert(v[15] == 26);
assert(v[16] == 27);
assert(v[17] == 28);
assert(v[18] == 30);
assert(v[19] == 31);
assert(v[20] == 32);
assert(v[21] == 34);
assert(v[22] == 35);
assert(v[23] == 36);
}
{
int raw_data[] = {0,1,2,3,4,5,6,7,8,9};
std::size_t idx_data[] = {0,2,4,6,8};
const std::valarray<int> data(raw_data, sizeof(raw_data)/sizeof(raw_data[0]));
std::valarray<std::size_t> idx(idx_data, sizeof(idx_data)/sizeof(idx_data[0]));
std::valarray<int> result = (data + 0)[idx];
assert(result.size() == 5);
assert(result[0] == data[idx[0]]);
assert(result[1] == data[idx[1]]);
assert(result[2] == data[idx[2]]);
assert(result[3] == data[idx[3]]);
assert(result[4] == data[idx[4]]);
}
return 0;
}
@@ -0,0 +1,75 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// <valarray>
// template<class T> class valarray;
// indirect_array<value_type> operator[](const valarray<size_t>& vs);
#include <valarray>
#include <cassert>
#include "test_macros.h"
int main(int, char**)
{
{
int a[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35,
36, 37, 38, 39, 40};
const std::size_t N1 = sizeof(a)/sizeof(a[0]);
std::size_t s[] = { 3, 4, 5, 7, 8, 9, 11, 12, 13, 15, 16, 17,
22, 23, 24, 26, 27, 28, 30, 31, 32, 34, 35, 36};
const std::size_t S = sizeof(s)/sizeof(s[0]);
std::valarray<int> v1(a, N1);
std::valarray<std::size_t> ia(s, S);
std::valarray<int> v(24);
v = v1[ia];
assert(v.size() == 24);
assert(v[ 0] == 3);
assert(v[ 1] == 4);
assert(v[ 2] == 5);
assert(v[ 3] == 7);
assert(v[ 4] == 8);
assert(v[ 5] == 9);
assert(v[ 6] == 11);
assert(v[ 7] == 12);
assert(v[ 8] == 13);
assert(v[ 9] == 15);
assert(v[10] == 16);
assert(v[11] == 17);
assert(v[12] == 22);
assert(v[13] == 23);
assert(v[14] == 24);
assert(v[15] == 26);
assert(v[16] == 27);
assert(v[17] == 28);
assert(v[18] == 30);
assert(v[19] == 31);
assert(v[20] == 32);
assert(v[21] == 34);
assert(v[22] == 35);
assert(v[23] == 36);
}
{
int raw_data[] = {0,1,2,3,4,5,6,7,8,9};
std::size_t idx_data[] = {0,2,4,6,8};
std::valarray<int> data(raw_data, sizeof(raw_data)/sizeof(raw_data[0]));
std::valarray<std::size_t> idx(idx_data, sizeof(idx_data)/sizeof(idx_data[0]));
std::valarray<int> result = (data + 0)[idx];
assert(result.size() == 5);
assert(result[0] == data[idx[0]]);
assert(result[1] == data[idx[1]]);
assert(result[2] == data[idx[2]]);
assert(result[3] == data[idx[3]]);
assert(result[4] == data[idx[4]]);
}
return 0;
}
@@ -0,0 +1,42 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// <valarray>
// template<class T> class valarray;
// valarray operator[](slice s) const;
#include <valarray>
#include <cassert>
#include "test_macros.h"
int main(int, char**)
{
{
int a1[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
const std::valarray<int> v1(a1, sizeof(a1)/sizeof(a1[0]));
std::valarray<int> v2 = v1[std::slice(1, 5, 3)];
assert(v2.size() == 5);
assert(v2[0] == 1);
assert(v2[1] == 4);
assert(v2[2] == 7);
assert(v2[3] == 10);
assert(v2[4] == 13);
}
{
int a1[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
const std::valarray<int> v1(a1, sizeof(a1)/sizeof(a1[0]));
std::valarray<int> v2 = (v1 + 0)[std::slice(0, 2, 3)];
assert(v2.size() == 2);
assert(v2[0] == 0);
assert(v2[1] == 3);
}
return 0;
}
@@ -0,0 +1,56 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// <valarray>
// template<class T> class valarray;
// slice_array<value_type> operator[](slice s);
#include <valarray>
#include <cassert>
#include "test_macros.h"
int main(int, char**)
{
{
int a1[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
int a2[] = {-1, -2, -3, -4, -5};
std::valarray<int> v1(a1, sizeof(a1)/sizeof(a1[0]));
std::valarray<int> v2(a2, sizeof(a2)/sizeof(a2[0]));
v1[std::slice(1, 5, 3)] = v2;
assert(v1.size() == 16);
assert(v1[ 0] == 0);
assert(v1[ 1] == -1);
assert(v1[ 2] == 2);
assert(v1[ 3] == 3);
assert(v1[ 4] == -2);
assert(v1[ 5] == 5);
assert(v1[ 6] == 6);
assert(v1[ 7] == -3);
assert(v1[ 8] == 8);
assert(v1[ 9] == 9);
assert(v1[10] == -4);
assert(v1[11] == 11);
assert(v1[12] == 12);
assert(v1[13] == -5);
assert(v1[14] == 14);
assert(v1[15] == 15);
}
{
int a1[] = {0, 1, 2, 3, 4, 5};
std::valarray<int> v1(a1, sizeof(a1)/sizeof(a1[0]));
std::valarray<int> v2((v1 + 0)[std::slice(0, 3, 2)]);
assert(v2.size() == 3);
assert(v2[0] == 0);
assert(v2[1] == 2);
assert(v2[2] == 4);
}
return 0;
}
@@ -0,0 +1,54 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// <valarray>
// template<class T> class valarray;
// valarray operator[](const valarray<bool>& vb) const;
#include <valarray>
#include <cassert>
#include "test_macros.h"
int main(int, char**)
{
{
int a1[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
const std::size_t N1 = sizeof(a1)/sizeof(a1[0]);
bool b[N1] = {true, false, false, true, true, false,
false, true, false, false, false, true};
std::valarray<int> v1(a1, N1);
std::valarray<bool> vb(b, N1);
std::valarray<int> v2(v1[vb]);
assert(v2.size() == 5);
assert(v2[ 0] == 0);
assert(v2[ 1] == 3);
assert(v2[ 2] == 4);
assert(v2[ 3] == 7);
assert(v2[ 4] == 11);
}
{
int a1[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
const std::size_t N1 = sizeof(a1)/sizeof(a1[0]);
bool b[N1] = {true, false, false, true, true, false,
false, true, false, false, false, true};
std::valarray<int> v1(a1, N1);
std::valarray<bool> vb(b, N1);
std::valarray<int> v2((v1 - 1)[vb]);
assert(v2.size() == 5);
assert(v2[ 0] == -1);
assert(v2[ 1] == 2);
assert(v2[ 2] == 3);
assert(v2[ 3] == 6);
assert(v2[ 4] == 10);
}
return 0;
}
@@ -0,0 +1,55 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// <valarray>
// template<class T> class valarray;
// mask_array<value_type> operator[](const valarray<bool>& vb);
#include <valarray>
#include <cassert>
#include "test_macros.h"
int main(int, char**)
{
{
int a1[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
const std::size_t N1 = sizeof(a1)/sizeof(a1[0]);
bool b[N1] = {true, false, false, true, true, false,
false, true, false, false, false, true};
std::valarray<int> v1(a1, N1);
std::valarray<bool> vb(b, N1);
std::valarray<int> v2(5);
v2 = v1[vb];
assert(v2.size() == 5);
assert(v2[ 0] == 0);
assert(v2[ 1] == 3);
assert(v2[ 2] == 4);
assert(v2[ 3] == 7);
assert(v2[ 4] == 11);
}
{
int a1[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
const std::size_t N1 = sizeof(a1)/sizeof(a1[0]);
bool b[N1] = {true, false, false, true, true, false,
false, true, false, false, false, true};
std::valarray<int> v1(a1, N1);
std::valarray<bool> vb(b, N1);
std::valarray<int> v2(5);
v2 = (v1 + 0)[vb];
assert(v2.size() == 5);
assert(v2[ 0] == 0);
assert(v2[ 1] == 3);
assert(v2[ 2] == 4);
assert(v2[ 3] == 7);
assert(v2[ 4] == 11);
}
return 0;
}
@@ -0,0 +1,68 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// <valarray>
// template<class T> class valarray;
// valarray operator~() const;
#include <valarray>
#include <cassert>
#include <cstddef>
#include "test_macros.h"
int main(int, char**)
{
{
typedef int T;
T a[] = {1, 2, 3, 4, 5};
const unsigned N = sizeof(a)/sizeof(a[0]);
std::valarray<T> v(a, N);
std::valarray<T> v2 = ~v;
assert(v2.size() == v.size());
for (std::size_t i = 0; i < v2.size(); ++i)
assert(v2[i] == ~v[i]);
}
{
typedef std::valarray<int> T;
T a[] = {T(1), T(2), T(3), T(4), T(5)};
const unsigned N = sizeof(a)/sizeof(a[0]);
std::valarray<T> v(a, N);
std::valarray<T> v2 = ~v;
assert(v2.size() == v.size());
for (unsigned i = 0; i < N; ++i)
{
assert(v2[i].size() == v[i].size());
for (std::size_t j = 0; j < v[i].size(); ++j)
assert(v2[i][j] == ~v[i][j]);
}
}
{
typedef int T;
T a[] = {1, 2, 3, 4, 5};
const unsigned N = sizeof(a)/sizeof(a[0]);
std::valarray<T> v(a, N);
std::valarray<T> v2 = ~(v + v);
assert(v2.size() == v.size());
for (std::size_t i = 0; i < v2.size(); ++i)
assert(v2[i] == ~(2*v[i]));
}
{
// Make sure we don't have dangling reference problems with unary expressions
int array[] = {1, 2, 3};
std::valarray<int> a(array, 3);
std::valarray<int> b(array, 3);
auto c = ~a + b;
assert(c.size() == 3);
assert(c[0] == (~1 + 1) && c[1] == (~2 + 2) && c[2] == (~3 + 3));
}
return 0;
}
@@ -0,0 +1,78 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// <valarray>
// template<class T> class valarray;
// valarray operator-() const;
#include <valarray>
#include <cassert>
#include <cstddef>
#include "test_macros.h"
int main(int, char**)
{
{
typedef int T;
T a[] = {1, 2, 3, 4, 5};
const unsigned N = sizeof(a)/sizeof(a[0]);
std::valarray<T> v(a, N);
std::valarray<T> v2 = -v;
assert(v2.size() == v.size());
for (std::size_t i = 0; i < v2.size(); ++i)
assert(v2[i] == -v[i]);
}
{
typedef double T;
T a[] = {1, 2.5, 3, 4.25, 5};
const unsigned N = sizeof(a)/sizeof(a[0]);
std::valarray<T> v(a, N);
std::valarray<T> v2 = -v;
assert(v2.size() == v.size());
for (std::size_t i = 0; i < v2.size(); ++i)
assert(v2[i] == -v[i]);
}
{
typedef std::valarray<double> T;
T a[] = {T(1), T(2), T(3), T(4), T(5)};
const unsigned N = sizeof(a)/sizeof(a[0]);
std::valarray<T> v(a, N);
std::valarray<T> v2 = -v;
assert(v2.size() == v.size());
for (unsigned i = 0; i < N; ++i)
{
assert(v2[i].size() == v[i].size());
for (std::size_t j = 0; j < v[i].size(); ++j)
assert(v2[i][j] == -v[i][j]);
}
}
{
typedef double T;
T a[] = {1, 2.5, 3, 4.25, 5};
const unsigned N = sizeof(a)/sizeof(a[0]);
std::valarray<T> v(a, N);
std::valarray<T> v2 = -(v + v);
assert(v2.size() == v.size());
for (std::size_t i = 0; i < v2.size(); ++i)
assert(v2[i] == -2*v[i]);
}
{
// Make sure we don't have dangling reference problems with unary expressions
int array[] = {1, 2, 3};
std::valarray<int> a(array, 3);
std::valarray<int> b(array, 3);
auto c = -a * b;
assert(c.size() == 3);
assert(c[0] == -1 && c[1] == -4 && c[2] == -9);
}
return 0;
}
@@ -0,0 +1,54 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// <valarray>
// template<class T> class valarray;
// valarray<bool> operator!() const;
#include <valarray>
#include <cassert>
#include <cstddef>
#include "test_macros.h"
int main(int, char**)
{
{
typedef int T;
T a[] = {1, 2, 3, 4, 5};
const unsigned N = sizeof(a)/sizeof(a[0]);
std::valarray<T> v(a, N);
std::valarray<bool> v2 = !v;
assert(v2.size() == v.size());
for (std::size_t i = 0; i < v2.size(); ++i)
assert(v2[i] == !v[i]);
}
{
typedef double T;
T a[] = {1, 2.5, 3, 4.25, 5};
const unsigned N = sizeof(a)/sizeof(a[0]);
std::valarray<T> v(a, N);
std::valarray<bool> v2 = !(v + v);
assert(v2.size() == v.size());
for (std::size_t i = 0; i < v2.size(); ++i)
assert(v2[i] == !(v[i] + v[i]));
}
{
// Make sure we don't have dangling reference problems with unary expressions
bool array[] = {true, false, true};
std::valarray<bool> a(array, 3);
std::valarray<bool> b(array, 3);
auto c = !a && b;
assert(c.size() == 3);
assert(c[0] == false && c[1] == false && c[2] == false);
}
return 0;
}
@@ -0,0 +1,78 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// <valarray>
// template<class T> class valarray;
// valarray operator+() const;
#include <valarray>
#include <cassert>
#include <cstddef>
#include "test_macros.h"
int main(int, char**)
{
{
typedef int T;
T a[] = {1, 2, 3, 4, 5};
const unsigned N = sizeof(a)/sizeof(a[0]);
std::valarray<T> v(a, N);
std::valarray<T> v2 = +v;
assert(v2.size() == v.size());
for (std::size_t i = 0; i < v2.size(); ++i)
assert(v2[i] == +v[i]);
}
{
typedef double T;
T a[] = {1, 2.5, 3, 4.25, 5};
const unsigned N = sizeof(a)/sizeof(a[0]);
std::valarray<T> v(a, N);
std::valarray<T> v2 = +v;
assert(v2.size() == v.size());
for (std::size_t i = 0; i < v2.size(); ++i)
assert(v2[i] == +v[i]);
}
{
typedef std::valarray<double> T;
T a[] = {T(1), T(2), T(3), T(4), T(5)};
const unsigned N = sizeof(a)/sizeof(a[0]);
std::valarray<T> v(a, N);
std::valarray<T> v2 = +v;
assert(v2.size() == v.size());
for (unsigned i = 0; i < N; ++i)
{
assert(v2[i].size() == v[i].size());
for (std::size_t j = 0; j < v[i].size(); ++j)
assert(v2[i][j] == +v[i][j]);
}
}
{
typedef double T;
T a[] = {1, 2.5, 3, 4.25, 5};
const unsigned N = sizeof(a)/sizeof(a[0]);
std::valarray<T> v(a, N);
std::valarray<T> v2 = +(v + v);
assert(v2.size() == v.size());
for (std::size_t i = 0; i < v2.size(); ++i)
assert(v2[i] == +2*v[i]);
}
{
// Make sure we don't have dangling reference problems with unary expressions
int array[] = {1, 2, 3};
std::valarray<int> a(array, 3);
std::valarray<int> b(array, 3);
auto c = +a * b;
assert(c.size() == 3);
assert(c[0] == 1 && c[1] == 4 && c[2] == 9);
}
return 0;
}