Home | History | Annotate | Download | only in valarray.assign
      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& operator=(const valarray& v);
     15 
     16 #include <valarray>
     17 #include <cassert>
     18 
     19 int main()
     20 {
     21     {
     22         typedef int T;
     23         T a[] = {1, 2, 3, 4, 5};
     24         const unsigned N = sizeof(a)/sizeof(a[0]);
     25         std::valarray<T> v(a, N);
     26         std::valarray<T> v2;
     27         v2 = v;
     28         assert(v2.size() == v.size());
     29         for (int i = 0; i < v2.size(); ++i)
     30             assert(v2[i] == v[i]);
     31     }
     32     {
     33         typedef double T;
     34         T a[] = {1, 2.5, 3, 4.25, 5};
     35         const unsigned N = sizeof(a)/sizeof(a[0]);
     36         std::valarray<T> v(a, N);
     37         std::valarray<T> v2;
     38         v2 = v;
     39         assert(v2.size() == v.size());
     40         for (int i = 0; i < v2.size(); ++i)
     41             assert(v2[i] == v[i]);
     42     }
     43     {
     44         typedef std::valarray<double> T;
     45         T a[] = {T(1), T(2), T(3), T(4), T(5)};
     46         const unsigned N = sizeof(a)/sizeof(a[0]);
     47         std::valarray<T> v(a, N);
     48         std::valarray<T> v2(a, N-2);
     49         v2 = v;
     50         assert(v2.size() == v.size());
     51         for (int i = 0; i < N; ++i)
     52         {
     53             assert(v2[i].size() == v[i].size());
     54             for (int j = 0; j < v[i].size(); ++j)
     55                 assert(v2[i][j] == v[i][j]);
     56         }
     57     }
     58 }
     59