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