Connecting Tech Pros Worldwide Forums | Help | Site Map

Problem with templated special functions

Juanjo
Guest
 
Posts: n/a
#1: Sep 10 '08
Hi,

I have a piece of code that looks like below. The code simply does not
compile because the compiler chooses to believe that std::cos<double>
has type signature std::complex<doublecos(std::complex<double>)

The reason I think is that there are two contradictory definitions,
one in cmath, ::using cos, and another one in complex which reads
template<typename _Tpcomplex<_Tpcos(const complex<_Tp>&);

This is with g++ 4.3. Does anybody have a solution? Am I trying the
impossible?

Juanjo

#include <cmath>
#include <complex>
#include <tensor/tensor.h>

namespace tensor {

Tensor<doublecos(const Tensor<double&t) {
Tensor<doubleoutput(t.dimensions());
// The iterators here have type double * and const double *
std::transform(t.begin(), t.end(), output.begin(),
std::cos<double>);
return output;
}

} // namespace tensor

Pete Becker
Guest
 
Posts: n/a
#2: Sep 10 '08

re: Problem with templated special functions


On 2008-09-10 14:37:26 -0400, Juanjo
<juanjose.garciaripoll@googlemail.comsaid:
Quote:
>
I have a piece of code that looks like below. The code simply does not
compile because the compiler chooses to believe that std::cos<double>
has type signature std::complex<doublecos(std::complex<double>)
The compiler is correct.
Quote:
std::transform(t.begin(), t.end(), output.begin(),
std::cos<double>);
Since the iterators deal in doubles, you obviously meant to refer to
the function cos that takes doubles, and were mislead by erroneous
documentation that you consulted. Make a note of it: whatever
documentation told you that the cos function that takes double is a
template should be discarded.

--
Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The
Standard C++ Library Extensions: a Tutorial and Reference
(www.petebecker.com/tr1book)

Closed Thread