This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: const valarray question
- From: Gabriel Dos Reis <gdr at integrable-solutions dot net>
- To: DJ Delorie <dj at redhat dot com>
- Cc: libstdc++ at gcc dot gnu dot org, gcc-patches at gcc dot gnu dot org
- Date: 17 Dec 2005 17:38:00 +0100
- Subject: Re: const valarray question
- References: <200511082052.jA8KqtgR003290@greed.delorie.com>
DJ Delorie <dj@redhat.com> writes:
| Another interpreting-the-standards question. Consider:
|
| const valarray<float> v(6);
| slice s1, s2;
|
| v[s1][s2];
|
| G++ currently rejects this, because v[s1] is the _Expr<> type, not the
| real valarray type, and the _Expr<> type doesn't implement (or doesn't
| choose) the [](slice)const method. G++ lists alternatives that take
| size_t instead of slice.
|
| Why doesn't 26.3.1.3 apply for operator[](slice)const here? Or, why
| doesn't g++ choose that method?
Implementor error. Fixed with this.
-- Gaby
2005-12-17 Gabriel Dos Reis <gdr@integrable-solutions.net>
* include/bits/valarray_after.h (_Expr<>::operator[](slice)):
Don't assume the closure implements general indexing, as a matter
of fact, most of them don't.
(_Expr<>::operator[](const gslice&)): Likewise.
(_Expr<>::operator[](const valarray<bool>&)): Likewise.
(_Expr<>::operator[](const valarray<size_t>&)): Likewise.
(_Expr<>::shift): Fix thinko.
(_Expr<>::cshift): Likewise.
(_Expr<>::apply): Likewise.
*** include/bits/valarray_after.h (revision 108716)
--- include/bits/valarray_after.h (local)
*************** namespace std
*** 222,268 ****
template<class _Clos, typename _Tp>
inline valarray<_Tp>
_Expr<_Clos, _Tp>::operator[](slice __s) const
! { return _M_closure[__s]; }
template<class _Clos, typename _Tp>
inline valarray<_Tp>
_Expr<_Clos, _Tp>::operator[](const gslice& __gs) const
! { return _M_closure[__gs]; }
template<class _Clos, typename _Tp>
inline valarray<_Tp>
_Expr<_Clos, _Tp>::operator[](const valarray<bool>& __m) const
! { return _M_closure[__m]; }
template<class _Clos, typename _Tp>
inline valarray<_Tp>
_Expr<_Clos, _Tp>::operator[](const valarray<size_t>& __i) const
! { return _M_closure[__i]; }
template<class _Clos, typename _Tp>
inline size_t
_Expr<_Clos, _Tp>::size() const
! { return _M_closure.size (); }
template<class _Clos, typename _Tp>
inline valarray<_Tp>
_Expr<_Clos, _Tp>::shift(int __n) const
! { return valarray<_Tp>(_M_closure).shift(__n); }
template<class _Clos, typename _Tp>
inline valarray<_Tp>
_Expr<_Clos, _Tp>::cshift(int __n) const
! { return valarray<_Tp>(_M_closure).cshift(__n); }
template<class _Clos, typename _Tp>
inline valarray<_Tp>
_Expr<_Clos, _Tp>::apply(_Tp __f(const _Tp&)) const
! { return valarray<_Tp>(_M_closure).apply(__f); }
template<class _Clos, typename _Tp>
inline valarray<_Tp>
_Expr<_Clos, _Tp>::apply(_Tp __f(_Tp)) const
! { return valarray<_Tp>(_M_closure).apply(__f); }
// XXX: replace this with a more robust summation algorithm.
template<class _Clos, typename _Tp>
--- 222,292 ----
template<class _Clos, typename _Tp>
inline valarray<_Tp>
_Expr<_Clos, _Tp>::operator[](slice __s) const
! {
! valarray<_Tp> __v = valarray<_Tp>(*this)[__s];
! return __v;
! }
template<class _Clos, typename _Tp>
inline valarray<_Tp>
_Expr<_Clos, _Tp>::operator[](const gslice& __gs) const
! {
! valarray<_Tp> __v = valarray<_Tp>(*this)[__gs];
! return __v;
! }
template<class _Clos, typename _Tp>
inline valarray<_Tp>
_Expr<_Clos, _Tp>::operator[](const valarray<bool>& __m) const
! {
! valarray<_Tp> __v = valarray<_Tp>(*this)[__m];
! return __v;
! }
template<class _Clos, typename _Tp>
inline valarray<_Tp>
_Expr<_Clos, _Tp>::operator[](const valarray<size_t>& __i) const
! {
! valarray<_Tp> __v = valarray<_Tp>(*this)[__i];
! return __v;
! }
template<class _Clos, typename _Tp>
inline size_t
_Expr<_Clos, _Tp>::size() const
! { return _M_closure.size(); }
template<class _Clos, typename _Tp>
inline valarray<_Tp>
_Expr<_Clos, _Tp>::shift(int __n) const
! {
! valarray<_Tp> __v = valarray<_Tp>(*this).shift(__n);
! return __v;
! }
template<class _Clos, typename _Tp>
inline valarray<_Tp>
_Expr<_Clos, _Tp>::cshift(int __n) const
! {
! valarray<_Tp> __v = valarray<_Tp>(*this).cshift(__n);
! return __v;
! }
template<class _Clos, typename _Tp>
inline valarray<_Tp>
_Expr<_Clos, _Tp>::apply(_Tp __f(const _Tp&)) const
! {
! valarray<_Tp> __v = valarray<_Tp>(*this).apply(__f);
! return __v;
! }
template<class _Clos, typename _Tp>
inline valarray<_Tp>
_Expr<_Clos, _Tp>::apply(_Tp __f(_Tp)) const
! {
! valarray<_Tp> __v = valarray<_Tp>(*this).apply(__f);
! return __v;
! }
// XXX: replace this with a more robust summation algorithm.
template<class _Clos, typename _Tp>