aboutsummaryrefslogtreecommitdiff
path: root/contrib/llvm-project/libcxx/include/valarray
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/llvm-project/libcxx/include/valarray')
-rw-r--r--contrib/llvm-project/libcxx/include/valarray168
1 files changed, 73 insertions, 95 deletions
diff --git a/contrib/llvm-project/libcxx/include/valarray b/contrib/llvm-project/libcxx/include/valarray
index c048a6d7e498..787d8aca2f8e 100644
--- a/contrib/llvm-project/libcxx/include/valarray
+++ b/contrib/llvm-project/libcxx/include/valarray
@@ -136,6 +136,7 @@ public:
void operator>>=(const valarray<value_type>& v) const;
void operator=(const value_type& x) const;
+ void operator=(const valarray<T>& val_arr) const;
slice_array() = delete;
};
@@ -802,7 +803,7 @@ private:
public:
// construct/destroy:
_LIBCPP_INLINE_VISIBILITY
- valarray() : __begin_(0), __end_(0) {}
+ valarray() : __begin_(nullptr), __end_(nullptr) {}
inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
explicit valarray(size_t __n);
_LIBCPP_INLINE_VISIBILITY
@@ -1264,6 +1265,9 @@ public:
_LIBCPP_INLINE_VISIBILITY
void operator=(const value_type& __x) const;
+ _LIBCPP_INLINE_VISIBILITY
+ void operator=(const valarray<value_type>& __va) const;
+
private:
_LIBCPP_INLINE_VISIBILITY
slice_array(const slice& __sl, const valarray<value_type>& __v)
@@ -1304,6 +1308,15 @@ slice_array<_Tp>::operator=(const _Expr& __v) const
}
template <class _Tp>
+inline void
+slice_array<_Tp>::operator=(const valarray<value_type>& __va) const
+{
+ value_type* __t = __vp_;
+ for (size_t __i = 0; __i < __va.size(); ++__i, __t += __stride_)
+ *__t = __va[__i];
+}
+
+template <class _Tp>
template <class _Expr>
inline
typename enable_if
@@ -2738,11 +2751,9 @@ __val_expr<_ValExpr>::operator valarray<__val_expr::result_type>() const
if (__n)
{
__r.__begin_ =
- __r.__end_ =
- static_cast<result_type*>(
- _VSTD::__libcpp_allocate(__n * sizeof(result_type), _LIBCPP_ALIGNOF(result_type)));
+ __r.__end_ = allocator<result_type>().allocate(__n);
for (size_t __i = 0; __i != __n; ++__r.__end_, ++__i)
- ::new (__r.__end_) result_type(__expr_[__i]);
+ ::new ((void*)__r.__end_) result_type(__expr_[__i]);
}
return __r;
}
@@ -2752,19 +2763,18 @@ __val_expr<_ValExpr>::operator valarray<__val_expr::result_type>() const
template <class _Tp>
inline
valarray<_Tp>::valarray(size_t __n)
- : __begin_(0),
- __end_(0)
+ : __begin_(nullptr),
+ __end_(nullptr)
{
if (__n)
{
- __begin_ = __end_ = static_cast<value_type*>(
- _VSTD::__libcpp_allocate(__n * sizeof(value_type), _LIBCPP_ALIGNOF(value_type)));
+ __begin_ = __end_ = allocator<value_type>().allocate(__n);
#ifndef _LIBCPP_NO_EXCEPTIONS
try
{
#endif // _LIBCPP_NO_EXCEPTIONS
for (size_t __n_left = __n; __n_left; --__n_left, ++__end_)
- ::new (__end_) value_type();
+ ::new ((void*)__end_) value_type();
#ifndef _LIBCPP_NO_EXCEPTIONS
}
catch (...)
@@ -2779,27 +2789,26 @@ valarray<_Tp>::valarray(size_t __n)
template <class _Tp>
inline
valarray<_Tp>::valarray(const value_type& __x, size_t __n)
- : __begin_(0),
- __end_(0)
+ : __begin_(nullptr),
+ __end_(nullptr)
{
resize(__n, __x);
}
template <class _Tp>
valarray<_Tp>::valarray(const value_type* __p, size_t __n)
- : __begin_(0),
- __end_(0)
+ : __begin_(nullptr),
+ __end_(nullptr)
{
if (__n)
{
- __begin_ = __end_ = static_cast<value_type*>(
- _VSTD::__libcpp_allocate(__n * sizeof(value_type), _LIBCPP_ALIGNOF(value_type)));
+ __begin_ = __end_ = allocator<value_type>().allocate(__n);
#ifndef _LIBCPP_NO_EXCEPTIONS
try
{
#endif // _LIBCPP_NO_EXCEPTIONS
for (size_t __n_left = __n; __n_left; ++__end_, ++__p, --__n_left)
- ::new (__end_) value_type(*__p);
+ ::new ((void*)__end_) value_type(*__p);
#ifndef _LIBCPP_NO_EXCEPTIONS
}
catch (...)
@@ -2813,19 +2822,18 @@ valarray<_Tp>::valarray(const value_type* __p, size_t __n)
template <class _Tp>
valarray<_Tp>::valarray(const valarray& __v)
- : __begin_(0),
- __end_(0)
+ : __begin_(nullptr),
+ __end_(nullptr)
{
if (__v.size())
{
- __begin_ = __end_ = static_cast<value_type*>(
- _VSTD::__libcpp_allocate(__v.size() * sizeof(value_type), _LIBCPP_ALIGNOF(value_type)));
+ __begin_ = __end_ = allocator<value_type>().allocate(__v.size());
#ifndef _LIBCPP_NO_EXCEPTIONS
try
{
#endif // _LIBCPP_NO_EXCEPTIONS
for (value_type* __p = __v.__begin_; __p != __v.__end_; ++__end_, ++__p)
- ::new (__end_) value_type(*__p);
+ ::new ((void*)__end_) value_type(*__p);
#ifndef _LIBCPP_NO_EXCEPTIONS
}
catch (...)
@@ -2850,21 +2858,20 @@ valarray<_Tp>::valarray(valarray&& __v) _NOEXCEPT
template <class _Tp>
valarray<_Tp>::valarray(initializer_list<value_type> __il)
- : __begin_(0),
- __end_(0)
+ : __begin_(nullptr),
+ __end_(nullptr)
{
const size_t __n = __il.size();
if (__n)
{
- __begin_ = __end_ = static_cast<value_type*>(
-_VSTD::__libcpp_allocate(__n * sizeof(value_type), _LIBCPP_ALIGNOF(value_type)));
+ __begin_ = __end_ = allocator<value_type>().allocate(__n);
#ifndef _LIBCPP_NO_EXCEPTIONS
try
{
#endif // _LIBCPP_NO_EXCEPTIONS
size_t __n_left = __n;
for (const value_type* __p = __il.begin(); __n_left; ++__end_, ++__p, --__n_left)
- ::new (__end_) value_type(*__p);
+ ::new ((void*)__end_) value_type(*__p);
#ifndef _LIBCPP_NO_EXCEPTIONS
}
catch (...)
@@ -2880,21 +2887,20 @@ _VSTD::__libcpp_allocate(__n * sizeof(value_type), _LIBCPP_ALIGNOF(value_type)))
template <class _Tp>
valarray<_Tp>::valarray(const slice_array<value_type>& __sa)
- : __begin_(0),
- __end_(0)
+ : __begin_(nullptr),
+ __end_(nullptr)
{
const size_t __n = __sa.__size_;
if (__n)
{
- __begin_ = __end_ = static_cast<value_type*>(
- _VSTD::__libcpp_allocate(__n * sizeof(value_type), _LIBCPP_ALIGNOF(value_type)));
+ __begin_ = __end_ = allocator<value_type>().allocate(__n);
#ifndef _LIBCPP_NO_EXCEPTIONS
try
{
#endif // _LIBCPP_NO_EXCEPTIONS
size_t __n_left = __n;
for (const value_type* __p = __sa.__vp_; __n_left; ++__end_, __p += __sa.__stride_, --__n_left)
- ::new (__end_) value_type(*__p);
+ ::new ((void*)__end_) value_type(*__p);
#ifndef _LIBCPP_NO_EXCEPTIONS
}
catch (...)
@@ -2908,14 +2914,13 @@ valarray<_Tp>::valarray(const slice_array<value_type>& __sa)
template <class _Tp>
valarray<_Tp>::valarray(const gslice_array<value_type>& __ga)
- : __begin_(0),
- __end_(0)
+ : __begin_(nullptr),
+ __end_(nullptr)
{
const size_t __n = __ga.__1d_.size();
if (__n)
{
- __begin_ = __end_ = static_cast<value_type*>(
- _VSTD::__libcpp_allocate(__n * sizeof(value_type), _LIBCPP_ALIGNOF(value_type)));
+ __begin_ = __end_ = allocator<value_type>().allocate(__n);
#ifndef _LIBCPP_NO_EXCEPTIONS
try
{
@@ -2924,7 +2929,7 @@ valarray<_Tp>::valarray(const gslice_array<value_type>& __ga)
const value_type* __s = __ga.__vp_;
for (_Ip __i = __ga.__1d_.__begin_, __e = __ga.__1d_.__end_;
__i != __e; ++__i, ++__end_)
- ::new (__end_) value_type(__s[*__i]);
+ ::new ((void*)__end_) value_type(__s[*__i]);
#ifndef _LIBCPP_NO_EXCEPTIONS
}
catch (...)
@@ -2938,14 +2943,13 @@ valarray<_Tp>::valarray(const gslice_array<value_type>& __ga)
template <class _Tp>
valarray<_Tp>::valarray(const mask_array<value_type>& __ma)
- : __begin_(0),
- __end_(0)
+ : __begin_(nullptr),
+ __end_(nullptr)
{
const size_t __n = __ma.__1d_.size();
if (__n)
{
- __begin_ = __end_ = static_cast<value_type*>(
- _VSTD::__libcpp_allocate(__n * sizeof(value_type), _LIBCPP_ALIGNOF(value_type)));
+ __begin_ = __end_ = allocator<value_type>().allocate(__n);
#ifndef _LIBCPP_NO_EXCEPTIONS
try
{
@@ -2954,7 +2958,7 @@ valarray<_Tp>::valarray(const mask_array<value_type>& __ma)
const value_type* __s = __ma.__vp_;
for (_Ip __i = __ma.__1d_.__begin_, __e = __ma.__1d_.__end_;
__i != __e; ++__i, ++__end_)
- ::new (__end_) value_type(__s[*__i]);
+ ::new ((void*)__end_) value_type(__s[*__i]);
#ifndef _LIBCPP_NO_EXCEPTIONS
}
catch (...)
@@ -2968,14 +2972,13 @@ valarray<_Tp>::valarray(const mask_array<value_type>& __ma)
template <class _Tp>
valarray<_Tp>::valarray(const indirect_array<value_type>& __ia)
- : __begin_(0),
- __end_(0)
+ : __begin_(nullptr),
+ __end_(nullptr)
{
const size_t __n = __ia.__1d_.size();
if (__n)
{
- __begin_ = __end_ = static_cast<value_type*>(
- _VSTD::__libcpp_allocate(__n * sizeof(value_type), _LIBCPP_ALIGNOF(value_type)));
+ __begin_ = __end_ = allocator<value_type>().allocate(__n);
#ifndef _LIBCPP_NO_EXCEPTIONS
try
{
@@ -2984,7 +2987,7 @@ valarray<_Tp>::valarray(const indirect_array<value_type>& __ia)
const value_type* __s = __ia.__vp_;
for (_Ip __i = __ia.__1d_.__begin_, __e = __ia.__1d_.__end_;
__i != __e; ++__i, ++__end_)
- ::new (__end_) value_type(__s[*__i]);
+ ::new ((void*)__end_) value_type(__s[*__i]);
#ifndef _LIBCPP_NO_EXCEPTIONS
}
catch (...)
@@ -3011,8 +3014,7 @@ valarray<_Tp>::__assign_range(const value_type* __f, const value_type* __l)
if (size() != __n)
{
__clear(size());
- __begin_ = static_cast<value_type*>(
- _VSTD::__libcpp_allocate(__n * sizeof(value_type), _LIBCPP_ALIGNOF(value_type)));
+ __begin_ = allocator<value_type>().allocate(__n);
__end_ = __begin_ + __n;
_VSTD::uninitialized_copy(__f, __l, __begin_);
} else {
@@ -3265,12 +3267,9 @@ valarray<_Tp>::operator+() const
size_t __n = size();
if (__n)
{
- __r.__begin_ =
- __r.__end_ =
- static_cast<value_type*>(
- _VSTD::__libcpp_allocate(__n * sizeof(value_type), _LIBCPP_ALIGNOF(value_type)));
+ __r.__begin_ = __r.__end_ = allocator<value_type>().allocate(__n);
for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
- ::new (__r.__end_) value_type(+*__p);
+ ::new ((void*)__r.__end_) value_type(+*__p);
}
return __r;
}
@@ -3283,12 +3282,9 @@ valarray<_Tp>::operator-() const
size_t __n = size();
if (__n)
{
- __r.__begin_ =
- __r.__end_ =
- static_cast<value_type*>(
- _VSTD::__libcpp_allocate(__n * sizeof(value_type), _LIBCPP_ALIGNOF(value_type)));
+ __r.__begin_ = __r.__end_ = allocator<value_type>().allocate(__n);
for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
- ::new (__r.__end_) value_type(-*__p);
+ ::new ((void*)__r.__end_) value_type(-*__p);
}
return __r;
}
@@ -3301,12 +3297,9 @@ valarray<_Tp>::operator~() const
size_t __n = size();
if (__n)
{
- __r.__begin_ =
- __r.__end_ =
- static_cast<value_type*>(
- _VSTD::__libcpp_allocate(__n * sizeof(value_type), _LIBCPP_ALIGNOF(value_type)));
+ __r.__begin_ = __r.__end_ = allocator<value_type>().allocate(__n);
for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
- ::new (__r.__end_) value_type(~*__p);
+ ::new ((void*)__r.__end_) value_type(~*__p);
}
return __r;
}
@@ -3319,11 +3312,9 @@ valarray<_Tp>::operator!() const
size_t __n = size();
if (__n)
{
- __r.__begin_ =
- __r.__end_ =
- static_cast<bool*>(_VSTD::__libcpp_allocate(__n * sizeof(bool), _LIBCPP_ALIGNOF(bool)));
+ __r.__begin_ = __r.__end_ = allocator<bool>().allocate(__n);
for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
- ::new (__r.__end_) bool(!*__p);
+ ::new ((void*)__r.__end_) bool(!*__p);
}
return __r;
}
@@ -3639,10 +3630,7 @@ valarray<_Tp>::shift(int __i) const
size_t __n = size();
if (__n)
{
- __r.__begin_ =
- __r.__end_ =
- static_cast<value_type*>(
- _VSTD::__libcpp_allocate(__n * sizeof(value_type), _LIBCPP_ALIGNOF(value_type)));
+ __r.__begin_ = __r.__end_ = allocator<value_type>().allocate(__n);
const value_type* __sb;
value_type* __tb;
value_type* __te;
@@ -3661,11 +3649,11 @@ valarray<_Tp>::shift(int __i) const
__te = __r.__begin_ + __n;
}
for (; __r.__end_ != __tb; ++__r.__end_)
- ::new (__r.__end_) value_type();
+ ::new ((void*)__r.__end_) value_type();
for (; __r.__end_ != __te; ++__r.__end_, ++__sb)
- ::new (__r.__end_) value_type(*__sb);
+ ::new ((void*)__r.__end_) value_type(*__sb);
for (__te = __r.__begin_ + __n; __r.__end_ != __te; ++__r.__end_)
- ::new (__r.__end_) value_type();
+ ::new ((void*)__r.__end_) value_type();
}
return __r;
}
@@ -3678,16 +3666,13 @@ valarray<_Tp>::cshift(int __i) const
size_t __n = size();
if (__n)
{
- __r.__begin_ =
- __r.__end_ =
- static_cast<value_type*>(
- _VSTD::__libcpp_allocate(__n * sizeof(value_type), _LIBCPP_ALIGNOF(value_type)));
+ __r.__begin_ = __r.__end_ = allocator<value_type>().allocate(__n);
__i %= static_cast<int>(__n);
const value_type* __m = __i >= 0 ? __begin_ + __i : __end_ + __i;
for (const value_type* __s = __m; __s != __end_; ++__r.__end_, ++__s)
- ::new (__r.__end_) value_type(*__s);
+ ::new ((void*)__r.__end_) value_type(*__s);
for (const value_type* __s = __begin_; __s != __m; ++__r.__end_, ++__s)
- ::new (__r.__end_) value_type(*__s);
+ ::new ((void*)__r.__end_) value_type(*__s);
}
return __r;
}
@@ -3700,12 +3685,9 @@ valarray<_Tp>::apply(value_type __f(value_type)) const
size_t __n = size();
if (__n)
{
- __r.__begin_ =
- __r.__end_ =
- static_cast<value_type*>(
- _VSTD::__libcpp_allocate(__n * sizeof(value_type), _LIBCPP_ALIGNOF(value_type)));
+ __r.__begin_ = __r.__end_ = allocator<value_type>().allocate(__n);
for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
- ::new (__r.__end_) value_type(__f(*__p));
+ ::new ((void*)__r.__end_) value_type(__f(*__p));
}
return __r;
}
@@ -3718,12 +3700,9 @@ valarray<_Tp>::apply(value_type __f(const value_type&)) const
size_t __n = size();
if (__n)
{
- __r.__begin_ =
- __r.__end_ =
- static_cast<value_type*>(
- _VSTD::__libcpp_allocate(__n * sizeof(value_type), _LIBCPP_ALIGNOF(value_type)));
+ __r.__begin_ = __r.__end_ = allocator<value_type>().allocate(__n);
for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
- ::new (__r.__end_) value_type(__f(*__p));
+ ::new ((void*)__r.__end_) value_type(__f(*__p));
}
return __r;
}
@@ -3736,7 +3715,7 @@ void valarray<_Tp>::__clear(size_t __capacity)
{
while (__end_ != __begin_)
(--__end_)->~value_type();
- _VSTD::__libcpp_deallocate(__begin_, __capacity * sizeof(value_type), _LIBCPP_ALIGNOF(value_type));
+ allocator<value_type>().deallocate(__begin_, __capacity);
__begin_ = __end_ = nullptr;
}
}
@@ -3748,14 +3727,13 @@ valarray<_Tp>::resize(size_t __n, value_type __x)
__clear(size());
if (__n)
{
- __begin_ = __end_ = static_cast<value_type*>(
- _VSTD::__libcpp_allocate(__n * sizeof(value_type), _LIBCPP_ALIGNOF(value_type)));
+ __begin_ = __end_ = allocator<value_type>().allocate(__n);
#ifndef _LIBCPP_NO_EXCEPTIONS
try
{
#endif // _LIBCPP_NO_EXCEPTIONS
for (size_t __n_left = __n; __n_left; --__n_left, ++__end_)
- ::new (__end_) value_type(__x);
+ ::new ((void*)__end_) value_type(__x);
#ifndef _LIBCPP_NO_EXCEPTIONS
}
catch (...)