E
ES Kim
Here's a code fragment from TC++PL, p679:
void f(valarray<double>& v)
{
size_t i[] = { 3, 2, 1, 0 };
valarray<size_t> index(i, 4);
valarray<double> vv = log(v[index]);
}
Every compiler I tried including Comeau produced an error message
something like "no match for call to log(indirect_array<double>)"
valarray has two indirect_array-related subscription operators:
template<typename T> class valarray
{
public:
valarray operator[](const valarray<size_t>&) const;
indirect_array<T> operator[](const valarray<size_t>&);
};
I guess v[index] calls the second one since v is non-const.
If I change the function to "void f(const valarray<double>& v)",
it compiles clean. So my question is:
Which is right - TC++PL or the compiler?
void f(valarray<double>& v)
{
size_t i[] = { 3, 2, 1, 0 };
valarray<size_t> index(i, 4);
valarray<double> vv = log(v[index]);
}
Every compiler I tried including Comeau produced an error message
something like "no match for call to log(indirect_array<double>)"
valarray has two indirect_array-related subscription operators:
template<typename T> class valarray
{
public:
valarray operator[](const valarray<size_t>&) const;
indirect_array<T> operator[](const valarray<size_t>&);
};
I guess v[index] calls the second one since v is non-const.
If I change the function to "void f(const valarray<double>& v)",
it compiles clean. So my question is:
Which is right - TC++PL or the compiler?