|
Boost : |
Subject: Re: [boost] Proposal: Monotonic Containers
From: Ross Levine (ross.levine_at_[hidden])
Date: 2009-06-16 02:45:17
>
> monotonic::storage<100> store;
> {
> typedef std::vector<char, monotonic::allocator<char> > Vector;
> Vector vec(store);
> vec.resize(10); // on the stack
> vec.resize(1000); // now on the heap
> }
I am telling you, this code is not portable. Some compilers will create code
that silently crashes because std::vector is not required to use any
specific monotonic::allocator.
Please, please remember that it is REQUIRED that all allocators of the same
type are completely interchangeable in STL containers. That means NO
non-static data. So what you have written below could fail on some
compilers. This type of failure is especially noticable in lists, and almost
unavoidable when using the splice member function if the compiler makes the
allocator equality assumption.
Actually, in general, I would assume this code would fail:
monotonic::storage<100> store1;
boost::monotonic::list<int> list1(store1);
{
monotonic::storage<100> store2;
boost::monotonic::list<int> list2(store2);
list2.push_back(1);
list1.splice(list1.begin(), list2);
}
std::cout << *list1.begin(); // segfault?
Though I haven't tested it. Of course, I don't think there's a way to fix
that. But it's something to know.
Also, your allocator's member pointer storage is public. I assume it's
supposed to be private?
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk