valarray and indirect_array

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?
 
T

Tom Widmer

ES said:
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]);

This fixes it:
valarray said:
}

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?

The compiler. log<double> isn't found since template argument deduction
doesn't work when a user defined conversion is required to call the
"correct" specialization.

Tom
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top