Topic: A question about the template specialization
Author: James Kuyper <kuyper@wizard.net>
Date: 1999/03/20 Raw View
Ryszard Kabatek wrote:
>
> I try to write a specialization of std::vector for pointers
You can legally specialize one of the standard templates, only if your
specialization is dependent on a user-defined type. Among other possible
problems, is that the template may have already been specialized by the
implementor. Allowing such specializations by the implementor is the
reason for this rule.
Most of the container templates are very likely to already be
specialized for pointers, because it makes sense to use a single
implementation for 'void *', and to derive the implementation for 'T*'
from 'void*', just as you are attempting to do.
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: Ryszard Kabatek <rysio@rumcajs.chemie.uni-halle.de>
Date: 1999/03/20 Raw View
I try to write a specialization of std::vector for pointers
(see the sample below).
I get the following error messages (egcs-2.93.12):
test.cc: In instantiation of `vector<void *,allocator<void *> >':
test.cc:22: instantiated from `vector<double *,allocator<double *> >'
test.cc:22: instantiated from here
test.cc:22: base class `vector<void *,allocator<void *> >' has
incomplete type
test.cc: In function `int main()':
test.cc:22: type `typename vector<void *,allocator<void *>
>::allocator_type' is not yet defined
test.cc: In method `vector<double *,allocator<double *>
>::vector(typename vector<void *,allocator<void *> >::allocator_type & = typename vector<void *,typename typename A::rebind::other>::allocator_type())':
test.cc:22: instantiated from here
test.cc:16: confused by earlier errors, bailing out
In my opinion
`allocator<void *>' has a complete type,
`vector<void *,allocator<void *> >' too.
Why I get the error messages?
// test.cc
# include <vector>
template <class T, class A>
class vector<T*, A> : private vector<void*, typename
A::rebind<void*>::other> {
typedef vector<void*, typename A::rebind<void*>::other> inherited;
public:
typedef T* value_type;
typedef typename inherited::allocator_type allocator_type;
public:
allocator_type get_allocator() const
{return inherited::allocator_type();}
vector(const allocator_type& a = allocator_type())
: inherited(a) {}
};
int main()
{
vector<double*> v;
}
--
Ryszard Kabatek
Martin-Luther University Halle-Wittenberg, Department of Physical
Chemistry
Geusaer Str. 88, 06217 Merseburg, Germany
Tel. +49 3461 46 2487 Fax. +49 3461 46 2129
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]