[libcxx] r215414 - Add return statement to slice_array and mask_array assignment. Closes PR20614.
Eric Fiselier
eric at efcs.ca
Mon Aug 11 17:06:58 PDT 2014
Author: ericwf
Date: Mon Aug 11 19:06:58 2014
New Revision: 215414
URL: http://llvm.org/viewvc/llvm-project?rev=215414&view=rev
Log:
Add return statement to slice_array and mask_array assignment. Closes PR20614.
This patch just adds the required return statements to slice_array::operator=
and mask_array::operator=.
Tests were added to check that the return value is the same as the object assigned
to.
Modified:
libcxx/trunk/include/valarray
libcxx/trunk/test/numerics/numarray/template.mask.array/mask.array.assign/mask_array.pass.cpp
libcxx/trunk/test/numerics/numarray/template.slice.array/slice.arr.assign/slice_array.pass.cpp
Modified: libcxx/trunk/include/valarray
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/valarray?rev=215414&r1=215413&r2=215414&view=diff
==============================================================================
--- libcxx/trunk/include/valarray (original)
+++ libcxx/trunk/include/valarray Mon Aug 11 19:06:58 2014
@@ -1220,6 +1220,7 @@ slice_array<_Tp>::operator=(const slice_
const value_type* __s = __sa.__vp_;
for (size_t __n = __size_; __n; --__n, __t += __stride_, __s += __sa.__stride_)
*__t = *__s;
+ return *this;
}
template <class _Tp>
@@ -2090,6 +2091,7 @@ mask_array<_Tp>::operator=(const mask_ar
size_t __n = __1d_.size();
for (size_t __i = 0; __i < __n; ++__i)
__vp_[__1d_[__i]] = __ma.__vp_[__1d_[__i]];
+ return *this;
}
template <class _Tp>
Modified: libcxx/trunk/test/numerics/numarray/template.mask.array/mask.array.assign/mask_array.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/numerics/numarray/template.mask.array/mask.array.assign/mask_array.pass.cpp?rev=215414&r1=215413&r2=215414&view=diff
==============================================================================
--- libcxx/trunk/test/numerics/numarray/template.mask.array/mask.array.assign/mask_array.pass.cpp (original)
+++ libcxx/trunk/test/numerics/numarray/template.mask.array/mask.array.assign/mask_array.pass.cpp Mon Aug 11 19:06:58 2014
@@ -18,6 +18,7 @@
int main()
{
+ {
int a1[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
const std::size_t N1 = sizeof(a1)/sizeof(a1[0]);
bool b1[N1] = {true, false, false, true, true, false,
@@ -48,4 +49,18 @@ int main()
assert(v1[13] == 13);
assert(v1[14] == 14);
assert(v1[15] == 15);
+ }
+ // Test return value of assignment
+ {
+ int a1[] = {0, 1, 2};
+ int a2[] = {3, 4, 5};
+ bool b1[] = {true, false, true};
+ std::valarray<int> v1(a1, 3);
+ std::valarray<int> v2(a2, 3);
+ std::valarray<bool> const vb1(b1, 3);
+ std::mask_array<int> m1 = v1[vb1];
+ std::mask_array<int> const m2 = v2[vb1];
+ std::mask_array<int> const & r = (m1 = m2);
+ assert(&r == &m1);
+ }
}
Modified: libcxx/trunk/test/numerics/numarray/template.slice.array/slice.arr.assign/slice_array.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/numerics/numarray/template.slice.array/slice.arr.assign/slice_array.pass.cpp?rev=215414&r1=215413&r2=215414&view=diff
==============================================================================
--- libcxx/trunk/test/numerics/numarray/template.slice.array/slice.arr.assign/slice_array.pass.cpp (original)
+++ libcxx/trunk/test/numerics/numarray/template.slice.array/slice.arr.assign/slice_array.pass.cpp Mon Aug 11 19:06:58 2014
@@ -18,6 +18,7 @@
int main()
{
+ {
int a1[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
int a2[] = {-1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -11, -12};
std::valarray<int> v1(a1, sizeof(a1)/sizeof(a1[0]));
@@ -40,4 +41,16 @@ int main()
assert(v1[13] == -11);
assert(v1[14] == 14);
assert(v1[15] == 15);
+ }
+ // Test return value of assignment.
+ {
+ int a1[] = {0, 1, 2};
+ int a2[] = {3, 4, 3};
+ std::valarray<int> v1(a1, 3);
+ const std::valarray<int> v2(a2, 3);
+ std::slice_array<int> s1 = v1[std::slice(1, 2, 3)];
+ std::slice_array<int> s2 = v1[std::slice(2, 2, 3)];
+ std::slice_array<int> const & s3 = (s1 = s2);
+ assert(&s1 == &s3);
+ }
}
More information about the cfe-commits
mailing list