blob: 3413bfa4a0f5d56b05baae78d63fe2827da17055 [file] [log] [blame]
//===----------------------------------------------------------------------===//
//
// 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;
}