]> git.ipfire.org Git - thirdparty/gcc.git/blobdiff - libstdc++-v3/include/bits/valarray_array.h
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / include / bits / valarray_array.h
index 8f5e047dea1c59f3f76fbf64d0ab6e4ab2a6766c..041fbbe252739e5ad691fe9a3a09c627c27aaf99 100644 (file)
@@ -1,6 +1,6 @@
 // The template and inlines for the -*- C++ -*- internal _Array helper class.
 
-// Copyright (C) 1997-2014 Free Software Foundation, Inc.
+// Copyright (C) 1997-2020 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
@@ -47,18 +47,15 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   // Helper functions on raw pointers
   //
 
-  // We get memory by the old fashion way
-  inline void*
-  __valarray_get_memory(size_t __n)
-  { return operator new(__n); }
+  // We get memory the old fashioned way
+  template<typename _Tp>
+    _Tp*
+    __valarray_get_storage(size_t) __attribute__((__malloc__));
 
   template<typename _Tp>
-    inline _Tp*__restrict__
+    inline _Tp*
     __valarray_get_storage(size_t __n)
-    {
-      return static_cast<_Tp*__restrict__>
-       (std::__valarray_get_memory(__n * sizeof(_Tp)));
-    }
+    { return static_cast<_Tp*>(operator new(__n * sizeof(_Tp))); }
 
   // Return memory to the system
   inline void
@@ -152,7 +149,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     {
       inline static void
       _S_do_it(const _Tp* __b, const _Tp* __e, _Tp* __restrict__ __o)
-      { __builtin_memcpy(__o, __b, (__e - __b) * sizeof(_Tp)); }
+      {
+       if (__b)
+         __builtin_memcpy(__o, __b, (__e - __b) * sizeof(_Tp));
+      }
     };
 
   template<typename _Tp>
@@ -258,7 +258,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     {
       inline static void
       _S_do_it(const _Tp* __restrict__ __a, size_t __n, _Tp* __restrict__ __b)
-      { __builtin_memcpy(__b, __a, __n * sizeof (_Tp)); }
+      {
+       if (__n != 0)
+         __builtin_memcpy(__b, __a, __n * sizeof (_Tp));
+      }
     };
 
   // Copy a plain array __a[<__n>] into a play array __b[<>]
@@ -335,33 +338,21 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     }
 
   //
-  // Compute the sum of elements in range [__f, __l)
+  // Compute the sum of elements in range [__f, __l) which must not be empty.
   // This is a naive algorithm.  It suffers from cancelling.
-  // In the future try to specialize
-  // for _Tp = float, double, long double using a more accurate
-  // algorithm.
+  // In the future try to specialize for _Tp = float, double, long double
+  // using a more accurate algorithm.
   //
   template<typename _Tp>
     inline _Tp
     __valarray_sum(const _Tp* __f, const _Tp* __l)
     {
-      _Tp __r = _Tp();
+      _Tp __r = *__f++;
       while (__f != __l)
        __r += *__f++;
       return __r;
     }
 
-  // Compute the product of all elements in range [__f, __l)
-  template<typename _Tp>
-    inline _Tp
-    __valarray_product(const _Tp* __f, const _Tp* __l)
-    {
-      _Tp __r = _Tp(1);
-      while (__f != __l)
-       __r = __r * *__f++;
-      return __r;
-    }
-
   // Compute the min/max of an array-expression
   template<typename _Ta>
     inline typename _Ta::value_type
@@ -404,7 +395,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   template<typename _Tp>
     struct _Array
     {
-      explicit _Array(size_t);
       explicit _Array(_Tp* const __restrict__);
       explicit _Array(const valarray<_Tp>&);
       _Array(const _Tp* __restrict__, size_t);
@@ -497,12 +487,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
                    __dst._M_data, __j._M_data);
     }
 
-  template<typename _Tp>
-    inline
-    _Array<_Tp>::_Array(size_t __n)
-    : _M_data(__valarray_get_storage<_Tp>(__n))
-    { std::__valarray_default_construct(_M_data, _M_data + __n); }
-
   template<typename _Tp>
     inline
     _Array<_Tp>::_Array(_Tp* const __restrict__ __p)