From 7c301abf46ba2073c869ec8512577d4244a3472f Mon Sep 17 00:00:00 2001 From: Gabriel Dos Reis Date: Wed, 13 Jun 2001 22:16:24 +0000 Subject: [PATCH] slice_array_assignment.cc (main): New test. * testsuite/26_numerics/slice_array_assignment.cc (main): New test. * include/bits/slice_array.h (slice_array<>::operator=): Make public and implement. (slice_array<>::slice_array): Make copy-constructor public. * include/bits/valarray_array.h (__valarray_copy): Add another overload to copy between strided arrays. From-SVN: r43352 --- libstdc++-v3/ChangeLog | 11 +++++ libstdc++-v3/include/bits/slice_array.h | 21 ++++++--- libstdc++-v3/include/bits/valarray_array.h | 19 ++++++++ .../26_numerics/slice_array_assignment.cc | 44 +++++++++++++++++++ 4 files changed, 90 insertions(+), 5 deletions(-) create mode 100644 libstdc++-v3/testsuite/26_numerics/slice_array_assignment.cc diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index c90471ff6c4..63eeb61109e 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,14 @@ +2001-06-13 Gabriel Dos Reis + + * testsuite/26_numerics/slice_array_assignment.cc (main): New test. + + * include/bits/slice_array.h (slice_array<>::operator=): Make + public and implement. + (slice_array<>::slice_array): Make copy-constructor public. + + * include/bits/valarray_array.h (__valarray_copy): Add another + overload to copy between strided arrays. + 2001-06-13 Benjamin Kosnik * acinclude.m4 (GLIBCPP_CONFIGURE): Bump version to 3.0.0. diff --git a/libstdc++-v3/include/bits/slice_array.h b/libstdc++-v3/include/bits/slice_array.h index a38da2a837c..b2b118987fd 100644 --- a/libstdc++-v3/include/bits/slice_array.h +++ b/libstdc++-v3/include/bits/slice_array.h @@ -42,7 +42,13 @@ namespace std { public: typedef _Tp value_type; - + + // This constructor is implemented since we need to return a value. + slice_array (const slice_array&); + + // This operator must be public. See DR-253. + slice_array& operator= (const slice_array&); + void operator= (const valarray<_Tp>&) const; void operator*= (const valarray<_Tp>&) const; void operator/= (const valarray<_Tp>&) const; @@ -87,13 +93,9 @@ namespace std const size_t _M_sz; const size_t _M_stride; const _Array<_Tp> _M_array; - - // this constructor is implemented since we need to return a value. - slice_array (const slice_array&); // not implemented slice_array (); - slice_array& operator= (const slice_array&); }; template @@ -109,6 +111,15 @@ namespace std // template // inline slice_array<_Tp>::~slice_array () {} + template + inline slice_array<_Tp>& + slice_array<_Tp>::operator=(const slice_array<_Tp>& __a) + { + __valarray_copy(_M_array, _M_sz, _M_stride, __a._M_array, __a._M_stride); + return *this; + } + + template inline void slice_array<_Tp>::operator= (const _Tp& __t) diff --git a/libstdc++-v3/include/bits/valarray_array.h b/libstdc++-v3/include/bits/valarray_array.h index 741f646d2b0..448de1b4524 100644 --- a/libstdc++-v3/include/bits/valarray_array.h +++ b/libstdc++-v3/include/bits/valarray_array.h @@ -252,6 +252,18 @@ namespace std __valarray_copy (const _Tp* __restrict__ __a, _Tp* __restrict__ __b, size_t __n, size_t __s) { for (size_t __i=0; __i<__n; ++__i, ++__a, __b+=__s) *__b = *__a; } + + // Copy strided array __src[<__n : __s1>] into another + // strided array __dst[< : __s2>]. Their sizes must match. + template + inline void + __valarray_copy(const _Tp* __restrict__ __src, size_t __n, size_t __s1, + _Tp* __restrict__ __dst, size_t __s2) + { + for (size_t __i = 0; __i < __n; ++__i) + __dst[__i * __s2] = __src [ __i * __s1]; + } + // copy indexed __a[__i[<__n>]] in plain __b[<__n>] template @@ -378,6 +390,13 @@ namespace std inline void __valarray_copy (_Array<_Tp> __a, _Array<_Tp> __b, size_t __n, size_t __s) { __valarray_copy (__a._M_data, __b._M_data, __n, __s); } + + template + inline void + __valarray_copy(_Array<_Tp> __a, size_t __n, size_t __s1, + _Array<_Tp> __b, size_t __s2) + { __valarray_copy(__a._M_data, __n, __s1, __b._M_data, __s2); } + template inline void diff --git a/libstdc++-v3/testsuite/26_numerics/slice_array_assignment.cc b/libstdc++-v3/testsuite/26_numerics/slice_array_assignment.cc new file mode 100644 index 00000000000..f2e20860b6c --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/slice_array_assignment.cc @@ -0,0 +1,44 @@ +// 20010613 gdr + +// Copyright (C) 2001 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. + + +// This is DR-253. Test for accessible assignment-operators. +#include + +int main() +{ + std::valarray v(10), w(10); + std::slice s(0, 0, 0); + + v[s] = w[s]; // dg-do compile + + std::slice_array t = v[s]; + + return 0; +} -- 2.30.2