mirror of
https://github.com/llvm-mirror/libcxx.git
synced 2025-10-23 18:38:30 +08:00
Fix a number of bugs in __val_expr's subset operator[].
The current definitions were entirely broken. They didn't call any existing constructor and the forgot to friend the expression types they were trying to construct. git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@357453 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -673,6 +673,7 @@ public:
|
||||
_LIBCPP_INLINE_VISIBILITY
|
||||
size_t size() const {return __size_;}
|
||||
|
||||
template <class> friend class __val_expr;
|
||||
template <class> friend class _LIBCPP_TEMPLATE_VIS valarray;
|
||||
};
|
||||
|
||||
@@ -2221,6 +2222,7 @@ public:
|
||||
_LIBCPP_INLINE_VISIBILITY
|
||||
size_t size() const {return __1d_.size();}
|
||||
|
||||
template <class> friend class __val_expr;
|
||||
template <class> friend class valarray;
|
||||
};
|
||||
|
||||
@@ -2591,6 +2593,7 @@ public:
|
||||
_LIBCPP_INLINE_VISIBILITY
|
||||
size_t size() const {return __1d_.size();}
|
||||
|
||||
template <class> friend class __val_expr;
|
||||
template <class> friend class _LIBCPP_TEMPLATE_VIS valarray;
|
||||
};
|
||||
|
||||
@@ -2613,19 +2616,31 @@ public:
|
||||
|
||||
_LIBCPP_INLINE_VISIBILITY
|
||||
__val_expr<__slice_expr<_ValExpr> > operator[](slice __s) const
|
||||
{return __val_expr<__slice_expr<_ValExpr> >(__expr_, __s);}
|
||||
{
|
||||
typedef __slice_expr<_ValExpr> _NewExpr;
|
||||
return __val_expr< _NewExpr >(_NewExpr(__s, __expr_));
|
||||
}
|
||||
|
||||
_LIBCPP_INLINE_VISIBILITY
|
||||
__val_expr<__indirect_expr<_ValExpr> > operator[](const gslice& __gs) const
|
||||
{return __val_expr<__indirect_expr<_ValExpr> >(__expr_, __gs.__1d_);}
|
||||
{
|
||||
typedef __indirect_expr<_ValExpr> _NewExpr;
|
||||
return __val_expr<_NewExpr >(_NewExpr(__gs.__1d_, __expr_));
|
||||
}
|
||||
|
||||
_LIBCPP_INLINE_VISIBILITY
|
||||
__val_expr<__mask_expr<_ValExpr> > operator[](const valarray<bool>& __vb) const
|
||||
{return __val_expr<__mask_expr<_ValExpr> >(__expr_, __vb);}
|
||||
{
|
||||
typedef __mask_expr<_ValExpr> _NewExpr;
|
||||
return __val_expr< _NewExpr >( _NewExpr(__vb, __expr_));
|
||||
}
|
||||
|
||||
_LIBCPP_INLINE_VISIBILITY
|
||||
__val_expr<__indirect_expr<_ValExpr> > operator[](const valarray<size_t>& __vs) const
|
||||
{return __val_expr<__indirect_expr<_ValExpr> >(__expr_, __vs);}
|
||||
{
|
||||
typedef __indirect_expr<_ValExpr> _NewExpr;
|
||||
return __val_expr< _NewExpr >(_NewExpr(__vs, __expr_));
|
||||
}
|
||||
|
||||
_LIBCPP_INLINE_VISIBILITY
|
||||
__val_expr<_UnaryOp<__unary_plus<value_type>, _ValExpr> >
|
||||
|
@@ -17,6 +17,7 @@
|
||||
|
||||
int main(int, char**)
|
||||
{
|
||||
{
|
||||
int a1[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
|
||||
12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
|
||||
24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35,
|
||||
@@ -73,6 +74,7 @@ int main(int, char**)
|
||||
assert(v1[38] == 38);
|
||||
assert(v1[39] == 39);
|
||||
assert(v1[40] == 40);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@@ -17,6 +17,7 @@
|
||||
|
||||
int main(int, char**)
|
||||
{
|
||||
{
|
||||
int a[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
|
||||
12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
|
||||
24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35,
|
||||
@@ -53,6 +54,44 @@ int main(int, char**)
|
||||
assert(v[21] == 34);
|
||||
assert(v[22] == 35);
|
||||
assert(v[23] == 36);
|
||||
|
||||
}
|
||||
{
|
||||
int a[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
|
||||
12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
|
||||
24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35,
|
||||
36, 37, 38, 39, 40};
|
||||
std::valarray<int> v1(a, sizeof(a)/sizeof(a[0]));
|
||||
std::size_t sz[] = {2, 4, 3};
|
||||
std::size_t st[] = {19, 4, 1};
|
||||
typedef std::valarray<std::size_t> sizes;
|
||||
typedef std::valarray<std::size_t> strides;
|
||||
std::valarray<int> v((v1 + 0)[std::gslice(3, sizes(sz, sizeof(sz)/sizeof(sz[0])),
|
||||
strides(st, sizeof(st)/sizeof(st[0])))]);
|
||||
assert(v.size() == 24);
|
||||
assert(v[ 0] == 3);
|
||||
assert(v[ 1] == 4);
|
||||
assert(v[ 2] == 5);
|
||||
assert(v[ 3] == 7);
|
||||
assert(v[ 4] == 8);
|
||||
assert(v[ 5] == 9);
|
||||
assert(v[ 6] == 11);
|
||||
assert(v[ 7] == 12);
|
||||
assert(v[ 8] == 13);
|
||||
assert(v[ 9] == 15);
|
||||
assert(v[10] == 16);
|
||||
assert(v[11] == 17);
|
||||
assert(v[12] == 22);
|
||||
assert(v[13] == 23);
|
||||
assert(v[14] == 24);
|
||||
assert(v[15] == 26);
|
||||
assert(v[16] == 27);
|
||||
assert(v[17] == 28);
|
||||
assert(v[18] == 30);
|
||||
assert(v[19] == 31);
|
||||
assert(v[20] == 32);
|
||||
assert(v[21] == 34);
|
||||
assert(v[22] == 35);
|
||||
assert(v[23] == 36);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@@ -17,6 +17,7 @@
|
||||
|
||||
int main(int, char**)
|
||||
{
|
||||
{
|
||||
int a[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
|
||||
12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
|
||||
24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35,
|
||||
@@ -53,6 +54,19 @@ int main(int, char**)
|
||||
assert(v[21] == 34);
|
||||
assert(v[22] == 35);
|
||||
assert(v[23] == 36);
|
||||
|
||||
}
|
||||
{
|
||||
int raw_data[] = {0,1,2,3,4,5,6,7,8,9};
|
||||
std::size_t idx_data[] = {0,2,4,6,8};
|
||||
const std::valarray<int> data(raw_data, sizeof(raw_data)/sizeof(raw_data[0]));
|
||||
std::valarray<std::size_t> idx(idx_data, sizeof(idx_data)/sizeof(idx_data[0]));
|
||||
std::valarray<int> result = (data + 0)[idx];
|
||||
assert(result.size() == 5);
|
||||
assert(result[0] == data[idx[0]]);
|
||||
assert(result[1] == data[idx[1]]);
|
||||
assert(result[2] == data[idx[2]]);
|
||||
assert(result[3] == data[idx[3]]);
|
||||
assert(result[4] == data[idx[4]]);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@@ -17,6 +17,7 @@
|
||||
|
||||
int main(int, char**)
|
||||
{
|
||||
{
|
||||
int a[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
|
||||
12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
|
||||
24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35,
|
||||
@@ -54,6 +55,19 @@ int main(int, char**)
|
||||
assert(v[21] == 34);
|
||||
assert(v[22] == 35);
|
||||
assert(v[23] == 36);
|
||||
|
||||
}
|
||||
{
|
||||
int raw_data[] = {0,1,2,3,4,5,6,7,8,9};
|
||||
std::size_t idx_data[] = {0,2,4,6,8};
|
||||
std::valarray<int> data(raw_data, sizeof(raw_data)/sizeof(raw_data[0]));
|
||||
std::valarray<std::size_t> idx(idx_data, sizeof(idx_data)/sizeof(idx_data[0]));
|
||||
std::valarray<int> result = (data + 0)[idx];
|
||||
assert(result.size() == 5);
|
||||
assert(result[0] == data[idx[0]]);
|
||||
assert(result[1] == data[idx[1]]);
|
||||
assert(result[2] == data[idx[2]]);
|
||||
assert(result[3] == data[idx[3]]);
|
||||
assert(result[4] == data[idx[4]]);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@@ -17,8 +17,9 @@
|
||||
|
||||
int main(int, char**)
|
||||
{
|
||||
{
|
||||
int a1[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
|
||||
std::valarray<int> v1(a1, sizeof(a1)/sizeof(a1[0]));
|
||||
const std::valarray<int> v1(a1, sizeof(a1)/sizeof(a1[0]));
|
||||
std::valarray<int> v2 = v1[std::slice(1, 5, 3)];
|
||||
assert(v2.size() == 5);
|
||||
assert(v2[0] == 1);
|
||||
@@ -26,6 +27,14 @@ int main(int, char**)
|
||||
assert(v2[2] == 7);
|
||||
assert(v2[3] == 10);
|
||||
assert(v2[4] == 13);
|
||||
|
||||
}
|
||||
{
|
||||
int a1[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
|
||||
const std::valarray<int> v1(a1, sizeof(a1)/sizeof(a1[0]));
|
||||
std::valarray<int> v2 = (v1 + 0)[std::slice(0, 2, 3)];
|
||||
assert(v2.size() == 2);
|
||||
assert(v2[0] == 0);
|
||||
assert(v2[1] == 3);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@@ -17,6 +17,7 @@
|
||||
|
||||
int main(int, char**)
|
||||
{
|
||||
{
|
||||
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};
|
||||
std::valarray<int> v1(a1, sizeof(a1)/sizeof(a1[0]));
|
||||
@@ -39,6 +40,15 @@ int main(int, char**)
|
||||
assert(v1[13] == -5);
|
||||
assert(v1[14] == 14);
|
||||
assert(v1[15] == 15);
|
||||
|
||||
}
|
||||
{
|
||||
int a1[] = {0, 1, 2, 3, 4, 5};
|
||||
std::valarray<int> v1(a1, sizeof(a1)/sizeof(a1[0]));
|
||||
std::valarray<int> v2((v1 + 0)[std::slice(0, 3, 2)]);
|
||||
assert(v2.size() == 3);
|
||||
assert(v2[0] == 0);
|
||||
assert(v2[1] == 2);
|
||||
assert(v2[2] == 4);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@@ -15,8 +15,10 @@
|
||||
#include <valarray>
|
||||
#include <cassert>
|
||||
|
||||
|
||||
int main(int, char**)
|
||||
{
|
||||
{
|
||||
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 b[N1] = {true, false, false, true, true, false,
|
||||
@@ -30,6 +32,21 @@ int main(int, char**)
|
||||
assert(v2[ 2] == 4);
|
||||
assert(v2[ 3] == 7);
|
||||
assert(v2[ 4] == 11);
|
||||
|
||||
}
|
||||
{
|
||||
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 b[N1] = {true, false, false, true, true, false,
|
||||
false, true, false, false, false, true};
|
||||
std::valarray<int> v1(a1, N1);
|
||||
std::valarray<bool> vb(b, N1);
|
||||
std::valarray<int> v2((v1 - 1)[vb]);
|
||||
assert(v2.size() == 5);
|
||||
assert(v2[ 0] == -1);
|
||||
assert(v2[ 1] == 2);
|
||||
assert(v2[ 2] == 3);
|
||||
assert(v2[ 3] == 6);
|
||||
assert(v2[ 4] == 10);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@@ -17,6 +17,7 @@
|
||||
|
||||
int main(int, char**)
|
||||
{
|
||||
{
|
||||
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 b[N1] = {true, false, false, true, true, false,
|
||||
@@ -31,6 +32,22 @@ int main(int, char**)
|
||||
assert(v2[ 2] == 4);
|
||||
assert(v2[ 3] == 7);
|
||||
assert(v2[ 4] == 11);
|
||||
|
||||
}
|
||||
{
|
||||
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 b[N1] = {true, false, false, true, true, false,
|
||||
false, true, false, false, false, true};
|
||||
std::valarray<int> v1(a1, N1);
|
||||
std::valarray<bool> vb(b, N1);
|
||||
std::valarray<int> v2(5);
|
||||
v2 = (v1 + 0)[vb];
|
||||
assert(v2.size() == 5);
|
||||
assert(v2[ 0] == 0);
|
||||
assert(v2[ 1] == 3);
|
||||
assert(v2[ 2] == 4);
|
||||
assert(v2[ 3] == 7);
|
||||
assert(v2[ 4] == 11);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
Reference in New Issue
Block a user