libstdc++
|
00001 // The template and inlines for the -*- C++ -*- valarray class. 00002 00003 // Copyright (C) 1997-2013 Free Software Foundation, Inc. 00004 // 00005 // This file is part of the GNU ISO C++ Library. This library is free 00006 // software; you can redistribute it and/or modify it under the 00007 // terms of the GNU General Public License as published by the 00008 // Free Software Foundation; either version 3, or (at your option) 00009 // any later version. 00010 00011 // This library is distributed in the hope that it will be useful, 00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 // GNU General Public License for more details. 00015 00016 // Under Section 7 of GPL version 3, you are granted additional 00017 // permissions described in the GCC Runtime Library Exception, version 00018 // 3.1, as published by the Free Software Foundation. 00019 00020 // You should have received a copy of the GNU General Public License and 00021 // a copy of the GCC Runtime Library Exception along with this program; 00022 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 00023 // <http://www.gnu.org/licenses/>. 00024 00025 /** @file include/valarray 00026 * This is a Standard C++ Library header. 00027 */ 00028 00029 // Written by Gabriel Dos Reis <Gabriel.Dos-Reis@DPTMaths.ENS-Cachan.Fr> 00030 00031 #ifndef _GLIBCXX_VALARRAY 00032 #define _GLIBCXX_VALARRAY 1 00033 00034 #pragma GCC system_header 00035 00036 #include <bits/c++config.h> 00037 #include <cmath> 00038 #include <algorithm> 00039 #include <debug/debug.h> 00040 #if __cplusplus >= 201103L 00041 #include <initializer_list> 00042 #endif 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; // An array of type _Tp 00079 class slice; // BLAS-like slice out of an array 00080 template<class _Tp> class slice_array; 00081 class gslice; // generalized slice out of an array 00082 template<class _Tp> class gslice_array; 00083 template<class _Tp> class mask_array; // masked array 00084 template<class _Tp> class indirect_array; // indirected array 00085 00086 _GLIBCXX_END_NAMESPACE_VERSION 00087 } // namespace 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 * @defgroup numeric_arrays Numeric Arrays 00098 * @ingroup numerics 00099 * 00100 * Classes and functions for representing and manipulating arrays of elements. 00101 * @{ 00102 */ 00103 00104 /** 00105 * @brief Smart array designed to support numeric processing. 00106 * 00107 * A valarray is an array that provides constraints intended to allow for 00108 * effective optimization of numeric array processing by reducing the 00109 * aliasing that can result from pointer representations. It represents a 00110 * one-dimensional array from which different multidimensional subsets can 00111 * be accessed and modified. 00112 * 00113 * @tparam _Tp Type of object in the array. 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 // _lib.valarray.cons_ construct/destroy: 00128 /// Construct an empty array. 00129 valarray(); 00130 00131 /// Construct an array with @a n elements. 00132 explicit valarray(size_t); 00133 00134 /// Construct an array with @a n elements initialized to @a t. 00135 valarray(const _Tp&, size_t); 00136 00137 /// Construct an array initialized to the first @a n elements of @a t. 00138 valarray(const _Tp* __restrict__, size_t); 00139 00140 /// Copy constructor. 00141 valarray(const valarray&); 00142 00143 #if __cplusplus >= 201103L 00144 /// Move constructor. 00145 valarray(valarray&&) noexcept; 00146 #endif 00147 00148 /// Construct an array with the same size and values in @a sa. 00149 valarray(const slice_array<_Tp>&); 00150 00151 /// Construct an array with the same size and values in @a ga. 00152 valarray(const gslice_array<_Tp>&); 00153 00154 /// Construct an array with the same size and values in @a ma. 00155 valarray(const mask_array<_Tp>&); 00156 00157 /// Construct an array with the same size and values in @a ia. 00158 valarray(const indirect_array<_Tp>&); 00159 00160 #if __cplusplus >= 201103L 00161 /// Construct an array with an initializer_list of values. 00162 valarray(initializer_list<_Tp>); 00163 #endif 00164 00165 template<class _Dom> 00166 valarray(const _Expr<_Dom, _Tp>& __e); 00167 00168 ~valarray() _GLIBCXX_NOEXCEPT; 00169 00170 // _lib.valarray.assign_ assignment: 00171 /** 00172 * @brief Assign elements to an array. 00173 * 00174 * Assign elements of array to values in @a v. 00175 * 00176 * @param __v Valarray to get values from. 00177 */ 00178 valarray<_Tp>& operator=(const valarray<_Tp>& __v); 00179 00180 #if __cplusplus >= 201103L 00181 /** 00182 * @brief Move assign elements to an array. 00183 * 00184 * Move assign elements of array to values in @a v. 00185 * 00186 * @param __v Valarray to get values from. 00187 */ 00188 valarray<_Tp>& operator=(valarray<_Tp>&& __v) noexcept; 00189 #endif 00190 00191 /** 00192 * @brief Assign elements to a value. 00193 * 00194 * Assign all elements of array to @a t. 00195 * 00196 * @param __t Value for elements. 00197 */ 00198 valarray<_Tp>& operator=(const _Tp& __t); 00199 00200 /** 00201 * @brief Assign elements to an array subset. 00202 * 00203 * Assign elements of array to values in @a sa. Results are undefined 00204 * if @a sa does not have the same size as this array. 00205 * 00206 * @param __sa Array slice to get values from. 00207 */ 00208 valarray<_Tp>& operator=(const slice_array<_Tp>& __sa); 00209 00210 /** 00211 * @brief Assign elements to an array subset. 00212 * 00213 * Assign elements of array to values in @a ga. Results are undefined 00214 * if @a ga does not have the same size as this array. 00215 * 00216 * @param __ga Array slice to get values from. 00217 */ 00218 valarray<_Tp>& operator=(const gslice_array<_Tp>& __ga); 00219 00220 /** 00221 * @brief Assign elements to an array subset. 00222 * 00223 * Assign elements of array to values in @a ma. Results are undefined 00224 * if @a ma does not have the same size as this array. 00225 * 00226 * @param __ma Array slice to get values from. 00227 */ 00228 valarray<_Tp>& operator=(const mask_array<_Tp>& __ma); 00229 00230 /** 00231 * @brief Assign elements to an array subset. 00232 * 00233 * Assign elements of array to values in @a ia. Results are undefined 00234 * if @a ia does not have the same size as this array. 00235 * 00236 * @param __ia Array slice to get values from. 00237 */ 00238 valarray<_Tp>& operator=(const indirect_array<_Tp>& __ia); 00239 00240 #if __cplusplus >= 201103L 00241 /** 00242 * @brief Assign elements to an initializer_list. 00243 * 00244 * Assign elements of array to values in @a __l. Results are undefined 00245 * if @a __l does not have the same size as this array. 00246 * 00247 * @param __l initializer_list to get values from. 00248 */ 00249 valarray& operator=(initializer_list<_Tp> __l); 00250 #endif 00251 00252 template<class _Dom> valarray<_Tp>& 00253 operator= (const _Expr<_Dom, _Tp>&); 00254 00255 // _lib.valarray.access_ element access: 00256 /** 00257 * Return a reference to the i'th array element. 00258 * 00259 * @param __i Index of element to return. 00260 * @return Reference to the i'th element. 00261 */ 00262 _Tp& operator[](size_t __i); 00263 00264 // _GLIBCXX_RESOLVE_LIB_DEFECTS 00265 // 389. Const overload of valarray::operator[] returns by value. 00266 const _Tp& operator[](size_t) const; 00267 00268 // _lib.valarray.sub_ subset operations: 00269 /** 00270 * @brief Return an array subset. 00271 * 00272 * Returns a new valarray containing the elements of the array 00273 * indicated by the slice argument. The new valarray has the same size 00274 * as the input slice. @see slice. 00275 * 00276 * @param __s The source slice. 00277 * @return New valarray containing elements in @a __s. 00278 */ 00279 _Expr<_SClos<_ValArray, _Tp>, _Tp> operator[](slice __s) const; 00280 00281 /** 00282 * @brief Return a reference to an array subset. 00283 * 00284 * Returns a new valarray containing the elements of the array 00285 * indicated by the slice argument. The new valarray has the same size 00286 * as the input slice. @see slice. 00287 * 00288 * @param __s The source slice. 00289 * @return New valarray containing elements in @a __s. 00290 */ 00291 slice_array<_Tp> operator[](slice __s); 00292 00293 /** 00294 * @brief Return an array subset. 00295 * 00296 * Returns a slice_array referencing the elements of the array 00297 * indicated by the slice argument. @see gslice. 00298 * 00299 * @param __s The source slice. 00300 * @return Slice_array referencing elements indicated by @a __s. 00301 */ 00302 _Expr<_GClos<_ValArray, _Tp>, _Tp> operator[](const gslice& __s) const; 00303 00304 /** 00305 * @brief Return a reference to an array subset. 00306 * 00307 * Returns a new valarray containing the elements of the array 00308 * indicated by the gslice argument. The new valarray has 00309 * the same size as the input gslice. @see gslice. 00310 * 00311 * @param __s The source gslice. 00312 * @return New valarray containing elements in @a __s. 00313 */ 00314 gslice_array<_Tp> operator[](const gslice& __s); 00315 00316 /** 00317 * @brief Return an array subset. 00318 * 00319 * Returns a new valarray containing the elements of the array 00320 * indicated by the argument. The input is a valarray of bool which 00321 * represents a bitmask indicating which elements should be copied into 00322 * the new valarray. Each element of the array is added to the return 00323 * valarray if the corresponding element of the argument is true. 00324 * 00325 * @param __m The valarray bitmask. 00326 * @return New valarray containing elements indicated by @a __m. 00327 */ 00328 valarray<_Tp> operator[](const valarray<bool>& __m) const; 00329 00330 /** 00331 * @brief Return a reference to an array subset. 00332 * 00333 * Returns a new mask_array referencing the elements of the array 00334 * indicated by the argument. The input is a valarray of bool which 00335 * represents a bitmask indicating which elements are part of the 00336 * subset. Elements of the array are part of the subset if the 00337 * corresponding element of the argument is true. 00338 * 00339 * @param __m The valarray bitmask. 00340 * @return New valarray containing elements indicated by @a __m. 00341 */ 00342 mask_array<_Tp> operator[](const valarray<bool>& __m); 00343 00344 /** 00345 * @brief Return an array subset. 00346 * 00347 * Returns a new valarray containing the elements of the array 00348 * indicated by the argument. The elements in the argument are 00349 * interpreted as the indices of elements of this valarray to copy to 00350 * the return valarray. 00351 * 00352 * @param __i The valarray element index list. 00353 * @return New valarray containing elements in @a __s. 00354 */ 00355 _Expr<_IClos<_ValArray, _Tp>, _Tp> 00356 operator[](const valarray<size_t>& __i) const; 00357 00358 /** 00359 * @brief Return a reference to an array subset. 00360 * 00361 * Returns an indirect_array referencing the elements of the array 00362 * indicated by the argument. The elements in the argument are 00363 * interpreted as the indices of elements of this valarray to include 00364 * in the subset. The returned indirect_array refers to these 00365 * elements. 00366 * 00367 * @param __i The valarray element index list. 00368 * @return Indirect_array referencing elements in @a __i. 00369 */ 00370 indirect_array<_Tp> operator[](const valarray<size_t>& __i); 00371 00372 // _lib.valarray.unary_ unary operators: 00373 /// Return a new valarray by applying unary + to each element. 00374 typename _UnaryOp<__unary_plus>::_Rt operator+() const; 00375 00376 /// Return a new valarray by applying unary - to each element. 00377 typename _UnaryOp<__negate>::_Rt operator-() const; 00378 00379 /// Return a new valarray by applying unary ~ to each element. 00380 typename _UnaryOp<__bitwise_not>::_Rt operator~() const; 00381 00382 /// Return a new valarray by applying unary ! to each element. 00383 typename _UnaryOp<__logical_not>::_Rt operator!() const; 00384 00385 // _lib.valarray.cassign_ computed assignment: 00386 /// Multiply each element of array by @a t. 00387 valarray<_Tp>& operator*=(const _Tp&); 00388 00389 /// Divide each element of array by @a t. 00390 valarray<_Tp>& operator/=(const _Tp&); 00391 00392 /// Set each element e of array to e % @a t. 00393 valarray<_Tp>& operator%=(const _Tp&); 00394 00395 /// Add @a t to each element of array. 00396 valarray<_Tp>& operator+=(const _Tp&); 00397 00398 /// Subtract @a t to each element of array. 00399 valarray<_Tp>& operator-=(const _Tp&); 00400 00401 /// Set each element e of array to e ^ @a t. 00402 valarray<_Tp>& operator^=(const _Tp&); 00403 00404 /// Set each element e of array to e & @a t. 00405 valarray<_Tp>& operator&=(const _Tp&); 00406 00407 /// Set each element e of array to e | @a t. 00408 valarray<_Tp>& operator|=(const _Tp&); 00409 00410 /// Left shift each element e of array by @a t bits. 00411 valarray<_Tp>& operator<<=(const _Tp&); 00412 00413 /// Right shift each element e of array by @a t bits. 00414 valarray<_Tp>& operator>>=(const _Tp&); 00415 00416 /// Multiply elements of array by corresponding elements of @a v. 00417 valarray<_Tp>& operator*=(const valarray<_Tp>&); 00418 00419 /// Divide elements of array by corresponding elements of @a v. 00420 valarray<_Tp>& operator/=(const valarray<_Tp>&); 00421 00422 /// Modulo elements of array by corresponding elements of @a v. 00423 valarray<_Tp>& operator%=(const valarray<_Tp>&); 00424 00425 /// Add corresponding elements of @a v to elements of array. 00426 valarray<_Tp>& operator+=(const valarray<_Tp>&); 00427 00428 /// Subtract corresponding elements of @a v from elements of array. 00429 valarray<_Tp>& operator-=(const valarray<_Tp>&); 00430 00431 /// Logical xor corresponding elements of @a v with elements of array. 00432 valarray<_Tp>& operator^=(const valarray<_Tp>&); 00433 00434 /// Logical or corresponding elements of @a v with elements of array. 00435 valarray<_Tp>& operator|=(const valarray<_Tp>&); 00436 00437 /// Logical and corresponding elements of @a v with elements of array. 00438 valarray<_Tp>& operator&=(const valarray<_Tp>&); 00439 00440 /// Left shift elements of array by corresponding elements of @a v. 00441 valarray<_Tp>& operator<<=(const valarray<_Tp>&); 00442 00443 /// Right shift elements of array by corresponding elements of @a v. 00444 valarray<_Tp>& operator>>=(const valarray<_Tp>&); 00445 00446 template<class _Dom> 00447 valarray<_Tp>& operator*=(const _Expr<_Dom, _Tp>&); 00448 template<class _Dom> 00449 valarray<_Tp>& operator/=(const _Expr<_Dom, _Tp>&); 00450 template<class _Dom> 00451 valarray<_Tp>& operator%=(const _Expr<_Dom, _Tp>&); 00452 template<class _Dom> 00453 valarray<_Tp>& operator+=(const _Expr<_Dom, _Tp>&); 00454 template<class _Dom> 00455 valarray<_Tp>& operator-=(const _Expr<_Dom, _Tp>&); 00456 template<class _Dom> 00457 valarray<_Tp>& operator^=(const _Expr<_Dom, _Tp>&); 00458 template<class _Dom> 00459 valarray<_Tp>& operator|=(const _Expr<_Dom, _Tp>&); 00460 template<class _Dom> 00461 valarray<_Tp>& operator&=(const _Expr<_Dom, _Tp>&); 00462 template<class _Dom> 00463 valarray<_Tp>& operator<<=(const _Expr<_Dom, _Tp>&); 00464 template<class _Dom> 00465 valarray<_Tp>& operator>>=(const _Expr<_Dom, _Tp>&); 00466 00467 // _lib.valarray.members_ member functions: 00468 #if __cplusplus >= 201103L 00469 /// Swap. 00470 void swap(valarray<_Tp>& __v) noexcept; 00471 #endif 00472 00473 /// Return the number of elements in array. 00474 size_t size() const; 00475 00476 /** 00477 * @brief Return the sum of all elements in the array. 00478 * 00479 * Accumulates the sum of all elements into a Tp using +=. The order 00480 * of adding the elements is unspecified. 00481 */ 00482 _Tp sum() const; 00483 00484 /// Return the minimum element using operator<(). 00485 _Tp min() const; 00486 00487 /// Return the maximum element using operator<(). 00488 _Tp max() const; 00489 00490 /** 00491 * @brief Return a shifted array. 00492 * 00493 * A new valarray is constructed as a copy of this array with elements 00494 * in shifted positions. For an element with index i, the new position 00495 * is i - n. The new valarray has the same size as the current one. 00496 * New elements without a value are set to 0. Elements whose new 00497 * position is outside the bounds of the array are discarded. 00498 * 00499 * Positive arguments shift toward index 0, discarding elements [0, n). 00500 * Negative arguments discard elements from the top of the array. 00501 * 00502 * @param __n Number of element positions to shift. 00503 * @return New valarray with elements in shifted positions. 00504 */ 00505 valarray<_Tp> shift (int __n) const; 00506 00507 /** 00508 * @brief Return a rotated array. 00509 * 00510 * A new valarray is constructed as a copy of this array with elements 00511 * in shifted positions. For an element with index i, the new position 00512 * is (i - n) % size(). The new valarray has the same size as the 00513 * current one. Elements that are shifted beyond the array bounds are 00514 * shifted into the other end of the array. No elements are lost. 00515 * 00516 * Positive arguments shift toward index 0, wrapping around the top. 00517 * Negative arguments shift towards the top, wrapping around to 0. 00518 * 00519 * @param __n Number of element positions to rotate. 00520 * @return New valarray with elements in shifted positions. 00521 */ 00522 valarray<_Tp> cshift(int __n) const; 00523 00524 /** 00525 * @brief Apply a function to the array. 00526 * 00527 * Returns a new valarray with elements assigned to the result of 00528 * applying func to the corresponding element of this array. The new 00529 * array has the same size as this one. 00530 * 00531 * @param func Function of Tp returning Tp to apply. 00532 * @return New valarray with transformed elements. 00533 */ 00534 _Expr<_ValFunClos<_ValArray, _Tp>, _Tp> apply(_Tp func(_Tp)) const; 00535 00536 /** 00537 * @brief Apply a function to the array. 00538 * 00539 * Returns a new valarray with elements assigned to the result of 00540 * applying func to the corresponding element of this array. The new 00541 * array has the same size as this one. 00542 * 00543 * @param func Function of const Tp& returning Tp to apply. 00544 * @return New valarray with transformed elements. 00545 */ 00546 _Expr<_RefFunClos<_ValArray, _Tp>, _Tp> apply(_Tp func(const _Tp&)) const; 00547 00548 /** 00549 * @brief Resize array. 00550 * 00551 * Resize this array to @a size and set all elements to @a c. All 00552 * references and iterators are invalidated. 00553 * 00554 * @param __size New array size. 00555 * @param __c New value for all elements. 00556 */ 00557 void resize(size_t __size, _Tp __c = _Tp()); 00558 00559 private: 00560 size_t _M_size; 00561 _Tp* __restrict__ _M_data; 00562 00563 friend class _Array<_Tp>; 00564 }; 00565 00566 template<typename _Tp> 00567 inline const _Tp& 00568 valarray<_Tp>::operator[](size_t __i) const 00569 { 00570 __glibcxx_requires_subscript(__i); 00571 return _M_data[__i]; 00572 } 00573 00574 template<typename _Tp> 00575 inline _Tp& 00576 valarray<_Tp>::operator[](size_t __i) 00577 { 00578 __glibcxx_requires_subscript(__i); 00579 return _M_data[__i]; 00580 } 00581 00582 // @} group numeric_arrays 00583 00584 _GLIBCXX_END_NAMESPACE_VERSION 00585 } // namespace 00586 00587 #include <bits/valarray_after.h> 00588 #include <bits/slice_array.h> 00589 #include <bits/gslice.h> 00590 #include <bits/gslice_array.h> 00591 #include <bits/mask_array.h> 00592 #include <bits/indirect_array.h> 00593 00594 namespace std _GLIBCXX_VISIBILITY(default) 00595 { 00596 _GLIBCXX_BEGIN_NAMESPACE_VERSION 00597 00598 /** 00599 * @addtogroup numeric_arrays 00600 * @{ 00601 */ 00602 00603 template<typename _Tp> 00604 inline 00605 valarray<_Tp>::valarray() : _M_size(0), _M_data(0) {} 00606 00607 template<typename _Tp> 00608 inline 00609 valarray<_Tp>::valarray(size_t __n) 00610 : _M_size(__n), _M_data(__valarray_get_storage<_Tp>(__n)) 00611 { std::__valarray_default_construct(_M_data, _M_data + __n); } 00612 00613 template<typename _Tp> 00614 inline 00615 valarray<_Tp>::valarray(const _Tp& __t, size_t __n) 00616 : _M_size(__n), _M_data(__valarray_get_storage<_Tp>(__n)) 00617 { std::__valarray_fill_construct(_M_data, _M_data + __n, __t); } 00618 00619 template<typename _Tp> 00620 inline 00621 valarray<_Tp>::valarray(const _Tp* __restrict__ __p, size_t __n) 00622 : _M_size(__n), _M_data(__valarray_get_storage<_Tp>(__n)) 00623 { 00624 _GLIBCXX_DEBUG_ASSERT(__p != 0 || __n == 0); 00625 std::__valarray_copy_construct(__p, __p + __n, _M_data); 00626 } 00627 00628 template<typename _Tp> 00629 inline 00630 valarray<_Tp>::valarray(const valarray<_Tp>& __v) 00631 : _M_size(__v._M_size), _M_data(__valarray_get_storage<_Tp>(__v._M_size)) 00632 { std::__valarray_copy_construct(__v._M_data, __v._M_data + _M_size, 00633 _M_data); } 00634 00635 #if __cplusplus >= 201103L 00636 template<typename _Tp> 00637 inline 00638 valarray<_Tp>::valarray(valarray<_Tp>&& __v) noexcept 00639 : _M_size(__v._M_size), _M_data(__v._M_data) 00640 { 00641 __v._M_size = 0; 00642 __v._M_data = 0; 00643 } 00644 #endif 00645 00646 template<typename _Tp> 00647 inline 00648 valarray<_Tp>::valarray(const slice_array<_Tp>& __sa) 00649 : _M_size(__sa._M_sz), _M_data(__valarray_get_storage<_Tp>(__sa._M_sz)) 00650 { 00651 std::__valarray_copy_construct 00652 (__sa._M_array, __sa._M_sz, __sa._M_stride, _Array<_Tp>(_M_data)); 00653 } 00654 00655 template<typename _Tp> 00656 inline 00657 valarray<_Tp>::valarray(const gslice_array<_Tp>& __ga) 00658 : _M_size(__ga._M_index.size()), 00659 _M_data(__valarray_get_storage<_Tp>(_M_size)) 00660 { 00661 std::__valarray_copy_construct 00662 (__ga._M_array, _Array<size_t>(__ga._M_index), 00663 _Array<_Tp>(_M_data), _M_size); 00664 } 00665 00666 template<typename _Tp> 00667 inline 00668 valarray<_Tp>::valarray(const mask_array<_Tp>& __ma) 00669 : _M_size(__ma._M_sz), _M_data(__valarray_get_storage<_Tp>(__ma._M_sz)) 00670 { 00671 std::__valarray_copy_construct 00672 (__ma._M_array, __ma._M_mask, _Array<_Tp>(_M_data), _M_size); 00673 } 00674 00675 template<typename _Tp> 00676 inline 00677 valarray<_Tp>::valarray(const indirect_array<_Tp>& __ia) 00678 : _M_size(__ia._M_sz), _M_data(__valarray_get_storage<_Tp>(__ia._M_sz)) 00679 { 00680 std::__valarray_copy_construct 00681 (__ia._M_array, __ia._M_index, _Array<_Tp>(_M_data), _M_size); 00682 } 00683 00684 #if __cplusplus >= 201103L 00685 template<typename _Tp> 00686 inline 00687 valarray<_Tp>::valarray(initializer_list<_Tp> __l) 00688 : _M_size(__l.size()), _M_data(__valarray_get_storage<_Tp>(__l.size())) 00689 { std::__valarray_copy_construct(__l.begin(), __l.end(), _M_data); } 00690 #endif 00691 00692 template<typename _Tp> template<class _Dom> 00693 inline 00694 valarray<_Tp>::valarray(const _Expr<_Dom, _Tp>& __e) 00695 : _M_size(__e.size()), _M_data(__valarray_get_storage<_Tp>(_M_size)) 00696 { std::__valarray_copy_construct(__e, _M_size, _Array<_Tp>(_M_data)); } 00697 00698 template<typename _Tp> 00699 inline 00700 valarray<_Tp>::~valarray() _GLIBCXX_NOEXCEPT 00701 { 00702 std::__valarray_destroy_elements(_M_data, _M_data + _M_size); 00703 std::__valarray_release_memory(_M_data); 00704 } 00705 00706 template<typename _Tp> 00707 inline valarray<_Tp>& 00708 valarray<_Tp>::operator=(const valarray<_Tp>& __v) 00709 { 00710 // _GLIBCXX_RESOLVE_LIB_DEFECTS 00711 // 630. arrays of valarray. 00712 if (_M_size == __v._M_size) 00713 std::__valarray_copy(__v._M_data, _M_size, _M_data); 00714 else 00715 { 00716 if (_M_data) 00717 { 00718 std::__valarray_destroy_elements(_M_data, _M_data + _M_size); 00719 std::__valarray_release_memory(_M_data); 00720 } 00721 _M_size = __v._M_size; 00722 _M_data = __valarray_get_storage<_Tp>(_M_size); 00723 std::__valarray_copy_construct(__v._M_data, __v._M_data + _M_size, 00724 _M_data); 00725 } 00726 return *this; 00727 } 00728 00729 #if __cplusplus >= 201103L 00730 template<typename _Tp> 00731 inline valarray<_Tp>& 00732 valarray<_Tp>::operator=(valarray<_Tp>&& __v) noexcept 00733 { 00734 if (_M_data) 00735 { 00736 std::__valarray_destroy_elements(_M_data, _M_data + _M_size); 00737 std::__valarray_release_memory(_M_data); 00738 } 00739 _M_size = __v._M_size; 00740 _M_data = __v._M_data; 00741 __v._M_size = 0; 00742 __v._M_data = 0; 00743 return *this; 00744 } 00745 00746 template<typename _Tp> 00747 inline valarray<_Tp>& 00748 valarray<_Tp>::operator=(initializer_list<_Tp> __l) 00749 { 00750 // _GLIBCXX_RESOLVE_LIB_DEFECTS 00751 // 630. arrays of valarray. 00752 if (_M_size == __l.size()) 00753 std::__valarray_copy(__l.begin(), __l.size(), _M_data); 00754 else 00755 { 00756 if (_M_data) 00757 { 00758 std::__valarray_destroy_elements(_M_data, _M_data + _M_size); 00759 std::__valarray_release_memory(_M_data); 00760 } 00761 _M_size = __l.size(); 00762 _M_data = __valarray_get_storage<_Tp>(_M_size); 00763 std::__valarray_copy_construct(__l.begin(), __l.begin() + _M_size, 00764 _M_data); 00765 } 00766 return *this; 00767 } 00768 #endif 00769 00770 template<typename _Tp> 00771 inline valarray<_Tp>& 00772 valarray<_Tp>::operator=(const _Tp& __t) 00773 { 00774 std::__valarray_fill(_M_data, _M_size, __t); 00775 return *this; 00776 } 00777 00778 template<typename _Tp> 00779 inline valarray<_Tp>& 00780 valarray<_Tp>::operator=(const slice_array<_Tp>& __sa) 00781 { 00782 _GLIBCXX_DEBUG_ASSERT(_M_size == __sa._M_sz); 00783 std::__valarray_copy(__sa._M_array, __sa._M_sz, 00784 __sa._M_stride, _Array<_Tp>(_M_data)); 00785 return *this; 00786 } 00787 00788 template<typename _Tp> 00789 inline valarray<_Tp>& 00790 valarray<_Tp>::operator=(const gslice_array<_Tp>& __ga) 00791 { 00792 _GLIBCXX_DEBUG_ASSERT(_M_size == __ga._M_index.size()); 00793 std::__valarray_copy(__ga._M_array, _Array<size_t>(__ga._M_index), 00794 _Array<_Tp>(_M_data), _M_size); 00795 return *this; 00796 } 00797 00798 template<typename _Tp> 00799 inline valarray<_Tp>& 00800 valarray<_Tp>::operator=(const mask_array<_Tp>& __ma) 00801 { 00802 _GLIBCXX_DEBUG_ASSERT(_M_size == __ma._M_sz); 00803 std::__valarray_copy(__ma._M_array, __ma._M_mask, 00804 _Array<_Tp>(_M_data), _M_size); 00805 return *this; 00806 } 00807 00808 template<typename _Tp> 00809 inline valarray<_Tp>& 00810 valarray<_Tp>::operator=(const indirect_array<_Tp>& __ia) 00811 { 00812 _GLIBCXX_DEBUG_ASSERT(_M_size == __ia._M_sz); 00813 std::__valarray_copy(__ia._M_array, __ia._M_index, 00814 _Array<_Tp>(_M_data), _M_size); 00815 return *this; 00816 } 00817 00818 template<typename _Tp> template<class _Dom> 00819 inline valarray<_Tp>& 00820 valarray<_Tp>::operator=(const _Expr<_Dom, _Tp>& __e) 00821 { 00822 // _GLIBCXX_RESOLVE_LIB_DEFECTS 00823 // 630. arrays of valarray. 00824 if (_M_size == __e.size()) 00825 std::__valarray_copy(__e, _M_size, _Array<_Tp>(_M_data)); 00826 else 00827 { 00828 if (_M_data) 00829 { 00830 std::__valarray_destroy_elements(_M_data, _M_data + _M_size); 00831 std::__valarray_release_memory(_M_data); 00832 } 00833 _M_size = __e.size(); 00834 _M_data = __valarray_get_storage<_Tp>(_M_size); 00835 std::__valarray_copy_construct(__e, _M_size, _Array<_Tp>(_M_data)); 00836 } 00837 return *this; 00838 } 00839 00840 template<typename _Tp> 00841 inline _Expr<_SClos<_ValArray,_Tp>, _Tp> 00842 valarray<_Tp>::operator[](slice __s) const 00843 { 00844 typedef _SClos<_ValArray,_Tp> _Closure; 00845 return _Expr<_Closure, _Tp>(_Closure (_Array<_Tp>(_M_data), __s)); 00846 } 00847 00848 template<typename _Tp> 00849 inline slice_array<_Tp> 00850 valarray<_Tp>::operator[](slice __s) 00851 { return slice_array<_Tp>(_Array<_Tp>(_M_data), __s); } 00852 00853 template<typename _Tp> 00854 inline _Expr<_GClos<_ValArray,_Tp>, _Tp> 00855 valarray<_Tp>::operator[](const gslice& __gs) const 00856 { 00857 typedef _GClos<_ValArray,_Tp> _Closure; 00858 return _Expr<_Closure, _Tp> 00859 (_Closure(_Array<_Tp>(_M_data), __gs._M_index->_M_index)); 00860 } 00861 00862 template<typename _Tp> 00863 inline gslice_array<_Tp> 00864 valarray<_Tp>::operator[](const gslice& __gs) 00865 { 00866 return gslice_array<_Tp> 00867 (_Array<_Tp>(_M_data), __gs._M_index->_M_index); 00868 } 00869 00870 template<typename _Tp> 00871 inline valarray<_Tp> 00872 valarray<_Tp>::operator[](const valarray<bool>& __m) const 00873 { 00874 size_t __s = 0; 00875 size_t __e = __m.size(); 00876 for (size_t __i=0; __i<__e; ++__i) 00877 if (__m[__i]) ++__s; 00878 return valarray<_Tp>(mask_array<_Tp>(_Array<_Tp>(_M_data), __s, 00879 _Array<bool> (__m))); 00880 } 00881 00882 template<typename _Tp> 00883 inline mask_array<_Tp> 00884 valarray<_Tp>::operator[](const valarray<bool>& __m) 00885 { 00886 size_t __s = 0; 00887 size_t __e = __m.size(); 00888 for (size_t __i=0; __i<__e; ++__i) 00889 if (__m[__i]) ++__s; 00890 return mask_array<_Tp>(_Array<_Tp>(_M_data), __s, _Array<bool>(__m)); 00891 } 00892 00893 template<typename _Tp> 00894 inline _Expr<_IClos<_ValArray,_Tp>, _Tp> 00895 valarray<_Tp>::operator[](const valarray<size_t>& __i) const 00896 { 00897 typedef _IClos<_ValArray,_Tp> _Closure; 00898 return _Expr<_Closure, _Tp>(_Closure(*this, __i)); 00899 } 00900 00901 template<typename _Tp> 00902 inline indirect_array<_Tp> 00903 valarray<_Tp>::operator[](const valarray<size_t>& __i) 00904 { 00905 return indirect_array<_Tp>(_Array<_Tp>(_M_data), __i.size(), 00906 _Array<size_t>(__i)); 00907 } 00908 00909 #if __cplusplus >= 201103L 00910 template<class _Tp> 00911 inline void 00912 valarray<_Tp>::swap(valarray<_Tp>& __v) noexcept 00913 { 00914 std::swap(_M_size, __v._M_size); 00915 std::swap(_M_data, __v._M_data); 00916 } 00917 #endif 00918 00919 template<class _Tp> 00920 inline size_t 00921 valarray<_Tp>::size() const 00922 { return _M_size; } 00923 00924 template<class _Tp> 00925 inline _Tp 00926 valarray<_Tp>::sum() const 00927 { 00928 _GLIBCXX_DEBUG_ASSERT(_M_size > 0); 00929 return std::__valarray_sum(_M_data, _M_data + _M_size); 00930 } 00931 00932 template<class _Tp> 00933 inline valarray<_Tp> 00934 valarray<_Tp>::shift(int __n) const 00935 { 00936 valarray<_Tp> __ret; 00937 00938 if (_M_size == 0) 00939 return __ret; 00940 00941 _Tp* __restrict__ __tmp_M_data = 00942 std::__valarray_get_storage<_Tp>(_M_size); 00943 00944 if (__n == 0) 00945 std::__valarray_copy_construct(_M_data, 00946 _M_data + _M_size, __tmp_M_data); 00947 else if (__n > 0) // shift left 00948 { 00949 if (size_t(__n) > _M_size) 00950 __n = int(_M_size); 00951 00952 std::__valarray_copy_construct(_M_data + __n, 00953 _M_data + _M_size, __tmp_M_data); 00954 std::__valarray_default_construct(__tmp_M_data + _M_size - __n, 00955 __tmp_M_data + _M_size); 00956 } 00957 else // shift right 00958 { 00959 if (-size_t(__n) > _M_size) 00960 __n = -int(_M_size); 00961 00962 std::__valarray_copy_construct(_M_data, _M_data + _M_size + __n, 00963 __tmp_M_data - __n); 00964 std::__valarray_default_construct(__tmp_M_data, 00965 __tmp_M_data - __n); 00966 } 00967 00968 __ret._M_size = _M_size; 00969 __ret._M_data = __tmp_M_data; 00970 return __ret; 00971 } 00972 00973 template<class _Tp> 00974 inline valarray<_Tp> 00975 valarray<_Tp>::cshift(int __n) const 00976 { 00977 valarray<_Tp> __ret; 00978 00979 if (_M_size == 0) 00980 return __ret; 00981 00982 _Tp* __restrict__ __tmp_M_data = 00983 std::__valarray_get_storage<_Tp>(_M_size); 00984 00985 if (__n == 0) 00986 std::__valarray_copy_construct(_M_data, 00987 _M_data + _M_size, __tmp_M_data); 00988 else if (__n > 0) // cshift left 00989 { 00990 if (size_t(__n) > _M_size) 00991 __n = int(__n % _M_size); 00992 00993 std::__valarray_copy_construct(_M_data, _M_data + __n, 00994 __tmp_M_data + _M_size - __n); 00995 std::__valarray_copy_construct(_M_data + __n, _M_data + _M_size, 00996 __tmp_M_data); 00997 } 00998 else // cshift right 00999 { 01000 if (-size_t(__n) > _M_size) 01001 __n = -int(-size_t(__n) % _M_size); 01002 01003 std::__valarray_copy_construct(_M_data + _M_size + __n, 01004 _M_data + _M_size, __tmp_M_data); 01005 std::__valarray_copy_construct(_M_data, _M_data + _M_size + __n, 01006 __tmp_M_data - __n); 01007 } 01008 01009 __ret._M_size = _M_size; 01010 __ret._M_data = __tmp_M_data; 01011 return __ret; 01012 } 01013 01014 template<class _Tp> 01015 inline void 01016 valarray<_Tp>::resize(size_t __n, _Tp __c) 01017 { 01018 // This complication is so to make valarray<valarray<T> > work 01019 // even though it is not required by the standard. Nobody should 01020 // be saying valarray<valarray<T> > anyway. See the specs. 01021 std::__valarray_destroy_elements(_M_data, _M_data + _M_size); 01022 if (_M_size != __n) 01023 { 01024 std::__valarray_release_memory(_M_data); 01025 _M_size = __n; 01026 _M_data = __valarray_get_storage<_Tp>(__n); 01027 } 01028 std::__valarray_fill_construct(_M_data, _M_data + __n, __c); 01029 } 01030 01031 template<typename _Tp> 01032 inline _Tp 01033 valarray<_Tp>::min() const 01034 { 01035 _GLIBCXX_DEBUG_ASSERT(_M_size > 0); 01036 return *std::min_element(_M_data, _M_data + _M_size); 01037 } 01038 01039 template<typename _Tp> 01040 inline _Tp 01041 valarray<_Tp>::max() const 01042 { 01043 _GLIBCXX_DEBUG_ASSERT(_M_size > 0); 01044 return *std::max_element(_M_data, _M_data + _M_size); 01045 } 01046 01047 template<class _Tp> 01048 inline _Expr<_ValFunClos<_ValArray, _Tp>, _Tp> 01049 valarray<_Tp>::apply(_Tp func(_Tp)) const 01050 { 01051 typedef _ValFunClos<_ValArray, _Tp> _Closure; 01052 return _Expr<_Closure, _Tp>(_Closure(*this, func)); 01053 } 01054 01055 template<class _Tp> 01056 inline _Expr<_RefFunClos<_ValArray, _Tp>, _Tp> 01057 valarray<_Tp>::apply(_Tp func(const _Tp &)) const 01058 { 01059 typedef _RefFunClos<_ValArray, _Tp> _Closure; 01060 return _Expr<_Closure, _Tp>(_Closure(*this, func)); 01061 } 01062 01063 #define _DEFINE_VALARRAY_UNARY_OPERATOR(_Op, _Name) \ 01064 template<typename _Tp> \ 01065 inline typename valarray<_Tp>::template _UnaryOp<_Name>::_Rt \ 01066 valarray<_Tp>::operator _Op() const \ 01067 { \ 01068 typedef _UnClos<_Name, _ValArray, _Tp> _Closure; \ 01069 typedef typename __fun<_Name, _Tp>::result_type _Rt; \ 01070 return _Expr<_Closure, _Rt>(_Closure(*this)); \ 01071 } 01072 01073 _DEFINE_VALARRAY_UNARY_OPERATOR(+, __unary_plus) 01074 _DEFINE_VALARRAY_UNARY_OPERATOR(-, __negate) 01075 _DEFINE_VALARRAY_UNARY_OPERATOR(~, __bitwise_not) 01076 _DEFINE_VALARRAY_UNARY_OPERATOR (!, __logical_not) 01077 01078 #undef _DEFINE_VALARRAY_UNARY_OPERATOR 01079 01080 #define _DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(_Op, _Name) \ 01081 template<class _Tp> \ 01082 inline valarray<_Tp>& \ 01083 valarray<_Tp>::operator _Op##=(const _Tp &__t) \ 01084 { \ 01085 _Array_augmented_##_Name(_Array<_Tp>(_M_data), _M_size, __t); \ 01086 return *this; \ 01087 } \ 01088 \ 01089 template<class _Tp> \ 01090 inline valarray<_Tp>& \ 01091 valarray<_Tp>::operator _Op##=(const valarray<_Tp> &__v) \ 01092 { \ 01093 _GLIBCXX_DEBUG_ASSERT(_M_size == __v._M_size); \ 01094 _Array_augmented_##_Name(_Array<_Tp>(_M_data), _M_size, \ 01095 _Array<_Tp>(__v._M_data)); \ 01096 return *this; \ 01097 } 01098 01099 _DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(+, __plus) 01100 _DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(-, __minus) 01101 _DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(*, __multiplies) 01102 _DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(/, __divides) 01103 _DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(%, __modulus) 01104 _DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(^, __bitwise_xor) 01105 _DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(&, __bitwise_and) 01106 _DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(|, __bitwise_or) 01107 _DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(<<, __shift_left) 01108 _DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(>>, __shift_right) 01109 01110 #undef _DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT 01111 01112 #define _DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(_Op, _Name) \ 01113 template<class _Tp> template<class _Dom> \ 01114 inline valarray<_Tp>& \ 01115 valarray<_Tp>::operator _Op##=(const _Expr<_Dom, _Tp>& __e) \ 01116 { \ 01117 _Array_augmented_##_Name(_Array<_Tp>(_M_data), __e, _M_size); \ 01118 return *this; \ 01119 } 01120 01121 _DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(+, __plus) 01122 _DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(-, __minus) 01123 _DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(*, __multiplies) 01124 _DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(/, __divides) 01125 _DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(%, __modulus) 01126 _DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(^, __bitwise_xor) 01127 _DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(&, __bitwise_and) 01128 _DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(|, __bitwise_or) 01129 _DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(<<, __shift_left) 01130 _DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(>>, __shift_right) 01131 01132 #undef _DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT 01133 01134 01135 #define _DEFINE_BINARY_OPERATOR(_Op, _Name) \ 01136 template<typename _Tp> \ 01137 inline _Expr<_BinClos<_Name, _ValArray, _ValArray, _Tp, _Tp>, \ 01138 typename __fun<_Name, _Tp>::result_type> \ 01139 operator _Op(const valarray<_Tp>& __v, const valarray<_Tp>& __w) \ 01140 { \ 01141 _GLIBCXX_DEBUG_ASSERT(__v.size() == __w.size()); \ 01142 typedef _BinClos<_Name, _ValArray, _ValArray, _Tp, _Tp> _Closure; \ 01143 typedef typename __fun<_Name, _Tp>::result_type _Rt; \ 01144 return _Expr<_Closure, _Rt>(_Closure(__v, __w)); \ 01145 } \ 01146 \ 01147 template<typename _Tp> \ 01148 inline _Expr<_BinClos<_Name, _ValArray,_Constant, _Tp, _Tp>, \ 01149 typename __fun<_Name, _Tp>::result_type> \ 01150 operator _Op(const valarray<_Tp>& __v, const _Tp& __t) \ 01151 { \ 01152 typedef _BinClos<_Name, _ValArray, _Constant, _Tp, _Tp> _Closure; \ 01153 typedef typename __fun<_Name, _Tp>::result_type _Rt; \ 01154 return _Expr<_Closure, _Rt>(_Closure(__v, __t)); \ 01155 } \ 01156 \ 01157 template<typename _Tp> \ 01158 inline _Expr<_BinClos<_Name, _Constant, _ValArray, _Tp, _Tp>, \ 01159 typename __fun<_Name, _Tp>::result_type> \ 01160 operator _Op(const _Tp& __t, const valarray<_Tp>& __v) \ 01161 { \ 01162 typedef _BinClos<_Name, _Constant, _ValArray, _Tp, _Tp> _Closure; \ 01163 typedef typename __fun<_Name, _Tp>::result_type _Rt; \ 01164 return _Expr<_Closure, _Rt>(_Closure(__t, __v)); \ 01165 } 01166 01167 _DEFINE_BINARY_OPERATOR(+, __plus) 01168 _DEFINE_BINARY_OPERATOR(-, __minus) 01169 _DEFINE_BINARY_OPERATOR(*, __multiplies) 01170 _DEFINE_BINARY_OPERATOR(/, __divides) 01171 _DEFINE_BINARY_OPERATOR(%, __modulus) 01172 _DEFINE_BINARY_OPERATOR(^, __bitwise_xor) 01173 _DEFINE_BINARY_OPERATOR(&, __bitwise_and) 01174 _DEFINE_BINARY_OPERATOR(|, __bitwise_or) 01175 _DEFINE_BINARY_OPERATOR(<<, __shift_left) 01176 _DEFINE_BINARY_OPERATOR(>>, __shift_right) 01177 _DEFINE_BINARY_OPERATOR(&&, __logical_and) 01178 _DEFINE_BINARY_OPERATOR(||, __logical_or) 01179 _DEFINE_BINARY_OPERATOR(==, __equal_to) 01180 _DEFINE_BINARY_OPERATOR(!=, __not_equal_to) 01181 _DEFINE_BINARY_OPERATOR(<, __less) 01182 _DEFINE_BINARY_OPERATOR(>, __greater) 01183 _DEFINE_BINARY_OPERATOR(<=, __less_equal) 01184 _DEFINE_BINARY_OPERATOR(>=, __greater_equal) 01185 01186 #undef _DEFINE_BINARY_OPERATOR 01187 01188 #if __cplusplus >= 201103L 01189 /** 01190 * @brief Return an iterator pointing to the first element of 01191 * the valarray. 01192 * @param __va valarray. 01193 */ 01194 template<class _Tp> 01195 inline _Tp* 01196 begin(valarray<_Tp>& __va) 01197 { return std::__addressof(__va[0]); } 01198 01199 /** 01200 * @brief Return an iterator pointing to the first element of 01201 * the const valarray. 01202 * @param __va valarray. 01203 */ 01204 template<class _Tp> 01205 inline const _Tp* 01206 begin(const valarray<_Tp>& __va) 01207 { return std::__addressof(__va[0]); } 01208 01209 /** 01210 * @brief Return an iterator pointing to one past the last element of 01211 * the valarray. 01212 * @param __va valarray. 01213 */ 01214 template<class _Tp> 01215 inline _Tp* 01216 end(valarray<_Tp>& __va) 01217 { return std::__addressof(__va[0]) + __va.size(); } 01218 01219 /** 01220 * @brief Return an iterator pointing to one past the last element of 01221 * the const valarray. 01222 * @param __va valarray. 01223 */ 01224 template<class _Tp> 01225 inline const _Tp* 01226 end(const valarray<_Tp>& __va) 01227 { return std::__addressof(__va[0]) + __va.size(); } 01228 #endif // C++11 01229 01230 // @} group numeric_arrays 01231 01232 _GLIBCXX_END_NAMESPACE_VERSION 01233 } // namespace 01234 01235 #endif /* _GLIBCXX_VALARRAY */