// The template and inlines for the -*- C++ -*- internal _Array helper class.
-// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
-// 2006, 2007
-// 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
// terms of the GNU General Public License as published by the
-// Free Software Foundation; either version 2, or (at your option)
+// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
-// You should have received a copy of the GNU General Public License along
-// with this library; see the file COPYING. If not, write to the Free
-// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
-// USA.
-
-// As a special exception, you may use this file as part of a free software
-// library without restriction. Specifically, if other files instantiate
-// templates or use macros or inline functions from this file, or you compile
-// this file and link it with other files to produce an executable, this
-// file does not by itself cause the resulting executable to be covered by
-// the GNU General Public License. This exception does not however
-// invalidate any other reasons why the executable file might be covered by
-// the GNU General Public License.
-
-/** @file valarray_array.h
+// Under Section 7 of GPL version 3, you are granted additional
+// permissions described in the GCC Runtime Library Exception, version
+// 3.1, as published by the Free Software Foundation.
+
+// You should have received a copy of the GNU General Public License and
+// a copy of the GCC Runtime Library Exception along with this program;
+// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
+// <http://www.gnu.org/licenses/>.
+
+/** @file bits/valarray_array.h
* This is an internal header file, included by other library headers.
- * You should not attempt to use it directly.
+ * Do not attempt to use it directly. @headername{valarray}
*/
// Written by Gabriel Dos Reis <Gabriel.Dos-Reis@DPTMaths.ENS-Cachan.Fr>
#include <cstdlib>
#include <new>
-_GLIBCXX_BEGIN_NAMESPACE(std)
+namespace std _GLIBCXX_VISIBILITY(default)
+{
+_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
// Please note that this isn't exception safe. But
// valarrays aren't required to be exception safe.
inline static void
- _S_do_it(_Tp* __restrict__ __b, _Tp* __restrict__ __e)
+ _S_do_it(_Tp* __b, _Tp* __e)
{
while (__b != __e)
new(__b++) _Tp();
{
// For fundamental types, it suffices to say 'memset()'
inline static void
- _S_do_it(_Tp* __restrict__ __b, _Tp* __restrict__ __e)
+ _S_do_it(_Tp* __b, _Tp* __e)
{ __builtin_memset(__b, 0, (__e - __b) * sizeof(_Tp)); }
};
template<typename _Tp>
inline void
- __valarray_default_construct(_Tp* __restrict__ __b, _Tp* __restrict__ __e)
+ __valarray_default_construct(_Tp* __b, _Tp* __e)
{
_Array_default_ctor<_Tp, __is_scalar<_Tp>::__value>::_S_do_it(__b, __e);
}
// Please note that this isn't exception safe. But
// valarrays aren't required to be exception safe.
inline static void
- _S_do_it(_Tp* __restrict__ __b, _Tp* __restrict__ __e, const _Tp __t)
+ _S_do_it(_Tp* __b, _Tp* __e, const _Tp __t)
{
while (__b != __e)
new(__b++) _Tp(__t);
struct _Array_init_ctor<_Tp, true>
{
inline static void
- _S_do_it(_Tp* __restrict__ __b, _Tp* __restrict__ __e, const _Tp __t)
+ _S_do_it(_Tp* __b, _Tp* __e, const _Tp __t)
{
while (__b != __e)
*__b++ = __t;
template<typename _Tp>
inline void
- __valarray_fill_construct(_Tp* __restrict__ __b, _Tp* __restrict__ __e,
- const _Tp __t)
+ __valarray_fill_construct(_Tp* __b, _Tp* __e, const _Tp __t)
{
- _Array_init_ctor<_Tp, __is_pod(_Tp)>::_S_do_it(__b, __e, __t);
+ _Array_init_ctor<_Tp, __is_trivial(_Tp)>::_S_do_it(__b, __e, __t);
}
//
// Please note that this isn't exception safe. But
// valarrays aren't required to be exception safe.
inline static void
- _S_do_it(const _Tp* __restrict__ __b, const _Tp* __restrict__ __e,
- _Tp* __restrict__ __o)
+ _S_do_it(const _Tp* __b, const _Tp* __e, _Tp* __restrict__ __o)
{
while (__b != __e)
new(__o++) _Tp(*__b++);
struct _Array_copy_ctor<_Tp, true>
{
inline static void
- _S_do_it(const _Tp* __restrict__ __b, const _Tp* __restrict__ __e,
- _Tp* __restrict__ __o)
- { __builtin_memcpy(__o, __b, (__e - __b) * sizeof(_Tp)); }
+ _S_do_it(const _Tp* __b, const _Tp* __e, _Tp* __restrict__ __o)
+ {
+ if (__b)
+ __builtin_memcpy(__o, __b, (__e - __b) * sizeof(_Tp));
+ }
};
template<typename _Tp>
inline void
- __valarray_copy_construct(const _Tp* __restrict__ __b,
- const _Tp* __restrict__ __e,
+ __valarray_copy_construct(const _Tp* __b, const _Tp* __e,
_Tp* __restrict__ __o)
{
- _Array_copy_ctor<_Tp, __is_pod(_Tp)>::_S_do_it(__b, __e, __o);
+ _Array_copy_ctor<_Tp, __is_trivial(_Tp)>::_S_do_it(__b, __e, __o);
}
// copy-construct raw array [__o, *) from strided array __a[<__n : __s>]
__valarray_copy_construct (const _Tp* __restrict__ __a, size_t __n,
size_t __s, _Tp* __restrict__ __o)
{
- if (__is_pod(_Tp))
+ if (__is_trivial(_Tp))
while (__n--)
{
*__o++ = *__a;
const size_t* __restrict__ __i,
_Tp* __restrict__ __o, size_t __n)
{
- if (__is_pod(_Tp))
+ if (__is_trivial(_Tp))
while (__n--)
*__o++ = __a[*__i++];
else
// Do the necessary cleanup when we're done with arrays.
template<typename _Tp>
inline void
- __valarray_destroy_elements(_Tp* __restrict__ __b, _Tp* __restrict__ __e)
+ __valarray_destroy_elements(_Tp* __b, _Tp* __e)
{
- if (!__is_pod(_Tp))
+ if (!__is_trivial(_Tp))
while (__b != __e)
{
__b->~_Tp();
{
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[<>]
__valarray_copy(const _Tp* __restrict__ __a, size_t __n,
_Tp* __restrict__ __b)
{
- _Array_copier<_Tp, __is_pod(_Tp)>::_S_do_it(__a, __n, __b);
+ _Array_copier<_Tp, __is_trivial(_Tp)>::_S_do_it(__a, __n, __b);
}
// Copy strided array __a[<__n : __s>] in plain __b[<__n>]
}
//
- // 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* __restrict__ __f, const _Tp* __restrict__ __l)
+ __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* __restrict__ __f,
- const _Tp* __restrict__ __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
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);
__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)
#undef _DEFINE_ARRAY_FUNCTION
-_GLIBCXX_END_NAMESPACE
+_GLIBCXX_END_NAMESPACE_VERSION
+} // namespace
-#ifndef _GLIBCXX_EXPORT_TEMPLATE
# include <bits/valarray_array.tcc>
-#endif
#endif /* _ARRAY_H */