 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Alexis Guest
|
Posted: Sat Jun 28, 2003 11:35 pm Post subject: partial specialization of function template |
|
|
Hello,
Have a look at this basic code. I am trying to specialize a templated
function. But gcc gives me errors for the line indicated: "partial
specialization `assign_vector<P, std::vector
std::allocator >' of function template". Huh? I
cannot specialize a template funtion?
PS: Ok, there some other few mistakes that prevents correct
compilation, but didnt have time. I am only interested in this
specific error.
Thanks
Alexis
template<class P, class V>
IMG_INLINE
void assign_vector(P& p, V& vector)
{
p.assign(vector);
}
template<class P, class V>
IMG_INLINE
void assign_vector<P, std::vector(P& p,
std::vector<typename P::T>& vector)
{ // ERROR HERE
std::copy(vector.begin(), vector.end(),
p.begin());
}
template<class P, class V>
IMG_INLINE
void assign_vector<P, typename P::T[]>(P& p, typename P::T[]&
vector)
{
std::size_t size = sizeof(vector);
for(std::size_t i=0 ; i
p[i] = vector[i];
}
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
llewelly Guest
|
Posted: Mon Jun 30, 2003 4:48 am Post subject: Re: partial specialization of function template |
|
|
[email]alexismajordomo (AT) yahoo (DOT) co.uk[/email] (Alexis) writes:
| Quote: | Hello,
Have a look at this basic code. I am trying to specialize a templated
function. But gcc gives me errors for the line indicated: "partial
specialization `assign_vector<P, std::vector
std::allocator >' of function template". Huh? I
cannot specialize a template funtion?
|
gcc is correct because here it follows the standard. You are confused
because the standard is wrong. Someone will reply to this post and
say there is nothing wrong with the standard, the DR on this topic
was ruled 'extension', etc. But I think it was a mistake to
support a template operation (partial specialization in this case)
for classes and not for functions. In particular, it means in some
cases a template implementor cannot give a template user the
freedom to choose between functors and functions.
| Quote: |
PS: Ok, there some other few mistakes that prevents correct
compilation, but didnt have time.
|
You should try to take the time. Sometimes it is really hard to figure
out the real problem if it is obscured by other errors in the
code. Sometimes it is impossible.
| Quote: | I am only interested in this
specific error.
[snip] |
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|