1 Nov 01:31
[Boot.Pool] Opinions about inconsistent pointer types
David Baird <dhbaird <at> gmail.com>
2007-11-01 00:31:20 GMT
2007-11-01 00:31:20 GMT
Hi,
I was looking through the Pool code and noticed that it presents
inconsistent pointer types to the user ("void *" versus "char *").
For example, if the user wants to implement his/her own user
allocator, they have to write it like, e.g. (using "char *" as the
pointer type):
struct default_user_allocator_new_delete
{
typedef std::size_t size_type;
typedef std::ptrdiff_t difference_type;
static char * malloc(const size_type bytes)
{ return new (std::nothrow) char[bytes]; }
static void free(char * const block)
{ delete [] block; }
};
However, other classes return "void *" as their pointer types, e.g.
singleton_pool:
template <typename Tag, unsigned RequestedSize,
typename UserAllocator,
typename Mutex,
unsigned NextSize>
struct singleton_pool
{
static void * malloc()
(Continue reading)
The question is: I want to have an iterator of a std::list type
that denotes a NULL iterator, which means the iterator points to
nothing, and is obviously different from list::end(), which points
to the pass-the-end of a list.
I'm using the following code:
list<int> alist;
alist.push_back(1);
list<int>::iterator it_NULL; // denotes a NULL iterator
list<int>::iterator it_beg = alist.begin();
std::cout << boolalpha;
std::cout << "(it_NULL == it_beg) " << (it_NULL == it_beg) << endl;
I got correct result under VS 2003, but under VS2005, I got an
runtime error. The cause of the error seems to be I could not compare
2 iterators that don't belong to the same container.
I have looked up the C++ 98 standard, and there seems not to be such a
restriction for 2 iterators of the same type in comparasion should
belong to a same container.
What's wrong? Or any other alternative solution available?
RSS Feed