1 // The template and inlines for the -*- C++ -*- indirect_array class.
3 // Copyright (C) 1997-2001 Free Software Foundation, Inc.
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)
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.
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, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
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.
30 // Written by Gabriel Dos Reis <Gabriel.Dos-Reis@DPTMaths.ENS-Cachan.Fr>
32 #ifndef _CPP_BITS_INDIRECT_ARRAY_H
33 #define _CPP_BITS_INDIRECT_ARRAY_H 1
35 #pragma GCC system_header
39 template <class _Tp> class indirect_array
42 typedef _Tp value_type;
44 void operator= (const valarray<_Tp>&) const;
45 void operator*= (const valarray<_Tp>&) const;
46 void operator/= (const valarray<_Tp>&) const;
47 void operator%= (const valarray<_Tp>&) const;
48 void operator+= (const valarray<_Tp>&) const;
49 void operator-= (const valarray<_Tp>&) const;
50 void operator^= (const valarray<_Tp>&) const;
51 void operator&= (const valarray<_Tp>&) const;
52 void operator|= (const valarray<_Tp>&) const;
53 void operator<<= (const valarray<_Tp>&) const;
54 void operator>>= (const valarray<_Tp>&) const;
55 void operator= (const _Tp&);
59 void operator= (const _Expr<_Dom, _Tp>&) const;
61 void operator*= (const _Expr<_Dom, _Tp>&) const;
63 void operator/= (const _Expr<_Dom, _Tp>&) const;
65 void operator%= (const _Expr<_Dom, _Tp>&) const;
67 void operator+= (const _Expr<_Dom, _Tp>&) const;
69 void operator-= (const _Expr<_Dom, _Tp>&) const;
71 void operator^= (const _Expr<_Dom, _Tp>&) const;
73 void operator&= (const _Expr<_Dom, _Tp>&) const;
75 void operator|= (const _Expr<_Dom, _Tp>&) const;
77 void operator<<= (const _Expr<_Dom, _Tp>&) const;
79 void operator>>= (const _Expr<_Dom, _Tp>&) const;
82 indirect_array (const indirect_array&);
83 indirect_array (_Array<_Tp>, size_t, _Array<size_t>);
85 friend class valarray<_Tp>;
86 friend class gslice_array<_Tp>;
89 const _Array<size_t> _M_index;
90 const _Array<_Tp> _M_array;
94 indirect_array& operator= (const indirect_array&);
97 template<typename _Tp>
98 inline indirect_array<_Tp>::indirect_array(const indirect_array<_Tp>& __a)
99 : _M_sz (__a._M_sz), _M_index (__a._M_index),
100 _M_array (__a._M_array) {}
102 template<typename _Tp>
104 indirect_array<_Tp>::indirect_array (_Array<_Tp> __a, size_t __s,
106 : _M_sz (__s), _M_index (__i), _M_array (__a) {}
108 // template<typename _Tp>
109 // inline indirect_array<_Tp>::~indirect_array() {}
111 template<typename _Tp>
113 indirect_array<_Tp>::operator= (const _Tp& __t)
114 { __valarray_fill(_M_array, _M_index, _M_sz, __t); }
116 template<typename _Tp>
118 indirect_array<_Tp>::operator= (const valarray<_Tp>& __v) const
119 { __valarray_copy (_Array<_Tp> (__v), _M_sz, _M_array, _M_index); }
121 template<typename _Tp>
124 indirect_array<_Tp>::operator= (const _Expr<_Dom,_Tp>& __e) const
125 { __valarray_copy (__e, _M_sz, _M_array, _M_index); }
127 #undef _DEFINE_VALARRAY_OPERATOR
128 #define _DEFINE_VALARRAY_OPERATOR(op, name) \
129 template<typename _Tp> \
131 indirect_array<_Tp>::operator op##= (const valarray<_Tp>& __v) const \
133 _Array_augmented_##name (_M_array, _M_index, _Array<_Tp> (__v), _M_sz); \
136 template<typename _Tp> template<class _Dom> \
138 indirect_array<_Tp>::operator op##= (const _Expr<_Dom,_Tp>& __e) const \
140 _Array_augmented_##name (_M_array, _M_index, __e, _M_sz); \
143 _DEFINE_VALARRAY_OPERATOR(*, multiplies)
144 _DEFINE_VALARRAY_OPERATOR(/, divides)
145 _DEFINE_VALARRAY_OPERATOR(%, modulus)
146 _DEFINE_VALARRAY_OPERATOR(+, plus)
147 _DEFINE_VALARRAY_OPERATOR(-, minus)
148 _DEFINE_VALARRAY_OPERATOR(^, xor)
149 _DEFINE_VALARRAY_OPERATOR(&, and)
150 _DEFINE_VALARRAY_OPERATOR(|, or)
151 _DEFINE_VALARRAY_OPERATOR(<<, shift_left)
152 _DEFINE_VALARRAY_OPERATOR(>>, shift_right)
154 #undef _DEFINE_VALARRAY_OPERATOR
158 #endif /* _CPP_BITS_INDIRECT_ARRAY_H */