Topic: An allocator extension??? please??
Author: sj@aracnet.com (Scott Johnson)
Date: 1996/09/07 Raw View
I've noticed a minor assymetry in the allocator interface; I thought it
might be nice to correct. (It would be useful for some stuff I want to
do.)
The allocator interface has, amone other things:
template<class T>
typename types<T>::pointer address (types<T>::reference x) const;
and
template<class T>
typename types<T>::const_pointer address (types<T>::const_reference x) const;
both of which take the provided object and return a pointer to it.
Why isn't there
template<class T>
typename types<T>::reference dereference (types<T>::pointer x) const;
and its const equivalent, to encapsulate the DEREFERENCE operator????
It would be nice to be able to write an allocator class called
safe_allocator, use THAT for library objects instead of allocator, and
have an exception thrown if someone tries to dereference null. Change a
typedef in the shipping version, and suddenly the checks disappear.
For that matter (changing the subject a bit), why isn't auto_ptr
parameterized in terms of an allocator? Why doesn't it look like:
template<class X, class Allocator=allocator>
class auto_ptr {
public:
typedef Allocator::types<T>::pointer pointer;
typedef Allocator::types<T>::const_pointer const_pointer;
typedef Allocator::types<T>::reference reference;
typedef Allocator::types<T>::const_reference const_reference;
typedef Allocator::types<T>::value_type value_type;
explicit auto_ptr(pointer p=0);
template<class Y>
auto_ptr(const auto_ptr<Y>& r);
template<class Y>
auto_ptr& operator=(const auto_ptr<Y>& r);
~auto_ptr();
reference operator*() const ;
pointer operator->() const ;
pointer get() const ;
pointer release() const ;
};
(I hope I got the interface right..... this was swiped from the More
Effective C++ homepage, with the implementation details removed and the
appropriate allocator stuff added....)
Scott
--
/--------------------------------------------------------------------------\
|Scott Johnson -- Professional (sometimes) SW Engineer and all-purpose Geek|
|I don't speak for nobody but myself, which everyone else is thankful for |
\--------------------------------------------------------------------------/
---
[ comp.std.c++ is moderated. To submit articles: Try just posting with your
newsreader. If that fails, use mailto:std-c++@ncar.ucar.edu
comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
Comments? mailto:std-c++-request@ncar.ucar.edu
]