
The list splice thing can't be helped, because you are splicing from a destructed storage location. So that's just a note in documentation. Obviously, there's nothing that can be done. However, the more pressing issue is the non-static data in monotonic::allocator (namely, the pointer "storage"). On newer compilers, there will be no problems. However, the allocator is non-portable, and that REALLY bothers me. There has to be some way to avoid that. Luckily it seems c++0x will eliminate that assumption about equal allocators. However it is a royal pain in the meantime. I have a few ideas and might play around with them. On Tue, Jun 16, 2009 at 3:26 AM, Christian Schladetsch < christian.schladetsch@gmail.com> wrote:
However, you are right that it fails on GCC.
On Tue, Jun 16, 2009 at 6:53 PM, Christian Schladetsch < christian.schladetsch@gmail.com> wrote:
BOOST_AUTO_TEST_CASE(test_splice) { monotonic::storage<100> store1; std::list<int, monotonic::allocator<int> > list1(store1); { monotonic::storage<100> store2; std::list<int, monotonic::allocator<int> > list2(store2); list2.push_back(1); list1.splice(list1.begin(), list2); } BOOST_CHECK_EQUAL(*list1.begin(), 1); }
Running 5 test cases...
*** No errors detected
On Tue, Jun 16, 2009 at 6:45 PM, Ross Levine <ross.levine@uky.edu> wrote:
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? _______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost