valarray_array.h

Go to the documentation of this file.
00001 // The template and inlines for the -*- C++ -*- internal _Array helper class. 00002 00003 // Copyright (C) 1997, 1998, 1999, 2000, 2003 00004 // Free Software Foundation, Inc. 00005 // 00006 // This file is part of the GNU ISO C++ Library. This library is free 00007 // software; you can redistribute it and/or modify it under the 00008 // terms of the GNU General Public License as published by the 00009 // Free Software Foundation; either version 2, or (at your option) 00010 // any later version. 00011 00012 // This library is distributed in the hope that it will be useful, 00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 // GNU General Public License for more details. 00016 00017 // You should have received a copy of the GNU General Public License along 00018 // with this library; see the file COPYING. If not, write to the Free 00019 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, 00020 // USA. 00021 00022 // As a special exception, you may use this file as part of a free software 00023 // library without restriction. Specifically, if other files instantiate 00024 // templates or use macros or inline functions from this file, or you compile 00025 // this file and link it with other files to produce an executable, this 00026 // file does not by itself cause the resulting executable to be covered by 00027 // the GNU General Public License. This exception does not however 00028 // invalidate any other reasons why the executable file might be covered by 00029 // the GNU General Public License. 00030 00031 // Written by Gabriel Dos Reis <Gabriel.Dos-Reis@DPTMaths.ENS-Cachan.Fr> 00032 00033 /** @file valarray_array.h 00034 * This is an internal header file, included by other library headers. 00035 * You should not attempt to use it directly. 00036 */ 00037 00038 #ifndef _VALARRAY_ARRAY_H 00039 #define _VALARRAY_ARRAY_H 1 00040 00041 #pragma GCC system_header 00042 00043 #include <bits/c++config.h> 00044 #include <bits/cpp_type_traits.h> 00045 #include <cstdlib> 00046 #include <cstring> 00047 #include <new> 00048 00049 namespace std 00050 { 00051 // 00052 // Helper functions on raw pointers 00053 // 00054 00055 // We get memory by the old fashion way 00056 inline void* 00057 __valarray_get_memory(size_t __n) 00058 { return operator new(__n); } 00059 00060 template<typename _Tp> 00061 inline _Tp*__restrict__ 00062 __valarray_get_storage(size_t __n) 00063 { 00064 return static_cast<_Tp*__restrict__> 00065 (std::__valarray_get_memory(__n * sizeof(_Tp))); 00066 } 00067 00068 // Return memory to the system 00069 inline void 00070 __valarray_release_memory(void* __p) 00071 { operator delete(__p); } 00072 00073 // Turn a raw-memory into an array of _Tp filled with _Tp() 00074 // This is required in 'valarray<T> v(n);' 00075 template<typename _Tp, bool> 00076 struct _Array_default_ctor 00077 { 00078 // Please note that this isn't exception safe. But 00079 // valarrays aren't required to be exception safe. 00080 inline static void 00081 _S_do_it(_Tp* __restrict__ __b, _Tp* __restrict__ __e) 00082 { while (__b != __e) new(__b++) _Tp(); } 00083 }; 00084 00085 template<typename _Tp> 00086 struct _Array_default_ctor<_Tp, true> 00087 { 00088 // For fundamental types, it suffices to say 'memset()' 00089 inline static void 00090 _S_do_it(_Tp* __restrict__ __b, _Tp* __restrict__ __e) 00091 { std::memset(__b, 0, (__e - __b)*sizeof(_Tp)); } 00092 }; 00093 00094 template<typename _Tp> 00095 inline void 00096 __valarray_default_construct(_Tp* __restrict__ __b, _Tp* __restrict__ __e) 00097 { 00098 _Array_default_ctor<_Tp, __is_fundamental<_Tp>::_M_type>:: 00099 _S_do_it(__b, __e); 00100 } 00101 00102 // Turn a raw-memory into an array of _Tp filled with __t 00103 // This is the required in valarray<T> v(n, t). Also 00104 // used in valarray<>::resize(). 00105 template<typename _Tp, bool> 00106 struct _Array_init_ctor 00107 { 00108 // Please note that this isn't exception safe. But 00109 // valarrays aren't required to be exception safe. 00110 inline static void 00111 _S_do_it(_Tp* __restrict__ __b, _Tp* __restrict__ __e, const _Tp __t) 00112 { while (__b != __e) new(__b++) _Tp(__t); } 00113 }; 00114 00115 template<typename _Tp> 00116 struct _Array_init_ctor<_Tp, true> 00117 { 00118 inline static void 00119 _S_do_it(_Tp* __restrict__ __b, _Tp* __restrict__ __e, const _Tp __t) 00120 { while (__b != __e) *__b++ = __t; } 00121 }; 00122 00123 template<typename _Tp> 00124 inline void 00125 __valarray_fill_construct(_Tp* __restrict__ __b, _Tp* __restrict__ __e, 00126 const _Tp __t) 00127 { 00128 _Array_init_ctor<_Tp, __is_fundamental<_Tp>::_M_type>:: 00129 _S_do_it(__b, __e, __t); 00130 } 00131 00132 // 00133 // copy-construct raw array [__o, *) from plain array [__b, __e) 00134 // We can't just say 'memcpy()' 00135 // 00136 template<typename _Tp, bool> 00137 struct _Array_copy_ctor 00138 { 00139 // Please note that this isn't exception safe. But 00140 // valarrays aren't required to be exception safe. 00141 inline static void 00142 _S_do_it(const _Tp* __restrict__ __b, const _Tp* __restrict__ __e, 00143 _Tp* __restrict__ __o) 00144 { while (__b != __e) new(__o++) _Tp(*__b++); } 00145 }; 00146 00147 template<typename _Tp> 00148 struct _Array_copy_ctor<_Tp, true> 00149 { 00150 inline static void 00151 _S_do_it(const _Tp* __restrict__ __b, const _Tp* __restrict__ __e, 00152 _Tp* __restrict__ __o) 00153 { std::memcpy(__o, __b, (__e - __b)*sizeof(_Tp)); } 00154 }; 00155 00156 template<typename _Tp> 00157 inline void 00158 __valarray_copy_construct(const _Tp* __restrict__ __b, 00159 const _Tp* __restrict__ __e, 00160 _Tp* __restrict__ __o) 00161 { 00162 _Array_copy_ctor<_Tp, __is_fundamental<_Tp>::_M_type>:: 00163 _S_do_it(__b, __e, __o); 00164 } 00165 00166 // copy-construct raw array [__o, *) from strided array __a[<__n : __s>] 00167 template<typename _Tp> 00168 inline void 00169 __valarray_copy_construct (const _Tp* __restrict__ __a, size_t __n, 00170 size_t __s, _Tp* __restrict__ __o) 00171 { 00172 if (__is_fundamental<_Tp>::_M_type) 00173 while (__n--) { *__o++ = *__a; __a += __s; } 00174 else 00175 while (__n--) { new(__o++) _Tp(*__a); __a += __s; } 00176 } 00177 00178 // copy-construct raw array [__o, *) from indexed array __a[__i[<__n>]] 00179 template<typename _Tp> 00180 inline void 00181 __valarray_copy_construct (const _Tp* __restrict__ __a, 00182 const size_t* __restrict__ __i, 00183 _Tp* __restrict__ __o, size_t __n) 00184 { 00185 if (__is_fundamental<_Tp>::_M_type) 00186 while (__n--) *__o++ = __a[*__i++]; 00187 else 00188 while (__n--) new (__o++) _Tp(__a[*__i++]); 00189 } 00190 00191 // Do the necessary cleanup when we're done with arrays. 00192 template<typename _Tp> 00193 inline void 00194 __valarray_destroy_elements(_Tp* __restrict__ __b, _Tp* __restrict__ __e) 00195 { 00196 if (!__is_fundamental<_Tp>::_M_type) 00197 while (__b != __e) { __b->~_Tp(); ++__b; } 00198 } 00199 00200 // Fill a plain array __a[<__n>] with __t 00201 template<typename _Tp> 00202 inline void 00203 __valarray_fill (_Tp* __restrict__ __a, size_t __n, const _Tp& __t) 00204 { while (__n--) *__a++ = __t; } 00205 00206 // fill strided array __a[<__n-1 : __s>] with __t 00207 template<typename _Tp> 00208 inline void 00209 __valarray_fill (_Tp* __restrict__ __a, size_t __n, 00210 size_t __s, const _Tp& __t) 00211 { for (size_t __i=0; __i<__n; ++__i, __a+=__s) *__a = __t; } 00212 00213 // fill indir ect array __a[__i[<__n>]] with __i 00214 template<typename _Tp> 00215 inline void 00216 __valarray_fill(_Tp* __restrict__ __a, const size_t* __restrict__ __i, 00217 size_t __n, const _Tp& __t) 00218 { for (size_t __j=0; __j<__n; ++__j, ++__i) __a[*__i] = __t; } 00219 00220 // copy plain array __a[<__n>] in __b[<__n>] 00221 // For non-fundamental types, it is wrong to say 'memcpy()' 00222 template<typename _Tp, bool> 00223 struct _Array_copier 00224 { 00225 inline static void 00226 _S_do_it(const _Tp* __restrict__ __a, size_t __n, _Tp* __restrict__ __b) 00227 { while (__n--) *__b++ = *__a++; } 00228 }; 00229 00230 template<typename _Tp> 00231 struct _Array_copier<_Tp, true> 00232 { 00233 inline static void 00234 _S_do_it(const _Tp* __restrict__ __a, size_t __n, _Tp* __restrict__ __b) 00235 { std::memcpy (__b, __a, __n * sizeof (_Tp)); } 00236 }; 00237 00238 // Copy a plain array __a[<__n>] into a play array __b[<>] 00239 template<typename _Tp> 00240 inline void 00241 __valarray_copy(const _Tp* __restrict__ __a, size_t __n, 00242 _Tp* __restrict__ __b) 00243 { 00244 _Array_copier<_Tp, __is_fundamental<_Tp>::_M_type>:: 00245 _S_do_it(__a, __n, __b); 00246 } 00247 00248 // Copy strided array __a[<__n : __s>] in plain __b[<__n>] 00249 template<typename _Tp> 00250 inline void 00251 __valarray_copy(const _Tp* __restrict__ __a, size_t __n, size_t __s, 00252 _Tp* __restrict__ __b) 00253 { for (size_t __i=0; __i<__n; ++__i, ++__b, __a += __s) *__b = *__a; } 00254 00255 // Copy a plain array __a[<__n>] into a strided array __b[<__n : __s>] 00256 template<typename _Tp> 00257 inline void 00258 __valarray_copy(const _Tp* __restrict__ __a, _Tp* __restrict__ __b, 00259 size_t __n, size_t __s) 00260 { for (size_t __i=0; __i<__n; ++__i, ++__a, __b+=__s) *__b = *__a; } 00261 00262 // Copy strided array __src[<__n : __s1>] into another 00263 // strided array __dst[< : __s2>]. Their sizes must match. 00264 template<typename _Tp> 00265 inline void 00266 __valarray_copy(const _Tp* __restrict__ __src, size_t __n, size_t __s1, 00267 _Tp* __restrict__ __dst, size_t __s2) 00268 { 00269 for (size_t __i = 0; __i < __n; ++__i) 00270 __dst[__i * __s2] = __src [ __i * __s1]; 00271 } 00272 00273 00274 // Copy an indexed array __a[__i[<__n>]] in plain array __b[<__n>] 00275 template<typename _Tp> 00276 inline void 00277 __valarray_copy (const _Tp* __restrict__ __a, 00278 const size_t* __restrict__ __i, 00279 _Tp* __restrict__ __b, size_t __n) 00280 { for (size_t __j=0; __j<__n; ++__j, ++__b, ++__i) *__b = __a[*__i]; } 00281 00282 // Copy a plain array __a[<__n>] in an indexed array __b[__i[<__n>]] 00283 template<typename _Tp> 00284 inline void 00285 __valarray_copy (const _Tp* __restrict__ __a, size_t __n, 00286 _Tp* __restrict__ __b, const size_t* __restrict__ __i) 00287 { for (size_t __j=0; __j<__n; ++__j, ++__a, ++__i) __b[*__i] = *__a; } 00288 00289 // Copy the __n first elements of an indexed array __src[<__i>] into 00290 // another indexed array __dst[<__j>]. 00291 template<typename _Tp> 00292 inline void 00293 __valarray_copy(const _Tp* __restrict__ __src, size_t __n, 00294 const size_t* __restrict__ __i, 00295 _Tp* __restrict__ __dst, const size_t* __restrict__ __j) 00296 { 00297 for (size_t __k = 0; __k < __n; ++__k) 00298 __dst[*__j++] = __src[*__i++]; 00299 } 00300 00301 // 00302 // Compute the sum of elements in range [__f, __l) 00303 // This is a naive algorithm. It suffers from cancelling. 00304 // In the future try to specialize 00305 // for _Tp = float, double, long double using a more accurate 00306 // algorithm. 00307 // 00308 template<typename _Tp> 00309 inline _Tp 00310 __valarray_sum(const _Tp* __restrict__ __f, const _Tp* __restrict__ __l) 00311 { 00312 _Tp __r = _Tp(); 00313 while (__f != __l) __r += *__f++; 00314 return __r; 00315 } 00316 00317 // Compute the product of all elements in range [__f, __l) 00318 template<typename _Tp> 00319 inline _Tp 00320 __valarray_product(const _Tp* __restrict__ __f, 00321 const _Tp* __restrict__ __l) 00322 { 00323 _Tp __r = _Tp(1); 00324 while (__f != __l) __r = __r * *__f++; 00325 return __r; 00326 } 00327 00328 // Compute the min/max of an array-expression 00329 template<typename _Ta> 00330 inline typename _Ta::value_type 00331 __valarray_min(const _Ta& __a) 00332 { 00333 size_t __s = __a.size(); 00334 typedef typename _Ta::value_type _Value_type; 00335 _Value_type __r = __s == 0 ? _Value_type() : __a[0]; 00336 for (size_t __i = 1; __i < __s; ++__i) 00337 { 00338 _Value_type __t = __a[__i]; 00339 if (__t < __r) 00340 __r = __t; 00341 } 00342 return __r; 00343 } 00344 00345 template<typename _Ta> 00346 inline typename _Ta::value_type 00347 __valarray_max(const _Ta& __a) 00348 { 00349 size_t __s = __a.size(); 00350 typedef typename _Ta::value_type _Value_type; 00351 _Value_type __r = __s == 0 ? _Value_type() : __a[0]; 00352 for (size_t __i = 1; __i < __s; ++__i) 00353 { 00354 _Value_type __t = __a[__i]; 00355 if (__t > __r) 00356 __r = __t; 00357 } 00358 return __r; 00359 } 00360 00361 // 00362 // Helper class _Array, first layer of valarray abstraction. 00363 // All operations on valarray should be forwarded to this class 00364 // whenever possible. -- gdr 00365 // 00366 00367 template<typename _Tp> 00368 struct _Array 00369 { 00370 explicit _Array (size_t); 00371 explicit _Array (_Tp* const __restrict__); 00372 explicit _Array (const valarray<_Tp>&); 00373 _Array (const _Tp* __restrict__, size_t); 00374 00375 _Tp* begin () const; 00376 00377 _Tp* const __restrict__ _M_data; 00378 }; 00379 00380 template<typename _Tp> 00381 inline void 00382 __valarray_fill (_Array<_Tp> __a, size_t __n, const _Tp& __t) 00383 { std::__valarray_fill (__a._M_data, __n, __t); } 00384 00385 template<typename _Tp> 00386 inline void 00387 __valarray_fill (_Array<_Tp> __a, size_t __n, size_t __s, const _Tp& __t) 00388 { std::__valarray_fill (__a._M_data, __n, __s, __t); } 00389 00390 template<typename _Tp> 00391 inline void 00392 __valarray_fill (_Array<_Tp> __a, _Array<size_t> __i, 00393 size_t __n, const _Tp& __t) 00394 { std::__valarray_fill (__a._M_data, __i._M_data, __n, __t); } 00395 00396 // Copy a plain array __a[<__n>] into a play array __b[<>] 00397 template<typename _Tp> 00398 inline void 00399 __valarray_copy(_Array<_Tp> __a, size_t __n, _Array<_Tp> __b) 00400 { std::__valarray_copy(__a._M_data, __n, __b._M_data); } 00401 00402 // Copy strided array __a[<__n : __s>] in plain __b[<__n>] 00403 template<typename _Tp> 00404 inline void 00405 __valarray_copy(_Array<_Tp> __a, size_t __n, size_t __s, _Array<_Tp> __b) 00406 { std::__valarray_copy(__a._M_data, __n, __s, __b._M_data); } 00407 00408 // Copy a plain array __a[<__n>] into a strided array __b[<__n : __s>] 00409 template<typename _Tp> 00410 inline void 00411 __valarray_copy(_Array<_Tp> __a, _Array<_Tp> __b, size_t __n, size_t __s) 00412 { __valarray_copy(__a._M_data, __b._M_data, __n, __s); } 00413 00414 // Copy strided array __src[<__n : __s1>] into another 00415 // strided array __dst[< : __s2>]. Their sizes must match. 00416 template<typename _Tp> 00417 inline void 00418 __valarray_copy(_Array<_Tp> __a, size_t __n, size_t __s1, 00419 _Array<_Tp> __b, size_t __s2) 00420 { std::__valarray_copy(__a._M_data, __n, __s1, __b._M_data, __s2); } 00421 00422 00423 // Copy an indexed array __a[__i[<__n>]] in plain array __b[<__n>] 00424 template<typename _Tp> 00425 inline void 00426 __valarray_copy(_Array<_Tp> __a, _Array<size_t> __i, 00427 _Array<_Tp> __b, size_t __n) 00428 { std::__valarray_copy(__a._M_data, __i._M_data, __b._M_data, __n); } 00429 00430 // Copy a plain array __a[<__n>] in an indexed array __b[__i[<__n>]] 00431 template<typename _Tp> 00432 inline void 00433 __valarray_copy(_Array<_Tp> __a, size_t __n, _Array<_Tp> __b, 00434 _Array<size_t> __i) 00435 { std::__valarray_copy(__a._M_data, __n, __b._M_data, __i._M_data); } 00436 00437 // Copy the __n first elements of an indexed array __src[<__i>] into 00438 // another indexed array __dst[<__j>]. 00439 template<typename _Tp> 00440 inline void 00441 __valarray_copy(_Array<_Tp> __src, size_t __n, _Array<size_t> __i, 00442 _Array<_Tp> __dst, _Array<size_t> __j) 00443 { 00444 std::__valarray_copy(__src._M_data, __n, __i._M_data, 00445 __dst._M_data, __j._M_data); 00446 } 00447 00448 template<typename _Tp> 00449 inline 00450 _Array<_Tp>::_Array (size_t __n) 00451 : _M_data(__valarray_get_storage<_Tp>(__n)) 00452 { std::__valarray_default_construct(_M_data, _M_data + __n); } 00453 00454 template<typename _Tp> 00455 inline 00456 _Array<_Tp>::_Array (_Tp* const __restrict__ __p) : _M_data (__p) {} 00457 00458 template<typename _Tp> 00459 inline _Array<_Tp>::_Array (const valarray<_Tp>& __v) 00460 : _M_data (__v._M_data) {} 00461 00462 template<typename _Tp> 00463 inline 00464 _Array<_Tp>::_Array (const _Tp* __restrict__ __b, size_t __s) 00465 : _M_data(__valarray_get_storage<_Tp>(__s)) 00466 { std::__valarray_copy_construct(__b, __s, _M_data); } 00467 00468 template<typename _Tp> 00469 inline _Tp* 00470 _Array<_Tp>::begin () const 00471 { return _M_data; } 00472 00473 #define _DEFINE_ARRAY_FUNCTION(_Op, _Name) \ 00474 template<typename _Tp> \ 00475 inline void \ 00476 _Array_augmented_##_Name (_Array<_Tp> __a, size_t __n, const _Tp& __t) \ 00477 { \ 00478 for (_Tp* __p=__a._M_data; __p<__a._M_data+__n; ++__p) \ 00479 *__p _Op##= __t; \ 00480 } \ 00481 \ 00482 template<typename _Tp> \ 00483 inline void \ 00484 _Array_augmented_##_Name (_Array<_Tp> __a, size_t __n, _Array<_Tp> __b) \ 00485 { \ 00486 _Tp* __p = __a._M_data; \ 00487 for (_Tp* __q=__b._M_data; __q<__b._M_data+__n; ++__p, ++__q) \ 00488 *__p _Op##= *__q; \ 00489 } \ 00490 \ 00491 template<typename _Tp, class _Dom> \ 00492 void \ 00493 _Array_augmented_##_Name (_Array<_Tp> __a, \ 00494 const _Expr<_Dom,_Tp>& __e, size_t __n) \ 00495 { \ 00496 _Tp* __p (__a._M_data); \ 00497 for (size_t __i=0; __i<__n; ++__i, ++__p) *__p _Op##= __e[__i]; \ 00498 } \ 00499 \ 00500 template<typename _Tp> \ 00501 inline void \ 00502 _Array_augmented_##_Name (_Array<_Tp> __a, size_t __n, size_t __s, \ 00503 _Array<_Tp> __b) \ 00504 { \ 00505 _Tp* __q (__b._M_data); \ 00506 for (_Tp* __p=__a._M_data; __p<__a._M_data+__s*__n; __p+=__s, ++__q) \ 00507 *__p _Op##= *__q; \ 00508 } \ 00509 \ 00510 template<typename _Tp> \ 00511 inline void \ 00512 _Array_augmented_##_Name (_Array<_Tp> __a, _Array<_Tp> __b, \ 00513 size_t __n, size_t __s) \ 00514 { \ 00515 _Tp* __q (__b._M_data); \ 00516 for (_Tp* __p=__a._M_data; __p<__a._M_data+__n; ++__p, __q+=__s) \ 00517 *__p _Op##= *__q; \ 00518 } \ 00519 \ 00520 template<typename _Tp, class _Dom> \ 00521 void \ 00522 _Array_augmented_##_Name (_Array<_Tp> __a, size_t __s, \ 00523 const _Expr<_Dom,_Tp>& __e, size_t __n) \ 00524 { \ 00525 _Tp* __p (__a._M_data); \ 00526 for (size_t __i=0; __i<__n; ++__i, __p+=__s) *__p _Op##= __e[__i]; \ 00527 } \ 00528 \ 00529 template<typename _Tp> \ 00530 inline void \ 00531 _Array_augmented_##_Name (_Array<_Tp> __a, _Array<size_t> __i, \ 00532 _Array<_Tp> __b, size_t __n) \ 00533 { \ 00534 _Tp* __q (__b._M_data); \ 00535 for (size_t* __j=__i._M_data; __j<__i._M_data+__n; ++__j, ++__q) \ 00536 __a._M_data[*__j] _Op##= *__q; \ 00537 } \ 00538 \ 00539 template<typename _Tp> \ 00540 inline void \ 00541 _Array_augmented_##_Name (_Array<_Tp> __a, size_t __n, \ 00542 _Array<_Tp> __b, _Array<size_t> __i) \ 00543 { \ 00544 _Tp* __p (__a._M_data); \ 00545 for (size_t* __j=__i._M_data; __j<__i._M_data+__n; ++__j, ++__p) \ 00546 *__p _Op##= __b._M_data[*__j]; \ 00547 } \ 00548 \ 00549 template<typename _Tp, class _Dom> \ 00550 void \ 00551 _Array_augmented_##_Name (_Array<_Tp> __a, _Array<size_t> __i, \ 00552 const _Expr<_Dom, _Tp>& __e, size_t __n) \ 00553 { \ 00554 size_t* __j (__i._M_data); \ 00555 for (size_t __k=0; __k<__n; ++__k, ++__j) \ 00556 __a._M_data[*__j] _Op##= __e[__k]; \ 00557 } \ 00558 \ 00559 template<typename _Tp> \ 00560 void \ 00561 _Array_augmented_##_Name (_Array<_Tp> __a, _Array<bool> __m, \ 00562 _Array<_Tp> __b, size_t __n) \ 00563 { \ 00564 bool* ok (__m._M_data); \ 00565 _Tp* __p (__a._M_data); \ 00566 for (_Tp* __q=__b._M_data; __q<__b._M_data+__n; ++__q, ++ok, ++__p) { \ 00567 while (! *ok) { \ 00568 ++ok; \ 00569 ++__p; \ 00570 } \ 00571 *__p _Op##= *__q; \ 00572 } \ 00573 } \ 00574 \ 00575 template<typename _Tp> \ 00576 void \ 00577 _Array_augmented_##_Name (_Array<_Tp> __a, size_t __n, \ 00578 _Array<_Tp> __b, _Array<bool> __m) \ 00579 { \ 00580 bool* ok (__m._M_data); \ 00581 _Tp* __q (__b._M_data); \ 00582 for (_Tp* __p=__a._M_data; __p<__a._M_data+__n; ++__p, ++ok, ++__q) { \ 00583 while (! *ok) { \ 00584 ++ok; \ 00585 ++__q; \ 00586 } \ 00587 *__p _Op##= *__q; \ 00588 } \ 00589 } \ 00590 \ 00591 template<typename _Tp, class _Dom> \ 00592 void \ 00593 _Array_augmented_##_Name (_Array<_Tp> __a, _Array<bool> __m, \ 00594 const _Expr<_Dom, _Tp>& __e, size_t __n) \ 00595 { \ 00596 bool* ok(__m._M_data); \ 00597 _Tp* __p (__a._M_data); \ 00598 for (size_t __i=0; __i<__n; ++__i, ++ok, ++__p) { \ 00599 while (! *ok) { \ 00600 ++ok; \ 00601 ++__p; \ 00602 } \ 00603 *__p _Op##= __e[__i]; \ 00604 } \ 00605 } 00606 00607 _DEFINE_ARRAY_FUNCTION(+, __plus) 00608 _DEFINE_ARRAY_FUNCTION(-, __minus) 00609 _DEFINE_ARRAY_FUNCTION(*, __multiplies) 00610 _DEFINE_ARRAY_FUNCTION(/, __divides) 00611 _DEFINE_ARRAY_FUNCTION(%, __modulus) 00612 _DEFINE_ARRAY_FUNCTION(^, __bitwise_xor) 00613 _DEFINE_ARRAY_FUNCTION(|, __bitwise_or) 00614 _DEFINE_ARRAY_FUNCTION(&, __bitwise_and) 00615 _DEFINE_ARRAY_FUNCTION(<<, __shift_left) 00616 _DEFINE_ARRAY_FUNCTION(>>, __shift_right) 00617 00618 #undef _DEFINE_VALARRAY_FUNCTION 00619 } // namespace std 00620 00621 #ifndef _GLIBCXX_EXPORT_TEMPLATE 00622 # include <bits/valarray_array.tcc> 00623 #endif 00624 00625 #endif /* _ARRAY_H */

Generated on Wed Sep 8 10:19:54 2004 for libstdc++-v3 Source by doxygen 1.3.8