f



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<typename P::T,
std::allocator<typename P::T> > >' 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<typename P::T> >(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<size ; ++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! ]
0
6/28/2003 11:35:50 PM
comp.lang.c++.moderated 10738 articles. 1 followers. allnor (8509) is leader. Post Follow

1 Replies
736 Views

Similar Articles

[PageSpeed] 44

alexismajordomo@yahoo.co.uk (Alexis) writes:

> 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<typename P::T,
> std::allocator<typename P::T> > >' 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.

>
> 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.

> 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! ]
0
llewelly
6/30/2003 4:48:53 AM
Reply: