00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #ifndef _GLIBCXX_VALARRAY
00039 #define _GLIBCXX_VALARRAY 1
00040
00041 #pragma GCC system_header
00042
00043 #include <bits/c++config.h>
00044 #include <cstddef>
00045 #include <cmath>
00046 #include <algorithm>
00047 #include <debug/debug.h>
00048
00049 _GLIBCXX_BEGIN_NAMESPACE(std)
00050
00051 template<class _Clos, typename _Tp>
00052 class _Expr;
00053
00054 template<typename _Tp1, typename _Tp2>
00055 class _ValArray;
00056
00057 template<class _Oper, template<class, class> class _Meta, class _Dom>
00058 struct _UnClos;
00059
00060 template<class _Oper,
00061 template<class, class> class _Meta1,
00062 template<class, class> class _Meta2,
00063 class _Dom1, class _Dom2>
00064 class _BinClos;
00065
00066 template<template<class, class> class _Meta, class _Dom>
00067 class _SClos;
00068
00069 template<template<class, class> class _Meta, class _Dom>
00070 class _GClos;
00071
00072 template<template<class, class> class _Meta, class _Dom>
00073 class _IClos;
00074
00075 template<template<class, class> class _Meta, class _Dom>
00076 class _ValFunClos;
00077
00078 template<template<class, class> class _Meta, class _Dom>
00079 class _RefFunClos;
00080
00081 template<class _Tp> class valarray;
00082 class slice;
00083 template<class _Tp> class slice_array;
00084 class gslice;
00085 template<class _Tp> class gslice_array;
00086 template<class _Tp> class mask_array;
00087 template<class _Tp> class indirect_array;
00088
00089 _GLIBCXX_END_NAMESPACE
00090
00091 #include <bits/valarray_array.h>
00092 #include <bits/valarray_before.h>
00093
00094 _GLIBCXX_BEGIN_NAMESPACE(std)
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107 template<class _Tp>
00108 class valarray
00109 {
00110 template<class _Op>
00111 struct _UnaryOp
00112 {
00113 typedef typename __fun<_Op, _Tp>::result_type __rt;
00114 typedef _Expr<_UnClos<_Op, _ValArray, _Tp>, __rt> _Rt;
00115 };
00116 public:
00117 typedef _Tp value_type;
00118
00119
00120
00121 valarray();
00122
00123
00124 explicit valarray(size_t);
00125
00126
00127 valarray(const _Tp&, size_t);
00128
00129
00130 valarray(const _Tp* __restrict__, size_t);
00131
00132
00133 valarray(const valarray&);
00134
00135
00136 valarray(const slice_array<_Tp>&);
00137
00138
00139 valarray(const gslice_array<_Tp>&);
00140
00141
00142 valarray(const mask_array<_Tp>&);
00143
00144
00145 valarray(const indirect_array<_Tp>&);
00146
00147 template<class _Dom>
00148 valarray(const _Expr<_Dom, _Tp>& __e);
00149
00150 ~valarray();
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161 valarray<_Tp>& operator=(const valarray<_Tp>&);
00162
00163
00164
00165
00166
00167
00168
00169
00170 valarray<_Tp>& operator=(const _Tp&);
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180 valarray<_Tp>& operator=(const slice_array<_Tp>&);
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190 valarray<_Tp>& operator=(const gslice_array<_Tp>&);
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200 valarray<_Tp>& operator=(const mask_array<_Tp>&);
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210 valarray<_Tp>& operator=(const indirect_array<_Tp>&);
00211
00212 template<class _Dom> valarray<_Tp>&
00213 operator= (const _Expr<_Dom, _Tp>&);
00214
00215
00216
00217
00218
00219
00220
00221
00222 _Tp& operator[](size_t);
00223
00224
00225
00226 const _Tp& operator[](size_t) const;
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239 _Expr<_SClos<_ValArray, _Tp>, _Tp> operator[](slice) const;
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251 slice_array<_Tp> operator[](slice);
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262 _Expr<_GClos<_ValArray, _Tp>, _Tp> operator[](const gslice&) const;
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274 gslice_array<_Tp> operator[](const gslice&);
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288 valarray<_Tp> operator[](const valarray<bool>&) const;
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302 mask_array<_Tp> operator[](const valarray<bool>&);
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315 _Expr<_IClos<_ValArray, _Tp>, _Tp>
00316 operator[](const valarray<size_t>&) const;
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330 indirect_array<_Tp> operator[](const valarray<size_t>&);
00331
00332
00333
00334 typename _UnaryOp<__unary_plus>::_Rt operator+() const;
00335
00336
00337 typename _UnaryOp<__negate>::_Rt operator-() const;
00338
00339
00340 typename _UnaryOp<__bitwise_not>::_Rt operator~() const;
00341
00342
00343 typename _UnaryOp<__logical_not>::_Rt operator!() const;
00344
00345
00346
00347 valarray<_Tp>& operator*=(const _Tp&);
00348
00349
00350 valarray<_Tp>& operator/=(const _Tp&);
00351
00352
00353 valarray<_Tp>& operator%=(const _Tp&);
00354
00355
00356 valarray<_Tp>& operator+=(const _Tp&);
00357
00358
00359 valarray<_Tp>& operator-=(const _Tp&);
00360
00361
00362 valarray<_Tp>& operator^=(const _Tp&);
00363
00364
00365 valarray<_Tp>& operator&=(const _Tp&);
00366
00367
00368 valarray<_Tp>& operator|=(const _Tp&);
00369
00370
00371 valarray<_Tp>& operator<<=(const _Tp&);
00372
00373
00374 valarray<_Tp>& operator>>=(const _Tp&);
00375
00376
00377 valarray<_Tp>& operator*=(const valarray<_Tp>&);
00378
00379
00380 valarray<_Tp>& operator/=(const valarray<_Tp>&);
00381
00382
00383 valarray<_Tp>& operator%=(const valarray<_Tp>&);
00384
00385
00386 valarray<_Tp>& operator+=(const valarray<_Tp>&);
00387
00388
00389 valarray<_Tp>& operator-=(const valarray<_Tp>&);
00390
00391
00392 valarray<_Tp>& operator^=(const valarray<_Tp>&);
00393
00394
00395 valarray<_Tp>& operator|=(const valarray<_Tp>&);
00396
00397
00398 valarray<_Tp>& operator&=(const valarray<_Tp>&);
00399
00400
00401 valarray<_Tp>& operator<<=(const valarray<_Tp>&);
00402
00403
00404 valarray<_Tp>& operator>>=(const valarray<_Tp>&);
00405
00406 template<class _Dom>
00407 valarray<_Tp>& operator*=(const _Expr<_Dom, _Tp>&);
00408 template<class _Dom>
00409 valarray<_Tp>& operator/=(const _Expr<_Dom, _Tp>&);
00410 template<class _Dom>
00411 valarray<_Tp>& operator%=(const _Expr<_Dom, _Tp>&);
00412 template<class _Dom>
00413 valarray<_Tp>& operator+=(const _Expr<_Dom, _Tp>&);
00414 template<class _Dom>
00415 valarray<_Tp>& operator-=(const _Expr<_Dom, _Tp>&);
00416 template<class _Dom>
00417 valarray<_Tp>& operator^=(const _Expr<_Dom, _Tp>&);
00418 template<class _Dom>
00419 valarray<_Tp>& operator|=(const _Expr<_Dom, _Tp>&);
00420 template<class _Dom>
00421 valarray<_Tp>& operator&=(const _Expr<_Dom, _Tp>&);
00422 template<class _Dom>
00423 valarray<_Tp>& operator<<=(const _Expr<_Dom, _Tp>&);
00424 template<class _Dom>
00425 valarray<_Tp>& operator>>=(const _Expr<_Dom, _Tp>&);
00426
00427
00428
00429 size_t size() const;
00430
00431
00432
00433
00434
00435
00436
00437 _Tp sum() const;
00438
00439
00440 _Tp min() const;
00441
00442
00443 _Tp max() const;
00444
00445
00446
00447
00448
00449
00450
00451
00452
00453
00454
00455
00456
00457
00458
00459
00460 valarray<_Tp> shift (int) const;
00461
00462
00463
00464
00465
00466
00467
00468
00469
00470
00471
00472
00473
00474
00475
00476
00477 valarray<_Tp> cshift(int) const;
00478
00479
00480
00481
00482
00483
00484
00485
00486
00487
00488
00489 _Expr<_ValFunClos<_ValArray, _Tp>, _Tp> apply(_Tp func(_Tp)) const;
00490
00491
00492
00493
00494
00495
00496
00497
00498
00499
00500
00501 _Expr<_RefFunClos<_ValArray, _Tp>, _Tp> apply(_Tp func(const _Tp&)) const;
00502
00503
00504
00505
00506
00507
00508
00509
00510
00511
00512 void resize(size_t __size, _Tp __c = _Tp());
00513
00514 private:
00515 size_t _M_size;
00516 _Tp* __restrict__ _M_data;
00517
00518 friend class _Array<_Tp>;
00519 };
00520
00521 template<typename _Tp>
00522 inline const _Tp&
00523 valarray<_Tp>::operator[](size_t __i) const
00524 {
00525 __glibcxx_requires_subscript(__i);
00526 return _M_data[__i];
00527 }
00528
00529 template<typename _Tp>
00530 inline _Tp&
00531 valarray<_Tp>::operator[](size_t __i)
00532 {
00533 __glibcxx_requires_subscript(__i);
00534 return _M_data[__i];
00535 }
00536
00537 _GLIBCXX_END_NAMESPACE
00538
00539 #include <bits/valarray_after.h>
00540 #include <bits/slice_array.h>
00541 #include <bits/gslice.h>
00542 #include <bits/gslice_array.h>
00543 #include <bits/mask_array.h>
00544 #include <bits/indirect_array.h>
00545
00546 _GLIBCXX_BEGIN_NAMESPACE(std)
00547
00548 template<typename _Tp>
00549 inline
00550 valarray<_Tp>::valarray() : _M_size(0), _M_data(0) {}
00551
00552 template<typename _Tp>
00553 inline
00554 valarray<_Tp>::valarray(size_t __n)
00555 : _M_size(__n), _M_data(__valarray_get_storage<_Tp>(__n))
00556 { std::__valarray_default_construct(_M_data, _M_data + __n); }
00557
00558 template<typename _Tp>
00559 inline
00560 valarray<_Tp>::valarray(const _Tp& __t, size_t __n)
00561 : _M_size(__n), _M_data(__valarray_get_storage<_Tp>(__n))
00562 { std::__valarray_fill_construct(_M_data, _M_data + __n, __t); }
00563
00564 template<typename _Tp>
00565 inline
00566 valarray<_Tp>::valarray(const _Tp* __restrict__ __p, size_t __n)
00567 : _M_size(__n), _M_data(__valarray_get_storage<_Tp>(__n))
00568 {
00569 _GLIBCXX_DEBUG_ASSERT(__p != 0 || __n == 0);
00570 std::__valarray_copy_construct(__p, __p + __n, _M_data);
00571 }
00572
00573 template<typename _Tp>
00574 inline
00575 valarray<_Tp>::valarray(const valarray<_Tp>& __v)
00576 : _M_size(__v._M_size), _M_data(__valarray_get_storage<_Tp>(__v._M_size))
00577 { std::__valarray_copy_construct(__v._M_data, __v._M_data + _M_size,
00578 _M_data); }
00579
00580 template<typename _Tp>
00581 inline
00582 valarray<_Tp>::valarray(const slice_array<_Tp>& __sa)
00583 : _M_size(__sa._M_sz), _M_data(__valarray_get_storage<_Tp>(__sa._M_sz))
00584 {
00585 std::__valarray_copy_construct
00586 (__sa._M_array, __sa._M_sz, __sa._M_stride, _Array<_Tp>(_M_data));
00587 }
00588
00589 template<typename _Tp>
00590 inline
00591 valarray<_Tp>::valarray(const gslice_array<_Tp>& __ga)
00592 : _M_size(__ga._M_index.size()),
00593 _M_data(__valarray_get_storage<_Tp>(_M_size))
00594 {
00595 std::__valarray_copy_construct
00596 (__ga._M_array, _Array<size_t>(__ga._M_index),
00597 _Array<_Tp>(_M_data), _M_size);
00598 }
00599
00600 template<typename _Tp>
00601 inline
00602 valarray<_Tp>::valarray(const mask_array<_Tp>& __ma)
00603 : _M_size(__ma._M_sz), _M_data(__valarray_get_storage<_Tp>(__ma._M_sz))
00604 {
00605 std::__valarray_copy_construct
00606 (__ma._M_array, __ma._M_mask, _Array<_Tp>(_M_data), _M_size);
00607 }
00608
00609 template<typename _Tp>
00610 inline
00611 valarray<_Tp>::valarray(const indirect_array<_Tp>& __ia)
00612 : _M_size(__ia._M_sz), _M_data(__valarray_get_storage<_Tp>(__ia._M_sz))
00613 {
00614 std::__valarray_copy_construct
00615 (__ia._M_array, __ia._M_index, _Array<_Tp>(_M_data), _M_size);
00616 }
00617
00618 template<typename _Tp> template<class _Dom>
00619 inline
00620 valarray<_Tp>::valarray(const _Expr<_Dom, _Tp>& __e)
00621 : _M_size(__e.size()), _M_data(__valarray_get_storage<_Tp>(_M_size))
00622 { std::__valarray_copy_construct(__e, _M_size, _Array<_Tp>(_M_data)); }
00623
00624 template<typename _Tp>
00625 inline
00626 valarray<_Tp>::~valarray()
00627 {
00628 std::__valarray_destroy_elements(_M_data, _M_data + _M_size);
00629 std::__valarray_release_memory(_M_data);
00630 }
00631
00632 template<typename _Tp>
00633 inline valarray<_Tp>&
00634 valarray<_Tp>::operator=(const valarray<_Tp>& __v)
00635 {
00636 _GLIBCXX_DEBUG_ASSERT(_M_size == __v._M_size);
00637 std::__valarray_copy(__v._M_data, _M_size, _M_data);
00638 return *this;
00639 }
00640
00641 template<typename _Tp>
00642 inline valarray<_Tp>&
00643 valarray<_Tp>::operator=(const _Tp& __t)
00644 {
00645 std::__valarray_fill(_M_data, _M_size, __t);
00646 return *this;
00647 }
00648
00649 template<typename _Tp>
00650 inline valarray<_Tp>&
00651 valarray<_Tp>::operator=(const slice_array<_Tp>& __sa)
00652 {
00653 _GLIBCXX_DEBUG_ASSERT(_M_size == __sa._M_sz);
00654 std::__valarray_copy(__sa._M_array, __sa._M_sz,
00655 __sa._M_stride, _Array<_Tp>(_M_data));
00656 return *this;
00657 }
00658
00659 template<typename _Tp>
00660 inline valarray<_Tp>&
00661 valarray<_Tp>::operator=(const gslice_array<_Tp>& __ga)
00662 {
00663 _GLIBCXX_DEBUG_ASSERT(_M_size == __ga._M_index.size());
00664 std::__valarray_copy(__ga._M_array, _Array<size_t>(__ga._M_index),
00665 _Array<_Tp>(_M_data), _M_size);
00666 return *this;
00667 }
00668
00669 template<typename _Tp>
00670 inline valarray<_Tp>&
00671 valarray<_Tp>::operator=(const mask_array<_Tp>& __ma)
00672 {
00673 _GLIBCXX_DEBUG_ASSERT(_M_size == __ma._M_sz);
00674 std::__valarray_copy(__ma._M_array, __ma._M_mask,
00675 _Array<_Tp>(_M_data), _M_size);
00676 return *this;
00677 }
00678
00679 template<typename _Tp>
00680 inline valarray<_Tp>&
00681 valarray<_Tp>::operator=(const indirect_array<_Tp>& __ia)
00682 {
00683 _GLIBCXX_DEBUG_ASSERT(_M_size == __ia._M_sz);
00684 std::__valarray_copy(__ia._M_array, __ia._M_index,
00685 _Array<_Tp>(_M_data), _M_size);
00686 return *this;
00687 }
00688
00689 template<typename _Tp> template<class _Dom>
00690 inline valarray<_Tp>&
00691 valarray<_Tp>::operator=(const _Expr<_Dom, _Tp>& __e)
00692 {
00693 _GLIBCXX_DEBUG_ASSERT(_M_size == __e.size());
00694 std::__valarray_copy(__e, _M_size, _Array<_Tp>(_M_data));
00695 return *this;
00696 }
00697
00698 template<typename _Tp>
00699 inline _Expr<_SClos<_ValArray,_Tp>, _Tp>
00700 valarray<_Tp>::operator[](slice __s) const
00701 {
00702 typedef _SClos<_ValArray,_Tp> _Closure;
00703 return _Expr<_Closure, _Tp>(_Closure (_Array<_Tp>(_M_data), __s));
00704 }
00705
00706 template<typename _Tp>
00707 inline slice_array<_Tp>
00708 valarray<_Tp>::operator[](slice __s)
00709 { return slice_array<_Tp>(_Array<_Tp>(_M_data), __s); }
00710
00711 template<typename _Tp>
00712 inline _Expr<_GClos<_ValArray,_Tp>, _Tp>
00713 valarray<_Tp>::operator[](const gslice& __gs) const
00714 {
00715 typedef _GClos<_ValArray,_Tp> _Closure;
00716 return _Expr<_Closure, _Tp>
00717 (_Closure(_Array<_Tp>(_M_data), __gs._M_index->_M_index));
00718 }
00719
00720 template<typename _Tp>
00721 inline gslice_array<_Tp>
00722 valarray<_Tp>::operator[](const gslice& __gs)
00723 {
00724 return gslice_array<_Tp>
00725 (_Array<_Tp>(_M_data), __gs._M_index->_M_index);
00726 }
00727
00728 template<typename _Tp>
00729 inline valarray<_Tp>
00730 valarray<_Tp>::operator[](const valarray<bool>& __m) const
00731 {
00732 size_t __s = 0;
00733 size_t __e = __m.size();
00734 for (size_t __i=0; __i<__e; ++__i)
00735 if (__m[__i]) ++__s;
00736 return valarray<_Tp>(mask_array<_Tp>(_Array<_Tp>(_M_data), __s,
00737 _Array<bool> (__m)));
00738 }
00739
00740 template<typename _Tp>
00741 inline mask_array<_Tp>
00742 valarray<_Tp>::operator[](const valarray<bool>& __m)
00743 {
00744 size_t __s = 0;
00745 size_t __e = __m.size();
00746 for (size_t __i=0; __i<__e; ++__i)
00747 if (__m[__i]) ++__s;
00748 return mask_array<_Tp>(_Array<_Tp>(_M_data), __s, _Array<bool>(__m));
00749 }
00750
00751 template<typename _Tp>
00752 inline _Expr<_IClos<_ValArray,_Tp>, _Tp>
00753 valarray<_Tp>::operator[](const valarray<size_t>& __i) const
00754 {
00755 typedef _IClos<_ValArray,_Tp> _Closure;
00756 return _Expr<_Closure, _Tp>(_Closure(*this, __i));
00757 }
00758
00759 template<typename _Tp>
00760 inline indirect_array<_Tp>
00761 valarray<_Tp>::operator[](const valarray<size_t>& __i)
00762 {
00763 return indirect_array<_Tp>(_Array<_Tp>(_M_data), __i.size(),
00764 _Array<size_t>(__i));
00765 }
00766
00767 template<class _Tp>
00768 inline size_t
00769 valarray<_Tp>::size() const
00770 { return _M_size; }
00771
00772 template<class _Tp>
00773 inline _Tp
00774 valarray<_Tp>::sum() const
00775 {
00776 _GLIBCXX_DEBUG_ASSERT(_M_size > 0);
00777 return std::__valarray_sum(_M_data, _M_data + _M_size);
00778 }
00779
00780 template<class _Tp>
00781 inline valarray<_Tp>
00782 valarray<_Tp>::shift(int __n) const
00783 {
00784 valarray<_Tp> __ret;
00785
00786 if (_M_size == 0)
00787 return __ret;
00788
00789 _Tp* __restrict__ __tmp_M_data =
00790 std::__valarray_get_storage<_Tp>(_M_size);
00791
00792 if (__n == 0)
00793 std::__valarray_copy_construct(_M_data,
00794 _M_data + _M_size, __tmp_M_data);
00795 else if (__n > 0)
00796 {
00797 if (size_t(__n) > _M_size)
00798 __n = int(_M_size);
00799
00800 std::__valarray_copy_construct(_M_data + __n,
00801 _M_data + _M_size, __tmp_M_data);
00802 std::__valarray_default_construct(__tmp_M_data + _M_size - __n,
00803 __tmp_M_data + _M_size);
00804 }
00805 else
00806 {
00807 if (-size_t(__n) > _M_size)
00808 __n = -int(_M_size);
00809
00810 std::__valarray_copy_construct(_M_data, _M_data + _M_size + __n,
00811 __tmp_M_data - __n);
00812 std::__valarray_default_construct(__tmp_M_data,
00813 __tmp_M_data - __n);
00814 }
00815
00816 __ret._M_size = _M_size;
00817 __ret._M_data = __tmp_M_data;
00818 return __ret;
00819 }
00820
00821 template<class _Tp>
00822 inline valarray<_Tp>
00823 valarray<_Tp>::cshift(int __n) const
00824 {
00825 valarray<_Tp> __ret;
00826
00827 if (_M_size == 0)
00828 return __ret;
00829
00830 _Tp* __restrict__ __tmp_M_data =
00831 std::__valarray_get_storage<_Tp>(_M_size);
00832
00833 if (__n == 0)
00834 std::__valarray_copy_construct(_M_data,
00835 _M_data + _M_size, __tmp_M_data);
00836 else if (__n > 0)
00837 {
00838 if (size_t(__n) > _M_size)
00839 __n = int(__n % _M_size);
00840
00841 std::__valarray_copy_construct(_M_data, _M_data + __n,
00842 __tmp_M_data + _M_size - __n);
00843 std::__valarray_copy_construct(_M_data + __n, _M_data + _M_size,
00844 __tmp_M_data);
00845 }
00846 else
00847 {
00848 if (-size_t(__n) > _M_size)
00849 __n = -int(-size_t(__n) % _M_size);
00850
00851 std::__valarray_copy_construct(_M_data + _M_size + __n,
00852 _M_data + _M_size, __tmp_M_data);
00853 std::__valarray_copy_construct(_M_data, _M_data + _M_size + __n,
00854 __tmp_M_data - __n);
00855 }
00856
00857 __ret._M_size = _M_size;
00858 __ret._M_data = __tmp_M_data;
00859 return __ret;
00860 }
00861
00862 template<class _Tp>
00863 inline void
00864 valarray<_Tp>::resize(size_t __n, _Tp __c)
00865 {
00866
00867
00868
00869 std::__valarray_destroy_elements(_M_data, _M_data + _M_size);
00870 if (_M_size != __n)
00871 {
00872 std::__valarray_release_memory(_M_data);
00873 _M_size = __n;
00874 _M_data = __valarray_get_storage<_Tp>(__n);
00875 }
00876 std::__valarray_fill_construct(_M_data, _M_data + __n, __c);
00877 }
00878
00879 template<typename _Tp>
00880 inline _Tp
00881 valarray<_Tp>::min() const
00882 {
00883 _GLIBCXX_DEBUG_ASSERT(_M_size > 0);
00884 return *std::min_element(_M_data, _M_data + _M_size);
00885 }
00886
00887 template<typename _Tp>
00888 inline _Tp
00889 valarray<_Tp>::max() const
00890 {
00891 _GLIBCXX_DEBUG_ASSERT(_M_size > 0);
00892 return *std::max_element(_M_data, _M_data + _M_size);
00893 }
00894
00895 template<class _Tp>
00896 inline _Expr<_ValFunClos<_ValArray, _Tp>, _Tp>
00897 valarray<_Tp>::apply(_Tp func(_Tp)) const
00898 {
00899 typedef _ValFunClos<_ValArray, _Tp> _Closure;
00900 return _Expr<_Closure, _Tp>(_Closure(*this, func));
00901 }
00902
00903 template<class _Tp>
00904 inline _Expr<_RefFunClos<_ValArray, _Tp>, _Tp>
00905 valarray<_Tp>::apply(_Tp func(const _Tp &)) const
00906 {
00907 typedef _RefFunClos<_ValArray, _Tp> _Closure;
00908 return _Expr<_Closure, _Tp>(_Closure(*this, func));
00909 }
00910
00911 #define _DEFINE_VALARRAY_UNARY_OPERATOR(_Op, _Name) \
00912 template<typename _Tp> \
00913 inline typename valarray<_Tp>::template _UnaryOp<_Name>::_Rt \
00914 valarray<_Tp>::operator _Op() const \
00915 { \
00916 typedef _UnClos<_Name, _ValArray, _Tp> _Closure; \
00917 typedef typename __fun<_Name, _Tp>::result_type _Rt; \
00918 return _Expr<_Closure, _Rt>(_Closure(*this)); \
00919 }
00920
00921 _DEFINE_VALARRAY_UNARY_OPERATOR(+, __unary_plus)
00922 _DEFINE_VALARRAY_UNARY_OPERATOR(-, __negate)
00923 _DEFINE_VALARRAY_UNARY_OPERATOR(~, __bitwise_not)
00924 _DEFINE_VALARRAY_UNARY_OPERATOR (!, __logical_not)
00925
00926 #undef _DEFINE_VALARRAY_UNARY_OPERATOR
00927
00928 #define _DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(_Op, _Name) \
00929 template<class _Tp> \
00930 inline valarray<_Tp>& \
00931 valarray<_Tp>::operator _Op##=(const _Tp &__t) \
00932 { \
00933 _Array_augmented_##_Name(_Array<_Tp>(_M_data), _M_size, __t); \
00934 return *this; \
00935 } \
00936 \
00937 template<class _Tp> \
00938 inline valarray<_Tp>& \
00939 valarray<_Tp>::operator _Op##=(const valarray<_Tp> &__v) \
00940 { \
00941 _GLIBCXX_DEBUG_ASSERT(_M_size == __v._M_size); \
00942 _Array_augmented_##_Name(_Array<_Tp>(_M_data), _M_size, \
00943 _Array<_Tp>(__v._M_data)); \
00944 return *this; \
00945 }
00946
00947 _DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(+, __plus)
00948 _DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(-, __minus)
00949 _DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(*, __multiplies)
00950 _DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(/, __divides)
00951 _DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(%, __modulus)
00952 _DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(^, __bitwise_xor)
00953 _DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(&, __bitwise_and)
00954 _DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(|, __bitwise_or)
00955 _DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(<<, __shift_left)
00956 _DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(>>, __shift_right)
00957
00958 #undef _DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT
00959
00960 #define _DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(_Op, _Name) \
00961 template<class _Tp> template<class _Dom> \
00962 inline valarray<_Tp>& \
00963 valarray<_Tp>::operator _Op##=(const _Expr<_Dom, _Tp>& __e) \
00964 { \
00965 _Array_augmented_##_Name(_Array<_Tp>(_M_data), __e, _M_size); \
00966 return *this; \
00967 }
00968
00969 _DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(+, __plus)
00970 _DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(-, __minus)
00971 _DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(*, __multiplies)
00972 _DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(/, __divides)
00973 _DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(%, __modulus)
00974 _DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(^, __bitwise_xor)
00975 _DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(&, __bitwise_and)
00976 _DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(|, __bitwise_or)
00977 _DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(<<, __shift_left)
00978 _DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(>>, __shift_right)
00979
00980 #undef _DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT
00981
00982
00983 #define _DEFINE_BINARY_OPERATOR(_Op, _Name) \
00984 template<typename _Tp> \
00985 inline _Expr<_BinClos<_Name, _ValArray, _ValArray, _Tp, _Tp>, \
00986 typename __fun<_Name, _Tp>::result_type> \
00987 operator _Op(const valarray<_Tp>& __v, const valarray<_Tp>& __w) \
00988 { \
00989 _GLIBCXX_DEBUG_ASSERT(__v.size() == __w.size()); \
00990 typedef _BinClos<_Name, _ValArray, _ValArray, _Tp, _Tp> _Closure; \
00991 typedef typename __fun<_Name, _Tp>::result_type _Rt; \
00992 return _Expr<_Closure, _Rt>(_Closure(__v, __w)); \
00993 } \
00994 \
00995 template<typename _Tp> \
00996 inline _Expr<_BinClos<_Name, _ValArray,_Constant, _Tp, _Tp>, \
00997 typename __fun<_Name, _Tp>::result_type> \
00998 operator _Op(const valarray<_Tp>& __v, const _Tp& __t) \
00999 { \
01000 typedef _BinClos<_Name, _ValArray, _Constant, _Tp, _Tp> _Closure; \
01001 typedef typename __fun<_Name, _Tp>::result_type _Rt; \
01002 return _Expr<_Closure, _Rt>(_Closure(__v, __t)); \
01003 } \
01004 \
01005 template<typename _Tp> \
01006 inline _Expr<_BinClos<_Name, _Constant, _ValArray, _Tp, _Tp>, \
01007 typename __fun<_Name, _Tp>::result_type> \
01008 operator _Op(const _Tp& __t, const valarray<_Tp>& __v) \
01009 { \
01010 typedef _BinClos<_Name, _Constant, _ValArray, _Tp, _Tp> _Closure; \
01011 typedef typename __fun<_Name, _Tp>::result_type _Rt; \
01012 return _Expr<_Closure, _Rt>(_Closure(__t, __v)); \
01013 }
01014
01015 _DEFINE_BINARY_OPERATOR(+, __plus)
01016 _DEFINE_BINARY_OPERATOR(-, __minus)
01017 _DEFINE_BINARY_OPERATOR(*, __multiplies)
01018 _DEFINE_BINARY_OPERATOR(/, __divides)
01019 _DEFINE_BINARY_OPERATOR(%, __modulus)
01020 _DEFINE_BINARY_OPERATOR(^, __bitwise_xor)
01021 _DEFINE_BINARY_OPERATOR(&, __bitwise_and)
01022 _DEFINE_BINARY_OPERATOR(|, __bitwise_or)
01023 _DEFINE_BINARY_OPERATOR(<<, __shift_left)
01024 _DEFINE_BINARY_OPERATOR(>>, __shift_right)
01025 _DEFINE_BINARY_OPERATOR(&&, __logical_and)
01026 _DEFINE_BINARY_OPERATOR(||, __logical_or)
01027 _DEFINE_BINARY_OPERATOR(==, __equal_to)
01028 _DEFINE_BINARY_OPERATOR(!=, __not_equal_to)
01029 _DEFINE_BINARY_OPERATOR(<, __less)
01030 _DEFINE_BINARY_OPERATOR(>, __greater)
01031 _DEFINE_BINARY_OPERATOR(<=, __less_equal)
01032 _DEFINE_BINARY_OPERATOR(>=, __greater_equal)
01033
01034 #undef _DEFINE_BINARY_OPERATOR
01035
01036 _GLIBCXX_END_NAMESPACE
01037
01038 #endif