Boost logo

Boost :

Subject: Re: [boost] Proposal: Monotonic Containers
From: Christian Schladetsch (christian.schladetsch_at_[hidden])
Date: 2009-06-16 02:53:51


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_at_[hidden]> 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
>


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk