]> git.ipfire.org Git - thirdparty/gcc.git/blobdiff - libstdc++-v3/include/std/valarray
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / include / std / valarray
index 79d3a16ecff013a633547350f9e0353d02b8c86b..a4eecd833f71d74907b6e3821cbc037a0f02d51b 100644 (file)
@@ -1,8 +1,6 @@
 // The template and inlines for the -*- C++ -*- valarray class.
 
-// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
-// 2006, 2007, 2009
-// Free Software Foundation, Inc.
+// Copyright (C) 1997-2024 Free Software Foundation, Inc.
 //
 // This file is part of the GNU ISO C++ Library.  This library is free
 // software; you can redistribute it and/or modify it under the
@@ -24,8 +22,8 @@
 // see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 // <http://www.gnu.org/licenses/>.
 
-/** @file valarray
- *  This is a Standard C++ Library header. 
+/** @file include/valarray
+ *  This is a Standard C++ Library header.
  */
 
 // Written by Gabriel Dos Reis <Gabriel.Dos-Reis@DPTMaths.ENS-Cachan.Fr>
 
 #pragma GCC system_header
 
+#include <bits/requires_hosted.h> // <cmath> dependant
+
 #include <bits/c++config.h>
-#include <cstddef>
 #include <cmath>
 #include <algorithm>
 #include <debug/debug.h>
+#if __cplusplus >= 201103L
 #include <initializer_list>
+#endif
 
-_GLIBCXX_BEGIN_NAMESPACE(std)
+namespace std _GLIBCXX_VISIBILITY(default)
+{
+_GLIBCXX_BEGIN_NAMESPACE_VERSION
 
-  template<class _Clos, typename _Tp> 
+  template<class _Clos, typename _Tp>
     class _Expr;
 
-  template<typename _Tp1, typename _Tp2> 
-    class _ValArray;    
+  template<typename _Tp1, typename _Tp2>
+    class _ValArray;
 
+namespace __detail
+{
   template<class _Oper, template<class, class> class _Meta, class _Dom>
     struct _UnClos;
 
   template<class _Oper,
         template<class, class> class _Meta1,
         template<class, class> class _Meta2,
-        class _Dom1, class _Dom2> 
-    class _BinClos;
-
-  template<template<class, class> class _Meta, class _Dom> 
-    class _SClos;
-
-  template<template<class, class> class _Meta, class _Dom> 
-    class _GClos;
-    
-  template<template<class, class> class _Meta, class _Dom> 
-    class _IClos;
-    
-  template<template<class, class> class _Meta, class _Dom> 
-    class _ValFunClos;
-  
-  template<template<class, class> class _Meta, class _Dom> 
-    class _RefFunClos;
+        class _Dom1, class _Dom2>
+    struct _BinClos;
+
+  template<template<class, class> class _Meta, class _Dom>
+    struct _SClos;
+
+  template<template<class, class> class _Meta, class _Dom>
+    struct _GClos;
+
+  template<template<class, class> class _Meta, class _Dom>
+    struct _IClos;
+
+  template<template<class, class> class _Meta, class _Dom>
+    struct _ValFunClos;
+
+  template<template<class, class> class _Meta, class _Dom>
+    struct _RefFunClos;
+} // namespace __detail
+
+  using __detail::_UnClos;
+  using __detail::_BinClos;
+  using __detail::_SClos;
+  using __detail::_GClos;
+  using __detail::_IClos;
+  using __detail::_ValFunClos;
+  using __detail::_RefFunClos;
 
   template<class _Tp> class valarray;   // An array of type _Tp
   class slice;                          // BLAS-like slice out of an array
@@ -82,12 +96,15 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
   template<class _Tp> class mask_array;     // masked array
   template<class _Tp> class indirect_array; // indirected array
 
-_GLIBCXX_END_NAMESPACE
+_GLIBCXX_END_NAMESPACE_VERSION
+} // namespace
 
 #include <bits/valarray_array.h>
 #include <bits/valarray_before.h>
-  
-_GLIBCXX_BEGIN_NAMESPACE(std)
+
+namespace std _GLIBCXX_VISIBILITY(default)
+{
+_GLIBCXX_BEGIN_NAMESPACE_VERSION
 
   /**
    * @defgroup numeric_arrays Numeric Arrays
@@ -105,24 +122,24 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
    *  aliasing that can result from pointer representations.  It represents a
    *  one-dimensional array from which different multidimensional subsets can
    *  be accessed and modified.
-   *  
-   *  @param  Tp  Type of object in the array.
+   *
+   *  @tparam  _Tp  Type of object in the array.
    */
-  template<class _Tp> 
+  template<class _Tp>
     class valarray
     {
       template<class _Op>
-       struct _UnaryOp 
+       struct _UnaryOp
        {
          typedef typename __fun<_Op, _Tp>::result_type __rt;
          typedef _Expr<_UnClos<_Op, _ValArray, _Tp>, __rt> _Rt;
        };
     public:
       typedef _Tp value_type;
-      
+
        // _lib.valarray.cons_ construct/destroy:
       ///  Construct an empty array.
-      valarray();
+      valarray() _GLIBCXX_NOTHROW;
 
       ///  Construct an array with @a n elements.
       explicit valarray(size_t);
@@ -136,6 +153,11 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
       ///  Copy constructor.
       valarray(const valarray&);
 
+#if __cplusplus >= 201103L
+      ///  Move constructor.
+      valarray(valarray&&) noexcept;
+#endif
+
       ///  Construct an array with the same size and values in @a sa.
       valarray(const slice_array<_Tp>&);
 
@@ -148,7 +170,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
       ///  Construct an array with the same size and values in @a ia.
       valarray(const indirect_array<_Tp>&);
 
-#ifdef __GXX_EXPERIMENTAL_CXX0X__
+#if __cplusplus >= 201103L
       ///  Construct an array with an initializer_list of values.
       valarray(initializer_list<_Tp>);
 #endif
@@ -156,27 +178,37 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
       template<class _Dom>
        valarray(const _Expr<_Dom, _Tp>& __e);
 
-      ~valarray();
+      ~valarray() _GLIBCXX_NOEXCEPT;
 
       // _lib.valarray.assign_ assignment:
       /**
        *  @brief  Assign elements to an array.
        *
-       *  Assign elements of array to values in @a v.  Results are undefined
-       *  if @a v does not have the same size as this array.
+       *  Assign elements of array to values in @a v.
+       *
+       *  @param  __v  Valarray to get values from.
+       */
+      valarray<_Tp>& operator=(const valarray<_Tp>& __v);
+
+#if __cplusplus >= 201103L
+      /**
+       *  @brief  Move assign elements to an array.
+       *
+       *  Move assign elements of array to values in @a v.
        *
-       *  @param  v  Valarray to get values from.
+       *  @param  __v  Valarray to get values from.
        */
-      valarray<_Tp>& operator=(const valarray<_Tp>&);
+      valarray<_Tp>& operator=(valarray<_Tp>&& __v) noexcept;
+#endif
 
       /**
        *  @brief  Assign elements to a value.
        *
        *  Assign all elements of array to @a t.
        *
-       *  @param  t  Value for elements.
+       *  @param  __t  Value for elements.
        */
-      valarray<_Tp>& operator=(const _Tp&);
+      valarray<_Tp>& operator=(const _Tp& __t);
 
       /**
        *  @brief  Assign elements to an array subset.
@@ -184,9 +216,9 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
        *  Assign elements of array to values in @a sa.  Results are undefined
        *  if @a sa does not have the same size as this array.
        *
-       *  @param  sa  Array slice to get values from.
+       *  @param  __sa  Array slice to get values from.
        */
-      valarray<_Tp>& operator=(const slice_array<_Tp>&);
+      valarray<_Tp>& operator=(const slice_array<_Tp>& __sa);
 
       /**
        *  @brief  Assign elements to an array subset.
@@ -194,9 +226,9 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
        *  Assign elements of array to values in @a ga.  Results are undefined
        *  if @a ga does not have the same size as this array.
        *
-       *  @param  ga  Array slice to get values from.
+       *  @param  __ga  Array slice to get values from.
        */
-      valarray<_Tp>& operator=(const gslice_array<_Tp>&);
+      valarray<_Tp>& operator=(const gslice_array<_Tp>& __ga);
 
       /**
        *  @brief  Assign elements to an array subset.
@@ -204,9 +236,9 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
        *  Assign elements of array to values in @a ma.  Results are undefined
        *  if @a ma does not have the same size as this array.
        *
-       *  @param  ma  Array slice to get values from.
+       *  @param  __ma  Array slice to get values from.
        */
-      valarray<_Tp>& operator=(const mask_array<_Tp>&);
+      valarray<_Tp>& operator=(const mask_array<_Tp>& __ma);
 
       /**
        *  @brief  Assign elements to an array subset.
@@ -214,20 +246,20 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
        *  Assign elements of array to values in @a ia.  Results are undefined
        *  if @a ia does not have the same size as this array.
        *
-       *  @param  ia  Array slice to get values from.
+       *  @param  __ia  Array slice to get values from.
        */
-      valarray<_Tp>& operator=(const indirect_array<_Tp>&);
+      valarray<_Tp>& operator=(const indirect_array<_Tp>& __ia);
 
-#ifdef __GXX_EXPERIMENTAL_CXX0X__
+#if __cplusplus >= 201103L
       /**
        *  @brief  Assign elements to an initializer_list.
        *
-       *  Assign elements of array to values in @a l.  Results are undefined
-       *  if @a l does not have the same size as this array.
+       *  Assign elements of array to values in @a __l.  Results are undefined
+       *  if @a __l does not have the same size as this array.
        *
-       *  @param  l  initializer_list to get values from.
+       *  @param  __l  initializer_list to get values from.
        */
-      valarray& operator=(initializer_list<_Tp>);
+      valarray& operator=(initializer_list<_Tp> __l);
 #endif
 
       template<class _Dom> valarray<_Tp>&
@@ -235,16 +267,16 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
 
       // _lib.valarray.access_ element access:
       /**
-       *  Return a reference to the i'th array element.  
+       *  Return a reference to the i'th array element.
        *
-       *  @param  i  Index of element to return.
+       *  @param  __i  Index of element to return.
        *  @return  Reference to the i'th element.
        */
-      _Tp&                operator[](size_t);
+      _Tp&                operator[](size_t __i) _GLIBCXX_NOTHROW;
 
       // _GLIBCXX_RESOLVE_LIB_DEFECTS
       // 389. Const overload of valarray::operator[] returns by value.
-      const _Tp&          operator[](size_t) const;
+      const _Tp&          operator[](size_t) const _GLIBCXX_NOTHROW;
 
       // _lib.valarray.sub_ subset operations:
       /**
@@ -254,10 +286,10 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
        *  indicated by the slice argument.  The new valarray has the same size
        *  as the input slice.  @see slice.
        *
-       *  @param  s  The source slice.
-       *  @return  New valarray containing elements in @a s.
+       *  @param  __s  The source slice.
+       *  @return  New valarray containing elements in @a __s.
        */
-      _Expr<_SClos<_ValArray, _Tp>, _Tp> operator[](slice) const;
+      _Expr<_SClos<_ValArray, _Tp>, _Tp> operator[](slice __s) const;
 
       /**
        *  @brief  Return a reference to an array subset.
@@ -266,10 +298,10 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
        *  indicated by the slice argument.  The new valarray has the same size
        *  as the input slice.  @see slice.
        *
-       *  @param  s  The source slice.
-       *  @return  New valarray containing elements in @a s.
+       *  @param  __s  The source slice.
+       *  @return  New valarray containing elements in @a __s.
        */
-      slice_array<_Tp>    operator[](slice);
+      slice_array<_Tp>    operator[](slice __s);
 
       /**
        *  @brief  Return an array subset.
@@ -277,10 +309,10 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
        *  Returns a slice_array referencing the elements of the array
        *  indicated by the slice argument.  @see gslice.
        *
-       *  @param  s  The source slice.
-       *  @return  Slice_array referencing elements indicated by @a s.
+       *  @param  __s  The source slice.
+       *  @return  Slice_array referencing elements indicated by @a __s.
        */
-      _Expr<_GClos<_ValArray, _Tp>, _Tp> operator[](const gslice&) const;
+      _Expr<_GClos<_ValArray, _Tp>, _Tp> operator[](const gslice& __s) const;
 
       /**
        *  @brief  Return a reference to an array subset.
@@ -289,10 +321,10 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
        *  indicated by the gslice argument.  The new valarray has
        *  the same size as the input gslice.  @see gslice.
        *
-       *  @param  s  The source gslice.
-       *  @return  New valarray containing elements in @a s.
+       *  @param  __s  The source gslice.
+       *  @return  New valarray containing elements in @a __s.
        */
-      gslice_array<_Tp>   operator[](const gslice&);
+      gslice_array<_Tp>   operator[](const gslice& __s);
 
       /**
        *  @brief  Return an array subset.
@@ -303,10 +335,10 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
        *  the new valarray.  Each element of the array is added to the return
        *  valarray if the corresponding element of the argument is true.
        *
-       *  @param  m  The valarray bitmask.
-       *  @return  New valarray containing elements indicated by @a m.
+       *  @param  __m  The valarray bitmask.
+       *  @return  New valarray containing elements indicated by @a __m.
        */
-      valarray<_Tp>       operator[](const valarray<bool>&) const;
+      valarray<_Tp>       operator[](const valarray<bool>& __m) const;
 
       /**
        *  @brief  Return a reference to an array subset.
@@ -317,10 +349,10 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
        *  subset.  Elements of the array are part of the subset if the
        *  corresponding element of the argument is true.
        *
-       *  @param  m  The valarray bitmask.
-       *  @return  New valarray containing elements indicated by @a m.
+       *  @param  __m  The valarray bitmask.
+       *  @return  New valarray containing elements indicated by @a __m.
        */
-      mask_array<_Tp>     operator[](const valarray<bool>&);
+      mask_array<_Tp>     operator[](const valarray<bool>& __m);
 
       /**
        *  @brief  Return an array subset.
@@ -330,11 +362,11 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
        *  interpreted as the indices of elements of this valarray to copy to
        *  the return valarray.
        *
-       *  @param  i  The valarray element index list.
-       *  @return  New valarray containing elements in @a s.
+       *  @param  __i  The valarray element index list.
+       *  @return  New valarray containing elements in @a __s.
        */
       _Expr<_IClos<_ValArray, _Tp>, _Tp>
-        operator[](const valarray<size_t>&) const;
+        operator[](const valarray<size_t>& __i) const;
 
       /**
        *  @brief  Return a reference to an array subset.
@@ -345,10 +377,10 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
        *  in the subset.  The returned indirect_array refers to these
        *  elements.
        *
-       *  @param  i  The valarray element index list.
-       *  @return  Indirect_array referencing elements in @a i.
+       *  @param  __i  The valarray element index list.
+       *  @return  Indirect_array referencing elements in @a __i.
        */
-      indirect_array<_Tp> operator[](const valarray<size_t>&);
+      indirect_array<_Tp> operator[](const valarray<size_t>& __i);
 
       // _lib.valarray.unary_ unary operators:
       ///  Return a new valarray by applying unary + to each element.
@@ -446,6 +478,11 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
        valarray<_Tp>& operator>>=(const _Expr<_Dom, _Tp>&);
 
       // _lib.valarray.members_ member functions:
+#if __cplusplus >= 201103L
+      ///  Swap.
+      void swap(valarray<_Tp>& __v) noexcept;
+#endif
+
       ///  Return the number of elements in array.
       size_t size() const;
 
@@ -458,10 +495,10 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
       _Tp    sum() const;
 
       ///  Return the minimum element using operator<().
-      _Tp    min() const;      
+      _Tp    min() const;
 
       ///  Return the maximum element using operator<().
-      _Tp    max() const;      
+      _Tp    max() const;
 
       /**
        *  @brief  Return a shifted array.
@@ -475,10 +512,10 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
        *  Positive arguments shift toward index 0, discarding elements [0, n).
        *  Negative arguments discard elements from the top of the array.
        *
-       *  @param  n  Number of element positions to shift.
+       *  @param  __n  Number of element positions to shift.
        *  @return  New valarray with elements in shifted positions.
        */
-      valarray<_Tp> shift (int) const;
+      valarray<_Tp> shift (int __n) const;
 
       /**
        *  @brief  Return a rotated array.
@@ -492,34 +529,34 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
        *  Positive arguments shift toward index 0, wrapping around the top.
        *  Negative arguments shift towards the top, wrapping around to 0.
        *
-       *  @param  n  Number of element positions to rotate.
+       *  @param  __n  Number of element positions to rotate.
        *  @return  New valarray with elements in shifted positions.
        */
-      valarray<_Tp> cshift(int) const;
+      valarray<_Tp> cshift(int __n) const;
 
       /**
        *  @brief  Apply a function to the array.
        *
        *  Returns a new valarray with elements assigned to the result of
-       *  applying func to the corresponding element of this array.  The new
+       *  applying __func to the corresponding element of this array.  The new
        *  array has the same size as this one.
        *
-       *  @param  func  Function of Tp returning Tp to apply.
+       *  @param  __func  Function of Tp returning Tp to apply.
        *  @return  New valarray with transformed elements.
        */
-      _Expr<_ValFunClos<_ValArray, _Tp>, _Tp> apply(_Tp func(_Tp)) const;
+      _Expr<_ValFunClos<_ValArray, _Tp>, _Tp> apply(_Tp __func(_Tp)) const;
 
       /**
        *  @brief  Apply a function to the array.
        *
        *  Returns a new valarray with elements assigned to the result of
-       *  applying func to the corresponding element of this array.  The new
+       *  applying __func to the corresponding element of this array.  The new
        *  array has the same size as this one.
        *
-       *  @param  func  Function of const Tp& returning Tp to apply.
+       *  @param  __func  Function of const Tp& returning Tp to apply.
        *  @return  New valarray with transformed elements.
        */
-      _Expr<_RefFunClos<_ValArray, _Tp>, _Tp> apply(_Tp func(const _Tp&)) const;
+      _Expr<_RefFunClos<_ValArray, _Tp>, _Tp> apply(_Tp __func(const _Tp&)) const;
 
       /**
        *  @brief  Resize array.
@@ -527,37 +564,43 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
        *  Resize this array to @a size and set all elements to @a c.  All
        *  references and iterators are invalidated.
        *
-       *  @param  size  New array size.
-       *  @param  c  New value for all elements.
+       *  @param  __size  New array size.
+       *  @param  __c  New value for all elements.
        */
       void resize(size_t __size, _Tp __c = _Tp());
 
     private:
       size_t _M_size;
       _Tp* __restrict__ _M_data;
-      
-      friend class _Array<_Tp>;
+
+      friend struct _Array<_Tp>;
     };
-  
+
+#if __cpp_deduction_guides >= 201606
+  template<typename _Tp, size_t _Nm>
+    valarray(const _Tp(&)[_Nm], size_t) -> valarray<_Tp>;
+#endif
+
   template<typename _Tp>
     inline const _Tp&
-    valarray<_Tp>::operator[](size_t __i) const
-    { 
+    valarray<_Tp>::operator[](size_t __i) const _GLIBCXX_NOTHROW
+    {
       __glibcxx_requires_subscript(__i);
       return _M_data[__i];
     }
 
   template<typename _Tp>
     inline _Tp&
-    valarray<_Tp>::operator[](size_t __i)
-    { 
+    valarray<_Tp>::operator[](size_t __i) _GLIBCXX_NOTHROW
+    {
       __glibcxx_requires_subscript(__i);
       return _M_data[__i];
     }
 
-  // @} group numeric_arrays
+  /// @} group numeric_arrays
 
-_GLIBCXX_END_NAMESPACE
+_GLIBCXX_END_NAMESPACE_VERSION
+} // namespace
 
 #include <bits/valarray_after.h>
 #include <bits/slice_array.h>
@@ -566,7 +609,9 @@ _GLIBCXX_END_NAMESPACE
 #include <bits/mask_array.h>
 #include <bits/indirect_array.h>
 
-_GLIBCXX_BEGIN_NAMESPACE(std)
+namespace std _GLIBCXX_VISIBILITY(default)
+{
+_GLIBCXX_BEGIN_NAMESPACE_VERSION
 
   /**
    * @addtogroup numeric_arrays
@@ -575,11 +620,11 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
 
   template<typename _Tp>
     inline
-    valarray<_Tp>::valarray() : _M_size(0), _M_data(0) {}
+    valarray<_Tp>::valarray() _GLIBCXX_NOTHROW : _M_size(0), _M_data(0) {}
 
   template<typename _Tp>
-    inline 
-    valarray<_Tp>::valarray(size_t __n) 
+    inline
+    valarray<_Tp>::valarray(size_t __n)
     : _M_size(__n), _M_data(__valarray_get_storage<_Tp>(__n))
     { std::__valarray_default_construct(_M_data, _M_data + __n); }
 
@@ -593,9 +638,9 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
     inline
     valarray<_Tp>::valarray(const _Tp* __restrict__ __p, size_t __n)
     : _M_size(__n), _M_data(__valarray_get_storage<_Tp>(__n))
-    { 
-      _GLIBCXX_DEBUG_ASSERT(__p != 0 || __n == 0);
-      std::__valarray_copy_construct(__p, __p + __n, _M_data); 
+    {
+      __glibcxx_assert(__p != 0 || __n == 0);
+      std::__valarray_copy_construct(__p, __p + __n, _M_data);
     }
 
   template<typename _Tp>
@@ -605,6 +650,17 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
     { std::__valarray_copy_construct(__v._M_data, __v._M_data + _M_size,
                                     _M_data); }
 
+#if __cplusplus >= 201103L
+  template<typename _Tp>
+    inline
+    valarray<_Tp>::valarray(valarray<_Tp>&& __v) noexcept
+    : _M_size(__v._M_size), _M_data(__v._M_data)
+    {
+      __v._M_size = 0;
+      __v._M_data = 0;
+    }
+#endif
+
   template<typename _Tp>
     inline
     valarray<_Tp>::valarray(const slice_array<_Tp>& __sa)
@@ -643,12 +699,12 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
        (__ia._M_array, __ia._M_index, _Array<_Tp>(_M_data), _M_size);
     }
 
-#ifdef __GXX_EXPERIMENTAL_CXX0X__
+#if __cplusplus >= 201103L
   template<typename _Tp>
     inline
     valarray<_Tp>::valarray(initializer_list<_Tp> __l)
-      : _M_size(__l.size()), _M_data(__valarray_get_storage<_Tp>(__l.size()))
-    { std::__valarray_copy_construct (__l.begin(), __l.end(), _M_data); }
+    : _M_size(__l.size()), _M_data(__valarray_get_storage<_Tp>(__l.size()))
+    { std::__valarray_copy_construct(__l.begin(), __l.end(), _M_data); }
 #endif
 
   template<typename _Tp> template<class _Dom>
@@ -659,7 +715,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
 
   template<typename _Tp>
     inline
-    valarray<_Tp>::~valarray()
+    valarray<_Tp>::~valarray() _GLIBCXX_NOEXCEPT
     {
       std::__valarray_destroy_elements(_M_data, _M_data + _M_size);
       std::__valarray_release_memory(_M_data);
@@ -669,18 +725,63 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
     inline valarray<_Tp>&
     valarray<_Tp>::operator=(const valarray<_Tp>& __v)
     {
-      _GLIBCXX_DEBUG_ASSERT(_M_size == __v._M_size);
-      std::__valarray_copy(__v._M_data, _M_size, _M_data);
+      // _GLIBCXX_RESOLVE_LIB_DEFECTS
+      // 630. arrays of valarray.
+      if (_M_size == __v._M_size)
+       std::__valarray_copy(__v._M_data, _M_size, _M_data);
+      else
+       {
+         if (_M_data)
+           {
+             std::__valarray_destroy_elements(_M_data, _M_data + _M_size);
+             std::__valarray_release_memory(_M_data);
+           }
+         _M_size = __v._M_size;
+         _M_data = __valarray_get_storage<_Tp>(_M_size);
+         std::__valarray_copy_construct(__v._M_data, __v._M_data + _M_size,
+                                        _M_data);
+       }
+      return *this;
+    }
+
+#if __cplusplus >= 201103L
+  template<typename _Tp>
+    inline valarray<_Tp>&
+    valarray<_Tp>::operator=(valarray<_Tp>&& __v) noexcept
+    {
+      if (_M_data)
+       {
+         std::__valarray_destroy_elements(_M_data, _M_data + _M_size);
+         std::__valarray_release_memory(_M_data);
+       }
+      _M_size = __v._M_size;
+      _M_data = __v._M_data;
+      __v._M_size = 0;
+      __v._M_data = 0;
       return *this;
     }
 
-#ifdef __GXX_EXPERIMENTAL_CXX0X__
   template<typename _Tp>
     inline valarray<_Tp>&
     valarray<_Tp>::operator=(initializer_list<_Tp> __l)
     {
-      _GLIBCXX_DEBUG_ASSERT(_M_size == __l.size());
-      std::__valarray_copy(__l.begin(), __l.size(), _M_data);
+      // _GLIBCXX_RESOLVE_LIB_DEFECTS
+      // 630. arrays of valarray.
+      if (_M_size == __l.size())
+       std::__valarray_copy(__l.begin(), __l.size(), _M_data);
+      else
+       {
+         if (_M_data)
+           {
+             std::__valarray_destroy_elements(_M_data, _M_data + _M_size);
+             std::__valarray_release_memory(_M_data);
+           }
+         _M_size = __l.size();
+         _M_data = __valarray_get_storage<_Tp>(_M_size);
+         std::__valarray_copy_construct(__l.begin(), __l.begin() + _M_size,
+                                        _M_data);
+       }
+      return *this;
     }
 #endif
 
@@ -696,7 +797,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
     inline valarray<_Tp>&
     valarray<_Tp>::operator=(const slice_array<_Tp>& __sa)
     {
-      _GLIBCXX_DEBUG_ASSERT(_M_size == __sa._M_sz);
+      __glibcxx_assert(_M_size == __sa._M_sz);
       std::__valarray_copy(__sa._M_array, __sa._M_sz,
                           __sa._M_stride, _Array<_Tp>(_M_data));
       return *this;
@@ -706,7 +807,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
     inline valarray<_Tp>&
     valarray<_Tp>::operator=(const gslice_array<_Tp>& __ga)
     {
-      _GLIBCXX_DEBUG_ASSERT(_M_size == __ga._M_index.size());
+      __glibcxx_assert(_M_size == __ga._M_index.size());
       std::__valarray_copy(__ga._M_array, _Array<size_t>(__ga._M_index),
                           _Array<_Tp>(_M_data), _M_size);
       return *this;
@@ -716,7 +817,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
     inline valarray<_Tp>&
     valarray<_Tp>::operator=(const mask_array<_Tp>& __ma)
     {
-      _GLIBCXX_DEBUG_ASSERT(_M_size == __ma._M_sz);
+      __glibcxx_assert(_M_size == __ma._M_sz);
       std::__valarray_copy(__ma._M_array, __ma._M_mask,
                           _Array<_Tp>(_M_data), _M_size);
       return *this;
@@ -726,7 +827,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
     inline valarray<_Tp>&
     valarray<_Tp>::operator=(const indirect_array<_Tp>& __ia)
     {
-      _GLIBCXX_DEBUG_ASSERT(_M_size == __ia._M_sz);
+      __glibcxx_assert(_M_size == __ia._M_sz);
       std::__valarray_copy(__ia._M_array, __ia._M_index,
                           _Array<_Tp>(_M_data), _M_size);
       return *this;
@@ -736,8 +837,21 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
     inline valarray<_Tp>&
     valarray<_Tp>::operator=(const _Expr<_Dom, _Tp>& __e)
     {
-      _GLIBCXX_DEBUG_ASSERT(_M_size == __e.size());
-      std::__valarray_copy(__e, _M_size, _Array<_Tp>(_M_data));
+      // _GLIBCXX_RESOLVE_LIB_DEFECTS
+      // 630. arrays of valarray.
+      if (_M_size == __e.size())
+       std::__valarray_copy(__e, _M_size, _Array<_Tp>(_M_data));
+      else
+       {
+         if (_M_data)
+           {
+             std::__valarray_destroy_elements(_M_data, _M_data + _M_size);
+             std::__valarray_release_memory(_M_data);
+           }
+         _M_size = __e.size();
+         _M_data = __valarray_get_storage<_Tp>(_M_size);
+         std::__valarray_copy_construct(__e, _M_size, _Array<_Tp>(_M_data));
+       }
       return *this;
     }
 
@@ -779,6 +893,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
       size_t __e = __m.size();
       for (size_t __i=0; __i<__e; ++__i)
        if (__m[__i]) ++__s;
+      __glibcxx_assert(__s <= _M_size);
       return valarray<_Tp>(mask_array<_Tp>(_Array<_Tp>(_M_data), __s,
                                           _Array<bool> (__m)));
     }
@@ -791,6 +906,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
       size_t __e = __m.size();
       for (size_t __i=0; __i<__e; ++__i)
        if (__m[__i]) ++__s;
+      __glibcxx_assert(__s <= _M_size);
       return mask_array<_Tp>(_Array<_Tp>(_M_data), __s, _Array<bool>(__m));
     }
 
@@ -810,8 +926,18 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
                                 _Array<size_t>(__i));
     }
 
+#if __cplusplus >= 201103L
+  template<class _Tp>
+    inline void
+    valarray<_Tp>::swap(valarray<_Tp>& __v) noexcept
+    {
+      std::swap(_M_size, __v._M_size);
+      std::swap(_M_data, __v._M_data);
+    }
+#endif
+
   template<class _Tp>
-    inline size_t 
+    inline size_t
     valarray<_Tp>::size() const
     { return _M_size; }
 
@@ -819,7 +945,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
     inline _Tp
     valarray<_Tp>::sum() const
     {
-      _GLIBCXX_DEBUG_ASSERT(_M_size > 0);
+      __glibcxx_assert(_M_size > 0);
       return std::__valarray_sum(_M_data, _M_data + _M_size);
     }
 
@@ -921,12 +1047,12 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
        }
       std::__valarray_fill_construct(_M_data, _M_data + __n, __c);
     }
-    
+
   template<typename _Tp>
     inline _Tp
     valarray<_Tp>::min() const
     {
-      _GLIBCXX_DEBUG_ASSERT(_M_size > 0);
+      __glibcxx_assert(_M_size > 0);
       return *std::min_element(_M_data, _M_data + _M_size);
     }
 
@@ -934,33 +1060,34 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
     inline _Tp
     valarray<_Tp>::max() const
     {
-      _GLIBCXX_DEBUG_ASSERT(_M_size > 0);
+      __glibcxx_assert(_M_size > 0);
       return *std::max_element(_M_data, _M_data + _M_size);
     }
-  
+
   template<class _Tp>
     inline _Expr<_ValFunClos<_ValArray, _Tp>, _Tp>
-    valarray<_Tp>::apply(_Tp func(_Tp)) const
+    valarray<_Tp>::apply(_Tp __func(_Tp)) const
     {
       typedef _ValFunClos<_ValArray, _Tp> _Closure;
-      return _Expr<_Closure, _Tp>(_Closure(*this, func));
+      return _Expr<_Closure, _Tp>(_Closure(*this, __func));
     }
 
   template<class _Tp>
     inline _Expr<_RefFunClos<_ValArray, _Tp>, _Tp>
-    valarray<_Tp>::apply(_Tp func(const _Tp &)) const
+    valarray<_Tp>::apply(_Tp __func(const _Tp &)) const
     {
       typedef _RefFunClos<_ValArray, _Tp> _Closure;
-      return _Expr<_Closure, _Tp>(_Closure(*this, func));
+      return _Expr<_Closure, _Tp>(_Closure(*this, __func));
     }
 
+  /// @cond undocumented
 #define _DEFINE_VALARRAY_UNARY_OPERATOR(_Op, _Name)                     \
   template<typename _Tp>                                               \
-    inline typename valarray<_Tp>::template _UnaryOp<_Name>::_Rt       \
+    inline typename valarray<_Tp>::template _UnaryOp<_Name>::_Rt       \
     valarray<_Tp>::operator _Op() const                                        \
     {                                                                  \
-      typedef _UnClos<_Name, _ValArray, _Tp> _Closure;                 \
-      typedef typename __fun<_Name, _Tp>::result_type _Rt;              \
+      typedef _UnClos<_Name, _ValArray, _Tp> _Closure;                 \
+      typedef typename __fun<_Name, _Tp>::result_type _Rt;             \
       return _Expr<_Closure, _Rt>(_Closure(*this));                    \
     }
 
@@ -984,7 +1111,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
     inline valarray<_Tp>&                                              \
     valarray<_Tp>::operator _Op##=(const valarray<_Tp> &__v)           \
     {                                                                  \
-      _GLIBCXX_DEBUG_ASSERT(_M_size == __v._M_size);                    \
+      __glibcxx_assert(_M_size == __v._M_size);                                \
       _Array_augmented_##_Name(_Array<_Tp>(_M_data), _M_size,          \
                               _Array<_Tp>(__v._M_data));               \
       return *this;                                                    \
@@ -1024,38 +1151,40 @@ _DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(<<, __shift_left)
 _DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(>>, __shift_right)
 
 #undef _DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT
-    
+
 
 #define _DEFINE_BINARY_OPERATOR(_Op, _Name)                            \
   template<typename _Tp>                                               \
-    inline _Expr<_BinClos<_Name, _ValArray, _ValArray, _Tp, _Tp>,       \
-                 typename __fun<_Name, _Tp>::result_type>               \
+    inline _Expr<_BinClos<_Name, _ValArray, _ValArray, _Tp, _Tp>,      \
+                typename __fun<_Name, _Tp>::result_type>               \
     operator _Op(const valarray<_Tp>& __v, const valarray<_Tp>& __w)   \
     {                                                                  \
-      _GLIBCXX_DEBUG_ASSERT(__v.size() == __w.size());                  \
-      typedef _BinClos<_Name, _ValArray, _ValArray, _Tp, _Tp> _Closure; \
-      typedef typename __fun<_Name, _Tp>::result_type _Rt;              \
-      return _Expr<_Closure, _Rt>(_Closure(__v, __w));                  \
+      __glibcxx_assert(__v.size() == __w.size());                      \
+      typedef _BinClos<_Name, _ValArray, _ValArray, _Tp, _Tp> _Closure;        \
+      typedef typename __fun<_Name, _Tp>::result_type _Rt;             \
+      return _Expr<_Closure, _Rt>(_Closure(__v, __w));                 \
     }                                                                  \
                                                                        \
   template<typename _Tp>                                               \
-    inline _Expr<_BinClos<_Name, _ValArray,_Constant, _Tp, _Tp>,        \
-                 typename __fun<_Name, _Tp>::result_type>               \
-    operator _Op(const valarray<_Tp>& __v, const _Tp& __t)             \
+    inline _Expr<_BinClos<_Name, _ValArray,_Constant, _Tp, _Tp>,       \
+                typename __fun<_Name, _Tp>::result_type>               \
+    operator _Op(const valarray<_Tp>& __v,                             \
+                const typename valarray<_Tp>::value_type& __t)         \
     {                                                                  \
       typedef _BinClos<_Name, _ValArray, _Constant, _Tp, _Tp> _Closure;        \
-      typedef typename __fun<_Name, _Tp>::result_type _Rt;              \
-      return _Expr<_Closure, _Rt>(_Closure(__v, __t));                 \
+      typedef typename __fun<_Name, _Tp>::result_type _Rt;             \
+      return _Expr<_Closure, _Rt>(_Closure(__v, __t));                 \
     }                                                                  \
                                                                        \
   template<typename _Tp>                                               \
-    inline _Expr<_BinClos<_Name, _Constant, _ValArray, _Tp, _Tp>,       \
-                 typename __fun<_Name, _Tp>::result_type>               \
-    operator _Op(const _Tp& __t, const valarray<_Tp>& __v)             \
+    inline _Expr<_BinClos<_Name, _Constant, _ValArray, _Tp, _Tp>,      \
+                typename __fun<_Name, _Tp>::result_type>               \
+    operator _Op(const typename valarray<_Tp>::value_type& __t,                \
+                const valarray<_Tp>& __v)                              \
     {                                                                  \
-      typedef _BinClos<_Name, _Constant, _ValArray, _Tp, _Tp> _Closure; \
-      typedef typename __fun<_Name, _Tp>::result_type _Rt;              \
-      return _Expr<_Closure, _Rt>(_Closure(__t, __v));                 \
+      typedef _BinClos<_Name, _Constant, _ValArray, _Tp, _Tp> _Closure;        \
+      typedef typename __fun<_Name, _Tp>::result_type _Rt;             \
+      return _Expr<_Closure, _Rt>(_Closure(__t, __v));                 \
     }
 
 _DEFINE_BINARY_OPERATOR(+, __plus)
@@ -1078,9 +1207,67 @@ _DEFINE_BINARY_OPERATOR(<=, __less_equal)
 _DEFINE_BINARY_OPERATOR(>=, __greater_equal)
 
 #undef _DEFINE_BINARY_OPERATOR
+  /// @endcond
+
+#if __cplusplus >= 201103L
+  /**
+   *  @brief  Return an iterator pointing to the first element of
+   *          the valarray.
+   *  @param  __va  valarray.
+   */
+  template<class _Tp>
+    [[__nodiscard__]]
+    inline _Tp*
+    begin(valarray<_Tp>& __va) noexcept
+    { return __va.size() ? std::__addressof(__va[0]) : nullptr; }
+
+  /**
+   *  @brief  Return an iterator pointing to the first element of
+   *          the const valarray.
+   *  @param  __va  valarray.
+   */
+  template<class _Tp>
+    [[__nodiscard__]]
+    inline const _Tp*
+    begin(const valarray<_Tp>& __va) noexcept
+    { return __va.size() ? std::__addressof(__va[0]) : nullptr; }
+
+  /**
+   *  @brief  Return an iterator pointing to one past the last element of
+   *          the valarray.
+   *  @param  __va  valarray.
+   */
+  template<class _Tp>
+    [[__nodiscard__]]
+    inline _Tp*
+    end(valarray<_Tp>& __va) noexcept
+    {
+      if (auto __n = __va.size())
+       return std::__addressof(__va[0]) + __n;
+      else
+       return nullptr;
+    }
+
+  /**
+   *  @brief  Return an iterator pointing to one past the last element of
+   *          the const valarray.
+   *  @param  __va  valarray.
+   */
+  template<class _Tp>
+    [[__nodiscard__]]
+    inline const _Tp*
+    end(const valarray<_Tp>& __va) noexcept
+    {
+      if (auto __n = __va.size())
+       return std::__addressof(__va[0]) + __n;
+      else
+       return nullptr;
+    }
+#endif // C++11
 
-  // @} group numeric_arrays
+  /// @} group numeric_arrays
 
-_GLIBCXX_END_NAMESPACE
+_GLIBCXX_END_NAMESPACE_VERSION
+} // namespace
 
 #endif /* _GLIBCXX_VALARRAY */