J
jimmy
I am trying to simulate typedef template similar to the suggestion of
Herb Sutter in the following article: http://www.gotw.ca/gotw/079.htm
However when implementing typedef templates according to his
suggestion, I run into type inference problems when passing typedef
templates as arguments to template functions. It seems the compiler
(gcc 4.0) cannot resolve the typedef template with an instantiation of
that typedef template. Below is an example to illustrate the exact
problem, along with the corresponding compiler error message. I would
like to the compiler to pattern match LinAlTraits<double>::Vector2 in
the function testThis, but instead it is trying to use the underlying
type boost::numeric::ublas::c_vector<double,2>. Any suggestions on a
workaround or idiom that would allow the syntactic nicety shown below
would be greatly appreciated.
#include <boost/numeric/ublas/vector.hpp>
template <typename Real>
struct LinAlTraits
{
typedef boost::numeric::ublas::c_vector<Real,2> Vector2;
};
template<typename T>
void
testThis(const typename LinAlTraits<T>::Vector2& v2)
{
}
int
main()
{
LinAlTraits<double>::Vector2 v2;
testThis(v2);
}
Here is the error message returned by gcc...
main.cc: In function 'int main()':
main.cc:20: error: no matching function for call to
'testThis(boost::numeric::ublas::c_vector<double, 2u>&)'
"g++" -Wall -ftemplate-depth-100 -O0 -fno-inline -g -c -o
"bin/gcc/debug/main.o" "main.cc"
Thanks,
Jimmy.
Herb Sutter in the following article: http://www.gotw.ca/gotw/079.htm
However when implementing typedef templates according to his
suggestion, I run into type inference problems when passing typedef
templates as arguments to template functions. It seems the compiler
(gcc 4.0) cannot resolve the typedef template with an instantiation of
that typedef template. Below is an example to illustrate the exact
problem, along with the corresponding compiler error message. I would
like to the compiler to pattern match LinAlTraits<double>::Vector2 in
the function testThis, but instead it is trying to use the underlying
type boost::numeric::ublas::c_vector<double,2>. Any suggestions on a
workaround or idiom that would allow the syntactic nicety shown below
would be greatly appreciated.
#include <boost/numeric/ublas/vector.hpp>
template <typename Real>
struct LinAlTraits
{
typedef boost::numeric::ublas::c_vector<Real,2> Vector2;
};
template<typename T>
void
testThis(const typename LinAlTraits<T>::Vector2& v2)
{
}
int
main()
{
LinAlTraits<double>::Vector2 v2;
testThis(v2);
}
Here is the error message returned by gcc...
main.cc: In function 'int main()':
main.cc:20: error: no matching function for call to
'testThis(boost::numeric::ublas::c_vector<double, 2u>&)'
"g++" -Wall -ftemplate-depth-100 -O0 -fno-inline -g -c -o
"bin/gcc/debug/main.o" "main.cc"
Thanks,
Jimmy.