Index: include/valarray =================================================================== --- include/valarray +++ include/valarray @@ -1263,6 +1263,9 @@ _LIBCPP_INLINE_VISIBILITY void operator=(const value_type& __x) const; + _LIBCPP_INLINE_VISIBILITY + void operator=(const valarray& __va) const; + private: _LIBCPP_INLINE_VISIBILITY slice_array(const slice& __sl, const valarray& __v) @@ -1302,6 +1305,15 @@ *__t = __v[__i]; } +template +inline void +slice_array<_Tp>::operator=(const valarray& __va) const +{ + value_type* __t = __vp_; + for (size_t __i = 0; __i < __va.size(); ++__i, __t += __stride_) + *__t = __va[__i]; +} + template template inline Index: test/std/numerics/numarray/template.indirect.array/indirect.array.assign/slice_assignment.pass.cpp =================================================================== --- /dev/null +++ test/std/numerics/numarray/template.indirect.array/indirect.array.assign/slice_assignment.pass.cpp @@ -0,0 +1,31 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +// + +// template class slice_array + +// void operator=(const valarray& v) const; + +#include +#include + +int main(int, char**) +{ + typedef std::valarray matrix; + + matrix m = { 0, 0, 0 }; + + m[std::slice(0, 3, 1)] = {1, 2, 3}; + + assert(m[0] == 1); + assert(m[1] == 2); + assert(m[2] == 3); + + return 0; +}