template<typename _Tp>
inline valarray<_Tp>::valarray (size_t __n)
- : _M_size(__n),
- _M_data(static_cast<_Tp*__restrict__>
- (__valarray_get_memory(__n * sizeof (_Tp))))
+ : _M_size(__n), _M_data(__valarray_get_storage<_Tp>(__n))
{ __valarray_default_construct(_M_data, _M_data + __n); }
template<typename _Tp>
inline valarray<_Tp>::valarray (const _Tp& __t, size_t __n)
- : _M_size(__n),
- _M_data(static_cast<_Tp*__restrict__>
- (__valarray_get_memory(__n * sizeof (_Tp))))
+ : _M_size(__n), _M_data(__valarray_get_storage<_Tp>(__n))
{ __valarray_fill_construct (_M_data, _M_data + __n, __t); }
template<typename _Tp>
inline valarray<_Tp>::valarray (const _Tp* __restrict__ __p, size_t __n)
- : _M_size(__n),
- _M_data(static_cast<_Tp*__restrict__>
- (__valarray_get_memory(__n * sizeof (_Tp))))
+ : _M_size(__n), _M_data(__valarray_get_storage<_Tp>(__n))
{ __valarray_copy_construct (__p, __p + __n, _M_data); }
template<typename _Tp>
inline valarray<_Tp>::valarray (const valarray<_Tp>& __v)
- : _M_size(__v._M_size),
- _M_data(static_cast<_Tp*__restrict__>
- (__valarray_get_memory(__v._M_size * sizeof (_Tp))))
+ : _M_size(__v._M_size), _M_data(__valarray_get_storage<_Tp>(__v._M_size))
{ __valarray_copy_construct (__v._M_data, __v._M_data + _M_size, _M_data); }
template<typename _Tp>
inline valarray<_Tp>::valarray (const slice_array<_Tp>& __sa)
- : _M_size(__sa._M_sz),
- _M_data(static_cast<_Tp*__restrict__>
- (__valarray_get_memory(__sa._M_sz * sizeof (_Tp))))
+ : _M_size(__sa._M_sz), _M_data(__valarray_get_storage<_Tp>(__sa._M_sz))
{
- __valarray_copy_construct
- (__sa._M_array, __sa._M_sz, __sa._M_stride, _Array<_Tp>(_M_data));
+ __valarray_copy_construct
+ (__sa._M_array, __sa._M_sz, __sa._M_stride, _Array<_Tp>(_M_data));
}
template<typename _Tp>
inline valarray<_Tp>::valarray (const gslice_array<_Tp>& __ga)
- : _M_size(__ga._M_index.size()),
- _M_data(static_cast<_Tp*__restrict__>
- (__valarray_get_memory(_M_size * sizeof (_Tp))))
+ : _M_size(__ga._M_index.size()),
+ _M_data(__valarray_get_storage<_Tp>(_M_size))
{
- __valarray_copy_construct
- (__ga._M_array, _Array<size_t>(__ga._M_index),
- _Array<_Tp>(_M_data), _M_size);
+ __valarray_copy_construct
+ (__ga._M_array, _Array<size_t>(__ga._M_index),
+ _Array<_Tp>(_M_data), _M_size);
}
template<typename _Tp>
inline valarray<_Tp>::valarray (const mask_array<_Tp>& __ma)
- : _M_size(__ma._M_sz),
- _M_data(static_cast<_Tp*__restrict__>
- (__valarray_get_memory(__ma._M_sz * sizeof (_Tp))))
+ : _M_size(__ma._M_sz), _M_data(__valarray_get_storage<_Tp>(__ma._M_sz))
{
- __valarray_copy_construct
- (__ma._M_array, __ma._M_mask, _Array<_Tp>(_M_data), _M_size);
+ __valarray_copy_construct
+ (__ma._M_array, __ma._M_mask, _Array<_Tp>(_M_data), _M_size);
}
template<typename _Tp>
inline valarray<_Tp>::valarray (const indirect_array<_Tp>& __ia)
- : _M_size(__ia._M_sz),
- _M_data(static_cast<_Tp*__restrict__>
- (__valarray_get_memory(__ia._M_sz * sizeof (_Tp))))
+ : _M_size(__ia._M_sz), _M_data(__valarray_get_storage<_Tp>(__ia._M_sz))
{
- __valarray_copy_construct
- (__ia._M_array, __ia._M_index, _Array<_Tp>(_M_data), _M_size);
+ __valarray_copy_construct
+ (__ia._M_array, __ia._M_index, _Array<_Tp>(_M_data), _M_size);
}
template<typename _Tp> template<class _Dom>
inline valarray<_Tp>::valarray (const _Expr<_Dom, _Tp>& __e)
- : _M_size(__e.size ()),
- _M_data(static_cast<_Tp*__restrict__>
- (__valarray_copy_construct(_M_size * sizeof (_Tp))))
+ : _M_size(__e.size ()), _M_data(__valarray_get_storage<_Tp>(_M_size))
{ __valarray_copy_construct (__e, _M_size, _Array<_Tp>(_M_data)); }
template<typename _Tp>
inline void
valarray<_Tp>::resize (size_t __n, _Tp __c)
{
- if (_M_size != __n) {
- __valarray_destroy_elements(_M_data, _M_data + _M_size);
- __valarray_release_memory(_M_data);
- _M_size = __n;
- _M_data = static_cast<_Tp*__restrict__>
- (__valarray_get_memory(__n * sizeof (_Tp)));
- __valarray_fill_construct(_M_data, _M_data + __n, __c);
- }
- else {
- // this is so to make valarray<valarray<T> > work
- // even though it is not required by the standard.
- __valarray_destroy_elements(_M_data, _M_data + _M_size);
- __valarray_fill_construct(_M_data, _M_data + _M_size, __c);
+ // This complication is so to make valarray<valarray<T> > work
+ // even though it is not required by the standard. Nobody should
+ // be saying valarray<valarray<T> > anyway. See the specs.
+ __valarray_destroy_elements(_M_data, _M_data + _M_size);
+ if (_M_size != __n)
+ {
+ __valarray_release_memory(_M_data);
+ _M_size = __n;
+ _M_data = __valarray_get_storage<_Tp>(__n);
}
+ __valarray_fill_construct(_M_data, _M_data + __n, __c);
}
template<typename _Tp>