By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,105 Members | 1,416 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,105 IT Pros & Developers. It's quick & easy.

valarray and indirect_array

P: n/a
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?

--
ES Kim
Jul 22 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
ES Kim wrote:
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<double> vv = log<double>(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?


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
Jul 22 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.