_valarray.h 52 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684
  1. /*
  2. * Copyright (c) 1999
  3. * Silicon Graphics Computer Systems, Inc.
  4. *
  5. * Copyright (c) 1999
  6. * Boris Fomitchev
  7. *
  8. * This material is provided "as is", with absolutely no warranty expressed
  9. * or implied. Any use is at your own risk.
  10. *
  11. * Permission to use or copy this software for any purpose is hereby granted
  12. * without fee, provided the above notices are retained on all copies.
  13. * Permission to modify the code and to distribute modified code is granted,
  14. * provided the above notices are retained, and a notice that the code was
  15. * modified is included with the above copyright notice.
  16. *
  17. */
  18. #ifndef _STLP_VALARRAY_H
  19. #define _STLP_VALARRAY_H
  20. #ifndef _STLP_INTERNAL_CMATH
  21. # include <stl/_cmath.h>
  22. #endif
  23. #ifndef _STLP_INTERNAL_NEW
  24. # include <stl/_new.h>
  25. #endif
  26. #ifndef _STLP_INTERNAL_ALGO_H
  27. # include <stl/_algo.h>
  28. #endif
  29. #ifndef _STLP_INTERNAL_NUMERIC_H
  30. # include <stl/_numeric.h>
  31. #endif
  32. #ifndef _STLP_INTERNAL_LIMITS
  33. # include <stl/_limits.h>
  34. #endif
  35. _STLP_BEGIN_NAMESPACE
  36. class slice;
  37. class gslice;
  38. template <class _Tp> class valarray;
  39. typedef valarray<bool> _Valarray_bool;
  40. typedef valarray<size_t> _Valarray_size_t;
  41. template <class _Tp> class slice_array;
  42. template <class _Tp> class gslice_array;
  43. template <class _Tp> class mask_array;
  44. template <class _Tp> class indirect_array;
  45. //----------------------------------------------------------------------
  46. // class valarray
  47. // Base class to handle memory allocation and deallocation. We can't just
  48. // use vector<>, because vector<bool> would be unsuitable as an internal
  49. // representation for valarray<bool>.
  50. template <class _Tp>
  51. struct _Valarray_base {
  52. _Tp* _M_first;
  53. size_t _M_size;
  54. _Valarray_base() : _M_first(0), _M_size(0) {}
  55. _Valarray_base(size_t __n) : _M_first(0), _M_size(0) { _M_allocate(__n); }
  56. ~_Valarray_base() { _M_deallocate(); }
  57. void _M_allocate(size_t __n) {
  58. if (__n != 0) {
  59. _M_first = __STATIC_CAST(_Tp*, __stl_new(__n * sizeof(_Tp)));
  60. _M_size = __n;
  61. }
  62. else {
  63. _M_first = 0;
  64. _M_size = 0;
  65. }
  66. }
  67. void _M_deallocate() {
  68. __stl_delete(_M_first);
  69. _M_first = 0;
  70. _M_size = 0;
  71. }
  72. };
  73. template <class _Tp>
  74. class valarray : private _Valarray_base<_Tp>
  75. {
  76. friend class gslice;
  77. public:
  78. typedef _Tp value_type;
  79. // Basic constructors
  80. valarray() : _Valarray_base<_Tp>() {}
  81. explicit valarray(size_t __n) : _Valarray_base<_Tp>(__n)
  82. { uninitialized_fill_n(this->_M_first, this->_M_size, _STLP_DEFAULT_CONSTRUCTED(value_type)); }
  83. valarray(const value_type& __x, size_t __n) : _Valarray_base<_Tp>(__n)
  84. { uninitialized_fill_n(this->_M_first, this->_M_size, __x); }
  85. valarray(const value_type* __p, size_t __n) : _Valarray_base<_Tp>(__n)
  86. { uninitialized_copy(__p, __p + __n, this->_M_first); }
  87. valarray(const valarray<_Tp>& __x) : _Valarray_base<_Tp>(__x._M_size) {
  88. uninitialized_copy(__x._M_first, __x._M_first + __x._M_size,
  89. this->_M_first);
  90. }
  91. // Constructors from auxiliary array types
  92. valarray(const slice_array<_Tp>&);
  93. valarray(const gslice_array<_Tp>&);
  94. valarray(const mask_array<_Tp>&);
  95. valarray(const indirect_array<_Tp>&);
  96. // Destructor
  97. ~valarray() { _STLP_STD::_Destroy_Range(this->_M_first, this->_M_first + this->_M_size); }
  98. // Extension: constructor that doesn't initialize valarray elements to a
  99. // specific value. This is faster for types such as int and double.
  100. private:
  101. void _M_initialize(const __true_type&) {}
  102. void _M_initialize(const __false_type&)
  103. { uninitialized_fill_n(this->_M_first, this->_M_size, _STLP_DEFAULT_CONSTRUCTED(_Tp)); }
  104. public:
  105. struct _NoInit {};
  106. valarray(size_t __n, _NoInit) : _Valarray_base<_Tp>(__n) {
  107. typedef typename __type_traits<_Tp>::has_trivial_default_constructor _Is_Trivial;
  108. _M_initialize(_Is_Trivial());
  109. }
  110. public: // Assignment
  111. // Basic assignment. Note that 'x = y' is undefined if x.size() != y.size()
  112. valarray<_Tp>& operator=(const valarray<_Tp>& __x) {
  113. _STLP_ASSERT(__x.size() == this->size())
  114. if (this != &__x)
  115. copy(__x._M_first, __x._M_first + __x._M_size, this->_M_first);
  116. return *this;
  117. }
  118. // Scalar assignment
  119. valarray<_Tp>& operator=(const value_type& __x) {
  120. fill_n(this->_M_first, this->_M_size, __x);
  121. return *this;
  122. }
  123. // Assignment of auxiliary array types
  124. valarray<_Tp>& operator=(const slice_array<_Tp>&);
  125. valarray<_Tp>& operator=(const gslice_array<_Tp>&);
  126. valarray<_Tp>& operator=(const mask_array<_Tp>&);
  127. valarray<_Tp>& operator=(const indirect_array<_Tp>&);
  128. public: // Element access
  129. value_type operator[](size_t __n) const {
  130. _STLP_ASSERT(__n < this->size())
  131. return this->_M_first[__n];
  132. }
  133. value_type& operator[](size_t __n) {
  134. _STLP_ASSERT(__n < this->size())
  135. return this->_M_first[__n];
  136. }
  137. size_t size() const { return this->_M_size; }
  138. public: // Subsetting operations with auxiliary type
  139. valarray<_Tp> operator[](slice) const;
  140. slice_array<_Tp> operator[](slice);
  141. valarray<_Tp> operator[](const gslice&) const;
  142. gslice_array<_Tp> operator[](const gslice&);
  143. valarray<_Tp> operator[](const _Valarray_bool&) const;
  144. mask_array<_Tp> operator[](const _Valarray_bool&);
  145. valarray<_Tp> operator[](const _Valarray_size_t&) const;
  146. indirect_array<_Tp> operator[](const _Valarray_size_t&);
  147. public: // Unary operators.
  148. valarray<_Tp> operator+() const { return *this; }
  149. valarray<_Tp> operator-() const {
  150. valarray<_Tp> __tmp(this->size(), _NoInit());
  151. for (size_t __i = 0; __i < this->size(); ++__i)
  152. __tmp[__i] = -(*this)[__i];
  153. return __tmp;
  154. }
  155. valarray<_Tp> operator~() const {
  156. valarray<_Tp> __tmp(this->size(), _NoInit());
  157. for (size_t __i = 0; __i < this->size(); ++__i)
  158. __tmp[__i] = ~(*this)[__i];
  159. return __tmp;
  160. }
  161. _Valarray_bool operator!() const;
  162. public: // Scalar computed assignment.
  163. valarray<_Tp>& operator*= (const value_type& __x) {
  164. for (size_t __i = 0; __i < this->size(); ++__i)
  165. (*this)[__i] *= __x;
  166. return *this;
  167. }
  168. valarray<_Tp>& operator/= (const value_type& __x) {
  169. for (size_t __i = 0; __i < this->size(); ++__i)
  170. (*this)[__i] /= __x;
  171. return *this;
  172. }
  173. valarray<_Tp>& operator%= (const value_type& __x) {
  174. for (size_t __i = 0; __i < this->size(); ++__i)
  175. (*this)[__i] %= __x;
  176. return *this;
  177. }
  178. valarray<_Tp>& operator+= (const value_type& __x) {
  179. for (size_t __i = 0; __i < this->size(); ++__i)
  180. (*this)[__i] += __x;
  181. return *this;
  182. }
  183. valarray<_Tp>& operator-= (const value_type& __x) {
  184. for (size_t __i = 0; __i < this->size(); ++__i)
  185. (*this)[__i] -= __x;
  186. return *this;
  187. }
  188. valarray<_Tp>& operator^= (const value_type& __x) {
  189. for (size_t __i = 0; __i < this->size(); ++__i)
  190. (*this)[__i] ^= __x;
  191. return *this;
  192. }
  193. valarray<_Tp>& operator&= (const value_type& __x) {
  194. for (size_t __i = 0; __i < this->size(); ++__i)
  195. (*this)[__i] &= __x;
  196. return *this;
  197. }
  198. valarray<_Tp>& operator|= (const value_type& __x) {
  199. for (size_t __i = 0; __i < this->size(); ++__i)
  200. (*this)[__i] |= __x;
  201. return *this;
  202. }
  203. valarray<_Tp>& operator<<= (const value_type& __x) {
  204. for (size_t __i = 0; __i < this->size(); ++__i)
  205. (*this)[__i] <<= __x;
  206. return *this;
  207. }
  208. valarray<_Tp>& operator>>= (const value_type& __x) {
  209. for (size_t __i = 0; __i < this->size(); ++__i)
  210. (*this)[__i] >>= __x;
  211. return *this;
  212. }
  213. public: // Array computed assignment.
  214. valarray<_Tp>& operator*= (const valarray<_Tp>& __x) {
  215. _STLP_ASSERT(__x.size() == this->size())
  216. for (size_t __i = 0; __i < this->size(); ++__i)
  217. (*this)[__i] *= __x[__i];
  218. return *this;
  219. }
  220. valarray<_Tp>& operator/= (const valarray<_Tp>& __x) {
  221. _STLP_ASSERT(__x.size() == this->size())
  222. for (size_t __i = 0; __i < this->size(); ++__i)
  223. (*this)[__i] /= __x[__i];
  224. return *this;
  225. }
  226. valarray<_Tp>& operator%= (const valarray<_Tp>& __x) {
  227. _STLP_ASSERT(__x.size() == this->size())
  228. for (size_t __i = 0; __i < this->size(); ++__i)
  229. (*this)[__i] %= __x[__i];
  230. return *this;
  231. }
  232. valarray<_Tp>& operator+= (const valarray<_Tp>& __x) {
  233. _STLP_ASSERT(__x.size() == this->size())
  234. for (size_t __i = 0; __i < this->size(); ++__i)
  235. (*this)[__i] += __x[__i];
  236. return *this;
  237. }
  238. valarray<_Tp>& operator-= (const valarray<_Tp>& __x) {
  239. _STLP_ASSERT(__x.size() == this->size())
  240. for (size_t __i = 0; __i < this->size(); ++__i)
  241. (*this)[__i] -= __x[__i];
  242. return *this;
  243. }
  244. valarray<_Tp>& operator^= (const valarray<_Tp>& __x) {
  245. _STLP_ASSERT(__x.size() == this->size())
  246. for (size_t __i = 0; __i < this->size(); ++__i)
  247. (*this)[__i] ^= __x[__i];
  248. return *this;
  249. }
  250. valarray<_Tp>& operator&= (const valarray<_Tp>& __x) {
  251. _STLP_ASSERT(__x.size() == this->size())
  252. for (size_t __i = 0; __i < this->size(); ++__i)
  253. (*this)[__i] &= __x[__i];
  254. return *this;
  255. }
  256. valarray<_Tp>& operator|= (const valarray<_Tp>& __x) {
  257. _STLP_ASSERT(__x.size() == this->size())
  258. for (size_t __i = 0; __i < this->size(); ++__i)
  259. (*this)[__i] |= __x[__i];
  260. return *this;
  261. }
  262. valarray<_Tp>& operator<<= (const valarray<_Tp>& __x) {
  263. _STLP_ASSERT(__x.size() == this->size())
  264. for (size_t __i = 0; __i < this->size(); ++__i)
  265. (*this)[__i] <<= __x[__i];
  266. return *this;
  267. }
  268. valarray<_Tp>& operator>>= (const valarray<_Tp>& __x) {
  269. _STLP_ASSERT(__x.size() == this->size())
  270. for (size_t __i = 0; __i < this->size(); ++__i)
  271. (*this)[__i] >>= __x[__i];
  272. return *this;
  273. }
  274. public: // Other member functions.
  275. // The result is undefined for zero-length arrays
  276. value_type sum() const {
  277. _STLP_ASSERT(this->size() != 0)
  278. return accumulate(this->_M_first + 1, this->_M_first + this->_M_size,
  279. (*this)[0]);
  280. }
  281. // The result is undefined for zero-length arrays
  282. value_type (min) () const {
  283. _STLP_ASSERT(this->size() != 0)
  284. return *min_element(this->_M_first + 0, this->_M_first + this->_M_size);
  285. }
  286. value_type (max) () const {
  287. _STLP_ASSERT(this->size() != 0)
  288. return *max_element(this->_M_first + 0, this->_M_first + this->_M_size);
  289. }
  290. valarray<_Tp> shift(int __n) const;
  291. valarray<_Tp> cshift(int __n) const;
  292. valarray<_Tp> apply(value_type __f(value_type)) const {
  293. valarray<_Tp> __tmp(this->size());
  294. transform(this->_M_first + 0, this->_M_first + this->_M_size, __tmp._M_first,
  295. __f);
  296. return __tmp;
  297. }
  298. valarray<_Tp> apply(value_type __f(const value_type&)) const {
  299. valarray<_Tp> __tmp(this->size());
  300. transform(this->_M_first + 0, this->_M_first + this->_M_size, __tmp._M_first,
  301. __f);
  302. return __tmp;
  303. }
  304. void resize(size_t __n, value_type __x = value_type()) {
  305. _STLP_STD::_Destroy_Range(this->_M_first, this->_M_first + this->_M_size);
  306. _Valarray_base<_Tp>::_M_deallocate();
  307. _Valarray_base<_Tp>::_M_allocate(__n);
  308. uninitialized_fill_n(this->_M_first, this->_M_size, __x);
  309. }
  310. };
  311. //----------------------------------------------------------------------
  312. // valarray non-member functions.
  313. // Binary arithmetic operations between two arrays. Behavior is
  314. // undefined if the two arrays do not have the same length.
  315. template <class _Tp>
  316. inline valarray<_Tp> _STLP_CALL operator*(const valarray<_Tp>& __x,
  317. const valarray<_Tp>& __y) {
  318. _STLP_ASSERT(__x.size() == __y.size())
  319. typedef typename valarray<_Tp>::_NoInit _NoInit;
  320. valarray<_Tp> __tmp(__x.size(), _NoInit());
  321. for (size_t __i = 0; __i < __x.size(); ++__i)
  322. __tmp[__i] = __x[__i] * __y[__i];
  323. return __tmp;
  324. }
  325. template <class _Tp>
  326. inline valarray<_Tp> _STLP_CALL operator/(const valarray<_Tp>& __x,
  327. const valarray<_Tp>& __y) {
  328. _STLP_ASSERT(__x.size() == __y.size())
  329. typedef typename valarray<_Tp>::_NoInit _NoInit;
  330. valarray<_Tp> __tmp(__x.size(), _NoInit());
  331. for (size_t __i = 0; __i < __x.size(); ++__i)
  332. __tmp[__i] = __x[__i] / __y[__i];
  333. return __tmp;
  334. }
  335. template <class _Tp>
  336. inline valarray<_Tp> _STLP_CALL operator%(const valarray<_Tp>& __x,
  337. const valarray<_Tp>& __y) {
  338. _STLP_ASSERT(__x.size() == __y.size())
  339. typedef typename valarray<_Tp>::_NoInit _NoInit;
  340. valarray<_Tp> __tmp(__x.size(), _NoInit());
  341. for (size_t __i = 0; __i < __x.size(); ++__i)
  342. __tmp[__i] = __x[__i] % __y[__i];
  343. return __tmp;
  344. }
  345. template <class _Tp>
  346. inline valarray<_Tp> _STLP_CALL operator+(const valarray<_Tp>& __x,
  347. const valarray<_Tp>& __y) {
  348. _STLP_ASSERT(__x.size() == __y.size())
  349. typedef typename valarray<_Tp>::_NoInit _NoInit;
  350. valarray<_Tp> __tmp(__x.size(), _NoInit());
  351. for (size_t __i = 0; __i < __x.size(); ++__i)
  352. __tmp[__i] = __x[__i] + __y[__i];
  353. return __tmp;
  354. }
  355. template <class _Tp>
  356. inline valarray<_Tp> _STLP_CALL operator-(const valarray<_Tp>& __x,
  357. const valarray<_Tp>& __y) {
  358. _STLP_ASSERT(__x.size() == __y.size())
  359. typedef typename valarray<_Tp>::_NoInit _NoInit;
  360. valarray<_Tp> __tmp(__x.size(), _NoInit());
  361. for (size_t __i = 0; __i < __x.size(); ++__i)
  362. __tmp[__i] = __x[__i] - __y[__i];
  363. return __tmp;
  364. }
  365. template <class _Tp>
  366. inline valarray<_Tp> _STLP_CALL operator^(const valarray<_Tp>& __x,
  367. const valarray<_Tp>& __y) {
  368. _STLP_ASSERT(__x.size() == __y.size())
  369. typedef typename valarray<_Tp>::_NoInit _NoInit;
  370. valarray<_Tp> __tmp(__x.size(), _NoInit());
  371. for (size_t __i = 0; __i < __x.size(); ++__i)
  372. __tmp[__i] = __x[__i] ^ __y[__i];
  373. return __tmp;
  374. }
  375. template <class _Tp>
  376. inline valarray<_Tp> _STLP_CALL operator&(const valarray<_Tp>& __x,
  377. const valarray<_Tp>& __y) {
  378. _STLP_ASSERT(__x.size() == __y.size())
  379. typedef typename valarray<_Tp>::_NoInit _NoInit;
  380. valarray<_Tp> __tmp(__x.size(), _NoInit());
  381. for (size_t __i = 0; __i < __x.size(); ++__i)
  382. __tmp[__i] = __x[__i] & __y[__i];
  383. return __tmp;
  384. }
  385. template <class _Tp>
  386. inline valarray<_Tp> _STLP_CALL operator|(const valarray<_Tp>& __x,
  387. const valarray<_Tp>& __y) {
  388. _STLP_ASSERT(__x.size() == __y.size())
  389. typedef typename valarray<_Tp>::_NoInit _NoInit;
  390. valarray<_Tp> __tmp(__x.size(), _NoInit());
  391. for (size_t __i = 0; __i < __x.size(); ++__i)
  392. __tmp[__i] = __x[__i] | __y[__i];
  393. return __tmp;
  394. }
  395. template <class _Tp>
  396. inline valarray<_Tp> _STLP_CALL operator<<(const valarray<_Tp>& __x,
  397. const valarray<_Tp>& __y) {
  398. _STLP_ASSERT(__x.size() == __y.size())
  399. typedef typename valarray<_Tp>::_NoInit _NoInit;
  400. valarray<_Tp> __tmp(__x.size(), _NoInit());
  401. for (size_t __i = 0; __i < __x.size(); ++__i)
  402. __tmp[__i] = __x[__i] << __y[__i];
  403. return __tmp;
  404. }
  405. template <class _Tp>
  406. inline valarray<_Tp> _STLP_CALL operator>>(const valarray<_Tp>& __x,
  407. const valarray<_Tp>& __y) {
  408. _STLP_ASSERT(__x.size() == __y.size())
  409. typedef typename valarray<_Tp>::_NoInit _NoInit;
  410. valarray<_Tp> __tmp(__x.size(), _NoInit());
  411. for (size_t __i = 0; __i < __x.size(); ++__i)
  412. __tmp[__i] = __x[__i] >> __y[__i];
  413. return __tmp;
  414. }
  415. // Binary arithmetic operations between an array and a scalar.
  416. template <class _Tp>
  417. inline valarray<_Tp> _STLP_CALL operator*(const valarray<_Tp>& __x, const _Tp& __c) {
  418. typedef typename valarray<_Tp>::_NoInit _NoInit;
  419. valarray<_Tp> __tmp(__x.size(), _NoInit());
  420. for (size_t __i = 0; __i < __x.size(); ++__i)
  421. __tmp[__i] = __x[__i] * __c;
  422. return __tmp;
  423. }
  424. template <class _Tp>
  425. inline valarray<_Tp> _STLP_CALL operator*(const _Tp& __c, const valarray<_Tp>& __x) {
  426. typedef typename valarray<_Tp>::_NoInit _NoInit;
  427. valarray<_Tp> __tmp(__x.size(), _NoInit());
  428. for (size_t __i = 0; __i < __x.size(); ++__i)
  429. __tmp[__i] = __c * __x[__i];
  430. return __tmp;
  431. }
  432. template <class _Tp>
  433. inline valarray<_Tp> _STLP_CALL operator/(const valarray<_Tp>& __x, const _Tp& __c) {
  434. typedef typename valarray<_Tp>::_NoInit _NoInit;
  435. valarray<_Tp> __tmp(__x.size(), _NoInit());
  436. for (size_t __i = 0; __i < __x.size(); ++__i)
  437. __tmp[__i] = __x[__i] / __c;
  438. return __tmp;
  439. }
  440. template <class _Tp>
  441. inline valarray<_Tp> _STLP_CALL operator/(const _Tp& __c, const valarray<_Tp>& __x) {
  442. typedef typename valarray<_Tp>::_NoInit _NoInit;
  443. valarray<_Tp> __tmp(__x.size(), _NoInit());
  444. for (size_t __i = 0; __i < __x.size(); ++__i)
  445. __tmp[__i] = __c / __x[__i];
  446. return __tmp;
  447. }
  448. template <class _Tp>
  449. inline valarray<_Tp> _STLP_CALL operator%(const valarray<_Tp>& __x, const _Tp& __c) {
  450. typedef typename valarray<_Tp>::_NoInit _NoInit;
  451. valarray<_Tp> __tmp(__x.size(), _NoInit());
  452. for (size_t __i = 0; __i < __x.size(); ++__i)
  453. __tmp[__i] = __x[__i] % __c;
  454. return __tmp;
  455. }
  456. template <class _Tp>
  457. inline valarray<_Tp> _STLP_CALL operator%(const _Tp& __c, const valarray<_Tp>& __x) {
  458. typedef typename valarray<_Tp>::_NoInit _NoInit;
  459. valarray<_Tp> __tmp(__x.size(), _NoInit());
  460. for (size_t __i = 0; __i < __x.size(); ++__i)
  461. __tmp[__i] = __c % __x[__i];
  462. return __tmp;
  463. }
  464. template <class _Tp>
  465. inline valarray<_Tp> _STLP_CALL operator+(const valarray<_Tp>& __x, const _Tp& __c) {
  466. typedef typename valarray<_Tp>::_NoInit _NoInit;
  467. valarray<_Tp> __tmp(__x.size(), _NoInit());
  468. for (size_t __i = 0; __i < __x.size(); ++__i)
  469. __tmp[__i] = __x[__i] + __c;
  470. return __tmp;
  471. }
  472. template <class _Tp>
  473. inline valarray<_Tp> _STLP_CALL operator+(const _Tp& __c, const valarray<_Tp>& __x) {
  474. typedef typename valarray<_Tp>::_NoInit _NoInit;
  475. valarray<_Tp> __tmp(__x.size(), _NoInit());
  476. for (size_t __i = 0; __i < __x.size(); ++__i)
  477. __tmp[__i] = __c + __x[__i];
  478. return __tmp;
  479. }
  480. template <class _Tp>
  481. inline valarray<_Tp> _STLP_CALL operator-(const valarray<_Tp>& __x, const _Tp& __c) {
  482. typedef typename valarray<_Tp>::_NoInit _NoInit;
  483. valarray<_Tp> __tmp(__x.size(), _NoInit());
  484. for (size_t __i = 0; __i < __x.size(); ++__i)
  485. __tmp[__i] = __x[__i] - __c;
  486. return __tmp;
  487. }
  488. template <class _Tp>
  489. inline valarray<_Tp> _STLP_CALL operator-(const _Tp& __c, const valarray<_Tp>& __x) {
  490. typedef typename valarray<_Tp>::_NoInit _NoInit;
  491. valarray<_Tp> __tmp(__x.size(), _NoInit());
  492. for (size_t __i = 0; __i < __x.size(); ++__i)
  493. __tmp[__i] = __c - __x[__i];
  494. return __tmp;
  495. }
  496. template <class _Tp>
  497. inline valarray<_Tp> _STLP_CALL operator^(const valarray<_Tp>& __x, const _Tp& __c) {
  498. typedef typename valarray<_Tp>::_NoInit _NoInit;
  499. valarray<_Tp> __tmp(__x.size(), _NoInit());
  500. for (size_t __i = 0; __i < __x.size(); ++__i)
  501. __tmp[__i] = __x[__i] ^ __c;
  502. return __tmp;
  503. }
  504. template <class _Tp>
  505. inline valarray<_Tp> _STLP_CALL operator^(const _Tp& __c, const valarray<_Tp>& __x) {
  506. typedef typename valarray<_Tp>::_NoInit _NoInit;
  507. valarray<_Tp> __tmp(__x.size(), _NoInit());
  508. for (size_t __i = 0; __i < __x.size(); ++__i)
  509. __tmp[__i] = __c ^ __x[__i];
  510. return __tmp;
  511. }
  512. template <class _Tp>
  513. inline valarray<_Tp> _STLP_CALL operator&(const valarray<_Tp>& __x, const _Tp& __c) {
  514. typedef typename valarray<_Tp>::_NoInit _NoInit;
  515. valarray<_Tp> __tmp(__x.size(), _NoInit());
  516. for (size_t __i = 0; __i < __x.size(); ++__i)
  517. __tmp[__i] = __x[__i] & __c;
  518. return __tmp;
  519. }
  520. template <class _Tp>
  521. inline valarray<_Tp> _STLP_CALL operator&(const _Tp& __c, const valarray<_Tp>& __x) {
  522. typedef typename valarray<_Tp>::_NoInit _NoInit;
  523. valarray<_Tp> __tmp(__x.size(), _NoInit());
  524. for (size_t __i = 0; __i < __x.size(); ++__i)
  525. __tmp[__i] = __c & __x[__i];
  526. return __tmp;
  527. }
  528. template <class _Tp>
  529. inline valarray<_Tp> _STLP_CALL operator|(const valarray<_Tp>& __x, const _Tp& __c) {
  530. typedef typename valarray<_Tp>::_NoInit _NoInit;
  531. valarray<_Tp> __tmp(__x.size(), _NoInit());
  532. for (size_t __i = 0; __i < __x.size(); ++__i)
  533. __tmp[__i] = __x[__i] | __c;
  534. return __tmp;
  535. }
  536. template <class _Tp>
  537. inline valarray<_Tp> _STLP_CALL operator|(const _Tp& __c, const valarray<_Tp>& __x) {
  538. typedef typename valarray<_Tp>::_NoInit _NoInit;
  539. valarray<_Tp> __tmp(__x.size(), _NoInit());
  540. for (size_t __i = 0; __i < __x.size(); ++__i)
  541. __tmp[__i] = __c | __x[__i];
  542. return __tmp;
  543. }
  544. template <class _Tp>
  545. inline valarray<_Tp> _STLP_CALL operator<<(const valarray<_Tp>& __x, const _Tp& __c) {
  546. typedef typename valarray<_Tp>::_NoInit _NoInit;
  547. valarray<_Tp> __tmp(__x.size(), _NoInit());
  548. for (size_t __i = 0; __i < __x.size(); ++__i)
  549. __tmp[__i] = __x[__i] << __c;
  550. return __tmp;
  551. }
  552. template <class _Tp>
  553. inline valarray<_Tp> _STLP_CALL operator<<(const _Tp& __c, const valarray<_Tp>& __x) {
  554. typedef typename valarray<_Tp>::_NoInit _NoInit;
  555. valarray<_Tp> __tmp(__x.size(), _NoInit());
  556. for (size_t __i = 0; __i < __x.size(); ++__i)
  557. __tmp[__i] = __c << __x[__i];
  558. return __tmp;
  559. }
  560. template <class _Tp>
  561. inline valarray<_Tp> _STLP_CALL operator>>(const valarray<_Tp>& __x, const _Tp& __c) {
  562. typedef typename valarray<_Tp>::_NoInit _NoInit;
  563. valarray<_Tp> __tmp(__x.size(), _NoInit());
  564. for (size_t __i = 0; __i < __x.size(); ++__i)
  565. __tmp[__i] = __x[__i] >> __c;
  566. return __tmp;
  567. }
  568. template <class _Tp>
  569. inline valarray<_Tp> _STLP_CALL operator>>(const _Tp& __c, const valarray<_Tp>& __x) {
  570. typedef typename valarray<_Tp>::_NoInit _NoInit;
  571. valarray<_Tp> __tmp(__x.size(), _NoInit());
  572. for (size_t __i = 0; __i < __x.size(); ++__i)
  573. __tmp[__i] = __c >> __x[__i];
  574. return __tmp;
  575. }
  576. // Binary logical operations between two arrays. Behavior is undefined
  577. // if the two arrays have different lengths. Note that operator== does
  578. // not do what you might at first expect.
  579. template <class _Tp>
  580. inline _Valarray_bool _STLP_CALL operator==(const valarray<_Tp>& __x,
  581. const valarray<_Tp>& __y) {
  582. _STLP_ASSERT(__x.size() == __y.size())
  583. _Valarray_bool __tmp(__x.size(), _Valarray_bool::_NoInit());
  584. for (size_t __i = 0; __i < __x.size(); ++__i)
  585. __tmp[__i] = __x[__i] == __y[__i];
  586. return __tmp;
  587. }
  588. template <class _Tp>
  589. inline _Valarray_bool _STLP_CALL operator<(const valarray<_Tp>& __x,
  590. const valarray<_Tp>& __y) {
  591. _STLP_ASSERT(__x.size() == __y.size())
  592. _Valarray_bool __tmp(__x.size(), _Valarray_bool::_NoInit());
  593. for (size_t __i = 0; __i < __x.size(); ++__i)
  594. __tmp[__i] = __x[__i] < __y[__i];
  595. return __tmp;
  596. }
  597. #ifdef _STLP_USE_SEPARATE_RELOPS_NAMESPACE
  598. template <class _Tp>
  599. inline _Valarray_bool _STLP_CALL operator!=(const valarray<_Tp>& __x,
  600. const valarray<_Tp>& __y) {
  601. _STLP_ASSERT(__x.size() == __y.size())
  602. _Valarray_bool __tmp(__x.size(), _Valarray_bool::_NoInit());
  603. for (size_t __i = 0; __i < __x.size(); ++__i)
  604. __tmp[__i] = __x[__i] != __y[__i];
  605. return __tmp;
  606. }
  607. template <class _Tp>
  608. inline _Valarray_bool _STLP_CALL operator>(const valarray<_Tp>& __x,
  609. const valarray<_Tp>& __y) {
  610. _STLP_ASSERT(__x.size() == __y.size())
  611. _Valarray_bool __tmp(__x.size(), _Valarray_bool::_NoInit());
  612. for (size_t __i = 0; __i < __x.size(); ++__i)
  613. __tmp[__i] = __x[__i] > __y[__i];
  614. return __tmp;
  615. }
  616. template <class _Tp>
  617. inline _Valarray_bool _STLP_CALL operator<=(const valarray<_Tp>& __x,
  618. const valarray<_Tp>& __y) {
  619. _STLP_ASSERT(__x.size() == __y.size())
  620. _Valarray_bool __tmp(__x.size(), _Valarray_bool::_NoInit());
  621. for (size_t __i = 0; __i < __x.size(); ++__i)
  622. __tmp[__i] = __x[__i] <= __y[__i];
  623. return __tmp;
  624. }
  625. template <class _Tp>
  626. inline _Valarray_bool _STLP_CALL operator>=(const valarray<_Tp>& __x,
  627. const valarray<_Tp>& __y) {
  628. _STLP_ASSERT(__x.size() == __y.size())
  629. _Valarray_bool __tmp(__x.size(), _Valarray_bool::_NoInit());
  630. for (size_t __i = 0; __i < __x.size(); ++__i)
  631. __tmp[__i] = __x[__i] >= __y[__i];
  632. return __tmp;
  633. }
  634. #endif /* _STLP_USE_SEPARATE_RELOPS_NAMESPACE */
  635. // fbp : swap ?
  636. template <class _Tp>
  637. inline _Valarray_bool _STLP_CALL operator&&(const valarray<_Tp>& __x,
  638. const valarray<_Tp>& __y) {
  639. _STLP_ASSERT(__x.size() == __y.size())
  640. _Valarray_bool __tmp(__x.size(), _Valarray_bool::_NoInit());
  641. for (size_t __i = 0; __i < __x.size(); ++__i)
  642. __tmp[__i] = __x[__i] && __y[__i];
  643. return __tmp;
  644. }
  645. template <class _Tp>
  646. inline _Valarray_bool _STLP_CALL operator||(const valarray<_Tp>& __x,
  647. const valarray<_Tp>& __y) {
  648. _STLP_ASSERT(__x.size() == __y.size())
  649. _Valarray_bool __tmp(__x.size(), _Valarray_bool::_NoInit());
  650. for (size_t __i = 0; __i < __x.size(); ++__i)
  651. __tmp[__i] = __x[__i] || __y[__i];
  652. return __tmp;
  653. }
  654. // Logical operations between an array and a scalar.
  655. template <class _Tp>
  656. inline _Valarray_bool _STLP_CALL operator==(const valarray<_Tp>& __x, const _Tp& __c) {
  657. _Valarray_bool __tmp(__x.size(), _Valarray_bool::_NoInit());
  658. for (size_t __i = 0; __i < __x.size(); ++__i)
  659. __tmp[__i] = __x[__i] == __c;
  660. return __tmp;
  661. }
  662. template <class _Tp>
  663. inline _Valarray_bool _STLP_CALL operator==(const _Tp& __c, const valarray<_Tp>& __x) {
  664. _Valarray_bool __tmp(__x.size(), _Valarray_bool::_NoInit());
  665. for (size_t __i = 0; __i < __x.size(); ++__i)
  666. __tmp[__i] = __c == __x[__i];
  667. return __tmp;
  668. }
  669. template <class _Tp>
  670. inline _Valarray_bool _STLP_CALL operator!=(const valarray<_Tp>& __x, const _Tp& __c) {
  671. _Valarray_bool __tmp(__x.size(), _Valarray_bool::_NoInit());
  672. for (size_t __i = 0; __i < __x.size(); ++__i)
  673. __tmp[__i] = __x[__i] != __c;
  674. return __tmp;
  675. }
  676. template <class _Tp>
  677. inline _Valarray_bool _STLP_CALL operator!=(const _Tp& __c, const valarray<_Tp>& __x) {
  678. _Valarray_bool __tmp(__x.size(), _Valarray_bool::_NoInit());
  679. for (size_t __i = 0; __i < __x.size(); ++__i)
  680. __tmp[__i] = __c != __x[__i];
  681. return __tmp;
  682. }
  683. template <class _Tp>
  684. inline _Valarray_bool _STLP_CALL operator<(const valarray<_Tp>& __x, const _Tp& __c) {
  685. _Valarray_bool __tmp(__x.size(), _Valarray_bool::_NoInit());
  686. for (size_t __i = 0; __i < __x.size(); ++__i)
  687. __tmp[__i] = __x[__i] < __c;
  688. return __tmp;
  689. }
  690. template <class _Tp>
  691. inline _Valarray_bool _STLP_CALL operator<(const _Tp& __c, const valarray<_Tp>& __x) {
  692. _Valarray_bool __tmp(__x.size(), _Valarray_bool::_NoInit());
  693. for (size_t __i = 0; __i < __x.size(); ++__i)
  694. __tmp[__i] = __c < __x[__i];
  695. return __tmp;
  696. }
  697. template <class _Tp>
  698. inline _Valarray_bool _STLP_CALL operator>(const valarray<_Tp>& __x, const _Tp& __c) {
  699. _Valarray_bool __tmp(__x.size(), _Valarray_bool::_NoInit());
  700. for (size_t __i = 0; __i < __x.size(); ++__i)
  701. __tmp[__i] = __x[__i] > __c;
  702. return __tmp;
  703. }
  704. template <class _Tp>
  705. inline _Valarray_bool _STLP_CALL operator>(const _Tp& __c, const valarray<_Tp>& __x) {
  706. _Valarray_bool __tmp(__x.size(), _Valarray_bool::_NoInit());
  707. for (size_t __i = 0; __i < __x.size(); ++__i)
  708. __tmp[__i] = __c > __x[__i];
  709. return __tmp;
  710. }
  711. template <class _Tp>
  712. inline _Valarray_bool _STLP_CALL operator<=(const valarray<_Tp>& __x, const _Tp& __c) {
  713. _Valarray_bool __tmp(__x.size(), _Valarray_bool::_NoInit());
  714. for (size_t __i = 0; __i < __x.size(); ++__i)
  715. __tmp[__i] = __x[__i] <= __c;
  716. return __tmp;
  717. }
  718. template <class _Tp>
  719. inline _Valarray_bool _STLP_CALL operator<=(const _Tp& __c, const valarray<_Tp>& __x) {
  720. _Valarray_bool __tmp(__x.size(), _Valarray_bool::_NoInit());
  721. for (size_t __i = 0; __i < __x.size(); ++__i)
  722. __tmp[__i] = __c <= __x[__i];
  723. return __tmp;
  724. }
  725. template <class _Tp>
  726. inline _Valarray_bool _STLP_CALL operator>=(const valarray<_Tp>& __x, const _Tp& __c) {
  727. _Valarray_bool __tmp(__x.size(), _Valarray_bool::_NoInit());
  728. for (size_t __i = 0; __i < __x.size(); ++__i)
  729. __tmp[__i] = __x[__i] >= __c;
  730. return __tmp;
  731. }
  732. template <class _Tp>
  733. inline _Valarray_bool _STLP_CALL operator>=(const _Tp& __c, const valarray<_Tp>& __x) {
  734. _Valarray_bool __tmp(__x.size(), _Valarray_bool::_NoInit());
  735. for (size_t __i = 0; __i < __x.size(); ++__i)
  736. __tmp[__i] = __c >= __x[__i];
  737. return __tmp;
  738. }
  739. template <class _Tp>
  740. inline _Valarray_bool _STLP_CALL operator&&(const valarray<_Tp>& __x, const _Tp& __c) {
  741. _Valarray_bool __tmp(__x.size(), _Valarray_bool::_NoInit());
  742. for (size_t __i = 0; __i < __x.size(); ++__i)
  743. __tmp[__i] = __x[__i] && __c;
  744. return __tmp;
  745. }
  746. template <class _Tp>
  747. inline _Valarray_bool _STLP_CALL operator&&(const _Tp& __c, const valarray<_Tp>& __x) {
  748. _Valarray_bool __tmp(__x.size(), _Valarray_bool::_NoInit());
  749. for (size_t __i = 0; __i < __x.size(); ++__i)
  750. __tmp[__i] = __c && __x[__i];
  751. return __tmp;
  752. }
  753. template <class _Tp>
  754. inline _Valarray_bool _STLP_CALL operator||(const valarray<_Tp>& __x, const _Tp& __c) {
  755. _Valarray_bool __tmp(__x.size(), _Valarray_bool::_NoInit());
  756. for (size_t __i = 0; __i < __x.size(); ++__i)
  757. __tmp[__i] = __x[__i] || __c;
  758. return __tmp;
  759. }
  760. template <class _Tp>
  761. inline _Valarray_bool _STLP_CALL operator||(const _Tp& __c, const valarray<_Tp>& __x) {
  762. _Valarray_bool __tmp(__x.size(), _Valarray_bool::_NoInit());
  763. for (size_t __i = 0; __i < __x.size(); ++__i)
  764. __tmp[__i] = __c || __x[__i];
  765. return __tmp;
  766. }
  767. // valarray "transcendentals" (the list includes abs and sqrt, which,
  768. // of course, are not transcendental).
  769. template <class _Tp>
  770. inline valarray<_Tp> abs(const valarray<_Tp>& __x) {
  771. typedef typename valarray<_Tp>::_NoInit _NoInit;
  772. valarray<_Tp> __tmp(__x.size(), _NoInit());
  773. for (size_t __i = 0; __i < __x.size(); ++__i)
  774. __tmp[__i] = ::abs(__x[__i]);
  775. return __tmp;
  776. }
  777. template <class _Tp>
  778. inline valarray<_Tp> acos(const valarray<_Tp>& __x) {
  779. typedef typename valarray<_Tp>::_NoInit _NoInit;
  780. valarray<_Tp> __tmp(__x.size(), _NoInit());
  781. for (size_t __i = 0; __i < __x.size(); ++__i)
  782. __tmp[__i] = ::acos(__x[__i]);
  783. return __tmp;
  784. }
  785. template <class _Tp>
  786. inline valarray<_Tp> asin(const valarray<_Tp>& __x) {
  787. typedef typename valarray<_Tp>::_NoInit _NoInit;
  788. valarray<_Tp> __tmp(__x.size(), _NoInit());
  789. for (size_t __i = 0; __i < __x.size(); ++__i)
  790. __tmp[__i] = ::asin(__x[__i]);
  791. return __tmp;
  792. }
  793. template <class _Tp>
  794. inline valarray<_Tp> atan(const valarray<_Tp>& __x) {
  795. typedef typename valarray<_Tp>::_NoInit _NoInit;
  796. valarray<_Tp> __tmp(__x.size(), _NoInit());
  797. for (size_t __i = 0; __i < __x.size(); ++__i)
  798. __tmp[__i] = ::atan(__x[__i]);
  799. return __tmp;
  800. }
  801. template <class _Tp>
  802. inline valarray<_Tp> atan2(const valarray<_Tp>& __x,
  803. const valarray<_Tp>& __y) {
  804. typedef typename valarray<_Tp>::_NoInit _NoInit;
  805. valarray<_Tp> __tmp(__x.size(), _NoInit());
  806. for (size_t __i = 0; __i < __x.size(); ++__i)
  807. __tmp[__i] = ::atan2(__x[__i], __y[__i]);
  808. return __tmp;
  809. }
  810. template <class _Tp>
  811. inline valarray<_Tp> atan2(const valarray<_Tp>& __x, const _Tp& __c) {
  812. typedef typename valarray<_Tp>::_NoInit _NoInit;
  813. valarray<_Tp> __tmp(__x.size(), _NoInit());
  814. for (size_t __i = 0; __i < __x.size(); ++__i)
  815. __tmp[__i] = ::atan2(__x[__i], __c);
  816. return __tmp;
  817. }
  818. template <class _Tp>
  819. inline valarray<_Tp> atan2(const _Tp& __c, const valarray<_Tp>& __x) {
  820. typedef typename valarray<_Tp>::_NoInit _NoInit;
  821. valarray<_Tp> __tmp(__x.size(), _NoInit());
  822. for (size_t __i = 0; __i < __x.size(); ++__i)
  823. __tmp[__i] = ::atan2(__c, __x[__i]);
  824. return __tmp;
  825. }
  826. template <class _Tp>
  827. inline valarray<_Tp> cos(const valarray<_Tp>& __x) {
  828. typedef typename valarray<_Tp>::_NoInit _NoInit;
  829. valarray<_Tp> __tmp(__x.size(), _NoInit());
  830. for (size_t __i = 0; __i < __x.size(); ++__i)
  831. __tmp[__i] = ::cos(__x[__i]);
  832. return __tmp;
  833. }
  834. template <class _Tp>
  835. inline valarray<_Tp> cosh(const valarray<_Tp>& __x) {
  836. typedef typename valarray<_Tp>::_NoInit _NoInit;
  837. valarray<_Tp> __tmp(__x.size(), _NoInit());
  838. for (size_t __i = 0; __i < __x.size(); ++__i)
  839. __tmp[__i] = ::cosh(__x[__i]);
  840. return __tmp;
  841. }
  842. template <class _Tp>
  843. inline valarray<_Tp> exp(const valarray<_Tp>& __x) {
  844. typedef typename valarray<_Tp>::_NoInit _NoInit;
  845. valarray<_Tp> __tmp(__x.size(), _NoInit());
  846. for (size_t __i = 0; __i < __x.size(); ++__i)
  847. __tmp[__i] = ::exp(__x[__i]);
  848. return __tmp;
  849. }
  850. template <class _Tp>
  851. inline valarray<_Tp> log(const valarray<_Tp>& __x) {
  852. typedef typename valarray<_Tp>::_NoInit _NoInit;
  853. valarray<_Tp> __tmp(__x.size(), _NoInit());
  854. for (size_t __i = 0; __i < __x.size(); ++__i)
  855. __tmp[__i] = ::log(__x[__i]);
  856. return __tmp;
  857. }
  858. template <class _Tp>
  859. inline valarray<_Tp> log10(const valarray<_Tp>& __x) {
  860. typedef typename valarray<_Tp>::_NoInit _NoInit;
  861. valarray<_Tp> __tmp(__x.size(), _NoInit());
  862. for (size_t __i = 0; __i < __x.size(); ++__i)
  863. __tmp[__i] = ::log10(__x[__i]);
  864. return __tmp;
  865. }
  866. template <class _Tp>
  867. inline valarray<_Tp> pow(const valarray<_Tp>& __x,
  868. const valarray<_Tp>& __y) {
  869. typedef typename valarray<_Tp>::_NoInit _NoInit;
  870. valarray<_Tp> __tmp(__x.size(), _NoInit());
  871. for (size_t __i = 0; __i < __x.size(); ++__i)
  872. __tmp[__i] = ::pow(__x[__i], __y[__i]);
  873. return __tmp;
  874. }
  875. template <class _Tp>
  876. inline valarray<_Tp> pow(const valarray<_Tp>& __x, const _Tp& __c) {
  877. typedef typename valarray<_Tp>::_NoInit _NoInit;
  878. valarray<_Tp> __tmp(__x.size(), _NoInit());
  879. for (size_t __i = 0; __i < __x.size(); ++__i)
  880. __tmp[__i] = ::pow(__x[__i], __c);
  881. return __tmp;
  882. }
  883. template <class _Tp>
  884. inline valarray<_Tp> pow(const _Tp& __c, const valarray<_Tp>& __x) {
  885. typedef typename valarray<_Tp>::_NoInit _NoInit;
  886. valarray<_Tp> __tmp(__x.size(), _NoInit());
  887. for (size_t __i = 0; __i < __x.size(); ++__i)
  888. __tmp[__i] = ::pow(__c, __x[__i]);
  889. return __tmp;
  890. }
  891. template <class _Tp>
  892. inline valarray<_Tp> sin(const valarray<_Tp>& __x) {
  893. typedef typename valarray<_Tp>::_NoInit _NoInit;
  894. valarray<_Tp> __tmp(__x.size(), _NoInit());
  895. for (size_t __i = 0; __i < __x.size(); ++__i)
  896. __tmp[__i] = ::sin(__x[__i]);
  897. return __tmp;
  898. }
  899. template <class _Tp>
  900. inline valarray<_Tp> sinh(const valarray<_Tp>& __x) {
  901. typedef typename valarray<_Tp>::_NoInit _NoInit;
  902. valarray<_Tp> __tmp(__x.size(), _NoInit());
  903. for (size_t __i = 0; __i < __x.size(); ++__i)
  904. __tmp[__i] = ::sinh(__x[__i]);
  905. return __tmp;
  906. }
  907. template <class _Tp>
  908. inline valarray<_Tp> sqrt(const valarray<_Tp>& __x) {
  909. typedef typename valarray<_Tp>::_NoInit _NoInit;
  910. valarray<_Tp> __tmp(__x.size(), _NoInit());
  911. for (size_t __i = 0; __i < __x.size(); ++__i)
  912. __tmp[__i] = ::sqrt(__x[__i]);
  913. return __tmp;
  914. }
  915. template <class _Tp>
  916. inline valarray<_Tp> tan(const valarray<_Tp>& __x) {
  917. typedef typename valarray<_Tp>::_NoInit _NoInit;
  918. valarray<_Tp> __tmp(__x.size(), _NoInit());
  919. for (size_t __i = 0; __i < __x.size(); ++__i)
  920. __tmp[__i] = ::tan(__x[__i]);
  921. return __tmp;
  922. }
  923. template <class _Tp>
  924. inline valarray<_Tp> tanh(const valarray<_Tp>& __x) {
  925. typedef typename valarray<_Tp>::_NoInit _NoInit;
  926. valarray<_Tp> __tmp(__x.size(), _NoInit());
  927. for (size_t __i = 0; __i < __x.size(); ++__i)
  928. __tmp[__i] = ::tanh(__x[__i]);
  929. return __tmp;
  930. }
  931. //----------------------------------------------------------------------
  932. // slice and slice_array
  933. class slice {
  934. public:
  935. slice() : _M_start(0), _M_length(0), _M_stride(0) {}
  936. slice(size_t __start, size_t __length, size_t __stride)
  937. : _M_start(__start), _M_length(__length), _M_stride(__stride)
  938. {}
  939. __TRIVIAL_DESTRUCTOR(slice)
  940. size_t start() const { return _M_start; }
  941. size_t size() const { return _M_length; }
  942. size_t stride() const { return _M_stride; }
  943. private:
  944. size_t _M_start;
  945. size_t _M_length;
  946. size_t _M_stride;
  947. };
  948. template <class _Tp>
  949. class slice_array {
  950. friend class valarray<_Tp>;
  951. public:
  952. typedef _Tp value_type;
  953. void operator=(const valarray<value_type>& __x) const {
  954. size_t __index = _M_slice.start();
  955. for (size_t __i = 0;
  956. __i < _M_slice.size();
  957. ++__i, __index += _M_slice.stride())
  958. _M_array[__index] = __x[__i];
  959. }
  960. void operator*=(const valarray<value_type>& __x) const {
  961. size_t __index = _M_slice.start();
  962. for (size_t __i = 0;
  963. __i < _M_slice.size();
  964. ++__i, __index += _M_slice.stride())
  965. _M_array[__index] *= __x[__i];
  966. }
  967. void operator/=(const valarray<value_type>& __x) const {
  968. size_t __index = _M_slice.start();
  969. for (size_t __i = 0;
  970. __i < _M_slice.size();
  971. ++__i, __index += _M_slice.stride())
  972. _M_array[__index] /= __x[__i];
  973. }
  974. void operator%=(const valarray<value_type>& __x) const {
  975. size_t __index = _M_slice.start();
  976. for (size_t __i = 0;
  977. __i < _M_slice.size();
  978. ++__i, __index += _M_slice.stride())
  979. _M_array[__index] %= __x[__i];
  980. }
  981. void operator+=(const valarray<value_type>& __x) const {
  982. size_t __index = _M_slice.start();
  983. for (size_t __i = 0;
  984. __i < _M_slice.size();
  985. ++__i, __index += _M_slice.stride())
  986. _M_array[__index] += __x[__i];
  987. }
  988. void operator-=(const valarray<value_type>& __x) const {
  989. size_t __index = _M_slice.start();
  990. for (size_t __i = 0;
  991. __i < _M_slice.size();
  992. ++__i, __index += _M_slice.stride())
  993. _M_array[__index] -= __x[__i];
  994. }
  995. void operator^=(const valarray<value_type>& __x) const {
  996. size_t __index = _M_slice.start();
  997. for (size_t __i = 0;
  998. __i < _M_slice.size();
  999. ++__i, __index += _M_slice.stride())
  1000. _M_array[__index] ^= __x[__i];
  1001. }
  1002. void operator&=(const valarray<value_type>& __x) const {
  1003. size_t __index = _M_slice.start();
  1004. for (size_t __i = 0;
  1005. __i < _M_slice.size();
  1006. ++__i, __index += _M_slice.stride())
  1007. _M_array[__index] &= __x[__i];
  1008. }
  1009. void operator|=(const valarray<value_type>& __x) const {
  1010. size_t __index = _M_slice.start();
  1011. for (size_t __i = 0;
  1012. __i < _M_slice.size();
  1013. ++__i, __index += _M_slice.stride())
  1014. _M_array[__index] |= __x[__i];
  1015. }
  1016. void operator<<=(const valarray<value_type>& __x) const {
  1017. size_t __index = _M_slice.start();
  1018. for (size_t __i = 0;
  1019. __i < _M_slice.size();
  1020. ++__i, __index += _M_slice.stride())
  1021. _M_array[__index] <<= __x[__i];
  1022. }
  1023. void operator>>=(const valarray<value_type>& __x) const {
  1024. size_t __index = _M_slice.start();
  1025. for (size_t __i = 0;
  1026. __i < _M_slice.size();
  1027. ++__i, __index += _M_slice.stride())
  1028. _M_array[__index] >>= __x[__i];
  1029. }
  1030. void operator=(const value_type& __c) /*const could be const but standard says NO (26.3.5.4-1)*/ {
  1031. size_t __index = _M_slice.start();
  1032. for (size_t __i = 0;
  1033. __i < _M_slice.size();
  1034. ++__i, __index += _M_slice.stride())
  1035. _M_array[__index] = __c;
  1036. }
  1037. // C++ Standard defect 253, copy constructor must be public.
  1038. slice_array(const slice_array &__x)
  1039. : _M_slice(__x._M_slice), _M_array(__x._M_array)
  1040. {}
  1041. ~slice_array() {}
  1042. private:
  1043. slice_array(const slice& __slice, valarray<_Tp> &__array)
  1044. : _M_slice(__slice), _M_array(__array)
  1045. {}
  1046. slice _M_slice;
  1047. valarray<_Tp>& _M_array;
  1048. private:
  1049. // Disable default constructor and assignment
  1050. slice_array();
  1051. slice_array& operator=(const slice_array&);
  1052. };
  1053. // valarray member functions dealing with slice and slice_array
  1054. template <class _Tp>
  1055. inline valarray<_Tp>::valarray(const slice_array<_Tp>& __x)
  1056. : _Valarray_base<_Tp>(__x._M_slice.size()) {
  1057. typedef typename __type_traits<_Tp>::has_trivial_default_constructor
  1058. _Is_Trivial;
  1059. _M_initialize(_Is_Trivial());
  1060. *this = __x;
  1061. }
  1062. template <class _Tp>
  1063. inline slice_array<_Tp> valarray<_Tp>::operator[](slice __slice)
  1064. { return slice_array<_Tp>(__slice, *this); }
  1065. //----------------------------------------------------------------------
  1066. // gslice and gslice_array
  1067. template <class _Size>
  1068. struct _Gslice_Iter_tmpl;
  1069. class gslice {
  1070. friend struct _Gslice_Iter_tmpl<size_t>;
  1071. public:
  1072. gslice() : _M_start(0), _M_lengths(), _M_strides() {}
  1073. gslice(size_t __start,
  1074. const _Valarray_size_t& __lengths, const _Valarray_size_t& __strides)
  1075. : _M_start(__start), _M_lengths(__lengths), _M_strides(__strides)
  1076. {}
  1077. __TRIVIAL_DESTRUCTOR(gslice)
  1078. size_t start() const { return _M_start; }
  1079. _Valarray_size_t size() const { return _M_lengths; }
  1080. _Valarray_size_t stride() const { return _M_strides; }
  1081. // Extension: check for an empty gslice.
  1082. bool _M_empty() const { return _M_lengths.size() == 0; }
  1083. // Extension: number of indices this gslice represents. (For a degenerate
  1084. // gslice, they're not necessarily all distinct.)
  1085. size_t _M_size() const {
  1086. return !this->_M_empty()
  1087. ? accumulate(_M_lengths._M_first + 1,
  1088. _M_lengths._M_first + _M_lengths._M_size,
  1089. _M_lengths[0],
  1090. multiplies<size_t>())
  1091. : 0;
  1092. }
  1093. # ifndef __HP_aCC
  1094. private:
  1095. # endif
  1096. size_t _M_start;
  1097. _Valarray_size_t _M_lengths;
  1098. _Valarray_size_t _M_strides;
  1099. };
  1100. // This is not an STL iterator. It is constructed from a gslice, and it
  1101. // steps through the gslice indices in sequence. See 23.3.6 of the C++
  1102. // standard, paragraphs 2-3, for an explanation of the sequence. At
  1103. // each step we get two things: the ordinal (i.e. number of steps taken),
  1104. // and the one-dimensional index.
  1105. template <class _Size>
  1106. struct _Gslice_Iter_tmpl {
  1107. _Gslice_Iter_tmpl(const gslice& __gslice)
  1108. : _M_step(0), _M_1d_idx(__gslice.start()),
  1109. _M_indices(size_t(0), __gslice._M_lengths.size()),
  1110. _M_gslice(__gslice)
  1111. {}
  1112. bool _M_done() const { return _M_indices[0] == _M_gslice._M_lengths[0]; }
  1113. bool _M_incr();
  1114. _Size _M_step;
  1115. _Size _M_1d_idx;
  1116. valarray<_Size> _M_indices;
  1117. const gslice& _M_gslice;
  1118. };
  1119. typedef _Gslice_Iter_tmpl<size_t> _Gslice_Iter;
  1120. template <class _Tp>
  1121. class gslice_array {
  1122. friend class valarray<_Tp>;
  1123. public:
  1124. typedef _Tp value_type;
  1125. void operator= (const valarray<value_type>& __x) const {
  1126. if (!_M_gslice._M_empty()) {
  1127. _Gslice_Iter __i(_M_gslice);
  1128. do _M_array[__i._M_1d_idx] = __x[__i._M_step]; while(__i._M_incr());
  1129. }
  1130. }
  1131. void operator*= (const valarray<value_type>& __x) const {
  1132. if (!_M_gslice._M_empty()) {
  1133. _Gslice_Iter __i(_M_gslice);
  1134. do _M_array[__i._M_1d_idx] *= __x[__i._M_step]; while(__i._M_incr());
  1135. }
  1136. }
  1137. void operator/= (const valarray<value_type>& __x) const {
  1138. if (!_M_gslice._M_empty()) {
  1139. _Gslice_Iter __i(_M_gslice);
  1140. do _M_array[__i._M_1d_idx] /= __x[__i._M_step]; while(__i._M_incr());
  1141. }
  1142. }
  1143. void operator%= (const valarray<value_type>& __x) const {
  1144. if (!_M_gslice._M_empty()) {
  1145. _Gslice_Iter __i(_M_gslice);
  1146. do _M_array[__i._M_1d_idx] %= __x[__i._M_step]; while(__i._M_incr());
  1147. }
  1148. }
  1149. void operator+= (const valarray<value_type>& __x) const {
  1150. if (!_M_gslice._M_empty()) {
  1151. _Gslice_Iter __i(_M_gslice);
  1152. do _M_array[__i._M_1d_idx] += __x[__i._M_step]; while(__i._M_incr());
  1153. }
  1154. }
  1155. void operator-= (const valarray<value_type>& __x) const {
  1156. if (!_M_gslice._M_empty()) {
  1157. _Gslice_Iter __i(_M_gslice);
  1158. do _M_array[__i._M_1d_idx] -= __x[__i._M_step]; while(__i._M_incr());
  1159. }
  1160. }
  1161. void operator^= (const valarray<value_type>& __x) const {
  1162. if (!_M_gslice._M_empty()) {
  1163. _Gslice_Iter __i(_M_gslice);
  1164. do _M_array[__i._M_1d_idx] ^= __x[__i._M_step]; while(__i._M_incr());
  1165. }
  1166. }
  1167. void operator&= (const valarray<value_type>& __x) const {
  1168. if (!_M_gslice._M_empty()) {
  1169. _Gslice_Iter __i(_M_gslice);
  1170. do _M_array[__i._M_1d_idx] &= __x[__i._M_step]; while(__i._M_incr());
  1171. }
  1172. }
  1173. void operator|= (const valarray<value_type>& __x) const {
  1174. if (!_M_gslice._M_empty()) {
  1175. _Gslice_Iter __i(_M_gslice);
  1176. do _M_array[__i._M_1d_idx] |= __x[__i._M_step]; while(__i._M_incr());
  1177. }
  1178. }
  1179. void operator<<= (const valarray<value_type>& __x) const {
  1180. if (!_M_gslice._M_empty()) {
  1181. _Gslice_Iter __i(_M_gslice);
  1182. do _M_array[__i._M_1d_idx] <<= __x[__i._M_step]; while(__i._M_incr());
  1183. }
  1184. }
  1185. void operator>>= (const valarray<value_type>& __x) const {
  1186. if (!_M_gslice._M_empty()) {
  1187. _Gslice_Iter __i(_M_gslice);
  1188. do _M_array[__i._M_1d_idx] >>= __x[__i._M_step]; while(__i._M_incr());
  1189. }
  1190. }
  1191. void operator= (const value_type& __c) /*const could be const but standard says NO (26.3.7.4-1)*/ {
  1192. if (!_M_gslice._M_empty()) {
  1193. _Gslice_Iter __i(_M_gslice);
  1194. do _M_array[__i._M_1d_idx] = __c; while(__i._M_incr());
  1195. }
  1196. }
  1197. // C++ Standard defect 253, copy constructor must be public.
  1198. gslice_array(const gslice_array& __x)
  1199. : _M_gslice(__x._M_gslice), _M_array(__x._M_array)
  1200. {}
  1201. ~gslice_array() {}
  1202. private:
  1203. gslice_array(const gslice &__gslice, valarray<_Tp> &__array)
  1204. : _M_gslice(__gslice), _M_array(__array)
  1205. {}
  1206. gslice _M_gslice;
  1207. valarray<value_type>& _M_array;
  1208. private:
  1209. // Disable default constructor and assignment
  1210. gslice_array();
  1211. void operator=(const gslice_array<_Tp>&);
  1212. };
  1213. // valarray member functions dealing with gslice and gslice_array. Note
  1214. // that it is illegal (behavior is undefined) to construct a gslice_array
  1215. // from a degenerate gslice.
  1216. template <class _Tp>
  1217. inline valarray<_Tp>::valarray(const gslice_array<_Tp>& __x)
  1218. : _Valarray_base<_Tp>(__x._M_gslice._M_size()) {
  1219. typedef typename __type_traits<_Tp>::has_trivial_default_constructor
  1220. _Is_Trivial;
  1221. _M_initialize(_Is_Trivial());
  1222. *this = __x;
  1223. }
  1224. template <class _Tp>
  1225. inline gslice_array<_Tp> valarray<_Tp>::operator[](const gslice& __slice)
  1226. { return gslice_array<_Tp>(__slice, *this); }
  1227. //----------------------------------------------------------------------
  1228. // mask_array
  1229. template <class _Tp>
  1230. class mask_array {
  1231. friend class valarray<_Tp>;
  1232. public:
  1233. typedef _Tp value_type;
  1234. void operator=(const valarray<value_type>& __x) const {
  1235. size_t __idx = 0;
  1236. for (size_t __i = 0; __i < _M_array.size(); ++__i)
  1237. if (_M_mask[__i]) _M_array[__i] = __x[__idx++];
  1238. }
  1239. void operator*=(const valarray<value_type>& __x) const {
  1240. size_t __idx = 0;
  1241. for (size_t __i = 0; __i < _M_array.size(); ++__i)
  1242. if (_M_mask[__i]) _M_array[__i] *= __x[__idx++];
  1243. }
  1244. void operator/=(const valarray<value_type>& __x) const {
  1245. size_t __idx = 0;
  1246. for (size_t __i = 0; __i < _M_array.size(); ++__i)
  1247. if (_M_mask[__i]) _M_array[__i] /= __x[__idx++];
  1248. }
  1249. void operator%=(const valarray<value_type>& __x) const {
  1250. size_t __idx = 0;
  1251. for (size_t __i = 0; __i < _M_array.size(); ++__i)
  1252. if (_M_mask[__i]) _M_array[__i] %= __x[__idx++];
  1253. }
  1254. void operator+=(const valarray<value_type>& __x) const {
  1255. size_t __idx = 0;
  1256. for (size_t __i = 0; __i < _M_array.size(); ++__i)
  1257. if (_M_mask[__i]) _M_array[__i] += __x[__idx++];
  1258. }
  1259. void operator-=(const valarray<value_type>& __x) const {
  1260. size_t __idx = 0;
  1261. for (size_t __i = 0; __i < _M_array.size(); ++__i)
  1262. if (_M_mask[__i]) _M_array[__i] -= __x[__idx++];
  1263. }
  1264. void operator^=(const valarray<value_type>& __x) const {
  1265. size_t __idx = 0;
  1266. for (size_t __i = 0; __i < _M_array.size(); ++__i)
  1267. if (_M_mask[__i]) _M_array[__i] ^= __x[__idx++];
  1268. }
  1269. void operator&=(const valarray<value_type>& __x) const {
  1270. size_t __idx = 0;
  1271. for (size_t __i = 0; __i < _M_array.size(); ++__i)
  1272. if (_M_mask[__i]) _M_array[__i] &= __x[__idx++];
  1273. }
  1274. void operator|=(const valarray<value_type>& __x) const {
  1275. size_t __idx = 0;
  1276. for (size_t __i = 0; __i < _M_array.size(); ++__i)
  1277. if (_M_mask[__i]) _M_array[__i] |= __x[__idx++];
  1278. }
  1279. void operator<<=(const valarray<value_type>& __x) const {
  1280. size_t __idx = 0;
  1281. for (size_t __i = 0; __i < _M_array.size(); ++__i)
  1282. if (_M_mask[__i]) _M_array[__i] <<= __x[__idx++];
  1283. }
  1284. void operator>>=(const valarray<value_type>& __x) const {
  1285. size_t __idx = 0;
  1286. for (size_t __i = 0; __i < _M_array.size(); ++__i)
  1287. if (_M_mask[__i]) _M_array[__i] >>= __x[__idx++];
  1288. }
  1289. void operator=(const value_type& __c) const {
  1290. for (size_t __i = 0; __i < _M_array.size(); ++__i)
  1291. if (_M_mask[__i]) _M_array[__i] = __c;
  1292. }
  1293. // Extension: number of true values in the mask
  1294. size_t _M_num_true() const {
  1295. size_t __result = 0;
  1296. for (size_t __i = 0; __i < _M_mask.size(); ++__i)
  1297. if (_M_mask[__i]) ++__result;
  1298. return __result;
  1299. }
  1300. // C++ Standard defect 253, copy constructor must be public.
  1301. mask_array(const mask_array& __x)
  1302. : _M_mask(__x._M_mask), _M_array(__x._M_array)
  1303. {}
  1304. ~mask_array() {}
  1305. private:
  1306. mask_array(const _Valarray_bool& __mask, valarray<_Tp>& __array)
  1307. : _M_mask(__mask), _M_array(__array)
  1308. {}
  1309. _Valarray_bool _M_mask;
  1310. valarray<_Tp>& _M_array;
  1311. private:
  1312. // Disable default constructor and assignment
  1313. mask_array();
  1314. void operator=(const mask_array<_Tp>&);
  1315. };
  1316. // valarray member functions dealing with mask_array
  1317. template <class _Tp>
  1318. inline valarray<_Tp>::valarray(const mask_array<_Tp>& __x)
  1319. : _Valarray_base<_Tp>(__x._M_num_true()) {
  1320. typedef typename __type_traits<_Tp>::has_trivial_default_constructor
  1321. _Is_Trivial;
  1322. _M_initialize(_Is_Trivial());
  1323. *this = __x;
  1324. }
  1325. // Behavior is undefined if __x._M_num_true() != this->size()
  1326. template <class _Tp>
  1327. inline valarray<_Tp>& valarray<_Tp>::operator=(const mask_array<_Tp>& __x) {
  1328. size_t __idx = 0;
  1329. for (size_t __i = 0; __i < __x._M_array.size(); ++__i)
  1330. if (__x._M_mask[__i]) (*this)[__idx++] = __x._M_array[__i];
  1331. return *this;
  1332. }
  1333. template <class _Tp>
  1334. inline mask_array<_Tp> valarray<_Tp>::operator[](const _Valarray_bool& __mask) {
  1335. _STLP_ASSERT(__mask.size() == this->size())
  1336. return mask_array<_Tp>(__mask, *this);
  1337. }
  1338. //----------------------------------------------------------------------
  1339. // indirect_array
  1340. template <class _Tp>
  1341. class indirect_array {
  1342. friend class valarray<_Tp>;
  1343. public:
  1344. typedef _Tp value_type;
  1345. void operator=(const valarray<value_type>& __x) const {
  1346. for (size_t __i = 0; __i < _M_addr.size(); ++__i)
  1347. _M_array[_M_addr[__i]] = __x[__i];
  1348. }
  1349. void operator*=(const valarray<value_type>& __x) const {
  1350. for (size_t __i = 0; __i < _M_addr.size(); ++__i)
  1351. _M_array[_M_addr[__i]] *= __x[__i];
  1352. }
  1353. void operator/=(const valarray<value_type>& __x) const {
  1354. for (size_t __i = 0; __i < _M_addr.size(); ++__i)
  1355. _M_array[_M_addr[__i]] /= __x[__i];
  1356. }
  1357. void operator%=(const valarray<value_type>& __x) const {
  1358. for (size_t __i = 0; __i < _M_addr.size(); ++__i)
  1359. _M_array[_M_addr[__i]] %= __x[__i];
  1360. }
  1361. void operator+=(const valarray<value_type>& __x) const {
  1362. for (size_t __i = 0; __i < _M_addr.size(); ++__i)
  1363. _M_array[_M_addr[__i]] += __x[__i];
  1364. }
  1365. void operator-=(const valarray<value_type>& __x) const {
  1366. for (size_t __i = 0; __i < _M_addr.size(); ++__i)
  1367. _M_array[_M_addr[__i]] -= __x[__i];
  1368. }
  1369. void operator^=(const valarray<value_type>& __x) const {
  1370. for (size_t __i = 0; __i < _M_addr.size(); ++__i)
  1371. _M_array[_M_addr[__i]] ^= __x[__i];
  1372. }
  1373. void operator&=(const valarray<value_type>& __x) const {
  1374. for (size_t __i = 0; __i < _M_addr.size(); ++__i)
  1375. _M_array[_M_addr[__i]] &= __x[__i];
  1376. }
  1377. void operator|=(const valarray<value_type>& __x) const {
  1378. for (size_t __i = 0; __i < _M_addr.size(); ++__i)
  1379. _M_array[_M_addr[__i]] |= __x[__i];
  1380. }
  1381. void operator<<=(const valarray<value_type>& __x) const {
  1382. for (size_t __i = 0; __i < _M_addr.size(); ++__i)
  1383. _M_array[_M_addr[__i]] <<= __x[__i];
  1384. }
  1385. void operator>>=(const valarray<value_type>& __x) const {
  1386. for (size_t __i = 0; __i < _M_addr.size(); ++__i)
  1387. _M_array[_M_addr[__i]] >>= __x[__i];
  1388. }
  1389. void operator=(const value_type& __c) const {
  1390. for (size_t __i = 0; __i < _M_addr.size(); ++__i)
  1391. _M_array[_M_addr[__i]] = __c;
  1392. }
  1393. // C++ Standard defect 253, copy constructor must be public.
  1394. indirect_array(const indirect_array& __x)
  1395. : _M_addr(__x._M_addr), _M_array(__x._M_array)
  1396. {}
  1397. ~indirect_array() {}
  1398. private:
  1399. indirect_array(const _Valarray_size_t& __addr, valarray<_Tp>& __array)
  1400. : _M_addr(__addr), _M_array(__array)
  1401. {}
  1402. _Valarray_size_t _M_addr;
  1403. valarray<_Tp>& _M_array;
  1404. private:
  1405. // Disable default constructor and assignment
  1406. indirect_array();
  1407. void operator=(const indirect_array<_Tp>&);
  1408. };
  1409. // valarray member functions dealing with indirect_array
  1410. template <class _Tp>
  1411. inline valarray<_Tp>::valarray(const indirect_array<_Tp>& __x)
  1412. : _Valarray_base<_Tp>(__x._M_addr.size()) {
  1413. typedef typename __type_traits<_Tp>::has_trivial_default_constructor
  1414. _Is_Trivial;
  1415. _M_initialize(_Is_Trivial());
  1416. *this = __x;
  1417. }
  1418. template <class _Tp>
  1419. inline indirect_array<_Tp>
  1420. valarray<_Tp>::operator[](const _Valarray_size_t& __addr)
  1421. { return indirect_array<_Tp>(__addr, *this); }
  1422. _STLP_END_NAMESPACE
  1423. # if !defined (_STLP_LINK_TIME_INSTANTIATION)
  1424. # include <stl/_valarray.c>
  1425. # endif
  1426. #endif /* _STLP_VALARRAY */
  1427. // Local Variables:
  1428. // mode:C++
  1429. // End: