C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

partial specialization of function template

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated)
View previous topic :: View next topic  
Author Message
Alexis
Guest





PostPosted: Sat Jun 28, 2003 11:35 pm    Post subject: partial specialization of function template Reply with 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?

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





PostPosted: Mon Jun 30, 2003 4:48 am    Post subject: Re: partial specialization of function template Reply with quote



[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
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated) All times are GMT
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.