Index: include/valarray =================================================================== --- include/valarray +++ include/valarray @@ -819,6 +819,7 @@ valarray(const gslice_array& __ga); valarray(const mask_array& __ma); valarray(const indirect_array& __ia); + _LIBCPP_INLINE_VISIBILITY ~valarray(); @@ -1058,10 +1059,63 @@ end(const valarray<_Up>& __v); }; +template +void +valarray<_Tp>::resize(size_t __n, value_type __x) +{ + if (__begin_ != nullptr) + { + while (__end_ != __begin_) + (--__end_)->~value_type(); + _VSTD::__deallocate(__begin_); + __begin_ = __end_ = nullptr; + } + if (__n) + { + __begin_ = __end_ = static_cast(_VSTD::__allocate(__n * sizeof(value_type))); +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + for (; __n; --__n, ++__end_) + ::new (__end_) value_type(__x); +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + resize(0); + throw; + } +#endif // _LIBCPP_NO_EXCEPTIONS + } +} + + +template +inline +valarray<_Tp>::valarray(size_t __n) + : __begin_(0), + __end_(0) +{ + resize(__n); +} + +template +inline +valarray<_Tp>::~valarray() +{ + resize(0); +} + +// The definition for these three functions must appear before they are used and +// before these extern template declarations. +// Otherwise GCC will fail to inline the definition which is an error because +// the functions are declared always inline. _LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS valarray::valarray(size_t)) _LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS valarray::~valarray()) _LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS void valarray::resize(size_t, size_t)) + template struct _UnaryOp<_Op, valarray<_Tp> > { @@ -2747,14 +2801,6 @@ // valarray -template -inline -valarray<_Tp>::valarray(size_t __n) - : __begin_(0), - __end_(0) -{ - resize(__n); -} template inline @@ -2971,12 +3017,6 @@ } } -template -inline -valarray<_Tp>::~valarray() -{ - resize(0); -} template valarray<_Tp>& @@ -3689,37 +3729,6 @@ return __r; } -template -void -valarray<_Tp>::resize(size_t __n, value_type __x) -{ - if (__begin_ != nullptr) - { - while (__end_ != __begin_) - (--__end_)->~value_type(); - _VSTD::__deallocate(__begin_); - __begin_ = __end_ = nullptr; - } - if (__n) - { - __begin_ = __end_ = static_cast(_VSTD::__allocate(__n * sizeof(value_type))); -#ifndef _LIBCPP_NO_EXCEPTIONS - try - { -#endif // _LIBCPP_NO_EXCEPTIONS - for (; __n; --__n, ++__end_) - ::new (__end_) value_type(__x); -#ifndef _LIBCPP_NO_EXCEPTIONS - } - catch (...) - { - resize(0); - throw; - } -#endif // _LIBCPP_NO_EXCEPTIONS - } -} - template inline _LIBCPP_INLINE_VISIBILITY void