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 return *this;
00685 }
00686 #endif
00687
00688 template<typename _Tp>
00689 inline valarray<_Tp>&
00690 valarray<_Tp>::operator=(const _Tp& __t)
00691 {
00692 std::__valarray_fill(_M_data, _M_size, __t);
00693 return *this;
00694 }
00695
00696 template<typename _Tp>
00697 inline valarray<_Tp>&
00698 valarray<_Tp>::operator=(const slice_array<_Tp>& __sa)
00699 {
00700 _GLIBCXX_DEBUG_ASSERT(_M_size == __sa._M_sz);
00701 std::__valarray_copy(__sa._M_array, __sa._M_sz,
00702 __sa._M_stride, _Array<_Tp>(_M_data));
00703 return *this;
00704 }
00705
00706 template<typename _Tp>
00707 inline valarray<_Tp>&
00708 valarray<_Tp>::operator=(const gslice_array<_Tp>& __ga)
00709 {
00710 _GLIBCXX_DEBUG_ASSERT(_M_size == __ga._M_index.size());
00711 std::__valarray_copy(__ga._M_array, _Array<size_t>(__ga._M_index),
00712 _Array<_Tp>(_M_data), _M_size);
00713 return *this;
00714 }
00715
00716 template<typename _Tp>
00717 inline valarray<_Tp>&
00718 valarray<_Tp>::operator=(const mask_array<_Tp>& __ma)
00719 {
00720 _GLIBCXX_DEBUG_ASSERT(_M_size == __ma._M_sz);
00721 std::__valarray_copy(__ma._M_array, __ma._M_mask,
00722 _Array<_Tp>(_M_data), _M_size);
00723 return *this;
00724 }
00725
00726 template<typename _Tp>
00727 inline valarray<_Tp>&
00728 valarray<_Tp>::operator=(const indirect_array<_Tp>& __ia)
00729 {
00730 _GLIBCXX_DEBUG_ASSERT(_M_size == __ia._M_sz);
00731 std::__valarray_copy(__ia._M_array, __ia._M_index,
00732 _Array<_Tp>(_M_data), _M_size);
00733 return *this;
00734 }
00735
00736 template<typename _Tp> template<class _Dom>
00737 inline valarray<_Tp>&
00738 valarray<_Tp>::operator=(const _Expr<_Dom, _Tp>& __e)
00739 {
00740 _GLIBCXX_DEBUG_ASSERT(_M_size == __e.size());
00741 std::__valarray_copy(__e, _M_size, _Array<_Tp>(_M_data));
00742 return *this;
00743 }
00744
00745 template<typename _Tp>
00746 inline _Expr<_SClos<_ValArray,_Tp>, _Tp>
00747 valarray<_Tp>::operator[](slice __s) const
00748 {
00749 typedef _SClos<_ValArray,_Tp> _Closure;
00750 return _Expr<_Closure, _Tp>(_Closure (_Array<_Tp>(_M_data), __s));
00751 }
00752
00753 template<typename _Tp>
00754 inline slice_array<_Tp>
00755 valarray<_Tp>::operator[](slice __s)
00756 { return slice_array<_Tp>(_Array<_Tp>(_M_data), __s); }
00757
00758 template<typename _Tp>
00759 inline _Expr<_GClos<_ValArray,_Tp>, _Tp>
00760 valarray<_Tp>::operator[](const gslice& __gs) const
00761 {
00762 typedef _GClos<_ValArray,_Tp> _Closure;
00763 return _Expr<_Closure, _Tp>
00764 (_Closure(_Array<_Tp>(_M_data), __gs._M_index->_M_index));
00765 }
00766
00767 template<typename _Tp>
00768 inline gslice_array<_Tp>
00769 valarray<_Tp>::operator[](const gslice& __gs)
00770 {
00771 return gslice_array<_Tp>
00772 (_Array<_Tp>(_M_data), __gs._M_index->_M_index);
00773 }
00774
00775 template<typename _Tp>
00776 inline valarray<_Tp>
00777 valarray<_Tp>::operator[](const valarray<bool>& __m) const
00778 {
00779 size_t __s = 0;
00780 size_t __e = __m.size();
00781 for (size_t __i=0; __i<__e; ++__i)
00782 if (__m[__i]) ++__s;
00783 return valarray<_Tp>(mask_array<_Tp>(_Array<_Tp>(_M_data), __s,
00784 _Array<bool> (__m)));
00785 }
00786
00787 template<typename _Tp>
00788 inline mask_array<_Tp>
00789 valarray<_Tp>::operator[](const valarray<bool>& __m)
00790 {
00791 size_t __s = 0;
00792 size_t __e = __m.size();
00793 for (size_t __i=0; __i<__e; ++__i)
00794 if (__m[__i]) ++__s;
00795 return mask_array<_Tp>(_Array<_Tp>(_M_data), __s, _Array<bool>(__m));
00796 }
00797
00798 template<typename _Tp>
00799 inline _Expr<_IClos<_ValArray,_Tp>, _Tp>
00800 valarray<_Tp>::operator[](const valarray<size_t>& __i) const
00801 {
00802 typedef _IClos<_ValArray,_Tp> _Closure;
00803 return _Expr<_Closure, _Tp>(_Closure(*this, __i));
00804 }
00805
00806 template<typename _Tp>
00807 inline indirect_array<_Tp>
00808 valarray<_Tp>::operator[](const valarray<size_t>& __i)
00809 {
00810 return indirect_array<_Tp>(_Array<_Tp>(_M_data), __i.size(),
00811 _Array<size_t>(__i));
00812 }
00813
00814 template<class _Tp>
00815 inline size_t
00816 valarray<_Tp>::size() const
00817 { return _M_size; }
00818
00819 template<class _Tp>
00820 inline _Tp
00821 valarray<_Tp>::sum() const
00822 {
00823 _GLIBCXX_DEBUG_ASSERT(_M_size > 0);
00824 return std::__valarray_sum(_M_data, _M_data + _M_size);
00825 }
00826
00827 template<class _Tp>
00828 inline valarray<_Tp>
00829 valarray<_Tp>::shift(int __n) const
00830 {
00831 valarray<_Tp> __ret;
00832
00833 if (_M_size == 0)
00834 return __ret;
00835
00836 _Tp* __restrict__ __tmp_M_data =
00837 std::__valarray_get_storage<_Tp>(_M_size);
00838
00839 if (__n == 0)
00840 std::__valarray_copy_construct(_M_data,
00841 _M_data + _M_size, __tmp_M_data);
00842 else if (__n > 0)
00843 {
00844 if (size_t(__n) > _M_size)
00845 __n = int(_M_size);
00846
00847 std::__valarray_copy_construct(_M_data + __n,
00848 _M_data + _M_size, __tmp_M_data);
00849 std::__valarray_default_construct(__tmp_M_data + _M_size - __n,
00850 __tmp_M_data + _M_size);
00851 }
00852 else
00853 {
00854 if (-size_t(__n) > _M_size)
00855 __n = -int(_M_size);
00856
00857 std::__valarray_copy_construct(_M_data, _M_data + _M_size + __n,
00858 __tmp_M_data - __n);
00859 std::__valarray_default_construct(__tmp_M_data,
00860 __tmp_M_data - __n);
00861 }
00862
00863 __ret._M_size = _M_size;
00864 __ret._M_data = __tmp_M_data;
00865 return __ret;
00866 }
00867
00868 template<class _Tp>
00869 inline valarray<_Tp>
00870 valarray<_Tp>::cshift(int __n) const
00871 {
00872 valarray<_Tp> __ret;
00873
00874 if (_M_size == 0)
00875 return __ret;
00876
00877 _Tp* __restrict__ __tmp_M_data =
00878 std::__valarray_get_storage<_Tp>(_M_size);
00879
00880 if (__n == 0)
00881 std::__valarray_copy_construct(_M_data,
00882 _M_data + _M_size, __tmp_M_data);
00883 else if (__n > 0)
00884 {
00885 if (size_t(__n) > _M_size)
00886 __n = int(__n % _M_size);
00887
00888 std::__valarray_copy_construct(_M_data, _M_data + __n,
00889 __tmp_M_data + _M_size - __n);
00890 std::__valarray_copy_construct(_M_data + __n, _M_data + _M_size,
00891 __tmp_M_data);
00892 }
00893 else
00894 {
00895 if (-size_t(__n) > _M_size)
00896 __n = -int(-size_t(__n) % _M_size);
00897
00898 std::__valarray_copy_construct(_M_data + _M_size + __n,
00899 _M_data + _M_size, __tmp_M_data);
00900 std::__valarray_copy_construct(_M_data, _M_data + _M_size + __n,
00901 __tmp_M_data - __n);
00902 }
00903
00904 __ret._M_size = _M_size;
00905 __ret._M_data = __tmp_M_data;
00906 return __ret;
00907 }
00908
00909 template<class _Tp>
00910 inline void
00911 valarray<_Tp>::resize(size_t __n, _Tp __c)
00912 {
00913
00914
00915
00916 std::__valarray_destroy_elements(_M_data, _M_data + _M_size);
00917 if (_M_size != __n)
00918 {
00919 std::__valarray_release_memory(_M_data);
00920 _M_size = __n;
00921 _M_data = __valarray_get_storage<_Tp>(__n);
00922 }
00923 std::__valarray_fill_construct(_M_data, _M_data + __n, __c);
00924 }
00925
00926 template<typename _Tp>
00927 inline _Tp
00928 valarray<_Tp>::min() const
00929 {
00930 _GLIBCXX_DEBUG_ASSERT(_M_size > 0);
00931 return *std::min_element(_M_data, _M_data + _M_size);
00932 }
00933
00934 template<typename _Tp>
00935 inline _Tp
00936 valarray<_Tp>::max() const
00937 {
00938 _GLIBCXX_DEBUG_ASSERT(_M_size > 0);
00939 return *std::max_element(_M_data, _M_data + _M_size);
00940 }
00941
00942 template<class _Tp>
00943 inline _Expr<_ValFunClos<_ValArray, _Tp>, _Tp>
00944 valarray<_Tp>::apply(_Tp func(_Tp)) const
00945 {
00946 typedef _ValFunClos<_ValArray, _Tp> _Closure;
00947 return _Expr<_Closure, _Tp>(_Closure(*this, func));
00948 }
00949
00950 template<class _Tp>
00951 inline _Expr<_RefFunClos<_ValArray, _Tp>, _Tp>
00952 valarray<_Tp>::apply(_Tp func(const _Tp &)) const
00953 {
00954 typedef _RefFunClos<_ValArray, _Tp> _Closure;
00955 return _Expr<_Closure, _Tp>(_Closure(*this, func));
00956 }
00957
00958 #define _DEFINE_VALARRAY_UNARY_OPERATOR(_Op, _Name) \
00959 template<typename _Tp> \
00960 inline typename valarray<_Tp>::template _UnaryOp<_Name>::_Rt \
00961 valarray<_Tp>::operator _Op() const \
00962 { \
00963 typedef _UnClos<_Name, _ValArray, _Tp> _Closure; \
00964 typedef typename __fun<_Name, _Tp>::result_type _Rt; \
00965 return _Expr<_Closure, _Rt>(_Closure(*this)); \
00966 }
00967
00968 _DEFINE_VALARRAY_UNARY_OPERATOR(+, __unary_plus)
00969 _DEFINE_VALARRAY_UNARY_OPERATOR(-, __negate)
00970 _DEFINE_VALARRAY_UNARY_OPERATOR(~, __bitwise_not)
00971 _DEFINE_VALARRAY_UNARY_OPERATOR (!, __logical_not)
00972
00973 #undef _DEFINE_VALARRAY_UNARY_OPERATOR
00974
00975 #define _DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(_Op, _Name) \
00976 template<class _Tp> \
00977 inline valarray<_Tp>& \
00978 valarray<_Tp>::operator _Op##=(const _Tp &__t) \
00979 { \
00980 _Array_augmented_##_Name(_Array<_Tp>(_M_data), _M_size, __t); \
00981 return *this; \
00982 } \
00983 \
00984 template<class _Tp> \
00985 inline valarray<_Tp>& \
00986 valarray<_Tp>::operator _Op##=(const valarray<_Tp> &__v) \
00987 { \
00988 _GLIBCXX_DEBUG_ASSERT(_M_size == __v._M_size); \
00989 _Array_augmented_##_Name(_Array<_Tp>(_M_data), _M_size, \
00990 _Array<_Tp>(__v._M_data)); \
00991 return *this; \
00992 }
00993
00994 _DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(+, __plus)
00995 _DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(-, __minus)
00996 _DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(*, __multiplies)
00997 _DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(/, __divides)
00998 _DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(%, __modulus)
00999 _DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(^, __bitwise_xor)
01000 _DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(&, __bitwise_and)
01001 _DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(|, __bitwise_or)
01002 _DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(<<, __shift_left)
01003 _DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(>>, __shift_right)
01004
01005 #undef _DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT
01006
01007 #define _DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(_Op, _Name) \
01008 template<class _Tp> template<class _Dom> \
01009 inline valarray<_Tp>& \
01010 valarray<_Tp>::operator _Op##=(const _Expr<_Dom, _Tp>& __e) \
01011 { \
01012 _Array_augmented_##_Name(_Array<_Tp>(_M_data), __e, _M_size); \
01013 return *this; \
01014 }
01015
01016 _DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(+, __plus)
01017 _DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(-, __minus)
01018 _DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(*, __multiplies)
01019 _DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(/, __divides)
01020 _DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(%, __modulus)
01021 _DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(^, __bitwise_xor)
01022 _DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(&, __bitwise_and)
01023 _DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(|, __bitwise_or)
01024 _DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(<<, __shift_left)
01025 _DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(>>, __shift_right)
01026
01027 #undef _DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT
01028
01029
01030 #define _DEFINE_BINARY_OPERATOR(_Op, _Name) \
01031 template<typename _Tp> \
01032 inline _Expr<_BinClos<_Name, _ValArray, _ValArray, _Tp, _Tp>, \
01033 typename __fun<_Name, _Tp>::result_type> \
01034 operator _Op(const valarray<_Tp>& __v, const valarray<_Tp>& __w) \
01035 { \
01036 _GLIBCXX_DEBUG_ASSERT(__v.size() == __w.size()); \
01037 typedef _BinClos<_Name, _ValArray, _ValArray, _Tp, _Tp> _Closure; \
01038 typedef typename __fun<_Name, _Tp>::result_type _Rt; \
01039 return _Expr<_Closure, _Rt>(_Closure(__v, __w)); \
01040 } \
01041 \
01042 template<typename _Tp> \
01043 inline _Expr<_BinClos<_Name, _ValArray,_Constant, _Tp, _Tp>, \
01044 typename __fun<_Name, _Tp>::result_type> \
01045 operator _Op(const valarray<_Tp>& __v, const _Tp& __t) \
01046 { \
01047 typedef _BinClos<_Name, _ValArray, _Constant, _Tp, _Tp> _Closure; \
01048 typedef typename __fun<_Name, _Tp>::result_type _Rt; \
01049 return _Expr<_Closure, _Rt>(_Closure(__v, __t)); \
01050 } \
01051 \
01052 template<typename _Tp> \
01053 inline _Expr<_BinClos<_Name, _Constant, _ValArray, _Tp, _Tp>, \
01054 typename __fun<_Name, _Tp>::result_type> \
01055 operator _Op(const _Tp& __t, const valarray<_Tp>& __v) \
01056 { \
01057 typedef _BinClos<_Name, _Constant, _ValArray, _Tp, _Tp> _Closure; \
01058 typedef typename __fun<_Name, _Tp>::result_type _Rt; \
01059 return _Expr<_Closure, _Rt>(_Closure(__t, __v)); \
01060 }
01061
01062 _DEFINE_BINARY_OPERATOR(+, __plus)
01063 _DEFINE_BINARY_OPERATOR(-, __minus)
01064 _DEFINE_BINARY_OPERATOR(*, __multiplies)
01065 _DEFINE_BINARY_OPERATOR(/, __divides)
01066 _DEFINE_BINARY_OPERATOR(%, __modulus)
01067 _DEFINE_BINARY_OPERATOR(^, __bitwise_xor)
01068 _DEFINE_BINARY_OPERATOR(&, __bitwise_and)
01069 _DEFINE_BINARY_OPERATOR(|, __bitwise_or)
01070 _DEFINE_BINARY_OPERATOR(<<, __shift_left)
01071 _DEFINE_BINARY_OPERATOR(>>, __shift_right)
01072 _DEFINE_BINARY_OPERATOR(&&, __logical_and)
01073 _DEFINE_BINARY_OPERATOR(||, __logical_or)
01074 _DEFINE_BINARY_OPERATOR(==, __equal_to)
01075 _DEFINE_BINARY_OPERATOR(!=, __not_equal_to)
01076 _DEFINE_BINARY_OPERATOR(<, __less)
01077 _DEFINE_BINARY_OPERATOR(>, __greater)
01078 _DEFINE_BINARY_OPERATOR(<=, __less_equal)
01079 _DEFINE_BINARY_OPERATOR(>=, __greater_equal)
01080
01081 #undef _DEFINE_BINARY_OPERATOR
01082
01083
01084
01085 _GLIBCXX_END_NAMESPACE
01086
01087 #endif