summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjlquinn <jlquinn@138bc75d-0d04-0410-961f-82ee72b054a4>2004-03-10 06:50:13 +0000
committerjlquinn <jlquinn@138bc75d-0d04-0410-961f-82ee72b054a4>2004-03-10 06:50:13 +0000
commita9ca39a06a57ccb6ba278bb32578401a64e75aa2 (patch)
tree8e2ff50b3353c86b0aa0ea231e442d679aae79bd
parentf8244ba2e6f01275ccc5614e33bae56deb807a0a (diff)
downloadgcc-a9ca39a06a57ccb6ba278bb32578401a64e75aa2.tar.gz
2004-03-10 Jerry Quinn <jlquinn@optonline.net>
PR 3247 * include/bits/gslice_array.h (gslice_array()): Make public. (operator=(gslice_array)): Make public. Implement. * include/bits/indirect_array.h (indirect_array()): Make public. * include/bits/mask_array.h (mask_array()): Make public. (operator=(mask_array)): Make public. Implement. * include/bits/valarray_array.tcc (__valarray_copy): Comment. Add versions for gslice_array and mask_array. * testsuite/26_numerics/valarray_subset_assignment.cc: New test. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@79226 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--libstdc++-v3/ChangeLog12
-rw-r--r--libstdc++-v3/include/bits/gslice.h2
-rw-r--r--libstdc++-v3/include/bits/gslice_array.h27
-rw-r--r--libstdc++-v3/include/bits/indirect_array.h5
-rw-r--r--libstdc++-v3/include/bits/mask_array.h25
-rw-r--r--libstdc++-v3/testsuite/26_numerics/valarray_subset_assignment.cc88
6 files changed, 142 insertions, 17 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index 4be32a5de2d..fa10cd9af4b 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -1,3 +1,15 @@
+2004-03-10 Jerry Quinn <jlquinn@optonline.net>
+
+ PR 3247
+ * include/bits/gslice_array.h (gslice_array()): Make public.
+ (operator=(gslice_array)): Make public. Implement.
+ * include/bits/indirect_array.h (indirect_array()): Make public.
+ * include/bits/mask_array.h (mask_array()): Make public.
+ (operator=(mask_array)): Make public. Implement.
+ * include/bits/valarray_array.tcc (__valarray_copy):
+ Comment. Add versions for gslice_array and mask_array.
+ * testsuite/26_numerics/valarray_subset_assignment.cc: New test.
+
2004-03-09 Benjamin Kosnik <bkoz@redhat.com>
* testsuite/23_containers/deque/modifiers/swap.cc: Add in bits for
diff --git a/libstdc++-v3/include/bits/gslice.h b/libstdc++-v3/include/bits/gslice.h
index ea8a9b4d430..78f8a67146b 100644
--- a/libstdc++-v3/include/bits/gslice.h
+++ b/libstdc++-v3/include/bits/gslice.h
@@ -106,7 +106,7 @@ namespace std {
size_t _M_start;
valarray<size_t> _M_size;
valarray<size_t> _M_stride;
- valarray<size_t> _M_index;
+ valarray<size_t> _M_index; // Linear array of referenced indices
_Indexer(size_t, const valarray<size_t>&,
const valarray<size_t>&);
void _M_increment_use() { ++_M_count; }
diff --git a/libstdc++-v3/include/bits/gslice_array.h b/libstdc++-v3/include/bits/gslice_array.h
index 292eaec37de..e50a74dc2bb 100644
--- a/libstdc++-v3/include/bits/gslice_array.h
+++ b/libstdc++-v3/include/bits/gslice_array.h
@@ -61,6 +61,15 @@ namespace std {
public:
typedef _Tp value_type;
+ // this constructor needs to be implemented.
+ /// Copy constructor. Both slices refer to the same underlying array.
+ gslice_array(const gslice_array&);
+
+ // This operator must be public. See DR-253.
+ /// Assignment operator. Assigns slice elements to corresponding
+ /// elements of @a a.
+ gslice_array& operator=(const gslice_array&);
+
/// Assign slice elements to corresponding elements of @a v.
void operator=(const valarray<_Tp>&) const;
/// Multiply slice elements by corresponding elements of @a v.
@@ -117,16 +126,8 @@ namespace std {
gslice_array(_Array<_Tp>, const valarray<size_t>&);
- // this constructor needs to be implemented.
- /// Copy constructor. Both slices refer to the same underlying array.
- gslice_array(const gslice_array&);
-
// not implemented
gslice_array();
-
- /// Assignment operator. Assigns slice elements to corresponding
- /// elements of @a a.
- gslice_array& operator= (const gslice_array&);
};
template<typename _Tp>
@@ -143,6 +144,16 @@ namespace std {
template<typename _Tp>
+ inline gslice_array<_Tp>&
+ gslice_array<_Tp>::operator=(const gslice_array<_Tp>& __a)
+ {
+ std::__valarray_copy(_Array<_Tp>(__a._M_array),
+ _Array<size_t>(__a._M_index), _M_index.size(),
+ _M_array, _Array<size_t>(_M_index));
+ return *this;
+ }
+
+ template<typename _Tp>
inline void
gslice_array<_Tp>::operator=(const _Tp& __t) const
{
diff --git a/libstdc++-v3/include/bits/indirect_array.h b/libstdc++-v3/include/bits/indirect_array.h
index 7f240a94c65..1f4a71377d4 100644
--- a/libstdc++-v3/include/bits/indirect_array.h
+++ b/libstdc++-v3/include/bits/indirect_array.h
@@ -63,6 +63,10 @@ namespace std
public:
typedef _Tp value_type;
+ // this constructor needs to be implemented.
+ /// Copy constructor. Both slices refer to the same underlying array.
+ indirect_array(const indirect_array&);
+
// XXX: This is a proposed resolution for DR-253.
/// Assignment operator. Assigns elements to corresponding elements
/// of @a a.
@@ -119,7 +123,6 @@ namespace std
private:
/// Copy constructor. Both slices refer to the same underlying array.
- indirect_array(const indirect_array&);
indirect_array(_Array<_Tp>, size_t, _Array<size_t>);
friend class valarray<_Tp>;
diff --git a/libstdc++-v3/include/bits/mask_array.h b/libstdc++-v3/include/bits/mask_array.h
index ce13c1a9920..4faa5d763bb 100644
--- a/libstdc++-v3/include/bits/mask_array.h
+++ b/libstdc++-v3/include/bits/mask_array.h
@@ -63,6 +63,15 @@ namespace std {
public:
typedef _Tp value_type;
+ // this constructor needs to be implemented.
+ /// Copy constructor. Both slices refer to the same underlying array.
+ mask_array (const mask_array&);
+
+ // This operator must be public. See DR-253.
+ /// Assignment operator. Assigns elements to corresponding elements
+ /// of @a a.
+ mask_array& operator=(const mask_array&);
+
void operator=(const valarray<_Tp>&) const;
/// Multiply slice elements by corresponding elements of @a v.
void operator*=(const valarray<_Tp>&) const;
@@ -120,15 +129,8 @@ namespace std {
const _Array<bool> _M_mask;
const _Array<_Tp> _M_array;
- /// Copy constructor. Both slices refer to the same underlying array.
- mask_array (const mask_array&);
-
// not implemented
mask_array();
-
- /// Assignment operator. Assigns elements to corresponding elements
- /// of @a a.
- mask_array& operator=(const mask_array&);
};
@@ -142,6 +144,15 @@ namespace std {
: _M_sz(__s), _M_mask(__m), _M_array(__a) {}
template<typename _Tp>
+ inline mask_array<_Tp>&
+ mask_array<_Tp>::operator=(const mask_array<_Tp>& __a)
+ {
+ std::__valarray_copy(__a._M_array, __a._M_mask,
+ _M_sz, _M_array, _M_mask);
+ return *this;
+ }
+
+ template<typename _Tp>
inline void
mask_array<_Tp>::operator=(const _Tp& __t) const
{ std::__valarray_fill(_M_array, _M_sz, _M_mask, __t); }
diff --git a/libstdc++-v3/testsuite/26_numerics/valarray_subset_assignment.cc b/libstdc++-v3/testsuite/26_numerics/valarray_subset_assignment.cc
new file mode 100644
index 00000000000..b8caaed889c
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/valarray_subset_assignment.cc
@@ -0,0 +1,88 @@
+// 2004-01-03 Jerry Quinn <jlquinn@optonline.net>
+
+// Copyright (C) 2004 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+// USA.
+
+// As a special exception, you may use this file as part of a free software
+// library without restriction. Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself cause the resulting executable to be covered by
+// the GNU General Public License. This exception does not however
+// invalidate any other reasons why the executable file might be covered by
+// the GNU General Public License.
+
+// PR 3247
+
+// This is DR-253. Test for accessible assignment-operators.
+#include <valarray>
+#include <testsuite_hooks.h>
+
+bool check_array(std::valarray<double>& a, double[] b)
+{
+ for (int i=0; i < a.size(); i++)
+ if (a[i] != b[i]) return false;
+ return true;
+}
+
+int main()
+{
+ double dvar = 1.0;
+ std::valarray<double> val_d(10); // 0 1 2 3 4 5 6 7 8 9
+ std::valarray<double> val_d1(10); // 10 9 8 7 6 5 4 3 2 1
+
+ for (int i=0; i< 10; i++) { val_d[i] = 10; val_d1[i] = i; }
+ std::valarray<double> val_c(val_d);
+ std::valarray<double> val_f(val_d);
+ std::valarray<double> val_g(val_d);
+
+ std::slice slc(1, 3, 3); // 1 4 7
+ val_d[slc] = val_d1[slc];
+
+ double ans1[10] = {10, 1, 10, 10, 4, 10, 10, 7, 10, 10};
+ VERIFY(check_array(val_d, ans1));
+
+ std::valarray<std::size_t> val_size(2);
+ std::valarray<std::size_t> val_stride(2);
+ val_size[0] = 2; val_size[1] = 3;
+ val_stride[0] = 4; val_stride[1] = 1;
+
+ std::gslice gslc(1, val_size, val_stride);
+ val_c[gslc] = val_d1[gslc];
+
+ double ans2[10] = {10, 1, 2, 3 10, 5, 6, 7, 10, 10};
+ VERIFY(check_array(val_c, ans2));
+
+ std::valarray<bool> val_b(false, 10);
+ val_b[2] = val_b[6] = val_b[9] = true;
+ val_f[val_b] = val_d1[val_b];
+
+ double ans3[10] = {10, 10, 2, 10, 10, 10, 6, 10, 10, 9};
+ VERIFY(check_array(val_f, ans3));
+
+ size_t addr[] = {1, 2, 3, 4, 5};
+ size_t addr1[] = {2, 7, 1, 9, 4};
+ std::valarray<std::size_t> val_indirect(addr, 5);
+ std::valarray<std::size_t> val_indirect1(addr1, 5);
+ val_g[val_indirect] = val_d1[val_indirect1];
+
+ double ans4[10] = {10, 2, 7, 1, 9, 4, 10, 10, 10, 10};
+ VERIFY(check_array(val_g, ans4));
+
+ return 0;
+};