OSDN Git Service

2007-02-20 Benjamin Kosnik <bkoz@redhat.com>
[pf3gnuchains/gcc-fork.git] / libstdc++-v3 / testsuite / 26_numerics / numeric_arrays / valarray / subset_assignment.cc
1 // 2004-01-03  Jerry Quinn  <jlquinn@optonline.net>
2
3 // Copyright (C) 2004 Free Software Foundation, Inc.
4 //
5 // This file is part of the GNU ISO C++ Library.  This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 2, or (at your option)
9 // any later version.
10
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 // GNU General Public License for more details.
15
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING.  If not, write to the Free
18 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
19 // USA.
20
21 // As a special exception, you may use this file as part of a free software
22 // library without restriction.  Specifically, if other files instantiate
23 // templates or use macros or inline functions from this file, or you compile
24 // this file and link it with other files to produce an executable, this
25 // file does not by itself cause the resulting executable to be covered by
26 // the GNU General Public License.  This exception does not however
27 // invalidate any other reasons why the executable file might be covered by
28 // the GNU General Public License.
29
30 // PR 3247
31
32 // This is DR-253.  Test for accessible assignment-operators.
33 #include <valarray>
34 #include <testsuite_hooks.h>
35
36 bool check_array(std::valarray<double>& a, double b[])
37 {
38   for (unsigned int i=0; i < a.size(); i++)
39     if (a[i] != b[i]) return false;
40   return true;
41 }
42
43 int main()
44 {
45   std::valarray<double> val_d(10);  //  0 1 2 3 4 5 6 7 8 9 
46   std::valarray<double> val_d1(10); // 10 9 8 7 6 5 4 3 2 1
47
48   for (int i=0; i< 10; i++) { val_d[i] = 10;  val_d1[i] = i; }
49   std::valarray<double> val_c(val_d);
50   std::valarray<double> val_f(val_d);
51   std::valarray<double> val_g(val_d);
52
53   std::slice slc(1, 3, 3);      // 1 4 7
54   val_d[slc] = val_d1[slc];
55
56   double ans1[10] = {10, 1, 10, 10, 4, 10, 10, 7, 10, 10};
57   VERIFY(check_array(val_d, ans1));
58
59   std::valarray<std::size_t> val_size(2);
60   std::valarray<std::size_t> val_stride(2);
61   val_size[0] = 2;   val_size[1] = 3;
62   val_stride[0] = 4; val_stride[1] = 1;
63
64   std::gslice gslc(1, val_size, val_stride);
65   val_c[gslc] = val_d1[gslc];
66
67   double ans2[10] = {10, 1, 2, 3, 10, 5, 6, 7, 10, 10};
68   VERIFY(check_array(val_c, ans2));
69
70   std::valarray<bool> val_b(false, 10);
71   val_b[2] = val_b[6] = val_b[9] = true;
72   val_f[val_b] = val_d1[val_b];
73
74   double ans3[10] = {10, 10, 2, 10, 10, 10, 6, 10, 10, 9};
75   VERIFY(check_array(val_f, ans3));
76
77   size_t addr[] = {1, 2, 3, 4, 5};
78   size_t addr1[] = {2, 7, 1, 9, 4};
79   std::valarray<std::size_t> val_indirect(addr, 5);
80   std::valarray<std::size_t> val_indirect1(addr1, 5);
81   val_g[val_indirect] = val_d1[val_indirect1];
82
83   double ans4[10] = {10, 2, 7, 1, 9, 4, 10, 10, 10, 10};
84   VERIFY(check_array(val_g, ans4));
85
86   return 0;
87 };