Topic: Container/Allocator assumptions.
Author: James Kuyper <kuyper@wizard.net>
Date: 1998/11/20 Raw View
In section 20.1.5, paragraph 4, the standard gives STL container
implementors permission to assume that an Allocator's pointer,
const_pointer, size_type, and difference type are T*, T const *, size_t,
and ptrdiff_t respectively.
I understand that the reason for this freedom, is that by making such
assumptions a container can be written that is far more efficient than
one that allows for the more general case, assuming only the Allocator
requirements listed in table 32. However, do implementors really need
this permission to achieve that efficiency? Wouldn't a partial
specialization take care of that? Here's an example of what I mean:
template <class Allocator, class pointer, class const_pointer,
class size_type, class difference_type> class Inside
{
// Generic implementation of a particular STL container, which
// makes no assumptions about Allocator's pointer,
// const_pointer, size_type, and difference_type typedefs
// beyond those guaranteed by Table 32
};
/* Partial specialization */
template<class T, class Allocator> class Inside<Allocator, T*, T const*,
size_t, ptrdiff_t>
{
// STL container implementation that achieves the full benefits
// of the typedef assumptions about Allocator listed in section
// 20.1.5, p4.
}
template<class T, class Allocator> class Container : public Inside <
Allocator, typename Allocator::pointer,
typename Allocator::const_pointer,
typename Allocator::size_type,
typename Allocator::difference_type>
{
// add ctor's and dtor's which just call the base class version.
};
I can't compile this; gcc bails with a message telling me to file a bug
report, on the partial specialization line.
---
[ 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 ]