Topic: overlay flag bit on pointer
Author: Christian Millour <chris161@club-internet.fr>
Date: 1997/06/27 Raw View
Hi all.
On several occasions I have needed to associate a boolean flag with a
pointer, much in the manner of the last version of auto_ptr. On most
architectures it is possible to overlay a bit on the pointer, and thus
get a [much] smaller footprint. Library implementors will most likely
implement this optimization for auto_ptr.
This prompts me to suggest that a new template class, say
template <class T> class flag_ptr {
public:
T & operator *() const;
T * operator->() const;
void flag(bool);
bool flag() const;
...
};
be introduced for public use. It might serve as a private base class
for auto_ptr. Some details need to be sorted out (e.g. assignment and
copy semantics) but I believe such a class would be genuinely useful.
(note that since ownership is not public in auto_ptr, one cannot kludge
flag_ptr around auto_ptr).
What do you think ?
---
[ 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
]