33 #ifndef __INCLUDE_MIST_OPERATOR_ARRAY__
34 #define __INCLUDE_MIST_OPERATOR_ARRAY__
46 template <
class T,
class Allocator >
47 inline const array< T, Allocator >&
operator +=( array< T, Allocator > &a1,
const array< T, Allocator > &a2 )
49 typedef typename array< T, Allocator >::size_type size_type;
50 #if _CHECK_ARRAY_OPERATION_ != 0
51 if( a1.size( ) != a2.size( ) )
54 ::std::cerr <<
"can't add arrays." << ::std::endl;
58 for( size_type i = 0 ; i < a1.size( ) ; i++ ) a1[i] += static_cast< T >( a2[i] );
72 template <
class T,
class Allocator >
73 inline const array< T, Allocator >&
operator -=( array< T, Allocator > &a1,
const array< T, Allocator > &a2 )
75 typedef typename array< T, Allocator >::size_type size_type;
76 #if _CHECK_ARRAY_OPERATION_ != 0
77 if( a1.size( ) != a2.size( ) )
80 ::std::cerr <<
"can't subtract arrays." << ::std::endl;
84 for( size_type i = 0 ; i < a1.size( ) ; i++ ) a1[i] -= static_cast< T >( a2[i] );
98 template <
class T,
class Allocator >
99 inline const array< T, Allocator >&
operator *=( array< T, Allocator > &a1,
const array< T, Allocator > &a2 )
101 typedef typename array< T, Allocator >::size_type size_type;
102 #if _CHECK_ARRAY_OPERATION_ != 0
103 if( a1.size( ) != a2.size( ) )
106 ::std::cerr <<
"can't multiply arrays." << ::std::endl;
110 for( size_type i = 0 ; i < a1.size( ) ; i++ ) a1[i] *= static_cast< T >( a2[i] );
124 template <
class T,
class Allocator >
125 inline const array< T, Allocator >&
operator /=( array< T, Allocator > &a1,
const array< T, Allocator > &a2 )
127 typedef typename array< T, Allocator >::size_type size_type;
128 #if _CHECK_ARRAY_OPERATION_ != 0
129 if( a1.size( ) != a2.size( ) )
132 ::std::cerr <<
"can't divide arrays." << ::std::endl;
136 for( size_type i = 0 ; i < a1.size( ) ; i++ ) a1[i] /= static_cast< T >( a2[i] );
150 template <
class T,
class Allocator >
151 inline const array< T, Allocator >&
operator +=( array< T, Allocator > &a1,
typename array< T, Allocator >::value_type val )
153 typedef typename array< T, Allocator >::size_type size_type;
154 for( size_type i = 0 ; i < a1.size( ) ; i++ ) a1[i] += val;
168 template <
class T,
class Allocator >
169 inline const array< T, Allocator >&
operator -=( array< T, Allocator > &a1,
typename array< T, Allocator >::value_type val )
171 typedef typename array< T, Allocator >::size_type size_type;
172 for( size_type i = 0 ; i < a1.size( ) ; i++ ) a1[i] -= val;
186 template <
class T,
class Allocator >
187 inline const array< T, Allocator >&
operator *=( array< T, Allocator > &a1,
typename array< T, Allocator >::value_type val )
189 typedef typename array< T, Allocator >::size_type size_type;
190 for( size_type i = 0 ; i < a1.size( ) ; i++ ) a1[i] *= val;
204 template <
class T,
class Allocator >
205 inline const array< T, Allocator >&
operator /=( array< T, Allocator > &a1,
typename array< T, Allocator >::value_type val )
207 typedef typename array< T, Allocator >::size_type size_type;
208 #if _CHECK_ARRAY_OPERATION_ != 0
212 ::std::cerr <<
"zero division occured." << ::std::endl;
216 for( size_type i = 0 ; i < a1.size( ) ; i++ ) a1[i] /= val;
230 template <
class T,
class Allocator >
231 inline array< T, Allocator >
operator -(
const array< T, Allocator > &a )
233 typedef typename array< T, Allocator >::size_type size_type;
234 array< T, Allocator > o( a.size( ) );
235 for( size_type i = 0 ; i < o.size( ) ; i++ ) o[i] = -a[i];
251 template <
class T,
class Allocator >
252 inline array< T, Allocator >
operator +(
const array< T, Allocator > &a1,
const array< T, Allocator > &a2 )
254 array< T, Allocator > tmp( a1 );
270 template <
class T,
class Allocator >
271 inline array< T, Allocator >
operator -(
const array< T, Allocator > &a1,
const array< T, Allocator > &a2 )
273 array< T, Allocator > tmp( a1 );
289 template <
class T,
class Allocator >
290 inline array< T, Allocator >
operator *(
const array< T, Allocator > &a1,
const array< T, Allocator > &a2 )
292 array< T, Allocator > tmp( a1 );
307 template <
class T,
class Allocator >
308 inline array< T, Allocator >
operator /(
const array< T, Allocator > &a1,
const array< T, Allocator > &a2 )
310 array< T, Allocator > tmp( a1 );
324 template <
class T,
class Allocator >
325 inline array< T, Allocator >
operator +(
const array< T, Allocator > &a,
typename array< T, Allocator >::value_type val )
327 array< T, Allocator > tmp( a );
328 return( tmp += val );
341 template <
class T,
class Allocator >
342 inline array< T, Allocator >
operator +(
typename array< T, Allocator >::value_type val,
const array< T, Allocator > &a )
344 array< T, Allocator > tmp( a );
345 return( tmp += val );
358 template <
class T,
class Allocator >
359 inline array< T, Allocator >
operator -(
const array< T, Allocator > &a,
typename array< T, Allocator >::value_type val )
361 array< T, Allocator > tmp( a );
362 return( tmp -= val );
375 template <
class T,
class Allocator >
376 inline array< T, Allocator >
operator -(
typename array< T, Allocator >::value_type val,
const array< T, Allocator > &a )
378 array< T, Allocator > tmp( a.size( ), val );
392 template <
class T,
class Allocator >
393 inline array< T, Allocator >
operator *(
const array< T, Allocator > &a,
typename array< T, Allocator >::value_type val )
395 array< T, Allocator > tmp( a );
396 return( tmp *= val );
409 template <
class T,
class Allocator >
410 inline array< T, Allocator >
operator *(
typename array< T, Allocator >::value_type val,
const array< T, Allocator > &a )
412 array< T, Allocator > tmp( a );
413 return( tmp *= val );
426 template <
class T,
class Allocator >
427 inline array< T, Allocator >
operator /(
const array< T, Allocator > &a,
typename array< T, Allocator >::value_type val )
429 array< T, Allocator > tmp( a );
430 return( tmp /= val );
433 #endif // __INCLUDE_MIST_OPERATOR_ARRAY__