Re: templates - partial specialization
In article
<f20a2a17-5bbc-4341-8cf6-79e350205875@8g2000hse.googlegroups.com>,
Bharath <tiromarch08@gmail.com> 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! ]