brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.8 KiB · d8eeea8 Raw
68 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& operator=(valarray&& v);16 17#include <valarray>18#include <cassert>19#include <cstddef>20 21#include "test_macros.h"22 23int main(int, char**)24{25    {26        typedef int T;27        T a[] = {1, 2, 3, 4, 5};28        const unsigned N = sizeof(a)/sizeof(a[0]);29        std::valarray<T> v(a, N);30        std::valarray<T> v2;31        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;43        v2 = std::move(v);44        assert(v2.size() == N);45        assert(v.size() == 0);46        for (std::size_t i = 0; i < v2.size(); ++i)47            assert(v2[i] == a[i]);48    }49    {50        typedef std::valarray<double> T;51        T a[] = {T(1), T(2), T(3), T(4), T(5)};52        const unsigned N = sizeof(a)/sizeof(a[0]);53        std::valarray<T> v(a, N);54        std::valarray<T> v2(a, N-2);55        v2 = std::move(v);56        assert(v2.size() == N);57        assert(v.size() == 0);58        for (unsigned i = 0; i < N; ++i)59        {60            assert(v2[i].size() == a[i].size());61            for (std::size_t j = 0; j < a[i].size(); ++j)62                assert(v2[i][j] == a[i][j]);63        }64    }65 66  return 0;67}68