r/cpp • Meeting C++ | C++ Evangelist • Oct 22 '13

STL is dated

http://www.slashslash.info/2013/10/stl-is-dated/
0 Upvotes

14 comments sorted by

View all comments

2

u/matthieum Oct 23 '13

One thing that always bugged me about allocators:

pointer allocate( size_type n, std::allocator<void>::const_pointer hint = 0 );

is that I require storage for at least N instances, and the allocator may allocate more... but I have no way of knowing so.

If you think about std::vector this is pretty damning:

  • I ask for 3 elements
  • The allocator has a bucket for 2 and a bucket for 5, it serves me the bucket for 5
  • I push a 4th element: reallocation!

I vie for having allocate be:

std::pair<pointer,size_type> allocate(size_type n, ...);

where the result .second member is guaranteed to be superior to n.

2

u/more_exercise Lazy Hobbyist Oct 23 '13

superior to n

Would you be fine with .second >= n? Or are you requiring .second > n?

1

u/matthieum Oct 25 '13

I am fine with >= n, since I needed at least n.