Home | History | Annotate | Download | only in valarray.cons
      1 //===----------------------------------------------------------------------===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is dual licensed under the MIT and the University of Illinois Open
      6 // Source Licenses. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 
     10 // <valarray>
     11 
     12 // template<class T> class valarray;
     13 
     14 // valarray(const valarray<value_type>& v);
     15 
     16 #include <valarray>
     17 #include <utility>
     18 #include <cassert>
     19 
     20 int main()
     21 {
     22 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
     23     {
     24         typedef int T;
     25         T a[] = {1, 2, 3, 4, 5};
     26         const unsigned N = sizeof(a)/sizeof(a[0]);
     27         std::valarray<T> v(a, N);
     28         std::valarray<T> v2 = std::move(v);
     29         assert(v2.size() == N);
     30         assert(v.size() == 0);
     31         for (int i = 0; i < v2.size(); ++i)
     32             assert(v2[i] == a[i]);
     33     }
     34     {
     35         typedef double T;
     36         T a[] = {1, 2.5, 3, 4.25, 5};
     37         const unsigned N = sizeof(a)/sizeof(a[0]);
     38         std::valarray<T> v(a, N);
     39         std::valarray<T> v2 = std::move(v);
     40         assert(v2.size() == N);
     41         assert(v.size() == 0);
     42         for (int i = 0; i < v2.size(); ++i)
     43             assert(v2[i] == a[i]);
     44     }
     45     {
     46         typedef std::valarray<double> T;
     47         T a[] = {T(1), T(2), T(3), T(4), T(5)};
     48         const unsigned N = sizeof(a)/sizeof(a[0]);
     49         std::valarray<T> v(a, N);
     50         std::valarray<T> v2 = std::move(v);
     51         assert(v2.size() == N);
     52         assert(v.size() == 0);
     53         for (int i = 0; i < N; ++i)
     54         {
     55             assert(v2[i].size() == a[i].size());
     56             for (int j = 0; j < v2[i].size(); ++j)
     57                 assert(v2[i][j] == a[i][j]);
     58         }
     59     }
     60 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
     61 }
     62