Commit 7c301abf by Gabriel Dos Reis Committed by Gabriel Dos Reis

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
parent 15a7ee9f
2001-06-13 Gabriel Dos Reis <gdr@merlin.codesourcery.com>
* 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 <bkoz@redhat.com>
* acinclude.m4 (GLIBCPP_CONFIGURE): Bump version to 3.0.0.
......
......@@ -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<typename _Tp>
......@@ -109,6 +111,15 @@ namespace std
// template<typename _Tp>
// inline slice_array<_Tp>::~slice_array () {}
template<typename _Tp>
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<typename _Tp>
inline void
slice_array<_Tp>::operator= (const _Tp& __t)
......
......@@ -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<typename _Tp>
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<typename _Tp>
......@@ -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<typename _Tp>
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<typename _Tp>
inline void
......
// 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 <valarray>
int main()
{
std::valarray<double> v(10), w(10);
std::slice s(0, 0, 0);
v[s] = w[s]; // dg-do compile
std::slice_array<double> t = v[s];
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment