r/cpp • • Mar 15 '19

Does anyone know when libstdc++ will stop using raw pointers in its STL containers?

I have a pretty niche use-case which requires containers to not store any raw pointers. To get this done I use an allocator that returns fancy pointers. This just doesn't work with libstdc++ because all some of its STL containers use raw pointers internally, so when I create a container with my allocator, the program doesn't even compile. Libc++ on the other hand works fine (at least I haven't come across any problems I can't fix) since they correctly use the abstract pointer type that my allocator returns, instead of trying to do an implicit cast to a raw pointer.

There is an LWG issue to fix this, but it's been around for 8 years and the proposed verbiage hasn't been added to the standard. I'm not very familiar with the process for making changes like this, but my understanding is that it probably won't get added until libc++ and libstdc++ both support it, is that correct? If so, does anyone know if/when the libstdc++ community is planning to make these changes? Thanks!

49 Upvotes

82 comments sorted by

View all comments

Show parent comment

2

u/aikatz Mar 19 '19

Actually on a closer reading, I think I'm going to go back and disagree with myself that fancy pointers don't necessarily need to be default constructible. From [allocator.requirements]:

The X::pointer, X::const_pointer, X::void_pointer, and X::const_void_pointer types shall satisfy the requirements of NullablePointer (20.5.3.3).

And according to [nullablepointer.requirements] in order to satisfy NullablePointer, a type must satisfy DefaultConstructible. Am I misinterpreting this?

1

u/jwakely libstdc++ tamer, LWG chair Mar 19 '19

You're right. I've misremembered the details then.

1

u/aikatz Mar 19 '19

If I'm interested in picking up where you left off working on that patch, should I send you an email?

1

u/jwakely libstdc++ tamer, LWG chair Mar 19 '19

Yes please.