Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ Moderated > Re: templates -...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 3 of 3 Topic 9574 of 9807
Post > Topic >>

Re: templates - partial specialization

by Carl Barron <cbarron413@[EMAIL PROTECTED] > May 8, 2008 at 03:28 AM

In article
<f20a2a17-5bbc-4341-8cf6-79e350205875@[EMAIL PROTECTED]
>,
Bharath <tiromarch08@[EMAIL PROTECTED]
> wrote:

> 
> basically he is extending the Vector<void*> to Vector<T*>. Why is it
> so? In my example given above, I didn't derive from anything else. But
> I think I'm solving the purpose to define a specialization that is
> used for every my_vec of pointers and ONLY for my_vec of pointers.
> I couldn't understand the author's intention correctly. Can someone
> please explain ?

Many if not most of the operations on a vector<T *> and vector<void *>
are the same.  further if S and T are different types vector<S *> and
vector<T  *> are completely different types so all operations must be
provided for vector<T *> and vector<S *> [at least those that are used]

But if one privately inherits a specialization of vector<void *> and
uses using clauses to make common public methods public again,
then  if   foo is a common operation [ex empty()] then there is
one  function shared by all vector<T *>'s not two or more identical
ones.

namespace std
{
    template <class T,class A = std::allocator<A> > class vector {/**/};

    template <class A = std::allocator<void *> > class vector<void *,A>
    {
       /**/
    };

    template<class T,class A>
    class vector<T *,A>:vector<void *,A>
    {
       /**/
    }
};

now vector<T *> and vector<S *> share common operations [on void ptrs]
and only members that depend on T need to be instanced for vector<T *>
and vector <S *>.  Functions like empty(),clear(),resize(), etc.  are
instanced once for void * ,the type actually stored and not one for T *
and another for S*.

-- 
      [ See http://www.gotw.ca/resources/clcm.htm
for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]
 




 3 Posts in Topic:
templates - partial specialization
Bharath <tiromarch08@[  2008-05-07 10:58:39 
Re: templates - partial specialization
Marcin Swiderski <sfid  2008-05-07 18:31:54 
Re: templates - partial specialization
Carl Barron <cbarron41  2008-05-08 03:28:24 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat Jul 19 19:52:40 CDT 2008.