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