brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.8 KiB · 4c2101c Raw
66 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8 9// UNSUPPORTED: c++0310 11// <valarray>12 13// template<class T> class valarray;14 15// valarray(const valarray<value_type>& v);16 17#include <valarray>18#include <utility>19#include <cassert>20#include <cstddef>21 22#include "test_macros.h"23 24int main(int, char**)25{26    {27        typedef int T;28        T a[] = {1, 2, 3, 4, 5};29        const unsigned N = sizeof(a)/sizeof(a[0]);30        std::valarray<T> v(a, N);31        std::valarray<T> v2 = std::move(v);32        assert(v2.size() == N);33        assert(v.size() == 0);34        for (std::size_t i = 0; i < v2.size(); ++i)35            assert(v2[i] == a[i]);36    }37    {38        typedef double T;39        T a[] = {1, 2.5, 3, 4.25, 5};40        const unsigned N = sizeof(a)/sizeof(a[0]);41        std::valarray<T> v(a, N);42        std::valarray<T> v2 = std::move(v);43        assert(v2.size() == N);44        assert(v.size() == 0);45        for (std::size_t i = 0; i < v2.size(); ++i)46            assert(v2[i] == a[i]);47    }48    {49        typedef std::valarray<double> T;50        T a[] = {T(1), T(2), T(3), T(4), T(5)};51        const unsigned N = sizeof(a)/sizeof(a[0]);52        std::valarray<T> v(a, N);53        std::valarray<T> v2 = std::move(v);54        assert(v2.size() == N);55        assert(v.size() == 0);56        for (unsigned i = 0; i < N; ++i)57        {58            assert(v2[i].size() == a[i].size());59            for (std::size_t j = 0; j < v2[i].size(); ++j)60                assert(v2[i][j] == a[i][j]);61        }62    }63 64  return 0;65}66